Commit Graph

7238 Commits

Author SHA1 Message Date
Ben Newman
d8436bb635 Convert tools/fs/safe-watcher.js to TypeScript.
This completes the TypeScript conversion of the tools/fs directory. 🎉
2019-07-05 18:58:18 -04:00
Ben Newman
85d8db7f1d Fix return types of fs.{watchFile,unwatchFile}.
These methods return a StatWatcher object with various useful methods, but
@types/node apparently gets this completely wrong, assuming void.
2019-07-05 18:48:16 -04:00
Ben Newman
8958cbc5e9 Convert tools/fs/watch.js to TypeScript. 2019-07-05 17:50:20 -04:00
Ben Newman
528b549460 Convert tools/fs/optimistic.js to TypeScript. 2019-07-05 12:29:19 -04:00
Ben Newman
55bde8acb8 Improve generic types in tools/fs/files.ts. 2019-07-05 12:28:57 -04:00
Ben Newman
8259c75421 Tweaks to pacify TypeScript in tools/fs/files.ts. 2019-07-04 17:25:41 -04:00
Ben Newman
101eea015f Update meteor-node-stubs npm dependency to v1.0.0. 2019-07-04 16:36:27 -04:00
Ben Newman
6979b55dfc Update @babel/runtime to latest version in remaining test apps. 2019-07-04 16:23:12 -04:00
Ben Newman
755d0d1722 Fix outdated import of optimism package in dynamic-import test. 2019-07-04 16:18:59 -04:00
Ben Newman
6d24ab5293 Update all dependencies of dynamic-import test app. 2019-07-04 16:18:45 -04:00
Ben Newman
146e6ba1d4 Update @babel/{runtime,...} dependencies of modules test app. 2019-07-04 16:04:33 -04:00
Ben Newman
c632542a04 Update meteor-babel to version 7.5.0. 2019-07-04 15:57:25 -04:00
Ben Newman
8a409d196c Convert mini-files.js to TypeScript. 2019-07-04 14:43:51 -04:00
Ben Newman
0d99790127 Add back profiling of files.* functions. 2019-07-04 14:18:30 -04:00
Ben Newman
c8766aee77 Bring back files.withCache, with a different implementation. 2019-07-04 14:18:30 -04:00
Ben Newman
2c39986f31 Use a few more import declarations in tools/fs/files. 2019-07-04 14:18:30 -04:00
Ben Newman
0df070fc5f Use const and let more consistently in tools/fs/files. 2019-07-04 14:18:30 -04:00
Ben Newman
62a78c5860 Finish converting tools/fs/files.ts to TypeScript. 2019-07-04 14:18:29 -04:00
Ben Newman
5ed64fb1db Remove explicit .js extension from tools/fs/files imports. 2019-07-04 10:32:09 -04:00
Ben Newman
f77cbc5bcf Rename tools/fs/files.js to files.ts. 2019-07-04 10:21:00 -04:00
Ben Newman
7de2d35747 Move global types into tools/index.d.ts. 2019-07-04 10:20:57 -04:00
Ben Newman
e195440442 Fall back to package.json "main" field if "module" cannot be resolved.
The meteor/tools/isobuild/resolver.js changes are the static half of the
puzzle. The runtime half was implemented in install@0.13.0 with this
commit: 233aa75ce3
2019-07-03 12:25:05 -04:00
Ben Newman
9b01729c79 Use reify/lib/parsers/babel rather than acorn.
Acorn seems to have trouble parsing code that @babel/parser parses
successfully, such as the dist/esm.js file in markdown-to-jsx@6.10.2.
2019-07-03 10:03:28 -04:00
Ben Newman
e10a7e1523 Remove hasModuleEntryPoint logic from PackageSource#_findSources.
Now that we have the meteor.nodeModules.recompile configuration (#10603),
we don't need to guess which packages might need to be recompiled.
2019-07-03 09:07:39 -04:00
Ben Newman
f7f36bb758 Use default parser for Reify Module.prototype._compile hook.
This saves us from having to install @babel/parser in the server bundle.

There is currently a bug in Reify that prevents it from loading this
parser by default, but we can work around that on the Meteor side for now.
2019-07-02 15:31:16 -04:00
Ben Newman
8ef0326380 Keep using module.useNode() instead of bundling server node_modules.
This partially reverts commit 4dfc74197a.

Some server packages, especially those that rely on __dirname or
__filename (e.g. puppeteer), simply cannot be included in the server
bundle, and must be evaluated natively by Node.

As long as we have a Module.prototype._compile hook to process natively
evaluated modules with Reify, module.useNode() can still benefit from ESM
import/export syntax.
2019-07-02 13:15:46 -04:00
Ben Newman
0c5cb13136 Ensure all code evaluated by Node is compiled with Reify. 2019-07-02 13:15:46 -04:00
Ben Newman
2fa761bbfc Test that ESM modules can be imported from npm packages.
With appropriate meteor.nodeModules.recompile configuration, that is.
2019-07-02 11:50:51 -04:00
Ben Newman
108144c3d5 Update @babel/* dependencies of modules test app. 2019-07-02 11:41:39 -04:00
Ben Newman
4dfc74197a Avoid delegating to module.useNode() for .js and .mjs modules.
This partially reverts f0d39b86e6 by simply
including .js and .mjs modules in the server bundle, rather than
delegating to pure Node evaluation. In practice, whether or not the
package has a "module" entry point (or "type":"module") in its
package.json was not a perfect indicator of whether it should be compiled
with Reify and bundled, or left untouched and handled by Node.

Truly native modules (such as those with a .node file extension) should
always be handled by Node, so module.useNode() definitely still has a role
to play in the server bundle.
2019-07-02 11:41:39 -04:00
Ben Newman
9c120b7a06 Compile unanticipated node_modules code with Reify only, again.
In PR #10585, I tried enabling full compiler plugin processing for any
modules imported from `node_modules` that were not otherwise handled by
compiler plugins, but doing that for all packages was just too slow, not
to mention potentially dangerous for modules whose code cannot be safely
recompiled by Babel.

The primary reasons for wanting to recompile node_modules are

  1. to enable "native" ECMAScript `import`/`export` syntax (given that
     Node.js still does not fully support ESM syntax yet), and

  2. to compile standard syntax like `const`, `let`, classes, and arrow
     functions for legacy browsers.

The first goal can be achieved by compiling unanticipated `node_modules`
code with Reify, which is much faster than Babel, in part because Reify
can avoid doing any parsing when the source contains no `import` or
`export` identifiers. This compilation is also cached on disk, so its
impact should only be felt during cold builds after a `meteor reset`.

The second goal can be accomplished using the new `package.json`
configuration option `meteor.nodeModules.recompile`, which causes the
recompiled packages to be handled by the normal compiler plugins system,
so that the `ImportScanner`'s fallback compilation is not necessary.
Before this option was introduced, this recompilation behavior could be
achieved by symlinking application directories into `node_modules`, but
that always felt like an esoteric hack.
2019-07-01 09:20:06 -04:00
Ben Newman
f61ba60326 Support meteor.nodeModules.recompile package.json configuration option.
Example:

  "meteor": {
    "mainModule": ...,
    "testModule": ...,
    "nodeModules": {
      "recompile": {
        "very-modern-package": ["client", "server"],
        "alternate-notation-for-client-and-server": true,
        "somewhat-modern-package": "legacy",
        "another-package": ["legacy", "server"]
      }
    }
  }

The keys of the meteor.nodeModules.recompile configuration object are npm
package names, and the values specify for which bundles those packages
should be recompiled using the Meteor compiler plugins system, as if the
packages were part of the Meteor application.

For example, if an npm package uses const/let syntax or arrow functions,
that's fine for modern and server code, but you would probably want to
recompile the package when building the legacy bundle. To accomplish this,
specify "legacy" or ["legacy"] as the value of the package's property,
similar to somewhat-modern-package above. These strings and arrays of
strings have the same meaning as the second argument to
api.addFiles(files, where) in a package.js file.

This configuration serves pretty much the same purpose as symlinking an
application directory into node_modules, but without any symlinking:
https://forums.meteor.com/t/litelement-import-litelement-html/45042/8?u=benjamn

The meteor.nodeModules.recompile configuration currently applies to the
application node_modules directory only (not to Npm.depends dependencies
in Meteor packages). Recompiled packages must be direct dependencies of
the application.
2019-07-01 09:15:28 -04:00
Ben Newman
2dae9be561 Regression test that the graphql package can be imported. 2019-06-25 14:25:23 -04:00
Robert Lowe
f214eba7d9 Allow for METEOR_GIT_COMMIT_HASH in lieu of findGitCommitHash's execFile (#10586) 2019-06-23 11:54:47 -04:00
Ben Newman
88004d4649 Add a basic regression test of issue #10563. 2019-06-20 12:11:29 -04:00
Ben Newman
9f88fa35c3 Use full power of compiler plugins to compile unanticipated modules.
Instead of merely supporting ECMAScript module syntax via Reify, we should
really be compiling unanticipated modules (typically within node_modules)
using the same logic that the rest of the application uses.

Note: this processing applies only to .js files for now, since that's what
the ImportScanner works with.

Should help with #10563.
2019-06-20 12:11:29 -04:00
Ben Newman
a2f5e1c3e5 Make PackageSourceBatch ResourceSlot creation more reusable. 2019-06-20 12:11:29 -04:00
Ben Newman
bd89ac8d1b Merge branch 'devel' into release-1.8.2 2019-06-19 13:19:11 -04:00
Filipe Névola
ce14282304 Enable running multiple Cordova apps from same application source (#10577)
Fixes #10576.
2019-06-19 13:07:25 -04:00
zodern
d0de6e1176 Add assets to watchSet, again (#10565)
Follow-up to #10452.
2019-06-17 12:51:33 -04:00
Ben Newman
f0d39b86e6 Avoid module.useNode() for packages with "module" entry points. 2019-05-17 11:22:23 -04:00
Ben Newman
9fc6642f5a Compile unhandled JS imports for server bundles, too. 2019-05-17 10:59:17 -04:00
Ben Newman
28d74dcc9f Use Reify to compile dynamic import(...). 2019-05-15 19:12:09 -04:00
Ben Newman
d5d7413a38 Compile all unhandled node_modules client JS with Reify.
Although I hoped we could be clever about which npm packages we compiled,
there are already too many exceptions to the rules (for example, not all
npm packages that contain ESM code have a "module" entry point in
package.json).

It seems safer simply to compile all modules imported from node_modules
that have not already been handled by compiler plugins, and trust that our
disk+memory caching system will provide acceptable build performance.

Should help with #10547, #10544, and #10546.
2019-05-10 15:43:48 -04:00
Ben Newman
646fa4e3ee Consider only named packages in optimisticLookupPackageJson.
Sometimes (very rarely) an npm package may contain package.json files
other than the one found in the root package directory. For example, the
date-fns@2.0.0-alpha.27 package includes a small package.json file for
each of its functions (date-fns/someDateFn/package.json) that contains
only { sideEffects, typings }, for whatever reason. These package.json
files clearly do not serve the same purpose as date-fns/package.json, and
it would be convenient to ignore them in optimisticLookupPackageJson. The
easiest way I can see to accomplish that is to ignore package.json files
that do not have a "name" property, since any package.json file that
governs an actual package must have a name.

Should fix #10547.
2019-05-06 17:23:06 -04:00
Ben Newman
d9fd447e6f Avoid using fs.unlinkSync on directories.
Should help with #10549.
2019-05-05 19:37:45 -04:00
Ben Newman
f4af3ab2fa Backstop ESM module compilation with Reify in the ImportScanner.
Instead of compiling ESM syntax in node_modules using compiler plugins,
the ImportScanner can provide "native" support for ESM syntax by using
Reify to quickly compile just the import/export syntax in any imported
modules that were not already handled by compiler plugins.

Since this code runs every time the app is built, it should not matter
which version of Meteor was used to publish a package. Compared to the
previous implementation based on PackageSource#_findSources and unibuild
JSON files (#10545), this implementation should have far fewer
compatibility concerns, as well as being faster thanks to not processing
or compiling modules until the ImportScanner determines that they are
actually imported.

Though the number of files that get compiled by this system should be
relatively small for now, to maintain good performance, the results of the
compilation are cached on disk and in memory.
2019-05-05 19:10:13 -04:00
Ben Newman
72c704bcae Revert using _findSources to scan .npm/package/node_modules.
After much thought, I believe this implementation (#10545) would have
caused severe compatibility problems when using packages published with
earlier versions of Meteor in a Meteor 1.8.2 app, or when publishing
packages with Meteor 1.8.2 for use with earlier Meteor versions.

Specifically, this implementation relied on writing the additional
.npm/package/node_modules resources found by _findSources into the
unibuild JSON file(s), and there just wasn't any good way to make sure the
new JSON format could be safely consumed by previous Meteor versions.

Even if we found a way to hide the new resources from older versions of
Meteor, perhaps by putting them in a new/different property of the
unibuild JSON file, packages published with older Meteor versions might
try to load an npm package with a "module" field without realizing the
code must be compiled, which would likely cause a syntax error in Meteor
1.8.2, since the "module" field always gets preference over the "main"
field of package.json (in Meteor 1.8.2).
2019-05-05 19:03:30 -04:00
zodern
da323022b1 Do not remove source map url comments in public files (#10525) 2019-05-05 15:23:13 -05:00
Ben Newman
683d23cdee Bump compiler.BUILT_BY and LINKER_CACHE_SALT to force rebuild. 2019-05-04 18:08:49 -04:00