@meteorjs/rspack 2.1.0 → 2.2.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/localDependenciesHelpers.js +8 -8
- package/lib/test.js +2 -2
- package/package.json +1 -1
- package/plugins/RequireExtenalsPlugin.js +25 -4
- package/rspack.config.js +18 -5
|
@@ -20,7 +20,7 @@ function extractLocalDependencies(configFilePath) {
|
|
|
20
20
|
|
|
21
21
|
// Parse the file into an AST
|
|
22
22
|
const ast = swc.parseSync(content, {
|
|
23
|
-
syntax: 'ecmascript',
|
|
23
|
+
syntax: /\.[mc]?tsx?$/.test(configFilePath) ? 'typescript' : 'ecmascript',
|
|
24
24
|
dynamicImport: true,
|
|
25
25
|
target: 'es2020',
|
|
26
26
|
});
|
|
@@ -30,10 +30,10 @@ function extractLocalDependencies(configFilePath) {
|
|
|
30
30
|
let modulePath = null;
|
|
31
31
|
|
|
32
32
|
// Handle require() calls: require('./plugin')
|
|
33
|
-
if (node.type === 'CallExpression' &&
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (node.type === 'CallExpression' &&
|
|
34
|
+
node.callee.type === 'Identifier' &&
|
|
35
|
+
node.callee.value === 'require' &&
|
|
36
|
+
node.arguments.length > 0) {
|
|
37
37
|
const arg = node.arguments[0];
|
|
38
38
|
if (arg.expression?.type === 'StringLiteral') {
|
|
39
39
|
modulePath = arg.expression.value;
|
|
@@ -42,8 +42,8 @@ function extractLocalDependencies(configFilePath) {
|
|
|
42
42
|
|
|
43
43
|
// Handle dynamic import() calls: import('./plugin')
|
|
44
44
|
if (node.type === 'CallExpression' &&
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
node.callee.type === 'Import' &&
|
|
46
|
+
node.arguments.length > 0) {
|
|
47
47
|
const arg = node.arguments[0];
|
|
48
48
|
if (arg.expression?.type === 'StringLiteral') {
|
|
49
49
|
modulePath = arg.expression.value;
|
|
@@ -163,7 +163,7 @@ function resolveLocalModule(modulePath, configDir, projectDir) {
|
|
|
163
163
|
const resolvedReal = fs.realpathSync(resolvedPath);
|
|
164
164
|
const projectReal = fs.realpathSync(projectDir);
|
|
165
165
|
|
|
166
|
-
const isWithinProject =
|
|
166
|
+
const isWithinProject =
|
|
167
167
|
resolvedReal === projectReal ||
|
|
168
168
|
resolvedReal.startsWith(projectReal + path.sep);
|
|
169
169
|
const hasNodeModulesSegment = resolvedReal.split(path.sep).includes('node_modules');
|
package/lib/test.js
CHANGED
|
@@ -74,14 +74,14 @@ const generateEagerTestFile = ({
|
|
|
74
74
|
exclude: ${excludeFoldersRegex.toString()},
|
|
75
75
|
mode: 'eager',
|
|
76
76
|
});
|
|
77
|
-
ctx.keys().filter((k) => {
|
|
77
|
+
await Promise.all(ctx.keys().filter((k) => {
|
|
78
78
|
${
|
|
79
79
|
excludeMeteorIgnoreRegex
|
|
80
80
|
? `// Only exclude based on *relative* path segments.
|
|
81
81
|
return !MeteorIgnoreRegex.test(k);`
|
|
82
82
|
: "return true;"
|
|
83
83
|
}
|
|
84
|
-
}).
|
|
84
|
+
}).map(ctx));
|
|
85
85
|
${
|
|
86
86
|
extraEntry
|
|
87
87
|
? `const extra = import.meta.webpackContext('${toPosix(path.dirname(
|
package/package.json
CHANGED
|
@@ -172,8 +172,24 @@ class RequireExternalsPlugin {
|
|
|
172
172
|
// 2) Re-load existing requires from disk on every run
|
|
173
173
|
const existing = this._readExistingRequires();
|
|
174
174
|
|
|
175
|
-
// 2a) Compute the *current* externals in this build
|
|
176
|
-
|
|
175
|
+
// 2a) Compute the *current* externals in this build.
|
|
176
|
+
// Only module names are needed, so start from `all: false` instead of
|
|
177
|
+
// serializing the whole stats object (chunks, assets, reasons, ...)
|
|
178
|
+
// on every compilation — a fixed cost per rebuild that grows with app
|
|
179
|
+
// size. `cachedModules: true` keeps unchanged modules in the list on
|
|
180
|
+
// incremental rebuilds, so their requires are not wrongly removed.
|
|
181
|
+
// `orphanModules: true` is required in production: module
|
|
182
|
+
// concatenation absorbs the externals' importers, marking the
|
|
183
|
+
// external modules themselves as orphans, and without this flag
|
|
184
|
+
// they vanish from the list entirely — which stripped every
|
|
185
|
+
// mirrored require (meteor/*, Blaze .html) from the meteor entry.
|
|
186
|
+
// See meteor/meteor#14568.
|
|
187
|
+
const info = stats.toJson({
|
|
188
|
+
all: false,
|
|
189
|
+
modules: true,
|
|
190
|
+
cachedModules: true,
|
|
191
|
+
orphanModules: true,
|
|
192
|
+
});
|
|
177
193
|
const current = new Set();
|
|
178
194
|
for (const m of info.modules) {
|
|
179
195
|
const matchInfo = this._isExternalModule(m.name);
|
|
@@ -497,17 +513,22 @@ class RequireExternalsPlugin {
|
|
|
497
513
|
|
|
498
514
|
_readExistingRequires() {
|
|
499
515
|
const existing = new Set();
|
|
516
|
+
// Generated Rspack bridge imports are not managed externals. Relative
|
|
517
|
+
// imports such as Blaze HTML files still belong to this plugin.
|
|
518
|
+
const isRspackBridgeImport = (modulePath) =>
|
|
519
|
+
typeof modulePath === 'string' &&
|
|
520
|
+
/(?:^|[/\\])[^/\\]*-rspack\.(?:js|cjs)$/.test(modulePath);
|
|
500
521
|
try {
|
|
501
522
|
const content = fs.readFileSync(this.filePath, 'utf-8');
|
|
502
523
|
// Check for require statements
|
|
503
524
|
let match;
|
|
504
525
|
while ((match = STANDALONE_REQUIRE_REGEX.exec(content)) !== null) {
|
|
505
|
-
existing.add(match[1]);
|
|
526
|
+
if (!isRspackBridgeImport(match[1])) existing.add(match[1]);
|
|
506
527
|
}
|
|
507
528
|
|
|
508
529
|
// Also check for import statements (used in the new format)
|
|
509
530
|
while ((match = STANDALONE_IMPORT_REGEX.exec(content)) !== null) {
|
|
510
|
-
existing.add(match[1]);
|
|
531
|
+
if (!isRspackBridgeImport(match[1])) existing.add(match[1]);
|
|
511
532
|
}
|
|
512
533
|
} catch {
|
|
513
534
|
// ignore if file missing or unreadable
|
package/rspack.config.js
CHANGED
|
@@ -101,8 +101,13 @@ function createCacheStrategy(
|
|
|
101
101
|
type: "persistent",
|
|
102
102
|
storage: {
|
|
103
103
|
type: "filesystem",
|
|
104
|
+
// Include the mode in the directory (not just the version):
|
|
105
|
+
// rspack invalidates a persistent cache on version mismatch, so
|
|
106
|
+
// sharing one directory between development and production would
|
|
107
|
+
// wipe the cache on every `meteor run` <-> `meteor build` switch
|
|
108
|
+
// instead of keeping both warm. See meteor/meteor#14568.
|
|
104
109
|
directory: `node_modules/.cache/rspack/${
|
|
105
|
-
[buildContext, side].filter(Boolean).join('-') || 'default'
|
|
110
|
+
[buildContext, side, mode].filter(Boolean).join('-') || 'default'
|
|
106
111
|
}`,
|
|
107
112
|
},
|
|
108
113
|
...(buildDependencies.length > 0 && {
|
|
@@ -401,7 +406,11 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
401
406
|
cacheStrategy = createCacheStrategy(
|
|
402
407
|
mode,
|
|
403
408
|
(Meteor.isClient && "client") || "server",
|
|
404
|
-
|
|
409
|
+
// buildContext must be passed here too: this reassignment is the
|
|
410
|
+
// effective cache strategy, and omitting it made the cache directory
|
|
411
|
+
// collide across build contexts (e.g. custom METEOR_LOCAL_DIR setups).
|
|
412
|
+
// See meteor/meteor#14568.
|
|
413
|
+
{ projectConfigPath, configPath, buildContext }
|
|
405
414
|
);
|
|
406
415
|
|
|
407
416
|
// Determine run point
|
|
@@ -488,7 +497,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
488
497
|
...(Meteor.isBlazeEnabled && {
|
|
489
498
|
externals: /\.html$/,
|
|
490
499
|
isEagerImport: (module) => module.endsWith(".html"),
|
|
491
|
-
...(isProd && {
|
|
500
|
+
...((isProd || (isTest && isClient)) && {
|
|
492
501
|
lastImports: [`./${outputFilename}`],
|
|
493
502
|
}),
|
|
494
503
|
}),
|
|
@@ -806,8 +815,12 @@ module.exports = async function (inMeteor = {}, argv = {}) {
|
|
|
806
815
|
isDevEnvironment || isNative || isTest
|
|
807
816
|
? "source-map"
|
|
808
817
|
: "hidden-source-map",
|
|
809
|
-
|
|
810
|
-
|
|
818
|
+
// Apply the persistent cache to production builds too (the client
|
|
819
|
+
// config always has it); previously `meteor build` recompiled the
|
|
820
|
+
// entire server bundle cold every time. Eager server test builds are
|
|
821
|
+
// still excluded, since their generated entry changes on every run.
|
|
822
|
+
// See meteor/meteor#14568.
|
|
823
|
+
...(!(isTest && isTestEager) && cacheStrategy),
|
|
811
824
|
...lazyCompilationConfig,
|
|
812
825
|
...loggingConfig,
|
|
813
826
|
};
|