Commit Graph

6983 Commits

Author SHA1 Message Date
Ben Newman
1cd91b5409 Cache File#getPrelinkedOutput in linker.js.
Another big win thanks to optimistic caching.
2018-06-30 11:44:25 -04:00
Ben Newman
1ed095c36d Cache minified CSS in minifyCssFiles rather than relying on plugins.
Static CSS gets merged in development as well as production by
ClientTarget#minifyCss; the only difference is that the CSS is also
minified in production. This development-time merging is especially
expensive because it involves source maps, and happens on every rebuild of
the app. That's why ClientTarget#minifyCss consistently shows up in
METEOR_PROFILE output for rebuilds.

The standard-minifier-css package tries to cache the merging based on the
hashes of the input files:
8a562523a4/packages/standard-minifier-css/plugin/minify-css.js (L58-L62)

However, not all CSS minifier plugins use a strategy like this, and
https://atmospherejs.com/juliancwirko/postcss is an increasingly popular
one that does not.

The time has come to move this caching logic into the Meteor build tool
itself, so that CSS minifier plugins no longer have to worry about basic
caching, and everyone who uses CSS minifiers with Meteor will benefit.

This implementation leverages Meteor's powerful optimistic caching
techniques to keep previous results in memory only as long as the minifier
object remains reachable.
2018-06-30 11:34:40 -04:00
Ben Newman
7b6fd0ee10 Let buildmessage.markBoundary take optional context argument.
Since markBoundary is essentially creating a bound wrapper function,
there's no reason we can't actually bind the function to a specific
context (this) object at the same time, instead of having to bind the
function and then wrap it with buildmessage.markBoundary.
2018-06-30 11:02:02 -04:00
Ben Newman
8b04c25390 Emit multiple meteorInstall calls for distinct meteorInstallOptions.
I recently noticed a bug whereby modules transferred from the application
bundle to the modules bundle would lose their application-specific import
extensions, since all modules installed in the modules bundle have only
.js and .json as import extensions, matching default Node behavior.

This commit fixes that bug by emitting one meteorInstall call per distinct
meteorInstallOptions object. This logic would work if every module had a
different meteorInstallOptions object, but in practice the modules bundle
should end up with exactly two meteorInstall calls, because a single
options object is shared among all modules from the same source batch.
2018-06-28 18:07:34 -04:00
Ben Newman
ae609e0d96 Improve file.imported logic in the ImportScanner. 2018-06-28 14:12:24 -04:00
Ben Newman
ea69f4ece1 Make unchecked pending errors fatal in OutputResource#_get. 2018-06-26 14:37:09 -04:00
Ben Newman
cf804f22e4 Do not return files with errors from ImportScanner#getOutputFiles.
This works whether or not the file object is a JsOutputResource.
2018-06-26 14:25:32 -04:00
Ben Newman
59eecf9dad Ensure at least one error reported when lazyFinalizer fails. 2018-06-26 14:24:16 -04:00
Ben Newman
5abc8fbdd2 Always record ResourceSlot errors in InputFile#addError. 2018-06-26 13:54:09 -04:00
Ben Newman
9f7ef9cdb1 Fix compiler plugins caching self-test for the stylus plugin. 2018-06-26 13:09:37 -04:00
Ben Newman
de3fef17ca Stop eagerly forcing compilation of lazy CssOutputResources.
This should be a better fix for the problem I tried to fix with
479e505d71.

If we're going to be using compileOneFileLater by default, that's what we
should be testing in the compiler plugins self-tests.
2018-06-26 13:09:28 -04:00
Ben Newman
f7f3d34181 Mark non-isRoot files lazy in MultiFileCachingCompiler.
The concept of a "root" file is specific to MultiFileCachingCompiler, so
we need to normalize it into a representation that makes sense to the rest
of the compiler plugin system.

Should help with #10014.
2018-06-26 13:09:14 -04:00
Ben Newman
9f06a6f6c5 Allow resolving index.* modules with non-.js file extensions. (#10027)
The previous commit enabled importing index.* modules at runtime, but
unfortunately the build-time Resolver logic also needed updating, which
will require a new Meteor release.
2018-06-25 14:36:45 -04:00
Ben Newman
281a849432 Be more defensive about lazy stylesheets that fail to compile.
I should have paid more attention to @abernix's analysis here, as it was
exactly right: https://github.com/meteor/meteor/pull/9983#issuecomment-397240476

cc @pagesrichie
2018-06-16 11:02:29 -04:00
Ben Newman
ce34a60387 Source maps and minification for dynamic CSS modules. (#9998)
When a CSS (or compiled-to-CSS) module is lazy (e.g., in `imports/` or
`node_modules`) and not otherwise imported by another CSS module, Meteor
automatically turns it into a JS module so that it can be handled by the
`ImportScanner`, and imported dynamically by other JS modules.

Until now, there were two problems with CSS handled in this way: it did
not have proper source maps, and the CSS text was not minified in
production.

This commit introduces a special minification step for dynamic CSS, which
must take place before we create the dynamic JS module. Waiting for the
usual minification of CSS would be a mistake, since that happens long
after the `ImportScanner` and `Linker` have already processed JavaScript
modules. Modifying the contents of JS modules at that point would be
impossible without recomputing source maps, etc.

Since the JS module dynamically creates a `<style>` tag and appends it to
the `<head>` of the document, the code of the JS module has no meaningful
relationship to the lines of CSS text that are actually evaluated by the
browser, so it would be a mistake to give the JS module the same source
map as the original CSS resource.

Instead, when there is a source map, we write it out as an asset that can
be requested at runtime, and append a sourceMappingURL comment to the end
of the CSS text referring to this asset URL. Note that this only happens
in development, which makes sense because minification in production
invalidates the source map, and we don't want to expose source code in
production anyway.
2018-06-15 16:10:26 -04:00
Ben Newman
a1f4e94c59 Merge branch 'master' into devel 2018-06-13 19:51:26 -04:00
Ben Newman
ea394be6e8 Don't ignore tests/ directory if meteor.testModule defined.
According to traditional Meteor file loading rules, tests/ directories are
completely ignored: https://guide.meteor.com/structure.html#special-directories

However, if you specify a meteor.testModule in your package.json that
refers to a file inside a tests/ directory, Meteor should permit modules
to be loaded from tests/, as well as any modules that are imported by the
meteor.testModule entry point.

Fixes #9991.
2018-06-13 17:59:40 -04:00
Ben Newman
85a66caa89 Merge branch 'master' into devel 2018-06-13 15:30:10 -04:00
Ben Newman
9b28ece2ba Bump @babel/runtime version in starter application skeletons. 2018-06-13 14:21:20 -04:00
Rob Fallows
a9af151df9 Update default and --minimal app skeletons. Fixes #9961 (#9977) 2018-06-13 13:22:39 -04:00
Ben Newman
2b505936b4 Tolerate async lazyFinalizer functions when immediately invoked. 2018-06-12 11:02:37 -04:00
Ben Newman
baa6108f0c Stop representing JS compilation errors as file objects. 2018-06-11 21:55:50 -04:00
Ben Newman
df712b6b7a Allow lazyFinalizer functions to return Promises. 2018-06-11 19:35:42 -04:00
Ben Newman
79cb14afbe Avoid accessing .data in ImportScanner until files get scanned. 2018-06-11 17:18:08 -04:00
Ben Newman
6f93bd1def Use custom CssOutputResource class in ResourceSlot#addStylesheet. 2018-06-11 17:18:08 -04:00
Ben Newman
98ed767522 Use custom JsOutputResource class in ResourceSlot#addJavaScript. 2018-06-11 16:45:32 -04:00
Ben Newman
9cc739078c Support lazy compilation of inputFile.add{JavaScript,Stylesheet,...} resources.
One limitation of Meteor's current compiler plugins system is that every
file we *might* use must be compiled before we know whether it *will* be
used by the application (which is something we only find out when we later
run the `ImportScanner`). More specifically, when inputFile.addJavaScript
is called, any information relevant to the current file must already have
been computed, even if the file will never be used.

This commit begins the process of supporting a lazy version of the
`inputFile.addJavaScript` method. For consistency, this interface is
supported by other methods like `inputFile.addStylesheet`, though it may
not make as much sense for non-JavaScript resources.

In this very basic initial implementation, the `lazyFinalizer` function is
called immediately, so that subsequent code can keep pretending that all
relevant information was eagerly provided.

The next step will be waiting to call `lazyFinalizer` until the last
possible moment, so that we can skip a potentially huge amount of
unnecessary compilation time.
2018-06-11 11:02:19 -04:00
Rob Fallows
a52b462f55 Update default and --minimal app skeletons. Fixes #9961 (#9977) 2018-06-11 09:15:39 -04:00
Ben Newman
f0e04facd2 Update dynamic-import test app to Meteor 1.7.0.1. 2018-06-07 11:36:34 -04:00
Ben Newman
38f570abc0 Ensure npm scripts find correct meteor executable. (#9941)
In my local development environment, the `meteor` command resolves to my
Meteor checkout, and I use `~/.meteor/meteor` explicitly when I want to run
a released version of Meteor.

If I run

  ~/.meteor/meteor npm test

and the `package.json` file defines an npm `test` script that refers to
`meteor`, in my environment this `meteor` won't be the same as the one I
used to run `~/.meteor/meteor npm test`, which can introduce weirdness
such as pinning the versions of packages in `meteor/packages/non-core`,
and all the usual Meteor version inconsistency risks.

This commit fixes that problem by prepending the directory that contains
the `meteor` (or `meteor.bat`) executable to the `PATH` before running
`meteor npm ...` commands.
2018-06-05 13:06:51 -04:00
Ben Newman
6b7df3fb0d When checking for existing builds, tolerate web.browser.legacy better.
This is a follow-up to b4a68e99c1, which
allowed obtaining a simplified list of build architectures (without
web.browser.legacy) by calling isopack.buildArchitectures(true), which was
helpful for matching existing builds of packages that were published
before the web.browser.legacy architecture was introduced in Meteor 1.7.

Now that some packages have been published with the web.browser.legacy
architecture as part of the Meteor 1.7 release, it's important to try
matching the full unsimplified list of architectures, while still falling
back to the simplified list for other packages.
2018-05-29 18:13:19 -04:00
Ben Newman
7f9706d0f2 Revert "Stop scanning node_modules directories in PackageSource#_findSources. (#9825)"
This reverts commit c5302bb2ba.

Based on conversation with @KoenLav, it seems this optimization was more
of a breaking change than anticipated, and the workaround of creating a
symbolic link to induce compilation is not just annoying on Windows but
also does not satisfy the goal of being able to import from node_modules
(as before) rather than importing via the symbolic link.

We will need to revisit this pitfall in Meteor 1.7.1, but it's important
to unbreak it ASAP in Meteor 1.7.0.1 (since 1.7 is unfortunately final).

https://github.com/meteor/meteor/pull/9826#issuecomment-392596129
https://github.com/mozfet/meteor-autoform-materialize/issues/43

For apps that are accidentally compiling too many LESS or SCSS files, the
recommended workaround (for now) is to add the offending directories
and/or files to a .meteorignore file.
2018-05-29 16:20:30 -04:00
Ben Newman
0fcf29eaee Update modules test app to Meteor 1.7. 2018-05-27 20:38:01 -04:00
Ben Newman
ad4f30c684 Lift process.env access to module scope.
https://github.com/meteor/meteor/pull/9911#pullrequestreview-123587003
2018-05-27 11:13:47 -04:00
Christian Klaussner
797f9ce78e Allow METEOR_FILE_WATCH_COALESCE to override file watcher delay (#9911) 2018-05-27 11:11:36 -04:00
Ben Newman
6407e4dafb Update meteor-babel to version 7.0.0-beta.49-1.
Also switching from babelOptions.sourceMap to babelOptions.sourceMaps,
finally: https://babeljs.io/docs/usage/api/#options
2018-05-25 18:43:13 -04:00
Ben Newman
5ac27341f7 Update @babel/runtime for new app skeletons to 7.0.0-beta.48. 2018-05-24 23:04:42 -04:00
Ben Newman
e3bac92c82 Strip //# sourceMappingURL comments for files without source maps.
https://github.com/meteor/meteor/issues/9894#issuecomment-391101074

Fixes #9894.
2018-05-23 19:19:05 -04:00
Ben Newman
d64e87b852 Bump LINKER_CACHE_SALT and compiler.BUILT_BY for good measure. 2018-05-16 20:43:26 -04:00
Ben Newman
a76e6da686 Update help text about minimal starter app to deemphasize emptiness. 2018-05-16 17:47:19 -04:00
Ben Newman
af9a0e183f Include "Learn Meteor!" links in minimial starter app HTML. 2018-05-16 17:31:59 -04:00
Ben Newman
10e69ee84d Include actual CSS in default starter app. 2018-05-16 17:31:37 -04:00
Ben Newman
c88b888275 Demonstrate basic server-side rendering in minimal starter app.
Now that the meteor/server-render package is lazy on the client, it adds
no weight to the client JavaScript bundle unless imported.
2018-05-16 17:22:12 -04:00
Ben Newman
c29b191a42 Make the minimal starter application follow best practices. 2018-05-16 15:20:38 -04:00
Ben Newman
b830665a1f Expose App.settings in mobile-config.js rather than Settings.
Follow-up to #9873.
2018-05-16 12:45:07 -04:00
Jan Owsiany
b35aab6c55 Expose Meteor settings inside mobile-config.js (#9873) 2018-05-16 12:22:38 -04:00
Ben Newman
124e334a95 Update meteor-babel and @babel/runtime to version 7.0.0-beta.47. 2018-05-16 12:16:28 -04:00
Ben Newman
8273eb84e3 Avoid calling files.readlink if target not a symbolic link. 2018-05-14 14:17:46 -04:00
zodern
903cd3c8b9 Fix creating symlinks on Windows April 2018 Update (#9887) 2018-05-14 11:20:56 -04:00
Ben Newman
5aab6d2a12 Avoid caching Resolver on PackageSourceBatch, but cache node_modules paths.
Now that getResolver takes options, it seems inappropriate to cache only
the first resolver created, since multiple resolvers might be created with
different options.

Fortunately, caching Resolver objects is not strictly necessary (even for
performance), since Resolver.getOrCreate already caches based on the
options it receives.

The only other meaningful work PackageSourceBatch#getResolver was doing
was computing the nodeModulesPaths option, so I've cached that.
2018-05-12 13:29:09 -04:00