@analogjs/vite-plugin-angular 3.0.0-beta.5 → 3.0.0-beta.50

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.
Files changed (133) hide show
  1. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +2 -1
  2. package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
  3. package/ngp/LICENSE +21 -0
  4. package/ngp/api.mjs +46806 -0
  5. package/ngp/build.json +4 -0
  6. package/ngp/ng_analyze.cjs +601 -0
  7. package/ngp/ng_analyze_bg.wasm +0 -0
  8. package/package.json +4 -1
  9. package/src/index.d.ts +2 -0
  10. package/src/index.js +3 -1
  11. package/src/index.js.map +1 -1
  12. package/src/lib/analog-plugin-interop.js +1 -1
  13. package/src/lib/angular-build-context.d.ts +215 -0
  14. package/src/lib/angular-build-context.js +361 -0
  15. package/src/lib/angular-build-context.js.map +1 -0
  16. package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
  17. package/src/lib/angular-build-optimizer-plugin.js +24 -9
  18. package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
  19. package/src/lib/angular-jit-plugin.d.ts +5 -3
  20. package/src/lib/angular-jit-plugin.js +14 -6
  21. package/src/lib/angular-jit-plugin.js.map +1 -1
  22. package/src/lib/angular-vite-plugin.d.ts +6 -109
  23. package/src/lib/angular-vite-plugin.js +8 -1249
  24. package/src/lib/angular-vite-plugin.js.map +1 -1
  25. package/src/lib/angular-vitest-plugin.d.ts +3 -2
  26. package/src/lib/angular-vitest-plugin.js +6 -3
  27. package/src/lib/angular-vitest-plugin.js.map +1 -1
  28. package/src/lib/companion-plugins.d.ts +7 -0
  29. package/src/lib/companion-plugins.js +38 -0
  30. package/src/lib/companion-plugins.js.map +1 -0
  31. package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
  32. package/src/lib/compilation-api/compilation-api-plugin.js +154 -282
  33. package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
  34. package/src/lib/compiler/compile.d.ts +1 -1
  35. package/src/lib/compiler/compile.js +190 -145
  36. package/src/lib/compiler/compile.js.map +1 -1
  37. package/src/lib/compiler/defer.d.ts +2 -3
  38. package/src/lib/compiler/defer.js +12 -14
  39. package/src/lib/compiler/defer.js.map +1 -1
  40. package/src/lib/compiler/dts-reader.d.ts +6 -1
  41. package/src/lib/compiler/dts-reader.js +19 -10
  42. package/src/lib/compiler/dts-reader.js.map +1 -1
  43. package/src/lib/compiler/hmr.d.ts +4 -0
  44. package/src/lib/compiler/hmr.js +7 -2
  45. package/src/lib/compiler/hmr.js.map +1 -1
  46. package/src/lib/compiler/index.d.ts +2 -2
  47. package/src/lib/compiler/index.js +4 -4
  48. package/src/lib/compiler/jit-metadata.d.ts +3 -1
  49. package/src/lib/compiler/jit-metadata.js +10 -8
  50. package/src/lib/compiler/jit-metadata.js.map +1 -1
  51. package/src/lib/compiler/jit-transform.js +2 -2
  52. package/src/lib/compiler/jit-transform.js.map +1 -1
  53. package/src/lib/compiler/js-emitter.d.ts +0 -3
  54. package/src/lib/compiler/js-emitter.js +3 -21
  55. package/src/lib/compiler/js-emitter.js.map +1 -1
  56. package/src/lib/compiler/registry.d.ts +7 -1
  57. package/src/lib/compiler/registry.js +23 -3
  58. package/src/lib/compiler/registry.js.map +1 -1
  59. package/src/lib/compiler/resource-inliner.d.ts +8 -9
  60. package/src/lib/compiler/resource-inliner.js +10 -18
  61. package/src/lib/compiler/resource-inliner.js.map +1 -1
  62. package/src/lib/compiler/style-ast.d.ts +9 -1
  63. package/src/lib/compiler/style-ast.js +26 -5
  64. package/src/lib/compiler/style-ast.js.map +1 -1
  65. package/src/lib/compiler/type-elision.d.ts +4 -3
  66. package/src/lib/compiler/type-elision.js +10 -11
  67. package/src/lib/compiler/type-elision.js.map +1 -1
  68. package/src/lib/compiler/utils.d.ts +9 -7
  69. package/src/lib/compiler/utils.js +49 -9
  70. package/src/lib/compiler/utils.js.map +1 -1
  71. package/src/lib/component-scanner.d.ts +74 -0
  72. package/src/lib/component-scanner.js +178 -0
  73. package/src/lib/component-scanner.js.map +1 -0
  74. package/src/lib/component-styles-plugin.d.ts +52 -0
  75. package/src/lib/component-styles-plugin.js +353 -0
  76. package/src/lib/component-styles-plugin.js.map +1 -0
  77. package/src/lib/compose-angular-plugins.d.ts +12 -0
  78. package/src/lib/compose-angular-plugins.js +31 -0
  79. package/src/lib/compose-angular-plugins.js.map +1 -0
  80. package/src/lib/dev-server-mode-plugin.d.ts +7 -0
  81. package/src/lib/dev-server-mode-plugin.js +23 -0
  82. package/src/lib/dev-server-mode-plugin.js.map +1 -0
  83. package/src/lib/fast-compile-api.d.ts +62 -0
  84. package/src/lib/fast-compile-api.js +12 -0
  85. package/src/lib/fast-compile-api.js.map +1 -0
  86. package/src/lib/fast-compile-plugin.d.ts +6 -1
  87. package/src/lib/fast-compile-plugin.js +167 -107
  88. package/src/lib/fast-compile-plugin.js.map +1 -1
  89. package/src/lib/host.d.ts +3 -0
  90. package/src/lib/host.js +4 -2
  91. package/src/lib/host.js.map +1 -1
  92. package/src/lib/live-reload-plugin.d.ts +6 -3
  93. package/src/lib/live-reload-plugin.js +13 -6
  94. package/src/lib/live-reload-plugin.js.map +1 -1
  95. package/src/lib/ngp-compile-api.d.ts +55 -0
  96. package/src/lib/ngp-compile-api.js +12 -0
  97. package/src/lib/ngp-compile-api.js.map +1 -0
  98. package/src/lib/ngp-compile-plugin.d.ts +4 -0
  99. package/src/lib/ngp-compile-plugin.js +662 -0
  100. package/src/lib/ngp-compile-plugin.js.map +1 -0
  101. package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
  102. package/src/lib/ngtsc-compile-plugin.js +778 -0
  103. package/src/lib/ngtsc-compile-plugin.js.map +1 -0
  104. package/src/lib/nx-folder-plugin.d.ts +6 -5
  105. package/src/lib/nx-folder-plugin.js +12 -7
  106. package/src/lib/nx-folder-plugin.js.map +1 -1
  107. package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
  108. package/src/lib/plugins/file-replacements.plugin.js +1 -0
  109. package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
  110. package/src/lib/router-plugin.d.ts +5 -1
  111. package/src/lib/router-plugin.js +13 -4
  112. package/src/lib/router-plugin.js.map +1 -1
  113. package/src/lib/utils/compilation-shared.js +1 -1
  114. package/src/lib/utils/devkit.js +1 -1
  115. package/src/lib/utils/hmr-component-updates.d.ts +7 -0
  116. package/src/lib/utils/hmr-component-updates.js +87 -0
  117. package/src/lib/utils/hmr-component-updates.js.map +1 -0
  118. package/src/lib/utils/lsp-type-checker.d.ts +75 -0
  119. package/src/lib/utils/lsp-type-checker.js +531 -0
  120. package/src/lib/utils/lsp-type-checker.js.map +1 -0
  121. package/src/lib/utils/ngp-host-fs.d.ts +32 -0
  122. package/src/lib/utils/ngp-host-fs.js +104 -0
  123. package/src/lib/utils/ngp-host-fs.js.map +1 -0
  124. package/src/lib/utils/plugin-config.d.ts +15 -8
  125. package/src/lib/utils/plugin-config.js +18 -5
  126. package/src/lib/utils/plugin-config.js.map +1 -1
  127. package/src/lib/utils/stylesheet-warning.d.ts +2 -0
  128. package/src/lib/utils/stylesheet-warning.js +11 -0
  129. package/src/lib/utils/stylesheet-warning.js.map +1 -0
  130. package/src/lib/utils/tsconfig-resolver.js +1 -1
  131. package/src/lib/virtual-modules-plugin.d.ts +11 -3
  132. package/src/lib/virtual-modules-plugin.js +43 -12
  133. package/src/lib/virtual-modules-plugin.js.map +1 -1
@@ -0,0 +1,74 @@
1
+ import type { parseSync } from "oxc-parser";
2
+ import type { ComponentRegistryEntries } from "./analog-plugin-interop.js";
3
+ import { type ComponentRegistry, type RegistryEntry } from "./compiler/index.js";
4
+ import type { FastCompileResolve, FastCompileSourceFormat } from "./fast-compile-api.js";
5
+ type OxcProgram = ReturnType<typeof parseSync>["program"];
6
+ /** Resolves an import to a source file to scan, or `null` to skip it. */
7
+ export type ResolveImport = (spec: string, importer: string) => Promise<string | null>;
8
+ /**
9
+ * Angular classes scanned from source files and package `.d.ts` declarations,
10
+ * so source formats can look up the selectors of the components they import
11
+ * before any compiler sees their modules. Shared by the fast compile and NGP
12
+ * plugins.
13
+ */
14
+ export declare class ComponentScanner {
15
+ readonly registry: ComponentRegistry;
16
+ readonly scannedDtsPackages: Set<string>;
17
+ /** Files scanned on demand, mapped to the barrel chain each pulled in. */
18
+ readonly lazyScans: Map<string, Promise<Set<string>>>;
19
+ /** Modules compiled against each scanned file. */
20
+ readonly importersByFile: Map<string, Set<string>>;
21
+ private readonly sourceFormats;
22
+ private root;
23
+ /** Where package declarations are looked up from. */
24
+ get projectRoot(): string;
25
+ reset(projectRoot: string): void;
26
+ registerSourceFormat(format: FastCompileSourceFormat): void;
27
+ sourceFormatOf(file: string): FastCompileSourceFormat | undefined;
28
+ /** Whether `file` is TypeScript or a module of a registered source format. */
29
+ isCompiledSource(file: string): boolean;
30
+ /**
31
+ * Reads a source file for scanning. Modules of a registered source format
32
+ * are converted to TypeScript first so the scanner sees their classes.
33
+ */
34
+ readScanSource(file: string): Promise<string>;
35
+ /**
36
+ * Adapts a Vite-style resolver to the scanner's: only source files this
37
+ * scanner reads, outside `node_modules` (package declarations come from the
38
+ * `.d.ts` scanner instead).
39
+ */
40
+ toResolveImport(resolve: FastCompileResolve): ResolveImport;
41
+ /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */
42
+ ensureDtsRegistryForPackages(packages: Iterable<string>): void;
43
+ ensureDtsRegistryForSource(code: string, id: string, program?: OxcProgram): void;
44
+ /**
45
+ * Scans the modules behind `specifiers`, imported by `importer`: packages
46
+ * from their `.d.ts` declarations, everything else from source.
47
+ */
48
+ scanImports(specifiers: string[], importer: string, resolve: FastCompileResolve): Promise<void>;
49
+ /**
50
+ * Scans the files behind `specs`, imported by `id`, into the registry and
51
+ * records `id` as their importer.
52
+ */
53
+ resolveImportSpecifiers(specs: string[], id: string, resolveImport: ResolveImport): Promise<void>;
54
+ /**
55
+ * The element selector of a component or directive class. `external` are
56
+ * registries contributed through `analog.setup()`.
57
+ */
58
+ lookupSelector(className: string, external?: readonly ComponentRegistryEntries[]): string | null;
59
+ /** The files scanned for `importer`. */
60
+ dependenciesOf(importer: string): string[];
61
+ entriesOf(file: string): RegistryEntry[];
62
+ /** Drops what was scanned from `file`, so the next scan reads it again. */
63
+ invalidate(file: string): void;
64
+ private addEntry;
65
+ private scanOnDemand;
66
+ /**
67
+ * Scan a file and everything it re-exports, resolving specifiers through
68
+ * Vite so path aliases work. Tuple barrels and NgModules can list classes
69
+ * their file imports without re-exporting, so their imports are followed
70
+ * too. Returns every file scanned.
71
+ */
72
+ private scanWithReExports;
73
+ }
74
+ export {};
@@ -0,0 +1,178 @@
1
+ import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX } from "./utils/plugin-config.js";
2
+ import { parseOxc } from "./compiler/utils.js";
3
+ import { scanFile } from "./compiler/registry.js";
4
+ import { collectAllImports, collectImportedPackages, collectReExports, scanPackageDts } from "./compiler/dts-reader.js";
5
+ import "./compiler/index.js";
6
+ import { promises } from "node:fs";
7
+ import { normalizePath } from "vite";
8
+ //#region packages/vite-plugin-angular/src/lib/component-scanner.ts
9
+ /**
10
+ * Angular classes scanned from source files and package `.d.ts` declarations,
11
+ * so source formats can look up the selectors of the components they import
12
+ * before any compiler sees their modules. Shared by the fast compile and NGP
13
+ * plugins.
14
+ */
15
+ var ComponentScanner = class {
16
+ registry = /* @__PURE__ */ new Map();
17
+ scannedDtsPackages = /* @__PURE__ */ new Set();
18
+ /** Files scanned on demand, mapped to the barrel chain each pulled in. */
19
+ lazyScans = /* @__PURE__ */ new Map();
20
+ /** Modules compiled against each scanned file. */
21
+ importersByFile = /* @__PURE__ */ new Map();
22
+ sourceFormats = [];
23
+ root = "";
24
+ /** Where package declarations are looked up from. */
25
+ get projectRoot() {
26
+ return this.root;
27
+ }
28
+ reset(projectRoot) {
29
+ this.root = projectRoot;
30
+ this.registry.clear();
31
+ this.scannedDtsPackages.clear();
32
+ this.lazyScans.clear();
33
+ this.importersByFile.clear();
34
+ }
35
+ registerSourceFormat(format) {
36
+ if (!this.sourceFormats.includes(format)) this.sourceFormats.push(format);
37
+ }
38
+ sourceFormatOf(file) {
39
+ const path = file.split("?")[0];
40
+ return this.sourceFormats.find((format) => format.test(path));
41
+ }
42
+ /** Whether `file` is TypeScript or a module of a registered source format. */
43
+ isCompiledSource(file) {
44
+ return TS_EXT_REGEX.test(file) || this.sourceFormatOf(file) !== void 0;
45
+ }
46
+ /**
47
+ * Reads a source file for scanning. Modules of a registered source format
48
+ * are converted to TypeScript first so the scanner sees their classes.
49
+ */
50
+ async readScanSource(file) {
51
+ const code = await promises.readFile(file, "utf-8");
52
+ const format = this.sourceFormatOf(file);
53
+ return format ? format.toScanSource(code, file) : code;
54
+ }
55
+ /**
56
+ * Adapts a Vite-style resolver to the scanner's: only source files this
57
+ * scanner reads, outside `node_modules` (package declarations come from the
58
+ * `.d.ts` scanner instead).
59
+ */
60
+ toResolveImport(resolve) {
61
+ return async (spec, importer) => {
62
+ const resolved = await resolve(spec, importer);
63
+ if (!resolved || resolved.external) return null;
64
+ const file = normalizePath(resolved.id.split("?")[0]);
65
+ return this.isCompiledSource(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
66
+ };
67
+ }
68
+ /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */
69
+ ensureDtsRegistryForPackages(packages) {
70
+ for (const pkg of packages) {
71
+ if (this.scannedDtsPackages.has(pkg)) continue;
72
+ this.scannedDtsPackages.add(pkg);
73
+ try {
74
+ const dtsEntries = scanPackageDts(pkg, this.root || process.cwd(), this.scannedDtsPackages);
75
+ for (const entry of dtsEntries) this.addEntry(entry);
76
+ } catch {}
77
+ }
78
+ }
79
+ ensureDtsRegistryForSource(code, id, program) {
80
+ this.ensureDtsRegistryForPackages(collectImportedPackages(code, id, program));
81
+ }
82
+ /**
83
+ * Scans the modules behind `specifiers`, imported by `importer`: packages
84
+ * from their `.d.ts` declarations, everything else from source.
85
+ */
86
+ scanImports(specifiers, importer, resolve) {
87
+ this.ensureDtsRegistryForPackages(specifiers.filter((spec) => !spec.startsWith(".") && !spec.startsWith("/")).map((spec) => {
88
+ const parts = spec.split("/");
89
+ return spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
90
+ }));
91
+ return this.resolveImportSpecifiers(specifiers, importer, this.toResolveImport(resolve));
92
+ }
93
+ /**
94
+ * Scans the files behind `specs`, imported by `id`, into the registry and
95
+ * records `id` as their importer.
96
+ */
97
+ async resolveImportSpecifiers(specs, id, resolveImport) {
98
+ await Promise.all(specs.map(async (spec) => {
99
+ const file = await resolveImport(spec, id);
100
+ if (!file) return;
101
+ for (const scanned of await this.scanOnDemand(file, resolveImport)) {
102
+ let importers = this.importersByFile.get(scanned);
103
+ if (!importers) {
104
+ importers = /* @__PURE__ */ new Set();
105
+ this.importersByFile.set(scanned, importers);
106
+ }
107
+ importers.add(id);
108
+ }
109
+ }));
110
+ }
111
+ /**
112
+ * The element selector of a component or directive class. `external` are
113
+ * registries contributed through `analog.setup()`.
114
+ */
115
+ lookupSelector(className, external = []) {
116
+ const entry = this.registry.get(className) ?? external.map((r) => r.get(className)).find((e) => e !== void 0);
117
+ if (!entry || entry.kind !== "component" && entry.kind !== "directive") return null;
118
+ return entry.selector;
119
+ }
120
+ /** The files scanned for `importer`. */
121
+ dependenciesOf(importer) {
122
+ return [...this.importersByFile].filter(([, importers]) => importers.has(importer)).map(([file]) => file);
123
+ }
124
+ entriesOf(file) {
125
+ return [...this.registry.values()].filter((e) => e.fileName === file);
126
+ }
127
+ /** Drops what was scanned from `file`, so the next scan reads it again. */
128
+ invalidate(file) {
129
+ for (const entry of this.entriesOf(file)) this.registry.delete(entry.className);
130
+ this.lazyScans.clear();
131
+ }
132
+ addEntry(entry) {
133
+ if (!this.registry.has(entry.className)) this.registry.set(entry.className, entry);
134
+ }
135
+ scanOnDemand(file, resolveImport) {
136
+ let scan = this.lazyScans.get(file);
137
+ if (!scan) {
138
+ scan = this.scanWithReExports(file, resolveImport);
139
+ this.lazyScans.set(file, scan);
140
+ }
141
+ return scan;
142
+ }
143
+ /**
144
+ * Scan a file and everything it re-exports, resolving specifiers through
145
+ * Vite so path aliases work. Tuple barrels and NgModules can list classes
146
+ * their file imports without re-exporting, so their imports are followed
147
+ * too. Returns every file scanned.
148
+ */
149
+ async scanWithReExports(file, resolveImport) {
150
+ const visited = /* @__PURE__ */ new Set();
151
+ const visit = async (current) => {
152
+ if (visited.has(current)) return;
153
+ visited.add(current);
154
+ let code;
155
+ let program;
156
+ try {
157
+ code = await this.readScanSource(current);
158
+ program = parseOxc(current, code).program;
159
+ } catch {
160
+ return;
161
+ }
162
+ const entries = scanFile(code, current, program);
163
+ for (const entry of entries) this.addEntry(entry);
164
+ this.ensureDtsRegistryForSource(code, current, program);
165
+ const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code, current, program) : collectReExports(code, current, program);
166
+ for (const spec of specifiers) {
167
+ const dep = await resolveImport(spec, current);
168
+ if (dep) await visit(dep);
169
+ }
170
+ };
171
+ await visit(file);
172
+ return visited;
173
+ }
174
+ };
175
+ //#endregion
176
+ export { ComponentScanner };
177
+
178
+ //# sourceMappingURL=component-scanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-scanner.js","names":[],"sources":["../../../src/lib/component-scanner.ts"],"sourcesContent":["import { promises as fsPromises } from 'node:fs';\nimport type { parseSync } from 'oxc-parser';\nimport { normalizePath } from 'vite';\n\nimport type { ComponentRegistryEntries } from './analog-plugin-interop.js';\nimport {\n collectAllImports,\n collectImportedPackages,\n collectReExports,\n scanFile,\n scanPackageDts,\n type ComponentRegistry,\n type RegistryEntry,\n} from './compiler/index.js';\nimport { parseOxc } from './compiler/utils.js';\nimport type {\n FastCompileResolve,\n FastCompileSourceFormat,\n} from './fast-compile-api.js';\nimport { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX } from './utils/plugin-config.js';\n\ntype OxcProgram = ReturnType<typeof parseSync>['program'];\n\n/** Resolves an import to a source file to scan, or `null` to skip it. */\nexport type ResolveImport = (\n spec: string,\n importer: string,\n) => Promise<string | null>;\n\n/**\n * Angular classes scanned from source files and package `.d.ts` declarations,\n * so source formats can look up the selectors of the components they import\n * before any compiler sees their modules. Shared by the fast compile and NGP\n * plugins.\n */\nexport class ComponentScanner {\n readonly registry: ComponentRegistry = new Map();\n readonly scannedDtsPackages: Set<string> = new Set();\n /** Files scanned on demand, mapped to the barrel chain each pulled in. */\n readonly lazyScans: Map<string, Promise<Set<string>>> = new Map();\n /** Modules compiled against each scanned file. */\n readonly importersByFile: Map<string, Set<string>> = new Map();\n private readonly sourceFormats: FastCompileSourceFormat[] = [];\n private root = '';\n\n /** Where package declarations are looked up from. */\n get projectRoot(): string {\n return this.root;\n }\n\n reset(projectRoot: string): void {\n this.root = projectRoot;\n this.registry.clear();\n this.scannedDtsPackages.clear();\n this.lazyScans.clear();\n this.importersByFile.clear();\n }\n\n registerSourceFormat(format: FastCompileSourceFormat): void {\n if (!this.sourceFormats.includes(format)) {\n this.sourceFormats.push(format);\n }\n }\n\n sourceFormatOf(file: string): FastCompileSourceFormat | undefined {\n const path = file.split('?')[0];\n return this.sourceFormats.find((format) => format.test(path));\n }\n\n /** Whether `file` is TypeScript or a module of a registered source format. */\n isCompiledSource(file: string): boolean {\n return TS_EXT_REGEX.test(file) || this.sourceFormatOf(file) !== undefined;\n }\n\n /**\n * Reads a source file for scanning. Modules of a registered source format\n * are converted to TypeScript first so the scanner sees their classes.\n */\n async readScanSource(file: string): Promise<string> {\n const code = await fsPromises.readFile(file, 'utf-8');\n const format = this.sourceFormatOf(file);\n return format ? format.toScanSource(code, file) : code;\n }\n\n /**\n * Adapts a Vite-style resolver to the scanner's: only source files this\n * scanner reads, outside `node_modules` (package declarations come from the\n * `.d.ts` scanner instead).\n */\n toResolveImport(resolve: FastCompileResolve): ResolveImport {\n return async (spec, importer) => {\n const resolved = await resolve(spec, importer);\n if (!resolved || resolved.external) return null;\n const file = normalizePath(resolved.id.split('?')[0]);\n return this.isCompiledSource(file) &&\n !EXCLUDED_TS_EXT_REGEX.test(file) &&\n !file.includes('/node_modules/')\n ? file\n : null;\n };\n }\n\n /** Scans the `.d.ts` declarations of `packages` into the registry, once each. */\n ensureDtsRegistryForPackages(packages: Iterable<string>): void {\n for (const pkg of packages) {\n if (this.scannedDtsPackages.has(pkg)) continue;\n this.scannedDtsPackages.add(pkg);\n try {\n const dtsEntries = scanPackageDts(\n pkg,\n // Before a tsconfig resolves, look up packages from the working directory.\n this.root || process.cwd(),\n this.scannedDtsPackages,\n );\n for (const entry of dtsEntries) {\n this.addEntry(entry);\n }\n } catch {\n // Package may not have .d.ts files or may not be Angular\n }\n }\n }\n\n ensureDtsRegistryForSource(\n code: string,\n id: string,\n program?: OxcProgram,\n ): void {\n this.ensureDtsRegistryForPackages(\n collectImportedPackages(code, id, program),\n );\n }\n\n /**\n * Scans the modules behind `specifiers`, imported by `importer`: packages\n * from their `.d.ts` declarations, everything else from source.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void> {\n this.ensureDtsRegistryForPackages(\n specifiers\n .filter((spec) => !spec.startsWith('.') && !spec.startsWith('/'))\n .map((spec) => {\n const parts = spec.split('/');\n return spec.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0];\n }),\n );\n return this.resolveImportSpecifiers(\n specifiers,\n importer,\n this.toResolveImport(resolve),\n );\n }\n\n /**\n * Scans the files behind `specs`, imported by `id`, into the registry and\n * records `id` as their importer.\n */\n async resolveImportSpecifiers(\n specs: string[],\n id: string,\n resolveImport: ResolveImport,\n ): Promise<void> {\n await Promise.all(\n specs.map(async (spec) => {\n const file = await resolveImport(spec, id);\n if (!file) return;\n for (const scanned of await this.scanOnDemand(file, resolveImport)) {\n let importers = this.importersByFile.get(scanned);\n if (!importers) {\n importers = new Set();\n this.importersByFile.set(scanned, importers);\n }\n importers.add(id);\n }\n }),\n );\n }\n\n /**\n * The element selector of a component or directive class. `external` are\n * registries contributed through `analog.setup()`.\n */\n lookupSelector(\n className: string,\n external: readonly ComponentRegistryEntries[] = [],\n ): string | null {\n const entry =\n this.registry.get(className) ??\n external.map((r) => r.get(className)).find((e) => e !== undefined);\n if (!entry || (entry.kind !== 'component' && entry.kind !== 'directive')) {\n return null;\n }\n return entry.selector;\n }\n\n /** The files scanned for `importer`. */\n dependenciesOf(importer: string): string[] {\n return [...this.importersByFile]\n .filter(([, importers]) => importers.has(importer))\n .map(([file]) => file);\n }\n\n entriesOf(file: string): RegistryEntry[] {\n return [...this.registry.values()].filter((e) => e.fileName === file);\n }\n\n /** Drops what was scanned from `file`, so the next scan reads it again. */\n invalidate(file: string): void {\n for (const entry of this.entriesOf(file)) {\n this.registry.delete(entry.className);\n }\n this.lazyScans.clear();\n }\n\n private addEntry(entry: RegistryEntry): void {\n if (!this.registry.has(entry.className)) {\n this.registry.set(entry.className, entry);\n }\n }\n\n private scanOnDemand(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n let scan = this.lazyScans.get(file);\n if (!scan) {\n scan = this.scanWithReExports(file, resolveImport);\n this.lazyScans.set(file, scan);\n }\n return scan;\n }\n\n /**\n * Scan a file and everything it re-exports, resolving specifiers through\n * Vite so path aliases work. Tuple barrels and NgModules can list classes\n * their file imports without re-exporting, so their imports are followed\n * too. Returns every file scanned.\n */\n private async scanWithReExports(\n file: string,\n resolveImport: ResolveImport,\n ): Promise<Set<string>> {\n const visited = new Set<string>();\n const visit = async (current: string): Promise<void> => {\n if (visited.has(current)) return;\n visited.add(current);\n let code: string;\n let program: OxcProgram;\n try {\n code = await this.readScanSource(current);\n program = parseOxc(current, code).program;\n } catch {\n return;\n }\n const entries = scanFile(code, current, program);\n for (const entry of entries) {\n this.addEntry(entry);\n }\n this.ensureDtsRegistryForSource(code, current, program);\n const followsImports = entries.some(\n (e) => e.kind === 'tuple' || e.kind === 'ngmodule',\n );\n const specifiers = followsImports\n ? collectAllImports(code, current, program)\n : collectReExports(code, current, program);\n for (const spec of specifiers) {\n const dep = await resolveImport(spec, current);\n if (dep) await visit(dep);\n }\n };\n await visit(file);\n return visited;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAmCA,IAAa,mBAAb,MAA8B;CAC5B,2BAAuC,IAAI,IAAI;CAC/C,qCAA2C,IAAI,IAAI;;CAEnD,4BAAwD,IAAI,IAAI;;CAEhE,kCAAqD,IAAI,IAAI;CAC7D,gBAA4D,CAAC;CAC7D,OAAe;;CAGf,IAAI,cAAsB;EACxB,OAAO,KAAK;CACd;CAEA,MAAM,aAA2B;EAC/B,KAAK,OAAO;EACZ,KAAK,SAAS,MAAM;EACpB,KAAK,mBAAmB,MAAM;EAC9B,KAAK,UAAU,MAAM;EACrB,KAAK,gBAAgB,MAAM;CAC7B;CAEA,qBAAqB,QAAuC;EAC1D,IAAI,CAAC,KAAK,cAAc,SAAS,MAAM,GACrC,KAAK,cAAc,KAAK,MAAM;CAElC;CAEA,eAAe,MAAmD;EAChE,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC;EAC7B,OAAO,KAAK,cAAc,MAAM,WAAW,OAAO,KAAK,IAAI,CAAC;CAC9D;;CAGA,iBAAiB,MAAuB;EACtC,OAAO,aAAa,KAAK,IAAI,KAAK,KAAK,eAAe,IAAI,MAAM,KAAA;CAClE;;;;;CAMA,MAAM,eAAe,MAA+B;EAClD,MAAM,OAAO,MAAM,SAAW,SAAS,MAAM,OAAO;EACpD,MAAM,SAAS,KAAK,eAAe,IAAI;EACvC,OAAO,SAAS,OAAO,aAAa,MAAM,IAAI,IAAI;CACpD;;;;;;CAOA,gBAAgB,SAA4C;EAC1D,OAAO,OAAO,MAAM,aAAa;GAC/B,MAAM,WAAW,MAAM,QAAQ,MAAM,QAAQ;GAC7C,IAAI,CAAC,YAAY,SAAS,UAAU,OAAO;GAC3C,MAAM,OAAO,cAAc,SAAS,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE;GAC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ACxC,UAAU,SAAS,SAAS,IAAI,CAAC,CAAC;GACpC,QAAQ;IACN;GACF;GACA,MAAM,UAAU,SAAS,MAAM,SAAS,OAAO;GAC/C,KAAK,MAAM,SAAS,SAClB,KAAK,SAAS,KAAK;GAErB,KAAK,2BAA2B,MAAM,SAAS,OAAO;GAItD,MAAM,aAHiB,QAAQ,MAC5B,MAAM,EAAE,SAAS,WAAW,EAAE,SAAS,UAEvB,IACf,kBAAkB,MAAM,SAAS,OAAO,IACxC,iBAAiB,MAAM,SAAS,OAAO;GAC3C,KAAK,MAAM,QAAQ,YAAY;IAC7B,MAAM,MAAM,MAAM,cAAc,MAAM,OAAO;IAC7C,IAAI,KAAK,MAAM,MAAM,GAAG;GAC1B;EACF;EACA,MAAM,MAAM,IAAI;EAChB,OAAO;CACT;AACF"}
@@ -0,0 +1,52 @@
1
+ import { type ModuleNode, type Plugin, type ViteDevServer } from "vite";
2
+ import { type AngularBuildContext, type AngularBuildContextOptions } from "./angular-build-context.js";
3
+ import type { StylePreprocessor, StylesheetDependency } from "./style-preprocessor.js";
4
+ import { AnalogStylesheetRegistry } from "./stylesheet-registry.js";
5
+ import { describeStylesheetContent } from "./utils/compilation-shared.js";
6
+ export interface ComponentStylesheetPipelineDiagnosis {
7
+ file: string;
8
+ sourcePath?: string;
9
+ source?: ReturnType<typeof describeStylesheetContent>;
10
+ registry?: ReturnType<typeof describeStylesheetContent>;
11
+ dependencies: StylesheetDependency[];
12
+ diagnostics: ReturnType<AnalogStylesheetRegistry["getDiagnosticsForSource"]>;
13
+ tags: string[];
14
+ directModuleId?: string;
15
+ directModuleUrl?: string;
16
+ trackedRequestIds: string[];
17
+ wrapperCount: number;
18
+ anomalies: string[];
19
+ hints: string[];
20
+ }
21
+ /**
22
+ * Self-contained Vite plugin that resolves and serves externalized Angular
23
+ * component stylesheets (`?ngcomp=...`) from the shared `AngularBuildContext`
24
+ * stylesheet registry and refreshes served records on source CSS edits.
25
+ */
26
+ export declare function componentStylesPlugin(ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions): Plugin;
27
+ export declare function markModuleSelfAccepting(mod: ModuleNode): ModuleNode;
28
+ /**
29
+ * Returns every live Vite module that can legitimately represent a changed
30
+ * Angular resource file.
31
+ *
32
+ * For normal files, `getModulesByFile()` is enough. For Angular component
33
+ * stylesheets, it is not: the browser often holds virtual hashed requests
34
+ * (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no
35
+ * longer discoverable from the original source path alone. We therefore merge:
36
+ * - watcher event modules
37
+ * - module-graph modules by source file
38
+ * - registry-tracked live request ids resolved back through the module graph
39
+ */
40
+ export declare function getModulesForChangedFile(server: ViteDevServer, file: string, eventModules?: readonly ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
41
+ export declare function isModuleForChangedResource(mod: ModuleNode, changedFile: string, stylesheetRegistry?: AnalogStylesheetRegistry): boolean;
42
+ export declare function diagnoseComponentStylesheetPipeline(changedFile: string, directModule: ModuleNode, stylesheetRegistry: AnalogStylesheetRegistry | undefined, wrapperModules: ModuleNode[], stylePreprocessor?: StylePreprocessor): ComponentStylesheetPipelineDiagnosis;
43
+ export declare function findComponentStylesheetWrapperModules(server: ViteDevServer, changedFile: string, directModule: ModuleNode, fileModules: ModuleNode[], stylesheetRegistry?: AnalogStylesheetRegistry): Promise<ModuleNode[]>;
44
+ export declare function findTemplateOwnerModules(server: ViteDevServer, resourceFile: string): ModuleNode[];
45
+ export declare function handleDirectComponentStyleHmr(options: {
46
+ server: ViteDevServer;
47
+ file: string;
48
+ directModule: ModuleNode;
49
+ fileModules: ModuleNode[];
50
+ stylesheetRegistry?: AnalogStylesheetRegistry;
51
+ stylePreprocessor?: StylePreprocessor;
52
+ }): Promise<ModuleNode[]>;