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
package/.prettierignore
CHANGED
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
1
|
ts-jest[versions] (WARN) Version 6.0.2 of typescript installed has not been tested with ts-jest. If you're experiencing issues, consider using a supported version (>=4.3.0 <6.0.0-0). Please do not report issues in ts-jest if you are using unsupported versions.
|
|
2
|
-
PASS src/commands/util/__tests__/build-size-budgets.tests.ts (
|
|
2
|
+
PASS src/commands/util/__tests__/build-size-budgets.tests.ts (14.165 s)
|
|
3
3
|
PASS src/commands/bundle-diff/__tests__/report.tests.ts
|
|
4
|
-
PASS src/configs/util/__tests__/load-config-file.tests.ts
|
|
4
|
+
PASS src/configs/util/__tests__/load-config-file.tests.ts
|
|
5
5
|
PASS src/commands/util/__tests__/rsdoctor-snapshot.tests.ts
|
|
6
|
+
PASS src/commands/util/__tests__/cache-diagnostics.tests.ts
|
|
7
|
+
PASS src/configs/cache/__tests__/compression.tests.ts
|
|
6
8
|
PASS src/plugins/__tests__/attribute-module-css.tests.ts
|
|
7
9
|
PASS src/commands/util/__tests__/map-artifacts-config.tests.ts
|
|
10
|
+
PASS src/commands/util/__tests__/run-compilers.tests.ts
|
|
11
|
+
PASS src/configs/cache/__tests__/identity.tests.ts
|
|
8
12
|
PASS src/commands/bundle-diff/__tests__/snapshot.tests.ts
|
|
9
13
|
PASS src/commands/util/__tests__/artifacts-config.tests.ts
|
|
10
14
|
PASS src/configs/util/__tests__/find-plugin.tests.ts
|
|
15
|
+
PASS src/configs/cache/__tests__/storage.tests.ts
|
|
16
|
+
PASS src/configs/util/__tests__/dcb-cache.tests.ts
|
|
11
17
|
PASS src/configs/__tests__/rspack-client-assets.tests.ts
|
|
12
|
-
PASS src/commands/util/__tests__/run-compilers.tests.ts
|
|
13
|
-
PASS src/commands/util/__tests__/typescript-watch.tests.ts
|
|
14
18
|
PASS src/commands/build/__tests__/client.tests.ts
|
|
19
|
+
PASS src/commands/util/__tests__/typescript-watch.tests.ts
|
|
15
20
|
PASS src/bin/__tests__/create-cli.tests.ts
|
|
16
21
|
PASS src/plugins/postcss-global-variables/utils/__tests__/add-global-variable.tests.ts
|
|
17
22
|
PASS src/commands/bundle-diff/__tests__/comment.tests.ts
|
|
18
23
|
PASS src/configs/app-configs/__tests__/typescript.tests.ts
|
|
24
|
+
PASS src/commands/build/__tests__/build-wrapper.tests.ts
|
|
19
25
|
PASS src/configs/app-configs/__tests__/update-with-presets.tests.ts
|
|
20
26
|
PASS src/configs/util/__tests__/create-watch-ignore-regex.tests.ts
|
|
21
27
|
PASS src/configs/util/__tests__/apply-overrides.tests.ts
|
|
22
28
|
PASS src/configs/jest/__tests__/settings.tests.ts
|
|
23
29
|
PASS src/configs/app-configs/__tests__/update-with-env.tests.ts
|
|
30
|
+
PASS src/commands/util/__tests__/graceful-shutdown.tests.ts
|
|
24
31
|
PASS src/configs/__tests__/rspack-client-modules.tests.ts
|
|
25
32
|
PASS src/commands/bundle-diff/__tests__/index.tests.ts
|
|
26
33
|
PASS src/configs/app-configs/__tests__/update-with-package.tests.ts
|
|
@@ -34,8 +41,8 @@ PASS src/configs/app-configs/__tests__/validate-build-size-budgets.tests.ts
|
|
|
34
41
|
PASS src/plugins/postcss-global-variables/utils/__tests__/get-media-query-name.tests.ts
|
|
35
42
|
PASS src/configs/app-configs/__tests__/validate-settings-keys.tests.ts
|
|
36
43
|
|
|
37
|
-
Test Suites:
|
|
38
|
-
Tests:
|
|
44
|
+
Test Suites: 41 passed, 41 total
|
|
45
|
+
Tests: 260 passed, 260 total
|
|
39
46
|
Snapshots: 0 total
|
|
40
|
-
Time:
|
|
47
|
+
Time: 25.192 s
|
|
41
48
|
Ran all test suites.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# arui-scripts
|
|
2
2
|
|
|
3
|
+
## 26.1.0-persistent-cache-beta-20261103084257
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`fee43779`](https://github.com/core-ds/arui-scripts/commit/fee43779196b3892084f98deab2e25d1c5937b41) Thanks [@dmitrbrvsk](https://github.com/dmitrbrvsk)! - **Что изменилось**
|
|
8
|
+
Добавлена диагностика persistent cache для проверки локально и в Jenkins: настройки каждого компилятора, подтвержденное восстановление snapshot, инвалидация, счетчики сжатия и завершение закрытия компилятора. Значения переменных окружения не выводятся.
|
|
9
|
+
|
|
10
|
+
**Что делать потребителю**
|
|
11
|
+
При включенном `persistentCache` задайте `ARUI_SCRIPTS_CACHE_DEBUG=1` на время проверки. Сравните холодную и повторную сборки по событиям с префиксом `[arui-scripts cache]`. Без переменной дополнительный лог выключен.
|
|
12
|
+
|
|
13
|
+
- [`01cc0bf9`](https://github.com/core-ds/arui-scripts/commit/01cc0bf9f5a35abf394ab538ff0fbc086468fa0a) Thanks [@dmitrbrvsk](https://github.com/dmitrbrvsk)! - **Что изменилось**
|
|
14
|
+
При включенном `persistentCache` результаты gzip, Brotli и DCB сохраняются между сборками. Изменение исходных данных, параметров сжатия или словаря вызывает пересчет; поврежденные записи восстанавливаются автоматически.
|
|
15
|
+
|
|
16
|
+
**Что делать потребителю**
|
|
17
|
+
Включите `persistentCache: true`. Для сохранения только кеша компиляции задайте `persistentCache: { compression: false }`. В Jenkins сохраняйте и восстанавливайте каталог `.cache/arui-scripts/rspack` целиком.
|
|
18
|
+
|
|
19
|
+
- [`c747e347`](https://github.com/core-ds/arui-scripts/commit/c747e3479994c418e4d7c7589a445fc87582e28c) Thanks [@dmitrbrvsk](https://github.com/dmitrbrvsk)! - **Что изменилось**
|
|
20
|
+
Добавлен постоянный кеш Rspack для dev и production-сборок с настройкой `persistentCache`, командами `cache:info` и `cache:clear` и сохранением данных при штатном завершении компиляторов. Добавлен пример использования в Jenkins.
|
|
21
|
+
|
|
22
|
+
**Что делать потребителю**
|
|
23
|
+
Для включения добавьте `persistentCache: true` в конфигурацию arui-scripts и `.cache/arui-scripts/` в `.gitignore` и `.prettierignore` приложения. В Jenkins настройте восстановление и сохранение этого каталога между сборками. По умолчанию постоянный кеш выключен.
|
|
24
|
+
|
|
3
25
|
## 26.0.0
|
|
4
26
|
|
|
5
27
|
### Major Changes
|
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ yarn start
|
|
|
19
19
|
CLI `arui-scripts` поддерживает глобальные флаги `--help`, `--version` и справку по командам
|
|
20
20
|
`arui-scripts <команда> --help`. Подробнее в [CLI](docs/cli.md).
|
|
21
21
|
|
|
22
|
+
Для повторных запусков dev и production-сборок можно включить [постоянный кеш Rspack](docs/persistent-cache.md)
|
|
23
|
+
настройкой `persistentCache: true`. По умолчанию он выключен. В документации есть пример подключения к Jenkins.
|
|
24
|
+
|
|
22
25
|
Команду `bundle-diff` можно запускать локально или в CI/CD.
|
|
23
26
|
|
|
24
27
|
Для анализа изменений клиентских бандлов необходимы snapshot двух production сборок:
|
|
@@ -4,6 +4,19 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.commands = void 0;
|
|
6
6
|
exports.commands = [
|
|
7
|
+
{
|
|
8
|
+
name: 'cache:info',
|
|
9
|
+
description: 'Показать состояние постоянного кеша Rspack',
|
|
10
|
+
options: [{ flags: '--json', description: 'Вывести данные в JSON' }],
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
12
|
+
load: (options) => require('../commands/cache').cacheInfo(Boolean(options.json)),
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'cache:clear',
|
|
16
|
+
description: 'Очистить постоянный кеш Rspack после остановки сборки',
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
18
|
+
load: () => require('../commands/cache').cacheClear(),
|
|
19
|
+
},
|
|
7
20
|
{
|
|
8
21
|
name: 'start',
|
|
9
22
|
description: 'Dev сервер для клиента и серверный код в watch режиме',
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Configuration, type MultiStats, type Stats } from '@rspack/core';
|
|
2
|
-
type
|
|
2
|
+
type CompilationResult = {
|
|
3
3
|
stats: Stats | MultiStats;
|
|
4
4
|
warnings: string[];
|
|
5
|
-
previousFileSizes: unknown;
|
|
6
5
|
};
|
|
7
|
-
declare function build(config: Configuration | Configuration[],
|
|
6
|
+
declare function build(config: Configuration | Configuration[], beforeClose?: (result: CompilationResult) => void | Promise<void>): Promise<{
|
|
7
|
+
warnings: string[];
|
|
8
|
+
}>;
|
|
8
9
|
export default build;
|
|
@@ -1,40 +1,76 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const core_1 = require("@rspack/core");
|
|
7
15
|
const chalk_1 = __importDefault(require("chalk"));
|
|
16
|
+
const create_compiler_1 = require("../util/create-compiler");
|
|
8
17
|
const format_rspack_messages_1 = require("../util/format-rspack-messages");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return
|
|
12
|
-
compiler
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const graceful_shutdown_1 = require("../util/graceful-shutdown");
|
|
19
|
+
function build(config, beforeClose) {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
const compiler = (0, create_compiler_1.createCompiler)(config);
|
|
22
|
+
let failed = false;
|
|
23
|
+
let failure;
|
|
24
|
+
let warnings = [];
|
|
25
|
+
try {
|
|
26
|
+
const result = yield new Promise((resolve, reject) => {
|
|
27
|
+
compiler.run((err, stats) => {
|
|
28
|
+
try {
|
|
29
|
+
if (err)
|
|
30
|
+
return reject(err);
|
|
31
|
+
if (!stats)
|
|
32
|
+
return reject(new Error('Compiler did not return build statistics'));
|
|
33
|
+
const messages = (0, format_rspack_messages_1.formatRspackMessages)(stats.toJson({}));
|
|
34
|
+
if (messages.errors.length) {
|
|
35
|
+
return reject(new Error(messages.errors[0]));
|
|
36
|
+
}
|
|
37
|
+
if (process.env.CI &&
|
|
38
|
+
process.env.CI.toLowerCase() !== 'false' &&
|
|
39
|
+
messages.warnings.length) {
|
|
40
|
+
console.log(chalk_1.default.yellow('\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
41
|
+
'Most CI servers set it automatically.\n'));
|
|
42
|
+
return reject(new Error(messages.warnings.join('\n\n')));
|
|
43
|
+
}
|
|
44
|
+
return resolve({ stats, warnings: messages.warnings });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return reject(error);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
// Native Stats/Compilation become invalid after close(). Consume them before flushing.
|
|
52
|
+
yield (beforeClose === null || beforeClose === void 0 ? void 0 : beforeClose(result));
|
|
53
|
+
warnings = result.warnings;
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
failed = true;
|
|
57
|
+
failure = error;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
yield (0, graceful_shutdown_1.closeCompiler)(compiler);
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
if (failed) {
|
|
64
|
+
console.error('Failed to close Rspack compiler:', error);
|
|
24
65
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
console.log(chalk_1.default.yellow('\nTreating warnings as errors because process.env.CI = true.\n' +
|
|
29
|
-
'Most CI servers set it automatically.\n'));
|
|
30
|
-
return reject(new Error(messages.warnings.join('\n\n')));
|
|
66
|
+
else {
|
|
67
|
+
failed = true;
|
|
68
|
+
failure = error;
|
|
31
69
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
37
|
-
});
|
|
70
|
+
}
|
|
71
|
+
if (failed)
|
|
72
|
+
throw failure;
|
|
73
|
+
return { warnings };
|
|
38
74
|
});
|
|
39
75
|
}
|
|
40
76
|
exports.default = build;
|
|
@@ -40,26 +40,27 @@ function main() {
|
|
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
try {
|
|
42
42
|
const snapshot = yield (0, rsdoctor_snapshot_1.enableRsdoctor)(rspack_client_prod_1.rspackClientConfig, process.env.ARUI_SCRIPTS_RSDOCTOR_OUTPUT, app_configs_1.configs.appSrc);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
console.log(chalk_1.default.green('Client compiled successfully.\n'));
|
|
52
|
-
}
|
|
53
|
-
if (Array.isArray(rspack_client_prod_1.rspackClientConfig)) {
|
|
54
|
-
for (const [index, conf] of rspack_client_prod_1.rspackClientConfig.entries()) {
|
|
55
|
-
// measure builds sequentially to bound gzip memory use
|
|
56
|
-
// eslint-disable-next-line no-await-in-loop
|
|
57
|
-
yield printOutputSizes(conf, stats.stats[index]);
|
|
43
|
+
yield (0, build_wrapper_1.default)(rspack_client_prod_1.rspackClientConfig, (_a) => __awaiter(this, [_a], void 0, function* ({ stats, warnings }) {
|
|
44
|
+
if (warnings.length) {
|
|
45
|
+
console.log(chalk_1.default.yellow('Client compiled with warnings.\n'));
|
|
46
|
+
console.log(warnings.join('\n\n'));
|
|
47
|
+
console.log(`Search for the ${chalk_1.default.underline(chalk_1.default.yellow('keywords'))} to learn more about each warning.`);
|
|
48
|
+
console.log(`To ignore, add ${chalk_1.default.cyan('// eslint-disable-next-line')} to the line before.`);
|
|
58
49
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
else {
|
|
51
|
+
console.log(chalk_1.default.green('Client compiled successfully.\n'));
|
|
52
|
+
}
|
|
53
|
+
if (Array.isArray(rspack_client_prod_1.rspackClientConfig)) {
|
|
54
|
+
for (const [index, conf] of rspack_client_prod_1.rspackClientConfig.entries()) {
|
|
55
|
+
// measure builds sequentially to bound gzip memory use
|
|
56
|
+
// eslint-disable-next-line no-await-in-loop
|
|
57
|
+
yield printOutputSizes(conf, stats.stats[index]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
yield printOutputSizes(rspack_client_prod_1.rspackClientConfig, stats);
|
|
62
|
+
}
|
|
63
|
+
}));
|
|
63
64
|
if (snapshot) {
|
|
64
65
|
yield (0, rsdoctor_snapshot_1.writeRsdoctorSnapshot)(snapshot);
|
|
65
66
|
}
|
|
@@ -35,6 +35,8 @@ const bundleAnalyzerStatsOptions = {
|
|
|
35
35
|
: [rspack_client_prod_1.rspackClientConfig];
|
|
36
36
|
/* eslint-disable no-param-reassign */
|
|
37
37
|
const promises = clientRspackConfigs.map((rspackConfig, i) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
// Profiling builds use temporary outputs and must collect a fresh module graph.
|
|
39
|
+
rspackConfig.cache = false;
|
|
38
40
|
const tmpDir = yield (0, make_tmp_dir_1.makeTmpDir)(i.toString());
|
|
39
41
|
const rspackStatsOptions = Object.assign(Object.assign({}, (typeof rspackConfig.stats === 'object' ? rspackConfig.stats : {})), bundleAnalyzerStatsOptions);
|
|
40
42
|
rspackConfig.plugins = [
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cacheInfo = cacheInfo;
|
|
4
|
+
exports.cacheClear = cacheClear;
|
|
5
|
+
/* eslint-disable global-require, @typescript-eslint/no-var-requires -- CLI loads optional configs only for info. */
|
|
6
|
+
const app_configs_1 = require("../configs/app-configs");
|
|
7
|
+
const settings_1 = require("../configs/cache/settings");
|
|
8
|
+
const storage_1 = require("../configs/cache/storage");
|
|
9
|
+
const persistent_cache_1 = require("../configs/persistent-cache");
|
|
10
|
+
function configuredCaches(json) {
|
|
11
|
+
const { log } = console;
|
|
12
|
+
// Overrides may log while loading. Keep machine-readable stdout valid JSON.
|
|
13
|
+
if (json)
|
|
14
|
+
console.log = (...args) => console.error(...args);
|
|
15
|
+
try {
|
|
16
|
+
// Resolve overrides for diagnostics only; no compiler is created and no cache is written.
|
|
17
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
18
|
+
const dev = require('../configs/rspack.client.dev').config;
|
|
19
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
20
|
+
const prod = require('../configs/rspack.client.prod').rspackClientConfig;
|
|
21
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
22
|
+
const serverDev = app_configs_1.configs.clientOnly
|
|
23
|
+
? []
|
|
24
|
+
: require('../configs/rspack.server.dev').rspackServerConfig;
|
|
25
|
+
// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
|
|
26
|
+
const serverProd = app_configs_1.configs.clientOnly
|
|
27
|
+
? []
|
|
28
|
+
: require('../configs/rspack.server.prod').rspackServerConfig;
|
|
29
|
+
return [dev, prod, serverDev, serverProd].flatMap(persistent_cache_1.describeCompilerCaches);
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
console.log = log;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function cacheInfo(json) {
|
|
36
|
+
const directory = (0, settings_1.cacheDirectory)(app_configs_1.configs);
|
|
37
|
+
const settings = (0, settings_1.cacheSettings)(app_configs_1.configs);
|
|
38
|
+
const configured = configuredCaches(json);
|
|
39
|
+
const info = Object.assign({ directory, enabled: !!settings, modes: settings ? settings.modes || ['dev', 'production'] : [], configured, portableCrossPathReuse: false }, (0, storage_1.inspectCache)(directory));
|
|
40
|
+
if (json)
|
|
41
|
+
console.log(JSON.stringify(info, null, 2));
|
|
42
|
+
else {
|
|
43
|
+
console.log(`Rspack cache: ${directory}\nEnabled: ${info.enabled}\nModes: ${info.modes.join(', ') || 'none'}\nSize: ${info.bytes} bytes`);
|
|
44
|
+
info.namespaces.forEach((namespace) => console.log(` ${namespace.name}: ${namespace.dependencies} dependencies, fingerprint ${namespace.fingerprint.slice(0, 12)}`));
|
|
45
|
+
configured
|
|
46
|
+
.filter((cache) => cache.policy === 'custom')
|
|
47
|
+
.forEach((cache) => console.log(` ${cache.name}/${cache.mode}: custom cache override (not managed)`));
|
|
48
|
+
if (!info.exists)
|
|
49
|
+
console.log('Cache does not exist yet.');
|
|
50
|
+
console.log('Raw Rspack cache overrides are custom and are not managed by cache:clear.');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function cacheClear() {
|
|
54
|
+
const directory = (0, settings_1.cacheDirectory)(app_configs_1.configs);
|
|
55
|
+
(0, storage_1.clearCache)(directory);
|
|
56
|
+
console.log(`Rspack cache cleared: ${directory}`);
|
|
57
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Compiler, type Configuration, type MultiCompiler } from '@rspack/core';
|
|
2
|
+
/** Only explicit snapshot evidence counts as disk reuse; generic recovery also occurs cold. */
|
|
3
|
+
export declare function summarizeNativeCache(messages: string[]): {
|
|
4
|
+
snapshot: string;
|
|
5
|
+
reason: string;
|
|
6
|
+
errors: number;
|
|
7
|
+
trackedBuildDependencies: number | undefined;
|
|
8
|
+
};
|
|
9
|
+
/** Debug output contains fixed labels, hashes and counters, never raw native logs or env values. */
|
|
10
|
+
export declare function attachCacheDiagnostics(compiler: Compiler | MultiCompiler, configuration: Configuration | Configuration[]): ((error: unknown, durationMs: number) => void) | undefined;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.summarizeNativeCache = summarizeNativeCache;
|
|
7
|
+
exports.attachCacheDiagnostics = attachCacheDiagnostics;
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const core_1 = require("@rspack/core");
|
|
10
|
+
const persistent_cache_1 = require("../../configs/persistent-cache");
|
|
11
|
+
const compression_cache_1 = require("../../plugins/compression-cache");
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
|
|
13
|
+
const { version } = require('../../../package.json');
|
|
14
|
+
const PREFIX = '[arui-scripts cache] ';
|
|
15
|
+
/** Only explicit snapshot evidence counts as disk reuse; generic recovery also occurs cold. */
|
|
16
|
+
function summarizeNativeCache(messages) {
|
|
17
|
+
let snapshot = 'unknown';
|
|
18
|
+
let reason = 'no-native-evidence';
|
|
19
|
+
if (messages.some((message) => message.includes('snapshot restored with detected changed dependencies'))) {
|
|
20
|
+
snapshot = 'invalidated';
|
|
21
|
+
reason = 'dependencies-changed';
|
|
22
|
+
}
|
|
23
|
+
else if (messages.some((message) => message.includes('snapshot restored with no changed dependencies'))) {
|
|
24
|
+
snapshot = 'hit';
|
|
25
|
+
reason = 'snapshot-unchanged';
|
|
26
|
+
}
|
|
27
|
+
else if (messages.some((message) => /version.*(does not match|doesn't match)/i.test(message))) {
|
|
28
|
+
snapshot = 'invalidated';
|
|
29
|
+
reason = 'version-changed';
|
|
30
|
+
}
|
|
31
|
+
else if (messages.some((message) => /build dependencies.*(invalid|changed)/i.test(message))) {
|
|
32
|
+
snapshot = 'invalidated';
|
|
33
|
+
reason = 'build-dependencies-changed';
|
|
34
|
+
}
|
|
35
|
+
else if (messages.some((message) => message.includes('read snapshot from persistent cache'))) {
|
|
36
|
+
snapshot = 'cold';
|
|
37
|
+
reason = 'no-restored-snapshot';
|
|
38
|
+
}
|
|
39
|
+
const errors = messages.filter((message) => /(?:decode|recovery|save|reset) failed/i.test(message)).length;
|
|
40
|
+
if (errors && snapshot !== 'hit' && snapshot !== 'invalidated') {
|
|
41
|
+
snapshot = 'unavailable';
|
|
42
|
+
reason = 'native-cache-error';
|
|
43
|
+
}
|
|
44
|
+
const tracked = messages.join('\n').match(/build dependencies are valid \((\d+) tracked\)/);
|
|
45
|
+
return {
|
|
46
|
+
snapshot,
|
|
47
|
+
reason,
|
|
48
|
+
errors,
|
|
49
|
+
trackedBuildDependencies: tracked ? Number(tracked[1]) : undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** Debug output contains fixed labels, hashes and counters, never raw native logs or env values. */
|
|
53
|
+
function attachCacheDiagnostics(compiler, configuration) {
|
|
54
|
+
var _a;
|
|
55
|
+
if (!['1', 'true'].includes(((_a = process.env.ARUI_SCRIPTS_CACHE_DEBUG) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || ''))
|
|
56
|
+
return undefined;
|
|
57
|
+
const children = 'compilers' in compiler ? compiler.compilers : [compiler];
|
|
58
|
+
const descriptions = (0, persistent_cache_1.describeCompilerCaches)(configuration);
|
|
59
|
+
const reporters = children.map((child, index) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const description = descriptions[index];
|
|
62
|
+
const { cache } = child.options;
|
|
63
|
+
const persistent = typeof cache === 'object' && cache.type === 'persistent' ? cache : undefined;
|
|
64
|
+
const common = {
|
|
65
|
+
schemaVersion: 1,
|
|
66
|
+
pid: process.pid,
|
|
67
|
+
compiler: description.name,
|
|
68
|
+
target: description.target,
|
|
69
|
+
mode: description.mode,
|
|
70
|
+
namespace: description.namespace,
|
|
71
|
+
};
|
|
72
|
+
const write = (event, details) => {
|
|
73
|
+
console.error(`${PREFIX}${JSON.stringify(Object.assign(Object.assign(Object.assign({}, common), { event }), details))}`);
|
|
74
|
+
};
|
|
75
|
+
let run = 0;
|
|
76
|
+
let closed = false;
|
|
77
|
+
let cacheType = cache ? 'memory' : 'disabled';
|
|
78
|
+
let persistence = 'disabled';
|
|
79
|
+
if (persistent) {
|
|
80
|
+
cacheType = 'persistent';
|
|
81
|
+
persistence = persistent.readonly ? 'readonly' : 'read-write';
|
|
82
|
+
}
|
|
83
|
+
write('configured', {
|
|
84
|
+
policy: description.policy,
|
|
85
|
+
reason: description.reason,
|
|
86
|
+
cacheType,
|
|
87
|
+
location: ((_a = persistent === null || persistent === void 0 ? void 0 : persistent.storage) === null || _a === void 0 ? void 0 : _a.type) === 'filesystem'
|
|
88
|
+
? persistent.storage.location
|
|
89
|
+
: undefined,
|
|
90
|
+
fingerprint: description.fingerprint,
|
|
91
|
+
versionHash: persistent
|
|
92
|
+
? crypto_1.default
|
|
93
|
+
.createHash('sha256')
|
|
94
|
+
.update(persistent.version || '')
|
|
95
|
+
.digest('hex')
|
|
96
|
+
: undefined,
|
|
97
|
+
readonly: (persistent === null || persistent === void 0 ? void 0 : persistent.readonly) || false,
|
|
98
|
+
portable: (persistent === null || persistent === void 0 ? void 0 : persistent.portable) || false,
|
|
99
|
+
compression: !!(0, compression_cache_1.getCompressionCache)(child),
|
|
100
|
+
toolchain: {
|
|
101
|
+
arui: version,
|
|
102
|
+
rspack: core_1.rspackVersion,
|
|
103
|
+
node: process.versions.node,
|
|
104
|
+
platform: process.platform,
|
|
105
|
+
arch: process.arch,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
child.hooks.done.tap('AruiCacheDiagnostics', (stats) => {
|
|
109
|
+
var _a, _b, _c;
|
|
110
|
+
run += 1;
|
|
111
|
+
try {
|
|
112
|
+
const snapshot = persistent && run === 1
|
|
113
|
+
? stats.toJson({
|
|
114
|
+
all: false,
|
|
115
|
+
logging: 'verbose',
|
|
116
|
+
loggingDebug: /^rspack\.persistentCache$/,
|
|
117
|
+
})
|
|
118
|
+
: undefined;
|
|
119
|
+
const messages = ((_c = (_b = (_a = snapshot === null || snapshot === void 0 ? void 0 : snapshot.logging) === null || _a === void 0 ? void 0 : _a['rspack.persistentCache']) === null || _b === void 0 ? void 0 : _b.entries) === null || _c === void 0 ? void 0 : _c.map((entry) => entry.message || '')) || [];
|
|
120
|
+
const compression = (0, compression_cache_1.getCompressionCache)(child);
|
|
121
|
+
let native = { snapshot: 'disabled' };
|
|
122
|
+
if (persistent) {
|
|
123
|
+
native =
|
|
124
|
+
run === 1 ? summarizeNativeCache(messages) : { snapshot: 'in-process' };
|
|
125
|
+
}
|
|
126
|
+
write('compilation', {
|
|
127
|
+
run,
|
|
128
|
+
result: stats.hasErrors() ? 'errors' : 'success',
|
|
129
|
+
durationMs: stats.endTime !== undefined && stats.startTime !== undefined
|
|
130
|
+
? stats.endTime - stats.startTime
|
|
131
|
+
: undefined,
|
|
132
|
+
native,
|
|
133
|
+
compression: compression
|
|
134
|
+
? Object.assign({ enabled: true }, compression.stats) : { enabled: false },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (_d) {
|
|
138
|
+
write('diagnostic-error', { run, reason: 'stats-unavailable' });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
child.hooks.failed.tap('AruiCacheDiagnostics', () => write('compilation', { run: run + 1, result: 'failed' }));
|
|
142
|
+
return (error, durationMs) => {
|
|
143
|
+
if (closed)
|
|
144
|
+
return;
|
|
145
|
+
write('close', {
|
|
146
|
+
result: error ? 'failed' : 'completed',
|
|
147
|
+
durationMs,
|
|
148
|
+
persistence,
|
|
149
|
+
});
|
|
150
|
+
closed = !error;
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
return (error, durationMs) => reporters.forEach((report) => report(error, durationMs));
|
|
154
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type Compiler, type Configuration, type MultiCompiler } from '@rspack/core';
|
|
2
|
+
/** Keep cache ownership until native close completes, including the error path. */
|
|
3
|
+
export declare function createCompiler(configuration: Configuration): Compiler;
|
|
4
|
+
export declare function createCompiler(configuration: Configuration[]): MultiCompiler;
|
|
5
|
+
export declare function createCompiler(configuration: Configuration | Configuration[]): Compiler | MultiCompiler;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCompiler = createCompiler;
|
|
4
|
+
const core_1 = require("@rspack/core");
|
|
5
|
+
const persistent_cache_1 = require("../../configs/persistent-cache");
|
|
6
|
+
const cache_diagnostics_1 = require("./cache-diagnostics");
|
|
7
|
+
function createCompiler(configuration) {
|
|
8
|
+
const releases = (0, persistent_cache_1.acquireCompilerCaches)(configuration);
|
|
9
|
+
const release = () => {
|
|
10
|
+
releases.splice(0).forEach((callback) => callback());
|
|
11
|
+
};
|
|
12
|
+
try {
|
|
13
|
+
const compiler = (0, core_1.rspack)(configuration);
|
|
14
|
+
const reportClose = (0, cache_diagnostics_1.attachCacheDiagnostics)(compiler, configuration);
|
|
15
|
+
const close = compiler.close.bind(compiler);
|
|
16
|
+
compiler.close = (callback) => {
|
|
17
|
+
const started = performance.now();
|
|
18
|
+
close((error) => {
|
|
19
|
+
try {
|
|
20
|
+
release();
|
|
21
|
+
}
|
|
22
|
+
catch (releaseError) {
|
|
23
|
+
reportClose === null || reportClose === void 0 ? void 0 : reportClose(error || releaseError, Math.round(performance.now() - started));
|
|
24
|
+
callback(error || releaseError);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
reportClose === null || reportClose === void 0 ? void 0 : reportClose(error, Math.round(performance.now() - started));
|
|
28
|
+
callback(error);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
return compiler;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
release();
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const SHUTDOWN_TIMEOUT = 10000;
|
|
2
|
+
/** A second signal forces termination; the first allows native cache writes to finish. */
|
|
3
|
+
export declare function registerShutdown(stop: () => Promise<void>): () => void;
|
|
4
|
+
export declare function closeCompiler(compiler: {
|
|
5
|
+
close: (callback: (error?: Error | null) => void) => void;
|
|
6
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SHUTDOWN_TIMEOUT = void 0;
|
|
4
|
+
exports.registerShutdown = registerShutdown;
|
|
5
|
+
exports.closeCompiler = closeCompiler;
|
|
6
|
+
exports.SHUTDOWN_TIMEOUT = 10000;
|
|
7
|
+
/** A second signal forces termination; the first allows native cache writes to finish. */
|
|
8
|
+
function registerShutdown(stop) {
|
|
9
|
+
let stopping = false;
|
|
10
|
+
let timer;
|
|
11
|
+
const dispose = () => {
|
|
12
|
+
process.removeListener('SIGINT', onSignal);
|
|
13
|
+
process.removeListener('SIGTERM', onSignal);
|
|
14
|
+
if (timer)
|
|
15
|
+
clearTimeout(timer);
|
|
16
|
+
};
|
|
17
|
+
function onSignal() {
|
|
18
|
+
if (stopping) {
|
|
19
|
+
console.error('Shutdown interrupted by a second signal; cache may not be saved.');
|
|
20
|
+
dispose();
|
|
21
|
+
process.exit(1);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
stopping = true;
|
|
25
|
+
timer = setTimeout(() => {
|
|
26
|
+
console.error('Compiler shutdown timed out after 10 seconds; cache may not be saved.');
|
|
27
|
+
dispose();
|
|
28
|
+
process.exit(1);
|
|
29
|
+
}, exports.SHUTDOWN_TIMEOUT);
|
|
30
|
+
stop().then(() => {
|
|
31
|
+
dispose();
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}, (error) => {
|
|
34
|
+
console.error('Compiler shutdown failed:', error);
|
|
35
|
+
dispose();
|
|
36
|
+
process.exit(1);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
process.on('SIGINT', onSignal);
|
|
40
|
+
process.on('SIGTERM', onSignal);
|
|
41
|
+
return dispose;
|
|
42
|
+
}
|
|
43
|
+
function closeCompiler(compiler) {
|
|
44
|
+
return new Promise((resolve, reject) => {
|
|
45
|
+
compiler.close((error) => {
|
|
46
|
+
if (error)
|
|
47
|
+
reject(error);
|
|
48
|
+
else
|
|
49
|
+
resolve();
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
@@ -76,6 +76,9 @@ function enableRsdoctor(configuration, outputDirectory, sourceRoot) {
|
|
|
76
76
|
yield Promise.all(configurations.map((_, index) => fs_extra_1.default.remove(path_1.default.join(directory, `client-${index}/rsdoctor-data.json`))));
|
|
77
77
|
const { RsdoctorRspackPlugin } = yield import('@rsdoctor/rspack-plugin');
|
|
78
78
|
const bundles = configurations.map((config, index) => {
|
|
79
|
+
// Rsdoctor needs fresh attribution data even when application compilation is cached.
|
|
80
|
+
// eslint-disable-next-line no-param-reassign
|
|
81
|
+
config.cache = false;
|
|
79
82
|
const reportDir = path_1.default.join(directory, `client-${index}`);
|
|
80
83
|
// eslint-disable-next-line no-param-reassign
|
|
81
84
|
config.plugins = [
|