@analogjs/vite-plugin-angular 2.6.3-beta.4 → 2.6.3-beta.5
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/package.json +1 -1
- package/src/lib/compiler-plugin.d.ts +3 -2
- package/src/lib/compiler-plugin.js +4 -4
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/router-plugin.js +10 -5
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/utils/plugin-config.js +11 -3
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/transform-cache.d.ts +43 -0
- package/src/lib/utils/transform-cache.js +102 -0
- package/src/lib/utils/transform-cache.js.map +1 -0
package/package.json
CHANGED
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { DepOptimizationConfig, Rolldown } from 'vite';
|
|
9
9
|
import { CompilerPluginOptions } from './utils/devkit.js';
|
|
10
|
+
import type { TransformCacheStore } from './utils/transform-cache.js';
|
|
10
11
|
type EsbuildOptions = NonNullable<DepOptimizationConfig['esbuildOptions']>;
|
|
11
12
|
type EsbuildPlugin = NonNullable<EsbuildOptions['plugins']>[number];
|
|
12
|
-
export declare function createCompilerPlugin(pluginOptions: CompilerPluginOptions, isTest: boolean, closeTransformer: boolean): EsbuildPlugin;
|
|
13
|
-
export declare function createRolldownCompilerPlugin(pluginOptions: CompilerPluginOptions, isTest: boolean, closeTransformer: boolean): Rolldown.Plugin;
|
|
13
|
+
export declare function createCompilerPlugin(pluginOptions: CompilerPluginOptions, isTest: boolean, closeTransformer: boolean, cache?: TransformCacheStore): EsbuildPlugin;
|
|
14
|
+
export declare function createRolldownCompilerPlugin(pluginOptions: CompilerPluginOptions, isTest: boolean, closeTransformer: boolean, cache?: TransformCacheStore): Rolldown.Plugin;
|
|
14
15
|
export {};
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* found in the LICENSE file at https://angular.dev/license
|
|
7
7
|
*/
|
|
8
8
|
import { JavaScriptTransformer, } from './utils/devkit.js';
|
|
9
|
-
export function createCompilerPlugin(pluginOptions, isTest, closeTransformer) {
|
|
10
|
-
const javascriptTransformer = new JavaScriptTransformer({ ...pluginOptions, jit: true }, 1);
|
|
9
|
+
export function createCompilerPlugin(pluginOptions, isTest, closeTransformer, cache) {
|
|
10
|
+
const javascriptTransformer = new JavaScriptTransformer({ ...pluginOptions, jit: true }, 1, cache);
|
|
11
11
|
return {
|
|
12
12
|
name: 'analogjs-angular-esbuild-deps-optimizer-plugin',
|
|
13
13
|
async setup(build) {
|
|
@@ -26,8 +26,8 @@ export function createCompilerPlugin(pluginOptions, isTest, closeTransformer) {
|
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
|
-
export function createRolldownCompilerPlugin(pluginOptions, isTest, closeTransformer) {
|
|
30
|
-
const javascriptTransformer = new JavaScriptTransformer({ ...pluginOptions, jit: true }, 1);
|
|
29
|
+
export function createRolldownCompilerPlugin(pluginOptions, isTest, closeTransformer, cache) {
|
|
30
|
+
const javascriptTransformer = new JavaScriptTransformer({ ...pluginOptions, jit: true }, 1, cache);
|
|
31
31
|
const plugin = {
|
|
32
32
|
name: 'analogjs-rolldown-deps-optimizer-plugin',
|
|
33
33
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/compiler-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAEL,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"compiler-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/compiler-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAEL,qBAAqB,GACtB,MAAM,mBAAmB,CAAC;AAM3B,MAAM,UAAU,oBAAoB,CAClC,aAAoC,EACpC,MAAe,EACf,gBAAyB,EACz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AE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;oBAC7C,MAAM,EAAE,IAAI;iBACN,CAAC;YACX,CAAC;SACF,CAAC;IACJ,CAAC;IAED,IAAI,gBAAgB,EAAE,CAAC;QACrB,MAAM,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;IACxD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/src/lib/router-plugin.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { JavaScriptTransformer } from './utils/devkit.js';
|
|
2
|
+
import { createPersistentTransformCache, resolveTransformCacheDir, withMemoryLayer, } from './utils/transform-cache.js';
|
|
2
3
|
export function routerPlugin() {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
get: (key) =>
|
|
4
|
+
const memoryCache = new Map();
|
|
5
|
+
const memoryOnly = {
|
|
6
|
+
get: (key) => memoryCache.get(key),
|
|
6
7
|
put: (key, value) => {
|
|
7
|
-
|
|
8
|
+
memoryCache.set(key, value);
|
|
8
9
|
},
|
|
9
|
-
}
|
|
10
|
+
};
|
|
11
|
+
const persistentDir = resolveTransformCacheDir(process.cwd());
|
|
12
|
+
const javascriptTransformer = new JavaScriptTransformer({ jit: true }, 1, persistentDir
|
|
13
|
+
? withMemoryLayer(createPersistentTransformCache(persistentDir))
|
|
14
|
+
: memoryOnly);
|
|
10
15
|
/**
|
|
11
16
|
* Transforms Angular packages the didn't get picked up by Vite's pre-optimization.
|
|
12
17
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/router-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"router-plugin.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-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AAE,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;iBAC9C,CAAC;YACJ,CAAC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
|
-
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
3
3
|
import * as vite from 'vite';
|
|
4
4
|
import { createCompilerPlugin, createRolldownCompilerPlugin, } from '../compiler-plugin.js';
|
|
5
|
+
import { createPersistentTransformCache, resolveTransformCacheDir, } from './transform-cache.js';
|
|
5
6
|
/**
|
|
6
7
|
* TypeScript file extension regex
|
|
7
8
|
* Match .ts / .cts / .mts extensions with an optional ?query suffix.
|
|
@@ -52,6 +53,13 @@ export function createDepOptimizerConfig(opts) {
|
|
|
52
53
|
ngI18nClosureMode: 'false',
|
|
53
54
|
...(opts.watchMode ? {} : { ngDevMode: 'false' }),
|
|
54
55
|
};
|
|
56
|
+
// Persist linked dependency output across dep-optimizer runs. The
|
|
57
|
+
// transformer's own key covers file bytes + options, and the directory
|
|
58
|
+
// is namespaced by Angular version, so entries never go stale.
|
|
59
|
+
const transformCacheDir = resolveTransformCacheDir(dirname(opts.tsconfig));
|
|
60
|
+
const transformCache = transformCacheDir
|
|
61
|
+
? createPersistentTransformCache(transformCacheDir)
|
|
62
|
+
: undefined;
|
|
55
63
|
const rolldownOptions = {
|
|
56
64
|
plugins: [
|
|
57
65
|
createRolldownCompilerPlugin({
|
|
@@ -60,7 +68,7 @@ export function createDepOptimizerConfig(opts) {
|
|
|
60
68
|
advancedOptimizations: opts.isProd,
|
|
61
69
|
jit: opts.jit,
|
|
62
70
|
incremental: opts.watchMode,
|
|
63
|
-
}, opts.isTest, !opts.isAstroIntegration),
|
|
71
|
+
}, opts.isTest, !opts.isAstroIntegration, transformCache),
|
|
64
72
|
],
|
|
65
73
|
};
|
|
66
74
|
const esbuildOptions = {
|
|
@@ -71,7 +79,7 @@ export function createDepOptimizerConfig(opts) {
|
|
|
71
79
|
advancedOptimizations: opts.isProd,
|
|
72
80
|
jit: opts.jit,
|
|
73
81
|
incremental: opts.watchMode,
|
|
74
|
-
}, opts.isTest, !opts.isAstroIntegration),
|
|
82
|
+
}, opts.isTest, !opts.isAstroIntegration, transformCache),
|
|
75
83
|
],
|
|
76
84
|
define: defineOptions,
|
|
77
85
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-config.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/plugin-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-config.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/plugin-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,8BAA8B,EAC9B,wBAAwB,GACzB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,oBAAoB,CAAC;AAQjD,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,QAAgB,EAChB,MAAe,EACf,MAAe,EACf,KAAc;IAEd,IAAI,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,C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riptTransformer`
|
|
3
|
+
* accepts as its third constructor argument. Keys are SHA-256 digests the
|
|
4
|
+
* transformer derives from the file bytes plus every option that affects
|
|
5
|
+
* output, so entries are immutable and never need invalidation — but the
|
|
6
|
+
* digest does NOT cover the linker version, so stores must be namespaced
|
|
7
|
+
* by Angular version (see {@link resolveTransformCacheDir}).
|
|
8
|
+
*/
|
|
9
|
+
export interface TransformCacheStore {
|
|
10
|
+
get(key: string): Promise<Uint8Array | undefined> | Uint8Array | undefined;
|
|
11
|
+
put(key: string, value: Uint8Array): Promise<void> | void;
|
|
12
|
+
}
|
|
13
|
+
interface TransformCacheStats {
|
|
14
|
+
hits: number;
|
|
15
|
+
misses: number;
|
|
16
|
+
writes: number;
|
|
17
|
+
/** Approximate total ms spent in the linker worker for cache misses. */
|
|
18
|
+
workerMs: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Disk-backed content-addressed store for linked/transformed dependency
|
|
22
|
+
* output. Entries are written atomically (temp + rename) so concurrent
|
|
23
|
+
* dev servers can share a directory; all failures degrade to a miss.
|
|
24
|
+
*/
|
|
25
|
+
export declare function createPersistentTransformCache(baseDir: string): TransformCacheStore & {
|
|
26
|
+
stats: TransformCacheStats;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Layer an unbounded in-memory map over a persistent store so repeat
|
|
30
|
+
* transforms in the same session never touch the disk.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withMemoryLayer(store: TransformCacheStore): TransformCacheStore;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the shared on-disk cache directory: `node_modules/.cache` at the
|
|
35
|
+
* nearest `node_modules` above `startDir` — the conventional tool-cache
|
|
36
|
+
* location, so installs and `node_modules` cleans evict it without a
|
|
37
|
+
* separate eviction pass. Namespaced by the installed Angular version
|
|
38
|
+
* because the transformer's cache key does not cover the linker version.
|
|
39
|
+
* Returns `null` (caching disabled) when no `node_modules` exists or the
|
|
40
|
+
* `ANALOG_TRANSFORM_CACHE=0` kill switch is set.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveTransformCacheDir(startDir: string): string | null;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as crypto from 'node:crypto';
|
|
4
|
+
import { VERSION } from '@angular/compiler';
|
|
5
|
+
import { createDebug } from 'obug';
|
|
6
|
+
const debugCache = createDebug('analog-transform-cache');
|
|
7
|
+
/**
|
|
8
|
+
* Disk-backed content-addressed store for linked/transformed dependency
|
|
9
|
+
* output. Entries are written atomically (temp + rename) so concurrent
|
|
10
|
+
* dev servers can share a directory; all failures degrade to a miss.
|
|
11
|
+
*/
|
|
12
|
+
export function createPersistentTransformCache(baseDir) {
|
|
13
|
+
const stats = {
|
|
14
|
+
hits: 0,
|
|
15
|
+
misses: 0,
|
|
16
|
+
writes: 0,
|
|
17
|
+
workerMs: 0,
|
|
18
|
+
};
|
|
19
|
+
// Miss timestamps by key: with the transformer's serialized worker, the
|
|
20
|
+
// gap between a missed get and its put approximates linker time per file.
|
|
21
|
+
const missedAt = new Map();
|
|
22
|
+
const entryPath = (key) => path.join(baseDir, key.slice(0, 2), key);
|
|
23
|
+
return {
|
|
24
|
+
stats,
|
|
25
|
+
async get(key) {
|
|
26
|
+
try {
|
|
27
|
+
const value = await fs.promises.readFile(entryPath(key));
|
|
28
|
+
stats.hits++;
|
|
29
|
+
debugCache('hit %s (hits=%d misses=%d)', key, stats.hits, stats.misses);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
stats.misses++;
|
|
34
|
+
missedAt.set(key, performance.now());
|
|
35
|
+
debugCache('miss %s (hits=%d misses=%d)', key, stats.hits, stats.misses);
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
async put(key, value) {
|
|
40
|
+
const startedAt = missedAt.get(key);
|
|
41
|
+
if (startedAt !== undefined) {
|
|
42
|
+
missedAt.delete(key);
|
|
43
|
+
stats.workerMs += performance.now() - startedAt;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const file = entryPath(key);
|
|
47
|
+
await fs.promises.mkdir(path.dirname(file), { recursive: true });
|
|
48
|
+
const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString('hex')}`;
|
|
49
|
+
await fs.promises.writeFile(tmp, value);
|
|
50
|
+
await fs.promises.rename(tmp, file);
|
|
51
|
+
stats.writes++;
|
|
52
|
+
debugCache('put %s (writes=%d workerMs=%d)', key, stats.writes, Math.round(stats.workerMs));
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
debugCache('put failed %s: %s', key, e?.message);
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Layer an unbounded in-memory map over a persistent store so repeat
|
|
62
|
+
* transforms in the same session never touch the disk.
|
|
63
|
+
*/
|
|
64
|
+
export function withMemoryLayer(store) {
|
|
65
|
+
const memory = new Map();
|
|
66
|
+
return {
|
|
67
|
+
async get(key) {
|
|
68
|
+
const cached = memory.get(key) ?? (await store.get(key));
|
|
69
|
+
if (cached)
|
|
70
|
+
memory.set(key, cached);
|
|
71
|
+
return cached;
|
|
72
|
+
},
|
|
73
|
+
async put(key, value) {
|
|
74
|
+
memory.set(key, value);
|
|
75
|
+
await store.put(key, value);
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolve the shared on-disk cache directory: `node_modules/.cache` at the
|
|
81
|
+
* nearest `node_modules` above `startDir` — the conventional tool-cache
|
|
82
|
+
* location, so installs and `node_modules` cleans evict it without a
|
|
83
|
+
* separate eviction pass. Namespaced by the installed Angular version
|
|
84
|
+
* because the transformer's cache key does not cover the linker version.
|
|
85
|
+
* Returns `null` (caching disabled) when no `node_modules` exists or the
|
|
86
|
+
* `ANALOG_TRANSFORM_CACHE=0` kill switch is set.
|
|
87
|
+
*/
|
|
88
|
+
export function resolveTransformCacheDir(startDir) {
|
|
89
|
+
if (process.env['ANALOG_TRANSFORM_CACHE'] === '0')
|
|
90
|
+
return null;
|
|
91
|
+
let dir = path.resolve(startDir);
|
|
92
|
+
for (;;) {
|
|
93
|
+
if (fs.existsSync(path.join(dir, 'node_modules'))) {
|
|
94
|
+
return path.join(dir, 'node_modules', '.cache', 'analog', 'transform-cache', VERSION.full);
|
|
95
|
+
}
|
|
96
|
+
const parent = path.dirname(dir);
|
|
97
|
+
if (parent === dir)
|
|
98
|
+
return null;
|
|
99
|
+
dir = parent;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=transform-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-cache.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-angular/src/lib/utils/transform-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAEnC,MAAM,UAAU,GAAG,WAAW,CAAC,wBAAwB,CAAC,CAAC;AAuBzD;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAC5C,OAAe;IAEf,MAAM,KAAK,GAAwB;QACjC,IAAI,EAAE,CAAC;QACP,MAAM,EAAE,CAAC;QACT,MAAM,EAAE,CAAC;QACT,QAAQ,EAAE,CAAC;KACZ,CAAC;IACF,wEAAwE;IACxE,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE3C,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC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