@analogjs/vite-plugin-angular 3.0.0-beta.47 → 3.0.0-beta.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +2 -1
- package/src/index.js.map +1 -1
- package/src/lib/component-scanner.d.ts +74 -0
- package/src/lib/component-scanner.js +178 -0
- package/src/lib/component-scanner.js.map +1 -0
- package/src/lib/fast-compile-plugin.js +26 -165
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/ngp-compile-api.d.ts +55 -0
- package/src/lib/ngp-compile-api.js +12 -0
- package/src/lib/ngp-compile-api.js.map +1 -0
- package/src/lib/ngp-compile-plugin.js +286 -41
- package/src/lib/ngp-compile-plugin.js.map +1 -1
- package/src/lib/utils/lsp-type-checker.d.ts +22 -2
- package/src/lib/utils/lsp-type-checker.js +39 -10
- package/src/lib/utils/lsp-type-checker.js.map +1 -1
- package/src/lib/utils/ngp-host-fs.d.ts +32 -0
- package/src/lib/utils/ngp-host-fs.js +104 -0
- package/src/lib/utils/ngp-host-fs.js.map +1 -0
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { angular } from "./lib/angular-vite-plugin.js";
|
|
|
4
4
|
export type { PluginOptions } from "./lib/angular-vite-plugin.js";
|
|
5
5
|
export type { AnalogIntegrationPlugin, AnalogPluginContext, AnalogPluginHooks, ComponentRegistryEntries, StylesheetRegistryConfigurator, StylesheetRegistryContext, TransformFilter } from "./lib/analog-plugin-interop.js";
|
|
6
6
|
export { findFastCompileApi, type FastCompileApi, type FastCompileOptions, type FastCompileResolve, type FastCompileSourceFormat, type SourceMapInput } from "./lib/fast-compile-api.js";
|
|
7
|
+
export { findNgpCompileApi, type NgpCompileApi, type NgpLowerContext, type NgpLoweredModule, type NgpSourceFormat } from "./lib/ngp-compile-api.js";
|
|
7
8
|
export type { RegistryEntry as ComponentRegistryEntry, RegistryInput as ComponentRegistryInput } from "./lib/compiler/registry.js";
|
|
8
9
|
export type { StylePreprocessor, StylesheetDependency, StylesheetDiagnostic, StylesheetRegistryReader, StylesheetTransformContext, StylesheetTransformResult } from "./lib/style-preprocessor.js";
|
|
9
10
|
export default angular;
|
package/src/index.js
CHANGED
|
@@ -2,9 +2,10 @@ import { angularCompilationPlugin } from "./lib/compilation-api/compilation-api-
|
|
|
2
2
|
import "./lib/compilation-api/index.js";
|
|
3
3
|
import { angular } from "./lib/angular-vite-plugin.js";
|
|
4
4
|
import { findFastCompileApi } from "./lib/fast-compile-api.js";
|
|
5
|
+
import { findNgpCompileApi } from "./lib/ngp-compile-api.js";
|
|
5
6
|
//#region packages/vite-plugin-angular/src/index.ts
|
|
6
7
|
var src_default = angular;
|
|
7
8
|
//#endregion
|
|
8
|
-
export { angular, angularCompilationPlugin, src_default as default, findFastCompileApi };
|
|
9
|
+
export { angular, angularCompilationPlugin, src_default as default, findFastCompileApi, findNgpCompileApi };
|
|
9
10
|
|
|
10
11
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n angularCompilationPlugin,\n type AngularCompilationPluginOptions,\n} from './lib/compilation-api/index.js';\nimport { angular } from './lib/angular-vite-plugin.js';\nexport { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\nexport type {\n AnalogIntegrationPlugin,\n AnalogPluginContext,\n AnalogPluginHooks,\n ComponentRegistryEntries,\n StylesheetRegistryConfigurator,\n StylesheetRegistryContext,\n TransformFilter,\n} from './lib/analog-plugin-interop.js';\nexport {\n findFastCompileApi,\n type FastCompileApi,\n type FastCompileOptions,\n type FastCompileResolve,\n type FastCompileSourceFormat,\n type SourceMapInput,\n} from './lib/fast-compile-api.js';\nexport type {\n RegistryEntry as ComponentRegistryEntry,\n RegistryInput as ComponentRegistryInput,\n} from './lib/compiler/registry.js';\nexport type {\n StylePreprocessor,\n StylesheetDependency,\n StylesheetDiagnostic,\n StylesheetRegistryReader,\n StylesheetTransformContext,\n StylesheetTransformResult,\n} from './lib/style-preprocessor.js';\n\nexport default angular;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["export {\n angularCompilationPlugin,\n type AngularCompilationPluginOptions,\n} from './lib/compilation-api/index.js';\nimport { angular } from './lib/angular-vite-plugin.js';\nexport { angular } from './lib/angular-vite-plugin.js';\nexport type { PluginOptions } from './lib/angular-vite-plugin.js';\nexport type {\n AnalogIntegrationPlugin,\n AnalogPluginContext,\n AnalogPluginHooks,\n ComponentRegistryEntries,\n StylesheetRegistryConfigurator,\n StylesheetRegistryContext,\n TransformFilter,\n} from './lib/analog-plugin-interop.js';\nexport {\n findFastCompileApi,\n type FastCompileApi,\n type FastCompileOptions,\n type FastCompileResolve,\n type FastCompileSourceFormat,\n type SourceMapInput,\n} from './lib/fast-compile-api.js';\nexport {\n findNgpCompileApi,\n type NgpCompileApi,\n type NgpLowerContext,\n type NgpLoweredModule,\n type NgpSourceFormat,\n} from './lib/ngp-compile-api.js';\nexport type {\n RegistryEntry as ComponentRegistryEntry,\n RegistryInput as ComponentRegistryInput,\n} from './lib/compiler/registry.js';\nexport type {\n StylePreprocessor,\n StylesheetDependency,\n StylesheetDiagnostic,\n StylesheetRegistryReader,\n StylesheetTransformContext,\n StylesheetTransformResult,\n} from './lib/style-preprocessor.js';\n\nexport default angular;\n"],"mappings":";;;;;;AA4CA,IAAA,cAAe"}
|
|
@@ -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,M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"}
|
|
@@ -2,7 +2,7 @@ import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
|
|
|
2
2
|
import { preprocessStylesheet } from "./stylesheet-registry.js";
|
|
3
3
|
import { isIgnoredHmrFile } from "./utils/compilation-shared.js";
|
|
4
4
|
import { isRolldown } from "./utils/rolldown.js";
|
|
5
|
-
import {
|
|
5
|
+
import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
|
|
6
6
|
import { reportStylesheetError } from "./utils/stylesheet-warning.js";
|
|
7
7
|
import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
|
|
8
8
|
import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
|
|
@@ -13,11 +13,12 @@ import { parseOxc } from "./compiler/utils.js";
|
|
|
13
13
|
import { debugRegistry } from "./compiler/debug.js";
|
|
14
14
|
import { compile } from "./compiler/compile.js";
|
|
15
15
|
import { declaresNonStandaloneComponent, scanFile } from "./compiler/registry.js";
|
|
16
|
-
import { collectAllImports,
|
|
16
|
+
import { collectAllImports, collectRelativeReExports } from "./compiler/dts-reader.js";
|
|
17
17
|
import { jitTransform } from "./compiler/jit-transform.js";
|
|
18
18
|
import { generateHmrCode } from "./compiler/hmr.js";
|
|
19
19
|
import { extractInlineStyles, inlineResourceUrls } from "./compiler/resource-inliner.js";
|
|
20
20
|
import "./compiler/index.js";
|
|
21
|
+
import { ComponentScanner } from "./component-scanner.js";
|
|
21
22
|
import { promises } from "node:fs";
|
|
22
23
|
import { dirname, resolve } from "node:path";
|
|
23
24
|
import * as vite from "vite";
|
|
@@ -42,34 +43,8 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
42
43
|
compilationBackend: "fast"
|
|
43
44
|
});
|
|
44
45
|
const pluginOptions = sharedCtx ? sharedCtx.options : optionsOrCtx;
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
const sourceFormatOf = (file) => {
|
|
48
|
-
const path = file.split("?")[0];
|
|
49
|
-
return sourceFormats.find((format) => format.test(path));
|
|
50
|
-
};
|
|
51
|
-
/** Whether `file` is a module compiled through this plugin. */
|
|
52
|
-
const isCompiledSource = (file) => TS_EXT_REGEX.test(file) || sourceFormatOf(file) !== void 0;
|
|
53
|
-
/**
|
|
54
|
-
* Reads a source file for registry scanning. Modules of a registered source
|
|
55
|
-
* format are converted to TypeScript first so the scanner sees their classes.
|
|
56
|
-
*/
|
|
57
|
-
const readScanSource = async (file) => {
|
|
58
|
-
const code = await promises.readFile(file, "utf-8");
|
|
59
|
-
const format = sourceFormatOf(file);
|
|
60
|
-
return format ? format.toScanSource(code, file) : code;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Adapts a Vite-style resolver to the scanner's: only source files this
|
|
64
|
-
* plugin compiles, outside `node_modules` (package declarations come from
|
|
65
|
-
* the lazy `.d.ts` scanner instead).
|
|
66
|
-
*/
|
|
67
|
-
const toResolveImport = (resolve) => async (spec, importer) => {
|
|
68
|
-
const resolved = await resolve(spec, importer);
|
|
69
|
-
if (!resolved || resolved.external) return null;
|
|
70
|
-
const file = normalizePath(resolved.id.split("?")[0]);
|
|
71
|
-
return isCompiledSource(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
|
|
72
|
-
};
|
|
46
|
+
const scanner = new ComponentScanner();
|
|
47
|
+
const registry = scanner.registry;
|
|
73
48
|
const tsconfigResolver = sharedCtx?.tsconfigResolver ?? new TsconfigResolver({
|
|
74
49
|
workspaceRoot: pluginOptions.workspaceRoot,
|
|
75
50
|
include: pluginOptions.include ?? [],
|
|
@@ -82,15 +57,10 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
82
57
|
let stylePreprocessor;
|
|
83
58
|
let tsConfigResolutionContext = null;
|
|
84
59
|
let watchMode = false;
|
|
85
|
-
const registry = /* @__PURE__ */ new Map();
|
|
86
60
|
const resourceToSource = /* @__PURE__ */ new Map();
|
|
87
|
-
const scannedDtsPackages = /* @__PURE__ */ new Set();
|
|
88
61
|
const emittedMaps = /* @__PURE__ */ new Map();
|
|
89
|
-
let projectRoot = "";
|
|
90
62
|
let useDefineForClassFields = true;
|
|
91
63
|
let tsConfig;
|
|
92
|
-
const lazyScans = /* @__PURE__ */ new Map();
|
|
93
|
-
const importersByFile = /* @__PURE__ */ new Map();
|
|
94
64
|
let projectScan;
|
|
95
65
|
/**
|
|
96
66
|
* Scan a file into the registry, then recursively walk its relative
|
|
@@ -113,7 +83,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
113
83
|
visited.add(file);
|
|
114
84
|
let code;
|
|
115
85
|
try {
|
|
116
|
-
code = fileContents?.get(file) ?? await readScanSource(file);
|
|
86
|
+
code = fileContents?.get(file) ?? await scanner.readScanSource(file);
|
|
117
87
|
fileContents?.set(file, code);
|
|
118
88
|
} catch (e) {
|
|
119
89
|
if (debugRegistry.enabled) debugRegistry("scanBarrelExports: failed to read %s: %s", file, e?.message);
|
|
@@ -148,13 +118,10 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
148
118
|
async function initFastCompile() {
|
|
149
119
|
emittedMaps.clear();
|
|
150
120
|
if (pluginOptions.jit) return;
|
|
151
|
-
registry.clear();
|
|
152
|
-
scannedDtsPackages.clear();
|
|
153
|
-
lazyScans.clear();
|
|
154
|
-
importersByFile.clear();
|
|
155
121
|
projectScan = void 0;
|
|
156
122
|
const resolvedTsConfigPath = resolveTsConfigPath();
|
|
157
|
-
projectRoot = dirname(resolvedTsConfigPath);
|
|
123
|
+
const projectRoot = dirname(resolvedTsConfigPath);
|
|
124
|
+
scanner.reset(projectRoot);
|
|
158
125
|
tsConfig = compilerCli.readConfiguration(resolvedTsConfigPath);
|
|
159
126
|
useDefineForClassFields = tsConfig.options?.useDefineForClassFields ?? true;
|
|
160
127
|
}
|
|
@@ -164,6 +131,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
164
131
|
const extraIncludes = tsconfigResolver.ensureIncludeCache();
|
|
165
132
|
const candidates = /* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes]);
|
|
166
133
|
const tsPaths = config.options?.paths;
|
|
134
|
+
const projectRoot = scanner.projectRoot;
|
|
167
135
|
const baseUrl = getPathsBasePath(config.options, projectRoot);
|
|
168
136
|
const fileContents = /* @__PURE__ */ new Map();
|
|
169
137
|
const scanResults = /* @__PURE__ */ new Map();
|
|
@@ -173,7 +141,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
173
141
|
}
|
|
174
142
|
const results = await Promise.all(Array.from(candidates).map(async (file) => {
|
|
175
143
|
try {
|
|
176
|
-
const code = await readScanSource(file);
|
|
144
|
+
const code = await scanner.readScanSource(file);
|
|
177
145
|
fileContents.set(file, code);
|
|
178
146
|
const entries = scanFile(code, file);
|
|
179
147
|
scanResults.set(file, entries);
|
|
@@ -226,7 +194,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
226
194
|
importWalkVisited.add(file);
|
|
227
195
|
let code;
|
|
228
196
|
try {
|
|
229
|
-
code = fileContents.get(file) ?? await readScanSource(file);
|
|
197
|
+
code = fileContents.get(file) ?? await scanner.readScanSource(file);
|
|
230
198
|
fileContents.set(file, code);
|
|
231
199
|
} catch {
|
|
232
200
|
return;
|
|
@@ -243,13 +211,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
243
211
|
scanResults.set(file, entries);
|
|
244
212
|
}
|
|
245
213
|
for (const entry of entries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
246
|
-
|
|
247
|
-
if (scannedDtsPackages.has(pkg)) continue;
|
|
248
|
-
scannedDtsPackages.add(pkg);
|
|
249
|
-
try {
|
|
250
|
-
for (const entry of scanPackageDts(pkg, projectRoot, scannedDtsPackages)) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
251
|
-
} catch {}
|
|
252
|
-
}
|
|
214
|
+
scanner.ensureDtsRegistryForSource(code, file, program);
|
|
253
215
|
const dir = dirname(file);
|
|
254
216
|
const targets = await Promise.all(collectAllImports(code, file, program).map((spec) => {
|
|
255
217
|
if (spec.startsWith(".")) return resolveToSource(resolve(dir, spec.replace(/\.(?:js|mjs)$/u, "")));
|
|
@@ -275,98 +237,6 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
275
237
|
}
|
|
276
238
|
debugRegistry("initFastCompile done: %d entries from %d candidate files", registry.size, candidates.size);
|
|
277
239
|
}
|
|
278
|
-
function ensureDtsRegistryForSource(code, id, program) {
|
|
279
|
-
ensureDtsRegistryForPackages(collectImportedPackages(code, id, program));
|
|
280
|
-
}
|
|
281
|
-
/** Scan the `.d.ts` declarations of `packages` into the registry, once each. */
|
|
282
|
-
function ensureDtsRegistryForPackages(packages) {
|
|
283
|
-
for (const pkg of packages) {
|
|
284
|
-
if (scannedDtsPackages.has(pkg)) continue;
|
|
285
|
-
scannedDtsPackages.add(pkg);
|
|
286
|
-
try {
|
|
287
|
-
const dtsEntries = scanPackageDts(pkg, projectRoot || process.cwd(), scannedDtsPackages);
|
|
288
|
-
for (const entry of dtsEntries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
289
|
-
} catch {}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* Scan the source files `id` imports into the registry on demand and record
|
|
294
|
-
* `id` as their importer, so a metadata change in any of them recompiles it.
|
|
295
|
-
*/
|
|
296
|
-
async function resolveImportedDeclarations(code, id, program, resolveImport) {
|
|
297
|
-
await resolveImportSpecifiers(collectAllImports(code, id, program), id, resolveImport);
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Scan the files behind `specs`, imported by `id`, into the registry and
|
|
301
|
-
* record `id` as their importer.
|
|
302
|
-
*/
|
|
303
|
-
async function resolveImportSpecifiers(specs, id, resolveImport) {
|
|
304
|
-
await Promise.all(specs.map(async (spec) => {
|
|
305
|
-
const file = await resolveImport(spec, id);
|
|
306
|
-
if (!file) return;
|
|
307
|
-
for (const scanned of await scanOnDemand(file, resolveImport)) {
|
|
308
|
-
let importers = importersByFile.get(scanned);
|
|
309
|
-
if (!importers) {
|
|
310
|
-
importers = /* @__PURE__ */ new Set();
|
|
311
|
-
importersByFile.set(scanned, importers);
|
|
312
|
-
}
|
|
313
|
-
importers.add(id);
|
|
314
|
-
}
|
|
315
|
-
}));
|
|
316
|
-
}
|
|
317
|
-
function scanOnDemand(file, resolveImport) {
|
|
318
|
-
let scan = lazyScans.get(file);
|
|
319
|
-
if (!scan) {
|
|
320
|
-
scan = scanWithReExports(file, resolveImport);
|
|
321
|
-
lazyScans.set(file, scan);
|
|
322
|
-
}
|
|
323
|
-
return scan;
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Scan a file and everything it re-exports, resolving specifiers through
|
|
327
|
-
* Vite so path aliases work. Tuple barrels and NgModules can list classes
|
|
328
|
-
* their file imports without re-exporting, so their imports are followed
|
|
329
|
-
* too. Returns every file scanned.
|
|
330
|
-
*/
|
|
331
|
-
async function scanWithReExports(file, resolveImport) {
|
|
332
|
-
const visited = /* @__PURE__ */ new Set();
|
|
333
|
-
const visit = async (current) => {
|
|
334
|
-
if (visited.has(current)) return;
|
|
335
|
-
visited.add(current);
|
|
336
|
-
let code;
|
|
337
|
-
let program;
|
|
338
|
-
try {
|
|
339
|
-
code = await readScanSource(current);
|
|
340
|
-
program = parseOxc(current, code).program;
|
|
341
|
-
} catch {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
const entries = scanFile(code, current, program);
|
|
345
|
-
for (const entry of entries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
346
|
-
ensureDtsRegistryForSource(code, current, program);
|
|
347
|
-
const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code, current, program) : collectReExports(code, current, program);
|
|
348
|
-
for (const spec of specifiers) {
|
|
349
|
-
const dep = await resolveImport(spec, current);
|
|
350
|
-
if (dep) await visit(dep);
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
await visit(file);
|
|
354
|
-
return visited;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* The element selector of a component or directive class, for source formats
|
|
358
|
-
* that reference components by class. Includes registries contributed
|
|
359
|
-
* through `analog.setup()`.
|
|
360
|
-
*/
|
|
361
|
-
function lookupSelector(className) {
|
|
362
|
-
const registries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
|
|
363
|
-
const entry = registry.get(className) ?? registries.map((r) => r.get(className)).find((e) => e !== void 0);
|
|
364
|
-
if (!entry || entry.kind !== "component" && entry.kind !== "directive") return null;
|
|
365
|
-
return entry.selector;
|
|
366
|
-
}
|
|
367
|
-
function registryEntriesOf(file) {
|
|
368
|
-
return [...registry.values()].filter((e) => e.fileName === file);
|
|
369
|
-
}
|
|
370
240
|
async function handleFastCompileTransform(code, id, resolveImport) {
|
|
371
241
|
if (!ANGULAR_DECORATOR_CALL_RE.test(code)) {
|
|
372
242
|
const stripped = vite.transformWithOxc ? await vite.transformWithOxc(code, id, {
|
|
@@ -416,7 +286,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
416
286
|
const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
|
|
417
287
|
const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
|
|
418
288
|
for (let i = 0; i < styleStrings.length; i++) {
|
|
419
|
-
const stylePath = stylePaths.get(i) ?? (sourceFormatOf(id) ? id + ".ts" : id).replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
|
|
289
|
+
const stylePath = stylePaths.get(i) ?? (scanner.sourceFormatOf(id) ? id + ".ts" : id).replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
|
|
420
290
|
try {
|
|
421
291
|
const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
|
|
422
292
|
filename: stylePath,
|
|
@@ -432,9 +302,9 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
432
302
|
}
|
|
433
303
|
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
434
304
|
}
|
|
435
|
-
ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
305
|
+
scanner.ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
436
306
|
for (const entry of scanFile(code, id, oxcProgram)) registry.set(entry.className, entry);
|
|
437
|
-
await
|
|
307
|
+
await scanner.resolveImportSpecifiers(collectAllImports(code, id, oxcProgram), id, resolveImport);
|
|
438
308
|
if (declaresNonStandaloneComponent(oxcProgram)) {
|
|
439
309
|
projectScan ??= scanProject();
|
|
440
310
|
await projectScan;
|
|
@@ -466,7 +336,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
466
336
|
}, result.map);
|
|
467
337
|
let outputCode = stripped.code;
|
|
468
338
|
if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
|
|
469
|
-
const fileDeclarations =
|
|
339
|
+
const fileDeclarations = scanner.entriesOf(id);
|
|
470
340
|
if (fileDeclarations.length > 0) {
|
|
471
341
|
const localDepClassNames = fileDeclarations.map((e) => e.className);
|
|
472
342
|
outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
|
|
@@ -492,19 +362,11 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
492
362
|
getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
|
|
493
363
|
hasEmitted: (id) => emittedMaps.has(normalizePath(id)),
|
|
494
364
|
fastCompile: {
|
|
495
|
-
registerSourceFormat(format)
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
scanImports(specifiers, importer, resolve) {
|
|
499
|
-
ensureDtsRegistryForPackages(specifiers.filter((spec) => !spec.startsWith(".") && !spec.startsWith("/")).map((spec) => {
|
|
500
|
-
const parts = spec.split("/");
|
|
501
|
-
return spec.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
502
|
-
}));
|
|
503
|
-
return resolveImportSpecifiers(specifiers, importer, toResolveImport(resolve));
|
|
504
|
-
},
|
|
505
|
-
resolveSelector: lookupSelector,
|
|
365
|
+
registerSourceFormat: (format) => scanner.registerSourceFormat(format),
|
|
366
|
+
scanImports: (specifiers, importer, resolve) => scanner.scanImports(specifiers, importer, resolve),
|
|
367
|
+
resolveSelector: (className) => scanner.lookupSelector(className, sharedCtx ? sharedCtx.componentRegistries : componentRegistries),
|
|
506
368
|
async compile(code, id, { resolve, mapToSource }) {
|
|
507
|
-
const transformed = await handleFastCompileTransform(code, id, toResolveImport(resolve));
|
|
369
|
+
const transformed = await handleFastCompileTransform(code, id, scanner.toResolveImport(resolve));
|
|
508
370
|
if (!transformed) return;
|
|
509
371
|
const map = transformed.map && mapToSource ? mapToSource(transformed.map) : transformed.map ?? null;
|
|
510
372
|
if (map) emittedMaps.set(normalizePath(id), typeof map === "string" ? map : JSON.stringify(map));
|
|
@@ -582,14 +444,13 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
582
444
|
const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
|
|
583
445
|
if (parentModule) return [parentModule];
|
|
584
446
|
}
|
|
585
|
-
if (isCompiledSource(ctx.file)) {
|
|
447
|
+
if (scanner.isCompiledSource(ctx.file)) {
|
|
586
448
|
const [fileId] = ctx.file.split("?");
|
|
587
|
-
const oldEntries =
|
|
588
|
-
|
|
449
|
+
const oldEntries = scanner.entriesOf(fileId);
|
|
450
|
+
scanner.invalidate(fileId);
|
|
589
451
|
await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
const importerModules = [...importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
|
|
452
|
+
if (JSON.stringify(oldEntries) !== JSON.stringify(scanner.entriesOf(fileId))) {
|
|
453
|
+
const importerModules = [...scanner.importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
|
|
593
454
|
return [...ctx.modules, ...importerModules];
|
|
594
455
|
}
|
|
595
456
|
}
|
|
@@ -618,7 +479,7 @@ function fastCompilePlugin(optionsOrCtx) {
|
|
|
618
479
|
const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
|
|
619
480
|
if (activeTransformFilter && !activeTransformFilter(code, id)) return;
|
|
620
481
|
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
621
|
-
const resolveImport = toResolveImport((spec, importer) => this.resolve(spec, importer, { skipSelf: true }));
|
|
482
|
+
const resolveImport = scanner.toResolveImport((spec, importer) => this.resolve(spec, importer, { skipSelf: true }));
|
|
622
483
|
const transformed = await handleFastCompileTransform(code, id, resolveImport);
|
|
623
484
|
if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
|
|
624
485
|
return transformed;
|