@meteorjs/rspack 0.0.64 → 0.0.66

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.
@@ -84,18 +84,35 @@ function setCache(
84
84
  * - Optional extras let you block non-core modules too
85
85
  */
86
86
  function makeWebNodeBuiltinsAlias(extras = []) {
87
- // Strip potential 'node:' prefixes then add both forms
87
+ // Node core list, normalized (strip `node:` prefix)
88
88
  const core = new Set(builtinModules.map((m) => m.replace(/^node:/, "")));
89
89
 
90
+ // browser-safe allowlist (these we *don't* mark as false)
91
+ const allowlist = new Set([
92
+ "process",
93
+ "buffer",
94
+ "util",
95
+ "events",
96
+ "path",
97
+ "stream",
98
+ "assert",
99
+ "assert/strict",
100
+ ]);
101
+
90
102
  const names = new Set();
91
103
  for (const m of core) {
92
- names.add(m); // e.g. 'fs'
93
- names.add(`node:${m}`); // e.g. 'node:fs'
104
+ // Add both 'fs' and 'node:fs' variants
105
+ names.add(m);
106
+ names.add(`node:${m}`);
94
107
  }
95
108
  for (const x of extras) names.add(x);
96
109
 
97
- // Map every name to false (causes hard error if imported)
98
- return Object.fromEntries([...names].map((m) => [m, false]));
110
+ // Everything except the allowlist gets mapped to false
111
+ const entries = [...names]
112
+ .filter((m) => !allowlist.has(m.replace(/^node:/, "")))
113
+ .map((m) => [m, false]);
114
+
115
+ return Object.fromEntries(entries);
99
116
  }
100
117
 
101
118
  /**
package/lib/test.js CHANGED
@@ -8,14 +8,15 @@ const { createIgnoreRegex, createIgnoreGlobConfig } = require("./ignore.js");
8
8
  * @param {boolean} options.isAppTest - Whether this is an app test
9
9
  * @param {string} options.projectDir - The project directory
10
10
  * @param {string} options.buildContext - The build context
11
- * @param {string[]} options.entries - Array of ignore patterns
11
+ * @param {string[]} options.ignoreEntries - Array of ignore patterns
12
12
  * @returns {string} The path to the generated file
13
13
  */
14
14
  const generateEagerTestFile = ({
15
15
  isAppTest,
16
16
  projectDir,
17
17
  buildContext,
18
- entries = [],
18
+ ignoreEntries: inIgnoreEntries = [],
19
+ prefix: inPrefix = '',
19
20
  }) => {
20
21
  const distDir = path.resolve(projectDir, ".meteor/local/test");
21
22
  if (!fs.existsSync(distDir)) {
@@ -29,7 +30,7 @@ const generateEagerTestFile = ({
29
30
  "**/public/**",
30
31
  "**/private/**",
31
32
  `**/${buildContext}/**`,
32
- ...entries,
33
+ ...inIgnoreEntries,
33
34
  ];
34
35
 
35
36
  // Create regex from ignore entries
@@ -37,7 +38,10 @@ const generateEagerTestFile = ({
37
38
  createIgnoreGlobConfig(ignoreEntries)
38
39
  );
39
40
 
40
- const filename = isAppTest ? "eager-app-tests.mjs" : "eager-tests.mjs";
41
+ const prefix = inPrefix && `${inPrefix}-` || '';
42
+ const filename = isAppTest
43
+ ? `${prefix}eager-app-tests.mjs`
44
+ : `${prefix}eager-tests.mjs`;
41
45
  const filePath = path.resolve(distDir, filename);
42
46
  const regExp = isAppTest
43
47
  ? "/\\.app-(?:test|spec)s?\\.[^.]+$/"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteorjs/rspack",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "description": "Configuration logic for using Rspack in Meteor projects",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -9,6 +9,7 @@
9
9
  "dependencies": {
10
10
  "fast-deep-equal": "^3.1.3",
11
11
  "ignore-loader": "^0.1.2",
12
+ "node-polyfill-webpack-plugin": "^4.1.0",
12
13
  "webpack-merge": "^6.0.1"
13
14
  },
14
15
  "peerDependencies": {
package/rspack.config.js CHANGED
@@ -3,6 +3,7 @@ const fs = require('fs');
3
3
  const { inspect } = require('node:util');
4
4
  const path = require('path');
5
5
  const { merge } = require('webpack-merge');
6
+ const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
6
7
 
7
8
  const { cleanOmittedPaths, mergeSplitOverlap } = require("./lib/mergeRulesSplitOverlap.js");
8
9
  const { getMeteorAppSwcConfig } = require('./lib/swc.js');
@@ -136,7 +137,7 @@ function createSwcConfig({
136
137
  return {
137
138
  test: /\.(?:[mc]?js|jsx|[mc]?ts|tsx)$/i,
138
139
  exclude: /node_modules|\.meteor\/local/,
139
- loader: 'builtin:swc-loader',
140
+ loader: "builtin:swc-loader",
140
141
  options: swcConfig,
141
142
  };
142
143
  }
@@ -217,6 +218,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
217
218
  const isTestModule = !!Meteor.isTestModule;
218
219
  const isTestEager = !!Meteor.isTestEager;
219
220
  const isTestFullApp = !!Meteor.isTestFullApp;
221
+ const isTestLike = !!Meteor.isTestLike;
220
222
  const swcExternalHelpers = !!Meteor.swcExternalHelpers;
221
223
  const isNative = !!Meteor.isNative;
222
224
  const mode = isProd ? 'production' : 'development';
@@ -405,15 +407,33 @@ module.exports = async function (inMeteor = {}, argv = {}) {
405
407
  ]
406
408
  : [];
407
409
 
408
- const clientNameConfig = `[${(isTest && 'test-') || ''}${
409
- (isTestModule && 'module') || 'client'
410
- }-rspack]`;
410
+
411
+ const clientEntry =
412
+ isTest && isTestEager && isTestFullApp
413
+ ? generateEagerTestFile({
414
+ isAppTest: true,
415
+ projectDir,
416
+ buildContext,
417
+ ignoreEntries: [...meteorIgnoreEntries, '**/server/**'],
418
+ prefix: 'client',
419
+ })
420
+ : isTest && isTestEager
421
+ ? generateEagerTestFile({
422
+ isAppTest: false,
423
+ isClient: true,
424
+ projectDir,
425
+ buildContext,
426
+ ignoreEntries: [...meteorIgnoreEntries, '**/server/**'],
427
+ prefix: 'client',
428
+ })
429
+ : path.resolve(process.cwd(), buildContext, entryPath);
430
+ const clientNameConfig = `[${(isTest && 'test-') || ''}client-rspack]`;
411
431
  // Base client config
412
432
  let clientConfig = {
413
433
  name: clientNameConfig,
414
434
  target: 'web',
415
435
  mode,
416
- entry: path.resolve(process.cwd(), buildContext, entryPath),
436
+ entry: clientEntry,
417
437
  output: {
418
438
  path: clientOutputDir,
419
439
  filename: (_module) => {
@@ -471,8 +491,8 @@ module.exports = async function (inMeteor = {}, argv = {}) {
471
491
  new DefinePlugin({
472
492
  'Meteor.isClient': JSON.stringify(true),
473
493
  'Meteor.isServer': JSON.stringify(false),
474
- 'Meteor.isTest': JSON.stringify(isTest && !isTestFullApp),
475
- 'Meteor.isAppTest': JSON.stringify(isTest && isTestFullApp),
494
+ 'Meteor.isTest': JSON.stringify(isTestLike && !isTestFullApp),
495
+ 'Meteor.isAppTest': JSON.stringify(isTestLike && isTestFullApp),
476
496
  'Meteor.isDevelopment': JSON.stringify(isDev),
477
497
  'Meteor.isProduction': JSON.stringify(isProd),
478
498
  }),
@@ -502,26 +522,25 @@ module.exports = async function (inMeteor = {}, argv = {}) {
502
522
  ...merge(cacheStrategy, { experiments: { css: true } })
503
523
  };
504
524
 
505
-
506
525
  const serverEntry =
507
526
  isTest && isTestEager && isTestFullApp
508
527
  ? generateEagerTestFile({
509
528
  isAppTest: true,
510
529
  projectDir,
511
530
  buildContext,
512
- entries: meteorIgnoreEntries,
531
+ ignoreEntries: [...meteorIgnoreEntries, '**/client/**'],
532
+ prefix: 'server',
513
533
  })
514
534
  : isTest && isTestEager
515
535
  ? generateEagerTestFile({
516
536
  isAppTest: false,
517
537
  projectDir,
518
538
  buildContext,
519
- entries: meteorIgnoreEntries,
539
+ ignoreEntries: [...meteorIgnoreEntries, '**/client/**'],
540
+ prefix: 'server',
520
541
  })
521
542
  : path.resolve(projectDir, buildContext, entryPath);
522
- const serverNameConfig = `[${(isTest && 'test-') || ''}${
523
- (isTestModule && 'module') || 'server'
524
- }-rspack]`;
543
+ const serverNameConfig = `[${(isTest && 'test-') || ''}server-rspack]`;
525
544
  // Base server config
526
545
  let serverConfig = {
527
546
  name: serverNameConfig,
@@ -569,8 +588,8 @@ module.exports = async function (inMeteor = {}, argv = {}) {
569
588
  : {
570
589
  'Meteor.isClient': JSON.stringify(false),
571
590
  'Meteor.isServer': JSON.stringify(true),
572
- 'Meteor.isTest': JSON.stringify(isTest && !isTestFullApp),
573
- 'Meteor.isAppTest': JSON.stringify(isTest && isTestFullApp),
591
+ 'Meteor.isTest': JSON.stringify(isTestLike && !isTestFullApp),
592
+ 'Meteor.isAppTest': JSON.stringify(isTestLike && isTestFullApp),
574
593
  'Meteor.isDevelopment': JSON.stringify(isDev),
575
594
  'Meteor.isProduction': JSON.stringify(isProd),
576
595
  },
@@ -676,10 +695,31 @@ module.exports = async function (inMeteor = {}, argv = {}) {
676
695
  }
677
696
  : {};
678
697
 
679
- const config = mergeSplitOverlap(
698
+ // Establish test client overrides to ensure proper running
699
+ const testClientExpandConfig =
700
+ isTest && isClient
701
+ ? {
702
+ module: {
703
+ parser: {
704
+ javascript: {
705
+ dynamicImportMode: "eager",
706
+ dynamicImportPrefetch: true,
707
+ dynamicImportPreload: true,
708
+ },
709
+ },
710
+ },
711
+ optimization: {
712
+ splitChunks: false,
713
+ },
714
+ plugins: [new NodePolyfillPlugin()],
715
+ }
716
+ : {};
717
+
718
+ let config = mergeSplitOverlap(
680
719
  isClient ? clientConfig : serverConfig,
681
720
  angularExpandConfig
682
721
  );
722
+ config = mergeSplitOverlap(config, testClientExpandConfig);
683
723
 
684
724
  if (Meteor.isDebug || Meteor.isVerbose) {
685
725
  console.log('Config:', inspect(config, { depth: null, colors: true }));