@analogjs/vite-plugin-angular 3.0.0-alpha.4 → 3.0.0-alpha.41
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/README.md +28 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/migrations/migrations.json +9 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
- package/package.json +25 -12
- package/src/index.d.ts +3 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
- package/src/lib/angular-build-optimizer-plugin.js +48 -62
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +3 -3
- package/src/lib/angular-jit-plugin.js +42 -37
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
- package/src/lib/angular-pending-tasks.plugin.js +17 -18
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +250 -40
- package/src/lib/angular-vite-plugin.js +2216 -964
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +19 -15
- package/src/lib/angular-vitest-plugin.js +99 -114
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +16 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +131 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +44 -0
- package/src/lib/compiler/compile.js +731 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +18 -0
- package/src/lib/compiler/constants.js +52 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +20 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +47 -0
- package/src/lib/compiler/defer.js +138 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +35 -0
- package/src/lib/compiler/dts-reader.js +365 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +69 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +7 -0
- package/src/lib/compiler/index.js +7 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +146 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +200 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +420 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +45 -0
- package/src/lib/compiler/metadata.js +633 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +49 -0
- package/src/lib/compiler/registry.js +164 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +21 -0
- package/src/lib/compiler/resource-inliner.js +152 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +8 -0
- package/src/lib/compiler/style-ast.js +54 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/type-elision.d.ts +26 -0
- package/src/lib/compiler/type-elision.js +211 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +10 -0
- package/src/lib/compiler/utils.js +35 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/compiler-plugin.d.ts +11 -11
- package/src/lib/compiler-plugin.js +43 -44
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +23 -5
- package/src/lib/component-resolvers.js +153 -63
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/fast-compile-plugin.d.ts +14 -0
- package/src/lib/fast-compile-plugin.js +270 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +113 -101
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +5 -5
- package/src/lib/live-reload-plugin.js +61 -62
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +9 -9
- package/src/lib/nx-folder-plugin.d.ts +5 -5
- package/src/lib/nx-folder-plugin.js +18 -16
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
- package/src/lib/plugins/file-replacements.plugin.js +40 -62
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +1 -1
- package/src/lib/router-plugin.js +23 -23
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-pipeline.d.ts +15 -0
- package/src/lib/style-pipeline.js +31 -0
- package/src/lib/style-pipeline.js.map +1 -0
- package/src/lib/style-preprocessor.d.ts +35 -0
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +73 -0
- package/src/lib/stylesheet-registry.js +168 -0
- package/src/lib/stylesheet-registry.js.map +1 -0
- package/src/lib/tools/package.json +2 -7
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -62
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/tools/src/index.js +0 -2
- package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
- package/src/lib/utils/debug-harness.d.ts +23 -0
- package/src/lib/utils/debug-harness.js +88 -0
- package/src/lib/utils/debug-harness.js.map +1 -0
- package/src/lib/utils/debug-log-file.d.ts +5 -0
- package/src/lib/utils/debug-log-file.js +56 -0
- package/src/lib/utils/debug-log-file.js.map +1 -0
- package/src/lib/utils/debug.d.ts +28 -0
- package/src/lib/utils/debug.js +39 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +6 -6
- package/src/lib/utils/devkit.js +34 -38
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/hmr-candidates.d.ts +28 -28
- package/src/lib/utils/plugin-config.d.ts +30 -0
- package/src/lib/utils/plugin-config.js +64 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- package/src/lib/utils/rolldown.d.ts +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- package/src/lib/utils/source-file-cache.d.ts +8 -15
- package/src/lib/utils/source-file-cache.js +35 -37
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/tailwind-reference.d.ts +12 -0
- package/src/lib/utils/tailwind-reference.js +99 -0
- package/src/lib/utils/tailwind-reference.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +8 -0
- package/src/lib/utils/virtual-ids.js +35 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +47 -0
- package/src/lib/utils/virtual-resources.js +89 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
- package/src/test-setup.d.ts +2 -0
- package/setup-vitest.d.ts +0 -4
- package/setup-vitest.js +0 -215
- package/setup-vitest.js.map +0 -1
- package/src/lib/models.js +0 -1
- package/src/lib/models.js.map +0 -1
- package/src/lib/tools/README.md +0 -3
- package/src/lib/tools/src/index.d.ts +0 -0
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/utils/compiler-plugin-options.js +0 -1
- package/src/lib/utils/compiler-plugin-options.js.map +0 -1
- package/src/lib/utils/hmr-candidates.js +0 -272
- package/src/lib/utils/hmr-candidates.js.map +0 -1
|
@@ -1,69 +1,159 @@
|
|
|
1
|
-
import { dirname, resolve } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// resolved style URLs.
|
|
24
|
-
if (entry && entry.matchedStyleUrls === matchedStyleUrls) {
|
|
25
|
-
return entry.styleUrls;
|
|
26
|
-
}
|
|
27
|
-
const styleUrls = matchedStyleUrls.map((styleUrlPath) => {
|
|
28
|
-
return `${styleUrlPath}|${normalizePath(resolve(dirname(id), styleUrlPath))}`;
|
|
29
|
-
});
|
|
30
|
-
this.styleUrlsCache.set(id, { styleUrls, matchedStyleUrls });
|
|
31
|
-
return styleUrls;
|
|
32
|
-
}
|
|
1
|
+
import { dirname, resolve } from "node:path";
|
|
2
|
+
import { normalizePath } from "vite";
|
|
3
|
+
import { parseSync } from "oxc-parser";
|
|
4
|
+
import { Visitor } from "rolldown/utils";
|
|
5
|
+
//#region packages/vite-plugin-angular/src/lib/component-resolvers.ts
|
|
6
|
+
/**
|
|
7
|
+
* Extracts a string value from an ESTree AST node.
|
|
8
|
+
*
|
|
9
|
+
* Handles three forms that Angular decorators may use:
|
|
10
|
+
* - `Literal` with a string value → `'./foo.css'` / `"./foo.css"`
|
|
11
|
+
* - `StringLiteral` (OXC-specific) → same representation
|
|
12
|
+
* - `TemplateLiteral` with zero expressions → `` `./foo.css` ``
|
|
13
|
+
*
|
|
14
|
+
* Uses `any` because OXC's AST mixes standard ESTree nodes with
|
|
15
|
+
* OXC-specific variants (e.g. `StringLiteral`), and the project's
|
|
16
|
+
* tsconfig enforces `noPropertyAccessFromIndexSignature`.
|
|
17
|
+
*/
|
|
18
|
+
function getStringValue(node) {
|
|
19
|
+
if (!node) return void 0;
|
|
20
|
+
if (node.type === "Literal" && typeof node.value === "string") return node.value;
|
|
21
|
+
if (node.type === "StringLiteral") return node.value;
|
|
22
|
+
if (node.type === "TemplateLiteral" && node.expressions.length === 0 && node.quasis.length === 1) return node.quasis[0].value.cooked ?? node.quasis[0].value.raw;
|
|
33
23
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Parses TypeScript/JS source with OXC and collects `styleUrl`, `styleUrls`,
|
|
26
|
+
* and `templateUrl` property values from Angular `@Component()` decorators
|
|
27
|
+
* in a single AST pass.
|
|
28
|
+
*
|
|
29
|
+
* This replaces the previous ts-morph implementation — OXC parses natively
|
|
30
|
+
* via Rust NAPI bindings, avoiding the overhead of spinning up a full
|
|
31
|
+
* TypeScript `Project` for each file.
|
|
32
|
+
*/
|
|
33
|
+
function collectComponentUrls(code) {
|
|
34
|
+
const { program } = parseSync("cmp.ts", code);
|
|
35
|
+
const styleUrls = [];
|
|
36
|
+
const templateUrls = [];
|
|
37
|
+
const inlineTemplates = [];
|
|
38
|
+
new Visitor({ ClassDeclaration(node) {
|
|
39
|
+
const decorators = node.decorators ?? [];
|
|
40
|
+
for (const decorator of decorators) {
|
|
41
|
+
const expression = decorator.expression;
|
|
42
|
+
if (expression?.type !== "CallExpression" || expression.callee?.type !== "Identifier" || expression.callee.name !== "Component") continue;
|
|
43
|
+
const componentArg = expression.arguments?.[0];
|
|
44
|
+
if (componentArg?.type !== "ObjectExpression") continue;
|
|
45
|
+
for (const property of componentArg.properties ?? []) {
|
|
46
|
+
if (property?.type !== "Property" || property.key?.type !== "Identifier") continue;
|
|
47
|
+
const name = property.key.name;
|
|
48
|
+
if (name === "styleUrls" && property.value?.type === "ArrayExpression") for (const el of property.value.elements) {
|
|
49
|
+
const val = getStringValue(el);
|
|
50
|
+
if (val !== void 0) styleUrls.push(val);
|
|
51
|
+
}
|
|
52
|
+
if (name === "styleUrl") {
|
|
53
|
+
const val = getStringValue(property.value);
|
|
54
|
+
if (val !== void 0) styleUrls.push(val);
|
|
55
|
+
}
|
|
56
|
+
if (name === "templateUrl") {
|
|
57
|
+
const val = getStringValue(property.value);
|
|
58
|
+
if (val !== void 0) templateUrls.push(val);
|
|
59
|
+
}
|
|
60
|
+
if (name === "template") {
|
|
61
|
+
const val = getStringValue(property.value);
|
|
62
|
+
if (val !== void 0) inlineTemplates.push(val);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} }).visit(program);
|
|
67
|
+
return {
|
|
68
|
+
styleUrls,
|
|
69
|
+
templateUrls,
|
|
70
|
+
inlineTemplates
|
|
71
|
+
};
|
|
39
72
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Extract Angular component identities from raw source code before Angular's
|
|
75
|
+
* compilation pipeline strips decorators. This is used for dev-time
|
|
76
|
+
* diagnostics such as duplicate selectors, duplicate component class names,
|
|
77
|
+
* selectorless shared components, and inline-template validation.
|
|
78
|
+
*/
|
|
79
|
+
function getAngularComponentMetadata(code) {
|
|
80
|
+
const { program } = parseSync("cmp.ts", code);
|
|
81
|
+
const components = [];
|
|
82
|
+
new Visitor({ ClassDeclaration(node) {
|
|
83
|
+
const decorators = node.decorators ?? [];
|
|
84
|
+
for (const decorator of decorators) {
|
|
85
|
+
const expression = decorator.expression;
|
|
86
|
+
if (expression?.type !== "CallExpression" || expression.callee?.type !== "Identifier" || expression.callee.name !== "Component") continue;
|
|
87
|
+
const componentArg = expression.arguments?.[0];
|
|
88
|
+
if (componentArg?.type !== "ObjectExpression") continue;
|
|
89
|
+
const metadata = {
|
|
90
|
+
className: node.id?.name ?? "(anonymous)",
|
|
91
|
+
styleUrls: [],
|
|
92
|
+
templateUrls: [],
|
|
93
|
+
inlineTemplates: []
|
|
94
|
+
};
|
|
95
|
+
for (const property of componentArg.properties ?? []) {
|
|
96
|
+
if (property?.type !== "Property" || property.key?.type !== "Identifier") continue;
|
|
97
|
+
const name = property.key.name;
|
|
98
|
+
if (name === "selector") metadata.selector = getStringValue(property.value);
|
|
99
|
+
else if (name === "styleUrl") {
|
|
100
|
+
const val = getStringValue(property.value);
|
|
101
|
+
if (val !== void 0) metadata.styleUrls.push(val);
|
|
102
|
+
} else if (name === "styleUrls" && property.value?.type === "ArrayExpression") for (const el of property.value.elements ?? []) {
|
|
103
|
+
const val = getStringValue(el);
|
|
104
|
+
if (val !== void 0) metadata.styleUrls.push(val);
|
|
105
|
+
}
|
|
106
|
+
else if (name === "templateUrl") {
|
|
107
|
+
const val = getStringValue(property.value);
|
|
108
|
+
if (val !== void 0) metadata.templateUrls.push(val);
|
|
109
|
+
} else if (name === "template") {
|
|
110
|
+
const val = getStringValue(property.value);
|
|
111
|
+
if (val !== void 0) metadata.inlineTemplates.push(val);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
components.push(metadata);
|
|
115
|
+
}
|
|
116
|
+
} }).visit(program);
|
|
117
|
+
return components;
|
|
50
118
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const properties = sourceFile.getDescendantsOfKind(SyntaxKind.PropertyAssignment);
|
|
55
|
-
return getTextByProperty('templateUrl', properties);
|
|
119
|
+
/** Extract all `styleUrl` / `styleUrls` values from Angular component source. */
|
|
120
|
+
function getStyleUrls(code) {
|
|
121
|
+
return collectComponentUrls(code).styleUrls;
|
|
56
122
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const entry = this.templateUrlsCache.get(id);
|
|
61
|
-
if (entry?.code === code) {
|
|
62
|
-
return entry.templateUrlPaths;
|
|
63
|
-
}
|
|
64
|
-
const templateUrlPaths = getTemplateUrls(code).map((url) => `${url}|${normalizePath(resolve(dirname(id), url))}`);
|
|
65
|
-
this.templateUrlsCache.set(id, { code, templateUrlPaths });
|
|
66
|
-
return templateUrlPaths;
|
|
67
|
-
}
|
|
123
|
+
/** Extract all `templateUrl` values from Angular component source. */
|
|
124
|
+
function getTemplateUrls(code) {
|
|
125
|
+
return collectComponentUrls(code).templateUrls;
|
|
68
126
|
}
|
|
127
|
+
var StyleUrlsResolver = class {
|
|
128
|
+
styleUrlsCache = /* @__PURE__ */ new Map();
|
|
129
|
+
resolve(code, id) {
|
|
130
|
+
const matchedStyleUrls = getStyleUrls(code);
|
|
131
|
+
const entry = this.styleUrlsCache.get(id);
|
|
132
|
+
if (entry && entry.matchedStyleUrls === matchedStyleUrls) return entry.styleUrls;
|
|
133
|
+
const styleUrls = matchedStyleUrls.map((styleUrlPath) => {
|
|
134
|
+
return `${styleUrlPath}|${normalizePath(resolve(dirname(id), styleUrlPath))}`;
|
|
135
|
+
});
|
|
136
|
+
this.styleUrlsCache.set(id, {
|
|
137
|
+
styleUrls,
|
|
138
|
+
matchedStyleUrls
|
|
139
|
+
});
|
|
140
|
+
return styleUrls;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
var TemplateUrlsResolver = class {
|
|
144
|
+
templateUrlsCache = /* @__PURE__ */ new Map();
|
|
145
|
+
resolve(code, id) {
|
|
146
|
+
const entry = this.templateUrlsCache.get(id);
|
|
147
|
+
if (entry?.code === code) return entry.templateUrlPaths;
|
|
148
|
+
const templateUrlPaths = getTemplateUrls(code).map((url) => `${url}|${normalizePath(resolve(dirname(id), url))}`);
|
|
149
|
+
this.templateUrlsCache.set(id, {
|
|
150
|
+
code,
|
|
151
|
+
templateUrlPaths
|
|
152
|
+
});
|
|
153
|
+
return templateUrlPaths;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
//#endregion
|
|
157
|
+
export { StyleUrlsResolver, TemplateUrlsResolver, getAngularComponentMetadata };
|
|
158
|
+
|
|
69
159
|
//# sourceMappingURL=component-resolvers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-resolvers.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/component-resolvers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAEL,OAAO,EAEP,UAAU,GACX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAOrC,MAAM,OAAO,iBAAiB;IAC5B,+DAA+D;IAC/D,oEAAoE;IACpE,sEAAsE;IACtE,oEAAoE;IACnD,cAAc,GAAG,IAAI,GAAG,EAA+B,CAAC;IAEzE,OAAO,CAAC,IAAY,EAAE,EAAU;QAC9B,mCAAmC;QACnC,eAAe;QACf,iBAAiB;QACjB,6BAA6B;QAC7B,MAAM;QACN,KAAK;QACL,2FAA2F;QAC3F,MAAM,gBAAgB,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC1C,yFAAyF;QACzF,qFAAqF;QACrF,sFAAsF;QACtF,uBAAuB;QACvB,IAAI,KAAK,IAAI,KAAK,CAAC,gBAAgB,KAAK,gBAAgB,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC,SAAS,C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EF,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,gBAAgB,EAAE,CAAC,CAAC;QAC3D,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"component-resolvers.js","names":[],"sources":["../../../src/lib/component-resolvers.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path';\n// OXC parser (native Rust, NAPI-RS) replaces ts-morph for AST extraction.\n// It is ~10-50x faster for the narrow task of pulling property values from\n// Angular component decorators. The Visitor helper from Rolldown walks the\n// ESTree-compatible AST that OXC produces.\nimport { parseSync } from 'oxc-parser';\nimport { Visitor } from 'rolldown/utils';\nimport { normalizePath } from 'vite';\n\n// ---------------------------------------------------------------------------\n// AST helpers\n// ---------------------------------------------------------------------------\n\n/**\n * Extracts a string value from an ESTree AST node.\n *\n * Handles three forms that Angular decorators may use:\n * - `Literal` with a string value → `'./foo.css'` / `\"./foo.css\"`\n * - `StringLiteral` (OXC-specific) → same representation\n * - `TemplateLiteral` with zero expressions → `` `./foo.css` ``\n *\n * Uses `any` because OXC's AST mixes standard ESTree nodes with\n * OXC-specific variants (e.g. `StringLiteral`), and the project's\n * tsconfig enforces `noPropertyAccessFromIndexSignature`.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction getStringValue(node: any): string | undefined {\n if (!node) return undefined;\n // Standard ESTree Literal (string value)\n if (node.type === 'Literal' && typeof node.value === 'string') {\n return node.value;\n }\n // OXC-specific StringLiteral node\n if (node.type === 'StringLiteral') {\n return node.value;\n }\n // Template literal with no interpolation (e.g., `./foo.css`)\n if (\n node.type === 'TemplateLiteral' &&\n node.expressions.length === 0 &&\n node.quasis.length === 1\n ) {\n return node.quasis[0].value.cooked ?? node.quasis[0].value.raw;\n }\n return undefined;\n}\n\n/**\n * Parses TypeScript/JS source with OXC and collects `styleUrl`, `styleUrls`,\n * and `templateUrl` property values from Angular `@Component()` decorators\n * in a single AST pass.\n *\n * This replaces the previous ts-morph implementation — OXC parses natively\n * via Rust NAPI bindings, avoiding the overhead of spinning up a full\n * TypeScript `Project` for each file.\n */\nfunction collectComponentUrls(code: string): {\n styleUrls: string[];\n templateUrls: string[];\n inlineTemplates: string[];\n} {\n const { program } = parseSync('cmp.ts', code);\n const styleUrls: string[] = [];\n const templateUrls: string[] = [];\n const inlineTemplates: string[] = [];\n\n const visitor = new Visitor({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ClassDeclaration(node: any) {\n const decorators = node.decorators ?? [];\n for (const decorator of decorators) {\n const expression = decorator.expression;\n if (\n expression?.type !== 'CallExpression' ||\n expression.callee?.type !== 'Identifier' ||\n expression.callee.name !== 'Component'\n ) {\n continue;\n }\n\n const componentArg = expression.arguments?.[0];\n if (componentArg?.type !== 'ObjectExpression') {\n continue;\n }\n\n for (const property of componentArg.properties ?? []) {\n if (\n property?.type !== 'Property' ||\n property.key?.type !== 'Identifier'\n ) {\n continue;\n }\n\n const name = property.key.name;\n\n if (\n name === 'styleUrls' &&\n property.value?.type === 'ArrayExpression'\n ) {\n for (const el of property.value.elements) {\n const val = getStringValue(el);\n if (val !== undefined) styleUrls.push(val);\n }\n }\n\n if (name === 'styleUrl') {\n const val = getStringValue(property.value);\n if (val !== undefined) styleUrls.push(val);\n }\n\n if (name === 'templateUrl') {\n const val = getStringValue(property.value);\n if (val !== undefined) templateUrls.push(val);\n }\n\n if (name === 'template') {\n const val = getStringValue(property.value);\n if (val !== undefined) inlineTemplates.push(val);\n }\n }\n }\n },\n });\n visitor.visit(program);\n\n return { styleUrls, templateUrls, inlineTemplates };\n}\n\nexport interface AngularComponentMetadata {\n className: string;\n selector?: string;\n styleUrls: string[];\n templateUrls: string[];\n inlineTemplates: string[];\n}\n\n/**\n * Extract Angular component identities from raw source code before Angular's\n * compilation pipeline strips decorators. This is used for dev-time\n * diagnostics such as duplicate selectors, duplicate component class names,\n * selectorless shared components, and inline-template validation.\n */\nexport function getAngularComponentMetadata(\n code: string,\n): AngularComponentMetadata[] {\n const { program } = parseSync('cmp.ts', code);\n const components: AngularComponentMetadata[] = [];\n\n const visitor = new Visitor({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ClassDeclaration(node: any) {\n const decorators = node.decorators ?? [];\n for (const decorator of decorators) {\n const expression = decorator.expression;\n if (\n expression?.type !== 'CallExpression' ||\n expression.callee?.type !== 'Identifier' ||\n expression.callee.name !== 'Component'\n ) {\n continue;\n }\n\n const componentArg = expression.arguments?.[0];\n if (componentArg?.type !== 'ObjectExpression') {\n continue;\n }\n\n const metadata: AngularComponentMetadata = {\n className: node.id?.name ?? '(anonymous)',\n styleUrls: [],\n templateUrls: [],\n inlineTemplates: [],\n };\n\n for (const property of componentArg.properties ?? []) {\n if (\n property?.type !== 'Property' ||\n property.key?.type !== 'Identifier'\n ) {\n continue;\n }\n\n const name = property.key.name;\n if (name === 'selector') {\n metadata.selector = getStringValue(property.value);\n } else if (name === 'styleUrl') {\n const val = getStringValue(property.value);\n if (val !== undefined) {\n metadata.styleUrls.push(val);\n }\n } else if (\n name === 'styleUrls' &&\n property.value?.type === 'ArrayExpression'\n ) {\n for (const el of property.value.elements ?? []) {\n const val = getStringValue(el);\n if (val !== undefined) {\n metadata.styleUrls.push(val);\n }\n }\n } else if (name === 'templateUrl') {\n const val = getStringValue(property.value);\n if (val !== undefined) {\n metadata.templateUrls.push(val);\n }\n } else if (name === 'template') {\n const val = getStringValue(property.value);\n if (val !== undefined) {\n metadata.inlineTemplates.push(val);\n }\n }\n }\n\n components.push(metadata);\n }\n },\n });\n visitor.visit(program);\n\n return components;\n}\n\n/** Extract all `styleUrl` / `styleUrls` values from Angular component source. */\nexport function getStyleUrls(code: string): string[] {\n return collectComponentUrls(code).styleUrls;\n}\n\n/** Extract all `templateUrl` values from Angular component source. */\nexport function getTemplateUrls(code: string): string[] {\n return collectComponentUrls(code).templateUrls;\n}\n\n/** Extract inline `template` strings from Angular component source. */\nexport function getInlineTemplates(code: string): string[] {\n return collectComponentUrls(code).inlineTemplates;\n}\n\n// ---------------------------------------------------------------------------\n// Resolver caches\n// ---------------------------------------------------------------------------\n\ninterface StyleUrlsCacheEntry {\n matchedStyleUrls: string[];\n styleUrls: string[];\n}\n\nexport class StyleUrlsResolver {\n // These resolvers may be called multiple times during the same\n // compilation for the same files. Caching is required because these\n // resolvers use synchronous system calls to the filesystem, which can\n // degrade performance when running compilations for multiple files.\n private readonly styleUrlsCache = new Map<string, StyleUrlsCacheEntry>();\n\n resolve(code: string, id: string): string[] {\n const matchedStyleUrls = getStyleUrls(code);\n const entry = this.styleUrlsCache.get(id);\n // We're using `matchedStyleUrls` as a key because the code may be changing continuously,\n // resulting in the resolver being called multiple times. While the code changes, the\n // `styleUrls` may remain constant, which means we should always return the previously\n // resolved style URLs.\n if (entry && entry.matchedStyleUrls === matchedStyleUrls) {\n return entry.styleUrls;\n }\n\n const styleUrls = matchedStyleUrls.map((styleUrlPath) => {\n return `${styleUrlPath}|${normalizePath(\n resolve(dirname(id), styleUrlPath),\n )}`;\n });\n\n this.styleUrlsCache.set(id, { styleUrls, matchedStyleUrls });\n return styleUrls;\n }\n}\n\ninterface TemplateUrlsCacheEntry {\n code: string;\n templateUrlPaths: string[];\n}\n\nexport class TemplateUrlsResolver {\n private readonly templateUrlsCache = new Map<\n string,\n TemplateUrlsCacheEntry\n >();\n\n resolve(code: string, id: string): string[] {\n const entry = this.templateUrlsCache.get(id);\n if (entry?.code === code) {\n return entry.templateUrlPaths;\n }\n\n const templateUrlPaths = getTemplateUrls(code).map(\n (url) => `${url}|${normalizePath(resolve(dirname(id), url))}`,\n );\n\n this.templateUrlsCache.set(id, { code, templateUrlPaths });\n return templateUrlPaths;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAS,eAAe,MAA+B;AACrD,KAAI,CAAC,KAAM,QAAO,KAAA;AAElB,KAAI,KAAK,SAAS,aAAa,OAAO,KAAK,UAAU,SACnD,QAAO,KAAK;AAGd,KAAI,KAAK,SAA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1C,SAAI,QAAQ,KAAA,EACV,UAAS,gBAAgB,KAAK,IAAI;;;AAKxC,cAAW,KAAK,SAAS;;IAG9B,CAAC,CACM,MAAM,QAAQ;AAEtB,QAAO;;;AAIT,SAAgB,aAAa,MAAwB;AACnD,QAAO,qBAAqB,KAAK,CAAC;;;AAIpC,SAAgB,gBAAgB,MAAwB;AACtD,QAAO,qBAAqB,KAAK,CAAC;;AAiBpC,IAAa,oBAAb,MAA+B;CAK7B,iCAAkC,IAAI,KAAkC;CAExE,QAAQ,MAAc,IAAsB;EAC1C,MAAM,mBAAmB,aAAa,KAAK;EAC3C,MAAM,QAAQ,KAAK,eAAe,IAAI,GAAG;AAKzC,MAAI,SAAS,MAAM,qBAAqB,iBACtC,QAAO,MAAM;EAGf,MAAM,YAAY,iBAAiB,KAAK,iBAAiB;AACvD,UAAO,GAAG,aAAa,GAAG,cACxB,QAAQ,QAAQ,GAAG,EAAE,aAAa,CACnC;IACD;AAEF,OAAK,eAAe,IAAI,IAAI;GAAE;GAAW;GAAkB,CAAC;AAC5D,SAAO;;;AASX,IAAa,uBAAb,MAAkC;CAChC,oCAAqC,IAAI,KAGtC;CAEH,QAAQ,MAAc,IAAsB;EAC1C,MAAM,QAAQ,KAAK,kBAAkB,IAAI,GAAG;AAC5C,MAAI,OAAO,SAAS,KAClB,QAAO,MAAM;EAGf,MAAM,mBAAmB,gBAAgB,KAAK,CAAC,KAC5C,QAAQ,GAAG,IAAI,GAAG,cAAc,QAAQ,QAAQ,GAAG,EAAE,IAAI,CAAC,GAC5D;AAED,OAAK,kBAAkB,IAAI,IAAI;GAAE;GAAM;GAAkB,CAAC;AAC1D,SAAO"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
export interface FastCompilePluginOptions {
|
|
3
|
+
tsconfigGetter: () => string;
|
|
4
|
+
workspaceRoot: string;
|
|
5
|
+
inlineStylesExtension: string;
|
|
6
|
+
jit: boolean;
|
|
7
|
+
liveReload: boolean;
|
|
8
|
+
supportedBrowsers: string[];
|
|
9
|
+
transformFilter?: (code: string, id: string) => boolean;
|
|
10
|
+
isTest: boolean;
|
|
11
|
+
isAstroIntegration: boolean;
|
|
12
|
+
fastCompileMode?: "full" | "partial";
|
|
13
|
+
}
|
|
14
|
+
export declare function fastCompilePlugin(pluginOptions: FastCompilePluginOptions): Plugin;
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { toVirtualRawId, toVirtualStyleId } from "./utils/virtual-ids.js";
|
|
2
|
+
import { loadVirtualRawModule, loadVirtualStyleModule, rewriteHtmlRawImport, rewriteInlineStyleImport, shouldPreprocessTestCss } from "./utils/virtual-resources.js";
|
|
3
|
+
import { debugCompile, debugRegistry } from "./compiler/debug.js";
|
|
4
|
+
import { compile } from "./compiler/compile.js";
|
|
5
|
+
import { scanFile } from "./compiler/registry.js";
|
|
6
|
+
import { collectImportedPackages, collectRelativeReExports, scanPackageDts } from "./compiler/dts-reader.js";
|
|
7
|
+
import { jitTransform } from "./compiler/jit-transform.js";
|
|
8
|
+
import { generateHmrCode } from "./compiler/hmr.js";
|
|
9
|
+
import { extractInlineStyles, inlineResourceUrls } from "./compiler/resource-inliner.js";
|
|
10
|
+
import "./compiler/index.js";
|
|
11
|
+
import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath } from "./utils/plugin-config.js";
|
|
12
|
+
import { promises } from "node:fs";
|
|
13
|
+
import { dirname, resolve } from "node:path";
|
|
14
|
+
import * as compilerCli from "@angular/compiler-cli";
|
|
15
|
+
import * as vite from "vite";
|
|
16
|
+
import { defaultClientConditions, normalizePath, preprocessCSS } from "vite";
|
|
17
|
+
//#region packages/vite-plugin-angular/src/lib/fast-compile-plugin.ts
|
|
18
|
+
function fastCompilePlugin(pluginOptions) {
|
|
19
|
+
let resolvedConfig;
|
|
20
|
+
let tsConfigResolutionContext = null;
|
|
21
|
+
let watchMode = false;
|
|
22
|
+
const registry = /* @__PURE__ */ new Map();
|
|
23
|
+
const resourceToSource = /* @__PURE__ */ new Map();
|
|
24
|
+
const scannedDtsPackages = /* @__PURE__ */ new Set();
|
|
25
|
+
let projectRoot = "";
|
|
26
|
+
let useDefineForClassFields = true;
|
|
27
|
+
/**
|
|
28
|
+
* Scan a file into the registry, then recursively walk its relative
|
|
29
|
+
* `export *` / `export { … } from './x'` chain so any underlying
|
|
30
|
+
* directive classes also land in the registry. Used both at
|
|
31
|
+
* `buildStart` (for tsconfig path entries) and at dev time (file
|
|
32
|
+
* `add` and `handleHotUpdate`) so newly added barrels stay in sync
|
|
33
|
+
* without requiring a server restart.
|
|
34
|
+
*
|
|
35
|
+
* The `visited` set prevents infinite recursion within a single
|
|
36
|
+
* top-level call. Each fresh scan should pass an empty set (so HMR
|
|
37
|
+
* re-scans aren't blocked by buildStart's earlier visits).
|
|
38
|
+
*/
|
|
39
|
+
async function scanBarrelExports(file, visited = /* @__PURE__ */ new Set(), overwrite = false) {
|
|
40
|
+
if (visited.has(file)) return;
|
|
41
|
+
visited.add(file);
|
|
42
|
+
let code;
|
|
43
|
+
try {
|
|
44
|
+
code = await promises.readFile(file, "utf-8");
|
|
45
|
+
} catch (e) {
|
|
46
|
+
if (debugRegistry.enabled) debugRegistry("scanBarrelExports: failed to read %s: %s", file, e?.message);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const entries = scanFile(code, file);
|
|
50
|
+
for (const entry of entries) if (overwrite || !registry.has(entry.className)) registry.set(entry.className, entry);
|
|
51
|
+
const dir = dirname(file);
|
|
52
|
+
for (const rel of collectRelativeReExports(code, file)) {
|
|
53
|
+
const normalizedRel = rel.replace(/\.(?:js|mjs)$/u, "");
|
|
54
|
+
const reExportCandidates = [resolve(dir, normalizedRel + ".ts"), resolve(dir, normalizedRel, "index.ts")];
|
|
55
|
+
let resolved = false;
|
|
56
|
+
for (const candidate of reExportCandidates) try {
|
|
57
|
+
await promises.access(candidate);
|
|
58
|
+
await scanBarrelExports(candidate, visited, overwrite);
|
|
59
|
+
resolved = true;
|
|
60
|
+
break;
|
|
61
|
+
} catch {}
|
|
62
|
+
if (!resolved && debugRegistry.enabled) debugRegistry("scanBarrelExports: %s re-export %s did not resolve to %o", file, rel, reExportCandidates);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function initFastCompile() {
|
|
66
|
+
if (pluginOptions.jit) return;
|
|
67
|
+
registry.clear();
|
|
68
|
+
scannedDtsPackages.clear();
|
|
69
|
+
const resolvedTsConfigPath = resolveTsConfigPath();
|
|
70
|
+
projectRoot = dirname(resolvedTsConfigPath);
|
|
71
|
+
const config = compilerCli.readConfiguration(resolvedTsConfigPath);
|
|
72
|
+
useDefineForClassFields = config.options?.useDefineForClassFields ?? true;
|
|
73
|
+
const candidates = new Set(config.rootNames);
|
|
74
|
+
const tsPaths = config.options?.paths;
|
|
75
|
+
const baseUrl = config.options?.baseUrl ?? projectRoot;
|
|
76
|
+
if (tsPaths) for (const targets of Object.values(tsPaths)) for (const target of targets) {
|
|
77
|
+
if (target.includes("*")) continue;
|
|
78
|
+
candidates.add(resolve(baseUrl, target));
|
|
79
|
+
}
|
|
80
|
+
const results = await Promise.all(Array.from(candidates).map(async (file) => {
|
|
81
|
+
try {
|
|
82
|
+
return scanFile(await promises.readFile(file, "utf-8"), file);
|
|
83
|
+
} catch (e) {
|
|
84
|
+
if (debugRegistry.enabled) debugRegistry("initFastCompile: skipping unreadable %s: %s", file, e?.message);
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
for (const entries of results) for (const entry of entries) registry.set(entry.className, entry);
|
|
89
|
+
const buildStartVisited = /* @__PURE__ */ new Set();
|
|
90
|
+
if (tsPaths) {
|
|
91
|
+
const barrelCandidates = [];
|
|
92
|
+
for (const targets of Object.values(tsPaths)) for (const target of targets) {
|
|
93
|
+
if (target.includes("*")) continue;
|
|
94
|
+
barrelCandidates.push(resolve(baseUrl, target));
|
|
95
|
+
}
|
|
96
|
+
await Promise.all(barrelCandidates.map((c) => scanBarrelExports(c, buildStartVisited)));
|
|
97
|
+
}
|
|
98
|
+
debugRegistry("initFastCompile done: %d entries from %d candidate files", registry.size, candidates.size);
|
|
99
|
+
}
|
|
100
|
+
function ensureDtsRegistryForSource(code, id) {
|
|
101
|
+
for (const pkg of collectImportedPackages(code, id)) {
|
|
102
|
+
if (scannedDtsPackages.has(pkg)) continue;
|
|
103
|
+
scannedDtsPackages.add(pkg);
|
|
104
|
+
try {
|
|
105
|
+
const dtsEntries = scanPackageDts(pkg, projectRoot);
|
|
106
|
+
for (const entry of dtsEntries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
107
|
+
} catch {}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function handleFastCompileTransform(code, id) {
|
|
111
|
+
if (!/(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code)) return;
|
|
112
|
+
if (pluginOptions.jit) {
|
|
113
|
+
const result = jitTransform(code, id);
|
|
114
|
+
return {
|
|
115
|
+
code: result.code,
|
|
116
|
+
map: result.map
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
code = inlineResourceUrls(code, id);
|
|
120
|
+
let resolvedStyles;
|
|
121
|
+
let resolvedInlineStyles;
|
|
122
|
+
if (pluginOptions.inlineStylesExtension !== "css") {
|
|
123
|
+
const styleStrings = extractInlineStyles(code, id);
|
|
124
|
+
if (styleStrings.length > 0) {
|
|
125
|
+
resolvedInlineStyles = /* @__PURE__ */ new Map();
|
|
126
|
+
for (let i = 0; i < styleStrings.length; i++) try {
|
|
127
|
+
const fakePath = id.replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension}`);
|
|
128
|
+
if (!shouldPreprocessTestCss(resolvedConfig, fakePath)) {
|
|
129
|
+
resolvedInlineStyles.set(i, styleStrings[i]);
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const processed = await preprocessCSS(styleStrings[i], fakePath, resolvedConfig);
|
|
133
|
+
resolvedInlineStyles.set(i, processed.code);
|
|
134
|
+
} catch (e) {
|
|
135
|
+
if (debugCompile.enabled) debugCompile("inline style #%d preprocessing failed in %s: %s", i, id, e?.message);
|
|
136
|
+
}
|
|
137
|
+
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
ensureDtsRegistryForSource(code, id);
|
|
141
|
+
const result = compile(code, id, {
|
|
142
|
+
registry,
|
|
143
|
+
resolvedStyles,
|
|
144
|
+
resolvedInlineStyles,
|
|
145
|
+
useDefineForClassFields,
|
|
146
|
+
compilationMode: pluginOptions.fastCompileMode
|
|
147
|
+
});
|
|
148
|
+
for (const dep of result.resourceDependencies) resourceToSource.set(dep, id);
|
|
149
|
+
let outputCode = (vite.transformWithOxc ? await vite.transformWithOxc(result.code, id, {
|
|
150
|
+
lang: "ts",
|
|
151
|
+
sourcemap: false,
|
|
152
|
+
decorator: {
|
|
153
|
+
legacy: false,
|
|
154
|
+
emitDecoratorMetadata: false
|
|
155
|
+
}
|
|
156
|
+
}) : await vite.transformWithEsbuild(result.code, id, {
|
|
157
|
+
loader: "ts",
|
|
158
|
+
sourcemap: false
|
|
159
|
+
})).code;
|
|
160
|
+
if (watchMode && pluginOptions.liveReload) {
|
|
161
|
+
const fileDeclarations = [...registry.values()].filter((e) => e.fileName === id);
|
|
162
|
+
if (fileDeclarations.length > 0) {
|
|
163
|
+
const localDepClassNames = fileDeclarations.map((e) => e.className);
|
|
164
|
+
outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
code: outputCode,
|
|
169
|
+
map: result.map
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function resolveTsConfigPath() {
|
|
173
|
+
const { root, isProd, isLib } = tsConfigResolutionContext;
|
|
174
|
+
return getTsConfigPath(root, pluginOptions.tsconfigGetter(), isProd, pluginOptions.isTest, isLib);
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
178
|
+
enforce: "pre",
|
|
179
|
+
async config(config, { command }) {
|
|
180
|
+
watchMode = command === "serve";
|
|
181
|
+
const isProd = config.mode === "production" || process.env.NODE_ENV === "production";
|
|
182
|
+
tsConfigResolutionContext = {
|
|
183
|
+
root: config.root || ".",
|
|
184
|
+
isProd,
|
|
185
|
+
isLib: !!config?.build?.lib
|
|
186
|
+
};
|
|
187
|
+
const depOptimizer = createDepOptimizerConfig({
|
|
188
|
+
tsconfig: resolveTsConfigPath(),
|
|
189
|
+
isProd,
|
|
190
|
+
jit: pluginOptions.jit,
|
|
191
|
+
watchMode,
|
|
192
|
+
isTest: pluginOptions.isTest,
|
|
193
|
+
isAstroIntegration: pluginOptions.isAstroIntegration
|
|
194
|
+
});
|
|
195
|
+
return {
|
|
196
|
+
...vite.rolldownVersion ? { oxc: {} } : { esbuild: false },
|
|
197
|
+
...depOptimizer,
|
|
198
|
+
resolve: { conditions: [...depOptimizer.resolve.conditions, ...config.resolve?.conditions || defaultClientConditions] }
|
|
199
|
+
};
|
|
200
|
+
},
|
|
201
|
+
configResolved(config) {
|
|
202
|
+
resolvedConfig = config;
|
|
203
|
+
},
|
|
204
|
+
configureServer(server) {
|
|
205
|
+
server.watcher.on("add", async (filePath) => {
|
|
206
|
+
if (filePath.endsWith(".ts") && !filePath.endsWith(".spec.ts") && !filePath.endsWith(".d.ts")) await scanBarrelExports(filePath, /* @__PURE__ */ new Set(), true);
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
async buildStart() {
|
|
210
|
+
await initFastCompile();
|
|
211
|
+
},
|
|
212
|
+
async handleHotUpdate(ctx) {
|
|
213
|
+
if (resourceToSource.has(ctx.file)) {
|
|
214
|
+
const parentSource = resourceToSource.get(ctx.file);
|
|
215
|
+
const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
|
|
216
|
+
if (parentModule) return [parentModule];
|
|
217
|
+
}
|
|
218
|
+
if (TS_EXT_REGEX.test(ctx.file)) {
|
|
219
|
+
const [fileId] = ctx.file.split("?");
|
|
220
|
+
const oldEntries = [...registry.entries()].filter(([_, v]) => v.fileName === fileId).map(([k]) => k);
|
|
221
|
+
for (const key of oldEntries) registry.delete(key);
|
|
222
|
+
await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
|
|
223
|
+
}
|
|
224
|
+
return ctx.modules;
|
|
225
|
+
},
|
|
226
|
+
resolveId(id, importer) {
|
|
227
|
+
if (id.startsWith("virtual:@analogjs/vite-plugin-angular:inline-style:") || id.startsWith("virtual:@analogjs/vite-plugin-angular:raw:")) return `\0${id}`;
|
|
228
|
+
if (pluginOptions.jit && id.startsWith("angular:jit:")) {
|
|
229
|
+
const filePath = normalizePath(resolve(dirname(importer), id.split(";")[1]));
|
|
230
|
+
return id.includes(":style") ? toVirtualStyleId(filePath) : toVirtualRawId(filePath);
|
|
231
|
+
}
|
|
232
|
+
const rawRewrite = rewriteHtmlRawImport(id, importer);
|
|
233
|
+
if (rawRewrite) return rawRewrite;
|
|
234
|
+
const inlineRewrite = rewriteInlineStyleImport(id, importer);
|
|
235
|
+
if (inlineRewrite) return inlineRewrite;
|
|
236
|
+
},
|
|
237
|
+
async load(id) {
|
|
238
|
+
const styleModule = await loadVirtualStyleModule(this, id, resolvedConfig);
|
|
239
|
+
if (styleModule !== void 0) return styleModule;
|
|
240
|
+
const rawModule = await loadVirtualRawModule(this, id);
|
|
241
|
+
if (rawModule !== void 0) return rawModule;
|
|
242
|
+
if (/\.(css|scss|sass|less)\?inline$/.test(id)) {
|
|
243
|
+
const filePath = id.split("?")[0];
|
|
244
|
+
const code = await promises.readFile(filePath, "utf-8");
|
|
245
|
+
if (!shouldPreprocessTestCss(resolvedConfig, filePath)) return `export default ${JSON.stringify(code)}`;
|
|
246
|
+
const result = await preprocessCSS(code, filePath, resolvedConfig);
|
|
247
|
+
return `export default ${JSON.stringify(result.code)}`;
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
transform: {
|
|
251
|
+
filter: { id: {
|
|
252
|
+
include: [TS_EXT_REGEX],
|
|
253
|
+
exclude: [
|
|
254
|
+
/node_modules/,
|
|
255
|
+
"type=script",
|
|
256
|
+
"@ng/component"
|
|
257
|
+
]
|
|
258
|
+
} },
|
|
259
|
+
async handler(code, id) {
|
|
260
|
+
if (pluginOptions.transformFilter && !(pluginOptions.transformFilter(code, id) ?? true)) return;
|
|
261
|
+
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
262
|
+
return handleFastCompileTransform(code, id);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
//#endregion
|
|
268
|
+
export { fastCompilePlugin };
|
|
269
|
+
|
|
270
|
+
//# sourceMappingURL=fast-compile-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-compile-plugin.js","names":[],"sources":["../../../src/lib/fast-compile-plugin.ts"],"sourcesContent":["import { promises as fsPromises } from 'node:fs';\nimport { dirname, resolve } from 'node:path';\nimport * as vite from 'vite';\n\nimport * as compilerCli from '@angular/compiler-cli';\nimport {\n defaultClientConditions,\n normalizePath,\n Plugin,\n preprocessCSS,\n ResolvedConfig,\n} from 'vite';\n\nimport {\n compile,\n scanFile,\n scanPackageDts,\n collectImportedPackages,\n collectRelativeReExports,\n jitTransform,\n inlineResourceUrls,\n extractInlineStyles,\n generateHmrCode,\n debugCompile,\n debugRegistry,\n type ComponentRegistry,\n} from './compiler/index.js';\n\nimport {\n TS_EXT_REGEX,\n getTsConfigPath,\n createDepOptimizerConfig,\n type TsConfigResolutionContext,\n} from './utils/plugin-config.js';\nimport {\n VIRTUAL_RAW_PREFIX,\n VIRTUAL_STYLE_PREFIX,\n toVirtualRawId,\n toVirtualStyleId,\n} from './utils/virtual-ids.js';\nimport {\n loadVirtualRawModule,\n loadVirtualStyleModule,\n rewriteHtmlRawImport,\n rewriteInlineStyleImport,\n shouldPreprocessTestCss,\n} from './utils/virtual-resources.js';\n\nexport interface FastCompilePluginOptions {\n tsconfigGetter: () => string;\n workspaceRoot: string;\n inlineStylesExtension: string;\n jit: boolean;\n liveReload: boolean;\n supportedBrowsers: string[];\n transformFilter?: (code: string, id: string) => boolean;\n isTest: boolean;\n isAstroIntegration: boolean;\n fastCompileMode?: 'full' | 'partial';\n}\n\nexport function fastCompilePlugin(\n pluginOptions: FastCompilePluginOptions,\n): Plugin {\n let resolvedConfig: ResolvedConfig;\n let tsConfigResolutionContext: TsConfigResolutionContext | null = null;\n let watchMode = false;\n\n // fast-compile plugin state\n const registry: ComponentRegistry = new Map();\n const resourceToSource = new Map<string, string>();\n const scannedDtsPackages = new Set<string>();\n let projectRoot = '';\n let useDefineForClassFields = true;\n\n /**\n * Scan a file into the registry, then recursively walk its relative\n * `export *` / `export { … } from './x'` chain so any underlying\n * directive classes also land in the registry. Used both at\n * `buildStart` (for tsconfig path entries) and at dev time (file\n * `add` and `handleHotUpdate`) so newly added barrels stay in sync\n * without requiring a server restart.\n *\n * The `visited` set prevents infinite recursion within a single\n * top-level call. Each fresh scan should pass an empty set (so HMR\n * re-scans aren't blocked by buildStart's earlier visits).\n */\n async function scanBarrelExports(\n file: string,\n visited: Set<string> = new Set(),\n overwrite = false,\n ): Promise<void> {\n if (visited.has(file)) return;\n visited.add(file);\n let code: string;\n try {\n code = await fsPromises.readFile(file, 'utf-8');\n } catch (e) {\n if (debugRegistry.enabled) {\n debugRegistry(\n 'scanBarrelExports: failed to read %s: %s',\n file,\n (e as Error)?.message,\n );\n }\n return;\n }\n const entries = scanFile(code, file);\n for (const entry of entries) {\n // At buildStart we want stable registry entries (don't overwrite\n // an earlier scan with a barrel re-scan); HMR explicitly asks\n // for overwrite so updated metadata replaces stale entries.\n if (overwrite || !registry.has(entry.className)) {\n registry.set(entry.className, entry);\n }\n }\n // Collect every relative re-export specifier via OXC AST so\n // recursive scans can't trip over each other (a shared `/g` regex\n // would have its `lastIndex` reset by each recursive call and\n // silently skip half of an outer barrel's re-exports, which\n // previously left directives like `HlmRadioGroup` unregistered).\n const dir = dirname(file);\n for (const rel of collectRelativeReExports(code, file)) {\n // NodeNext-style libraries write `export * from './foo.js'`\n // even though the source is `./foo.ts`. Strip the ESM\n // extension before probing or the candidates would be\n // `foo.js.ts` / `foo.js/index.ts`, which never exist.\n const normalizedRel = rel.replace(/\\.(?:js|mjs)$/u, '');\n const reExportCandidates = [\n resolve(dir, normalizedRel + '.ts'),\n resolve(dir, normalizedRel, 'index.ts'),\n ];\n let resolved = false;\n for (const candidate of reExportCandidates) {\n try {\n await fsPromises.access(candidate);\n await scanBarrelExports(candidate, visited, overwrite);\n resolved = true;\n break;\n } catch {\n // try next candidate\n }\n }\n if (!resolved && debugRegistry.enabled) {\n debugRegistry(\n 'scanBarrelExports: %s re-export %s did not resolve to %o',\n file,\n rel,\n reExportCandidates,\n );\n }\n }\n }\n\n async function initFastCompile() {\n if (pluginOptions.jit) return; // JIT: no registry scan needed\n\n // Scan all source files to build the registry\n registry.clear();\n scannedDtsPackages.clear();\n const resolvedTsConfigPath = resolveTsConfigPath();\n projectRoot = dirname(resolvedTsConfigPath);\n const config = compilerCli.readConfiguration(resolvedTsConfigPath);\n useDefineForClassFields = config.options?.useDefineForClassFields ?? true;\n\n // Collect candidate files: tsconfig rootNames PLUS the entry points\n // named in `compilerOptions.paths`. App tsconfigs typically only\n // include the app's own sources, so workspace library entry barrels\n // (e.g. `HlmSelectImports = [HlmSelect, HlmSelectContent, ...] as\n // const`) live outside `rootNames` and would otherwise miss the\n // initial scan. The compiler then can't see that `HlmSelectImports`\n // is a tuple barrel and emits the bare identifier into the parent\n // component's `dependencies()` list, where Angular's runtime\n // silently drops it because arrays don't have a directive def.\n const candidates = new Set<string>(config.rootNames);\n const tsPaths = config.options?.paths;\n const baseUrl = (config.options?.baseUrl ?? projectRoot) as string;\n if (tsPaths) {\n for (const targets of Object.values(tsPaths)) {\n for (const target of targets as string[]) {\n // Skip wildcard patterns — entry barrels are normally exact\n // file paths like \"libs/helm/select/src/index.ts\".\n if (target.includes('*')) continue;\n candidates.add(resolve(baseUrl, target));\n }\n }\n }\n const results = await Promise.all(\n Array.from(candidates).map(async (file) => {\n try {\n const code = await fsPromises.readFile(file, 'utf-8');\n return scanFile(code, file);\n } catch (e) {\n if (debugRegistry.enabled) {\n debugRegistry(\n 'initFastCompile: skipping unreadable %s: %s',\n file,\n (e as Error)?.message,\n );\n }\n return []; // Skip unreadable files\n }\n }),\n );\n\n for (const entries of results) {\n for (const entry of entries) {\n registry.set(entry.className, entry);\n }\n }\n\n // Library barrels typically `export * from './lib/...'` rather than\n // declaring directives directly, so the entry file alone gives us\n // the tuple consts but not the directive classes they reference.\n // Walk the relative `export *` chain so the underlying classes also\n // land in the registry. Use a SHARED visited set across all\n // barrels so recursive walks don't double-scan a file that's\n // re-exported from multiple entry points.\n const buildStartVisited = new Set<string>();\n if (tsPaths) {\n const barrelCandidates: string[] = [];\n for (const targets of Object.values(tsPaths)) {\n for (const target of targets as string[]) {\n if (target.includes('*')) continue;\n barrelCandidates.push(resolve(baseUrl, target));\n }\n }\n await Promise.all(\n barrelCandidates.map((c) => scanBarrelExports(c, buildStartVisited)),\n );\n }\n debugRegistry(\n 'initFastCompile done: %d entries from %d candidate files',\n registry.size,\n candidates.size,\n );\n }\n\n function ensureDtsRegistryForSource(code: string, id: string) {\n for (const pkg of collectImportedPackages(code, id)) {\n if (scannedDtsPackages.has(pkg)) continue;\n scannedDtsPackages.add(pkg);\n\n try {\n const dtsEntries = scanPackageDts(pkg, projectRoot);\n for (const entry of dtsEntries) {\n if (!registry.has(entry.className)) {\n registry.set(entry.className, entry);\n }\n }\n } catch {\n // Package may not have .d.ts files or may not be Angular\n }\n }\n }\n\n async function handleFastCompileTransform(\n code: string,\n id: string,\n ): Promise<{ code: string; map: any } | undefined> {\n if (!/(Component|Directive|Pipe|Injectable|NgModule)\\(/.test(code)) {\n // Non-Angular file — leave it alone so a downstream plugin (or\n // Vite's built-in TS handler) can process it.\n return undefined;\n }\n\n // JIT mode\n if (pluginOptions.jit) {\n const result = jitTransform(code, id);\n return { code: result.code, map: result.map };\n }\n\n // Inline external templateUrl/styleUrl(s) into the source before compilation\n code = inlineResourceUrls(code, id);\n\n // Pre-resolve inline styles that need preprocessing (SCSS/Sass/Less)\n let resolvedStyles: Map<string, string> | undefined;\n let resolvedInlineStyles: Map<number, string> | undefined;\n\n if (pluginOptions.inlineStylesExtension !== 'css') {\n const styleStrings = extractInlineStyles(code, id);\n\n if (styleStrings.length > 0) {\n resolvedInlineStyles = new Map();\n for (let i = 0; i < styleStrings.length; i++) {\n try {\n const fakePath = id.replace(\n /\\.ts$/,\n `.inline-${i}.${pluginOptions.inlineStylesExtension}`,\n );\n // In tests, mirror Vitest's `test.css` rules — defaults to no\n // preprocessing (matches Vite's CSS pipeline behavior). (#2297)\n if (!shouldPreprocessTestCss(resolvedConfig, fakePath)) {\n resolvedInlineStyles.set(i, styleStrings[i]);\n continue;\n }\n const processed = await preprocessCSS(\n styleStrings[i],\n fakePath,\n resolvedConfig,\n );\n resolvedInlineStyles.set(i, processed.code);\n } catch (e) {\n if (debugCompile.enabled) {\n debugCompile(\n 'inline style #%d preprocessing failed in %s: %s',\n i,\n id,\n (e as Error)?.message,\n );\n }\n // Skip styles that can't be preprocessed\n }\n }\n if (resolvedInlineStyles.size === 0) resolvedInlineStyles = undefined;\n }\n }\n\n ensureDtsRegistryForSource(code, id);\n\n const result = compile(code, id, {\n registry,\n resolvedStyles,\n resolvedInlineStyles,\n useDefineForClassFields,\n compilationMode: pluginOptions.fastCompileMode,\n });\n\n // Track resource dependencies for HMR\n for (const dep of result.resourceDependencies) {\n resourceToSource.set(dep, id);\n }\n\n // Strip TypeScript-only syntax\n const stripped = vite.transformWithOxc\n ? await vite.transformWithOxc(result.code, id, {\n lang: 'ts',\n sourcemap: false,\n decorator: { legacy: false, emitDecoratorMetadata: false },\n })\n : await vite.transformWithEsbuild(result.code, id, {\n loader: 'ts',\n sourcemap: false,\n });\n let outputCode = stripped.code;\n\n // Append HMR code in dev mode\n if (watchMode && pluginOptions.liveReload) {\n const fileDeclarations = [...registry.values()].filter(\n (e) => e.fileName === id,\n );\n if (fileDeclarations.length > 0) {\n const localDepClassNames = fileDeclarations.map((e) => e.className);\n outputCode += generateHmrCode(fileDeclarations, localDepClassNames);\n }\n }\n\n return { code: outputCode, map: result.map };\n }\n\n function resolveTsConfigPath() {\n const { root, isProd, isLib } = tsConfigResolutionContext!;\n return getTsConfigPath(\n root,\n pluginOptions.tsconfigGetter(),\n isProd,\n pluginOptions.isTest,\n isLib,\n );\n }\n\n return {\n name: '@analogjs/vite-plugin-angular-fast-compile',\n enforce: 'pre' as const,\n async config(config, { command }) {\n watchMode = command === 'serve';\n const isProd =\n config.mode === 'production' ||\n process.env['NODE_ENV'] === 'production';\n\n tsConfigResolutionContext = {\n root: config.root || '.',\n isProd,\n isLib: !!config?.build?.lib,\n };\n\n const preliminaryTsConfigPath = resolveTsConfigPath();\n\n const depOptimizer = createDepOptimizerConfig({\n tsconfig: preliminaryTsConfigPath,\n isProd,\n jit: pluginOptions.jit,\n watchMode,\n isTest: pluginOptions.isTest,\n isAstroIntegration: pluginOptions.isAstroIntegration,\n });\n\n return {\n ...(vite.rolldownVersion ? { oxc: {} as any } : { esbuild: false }),\n ...depOptimizer,\n resolve: {\n conditions: [\n ...depOptimizer.resolve.conditions,\n ...(config.resolve?.conditions || defaultClientConditions),\n ],\n },\n };\n },\n configResolved(config) {\n resolvedConfig = config;\n },\n configureServer(server) {\n // Watch for new .ts files and scan them into the registry. Use\n // the barrel-aware scanner so a newly added re-export entry\n // (`export * from './x'`) also expands its underlying directive\n // classes — otherwise the registry stays stale until restart.\n server.watcher.on('add', async (filePath) => {\n if (\n filePath.endsWith('.ts') &&\n !filePath.endsWith('.spec.ts') &&\n !filePath.endsWith('.d.ts')\n ) {\n await scanBarrelExports(filePath, new Set(), true);\n }\n });\n },\n async buildStart() {\n await initFastCompile();\n },\n async handleHotUpdate(ctx) {\n // Resource file changes → invalidate parent .ts module\n if (resourceToSource.has(ctx.file)) {\n const parentSource = resourceToSource.get(ctx.file)!;\n const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);\n if (parentModule) {\n return [parentModule];\n }\n }\n\n if (TS_EXT_REGEX.test(ctx.file)) {\n const [fileId] = ctx.file.split('?');\n\n // Remove old entries from this file\n const oldEntries = [...registry.entries()]\n .filter(([_, v]) => v.fileName === fileId)\n .map(([k]) => k);\n for (const key of oldEntries) {\n registry.delete(key);\n }\n\n // Rescan the changed file via the barrel-aware scanner so an\n // edited barrel re-export picks up newly-referenced files.\n // Pass overwrite=true so updated metadata replaces stale\n // entries from the previous scan.\n await scanBarrelExports(fileId, new Set(), true);\n }\n\n // Let Vite handle the rest — the transform hook will recompile\n return ctx.modules;\n },\n resolveId(id, importer) {\n if (\n id.startsWith(VIRTUAL_STYLE_PREFIX) ||\n id.startsWith(VIRTUAL_RAW_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n if (pluginOptions.jit && id.startsWith('angular:jit:')) {\n const filePath = normalizePath(\n resolve(dirname(importer as string), id.split(';')[1]),\n );\n return id.includes(':style')\n ? toVirtualStyleId(filePath)\n : toVirtualRawId(filePath);\n }\n\n const rawRewrite = rewriteHtmlRawImport(id, importer);\n if (rawRewrite) return rawRewrite;\n\n const inlineRewrite = rewriteInlineStyleImport(id, importer);\n if (inlineRewrite) return inlineRewrite;\n\n return undefined;\n },\n async load(id) {\n const styleModule = await loadVirtualStyleModule(\n this,\n id,\n resolvedConfig,\n );\n if (styleModule !== undefined) return styleModule;\n\n const rawModule = await loadVirtualRawModule(this, id);\n if (rawModule !== undefined) return rawModule;\n\n // Vitest bypass: module-runner skips resolveId, so the bare `?inline`\n // query reaches load unchanged.\n if (/\\.(css|scss|sass|less)\\?inline$/.test(id)) {\n const filePath = id.split('?')[0];\n const code = await fsPromises.readFile(filePath, 'utf-8');\n // In tests, mirror Vitest's `test.css` rules — defaults to no\n // preprocessing (matches Vite's CSS pipeline behavior). (#2297)\n if (!shouldPreprocessTestCss(resolvedConfig, filePath)) {\n return `export default ${JSON.stringify(code)}`;\n }\n const result = await preprocessCSS(code, filePath, resolvedConfig);\n return `export default ${JSON.stringify(result.code)}`;\n }\n\n return;\n },\n transform: {\n filter: {\n id: {\n include: [TS_EXT_REGEX],\n exclude: [/node_modules/, 'type=script', '@ng/component'],\n },\n },\n async handler(code, id) {\n if (\n pluginOptions.transformFilter &&\n !(pluginOptions.transformFilter(code, id) ?? true)\n ) {\n return;\n }\n\n if (id.includes('.ts?')) {\n id = id.replace(/\\?(.*)/, '');\n }\n return handleFastCompileTransform(code, id);\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA6DA,SAAgB,kBACd,eACQ;CACR,IAAI;CACJ,IAAI,4BAA8D;CAClE,IAAI,YAAY;CAGhB,MAAM,2BAA8B,IAAI,KAAK;CAC7C,MAAM,mCAAmB,IAAI,KAAqB;CAClD,MAAM,qCAAqB,IAAI,KAAa;CAC5C,IAAI,cAAc;CAClB,IAAI,0BAA0B;;;;;;;;;;;;;CAc9B,eAAe,kBACb,MACA,0BAAuB,IAAI,KAAK,EAChC,YAAY,OACG;AACf,MAAI,QAAQ,IAAI,KAAK,CAAE;AACvB,UAAQ,IAAI,KAAK;EACjB,IAAI;AACJ,MAAI;AACF,UAAO,MAAM,SAAW,SAAS,MAAM,QAAQ;WACxC,GAAG;AACV,OAAI,cAAc,QAChB,eACE,4CACA,MACC,GAAa,QACf;AAEH;;EAEF,MAAM,UAAU,SAAS,MAAM,KAAK;AACpC,OAAK,MAAM,SAAS,QAIlB,KAAI,aAAa,CAAC,SAAS,IAAI,MAAM,UAAU,CAC7C,UAAS,IAAI,MAAM,WAAW,MAAM;EAQxC,MAAM,MAAM,QAAQ,KAAK;AACzB,OAAK,MAAM,OAAO,yBAAyB,MAAM,KAAK,EAAE;GAKtD,MAAM,gBAAgB,IAAI,QAAQ,kBAAkB,GA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@@
|
|
|
1
|
-
import * as ts from
|
|
2
|
-
import type
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
import { type StylePreprocessor } from "./style-preprocessor.js";
|
|
3
|
+
import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
|
|
4
|
+
import type { SourceFileCache } from "./utils/source-file-cache.js";
|
|
3
5
|
export declare function augmentHostWithResources(host: ts.CompilerHost, transform: (code: string, id: string, options?: {
|
|
4
|
-
|
|
6
|
+
ssr?: boolean;
|
|
5
7
|
}) => ReturnType<any> | null, options: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
inlineStylesExtension: string;
|
|
9
|
+
isProd?: boolean;
|
|
10
|
+
stylesheetRegistry?: AnalogStylesheetRegistry;
|
|
11
|
+
sourceFileCache?: SourceFileCache;
|
|
12
|
+
stylePreprocessor?: StylePreprocessor;
|
|
11
13
|
}): void;
|
|
12
14
|
export declare function augmentProgramWithVersioning(program: ts.Program): void;
|
|
13
15
|
export declare function augmentHostWithCaching(host: ts.CompilerHost, cache: Map<string, ts.SourceFile>): void;
|