Commit Graph

30 Commits

Author SHA1 Message Date
Ben Newman
bd9043db20 Prefer "main" field of package.json over "module" in legacy bundle.
https://github.com/meteor/meteor/issues/10658#issuecomment-550456095
https://github.com/meteor/meteor/issues/10658#issuecomment-551870115

As usual, changes to module resolution logic need to happen in parallel in
tools/isobuild/resolver.ts and in packages/modules-runtime. However,
thanks to the modern/legacy system, it's easy to make the modules-runtime
package behave exactly the way(s) we want in the server, modern client,
and legacy client bundles.
2019-11-08 11:15:23 -05:00
Ben Newman
df4e54a80d Test that the ganalytics npm package is importable.
As reported by @arggh in this comment:
https://github.com/meteor/meteor/pull/10522#issuecomment-508908306
2019-07-06 12:38:04 -04:00
Ben Newman
5d0a1200c7 Allow .npm/package/node_modules to be compiled in Meteor packages.
When I implemented support for the "module" entry point in package.json
files for client code in #10541, I modified PackageSource#_findSources to
include files found in node_modules that need to be compiled, but my
implementation considered only "local" node_modules directories, like the
one in the application root directory, while neglecting the private
.npm/package/node_modules directories that many Meteor packages have.

This commit includes .npm/**/node_modules when _findSources is scanning a
Meteor package, which should solve issues like #10544, where a Meteor
package imports an npm package that was installed with Npm.depends, and
that npm package has a "module" field in its package.json file, pointing
to an ESM entry point module, but the ESM syntax was not appropriately
compiled, leading to parse errors like "Unexpected token export".

Before lazy compilation was introduced in Meteor 1.7 (#9983), including
the node_modules directories of Meteor packages would likely have been a
big problem for build performance, since there would be that many more
modules to compile. It's still worth making sure this change doesn't
regress build performance for other reasons, but I'm reasonably confident
lazy compilation will save us here, unless there are just too many npm
packages installed via Npm.depends that export ESM modules.
2019-05-04 18:08:49 -04:00
Ben Newman
20da99c219 Do not treat client and server directories specially in packages. (#10414)
Fixes #10393.

Bumping compiler.BUILT_BY and LINKER_CACHE_SALT because
PR #10414 changes the behavior of the build system in a subtle way that
does not automatically trigger recompilation.
2019-01-11 16:52:23 -05:00
Ben Newman
c5f6c270b7 Avoid modifying source files explicitly added by compiler plugins.
Should resolve #10233, reported by @klaussner.

Previously, if a compiler plugin called inputFile.addJavaScript multiple
times with different { path } strings, Meteor would allow importing all of
those modules at once by importing the original source module identifier,
by synthesizing a new source module containing a series of re-exports for
each of the generated modules.

Preserving this behavior is important for backwards compatibility, since
some compiler plugins still generate files like "module.ext.js" given an
input file named "module.ext", so Meteor tries to make those modules
interchangeable/synonymous.

However, if the compiler plugin explicitly calls inputFile.addJavaScript
with the original source path, then it would be a mistake to modify the
contents of that module, so Meteor will now leave the contents of that
explicit source module unmodified, rather than using it as a catch-all way
to import other generated modules.
2018-10-03 15:13:08 -04:00
Ben Newman
7dc77cdaf1 Fix importing local .json modules within Meteor packages.
The ImportScanner was mistakenly generating module.useNode() stub modules
for local .json files within Meteor packages, just because their absolute
module identifiers include "node_modules", which happens because we put
package modules under the /node_modules/meteor/<package name/ namespace.

Fix: make logic for determining when to generate module.useNode() stubs
match Module.prototype.useNode logic in modules-runtime/server.js.

Closes #10122.
2018-08-03 11:07:51 -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
b343ec8568 Fix #9305 by including default when mirroring module exports.
This functionality was added in reify@0.13.3:
10c90cd0a2

The changes to modules-test-plugin/plugin.js cause files like array.arson
to mirror array.arson.js, which exercises module.makeNsSetter(true) and
relies on default exports.
2017-12-12 13:31:28 -05:00
Ben Newman
cfc2c25d1d Update package-lock.json and shrinkwraps for modules test app. 2017-06-27 19:22:04 -04:00
Ben Newman
b80b4108b1 Fix modules tests broken by the upgrade to npm 5.0.3.
The new version of npm no longer tolerates stray packages in node_modules
that are not mentioned in package.json, such as node_modules/repl.
2017-06-27 19:22:04 -04:00
Ben Newman
a3e8cf6763 Update modules test app to Meteor 1.4.2.4. 2017-02-02 15:46:59 -05:00
Ben Newman
e3387599a2 Test lazy main modules and stray imports in modules test app. 2016-11-14 13:35:50 -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
9810562403 Test that one package can have both node_modules and Npm.depends. 2016-09-22 14:34:32 -04:00
Ben Newman
5ae53de46b Warn but do not crash when .babelrc dependencies unmet. 2016-06-06 19:55:22 -04:00
Ben Newman
bfc59dd3e3 Test that relative module identifiers work for .babelrc plugins. 2016-06-01 01:39:24 -04:00
Ben Newman
eb18d43024 Test that unprefixed .babelrc package names work too. 2016-06-01 01:39:23 -04:00
Ben Newman
398c2717e7 Use .babelrc instead of package.json in modules-test-plugin. 2016-05-20 13:09:41 -04:00
Ben Newman
1ef013f6ad Use regenerator-runtime in modules test app.
Apparently regenerator/runtime is now deprecated. I say "apparently," but
of course is my own doing.
2016-05-19 17:04:07 -04:00
Ben Newman
7c63a8e704 Allow custom Babel presets and plugins via package.json.
When the babel-compiler package is processing files, it will now read
their package.json files looking for a "babel" section with "presets" or
"plugins" fields. If found, these presets or plugins will be appended to
the existing babelOptions.presets or babelOptions.plugins arrays.

Note that no other Babel options are currently supported, and the
"babel-preset-meteor" preset cannot be removed, though additional presets
and/or plugins can be added to it. This is by design: Meteor cannot
support your configuration it uses babel-preset-meteor, at least.

The preset and/or plugin modules listed in package.json must be installed
locally somewhere such that the given file can import them. If they are
top-level identifiers, they will be prefixed with "babel-plugin-" or
"babel-preset-", the same as Babel does it. Otherwise they will be
required as-is, so that you can implement your own Babel plugins locally,
rather than always using plugins installed from npm.

See the included tests for a concrete example.

Fixes #6351.
2016-05-18 16:37:38 -04:00
Ben Newman
b16e8d5019 Implement inputFile.{getPackageJson,resolve,require} for use by plugins.
These changes allow Package.registerCompiler-style compiler plugins to
extract package.json and npm package information at compile time from the
files that the plugin processes.

This information was accessible before, but it certainly wasn't easy to
obtain it. These convenience methods should satisfy the motivation behind
2016-05-18 16:37:37 -04:00
Ben Newman
f6b75305b3 Pay attention to unibuild.arch when determining usesModules.
Fixes #6877.
2016-05-17 14:27:56 -04:00
Ben Newman
f56940b314 Fix CSS computed property tests broken by app-hiding logic. 2016-03-10 16:04:04 -05:00
Ben Newman
5c47891489 Allow custom stubs to override meteor-node-stubs.
Part of #6056.
2016-02-29 19:45:52 -05:00
Ben Newman
868c249c15 Add a test to verify #6240 has been fixed.
Closes #6240.
2016-02-16 20:58:12 -05:00
Ben Newman
5d0a8f8f0e Allow apps and packages to import "meteor/<package>/..." modules. 2016-02-11 11:45:58 -05:00
Ben Newman
ce4fda3783 Tolerate compilation errors for lazy files.
Fixes #5998.
2016-02-11 11:41:39 -05:00
Ben Newman
524970a20e Add tests of importing lazy CSS files in apps and packages. 2016-01-19 21:00:48 -05:00
Ben Newman
c631d3ac35 Bundle global npm dependencies into the modules bundle.
This allows packages to import npm packages they have not installed, with
the expectation that the app developer will provide those dependencies by
installing them into the top-level node_modules directory in the app.

For example, an app can now `npm install react` and that npm package can
be used by any package as well as by the app.
2016-01-18 19:05:43 -05:00
Ben Newman
988b8b3d0c Commit an app that tests many aspects of the module system.
Partially satisfies #5782.
2016-01-11 15:31:32 -05:00