Commit Graph

21 Commits

Author SHA1 Message Date
Ben Newman
59124681bc Preserve true "main" and "browser" fields of package.json modules.
This reverts commit 32140c8707, restoring
commit 6c643a4763.
2017-02-07 10:43:20 -05:00
Jesse Rosenberger
32140c8707 Revert "Preserve true "main" and "browser" fields of package.json modules."
This reverts commit 6c643a4763.
2017-02-02 20:26:54 -08:00
Ben Newman
6c643a4763 Preserve true "main" and "browser" fields of package.json modules.
Previously, when building a JavaScript bundle for the client, if a
package.json file had a string-valued "browser" field, we would replace
the value of the "main" field of the bundled package.json module with the
value of the "browser" field. This trick was important because it allowed
an npm package to have a different entry point on the client than it had
on the server.

However, that approach became inconsistent if the package.json file was
also explicitly imported as a module, because the package.json stub used
for module resolution prevented the real contents of package.json from
getting bundled, and disagreed with the original package.json module about
the value of the "main" field.

To resolve that inconsistency, it seems better to avoid modifying the
"main" field of package.json modules, and instead rely on the runtime
module system to make sense of the "browser" field, regardless of whether
the package.json module is a stub used only for module resolution or
contains the full contents of the original package.json file.

The ability to understand "browser" fields of package.json modules was
introduced in install@0.8.3:
377d1a3b51

This is potentially a backwards-incompatible change for developers using
this version of `ImportScanner` and `Resolver` who have not yet upgraded
their `modules-runtime` package to at least version 0.7.8. The solution is
to upgrade `modules-runtime`, though it would be nice to enforce that
better somehow.
2017-02-01 10:34:52 -05:00
Ben Newman
61ada2d27b Update statOrNull method of cached Resolver objects.
This solves a problem that sometimes occurs when new modules are added
to an app but the cached Resolver object cannot find them because its
statOrNull method is still using a previous instance of the
corresponding ImportScanner.

Related issues and comments:

https://forums.meteor.com/t/meteor-not-detecting-new-files/31151
https://github.com/Akryum/meteor-vue-component/issues/80
https://github.com/meteor/meteor/pull/7975#issuecomment-259263650
https://github.com/meteor/meteor/issues/8008
2016-11-10 17:50:59 -05:00
Ben Newman
320874989f Implement and use optimisticReadJsonOrNull for better caching.
The problem with optimisticReadFile is that it doesn't cache anything when
the file is missing, because files.readFile throws an ENOENT exception.
2016-10-18 14:05:52 -04:00
Ben Newman
7ea95063b0 Ignore non-top-level identifiers early in Resolver#_resolveNodeModule. 2016-10-13 19:24:33 -04:00
Ben Newman
ebecfeeb3e Prevent exceptional optimisticReadFile from invalidating Resolver caching. 2016-10-12 11:41:34 -04:00
Ben Newman
bcc5f7ff97 Avoid dropping package.json files when "main" names a directory.
An example of an npm package that triggers this bug is the `cli-color`
package, which has a package.json file with a "main" property whose value
is "lib", and a "lib" directory that contains an index.js file.
2016-10-05 14:58:09 -04:00
Ben Newman
21b4c664f4 Cache Resolver objects by their constructor arguments.
This is critical because it means Resolver objects can now survive
development server restarts, which means the optimistic Resolver#resolve
method can remember results indefinitely. Thanks to this change, the
Resolver#resolve method has practically disappeared from rebuild
performance profiles.
2016-10-04 13:08:13 -04:00
Ben Newman
dd3d4363b7 Use optimistic wapper for Resolver#resolve instead of _resolveCache. 2016-10-04 12:59:16 -04:00
Ben Newman
3ef7a08297 Eliminate the onMissing callback from the Resolver API. 2016-10-03 22:06:50 -04:00
Ben Newman
5b238bb0c7 Eliminate the onPackageJson callback from the Resolver API. 2016-10-03 22:06:38 -04:00
Ben Newman
97ca5f1836 Don't pass watchSet when instantiating Resolver objects.
We used the watchSet only when reading package.json files, and I think we
can add package.json files to the watchSet in the ImportScanner instead.
2016-10-03 21:45:36 -04:00
Ben Newman
1a3ae4e117 Remove _statCache and _pkgJsonCache members from Resolver.
This caching is redundant now that we're using optimistic functions for
accessing the file system in Resolver methods.
2016-10-03 21:01:01 -04:00
Ben Newman
033a935a89 Use optimistic functions to speed up IO-bound bottlenecks. 2016-09-26 20:04:28 -04:00
Ben Newman
3f3a6dc6b5 Fix misuse of Map object in Resolver.prototype.resolve.
Using this._resolveCache as an object rather than using the Map methods
(.has, .get, .set) almost works, miraculously, except of course when
resolving a module identifier whose name is "has", "get", or "set",
because then the cache appears to contain a matching entry, but the cached
value is a function object, not a proper byParentDir object.

Fixes #7215.
2016-06-16 16:59:56 -04:00
Ben Newman
40b5a9bdeb Cache Resolver.prototype.resolve results by id and directory. 2016-06-02 17:08:31 -04:00
Ben Newman
00641091d7 Enable profiling for Resolver methods. 2016-06-02 11:25:58 -04:00
Ben Newman
dc9941bfa6 Return {path,id,stat} from Resolver.prototype.resolve.
The id property is an absolute module identifer, suitable for passing to a
native Node require function.
2016-06-01 13:39:57 -04:00
Ben Newman
949e418c12 Privatize resolve* helper methods of Resolver class. 2016-06-01 13:37:17 -04:00
Ben Newman
ec679755ce Extract standalone Resolver class from ImportScanner. 2016-06-01 01:39:23 -04:00