Commit Graph

476 Commits

Author SHA1 Message Date
Ben Newman
24b0ea9fdd Bump compiler/linker/bundler salts to trigger fresh builds. 2016-11-14 21:18:03 -05:00
Ben Newman
e4c7b0890c Watch all imported files in linked npm packages on server. 2016-11-14 14:25:22 -05:00
Ben Newman
2437f72cd7 Strip unnecessary imports for packages with no modules.
Note that even an empty package needs to define Package[name] = {}, so
that other packages can tell at runtime whether it's installed.

Fixes #7927.
2016-11-14 12:51:00 -05:00
Ben Newman
911f25bbf4 Allow lazy api.mainModule modules.
If you call api.mainModule(path, where, { lazy: true }), that main
module will not be evaluated until other code imports it at runtime, and
won't even be bundled if no other code imports it.

Closes #6132.
2016-11-14 12:51:00 -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
8f07a87bd5 Give package test modules access to Npm.depends dependencies.
Similar in spirit to bbac272530.

Fixes #7999.
2016-11-08 15:36:36 -05:00
Ben Newman
932115120f Don't let options.hash override File#hash() salting. 2016-11-08 14:08:08 -05:00
Ben Newman
4ada5c8a17 Bump LINKER_CACHE_SALT and compiler.BUILT_BY for good measure.
This will trigger recompilation and relinking, which should help prevent
various stale caching issues, e.g. #7977.
2016-11-08 13:50:32 -05:00
Ben Newman
940cc4f4d6 Add salt to File#hash in bundler.js.
This is what determines, among other things, source map URL names of the
form <hash>.map, so this may help to avoid #7977.
2016-11-08 13:48:54 -05:00
Ben Newman
a7ac32e00a Tolerate ENOENT errors in Builder#copyDirectory. 2016-11-08 13:33:20 -05:00
Ben Newman
ad460e0d7d Tolerate files.realpath throwing ELOOP exceptions. 2016-11-04 18:45:51 -04:00
Ben Newman
52697c7167 Cache getProdPackageNames optimistically. 2016-11-04 18:26:03 -04:00
Ben Newman
7f35e94713 Tolerate files.realpath throwing ENOENT exceptions. 2016-11-04 18:14:09 -04:00
Ben Newman
af51b8160c Use absolute paths for external symlinks in Builder#copyDirectory.
Thanks to @worldsayshi for reporting this issue with a reproduction.

Fixes #8005.
Fixes #2876.
Fixes #7154.
2016-11-04 17:44:42 -04:00
Ben Newman
8bc4fe20c6 Cache .meteor-portable values temporarily in memory.
This is another way to fix the bug I previously fixed by passing
options.allowSyntaxError to optimisticReadJsonOrNull.

To reproduce the bug (and/or verify that it is fixed), run the following
commands in a terminal:

  rm -rf meteor/packages/npm-mongo/.npm
  meteor/meteor --get-ready

Before these two commits, optimisticReadJsonOrNull would throw a
SyntaxError when reading one of the .meteor-portable files because an
asynchronous write to the same file had not yet finished.
2016-11-02 13:15:57 -04:00
Ben Newman
909419b36e Optionally tolerate SyntaxError in optimisticReadJsonOrNull. 2016-11-02 13:04:09 -04:00
Ben Newman
f0355276a5 Remove babel-runtime-specific logic from compiler-plugin.js. 2016-11-02 12:05:33 -04:00
Ben Newman
1b3edb2300 Write files with appropriate mode in Builder#copyDirectory.
Fixes #7974.
2016-10-28 16:11:29 -04:00
Ben Newman
8d5bfd8ae9 Trivial: fix comment indentation. 2016-10-28 14:49:46 -04:00
Tom Coleman
04f401c711 JSdoc refactoring to make API boxes work again. 2016-10-27 14:55:56 -07:00
Ben Newman
cadf113e6c Only strip devDependencies when buildMode !== "test".
Follow-up to #7953.
2016-10-25 08:46:33 -07:00
Ben Newman
03e798abc9 Only strip devDependencies when buildMode === "production".
Fixes #7953.
2016-10-24 22:10:02 -07:00
Ben Newman
7bcc50c842 Add profiling for meteorInstall-based require calls.
The options.wrapRequire API is new in install@0.8.2.
2016-10-24 18:48:16 -07:00
Ben Newman
33964e9661 Add profiling for Npm.require calls during server startup. 2016-10-24 18:18:03 -07:00
Ben Newman
739890d955 Bump compiler.BUILT_BY and LINKER_CACHE_SALT. 2016-10-23 18:17:26 -04:00
Ben Newman
bdee913b1b Support npm packages with native .node "main" modules.
Note that the value of the "main" property must include the ".node"
extension explicitly, because I have yet to encounter an npm package with
a native "main" module that omits the ".node" extension, and I am loathe
to start calling files.stat(id + ".node") uselessly for every single
missing module.

Fixes #7947.
2016-10-23 17:43:06 -04:00
Ben Newman
8e9896cfcf Include server startup timings in METEOR_PROFILE output.
Meteor 1.4.2 has been mostly focused on improving rebuild times, but what
ultimately matters is the time from changing a file to being able to make
requests against the restarted server, and any code that runs before
server startup should be considered part of that critical path.

If you have a lot of packages, and they do non-trivial work on startup,
this commit should give you much better insight into where time is spent.

Credit to @stubailo for pushing me to provide Meteor developers with
better profiling tools, and thanks to @veered for this specific idea.

Note: because tools/tool-env/profile.js is now loaded as-is by boot.js,
certain ECMAScript features are off-limits, e.g. ...rest params.
2016-10-23 16:36:23 -04:00
Ben Newman
48a2ccbde7 Dirty optimistic functions when node_modules directories change.
This is a bit different from the previous strategy of invalidating
optimistic functions for specific npm package names.

Now, whenever we make changes to the contents of a specific node_modules
directory, or whenever the developer independently modifies an app's
node_modules directory, all optimistic results derived from paths
contained within that node_modules directory will be marked as dirty, and
thus may need to be recomputed.

This strategy prioritizes starting fewer watchers (just one per
node_modules directory) while still allowing npm packages to be added or
removed while the app is running:

  https://github.com/meteor/meteor/pull/7668#issuecomment-255120373

The drawback is that changes within subdirectories of node_modules will
not be detected until the server is fully restarted, but that seems like
an acceptable tradeoff, since npm packages change much less often than
application code.
2016-10-21 20:06:23 -04:00
Ben Newman
5df8f89f7b Warn about babel-runtime helpers not provided by the Meteor package. 2016-10-21 17:56:01 -04:00
Ben Newman
42a9d37326 Tolerate missing files in ImportScanner#_readModule. 2016-10-21 14:00:13 -04: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
6999bdd99e Revert "Use files.* methods instead of optimistic functions in meteor-npm.js."
This reverts commit b69716d778.

Now that we have a better system for invalidating optimistic results
derived from node_modules paths, these optimizations are safe (and yes
fourseven:scss rebuilds successfully).
2016-10-18 14:05:51 -04:00
Ben Newman
af626a5ed6 Dirty relevant optimistic functions after npm updates. 2016-10-18 14:05:51 -04:00
Ben Newman
b69716d778 Use files.* methods instead of optimistic functions in meteor-npm.js.
This fixes a bug that prevents fourseven:scss from properly rebuilding,
because the new .../node_modules/node-sass/vendor/<platform>/binding.node
file is not found by Builder#copyDirectory, because the cached results of
optimisticReaddir are the same as before the rebuild.

Unfortunately, this change introduces a small performance regression
(hundreds of milliseconds at worst), because these files.* methods are
called many times.

I think we can continue using optimistic functions here if we are more
careful about invalidating their results, especially after calling
meteorNpm.rebuildIfNonPortable, but I'll save that for a future commit.
2016-10-18 13:02:20 -04:00
Ben Newman
c33c68f817 Avoid scanning app node_modules for global variable assignments.
File#computeAssignedVariables is one of the most expensive methods called
during initial startup. This change significantly reduces the number of
times it needs to call through to findAssignedGlobals, which saves quite a
bit of parsing time. The exact savings are hard to quantify, of course,
because they depend entirely on how many modules you have in your app's
node_modules directory.

Scanning for global variable assignments is only really useful in Meteor
packages, where we sometimes need to intercept assignments for the
purposes of api.export, though this is increasingly unnecessary now that
you can (and should) just import values from node_modules.

In the app, the only possible value of intercepting global variable
assignments was to prevent polluting the global scope, but we don't even
create a private scope for the app when useGlobalNamespace is true, so
there really was no point to scanning app node_modules.
2016-10-17 11:51:52 -04:00
Ben Newman
7a18012975 Consult babel-runtime package when discarding helper modules.
The most fool-proof way to tell if a module is provided by babel-runtime
is to load babel-runtime as an isopacket and ask it.

This should fix any remaining issues like this one:
https://github.com/meteor/meteor/pull/7668#pullrequestreview-4379559
2016-10-16 16:40:11 -04:00
Ben Newman
8d4ef3f1f7 Only filter out node_modules/babel-runtime/{helpers,regenerator} modules.
This is a refinement of my previous commit 56c041c858.

The Meteor babel-runtime package does not provide substitutes for
babel-runtime/core-js/* modules, so we should not be discarding them from
the client bundle.

Fixes #7930.
2016-10-15 12:01:02 -04:00
Ben Newman
e94d2ad4fc Remove references to node_modules "reference-directly" mode. 2016-10-14 17:01:47 -04:00
Ben Newman
c572b12f26 Allow Builder#copyDirectory to make junction links on Windows. 2016-10-14 16:25:07 -04:00
Ben Newman
56c041c858 Filter out node_modules/babel-runtime/* when Meteor provides babel-runtime.
Should fix #7872 and others (e.g. #7833).
2016-10-13 19:24:34 -04:00
Ben Newman
5de9070c9c Implement ImportScanner#isWeb convenience method. 2016-10-13 19:24:33 -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
6a66368e09 Cache optimistic stat objects in InputFile#findControlFile. 2016-10-10 15:22:53 -04:00
Ben Newman
817876f7b3 Use optimistic functions in PackageSource#initFromPackageDir. 2016-10-07 19:31:17 -04:00
Ben Newman
2553958c38 Merge branch 'devel' into release-1.4.2 2016-10-07 19:30:30 -04:00
Ben Newman
14ee8775c3 Decompose PackageNamespace, PackageNpm, and PackageCordova classes.
Similar to the treatment given to PackageAPI in my commit
af50b4cc5b.

This clear separation of concerns will be helpful for optimizing
PackageSource#initFromPackageDir.
2016-10-06 17:39:23 -04:00
Ben Newman
9608506ce5 Merge pull request #7835 from sebakerckhof/optimize-ignorefiles
Optimize ignoreFiles patterns.
2016-10-06 15:07:29 -04:00
Ben Newman
1d149a0ed7 Keep Resolver.getOrCreate cache results distinct by caller.
The options.statOrNull function is not included in the JSON.stringify key,
but it affects the results because the implementation provided by the
ImportScanner relies on scanner._getFile to return fakeFileStat for
make-believe files created by the ImportScanner.

This becomes a problem if PackageSourceBatch#getResolver accidentally uses
a Resolver created initially for the ImportScanner, or vice-versa.

In particular, when a compiler plugin calls addJavaScript with a path
different from the original file path, the ImportScanner generates two
different modules, one of which imports the other. Only one of the files
exists on disk, though, so a special implementation of statOrNull is
necessary to keep the Resolver from having to share implementation details
with the ImportScanner.

When this system fails, users of compiler plugins see errors like this:
https://github.com/meteor/meteor/pull/7668#issuecomment-251976739
2016-10-06 12:43:37 -04:00
Ben Newman
43aa2c777b Avoid calling files.realpath in IsopackCache#getSourceRoot.
It's difficult to keep track of all the factors that could affect the
output of files.realpath, so it doesn't seem feasible to replace this call
with an optimistic function.

Fortunately, it's fine if the paths returned by IsopackCache#getSourceRoot
contain symlinks, and possibly even preferable, since

  ~/.meteor/packages/<name>/<version>

is more consistent than

  ~/.meteor/packages/<name>/.<version>.<junk>++<more junk>

though the latter happens to be a symlink to the latter.
2016-10-06 12:34:04 -04:00