@analogjs/vite-plugin-angular 3.0.0-alpha.59 → 3.0.0-alpha.60
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/angular-vite-plugin.js +9 -3
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/compiler/compile.d.ts +6 -0
- package/src/lib/compiler/compile.js +68 -9
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/constants.d.ts +6 -0
- package/src/lib/compiler/constants.js +7 -1
- package/src/lib/compiler/constants.js.map +1 -1
- package/src/lib/compiler/defer.js +1 -1
- package/src/lib/compiler/dts-reader.d.ts +13 -3
- package/src/lib/compiler/dts-reader.js +38 -8
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -1
- package/src/lib/compiler/index.js +1 -0
- package/src/lib/compiler/jit-transform.js +1 -1
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.js +2 -2
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/metadata.d.ts +0 -9
- package/src/lib/compiler/metadata.js +67 -6
- package/src/lib/compiler/metadata.js.map +1 -1
- package/src/lib/compiler/registry.d.ts +8 -1
- package/src/lib/compiler/registry.js +15 -3
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.d.ts +27 -5
- package/src/lib/compiler/resource-inliner.js +138 -60
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +2 -1
- package/src/lib/compiler/style-ast.js +2 -2
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.d.ts +5 -3
- package/src/lib/compiler/type-elision.js +8 -8
- package/src/lib/compiler/type-elision.js.map +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/component-resolvers.js +4 -5
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/fast-compile-plugin.js +136 -23
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/router-plugin.js +13 -1
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/utils/plugin-config.js +6 -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 +97 -0
- package/src/lib/utils/transform-cache.js.map +1 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `{ get, put }` shape `@angular/build`'s `JavaScriptTransformer`
|
|
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,97 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path$1 from "node:path";
|
|
3
|
+
import * as crypto from "node:crypto";
|
|
4
|
+
import { createDebug } from "obug";
|
|
5
|
+
import { VERSION } from "@angular/compiler";
|
|
6
|
+
//#region packages/vite-plugin-angular/src/lib/utils/transform-cache.ts
|
|
7
|
+
var debugCache = createDebug("analog-transform-cache");
|
|
8
|
+
/**
|
|
9
|
+
* Disk-backed content-addressed store for linked/transformed dependency
|
|
10
|
+
* output. Entries are written atomically (temp + rename) so concurrent
|
|
11
|
+
* dev servers can share a directory; all failures degrade to a miss.
|
|
12
|
+
*/
|
|
13
|
+
function createPersistentTransformCache(baseDir) {
|
|
14
|
+
const stats = {
|
|
15
|
+
hits: 0,
|
|
16
|
+
misses: 0,
|
|
17
|
+
writes: 0,
|
|
18
|
+
workerMs: 0
|
|
19
|
+
};
|
|
20
|
+
const missedAt = /* @__PURE__ */ new Map();
|
|
21
|
+
const entryPath = (key) => path$1.join(baseDir, key.slice(0, 2), key);
|
|
22
|
+
return {
|
|
23
|
+
stats,
|
|
24
|
+
async get(key) {
|
|
25
|
+
try {
|
|
26
|
+
const value = await fs.promises.readFile(entryPath(key));
|
|
27
|
+
stats.hits++;
|
|
28
|
+
debugCache("hit %s (hits=%d misses=%d)", key, stats.hits, stats.misses);
|
|
29
|
+
return value;
|
|
30
|
+
} catch {
|
|
31
|
+
stats.misses++;
|
|
32
|
+
missedAt.set(key, performance.now());
|
|
33
|
+
debugCache("miss %s (hits=%d misses=%d)", key, stats.hits, stats.misses);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
async put(key, value) {
|
|
38
|
+
const startedAt = missedAt.get(key);
|
|
39
|
+
if (startedAt !== void 0) {
|
|
40
|
+
missedAt.delete(key);
|
|
41
|
+
stats.workerMs += performance.now() - startedAt;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const file = entryPath(key);
|
|
45
|
+
await fs.promises.mkdir(path$1.dirname(file), { recursive: true });
|
|
46
|
+
const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString("hex")}`;
|
|
47
|
+
await fs.promises.writeFile(tmp, value);
|
|
48
|
+
await fs.promises.rename(tmp, file);
|
|
49
|
+
stats.writes++;
|
|
50
|
+
debugCache("put %s (writes=%d workerMs=%d)", key, stats.writes, Math.round(stats.workerMs));
|
|
51
|
+
} catch (e) {
|
|
52
|
+
debugCache("put failed %s: %s", key, e?.message);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Layer an unbounded in-memory map over a persistent store so repeat
|
|
59
|
+
* transforms in the same session never touch the disk.
|
|
60
|
+
*/
|
|
61
|
+
function withMemoryLayer(store) {
|
|
62
|
+
const memory = /* @__PURE__ */ new Map();
|
|
63
|
+
return {
|
|
64
|
+
async get(key) {
|
|
65
|
+
const cached = memory.get(key) ?? await store.get(key);
|
|
66
|
+
if (cached) memory.set(key, cached);
|
|
67
|
+
return cached;
|
|
68
|
+
},
|
|
69
|
+
async put(key, value) {
|
|
70
|
+
memory.set(key, value);
|
|
71
|
+
await store.put(key, value);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolve the shared on-disk cache directory: `node_modules/.cache` at the
|
|
77
|
+
* nearest `node_modules` above `startDir` — the conventional tool-cache
|
|
78
|
+
* location, so installs and `node_modules` cleans evict it without a
|
|
79
|
+
* separate eviction pass. Namespaced by the installed Angular version
|
|
80
|
+
* because the transformer's cache key does not cover the linker version.
|
|
81
|
+
* Returns `null` (caching disabled) when no `node_modules` exists or the
|
|
82
|
+
* `ANALOG_TRANSFORM_CACHE=0` kill switch is set.
|
|
83
|
+
*/
|
|
84
|
+
function resolveTransformCacheDir(startDir) {
|
|
85
|
+
if (process.env["ANALOG_TRANSFORM_CACHE"] === "0") return null;
|
|
86
|
+
let dir = path$1.resolve(startDir);
|
|
87
|
+
for (;;) {
|
|
88
|
+
if (fs.existsSync(path$1.join(dir, "node_modules"))) return path$1.join(dir, "node_modules", ".cache", "analog", "transform-cache", VERSION.full);
|
|
89
|
+
const parent = path$1.dirname(dir);
|
|
90
|
+
if (parent === dir) return null;
|
|
91
|
+
dir = parent;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { createPersistentTransformCache, resolveTransformCacheDir, withMemoryLayer };
|
|
96
|
+
|
|
97
|
+
//# sourceMappingURL=transform-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform-cache.js","names":[],"sources":["../../../../src/lib/utils/transform-cache.ts"],"sourcesContent":["import * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as crypto from 'node:crypto';\nimport { VERSION } from '@angular/compiler';\nimport { createDebug } from 'obug';\n\nconst debugCache = createDebug('analog-transform-cache');\n\n/**\n * The `{ get, put }` shape `@angular/build`'s `JavaScriptTransformer`\n * accepts as its third constructor argument. Keys are SHA-256 digests the\n * transformer derives from the file bytes plus every option that affects\n * output, so entries are immutable and never need invalidation — but the\n * digest does NOT cover the linker version, so stores must be namespaced\n * by Angular version (see {@link resolveTransformCacheDir}).\n */\nexport interface TransformCacheStore {\n get(key: string): Promise<Uint8Array | undefined> | Uint8Array | undefined;\n put(key: string, value: Uint8Array): Promise<void> | void;\n}\n\ninterface TransformCacheStats {\n hits: number;\n misses: number;\n writes: number;\n /** Approximate total ms spent in the linker worker for cache misses. */\n workerMs: number;\n}\n\n/**\n * Disk-backed content-addressed store for linked/transformed dependency\n * output. Entries are written atomically (temp + rename) so concurrent\n * dev servers can share a directory; all failures degrade to a miss.\n */\nexport function createPersistentTransformCache(\n baseDir: string,\n): TransformCacheStore & { stats: TransformCacheStats } {\n const stats: TransformCacheStats = {\n hits: 0,\n misses: 0,\n writes: 0,\n workerMs: 0,\n };\n // Miss timestamps by key: with the transformer's serialized worker, the\n // gap between a missed get and its put approximates linker time per file.\n const missedAt = new Map<string, number>();\n\n const entryPath = (key: string) => path.join(baseDir, key.slice(0, 2), key);\n\n return {\n stats,\n async get(key: string): Promise<Uint8Array | undefined> {\n try {\n const value = await fs.promises.readFile(entryPath(key));\n stats.hits++;\n debugCache('hit %s (hits=%d misses=%d)', key, stats.hits, stats.misses);\n return value;\n } catch {\n stats.misses++;\n missedAt.set(key, performance.now());\n debugCache(\n 'miss %s (hits=%d misses=%d)',\n key,\n stats.hits,\n stats.misses,\n );\n return undefined;\n }\n },\n async put(key: string, value: Uint8Array): Promise<void> {\n const startedAt = missedAt.get(key);\n if (startedAt !== undefined) {\n missedAt.delete(key);\n stats.workerMs += performance.now() - startedAt;\n }\n try {\n const file = entryPath(key);\n await fs.promises.mkdir(path.dirname(file), { recursive: true });\n const tmp = `${file}.${process.pid}.${crypto.randomBytes(4).toString('hex')}`;\n await fs.promises.writeFile(tmp, value);\n await fs.promises.rename(tmp, file);\n stats.writes++;\n debugCache(\n 'put %s (writes=%d workerMs=%d)',\n key,\n stats.writes,\n Math.round(stats.workerMs),\n );\n } catch (e) {\n debugCache('put failed %s: %s', key, (e as Error)?.message);\n }\n },\n };\n}\n\n/**\n * Layer an unbounded in-memory map over a persistent store so repeat\n * transforms in the same session never touch the disk.\n */\nexport function withMemoryLayer(\n store: TransformCacheStore,\n): TransformCacheStore {\n const memory = new Map<string, Uint8Array>();\n return {\n async get(key: string): Promise<Uint8Array | undefined> {\n const cached = memory.get(key) ?? (await store.get(key));\n if (cached) memory.set(key, cached);\n return cached;\n },\n async put(key: string, value: Uint8Array): Promise<void> {\n memory.set(key, value);\n await store.put(key, value);\n },\n };\n}\n\n/**\n * Resolve the shared on-disk cache directory: `node_modules/.cache` at the\n * nearest `node_modules` above `startDir` — the conventional tool-cache\n * location, so installs and `node_modules` cleans evict it without a\n * separate eviction pass. Namespaced by the installed Angular version\n * because the transformer's cache key does not cover the linker version.\n * Returns `null` (caching disabled) when no `node_modules` exists or the\n * `ANALOG_TRANSFORM_CACHE=0` kill switch is set.\n */\nexport function resolveTransformCacheDir(startDir: string): string | null {\n if (process.env['ANALOG_TRANSFORM_CACHE'] === '0') return null;\n let dir = path.resolve(startDir);\n for (;;) {\n if (fs.existsSync(path.join(dir, 'node_modules'))) {\n return path.join(\n dir,\n 'node_modules',\n '.cache',\n 'analog',\n 'transform-cache',\n VERSION.full,\n );\n }\n const parent = path.dirname(dir);\n if (parent === dir) return null;\n dir = parent;\n }\n}\n"],"mappings":";;;;;;AAMA,IAAM,aAAa,YAAY,yBAAyB;;;;;;AA4BxD,SAAgB,+BACd,SACsD;CACtD,MAAM,QAA6B;EACjC,MAAM;EACN,QAAQ;EACR,QAAQ;EACR,UAAU;EACX;CAGD,MAAM,2BAAW,IAAI,KAAqB;CAE1C,MAAM,aAAa,QAAgB,OAAK,KAAK,SAAS,IAAI,MAAM,GAAG,EAAE,EAAE,IAAI;AAE3E,QAAO;EACL;EACA,MAAM,IAAI,KAA8C;AACtD,OAAI;IACF,MAAM,QAAQ,MAAM,GAAG,SAAS,SAAS,UAAU,IAAI,CAAC;AACxD,UAAM;AACN,eAAW,8BAA8B,KAA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