mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
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.
69 lines
1.9 KiB
JavaScript
69 lines
1.9 KiB
JavaScript
import { invariant } from "ts-invariant";
|
|
|
|
invariant(
|
|
typeof process.versions.node === "string",
|
|
"Meteor plugins should only run in Node.js",
|
|
);
|
|
|
|
invariant(
|
|
require.resolve("ts-invariant"),
|
|
"/node_modules/meteor/meteor-test-plugin/node_modules/ts-invariant/lib/invariant.js",
|
|
);
|
|
|
|
// This verifies that babel-plugin-transform-strict-mode is enabled.
|
|
let expected;
|
|
try {
|
|
console.log(arguments.callee.toString());
|
|
} catch (e) {
|
|
expected = e;
|
|
}
|
|
invariant(expected instanceof TypeError);
|
|
invariant(/callee/.test(expected.message), expected.message);
|
|
|
|
Plugin.registerCompiler({
|
|
extensions: ["arson"]
|
|
}, () => new ArsonCompiler);
|
|
|
|
class ArsonCompiler {
|
|
// This verifies that the babel-plugin-transform-class-properties plugin
|
|
// enabled by package.json is respected.
|
|
expectedName = "compile-arson";
|
|
|
|
processFilesForTarget(inputFiles) {
|
|
invariant(this.expectedName === "compile-arson", this.expectedName);
|
|
invariant(inputFiles.length > 0);
|
|
|
|
let vueCheckCount = 0;
|
|
|
|
inputFiles.forEach(file => {
|
|
const arson = file.require("arson");
|
|
let encoded = file.getContentsAsString();
|
|
const decoded = arson.decode(encoded);
|
|
decoded.self = decoded;
|
|
encoded = arson.encode(decoded);
|
|
|
|
file.addJavaScript({
|
|
path: file.getPathInPackage() + ".js",
|
|
data: [
|
|
'module.exportDefault(require("arson").decode(',
|
|
" " + JSON.stringify(encoded),
|
|
"));",
|
|
""
|
|
].join("\n"),
|
|
hash: file.getSourceHash()
|
|
});
|
|
|
|
if (file.getPackageName() === "modules-test-plugin") {
|
|
const vueCompilerId = file.resolve("vue-template-compiler");
|
|
// Make sure resolution does not use the "browser" field of
|
|
// vue-template-compiler/package.json.
|
|
const base = vueCompilerId.split("/").pop();
|
|
invariant(base === "index.js", base);
|
|
++vueCheckCount;
|
|
}
|
|
});
|
|
|
|
invariant(vueCheckCount > 0);
|
|
}
|
|
}
|