arui-scripts 26.0.0 → 26.1.0-persistent-cache-beta-20261103084257
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/.prettierignore +1 -0
- package/.turbo/turbo-test.log +14 -7
- package/CHANGELOG.md +22 -0
- package/README.md +3 -0
- package/build/bin/commands-registry.js +13 -0
- package/build/commands/build/build-wrapper.d.ts +4 -3
- package/build/commands/build/build-wrapper.js +64 -28
- package/build/commands/build/client.js +20 -19
- package/build/commands/bundle-analyze/index.js +2 -0
- package/build/commands/cache.d.ts +2 -0
- package/build/commands/cache.js +57 -0
- package/build/commands/util/cache-diagnostics.d.ts +10 -0
- package/build/commands/util/cache-diagnostics.js +154 -0
- package/build/commands/util/create-compiler.d.ts +5 -0
- package/build/commands/util/create-compiler.js +37 -0
- package/build/commands/util/graceful-shutdown.d.ts +6 -0
- package/build/commands/util/graceful-shutdown.js +52 -0
- package/build/commands/util/rsdoctor-snapshot.js +3 -0
- package/build/commands/util/run-client-dev-server.js +26 -4
- package/build/commands/util/run-compilers.js +61 -23
- package/build/commands/util/run-server-watch-compiler.js +4 -2
- package/build/configs/app-configs/calculate-dependent-config.js +6 -1
- package/build/configs/app-configs/get-defaults.js +1 -0
- package/build/configs/app-configs/types.d.ts +11 -0
- package/build/configs/app-configs/validate-config.js +4 -0
- package/build/configs/cache/compression.d.ts +24 -0
- package/build/configs/cache/compression.js +120 -0
- package/build/configs/cache/dependencies.d.ts +4 -0
- package/build/configs/cache/dependencies.js +86 -0
- package/build/configs/cache/settings.d.ts +5 -0
- package/build/configs/cache/settings.js +99 -0
- package/build/configs/cache/storage.d.ts +17 -0
- package/build/configs/cache/storage.js +148 -0
- package/build/configs/persistent-cache.d.ts +16 -0
- package/build/configs/persistent-cache.js +275 -0
- package/build/configs/rspack.client.dev.js +3 -2
- package/build/configs/rspack.client.js +7 -5
- package/build/configs/rspack.client.prod.js +3 -2
- package/build/configs/rspack.server.dev.js +2 -1
- package/build/configs/rspack.server.js +2 -1
- package/build/configs/rspack.server.prod.js +2 -1
- package/build/configs/util/compression-plugins-for-dictionaries.js +25 -12
- package/build/configs/util/dcb-compression-plugin.d.ts +6 -4
- package/build/configs/util/dcb-compression-plugin.js +48 -82
- package/build/configs/util/persistent-compression-plugin.d.ts +3 -0
- package/build/configs/util/persistent-compression-plugin.js +41 -0
- package/build/index.d.ts +1 -1
- package/build/plugins/compression-cache.d.ts +12 -0
- package/build/plugins/compression-cache.js +49 -0
- package/build/plugins/reload-server-plugin.js +16 -0
- package/docs/cli.md +4 -1
- package/docs/commands.md +20 -0
- package/docs/persistent-cache.md +214 -0
- package/docs/settings.md +17 -0
- package/package.json +2 -1
- package/test/persistent-cache-lifecycle.cjs +124 -0
- package/test/persistent-cache.cjs +528 -0
- package/tsconfig-local.tsbuildinfo +1 -1
- package/tsconfig.eslint.json +1 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* Run after building arui-scripts. Exercises the real parent/client/watch shutdown path. */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires -- Standalone CommonJS integration fixture. */
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const os = require('node:os');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const { spawn } = require('node:child_process');
|
|
8
|
+
|
|
9
|
+
const cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'arui-cache-lifecycle-'));
|
|
10
|
+
const cli = path.resolve(__dirname, '../build/bin/index.js');
|
|
11
|
+
|
|
12
|
+
fs.mkdirSync(path.join(cwd, 'src/server'), { recursive: true });
|
|
13
|
+
fs.writeFileSync(
|
|
14
|
+
path.join(cwd, 'package.json'),
|
|
15
|
+
JSON.stringify({
|
|
16
|
+
name: 'cache-lifecycle-fixture',
|
|
17
|
+
version: '1.0.0',
|
|
18
|
+
aruiScripts: { persistentCache: true, clientServerPort: 0 },
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
fs.writeFileSync(path.join(cwd, 'src/index.js'), 'console.log("client lifecycle");');
|
|
22
|
+
fs.writeFileSync(
|
|
23
|
+
path.join(cwd, 'src/server/index.js'),
|
|
24
|
+
'console.log("server lifecycle"); setInterval(() => {}, 1000);',
|
|
25
|
+
);
|
|
26
|
+
fs.writeFileSync(
|
|
27
|
+
path.join(cwd, 'arui-scripts.overrides.js'),
|
|
28
|
+
"const fs = require('fs'); module.exports = { devServer(config) { return {...config, host:'127.0.0.1'}; }, rspack(config) { for (const c of Array.isArray(config) ? config : [config]) { c.plugins.push({ apply(compiler) { compiler.hooks.done.tap('LifecycleFixture', stats => fs.writeFileSync(c.target === 'node' ? 'server-stats.json' : 'client-stats.json', JSON.stringify(stats.toJson({all:false, logging:'verbose', loggingDebug:/rspack\\.persistentCache/})))); }}); } return config; }};",
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
async function startAndStop(label) {
|
|
32
|
+
fs.rmSync(path.join(cwd, 'client-stats.json'), { force: true });
|
|
33
|
+
fs.rmSync(path.join(cwd, 'server-stats.json'), { force: true });
|
|
34
|
+
const child = spawn(process.execPath, [cli, 'start'], {
|
|
35
|
+
cwd,
|
|
36
|
+
env: {
|
|
37
|
+
...process.env,
|
|
38
|
+
CI: 'false',
|
|
39
|
+
WATCHPACK_POLLING: '100',
|
|
40
|
+
ARUI_SCRIPTS_CACHE_DEBUG: '1',
|
|
41
|
+
},
|
|
42
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
43
|
+
});
|
|
44
|
+
let output = '';
|
|
45
|
+
|
|
46
|
+
child.stdout.on('data', (chunk) => {
|
|
47
|
+
output += chunk;
|
|
48
|
+
});
|
|
49
|
+
child.stderr.on('data', (chunk) => {
|
|
50
|
+
output += chunk;
|
|
51
|
+
});
|
|
52
|
+
const completed = new Promise((resolve, reject) => {
|
|
53
|
+
child.on('error', reject);
|
|
54
|
+
child.on('close', (code, signal) => resolve({ code, signal }));
|
|
55
|
+
});
|
|
56
|
+
const deadline = Date.now() + 30000;
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
while (
|
|
60
|
+
!fs.existsSync(path.join(cwd, 'client-stats.json')) ||
|
|
61
|
+
!fs.existsSync(path.join(cwd, 'server-stats.json'))
|
|
62
|
+
) {
|
|
63
|
+
if (child.exitCode !== null || Date.now() > deadline)
|
|
64
|
+
throw new Error(`${label}: startup failed\n${output.slice(-5000)}`);
|
|
65
|
+
// eslint-disable-next-line no-await-in-loop -- Poll this process before sending its stop signal.
|
|
66
|
+
await new Promise((resolve) => {
|
|
67
|
+
setTimeout(resolve, 50);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const timer = setTimeout(() => child.kill('SIGKILL'), 12000);
|
|
71
|
+
|
|
72
|
+
child.kill('SIGTERM');
|
|
73
|
+
const result = await completed;
|
|
74
|
+
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
assert.equal(
|
|
77
|
+
result.code,
|
|
78
|
+
0,
|
|
79
|
+
`${label}: shutdown must wait for flush and exit successfully\n${output.slice(-5000)}`,
|
|
80
|
+
);
|
|
81
|
+
const files = fs.readdirSync(path.join(cwd, '.cache/arui-scripts/rspack'), {
|
|
82
|
+
recursive: true,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
assert.ok(files.some((file) => file.endsWith('.pack')));
|
|
86
|
+
assert.ok(
|
|
87
|
+
!files.some((file) => file.endsWith('.writer.json')),
|
|
88
|
+
'leases must be released after native close',
|
|
89
|
+
);
|
|
90
|
+
const diagnostics = output
|
|
91
|
+
.split('\n')
|
|
92
|
+
.filter((line) => line.startsWith('[arui-scripts cache] {'))
|
|
93
|
+
.map((line) => JSON.parse(line.slice('[arui-scripts cache] '.length)));
|
|
94
|
+
|
|
95
|
+
assert.equal(
|
|
96
|
+
diagnostics.filter((event) => event.event === 'close' && event.result === 'completed')
|
|
97
|
+
.length,
|
|
98
|
+
2,
|
|
99
|
+
);
|
|
100
|
+
if (label === 'warm')
|
|
101
|
+
assert.ok(
|
|
102
|
+
diagnostics.some(
|
|
103
|
+
(event) => event.event === 'compilation' && event.native?.snapshot === 'hit',
|
|
104
|
+
),
|
|
105
|
+
'warm dev must recover from disk',
|
|
106
|
+
);
|
|
107
|
+
console.log(
|
|
108
|
+
`PASS: ${label} real dev startup, SIGTERM, server worker shutdown and cache flush`,
|
|
109
|
+
);
|
|
110
|
+
} finally {
|
|
111
|
+
if (child.exitCode === null) child.kill('SIGKILL');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
(async () => {
|
|
115
|
+
try {
|
|
116
|
+
await startAndStop('cold');
|
|
117
|
+
await startAndStop('warm');
|
|
118
|
+
} finally {
|
|
119
|
+
fs.rmSync(cwd, { recursive: true, force: true });
|
|
120
|
+
}
|
|
121
|
+
})().catch((error) => {
|
|
122
|
+
console.error(error);
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
});
|
|
@@ -0,0 +1,528 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires -- Run directly as CommonJS in Node. */
|
|
2
|
+
/* Integration test: run after building arui-scripts. Every build uses a fresh process. */
|
|
3
|
+
const assert = require('node:assert/strict');
|
|
4
|
+
const crypto = require('node:crypto');
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { spawnSync } = require('node:child_process');
|
|
9
|
+
|
|
10
|
+
let cwd = fs.mkdtempSync(path.join(os.tmpdir(), 'arui-persistent-cache-'));
|
|
11
|
+
const cli = path.resolve(__dirname, '../build/bin/index.js');
|
|
12
|
+
const write = (name, content) => fs.writeFileSync(path.join(cwd, name), content);
|
|
13
|
+
const json = (name, content) => write(name, JSON.stringify(content));
|
|
14
|
+
function linkTypeScript() {
|
|
15
|
+
fs.mkdirSync(path.join(cwd, 'node_modules'), { recursive: true });
|
|
16
|
+
fs.symlinkSync(
|
|
17
|
+
path.dirname(require.resolve('typescript/package.json')),
|
|
18
|
+
path.join(cwd, 'node_modules/typescript'),
|
|
19
|
+
'dir',
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const payload = Array.from({ length: 1000 }, (_, i) =>
|
|
24
|
+
crypto.createHash('sha256').update(String(i)).digest('hex'),
|
|
25
|
+
).join('-');
|
|
26
|
+
|
|
27
|
+
const source = (marker) =>
|
|
28
|
+
`import "./fixture.css"; declare const AUDIT_MARKER: string; console.log(AUDIT_MARKER, ${JSON.stringify(
|
|
29
|
+
marker,
|
|
30
|
+
)}, ${JSON.stringify(payload)}); export {};`;
|
|
31
|
+
|
|
32
|
+
function artifacts(directory = path.join(cwd, '.build'), prefix = '') {
|
|
33
|
+
return Object.fromEntries(
|
|
34
|
+
fs
|
|
35
|
+
.readdirSync(directory)
|
|
36
|
+
.sort()
|
|
37
|
+
.flatMap((name) => {
|
|
38
|
+
const file = path.join(directory, name);
|
|
39
|
+
const key = `${prefix}${name}`;
|
|
40
|
+
|
|
41
|
+
if (fs.statSync(file).isDirectory())
|
|
42
|
+
return Object.entries(artifacts(file, `${key}/`));
|
|
43
|
+
if (!/\.(js|css|gz|br|dcb|json|map)$/.test(name) || name === 'env-config.json')
|
|
44
|
+
return [];
|
|
45
|
+
|
|
46
|
+
return [
|
|
47
|
+
[key, crypto.createHash('sha256').update(fs.readFileSync(file)).digest('hex')],
|
|
48
|
+
];
|
|
49
|
+
}),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function build(label, env = {}) {
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
const result = spawnSync(process.execPath, [cli, 'build'], {
|
|
56
|
+
cwd,
|
|
57
|
+
env: { ...process.env, CI: 'false', ARUI_SCRIPTS_CACHE_DEBUG: '1', ...env },
|
|
58
|
+
encoding: 'utf8',
|
|
59
|
+
timeout: 60000,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
assert.equal(
|
|
63
|
+
result.status,
|
|
64
|
+
0,
|
|
65
|
+
`${label}: ${result.error || ''}\n${result.stdout.slice(0, 6000)}\n${result.stderr.slice(
|
|
66
|
+
0,
|
|
67
|
+
3000,
|
|
68
|
+
)}`,
|
|
69
|
+
);
|
|
70
|
+
const prefix = '[arui-scripts cache] ';
|
|
71
|
+
const diagnostics = [];
|
|
72
|
+
|
|
73
|
+
for (const line of `${result.stdout}\n${result.stderr}`.split('\n')) {
|
|
74
|
+
if (line.startsWith(`${prefix}{`)) diagnostics.push(JSON.parse(line.slice(prefix.length)));
|
|
75
|
+
else if (line.includes(prefix)) console.log(line);
|
|
76
|
+
}
|
|
77
|
+
const stats = JSON.parse(fs.readFileSync(path.join(cwd, 'client-stats.json'), 'utf8'));
|
|
78
|
+
|
|
79
|
+
console.log(`${label}: ${Date.now() - started} ms`);
|
|
80
|
+
|
|
81
|
+
return { stats, output: artifacts(), diagnostics };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function logs(stats) {
|
|
85
|
+
return (stats.logging?.['rspack.persistentCache']?.entries || [])
|
|
86
|
+
.map((entry) => entry.message)
|
|
87
|
+
.join('\n');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function compressionStats(stats) {
|
|
91
|
+
const entries = stats.logging?.['arui-scripts.compressionCache']?.entries || [];
|
|
92
|
+
const message = entries.find((entry) =>
|
|
93
|
+
entry.message.startsWith('Compression cache: '),
|
|
94
|
+
)?.message;
|
|
95
|
+
|
|
96
|
+
return message ? JSON.parse(message.slice('Compression cache: '.length)) : undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
linkTypeScript();
|
|
101
|
+
fs.mkdirSync(path.join(cwd, 'src/server'), { recursive: true });
|
|
102
|
+
json('package.json', {
|
|
103
|
+
name: 'cache-fixture',
|
|
104
|
+
version: '1.0.0',
|
|
105
|
+
aruiScripts: {
|
|
106
|
+
persistentCache: { env: ['AUDIT_ENV'] },
|
|
107
|
+
dictionaryCompression: { dictionaryPath: ['./dictionary.txt'] },
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
json('tsconfig.base.json', {
|
|
111
|
+
compilerOptions: {
|
|
112
|
+
target: 'ES2020',
|
|
113
|
+
module: 'ESNext',
|
|
114
|
+
moduleResolution: 'bundler',
|
|
115
|
+
types: [],
|
|
116
|
+
skipLibCheck: true,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
json('tsconfig.json', { extends: './tsconfig.base.json', include: ['src'] });
|
|
120
|
+
json('build-values.json', { marker: 'CONFIG_A' });
|
|
121
|
+
write('yarn.lock', '# fixture lock v1\n');
|
|
122
|
+
write('.browserslistrc', 'Chrome 100\n');
|
|
123
|
+
write('dictionary.txt', payload.slice(0, 20000));
|
|
124
|
+
write('src/css.d.ts', 'declare module "*.css"; declare function require(name: string): any;');
|
|
125
|
+
write('src/fixture.css', 'body { color: red; padding: 10px; }');
|
|
126
|
+
// eslint-disable-next-line no-template-curly-in-string -- The runtime placeholder must stay literal.
|
|
127
|
+
write('env-config.json', '{"runtime":"${CACHE_RUNTIME}"}');
|
|
128
|
+
write('src/index.ts', source('SOURCE_A'));
|
|
129
|
+
write('src/server/index.ts', 'console.log("server-cache"); export {};');
|
|
130
|
+
write(
|
|
131
|
+
'arui-scripts.overrides.js',
|
|
132
|
+
`
|
|
133
|
+
const fs = require('fs');
|
|
134
|
+
const values = require('./build-values.json');
|
|
135
|
+
module.exports = { rspack(config) {
|
|
136
|
+
for (const c of Array.isArray(config) ? config : [config]) {
|
|
137
|
+
if (process.env.COMPRESSION_LEVEL) {
|
|
138
|
+
const gzip = c.plugins.find(plugin => plugin?.constructor.name === 'CompressionPlugin' && plugin.options.algorithm === 'gzip');
|
|
139
|
+
if (gzip) gzip.options.compressionOptions.level = Number(process.env.COMPRESSION_LEVEL);
|
|
140
|
+
}
|
|
141
|
+
c.plugins.push({ apply(compiler) {
|
|
142
|
+
new compiler.webpack.DefinePlugin({ AUDIT_MARKER: JSON.stringify(values.marker + (process.env.AUDIT_ENV || '')) }).apply(compiler);
|
|
143
|
+
if (c.target !== 'node') compiler.hooks.thisCompilation.tap('FreshCompressionInput', compilation => {
|
|
144
|
+
compilation.hooks.processAssets.tap({name: 'FreshCompressionInput', stage: 2990}, () => {
|
|
145
|
+
compilation.emitAsset('compression-fixture.js', new compiler.webpack.sources.RawSource(${JSON.stringify(
|
|
146
|
+
JSON.stringify(payload),
|
|
147
|
+
)}));
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
compiler.hooks.done.tap('CacheTest', stats => fs.writeFileSync(
|
|
151
|
+
c.target === 'node' ? 'server-stats.json' : 'client-stats.json',
|
|
152
|
+
JSON.stringify(stats.toJson({ all: false, modules: true, cachedModules: true, logging: 'verbose', loggingDebug: /rspack\\.persistentCache|arui-scripts\\.compressionCache/ }))
|
|
153
|
+
));
|
|
154
|
+
}});
|
|
155
|
+
}
|
|
156
|
+
return config;
|
|
157
|
+
}};
|
|
158
|
+
`,
|
|
159
|
+
);
|
|
160
|
+
const cold = build('cold');
|
|
161
|
+
const warm = build('warm');
|
|
162
|
+
|
|
163
|
+
assert.ok(
|
|
164
|
+
cold.diagnostics.some(
|
|
165
|
+
(event) => event.event === 'compilation' && event.native.snapshot === 'cold',
|
|
166
|
+
),
|
|
167
|
+
);
|
|
168
|
+
for (const result of [cold, warm]) {
|
|
169
|
+
assert.equal(
|
|
170
|
+
result.diagnostics.filter(
|
|
171
|
+
(event) => event.event === 'configured' && event.cacheType === 'persistent',
|
|
172
|
+
).length,
|
|
173
|
+
2,
|
|
174
|
+
);
|
|
175
|
+
assert.equal(
|
|
176
|
+
result.diagnostics.filter(
|
|
177
|
+
(event) => event.event === 'close' && event.result === 'completed',
|
|
178
|
+
).length,
|
|
179
|
+
2,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
assert.equal(
|
|
183
|
+
warm.diagnostics.filter(
|
|
184
|
+
(event) => event.event === 'compilation' && event.native.snapshot === 'hit',
|
|
185
|
+
).length,
|
|
186
|
+
2,
|
|
187
|
+
);
|
|
188
|
+
assert.ok(
|
|
189
|
+
warm.diagnostics.some(
|
|
190
|
+
(event) => event.compression?.hits >= 3 && event.compression.misses === 0,
|
|
191
|
+
),
|
|
192
|
+
);
|
|
193
|
+
const quiet = build('warm diagnostics disabled', { ARUI_SCRIPTS_CACHE_DEBUG: '0' });
|
|
194
|
+
|
|
195
|
+
assert.equal(quiet.diagnostics.length, 0);
|
|
196
|
+
assert.match(logs(quiet.stats), /snapshot restored with no changed dependencies/);
|
|
197
|
+
assert.deepEqual(quiet.output, warm.output);
|
|
198
|
+
|
|
199
|
+
assert.match(logs(warm.stats), /make persistent cache recovery succeeded/);
|
|
200
|
+
assert.ok(compressionStats(cold.stats).misses >= 3, 'cold build runs all three compressors');
|
|
201
|
+
assert.ok(
|
|
202
|
+
compressionStats(warm.stats).hits >= 3,
|
|
203
|
+
'gzip, Brotli and DCB bytes survive process restart',
|
|
204
|
+
);
|
|
205
|
+
assert.equal(
|
|
206
|
+
compressionStats(warm.stats).misses,
|
|
207
|
+
0,
|
|
208
|
+
'warm build does not recompress unchanged bytes',
|
|
209
|
+
);
|
|
210
|
+
const nativeOnly = build('native cache without compression cache', {
|
|
211
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: { compression: false } }),
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
assert.equal(compressionStats(nativeOnly.stats), undefined);
|
|
215
|
+
assert.deepEqual(nativeOnly.output, warm.output);
|
|
216
|
+
const serverStats = JSON.parse(fs.readFileSync(path.join(cwd, 'server-stats.json'), 'utf8'));
|
|
217
|
+
|
|
218
|
+
assert.match(logs(serverStats), /make persistent cache recovery succeeded/);
|
|
219
|
+
const changedLevel = build('gzip level change', { COMPRESSION_LEVEL: '1' });
|
|
220
|
+
|
|
221
|
+
assert.ok(compressionStats(changedLevel.stats).misses > 0);
|
|
222
|
+
assert.ok(compressionStats(changedLevel.stats).hits >= 2, 'Brotli and DCB remain reusable');
|
|
223
|
+
assert.notDeepEqual(changedLevel.output, warm.output);
|
|
224
|
+
const changedLevelWarm = build('gzip level change warm', { COMPRESSION_LEVEL: '1' });
|
|
225
|
+
|
|
226
|
+
assert.equal(compressionStats(changedLevelWarm.stats).misses, 0);
|
|
227
|
+
assert.deepEqual(changedLevelWarm.output, changedLevel.output);
|
|
228
|
+
assert.deepEqual(
|
|
229
|
+
build('gzip level change uncached', {
|
|
230
|
+
COMPRESSION_LEVEL: '1',
|
|
231
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: false }),
|
|
232
|
+
}).output,
|
|
233
|
+
changedLevel.output,
|
|
234
|
+
);
|
|
235
|
+
assert.deepEqual(
|
|
236
|
+
warm.output,
|
|
237
|
+
cold.output,
|
|
238
|
+
'all emitted artifacts, including DCB, survive cache recovery',
|
|
239
|
+
);
|
|
240
|
+
assert.ok(
|
|
241
|
+
Object.keys(warm.output).some((file) => file.endsWith('.dcb')),
|
|
242
|
+
'DCB fixture must actually emit a file',
|
|
243
|
+
);
|
|
244
|
+
write('src/index.ts', source('SOURCE_B'));
|
|
245
|
+
const edited = build('source edit');
|
|
246
|
+
|
|
247
|
+
assert.notDeepEqual(edited.output, warm.output);
|
|
248
|
+
const uncached = build('source edit, cache disabled', {
|
|
249
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: false }),
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
assert.ok(
|
|
253
|
+
uncached.diagnostics.some(
|
|
254
|
+
(event) => event.event === 'configured' && event.reason === 'disabled-by-setting',
|
|
255
|
+
),
|
|
256
|
+
);
|
|
257
|
+
assert.ok(
|
|
258
|
+
uncached.diagnostics
|
|
259
|
+
.filter((event) => event.event === 'compilation')
|
|
260
|
+
.every((event) => event.native.snapshot === 'disabled'),
|
|
261
|
+
);
|
|
262
|
+
|
|
263
|
+
assert.deepEqual(edited.output, uncached.output);
|
|
264
|
+
|
|
265
|
+
write('dictionary.txt', payload.slice(10000, 35000));
|
|
266
|
+
const dictionary = build('dictionary edit');
|
|
267
|
+
|
|
268
|
+
assert.ok(
|
|
269
|
+
dictionary.diagnostics.some(
|
|
270
|
+
(event) => event.event === 'compilation' && event.native.snapshot === 'invalidated',
|
|
271
|
+
),
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
assert.ok(compressionStats(dictionary.stats).misses > 0, 'new dictionary recompresses DCB');
|
|
275
|
+
assert.ok(
|
|
276
|
+
compressionStats(dictionary.stats).hits >= 2,
|
|
277
|
+
'unchanged gzip/Brotli bytes are reused',
|
|
278
|
+
);
|
|
279
|
+
assert.notDeepEqual(dictionary.output, edited.output);
|
|
280
|
+
assert.deepEqual(build('dictionary warm').output, dictionary.output);
|
|
281
|
+
|
|
282
|
+
json('build-values.json', { marker: 'CONFIG_B' });
|
|
283
|
+
const configEdit = build('transitive override input');
|
|
284
|
+
|
|
285
|
+
assert.match(logs(configEdit.stats), /invalid|changed/i);
|
|
286
|
+
assert.notDeepEqual(configEdit.output, dictionary.output);
|
|
287
|
+
json('tsconfig.base.json', {
|
|
288
|
+
compilerOptions: {
|
|
289
|
+
target: 'ES2021',
|
|
290
|
+
module: 'ESNext',
|
|
291
|
+
moduleResolution: 'bundler',
|
|
292
|
+
types: [],
|
|
293
|
+
skipLibCheck: true,
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
assert.match(logs(build('extended tsconfig').stats), /invalid|changed/i);
|
|
297
|
+
write('yarn.lock', '# fixture lock v2\n');
|
|
298
|
+
assert.match(logs(build('lockfile edit').stats), /invalid|changed/i);
|
|
299
|
+
write('.browserslistrc', 'Chrome 110\n');
|
|
300
|
+
assert.match(logs(build('browserslist edit').stats), /invalid|changed/i);
|
|
301
|
+
assert.match(
|
|
302
|
+
logs(build('environment edit', { BROWSERSLIST: 'Chrome 120' }).stats),
|
|
303
|
+
/invalid|changed|version/i,
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const declaredEnv = build('declared compile env', { AUDIT_ENV: 'ENV_B' });
|
|
307
|
+
|
|
308
|
+
assert.notDeepEqual(declaredEnv.output, configEdit.output);
|
|
309
|
+
build('compile env reset');
|
|
310
|
+
const readonly = build('readonly existing', {
|
|
311
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: { readonly: true } }),
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
assert.match(logs(readonly.stats), /make persistent cache recovery succeeded/);
|
|
315
|
+
assert.equal(compressionStats(readonly.stats).writes, 0);
|
|
316
|
+
const readonlyMissing = build('readonly missing', {
|
|
317
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({
|
|
318
|
+
persistentCache: { readonly: true, directory: '.cache/readonly-missing' },
|
|
319
|
+
}),
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
assert.deepEqual(readonlyMissing.output, readonly.output);
|
|
323
|
+
assert.equal(compressionStats(readonlyMissing.stats).writes, 0);
|
|
324
|
+
assert.ok(
|
|
325
|
+
!fs.existsSync(path.join(cwd, '.cache/readonly-missing')) ||
|
|
326
|
+
!fs
|
|
327
|
+
.readdirSync(path.join(cwd, '.cache/readonly-missing'), { recursive: true })
|
|
328
|
+
.some((name) => name.includes('compression-v1')),
|
|
329
|
+
'readonly misses must not create compression records',
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
fs.mkdirSync(path.join(cwd, 'node_modules'), { recursive: true });
|
|
333
|
+
fs.mkdirSync(path.join(cwd, 'linked-package'), { recursive: true });
|
|
334
|
+
json('linked-package/package.json', {
|
|
335
|
+
name: 'cache-linked',
|
|
336
|
+
version: '1.0.0',
|
|
337
|
+
main: 'index.js',
|
|
338
|
+
});
|
|
339
|
+
write('linked-package/index.js', 'module.exports = "LINK_A";');
|
|
340
|
+
fs.symlinkSync(path.join(cwd, 'linked-package'), path.join(cwd, 'node_modules/cache-linked'));
|
|
341
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json')));
|
|
342
|
+
|
|
343
|
+
pkg.dependencies = { 'cache-linked': 'file:./linked-package' };
|
|
344
|
+
json('package.json', pkg);
|
|
345
|
+
write('src/index.ts', `${source('SOURCE_LINK')}console.log(require("cache-linked"));`);
|
|
346
|
+
const linked = build('linked package cold');
|
|
347
|
+
|
|
348
|
+
assert.deepEqual(build('linked package warm').output, linked.output);
|
|
349
|
+
write('linked-package/index.js', 'module.exports = "LINK_B";');
|
|
350
|
+
assert.notDeepEqual(
|
|
351
|
+
build('linked package source edit without version bump').output,
|
|
352
|
+
linked.output,
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
write('src/index.ts', `${source('SOURCE_TYPE_ERROR')}const bad: string = 123;`);
|
|
356
|
+
const failed = spawnSync(process.execPath, [cli, 'build'], {
|
|
357
|
+
cwd,
|
|
358
|
+
env: { ...process.env, CI: 'false' },
|
|
359
|
+
encoding: 'utf8',
|
|
360
|
+
timeout: 60000,
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
assert.notEqual(failed.status, 0, 'type errors must still fail after cache restore');
|
|
364
|
+
assert.match(failed.stdout + failed.stderr, /TS2322|string/);
|
|
365
|
+
write('src/index.ts', source('SOURCE_RECOVERED'));
|
|
366
|
+
build('after type error');
|
|
367
|
+
|
|
368
|
+
const originalCwd = cwd;
|
|
369
|
+
const portableEnv = {
|
|
370
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: { portable: true } }),
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
build('portable cold', portableEnv);
|
|
374
|
+
const portableWarm = build('portable warm', portableEnv);
|
|
375
|
+
|
|
376
|
+
assert.match(logs(portableWarm.stats), /make persistent cache recovery succeeded/);
|
|
377
|
+
const relocated = fs.mkdtempSync(path.join(os.tmpdir(), 'arui-cache-relocated-'));
|
|
378
|
+
|
|
379
|
+
fs.cpSync(cwd, relocated, {
|
|
380
|
+
recursive: true,
|
|
381
|
+
filter: (file) => !file.includes('/node_modules') && !file.includes('/linked-package'),
|
|
382
|
+
});
|
|
383
|
+
cwd = relocated;
|
|
384
|
+
try {
|
|
385
|
+
linkTypeScript();
|
|
386
|
+
const moved = build('portable new checkout path', portableEnv);
|
|
387
|
+
|
|
388
|
+
// Rspack 2.2.5 relocation guard: first build in a new checkout is cold and correct.
|
|
389
|
+
assert.match(logs(moved.stats), /invalid|version|changed/i);
|
|
390
|
+
const movedWarm = build('portable relocated warm', portableEnv);
|
|
391
|
+
|
|
392
|
+
assert.match(logs(movedWarm.stats), /make persistent cache recovery succeeded/);
|
|
393
|
+
const movedFresh = build('portable relocated uncached parity', {
|
|
394
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: false }),
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
assert.deepEqual(moved.output, movedFresh.output);
|
|
398
|
+
} finally {
|
|
399
|
+
cwd = originalCwd;
|
|
400
|
+
fs.rmSync(relocated, { recursive: true, force: true });
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const cacheRoot = path.join(cwd, '.cache/arui-scripts/rspack');
|
|
404
|
+
const cacheFiles = fs
|
|
405
|
+
.readdirSync(cacheRoot, { recursive: true })
|
|
406
|
+
.filter((file) => file.endsWith('.pack'));
|
|
407
|
+
|
|
408
|
+
assert.ok(cacheFiles.length > 0);
|
|
409
|
+
cacheFiles.forEach((file) => fs.writeFileSync(path.join(cacheRoot, file), 'CORRUPT'));
|
|
410
|
+
const recovered = build('corrupt cache recovery');
|
|
411
|
+
|
|
412
|
+
assert.deepEqual(
|
|
413
|
+
recovered.output,
|
|
414
|
+
build('corrupt recovery uncached', {
|
|
415
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ persistentCache: false }),
|
|
416
|
+
}).output,
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
fs.mkdirSync(path.join(cwd, '.cache/unwritable'), { recursive: true });
|
|
420
|
+
fs.chmodSync(path.join(cwd, '.cache/unwritable'), 0o555);
|
|
421
|
+
try {
|
|
422
|
+
const fallback = build('unwritable cache fallback', {
|
|
423
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({
|
|
424
|
+
persistentCache: { directory: '.cache/unwritable' },
|
|
425
|
+
}),
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
assert.deepEqual(fallback.output, recovered.output);
|
|
429
|
+
assert.ok(
|
|
430
|
+
fallback.diagnostics.some(
|
|
431
|
+
(event) =>
|
|
432
|
+
event.event === 'configured' &&
|
|
433
|
+
event.reason === 'storage-unavailable' &&
|
|
434
|
+
event.cacheType === 'disabled',
|
|
435
|
+
),
|
|
436
|
+
);
|
|
437
|
+
} finally {
|
|
438
|
+
fs.chmodSync(path.join(cwd, '.cache/unwritable'), 0o755);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const overridesPath = path.join(cwd, 'arui-scripts.overrides.js');
|
|
442
|
+
const overrideContents = fs.readFileSync(overridesPath, 'utf8');
|
|
443
|
+
|
|
444
|
+
fs.appendFileSync(overridesPath, '\nconsole.log("override diagnostic");\n');
|
|
445
|
+
const info = spawnSync(process.execPath, [cli, 'cache:info', '--json'], {
|
|
446
|
+
cwd,
|
|
447
|
+
encoding: 'utf8',
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
assert.equal(info.status, 0, info.stderr);
|
|
451
|
+
const report = JSON.parse(info.stdout);
|
|
452
|
+
|
|
453
|
+
assert.ok(report.bytes > 0 && report.namespaces.length >= 2);
|
|
454
|
+
assert.doesNotMatch(info.stdout, /ENV_B|runtime-other/);
|
|
455
|
+
assert.doesNotMatch(info.stdout, /override diagnostic/);
|
|
456
|
+
assert.match(info.stderr, /override diagnostic/);
|
|
457
|
+
fs.writeFileSync(overridesPath, overrideContents);
|
|
458
|
+
const clear = spawnSync(process.execPath, [cli, 'cache:clear'], { cwd, encoding: 'utf8' });
|
|
459
|
+
|
|
460
|
+
assert.equal(clear.status, 0, clear.stderr);
|
|
461
|
+
assert.ok(fs.existsSync(path.join(cwd, '.build')), 'clear must preserve build output');
|
|
462
|
+
assert.ok(
|
|
463
|
+
!fs.readdirSync(cacheRoot, { recursive: true }).some((name) => name.endsWith('.bin')),
|
|
464
|
+
'clear removes compressed bytes with native cache',
|
|
465
|
+
);
|
|
466
|
+
const devProgram = `
|
|
467
|
+
const { createCompiler } = require(${JSON.stringify(
|
|
468
|
+
path.resolve(__dirname, '../build/commands/util/create-compiler.js'),
|
|
469
|
+
)});
|
|
470
|
+
const { config } = require(${JSON.stringify(
|
|
471
|
+
path.resolve(__dirname, '../build/configs/rspack.client.dev.js'),
|
|
472
|
+
)});
|
|
473
|
+
const compiler = createCompiler(config);
|
|
474
|
+
compiler.run((error, stats) => { const failed = stats?.hasErrors(); compiler.close(closeError => {
|
|
475
|
+
if (error || closeError || failed) {
|
|
476
|
+
console.error(error || closeError || 'Compilation failed');
|
|
477
|
+
process.exitCode = 1;
|
|
478
|
+
}
|
|
479
|
+
}); });
|
|
480
|
+
`;
|
|
481
|
+
|
|
482
|
+
for (const label of ['dev cold', 'dev warm']) {
|
|
483
|
+
fs.rmSync(path.join(cwd, '.build'), { recursive: true, force: true });
|
|
484
|
+
const result = spawnSync(process.execPath, ['-e', devProgram], {
|
|
485
|
+
cwd,
|
|
486
|
+
env: { ...process.env, NODE_ENV: 'development' },
|
|
487
|
+
encoding: 'utf8',
|
|
488
|
+
timeout: 60000,
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
assert.equal(result.status, 0, result.stderr);
|
|
492
|
+
if (label === 'dev warm') {
|
|
493
|
+
const stats = JSON.parse(fs.readFileSync(path.join(cwd, 'client-stats.json'), 'utf8'));
|
|
494
|
+
|
|
495
|
+
assert.match(logs(stats), /make persistent cache recovery succeeded/);
|
|
496
|
+
}
|
|
497
|
+
console.log(`PASS: ${label}`);
|
|
498
|
+
}
|
|
499
|
+
for (const [label, value] of [
|
|
500
|
+
['runtime dev cold', 'runtime-new'],
|
|
501
|
+
['runtime dev warm', 'runtime-other'],
|
|
502
|
+
]) {
|
|
503
|
+
const result = spawnSync(process.execPath, ['-e', devProgram], {
|
|
504
|
+
cwd,
|
|
505
|
+
encoding: 'utf8',
|
|
506
|
+
timeout: 60000,
|
|
507
|
+
env: {
|
|
508
|
+
...process.env,
|
|
509
|
+
NODE_ENV: 'development',
|
|
510
|
+
CACHE_RUNTIME: value,
|
|
511
|
+
ARUI_SCRIPTS_CONFIG: JSON.stringify({ clientOnly: true }),
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
assert.equal(result.status, 0, result.stderr);
|
|
516
|
+
assert.equal(
|
|
517
|
+
JSON.parse(fs.readFileSync(path.join(cwd, '.build/env-config.json'))).runtime,
|
|
518
|
+
value,
|
|
519
|
+
);
|
|
520
|
+
console.log(`PASS: ${label}`);
|
|
521
|
+
}
|
|
522
|
+
console.log(
|
|
523
|
+
'PASS: disk reuse, client/server isolation, source/config/dictionary invalidation and artifact parity',
|
|
524
|
+
);
|
|
525
|
+
} finally {
|
|
526
|
+
if (process.env.ARUI_CACHE_KEEP_FIXTURE) console.log(`Fixture: ${cwd}`);
|
|
527
|
+
else fs.rmSync(cwd, { recursive: true, force: true });
|
|
528
|
+
}
|