Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add browser and module field support to package.json processing #2433

Closed
ChadKillingsworth opened this issue Apr 13, 2017 · 3 comments
Closed
Assignees

Comments

@ChadKillingsworth
Copy link
Collaborator

Closure-compiler uses the standard node field main in a package.json to locate the entry point of a package. However, several other defacto standards have emerged including the module and browser fields. We need to honor those.

Also, it's become increasingly common for build tooling to add their own field and use that. Angular is using es2015:main and esnext:main fields. We should provide a flag to allow specifying a custom set and order of fields to search.

See the discussion in #2413

@ChadKillingsworth ChadKillingsworth self-assigned this Apr 13, 2017
@kylecordes
Copy link

It looks like:

https://github.com/angular/core-builds/blob/master/package.json#L7

Angular uses es2015 rather than es2015:main as the field to point to the ES2015-in-ES2015-modules code most suitable for Angular app builds in Closure.

Syntax idea:

--node_module_package_fields es2015,module,main

... to mean it should look for those fields, in that order.

@Deraen
Copy link
Contributor

Deraen commented Jul 31, 2017

Any idea how hard this would be to implement? ClojureScript compiler Node module indexing already supports browser field so we only pass the browser file to Closure, which doesn't work as Closure can't resolve requires to that file.

With a very quick glance, looks like RewriteJsonToModule/visitScript for package.json files would need to be updated to check the configured fields: https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/RewriteJsonToModule.java#L139

Example case:
https://github.com/PaulLeCam/react-leaflet/blob/master/lib/Pane.js#L47
https://github.com/BerkeleyTrue/warning/blob/master/browser.js

WARNING: JSC_JS_MODULE_LOAD_WARNING. Failed to load module "warning" at /home/juho/Source/x/y/node_modules/react-leaflet/lib/Pane.js line 47 : 4
WARNING: JSC_JS_MODULE_LOAD_WARNING. Failed to load module "warning" at /home/juho/Source/x/y/node_modules/react-leaflet/lib/Pane.js line 47 : 15

@anmonteiro
Copy link
Contributor

I think this ticket can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants