Commit Graph

6969 Commits

Author SHA1 Message Date
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
Ben Newman
dbdadc1b11 Avoid using "browser" field of package.json for inputFile.resolve.
Fixes #9870.
2018-05-12 12:43:54 -04:00
Ben Newman
1b17025cd4 Tolerate missing files in Builder#_ensureDirectory.
Fixes #9882.
2018-05-12 11:40:01 -04:00
Ben Newman
1892633dba Avoid unnecessary files.{rm_recursive,symlink} in symlinkWithOverwrite.
When we copy node_modules directories during rebuilds, we try to create
symlinks instead of doing a full recursive copy. Very often, however, the
symlinks already exist, and they point to the right location already, so
we can avoid recreating them for even better performance.

Another optimization identified by using the qualia:profile package
created by @veered: https://atmospherejs.com/qualia/profile
2018-05-10 14:27:44 -04:00
Ben Newman
b7579ad100 Update modules test app to Meteor 1.7-rc.5. 2018-05-09 19:12:13 -04:00
Ben Newman
a8b6accb11 Set .babel-cache directory correctly for command-line tool.
This depends on new functionality in meteor-babel@7.0.0-beta.46-3:
d5d2bbf81e
dea6465daf
2018-05-09 16:16:05 -04:00
Ben Newman
81248867aa Update meteor-node-stubs to version 0.4.1.
This only affects newly created applications for now, but developers can
update to the latest meteor-node-stubs by running

  meteor npm install meteor-node-stubs@latest

https://github.com/meteor/node-stubs/issues/15
2018-05-08 12:56:03 -04:00
Ben Newman
7baaf19020 Report an error when meteor.mainModule cannot be resolved.
https://github.com/meteor/meteor/pull/9826#issuecomment-387172568
2018-05-07 18:48:38 -04:00
Ben Newman
a0842f70f6 Expose Cordova assets with and without /__cordova URL prefix.
Related to #9776.
Fixes #9782.
2018-05-03 19:12:01 -04:00
Ben Newman
0d6fbba203 Make sure minimal apps depend directly on meteor package.
All Meteor packages implicitly depend on the meteor package, and the
meteor-base package implies the meteor package for most Meteor apps, but
the new minimal skeleton does not use meteor-base, so minimal Meteor apps
were not directly depending on the meteor package.

The only reason this mattered was that the meteor package registers a
default compiler plugin for CSS files, and compiler plugins only apply if
an app or package directly depends on them (or depends on a package that
implies them, such as meteor-base).

In other words, this change reenables support for raw CSS files for
minimal apps.
2018-05-01 15:15:00 -04:00
Ben Newman
d6c8a96bda Refine URL prefix logic to exclude just web.browser[.legacy].
This still leaves web.cordova as the only architecture whose URLs get
prefixed (with /__cordova/), but the implementation better reflects the
special status of web.browser and web.browser.legacy as architectures that
the webapp and dynamic-import packages understand how to disambiguate
using the isModern test from the modern-browsers package.
2018-04-29 10:06:08 -04:00
Ben Newman
7e5e5b9fa1 Restrict URL prefixing to web.cordova URLs.
Now that webapp can differentiate between modern and legacy browsers when
serving static files, without relying on URL prefixes, in principle we
shouldn't have to use prefixes for any URLs except Cordova ones.
2018-04-29 09:58:08 -04:00
Ben Newman
229fc24aad Go back to prefixing asset URLs with /__{browser.legacy,cordova,...}.
https://github.com/meteor/meteor/pull/9776#issuecomment-385180806
2018-04-28 11:20:25 -04:00
Ben Newman
74a55ff107 Fix addAsset tests now that /__browser.legacy/ prefix no longer used. 2018-04-27 12:47:35 -04:00
Kevin Newman
06f9f78277 Avoid the need to rewrite URLs in appcache, by avoiding adding the prefix at build time for assets 2018-04-27 09:47:21 -04:00