@angular/build 22.2.0-next.6 → 22.2.0-rc.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.
- package/builders.json +1 -1
- package/package.json +15 -15
- package/src/builders/application/build-action.js +1 -0
- package/src/builders/application/build-action.js.map +1 -1
- package/src/builders/application/chunk-optimizer.js +4 -1
- package/src/builders/application/chunk-optimizer.js.map +1 -1
- package/src/builders/application/execute-post-bundle.js +2 -2
- package/src/builders/application/execute-post-bundle.js.map +1 -1
- package/src/builders/application/i18n.d.ts +3 -1
- package/src/builders/application/i18n.js +4 -2
- package/src/builders/application/i18n.js.map +1 -1
- package/src/builders/application/options.js +5 -2
- package/src/builders/application/options.js.map +1 -1
- package/src/builders/application/schema.d.ts +2 -1
- package/src/builders/application/schema.js.map +1 -1
- package/src/builders/application/schema.json +1 -2
- package/src/builders/dev-server/options.d.ts +4 -1
- package/src/builders/dev-server/options.js +1 -0
- package/src/builders/dev-server/options.js.map +1 -1
- package/src/builders/dev-server/vite/index.js +1 -1
- package/src/builders/dev-server/vite/index.js.map +1 -1
- package/src/builders/dev-server/vite/server.js +1 -1
- package/src/builders/dev-server/vite/server.js.map +1 -1
- package/src/builders/unit-test/runners/vitest/plugins.d.ts +3 -4
- package/src/builders/unit-test/runners/vitest/plugins.js +2 -0
- package/src/builders/unit-test/runners/vitest/plugins.js.map +1 -1
- package/src/builders/unit-test/schema.d.ts +3 -2
- package/src/builders/unit-test/schema.js.map +1 -1
- package/src/builders/unit-test/schema.json +3 -2
- package/src/private.d.ts +0 -1
- package/src/private.js +1 -3
- package/src/private.js.map +1 -1
- package/src/tools/angular/compilation/aot-compilation.d.ts +1 -1
- package/src/tools/angular/compilation/aot-compilation.js +1 -3
- package/src/tools/angular/compilation/aot-compilation.js.map +1 -1
- package/src/tools/angular/compilation/jit-compilation.d.ts +1 -1
- package/src/tools/angular/compilation/jit-compilation.js +1 -3
- package/src/tools/angular/compilation/jit-compilation.js.map +1 -1
- package/src/tools/angular/compilation/typescript-compilation.d.ts +8 -1
- package/src/tools/angular/compilation/typescript-compilation.js +10 -2
- package/src/tools/angular/compilation/typescript-compilation.js.map +1 -1
- package/src/tools/esbuild/angular/compiler-plugin.js +42 -18
- package/src/tools/esbuild/angular/compiler-plugin.js.map +1 -1
- package/src/tools/esbuild/angular/component-stylesheets.js +4 -1
- package/src/tools/esbuild/angular/component-stylesheets.js.map +1 -1
- package/src/tools/esbuild/application-code-bundle.js +3 -3
- package/src/tools/esbuild/application-code-bundle.js.map +1 -1
- package/src/tools/esbuild/bundler-context.js +7 -4
- package/src/tools/esbuild/bundler-context.js.map +1 -1
- package/src/tools/esbuild/cache.d.ts +17 -10
- package/src/tools/esbuild/cache.js +60 -47
- package/src/tools/esbuild/cache.js.map +1 -1
- package/src/tools/esbuild/i18n-inliner.d.ts +7 -1
- package/src/tools/esbuild/i18n-inliner.js +24 -7
- package/src/tools/esbuild/i18n-inliner.js.map +1 -1
- package/src/tools/esbuild/index-html-generator.js +1 -1
- package/src/tools/esbuild/index-html-generator.js.map +1 -1
- package/src/tools/esbuild/javascript-transformer.d.ts +25 -8
- package/src/tools/esbuild/javascript-transformer.js +86 -67
- package/src/tools/esbuild/javascript-transformer.js.map +1 -1
- package/src/tools/esbuild/lmdb-cache-store.js +1 -1
- package/src/tools/esbuild/lmdb-cache-store.js.map +1 -1
- package/src/tools/esbuild/persistent-load-result-cache.js +9 -31
- package/src/tools/esbuild/persistent-load-result-cache.js.map +1 -1
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.js +109 -0
- package/src/tools/esbuild/sourcemap-ignorelist-plugin.js.map +1 -1
- package/src/tools/esbuild/sqlite-cache-store.d.ts +1 -1
- package/src/tools/esbuild/sqlite-cache-store.js +239 -65
- package/src/tools/esbuild/sqlite-cache-store.js.map +1 -1
- package/src/tools/esbuild/stylesheets/sass-language.d.ts +2 -0
- package/src/tools/esbuild/stylesheets/sass-language.js +61 -28
- package/src/tools/esbuild/stylesheets/sass-language.js.map +1 -1
- package/src/tools/esbuild/watcher.js +26 -3
- package/src/tools/esbuild/watcher.js.map +1 -1
- package/src/tools/oxc/oxc-transform.js +1 -1
- package/src/tools/oxc/oxc-transform.js.map +1 -1
- package/src/tools/sass/sass-service.d.ts +4 -0
- package/src/tools/sass/sass-service.js +9 -1
- package/src/tools/sass/sass-service.js.map +1 -1
- package/src/utils/environment-options.d.ts +8 -0
- package/src/utils/environment-options.js +9 -1
- package/src/utils/environment-options.js.map +1 -1
- package/src/utils/index-file/index-html-generator.d.ts +1 -1
- package/src/utils/index-file/index-html-generator.js +9 -13
- package/src/utils/index-file/index-html-generator.js.map +1 -1
- package/src/utils/index-file/inline-critical-css.d.ts +16 -18
- package/src/utils/index-file/inline-critical-css.js +44 -189
- package/src/utils/index-file/inline-critical-css.js.map +1 -1
- package/src/utils/index-file/nonce.d.ts +2 -0
- package/src/utils/index-file/nonce.js +1 -0
- package/src/utils/index-file/nonce.js.map +1 -1
- package/src/utils/normalize-cache.js +1 -1
- package/src/utils/server-rendering/manifest.d.ts +2 -2
- package/src/utils/server-rendering/manifest.js +53 -4
- package/src/utils/server-rendering/manifest.js.map +1 -1
|
@@ -15,16 +15,13 @@ const node_url_1 = require("node:url");
|
|
|
15
15
|
const hash_1 = require("../../utils/hash");
|
|
16
16
|
const load_result_cache_1 = require("./load-result-cache");
|
|
17
17
|
/**
|
|
18
|
-
* Calculates a unique cache key
|
|
19
|
-
* This prevents implicit string coercion of large binary content buffers.
|
|
18
|
+
* Calculates a unique cache key from the global configuration hash and path.
|
|
20
19
|
*/
|
|
21
|
-
function calculateCacheKey(globalConfigHash, path
|
|
20
|
+
function calculateCacheKey(globalConfigHash, path) {
|
|
22
21
|
const hasher = (0, hash_1.createContentHash)();
|
|
23
22
|
hasher.update(globalConfigHash);
|
|
24
23
|
hasher.update('\0');
|
|
25
24
|
hasher.update(path);
|
|
26
|
-
hasher.update('\0');
|
|
27
|
-
hasher.update(content);
|
|
28
25
|
return hasher.digest();
|
|
29
26
|
}
|
|
30
27
|
/**
|
|
@@ -75,7 +72,7 @@ async function mapConcurrent(items, limit, fn) {
|
|
|
75
72
|
* Performs a fast-path metadata check (mtime + size) first, falling back to content hashing.
|
|
76
73
|
* Heals/updates the cached metadata on disk if the content hash was valid but the metadata changed.
|
|
77
74
|
*/
|
|
78
|
-
async function validateAndHealCacheEntry(watchFilesMetadata, store, cacheKey, cached
|
|
75
|
+
async function validateAndHealCacheEntry(watchFilesMetadata, store, cacheKey, cached) {
|
|
79
76
|
if (!watchFilesMetadata) {
|
|
80
77
|
return false;
|
|
81
78
|
}
|
|
@@ -92,17 +89,7 @@ async function validateAndHealCacheEntry(watchFilesMetadata, store, cacheKey, ca
|
|
|
92
89
|
if (stats.size === expected.size && stats.mtimeMs === expected.mtimeMs) {
|
|
93
90
|
return true;
|
|
94
91
|
}
|
|
95
|
-
// 2.
|
|
96
|
-
if (targetFilePath && filePath === targetFilePath) {
|
|
97
|
-
watchFilesMetadata[filePath] = {
|
|
98
|
-
...expected,
|
|
99
|
-
mtimeMs: stats.mtimeMs,
|
|
100
|
-
size: stats.size,
|
|
101
|
-
};
|
|
102
|
-
healed = true;
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
// 3. Slow Path for dependencies: content hash fallback
|
|
92
|
+
// 2. Slow Path: content hash fallback
|
|
106
93
|
const currentContent = await (0, promises_1.readFile)(filePath);
|
|
107
94
|
const currentHash = (0, hash_1.calculateHash)(currentContent);
|
|
108
95
|
if (currentHash === expected.hash) {
|
|
@@ -183,20 +170,10 @@ class PersistentLoadResultCache {
|
|
|
183
170
|
return undefined;
|
|
184
171
|
}
|
|
185
172
|
// 2. Check L2 Persistent Disk Cache
|
|
186
|
-
|
|
187
|
-
const filePath = extractDiskFilePath(path);
|
|
188
|
-
if (filePath) {
|
|
189
|
-
try {
|
|
190
|
-
content = await (0, promises_1.readFile)(filePath);
|
|
191
|
-
}
|
|
192
|
-
catch {
|
|
193
|
-
return undefined;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const cacheKey = calculateCacheKey(this.globalConfigHash, path, content);
|
|
173
|
+
const cacheKey = calculateCacheKey(this.globalConfigHash, path);
|
|
197
174
|
const cached = await this.persistentStore.get(cacheKey);
|
|
198
175
|
if (cached &&
|
|
199
|
-
(await validateAndHealCacheEntry(cached.watchFilesMetadata, this.persistentStore, cacheKey, cached
|
|
176
|
+
(await validateAndHealCacheEntry(cached.watchFilesMetadata, this.persistentStore, cacheKey, cached))) {
|
|
200
177
|
const result = {
|
|
201
178
|
contents: cached.contents,
|
|
202
179
|
loader: cached.loader,
|
|
@@ -229,13 +206,14 @@ class PersistentLoadResultCache {
|
|
|
229
206
|
return;
|
|
230
207
|
}
|
|
231
208
|
}
|
|
232
|
-
const cacheKey = calculateCacheKey(this.globalConfigHash, path
|
|
209
|
+
const cacheKey = calculateCacheKey(this.globalConfigHash, path);
|
|
233
210
|
// Reuse the target file's pre-read content buffer to avoid redundant disk reads (readFile)
|
|
234
211
|
// during dependency watch file metadata computation.
|
|
235
212
|
const knownContents = filePath
|
|
236
213
|
? new Map([[filePath, content]])
|
|
237
214
|
: undefined;
|
|
238
|
-
const
|
|
215
|
+
const allWatchFiles = Array.from(new Set(filePath ? [filePath, ...(result.watchFiles ?? [])] : result.watchFiles));
|
|
216
|
+
const watchFilesMetadata = await computeMetadataForWatchFiles(allWatchFiles, knownContents);
|
|
239
217
|
await this.persistentStore.put(cacheKey, {
|
|
240
218
|
contents: result.contents,
|
|
241
219
|
loader: result.loader,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"persistent-load-result-cache.js","sourceRoot":"","sources":["persistent-load-result-cache.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;
|
|
1
|
+
{"version":3,"file":"persistent-load-result-cache.js","sourceRoot":"","sources":["persistent-load-result-cache.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAkFH,kDAuBC;AAjFD,+CAAkD;AAClD,yCAAuC;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,UAAU,CAAC;IACrC,CAAC;CACF;AAhHD,8DAgHC"}
|
|
@@ -19,6 +19,87 @@ const IGNORE_LIST_ID = 'x_google_ignoreList';
|
|
|
19
19
|
* of a full source map if not present in the source map data.
|
|
20
20
|
*/
|
|
21
21
|
const NODE_MODULE_BYTES = Buffer.from('node_modules/', 'utf-8');
|
|
22
|
+
/**
|
|
23
|
+
* The UTF-8 bytes for the "sources" property key used to locate the sources array.
|
|
24
|
+
*/
|
|
25
|
+
const SOURCES_KEY_BYTES = Buffer.from('"sources"', 'utf-8');
|
|
26
|
+
/**
|
|
27
|
+
* The UTF-8 bytes for the ignore list identifier to check if already present.
|
|
28
|
+
*/
|
|
29
|
+
const IGNORE_LIST_BYTES = Buffer.from(`"${IGNORE_LIST_ID}"`, 'utf-8');
|
|
30
|
+
function extractSources(contents) {
|
|
31
|
+
const sourcesKeyIndex = contents.indexOf(SOURCES_KEY_BYTES);
|
|
32
|
+
if (sourcesKeyIndex === -1) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
// Find the ':' after "sources"
|
|
36
|
+
let colonIndex = sourcesKeyIndex + SOURCES_KEY_BYTES.length;
|
|
37
|
+
while (colonIndex < contents.length && contents[colonIndex] <= 0x20) {
|
|
38
|
+
colonIndex++;
|
|
39
|
+
}
|
|
40
|
+
if (contents[colonIndex] !== 0x3a /* : */) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
// Find the '[' for the array
|
|
44
|
+
let arrayStartIndex = colonIndex + 1;
|
|
45
|
+
while (arrayStartIndex < contents.length && contents[arrayStartIndex] <= 0x20) {
|
|
46
|
+
arrayStartIndex++;
|
|
47
|
+
}
|
|
48
|
+
if (contents[arrayStartIndex] !== 0x5b /* [ */) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
// Scan until matching ']'
|
|
52
|
+
let depth = 0;
|
|
53
|
+
let inString = false;
|
|
54
|
+
for (let i = arrayStartIndex; i < contents.length; i++) {
|
|
55
|
+
const byte = contents[i];
|
|
56
|
+
if (inString) {
|
|
57
|
+
if (byte === 0x5c /* \ */) {
|
|
58
|
+
i++; // skip escaped character
|
|
59
|
+
}
|
|
60
|
+
else if (byte === 0x22 /* " */) {
|
|
61
|
+
inString = false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (byte === 0x22 /* " */) {
|
|
65
|
+
inString = true;
|
|
66
|
+
}
|
|
67
|
+
else if (byte === 0x5b /* [ */) {
|
|
68
|
+
depth++;
|
|
69
|
+
}
|
|
70
|
+
else if (byte === 0x5d /* ] */) {
|
|
71
|
+
depth--;
|
|
72
|
+
if (depth === 0) {
|
|
73
|
+
try {
|
|
74
|
+
const slice = contents.toString('utf-8', arrayStartIndex, i + 1);
|
|
75
|
+
const parsed = JSON.parse(slice);
|
|
76
|
+
return Array.isArray(parsed) && parsed.every((s) => typeof s === 'string')
|
|
77
|
+
? parsed
|
|
78
|
+
: undefined;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
function updateSourcemapFast(contents, ignoreList) {
|
|
89
|
+
let braceIndex = 0;
|
|
90
|
+
while (braceIndex < contents.length && contents[braceIndex] <= 0x20) {
|
|
91
|
+
braceIndex++;
|
|
92
|
+
}
|
|
93
|
+
if (contents[braceIndex] !== 0x7b /* { */) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const injection = Buffer.from(`"${IGNORE_LIST_ID}":${JSON.stringify(ignoreList)},`, 'utf-8');
|
|
97
|
+
return Buffer.concat([
|
|
98
|
+
contents.subarray(0, braceIndex + 1),
|
|
99
|
+
injection,
|
|
100
|
+
contents.subarray(braceIndex + 1),
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
22
103
|
/**
|
|
23
104
|
* Creates an esbuild plugin that updates generated sourcemaps to include the Chrome
|
|
24
105
|
* DevTools ignore list extension. All source files that originate from a node modules
|
|
@@ -49,7 +130,35 @@ function createSourcemapIgnorelistPlugin() {
|
|
|
49
130
|
if (!contents.includes(NODE_MODULE_BYTES)) {
|
|
50
131
|
continue;
|
|
51
132
|
}
|
|
133
|
+
let fastPathSuccess = false;
|
|
134
|
+
if (!contents.includes(IGNORE_LIST_BYTES)) {
|
|
135
|
+
const sources = extractSources(contents);
|
|
136
|
+
if (sources) {
|
|
137
|
+
const ignoreList = [];
|
|
138
|
+
for (let index = 0; index < sources.length; ++index) {
|
|
139
|
+
const location = sources[index].indexOf('node_modules/');
|
|
140
|
+
if (location === 0 || (location > 0 && sources[index][location - 1] === '/')) {
|
|
141
|
+
ignoreList.push(index);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (ignoreList.length === 0) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const updated = updateSourcemapFast(contents, ignoreList);
|
|
148
|
+
if (updated) {
|
|
149
|
+
file.contents = updated;
|
|
150
|
+
fastPathSuccess = true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (fastPathSuccess) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// Fallback to full JSON parse/stringify if fast scanning or splicing fails
|
|
52
158
|
const map = JSON.parse(contents.toString('utf-8'));
|
|
159
|
+
if (map[IGNORE_LIST_ID]) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
53
162
|
const ignoreList = [];
|
|
54
163
|
// Check and store the index of each source originating from a node modules directory
|
|
55
164
|
for (let index = 0; index < map.sources.length; ++index) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sourcemap-ignorelist-plugin.js","sourceRoot":"","sources":["sourcemap-ignorelist-plugin.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;
|
|
1
|
+
{"version":3,"file":"sourcemap-ignorelist-plugin.js","sourceRoot":"","sources":["sourc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: string;
|
|
20
20
|
private readonly maxPayloadSize;
|
|
21
21
|
private readonly ttlDays;
|
|
22
|
-
constructor(cachePath: string, maxPayloadSize?: number, ttlDays?: number);
|
|
22
|
+
constructor(cachePath: string, maxPayloadSize?: number, ttlDays?: number, busyTimeoutMs?: number);
|
|
23
23
|
get(key: string): Promise<any>;
|
|
24
24
|
has(key: string): boolean;
|
|
25
25
|
set(key: string, value: unknown): Promise<this>;
|
|
@@ -8,9 +8,45 @@
|
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
exports.SqliteCacheStore = void 0;
|
|
11
|
+
const node_fs_1 = require("node:fs");
|
|
12
|
+
const node_path_1 = require("node:path");
|
|
11
13
|
const node_sqlite_1 = require("node:sqlite");
|
|
14
|
+
const node_util_1 = require("node:util");
|
|
12
15
|
const node_v8_1 = require("node:v8");
|
|
16
|
+
const node_zlib_1 = require("node:zlib");
|
|
13
17
|
const cache_1 = require("./cache");
|
|
18
|
+
const deflateRawAsync = (0, node_util_1.promisify)(node_zlib_1.deflateRaw);
|
|
19
|
+
/**
|
|
20
|
+
* Minimum payload size (in bytes) required to attempt compression.
|
|
21
|
+
* Smaller payloads generally do not achieve meaningful compression ratios, while larger payloads
|
|
22
|
+
* (such as transformed JavaScript modules from node_modules) achieve 70-80% size reduction
|
|
23
|
+
* and drastically reduce SQLite overflow pages.
|
|
24
|
+
*/
|
|
25
|
+
const COMPRESSION_THRESHOLD = 32 * 1024; // 32 KB
|
|
26
|
+
/**
|
|
27
|
+
* Storage format discriminator values for cache table entries.
|
|
28
|
+
*/
|
|
29
|
+
var CacheFormat;
|
|
30
|
+
(function (CacheFormat) {
|
|
31
|
+
CacheFormat[CacheFormat["V8"] = 0] = "V8";
|
|
32
|
+
CacheFormat[CacheFormat["V8Compressed"] = 1] = "V8Compressed";
|
|
33
|
+
CacheFormat[CacheFormat["RawBinary"] = 2] = "RawBinary";
|
|
34
|
+
CacheFormat[CacheFormat["RawBinaryCompressed"] = 3] = "RawBinaryCompressed";
|
|
35
|
+
})(CacheFormat || (CacheFormat = {}));
|
|
36
|
+
/**
|
|
37
|
+
* Common SQLite primary result codes.
|
|
38
|
+
* @see https://www.sqlite.org/rescode.html
|
|
39
|
+
*/
|
|
40
|
+
var SqliteResultCode;
|
|
41
|
+
(function (SqliteResultCode) {
|
|
42
|
+
SqliteResultCode[SqliteResultCode["Busy"] = 5] = "Busy";
|
|
43
|
+
SqliteResultCode[SqliteResultCode["Locked"] = 6] = "Locked";
|
|
44
|
+
})(SqliteResultCode || (SqliteResultCode = {}));
|
|
45
|
+
function isSqliteError(error) {
|
|
46
|
+
return (error instanceof Error &&
|
|
47
|
+
('errcode' in error ||
|
|
48
|
+
('code' in error && error.code === 'ERR_SQLITE_ERROR')));
|
|
49
|
+
}
|
|
14
50
|
/**
|
|
15
51
|
* A persistent cache store backed by SQLite.
|
|
16
52
|
*
|
|
@@ -24,42 +60,115 @@ class SqliteCacheStore {
|
|
|
24
60
|
maxPayloadSize;
|
|
25
61
|
ttlDays;
|
|
26
62
|
#db;
|
|
63
|
+
#disabled = false;
|
|
27
64
|
#getStmt;
|
|
28
65
|
#hasStmt;
|
|
29
66
|
#setStmt;
|
|
30
67
|
#updateAccessedStmt;
|
|
31
68
|
#pendingAccessedKeys = new Set();
|
|
32
69
|
#flushTimeout;
|
|
33
|
-
|
|
70
|
+
#busyTimeoutMs;
|
|
71
|
+
constructor(cachePath, maxPayloadSize = 1024 * 1024 * 1024, ttlDays = 14, busyTimeoutMs = 5000) {
|
|
34
72
|
this.cachePath = cachePath;
|
|
35
73
|
this.maxPayloadSize = maxPayloadSize;
|
|
36
74
|
this.ttlDays = ttlDays;
|
|
75
|
+
this.#busyTimeoutMs =
|
|
76
|
+
Number.isSafeInteger(busyTimeoutMs) && busyTimeoutMs >= 0 ? busyTimeoutMs : 5000;
|
|
77
|
+
}
|
|
78
|
+
#openDatabase() {
|
|
79
|
+
let db;
|
|
80
|
+
try {
|
|
81
|
+
if (this.cachePath === ':memory:') {
|
|
82
|
+
db = new node_sqlite_1.DatabaseSync(this.cachePath);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
// Optimistically attempt to open the database file first to avoid directory creation
|
|
86
|
+
// syscalls on warm builds where the parent directory already exists.
|
|
87
|
+
try {
|
|
88
|
+
db = new node_sqlite_1.DatabaseSync(this.cachePath);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
(0, node_fs_1.mkdirSync)((0, node_path_1.dirname)(this.cachePath), { recursive: true });
|
|
92
|
+
db = new node_sqlite_1.DatabaseSync(this.cachePath);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Optimize SQLite for cache usage
|
|
96
|
+
db.exec(`PRAGMA busy_timeout = ${this.#busyTimeoutMs};`);
|
|
97
|
+
db.exec('PRAGMA auto_vacuum = FULL;');
|
|
98
|
+
db.exec('PRAGMA journal_mode = WAL;');
|
|
99
|
+
db.exec('PRAGMA synchronous = NORMAL;');
|
|
100
|
+
db.exec('PRAGMA temp_store = MEMORY;');
|
|
101
|
+
db.exec('PRAGMA mmap_size = 268435456;');
|
|
102
|
+
db.exec('CREATE TABLE IF NOT EXISTS cache (' +
|
|
103
|
+
'key TEXT PRIMARY KEY, ' +
|
|
104
|
+
'value BLOB, ' +
|
|
105
|
+
'format INTEGER NOT NULL DEFAULT 0, ' +
|
|
106
|
+
'last_accessed INTEGER NOT NULL' +
|
|
107
|
+
') WITHOUT ROWID;');
|
|
108
|
+
try {
|
|
109
|
+
db.exec('ALTER TABLE cache ADD COLUMN format INTEGER NOT NULL DEFAULT 0;');
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Ignore error if format column already exists
|
|
113
|
+
}
|
|
114
|
+
db.exec('CREATE INDEX IF NOT EXISTS idx_cache_accessed ON cache (last_accessed DESC, key DESC);');
|
|
115
|
+
this.#getStmt = db.prepare('SELECT value, format FROM cache WHERE key = ?');
|
|
116
|
+
this.#hasStmt = db.prepare('SELECT 1 FROM cache WHERE key = ?');
|
|
117
|
+
this.#setStmt = db.prepare('INSERT OR REPLACE INTO cache (key, value, format, last_accessed) VALUES (?, ?, ?, unixepoch())');
|
|
118
|
+
this.#updateAccessedStmt = db.prepare('UPDATE cache SET last_accessed = unixepoch() WHERE key = ?');
|
|
119
|
+
this.#db = db;
|
|
120
|
+
return db;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
try {
|
|
124
|
+
db?.close();
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// Ignore close error on corrupted handle
|
|
128
|
+
}
|
|
129
|
+
this.#getStmt = undefined;
|
|
130
|
+
this.#hasStmt = undefined;
|
|
131
|
+
this.#setStmt = undefined;
|
|
132
|
+
this.#updateAccessedStmt = undefined;
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
37
135
|
}
|
|
38
136
|
#ensureDb() {
|
|
137
|
+
if (this.#disabled) {
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
39
140
|
if (!this.#db) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
141
|
+
try {
|
|
142
|
+
return this.#openDatabase();
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
// If the database is locked by another active process,
|
|
146
|
+
// do not attempt to delete the database files as that could corrupt the active process's database.
|
|
147
|
+
const isBusy = isSqliteError(error) &&
|
|
148
|
+
(error.errcode === SqliteResultCode.Busy || error.errcode === SqliteResultCode.Locked);
|
|
149
|
+
// Attempt to recover from database corruption by deleting the corrupted files and recreating
|
|
150
|
+
if (!isBusy && this.cachePath !== ':memory:') {
|
|
151
|
+
try {
|
|
152
|
+
(0, node_fs_1.rmSync)(this.cachePath, { force: true });
|
|
153
|
+
(0, node_fs_1.rmSync)(this.cachePath + '-wal', { force: true });
|
|
154
|
+
(0, node_fs_1.rmSync)(this.cachePath + '-shm', { force: true });
|
|
155
|
+
(0, node_fs_1.rmSync)(this.cachePath + '-journal', { force: true });
|
|
156
|
+
return this.#openDatabase();
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// If recovery fails (e.g. read-only filesystem or permission denied), disable caching
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.#disabled = true;
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
53
165
|
}
|
|
54
166
|
return this.#db;
|
|
55
167
|
}
|
|
56
168
|
#queueAccessUpdate(key) {
|
|
57
169
|
this.#pendingAccessedKeys.add(key);
|
|
58
|
-
if (this.#
|
|
59
|
-
this.#flushAccessUpdates();
|
|
60
|
-
}
|
|
61
|
-
else if (!this.#flushTimeout) {
|
|
62
|
-
this.#flushTimeout = setTimeout(() => this.#flushAccessUpdates(), 500);
|
|
170
|
+
if (!this.#flushTimeout) {
|
|
171
|
+
this.#flushTimeout = setTimeout(() => this.#flushAccessUpdates(), 1000);
|
|
63
172
|
this.#flushTimeout.unref?.();
|
|
64
173
|
}
|
|
65
174
|
}
|
|
@@ -68,19 +177,21 @@ class SqliteCacheStore {
|
|
|
68
177
|
clearTimeout(this.#flushTimeout);
|
|
69
178
|
this.#flushTimeout = undefined;
|
|
70
179
|
}
|
|
71
|
-
if (
|
|
180
|
+
if (this.#pendingAccessedKeys.size === 0) {
|
|
72
181
|
return;
|
|
73
182
|
}
|
|
74
183
|
try {
|
|
75
|
-
this.#db
|
|
76
|
-
|
|
77
|
-
this.#
|
|
184
|
+
if (this.#db && this.#updateAccessedStmt) {
|
|
185
|
+
this.#db.exec('BEGIN IMMEDIATE TRANSACTION;');
|
|
186
|
+
for (const key of this.#pendingAccessedKeys) {
|
|
187
|
+
this.#updateAccessedStmt.run(key);
|
|
188
|
+
}
|
|
189
|
+
this.#db.exec('COMMIT;');
|
|
78
190
|
}
|
|
79
|
-
this.#db.exec('COMMIT;');
|
|
80
191
|
}
|
|
81
192
|
catch {
|
|
82
193
|
try {
|
|
83
|
-
this.#db
|
|
194
|
+
this.#db?.exec('ROLLBACK;');
|
|
84
195
|
}
|
|
85
196
|
catch {
|
|
86
197
|
// Ignore rollback errors if transaction was not active
|
|
@@ -92,73 +203,136 @@ class SqliteCacheStore {
|
|
|
92
203
|
}
|
|
93
204
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
205
|
async get(key) {
|
|
95
|
-
this.#ensureDb()
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
206
|
+
if (!this.#ensureDb()) {
|
|
207
|
+
return undefined;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
// SQLite column types are dynamic, so the stored value is only known at runtime.
|
|
211
|
+
const row = this.#getStmt?.get(key);
|
|
212
|
+
if (row) {
|
|
213
|
+
this.#queueAccessUpdate(key);
|
|
214
|
+
if (row.value instanceof Uint8Array) {
|
|
215
|
+
try {
|
|
216
|
+
switch (row.format) {
|
|
217
|
+
case CacheFormat.RawBinary:
|
|
218
|
+
return row.value;
|
|
219
|
+
case CacheFormat.RawBinaryCompressed: {
|
|
220
|
+
const decompressed = (0, node_zlib_1.inflateRawSync)(row.value);
|
|
221
|
+
return new Uint8Array(decompressed.buffer, decompressed.byteOffset, decompressed.byteLength);
|
|
222
|
+
}
|
|
223
|
+
case CacheFormat.V8Compressed:
|
|
224
|
+
return (0, node_v8_1.deserialize)((0, node_zlib_1.inflateRawSync)(row.value));
|
|
225
|
+
case CacheFormat.V8:
|
|
226
|
+
default:
|
|
227
|
+
return (0, node_v8_1.deserialize)(row.value);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
// Treat corrupt or unparseable cached payloads as a cache miss.
|
|
232
|
+
}
|
|
106
233
|
}
|
|
107
234
|
}
|
|
108
235
|
}
|
|
236
|
+
catch {
|
|
237
|
+
// Treat query errors (e.g. disk read failures) as a cache miss.
|
|
238
|
+
}
|
|
109
239
|
return undefined;
|
|
110
240
|
}
|
|
111
241
|
has(key) {
|
|
112
|
-
this.#ensureDb()
|
|
113
|
-
|
|
242
|
+
if (!this.#ensureDb()) {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
return !!this.#hasStmt?.get(key);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
114
251
|
}
|
|
115
252
|
async set(key, value) {
|
|
116
|
-
this.#ensureDb()
|
|
117
|
-
|
|
118
|
-
|
|
253
|
+
if (!this.#ensureDb()) {
|
|
254
|
+
return this;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
this.#pendingAccessedKeys.delete(key);
|
|
258
|
+
const isBinary = value instanceof Uint8Array;
|
|
259
|
+
const data = isBinary ? value : (0, node_v8_1.serialize)(value);
|
|
260
|
+
let format = isBinary ? CacheFormat.RawBinary : CacheFormat.V8;
|
|
261
|
+
let payload = data;
|
|
262
|
+
if (data.byteLength >= COMPRESSION_THRESHOLD) {
|
|
263
|
+
const compressed = await deflateRawAsync(data, { level: 1 });
|
|
264
|
+
if (compressed.byteLength < data.byteLength) {
|
|
265
|
+
payload = compressed;
|
|
266
|
+
format = isBinary ? CacheFormat.RawBinaryCompressed : CacheFormat.V8Compressed;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
this.#setStmt?.run(key, payload, format);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
// Writing to cache is non-fatal and should not fail the build.
|
|
273
|
+
}
|
|
119
274
|
return this;
|
|
120
275
|
}
|
|
121
276
|
createCache(namespace) {
|
|
122
|
-
return new cache_1.Cache(this, namespace);
|
|
277
|
+
return new cache_1.Cache(new cache_1.NamespacedCacheStore(this, namespace));
|
|
123
278
|
}
|
|
124
279
|
close() {
|
|
280
|
+
this.#flushAccessUpdates();
|
|
125
281
|
if (this.#db) {
|
|
126
282
|
try {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
283
|
+
this.#db.exec('BEGIN IMMEDIATE TRANSACTION;');
|
|
284
|
+
try {
|
|
285
|
+
// 1. Delete items older than N days
|
|
286
|
+
this.#db
|
|
287
|
+
.prepare("DELETE FROM cache WHERE last_accessed < unixepoch('now', ?);")
|
|
288
|
+
.run(`-${this.ttlDays} days`);
|
|
289
|
+
// 2. Prune oldest items if payload exceeds maxPayloadSize
|
|
290
|
+
// Skip the expensive window aggregate query if total database size is below maxPayloadSize
|
|
291
|
+
const sizeResult = this.#db
|
|
292
|
+
.prepare('SELECT (page_count - freelist_count) * page_size AS total_size ' +
|
|
293
|
+
'FROM pragma_page_count(), pragma_freelist_count(), pragma_page_size();')
|
|
294
|
+
.get();
|
|
295
|
+
if ((sizeResult?.total_size ?? 0) > this.maxPayloadSize) {
|
|
296
|
+
this.#db
|
|
297
|
+
.prepare(`DELETE FROM cache WHERE key IN (
|
|
298
|
+
SELECT key FROM (
|
|
299
|
+
SELECT key,
|
|
300
|
+
sum(length(key) + length(value)) OVER (ORDER BY last_accessed DESC, key DESC) as running_size
|
|
301
|
+
FROM cache
|
|
302
|
+
) WHERE running_size > ?
|
|
303
|
+
);`)
|
|
304
|
+
.run(this.maxPayloadSize);
|
|
305
|
+
}
|
|
306
|
+
this.#db.exec('COMMIT;');
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
try {
|
|
310
|
+
this.#db.exec('ROLLBACK;');
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
// Ignore rollback errors if transaction was not active
|
|
314
|
+
}
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
144
317
|
}
|
|
145
318
|
catch {
|
|
146
319
|
// Pruning errors should not block build success
|
|
147
320
|
}
|
|
148
321
|
finally {
|
|
149
|
-
if (this.#flushTimeout) {
|
|
150
|
-
clearTimeout(this.#flushTimeout);
|
|
151
|
-
this.#flushTimeout = undefined;
|
|
152
|
-
}
|
|
153
|
-
this.#pendingAccessedKeys.clear();
|
|
154
322
|
this.#getStmt = undefined;
|
|
155
323
|
this.#hasStmt = undefined;
|
|
156
324
|
this.#setStmt = undefined;
|
|
157
325
|
this.#updateAccessedStmt = undefined;
|
|
158
|
-
|
|
326
|
+
try {
|
|
327
|
+
this.#db.close();
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
// Failure to close should not block build success
|
|
331
|
+
}
|
|
159
332
|
this.#db = undefined;
|
|
160
333
|
}
|
|
161
334
|
}
|
|
335
|
+
this.#disabled = false;
|
|
162
336
|
}
|
|
163
337
|
}
|
|
164
338
|
exports.SqliteCacheStore = SqliteCacheStore;
|