arui-scripts 25.1.0 → 26.0.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.
Files changed (50) hide show
  1. package/.turbo/turbo-test.log +11 -6
  2. package/CHANGELOG.md +37 -0
  3. package/README.md +17 -0
  4. package/build/commands/start/index.js +1 -1
  5. package/build/commands/start-prod/index.js +1 -1
  6. package/build/commands/util/artifacts-config.d.ts +2 -13
  7. package/build/commands/util/artifacts-config.js +8 -75
  8. package/build/commands/util/arui-scripts-artifacts.d.ts +3 -12
  9. package/build/commands/util/arui-scripts-artifacts.js +4 -23
  10. package/build/commands/util/docker-build.d.ts +3 -9
  11. package/build/commands/util/docker-build.js +3 -9
  12. package/build/commands/util/map-artifacts-config.d.ts +8 -0
  13. package/build/commands/util/map-artifacts-config.js +57 -0
  14. package/build/commands/util/tsc.d.ts +1 -1
  15. package/build/commands/util/tsc.js +7 -9
  16. package/build/commands/util/yarn.d.ts +1 -4
  17. package/build/commands/util/yarn.js +1 -4
  18. package/build/configs/app-configs/index.d.ts +0 -1
  19. package/build/configs/app-configs/index.js +0 -1
  20. package/build/configs/app-configs/read-config-file.js +3 -5
  21. package/build/configs/app-configs/types.d.ts +2 -9
  22. package/build/configs/app-configs/update-with-presets.js +3 -3
  23. package/build/configs/app-configs/validate-config.js +6 -0
  24. package/build/configs/app-configs/warn-about-deprecations.js +5 -0
  25. package/build/configs/jest/settings.js +7 -3
  26. package/build/configs/rspack.client.js +3 -1
  27. package/build/configs/util/apply-overrides.d.ts +0 -10
  28. package/build/configs/util/apply-overrides.js +3 -11
  29. package/build/configs/util/load-config-file.d.ts +1 -0
  30. package/build/configs/util/load-config-file.js +14 -0
  31. package/build/configs/util/resolve.js +9 -5
  32. package/build/configs/util/typescript.d.ts +8 -0
  33. package/build/configs/util/typescript.js +18 -0
  34. package/build/index.d.ts +1 -6
  35. package/build/index.js +1 -6
  36. package/docs/artifact.md +4 -3
  37. package/docs/compilers.md +31 -8
  38. package/docs/migration-v26.md +27 -0
  39. package/docs/modules.md +43 -0
  40. package/docs/overrides.md +5 -11
  41. package/docs/settings.md +5 -11
  42. package/package.json +5 -4
  43. package/test-start.js +200 -0
  44. package/test-typescript-watch.js +86 -0
  45. package/test-typescript.js +146 -0
  46. package/tsconfig-local.tsbuildinfo +1 -1
  47. package/build/commands/util/artifacts-deprecations.d.ts +0 -9
  48. package/build/commands/util/artifacts-deprecations.js +0 -66
  49. package/build/configs/util/register-ts-node.d.ts +0 -1
  50. package/build/configs/util/register-ts-node.js +0 -19
package/test-start.js ADDED
@@ -0,0 +1,200 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires, no-await-in-loop */
2
+ // Startup and shutdown polling must await each check before trying again.
3
+ const assert = require('node:assert/strict');
4
+ const { spawn } = require('node:child_process');
5
+ const fs = require('node:fs/promises');
6
+ const net = require('node:net');
7
+ const path = require('node:path');
8
+ const { stripVTControlCharacters } = require('node:util');
9
+ const { setTimeout: delay } = require('node:timers/promises');
10
+
11
+ const example = path.resolve(__dirname, '../example');
12
+ const timeout = Number(process.env.START_SMOKE_TIMEOUT_MS || 45000);
13
+ const controller = new AbortController();
14
+ const { signal } = controller;
15
+
16
+ async function reservePort() {
17
+ const server = net.createServer();
18
+
19
+ await new Promise((resolve, reject) => {
20
+ server.once('error', reject);
21
+ server.listen(0, '0.0.0.0', resolve);
22
+ });
23
+
24
+ return {
25
+ port: server.address().port,
26
+ close: () =>
27
+ new Promise((resolve, reject) => {
28
+ server.close((error) => (error ? reject(error) : resolve()));
29
+ }),
30
+ };
31
+ }
32
+
33
+ function groupExists(pid) {
34
+ try {
35
+ process.kill(-pid, 0);
36
+
37
+ return true;
38
+ } catch (error) {
39
+ if (error.code === 'ESRCH') return false;
40
+ throw error;
41
+ }
42
+ }
43
+
44
+ async function stop(child) {
45
+ if (!child?.pid || !groupExists(child.pid)) return;
46
+
47
+ process.kill(-child.pid, 'SIGTERM');
48
+ const deadline = Date.now() + 3000;
49
+
50
+ while (groupExists(child.pid) && Date.now() < deadline) {
51
+ await delay(50);
52
+ }
53
+ if (groupExists(child.pid)) {
54
+ process.kill(-child.pid, 'SIGKILL');
55
+ }
56
+ }
57
+
58
+ async function get(url) {
59
+ const response = await fetch(url, {
60
+ signal: AbortSignal.any([signal, AbortSignal.timeout(1500)]),
61
+ });
62
+
63
+ assert.equal(response.status, 200, `${url}: HTTP ${response.status}`);
64
+
65
+ return { body: await response.text(), type: response.headers.get('content-type') || '' };
66
+ }
67
+
68
+ async function verifyHttp(origin, assetsPath) {
69
+ const html = await get(`${origin}/`);
70
+
71
+ assert(html.body.includes(`/${assetsPath}/`), 'SSR responded with a different build');
72
+ const script = html.body.match(/<script[^>]*src=['"]([^'"]+\.js)['"]/);
73
+
74
+ assert(script, 'SSR did not include a JavaScript entry');
75
+ const mainScript = await get(new URL(script[1], origin));
76
+ const worker = await get(`${origin}/${assetsPath}/worker.js`);
77
+
78
+ assert(
79
+ /javascript/.test(mainScript.type) && mainScript.body.length > 0,
80
+ 'Expected JavaScript entry',
81
+ );
82
+ assert(/javascript/.test(worker.type) && worker.body.length > 0, 'Expected worker JavaScript');
83
+ }
84
+
85
+ function assertRunning(child, childError, output) {
86
+ if (childError)
87
+ throw new Error(`Unable to start yarn: ${childError.message}`, { cause: childError });
88
+ if (child.exitCode !== null || child.signalCode !== null) {
89
+ throw new Error(
90
+ `yarn start exited before readiness (${child.exitCode ?? child.signalCode})`,
91
+ );
92
+ }
93
+ if (/\b(?:TypeError|Error):|ERROR in|compiled with[^\n]*errors?|error TS\d+/.test(output)) {
94
+ throw new Error('yarn start reported a startup or compilation error');
95
+ }
96
+ }
97
+
98
+ async function main() {
99
+ assert(Number.isFinite(timeout) && timeout > 0, 'START_SMOKE_TIMEOUT_MS must be positive');
100
+ const timer = setTimeout(
101
+ () => controller.abort(new Error(`Start timed out after ${timeout} ms`)),
102
+ timeout,
103
+ );
104
+ const interrupt = () => controller.abort(new Error('Start smoke test interrupted'));
105
+ const ports = [];
106
+ let buildPath;
107
+ let child;
108
+ let output = '';
109
+ let childError;
110
+ let lastHttpError;
111
+
112
+ process.once('SIGINT', interrupt);
113
+ process.once('SIGTERM', interrupt);
114
+
115
+ try {
116
+ ports.push(await reservePort());
117
+ ports.push(await reservePort());
118
+ signal.throwIfAborted();
119
+ const [server, client] = ports;
120
+
121
+ buildPath = await fs.mkdtemp(path.join(example, '.build-start-'));
122
+ const assetsPath = `assets-${path.basename(buildPath)}`;
123
+ const config = {
124
+ serverPort: server.port,
125
+ clientServerPort: client.port,
126
+ buildPath,
127
+ assetsPath,
128
+ };
129
+
130
+ await Promise.all(ports.map((port) => port.close()));
131
+ ports.length = 0;
132
+ child = spawn('yarn', ['start'], {
133
+ cwd: example,
134
+ env: { ...process.env, ARUI_SCRIPTS_CONFIG: JSON.stringify(config) },
135
+ detached: true,
136
+ stdio: ['ignore', 'pipe', 'pipe'],
137
+ });
138
+ child.on('error', (error) => {
139
+ childError = error;
140
+ });
141
+ const collect = (chunk) => {
142
+ // Retain startup diagnostics, without printing successful compiler output in hooks.
143
+ output = (output + stripVTControlCharacters(chunk.toString())).slice(-131072);
144
+ };
145
+
146
+ child.stdout.on('data', collect);
147
+ child.stderr.on('data', collect);
148
+
149
+ while (!signal.aborted) {
150
+ signal.throwIfAborted();
151
+ assertRunning(child, childError, output);
152
+
153
+ const compiled =
154
+ /\[Server\][^\n]*compiled successfully/.test(output) &&
155
+ /\[Client\][^\n]*compiled successfully/.test(output) &&
156
+ /worker[^\n]*compiled successfully/.test(output) &&
157
+ /Found 0 errors\. Watching for file changes/.test(output);
158
+
159
+ if (compiled) {
160
+ try {
161
+ await verifyHttp(`http://127.0.0.1:${client.port}`, assetsPath);
162
+ signal.throwIfAborted();
163
+ assertRunning(child, childError, output);
164
+ console.log(
165
+ 'example start: client, server, worker, SSR proxy and JavaScript are ready',
166
+ );
167
+
168
+ return;
169
+ } catch (error) {
170
+ lastHttpError = error;
171
+ }
172
+ }
173
+
174
+ await delay(100, undefined, { signal });
175
+ }
176
+ signal.throwIfAborted();
177
+ } catch (error) {
178
+ throw new Error(
179
+ `${signal.reason?.message || error.message}${
180
+ lastHttpError ? `\nHTTP check: ${lastHttpError.message}` : ''
181
+ }\n${output}`,
182
+ { cause: error },
183
+ );
184
+ } finally {
185
+ clearTimeout(timer);
186
+ process.removeListener('SIGINT', interrupt);
187
+ process.removeListener('SIGTERM', interrupt);
188
+ try {
189
+ await stop(child);
190
+ } finally {
191
+ await Promise.all(ports.map((port) => port.close()));
192
+ if (buildPath) await fs.rm(buildPath, { recursive: true, force: true });
193
+ }
194
+ }
195
+ }
196
+
197
+ main().catch((error) => {
198
+ console.error(error.message);
199
+ process.exitCode = 1;
200
+ });
@@ -0,0 +1,86 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const { spawn } = require('node:child_process');
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+
6
+ function checkTypeScriptWatch(watchCommand, project, timeoutMs = 15000) {
7
+ return new Promise((resolve, reject) => {
8
+ const child = spawn(process.execPath, [...watchCommand, '--pretty', 'false'], {
9
+ cwd: project,
10
+ detached: process.platform !== 'win32',
11
+ });
12
+ let output = '';
13
+ let phase = 'initial compilation';
14
+ let edits = 0;
15
+ let finished = false;
16
+ let failure;
17
+ let retry;
18
+ let killTimer;
19
+ const timer = setTimeout(
20
+ () => finish(new Error(`Watch timed out waiting for ${phase} (${edits} edits)`)),
21
+ timeoutMs,
22
+ );
23
+
24
+ function finish(error) {
25
+ if (finished) return;
26
+ finished = true;
27
+ failure = error;
28
+ clearTimeout(timer);
29
+ clearInterval(retry);
30
+ stop('SIGTERM');
31
+ killTimer = setTimeout(() => stop('SIGKILL'), 1000);
32
+ }
33
+
34
+ function stop(signal) {
35
+ try {
36
+ if (child.pid && process.platform !== 'win32') process.kill(-child.pid, signal);
37
+ else child.kill(signal);
38
+ } catch (error) {
39
+ if (error.code !== 'ESRCH') throw error;
40
+ }
41
+ }
42
+
43
+ function edit() {
44
+ if (finished) return;
45
+ try {
46
+ edits += 1;
47
+ fs.writeFileSync(
48
+ path.join(project, 'src/index.ts'),
49
+ `export const value: number = "wrong-${edits}";`,
50
+ );
51
+ } catch (error) {
52
+ finish(error);
53
+ }
54
+ }
55
+
56
+ function collect(chunk) {
57
+ output += chunk.toString();
58
+ if (finished) return;
59
+ if (phase === 'initial compilation' && /Found 0 errors/.test(output)) {
60
+ phase = 'change diagnostic';
61
+ // The summary can reach the parent before filesystem watchers are registered.
62
+ // Repeat distinct edits until an actual change diagnostic confirms watch works.
63
+ edit();
64
+ if (!finished) retry = setInterval(edit, 500);
65
+ }
66
+ if (phase === 'change diagnostic' && /TS2322/.test(output)) finish();
67
+ }
68
+
69
+ child.stdout.on('data', collect);
70
+ child.stderr.on('data', collect);
71
+ child.on('error', finish);
72
+ child.on('close', (code, signal) => {
73
+ clearTimeout(timer);
74
+ clearInterval(retry);
75
+ clearTimeout(killTimer);
76
+ if (!finished)
77
+ failure = new Error(
78
+ `Watch exited with ${code ?? signal} while waiting for ${phase}`,
79
+ );
80
+ if (failure) reject(new Error(`${failure.message}\n${output}`, { cause: failure }));
81
+ else resolve();
82
+ });
83
+ });
84
+ }
85
+
86
+ module.exports = { checkTypeScriptWatch };
@@ -0,0 +1,146 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires, global-require */
2
+ const assert = require('node:assert/strict');
3
+ const { spawnSync } = require('node:child_process');
4
+ const fs = require('node:fs');
5
+ const os = require('node:os');
6
+ const path = require('node:path');
7
+
8
+ const { rspack } = require('@rspack/core');
9
+
10
+ const { checkTypeScriptWatch } = require('./test-typescript-watch');
11
+
12
+ // Pass an installed TypeScript package directory; CI installs each version outside the workspace.
13
+ const typescriptPath = fs.realpathSync(process.argv[2]);
14
+ const temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'arui-typescript-integration-'));
15
+ // TS 7.0.2 ignores shallow watch roots such as /tmp/<fixture>/src on Linux.
16
+ // https://github.com/microsoft/TypeScript/issues/64425
17
+ const project = path.join(temporaryRoot, 'workspace', 'project');
18
+ const originalCwd = process.cwd();
19
+
20
+ function write(filename, content) {
21
+ const destination = path.join(project, filename);
22
+
23
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
24
+ fs.writeFileSync(destination, content);
25
+ }
26
+
27
+ async function main() {
28
+ write('package.json', JSON.stringify({ name: 'typescript-integration' }));
29
+ write('src/index.ts', 'export const value: number = 42;');
30
+ write('arui-scripts.config.ts', 'export default { serverPort: 4321 };');
31
+ write(
32
+ 'tsconfig.json',
33
+ JSON.stringify({
34
+ extends: path.join(__dirname, 'tsconfig.json'),
35
+ compilerOptions: { types: [], skipLibCheck: true },
36
+ include: ['src/**/*.ts'],
37
+ exclude: ['src/__tests__'],
38
+ }),
39
+ );
40
+ fs.mkdirSync(path.join(project, 'node_modules'), { recursive: true });
41
+ fs.symlinkSync(typescriptPath, path.join(project, 'node_modules/typescript'), 'junction');
42
+ process.chdir(project);
43
+
44
+ const { configs } = require('./build/configs/app-configs');
45
+ const { validateConfig } = require('./build/configs/app-configs/validate-config');
46
+ const { getProjectTypeScript } = require('./build/configs/util/typescript');
47
+ const { getTscWatchCommand } = require('./build/commands/util/tsc');
48
+ const { createSingleClientRspackConfig } = require('./build/configs/rspack.client');
49
+ const { swcClientConfig } = require('./build/configs/swc');
50
+ const jestSettings = require('./build/configs/jest/settings');
51
+ const { version } = getProjectTypeScript(project);
52
+
53
+ assert.equal(configs.serverPort, 4321);
54
+ const watchCommand = getTscWatchCommand(configs.tsconfig, project);
55
+ const [tsc] = watchCommand;
56
+ const versionResult = spawnSync(process.execPath, [tsc, '--version'], { encoding: 'utf8' });
57
+
58
+ assert.equal(versionResult.status, 0, versionResult.stderr);
59
+ assert(versionResult.stdout.includes(version));
60
+ ['codeLoader', 'jestCodeTransformer'].forEach((key) => {
61
+ const validate = () => validateConfig({ ...configs, [key]: 'tsc' });
62
+
63
+ if (Number.parseInt(version, 10) >= 7) {
64
+ assert.throws(validate, new RegExp(`${key}.*swc.*babel`));
65
+ } else {
66
+ assert.doesNotThrow(validate);
67
+ }
68
+ });
69
+
70
+ async function compile(valid) {
71
+ const original = createSingleClientRspackConfig('prod', {
72
+ main: [path.join(project, 'src/index.ts')],
73
+ });
74
+ const checker = original.plugins.find(
75
+ (plugin) => plugin?.constructor.name === 'TsCheckerRspackPlugin',
76
+ );
77
+
78
+ assert(checker, 'Production type checking must be enabled');
79
+ const compiler = rspack({
80
+ mode: 'development',
81
+ context: project,
82
+ entry: './src/index.ts',
83
+ output: { path: path.join(project, '.build'), filename: 'out.js' },
84
+ module: {
85
+ rules: [
86
+ {
87
+ test: /\.ts$/,
88
+ loader: require.resolve('swc-loader'),
89
+ options: swcClientConfig,
90
+ },
91
+ ],
92
+ },
93
+ plugins: [checker],
94
+ });
95
+
96
+ try {
97
+ const stats = await new Promise((resolve, reject) => {
98
+ compiler.run((error, result) => (error ? reject(error) : resolve(result)));
99
+ });
100
+ const { errors } = stats.toJson({ all: false, errors: true });
101
+
102
+ assert.equal(stats.hasErrors(), !valid, JSON.stringify(errors));
103
+ if (!valid) assert(errors.some((error) => /TS2322/.test(error.message)));
104
+ } finally {
105
+ await new Promise((resolve, reject) => {
106
+ compiler.close((error) => (error ? reject(error) : resolve()));
107
+ });
108
+ }
109
+ }
110
+
111
+ await compile(true);
112
+ write('src/index.ts', 'export const value: number = "wrong";');
113
+ await compile(false);
114
+ write('src/index.ts', 'export const value: number = 42;');
115
+ await checkTypeScriptWatch(watchCommand, project);
116
+ write('src/index.ts', 'export const value: number = 42;');
117
+ write(
118
+ 'src/__tests__/value.tests.ts',
119
+ 'import { value } from "../index"; test("SWC transforms TypeScript", () => expect(value).toBe(42));',
120
+ );
121
+ const jestResult = spawnSync(
122
+ process.execPath,
123
+ [
124
+ require.resolve('jest/bin/jest'),
125
+ '--runInBand',
126
+ '--config',
127
+ JSON.stringify({ ...jestSettings, rootDir: project, cache: false }),
128
+ ],
129
+ { encoding: 'utf8', timeout: 30000 },
130
+ );
131
+
132
+ assert.equal(jestResult.status, 0, `${jestResult.stdout}\n${jestResult.stderr}`);
133
+ console.log(
134
+ `TypeScript ${version}: config loading, CLI/watch, SWC, Rspack diagnostics and Jest passed`,
135
+ );
136
+ }
137
+
138
+ main()
139
+ .catch((error) => {
140
+ console.error(error);
141
+ process.exitCode = 1;
142
+ })
143
+ .finally(() => {
144
+ process.chdir(originalCwd);
145
+ fs.rmSync(temporaryRoot, { recursive: true, force: true });
146
+ });