@meteorjs/rspack 3.0.0-rc.0 → 3.0.0-rc.1

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.
@@ -0,0 +1,33 @@
1
+ // Type checkers and other plugins/watchers can invalidate a compilation without
2
+ // changing its output. This can affect any Rspack project, regardless of language.
3
+ // Rspack already compares asset contents before writing them, so track emitted
4
+ // flags and asset names without copying and hashing entire bundles in JS.
5
+ function createOutputTracker() {
6
+ let version = 0;
7
+ let previousNames;
8
+
9
+ return stats => {
10
+ const { assets } = stats.toJson({
11
+ all: false,
12
+ assets: true,
13
+ cachedAssets: true,
14
+ relatedAssets: true,
15
+ });
16
+ const pending = [...assets];
17
+ const names = [];
18
+ let emitted = false;
19
+ for (let i = 0; i < pending.length; i++) {
20
+ const asset = pending[i];
21
+ names.push(asset.name);
22
+ emitted ||= asset.emitted;
23
+ // Source maps are nested under their parent asset in Rspack stats.
24
+ if (asset.related) pending.push(...asset.related);
25
+ }
26
+ const currentNames = JSON.stringify(names.sort());
27
+ if (emitted || currentNames !== previousNames) version++;
28
+ previousNames = currentNames;
29
+ return version;
30
+ };
31
+ }
32
+
33
+ module.exports = { createOutputTracker };
@@ -0,0 +1,62 @@
1
+ const { createOutputTracker } = require('./compilationOutput.js');
2
+
3
+ const stats = (assets, { hash = 'compilation-hash', hasErrors = false } = {}) => ({
4
+ hash,
5
+ hasErrors: () => hasErrors,
6
+ toJson: () => ({ assets }),
7
+ });
8
+ const asset = (name, emitted = false, related = []) => ({
9
+ name, emitted, related,
10
+ });
11
+
12
+ describe('server output tracking', () => {
13
+ test('ignores compilation-only changes and asset ordering', () => {
14
+ const track = createOutputTracker();
15
+ const first = track(stats([
16
+ asset('server.js', true),
17
+ asset('chunk.js', true),
18
+ ]));
19
+
20
+ expect(track(stats([
21
+ asset('chunk.js'),
22
+ asset('server.js'),
23
+ ], { hash: 'different-compilation-hash' }))).toBe(first);
24
+
25
+ expect(track(stats([
26
+ asset('server.js'),
27
+ asset('chunk.js', true),
28
+ ]))).not.toBe(first);
29
+ });
30
+
31
+ test('detects source-map-only changes and asset removals', () => {
32
+ const track = createOutputTracker();
33
+ const first = track(stats([
34
+ asset('server.js', false, [asset('server.js.map')]),
35
+ asset('chunk.js'),
36
+ ]));
37
+ const updatedMap = track(stats([
38
+ asset('server.js', false, [asset('server.js.map', true)]),
39
+ asset('chunk.js'),
40
+ ]));
41
+ expect(updatedMap).not.toBe(first);
42
+
43
+ const removedChunk = track(stats([
44
+ asset('server.js', false, [asset('server.js.map')]),
45
+ ]));
46
+ expect(removedChunk).not.toBe(updatedMap);
47
+ expect(track(stats([
48
+ asset('server.js', false, [asset('server.js.map')]),
49
+ ]))).toBe(removedChunk);
50
+ });
51
+
52
+ test('keeps output changes visible when a failed build recovers without writing again', () => {
53
+ const track = createOutputTracker();
54
+ const lastSuccessful = track(stats([asset('server.js', true)]));
55
+ const failed = track(stats([asset('server.js', true)], { hasErrors: true }));
56
+ // Meteor ignores failed compilations; recovery must still differ from the
57
+ // last successful version even when Rspack has already written the output.
58
+ const recovered = track(stats([asset('server.js')]));
59
+ expect(recovered).toBe(failed);
60
+ expect(recovered).not.toBe(lastSuccessful);
61
+ });
62
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteorjs/rspack",
3
- "version": "3.0.0-rc.0",
3
+ "version": "3.0.0-rc.1",
4
4
  "description": "Configuration logic for using Rspack in Meteor projects",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
package/rspack.config.js CHANGED
@@ -30,6 +30,7 @@ const { loadUserAndOverrideConfig } = require('./lib/meteorRspackConfigHelpers.j
30
30
  const { prepareMeteorRspackConfig } = require("./lib/meteorRspackConfigFactory");
31
31
  const { extractLocalDependencies } = require('./lib/localDependenciesHelpers.js');
32
32
  const { createTestClientNodePolyfillConfig } = require("./lib/testClientNodePolyfills.js");
33
+ const { createOutputTracker } = require('./lib/compilationOutput.js');
33
34
 
34
35
  // Safe require that doesn't throw if the module isn't found
35
36
  function safeRequire(moduleName) {
@@ -961,6 +962,7 @@ module.exports = async function (inMeteor = {}, argv = {}) {
961
962
  }
962
963
 
963
964
  // Add MeteorRspackOutputPlugin as the last plugin to output compilation info
965
+ const trackServerOutput = createOutputTracker();
964
966
  const meteorRspackOutputPlugin = new MeteorRspackOutputPlugin({
965
967
  getData: (stats, { isRebuild, compilationCount, compiler }) => {
966
968
  const generatedAppPaths = [
@@ -988,7 +990,13 @@ module.exports = async function (inMeteor = {}, argv = {}) {
988
990
  hasErrors: stats.hasErrors(),
989
991
  hasWarnings: stats.hasWarnings(),
990
992
  hasAppSourceChanges,
991
- hash: stats.hash,
993
+ // Use output changes to decide development server restarts. Production,
994
+ // test, native, and client compilations keep Rspack's original hash.
995
+ // Include failed emissions in the version so recovery still restarts
996
+ // if the output changed before the errors were cleared.
997
+ hash: isServer && isDevEnvironment
998
+ ? trackServerOutput(stats)
999
+ : stats.hash,
992
1000
  timestamp: Date.now(),
993
1001
  statsOverrided,
994
1002
  compilationCount,