@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.
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +2 -1
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
- package/ngp/LICENSE +21 -0
- package/ngp/api.mjs +46806 -0
- package/ngp/build.json +4 -0
- package/ngp/ng_analyze.cjs +601 -0
- package/ngp/ng_analyze_bg.wasm +0 -0
- package/package.json +4 -1
- package/src/index.d.ts +2 -0
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.js +1 -1
- package/src/lib/angular-build-context.d.ts +215 -0
- package/src/lib/angular-build-context.js +361 -0
- package/src/lib/angular-build-context.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
- package/src/lib/angular-build-optimizer-plugin.js +24 -9
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +5 -3
- package/src/lib/angular-jit-plugin.js +14 -6
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +6 -109
- package/src/lib/angular-vite-plugin.js +8 -1249
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +3 -2
- package/src/lib/angular-vitest-plugin.js +6 -3
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/companion-plugins.d.ts +7 -0
- package/src/lib/companion-plugins.js +38 -0
- package/src/lib/companion-plugins.js.map +1 -0
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
- package/src/lib/compilation-api/compilation-api-plugin.js +154 -282
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compiler/compile.d.ts +1 -1
- package/src/lib/compiler/compile.js +190 -145
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +12 -14
- package/src/lib/compiler/defer.js.map +1 -1
- package/src/lib/compiler/dts-reader.d.ts +6 -1
- package/src/lib/compiler/dts-reader.js +19 -10
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/hmr.d.ts +4 -0
- package/src/lib/compiler/hmr.js +7 -2
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +4 -4
- package/src/lib/compiler/jit-metadata.d.ts +3 -1
- package/src/lib/compiler/jit-metadata.js +10 -8
- package/src/lib/compiler/jit-metadata.js.map +1 -1
- package/src/lib/compiler/jit-transform.js +2 -2
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.d.ts +0 -3
- package/src/lib/compiler/js-emitter.js +3 -21
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/registry.d.ts +7 -1
- package/src/lib/compiler/registry.js +23 -3
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.d.ts +8 -9
- package/src/lib/compiler/resource-inliner.js +10 -18
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +9 -1
- package/src/lib/compiler/style-ast.js +26 -5
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.d.ts +4 -3
- package/src/lib/compiler/type-elision.js +10 -11
- package/src/lib/compiler/type-elision.js.map +1 -1
- package/src/lib/compiler/utils.d.ts +9 -7
- package/src/lib/compiler/utils.js +49 -9
- package/src/lib/compiler/utils.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/component-styles-plugin.d.ts +52 -0
- package/src/lib/component-styles-plugin.js +353 -0
- package/src/lib/component-styles-plugin.js.map +1 -0
- package/src/lib/compose-angular-plugins.d.ts +12 -0
- package/src/lib/compose-angular-plugins.js +31 -0
- package/src/lib/compose-angular-plugins.js.map +1 -0
- package/src/lib/dev-server-mode-plugin.d.ts +7 -0
- package/src/lib/dev-server-mode-plugin.js +23 -0
- package/src/lib/dev-server-mode-plugin.js.map +1 -0
- package/src/lib/fast-compile-api.d.ts +62 -0
- package/src/lib/fast-compile-api.js +12 -0
- package/src/lib/fast-compile-api.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +6 -1
- package/src/lib/fast-compile-plugin.js +167 -107
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.d.ts +3 -0
- package/src/lib/host.js +4 -2
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +6 -3
- package/src/lib/live-reload-plugin.js +13 -6
- package/src/lib/live-reload-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.d.ts +4 -0
- package/src/lib/ngp-compile-plugin.js +662 -0
- package/src/lib/ngp-compile-plugin.js.map +1 -0
- package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
- package/src/lib/ngtsc-compile-plugin.js +778 -0
- package/src/lib/ngtsc-compile-plugin.js.map +1 -0
- package/src/lib/nx-folder-plugin.d.ts +6 -5
- package/src/lib/nx-folder-plugin.js +12 -7
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
- package/src/lib/plugins/file-replacements.plugin.js +1 -0
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +5 -1
- package/src/lib/router-plugin.js +13 -4
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/utils/compilation-shared.js +1 -1
- package/src/lib/utils/devkit.js +1 -1
- package/src/lib/utils/hmr-component-updates.d.ts +7 -0
- package/src/lib/utils/hmr-component-updates.js +87 -0
- package/src/lib/utils/hmr-component-updates.js.map +1 -0
- package/src/lib/utils/lsp-type-checker.d.ts +75 -0
- package/src/lib/utils/lsp-type-checker.js +531 -0
- package/src/lib/utils/lsp-type-checker.js.map +1 -0
- 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/src/lib/utils/plugin-config.d.ts +15 -8
- package/src/lib/utils/plugin-config.js +18 -5
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/stylesheet-warning.d.ts +2 -0
- package/src/lib/utils/stylesheet-warning.js +11 -0
- package/src/lib/utils/stylesheet-warning.js.map +1 -0
- package/src/lib/utils/tsconfig-resolver.js +1 -1
- package/src/lib/virtual-modules-plugin.d.ts +11 -3
- package/src/lib/virtual-modules-plugin.js +43 -12
- package/src/lib/virtual-modules-plugin.js.map +1 -1
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
|
|
2
1
|
import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
|
|
2
|
+
import { preprocessStylesheet } from "./stylesheet-registry.js";
|
|
3
|
+
import { isIgnoredHmrFile } from "./utils/compilation-shared.js";
|
|
4
|
+
import { isRolldown } from "./utils/rolldown.js";
|
|
5
|
+
import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
|
|
6
|
+
import { reportStylesheetError } from "./utils/stylesheet-warning.js";
|
|
7
|
+
import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
|
|
8
|
+
import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
|
|
3
9
|
import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
|
|
4
|
-
import {
|
|
5
|
-
import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
|
|
10
|
+
import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
|
|
6
11
|
import { ANGULAR_DECORATOR_CALL_RE } from "./compiler/constants.js";
|
|
7
|
-
import {
|
|
12
|
+
import { parseOxc } from "./compiler/utils.js";
|
|
13
|
+
import { debugRegistry } from "./compiler/debug.js";
|
|
8
14
|
import { compile } from "./compiler/compile.js";
|
|
9
|
-
import { scanFile } from "./compiler/registry.js";
|
|
10
|
-
import { collectAllImports,
|
|
15
|
+
import { declaresNonStandaloneComponent, scanFile } from "./compiler/registry.js";
|
|
16
|
+
import { collectAllImports, collectRelativeReExports } from "./compiler/dts-reader.js";
|
|
11
17
|
import { jitTransform } from "./compiler/jit-transform.js";
|
|
12
18
|
import { generateHmrCode } from "./compiler/hmr.js";
|
|
13
19
|
import { extractInlineStyles, inlineResourceUrls } from "./compiler/resource-inliner.js";
|
|
14
20
|
import "./compiler/index.js";
|
|
15
|
-
import {
|
|
21
|
+
import { ComponentScanner } from "./component-scanner.js";
|
|
16
22
|
import { promises } from "node:fs";
|
|
17
|
-
import { dirname,
|
|
23
|
+
import { dirname, resolve } from "node:path";
|
|
18
24
|
import * as vite from "vite";
|
|
19
25
|
import { normalizePath, preprocessCSS } from "vite";
|
|
20
26
|
import * as compilerCli from "@angular/compiler-cli";
|
|
21
|
-
import { parseSync } from "oxc-parser";
|
|
22
27
|
//#region packages/vite-plugin-angular/src/lib/fast-compile-plugin.ts
|
|
28
|
+
function isFastCompilePluginOptions(value) {
|
|
29
|
+
return typeof value === "object" && value !== null && !isAngularBuildContext(value) && "tsconfigGetter" in value && typeof value.tsconfigGetter === "function";
|
|
30
|
+
}
|
|
23
31
|
/**
|
|
24
32
|
* Directory that `compilerOptions.paths` targets resolve against. Mirrors
|
|
25
33
|
* TypeScript: `baseUrl` when set, otherwise the directory of the config
|
|
@@ -29,17 +37,31 @@ import { parseSync } from "oxc-parser";
|
|
|
29
37
|
function getPathsBasePath(options, fallback) {
|
|
30
38
|
return options?.baseUrl ?? options?.pathsBasePath ?? fallback;
|
|
31
39
|
}
|
|
32
|
-
function fastCompilePlugin(
|
|
40
|
+
function fastCompilePlugin(optionsOrCtx) {
|
|
41
|
+
const sharedCtx = isAngularBuildContext(optionsOrCtx) ? optionsOrCtx : isFastCompilePluginOptions(optionsOrCtx) ? void 0 : createAngularBuildContext({
|
|
42
|
+
...optionsOrCtx,
|
|
43
|
+
compilationBackend: "fast"
|
|
44
|
+
});
|
|
45
|
+
const pluginOptions = sharedCtx ? sharedCtx.options : optionsOrCtx;
|
|
46
|
+
const scanner = new ComponentScanner();
|
|
47
|
+
const registry = scanner.registry;
|
|
48
|
+
const tsconfigResolver = sharedCtx?.tsconfigResolver ?? new TsconfigResolver({
|
|
49
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
50
|
+
include: pluginOptions.include ?? [],
|
|
51
|
+
liveReload: pluginOptions.liveReload,
|
|
52
|
+
isTest: pluginOptions.isTest
|
|
53
|
+
});
|
|
33
54
|
let resolvedConfig;
|
|
34
55
|
let transformFilter;
|
|
35
56
|
let componentRegistries = [];
|
|
57
|
+
let stylePreprocessor;
|
|
36
58
|
let tsConfigResolutionContext = null;
|
|
37
59
|
let watchMode = false;
|
|
38
|
-
const registry = /* @__PURE__ */ new Map();
|
|
39
60
|
const resourceToSource = /* @__PURE__ */ new Map();
|
|
40
|
-
const
|
|
41
|
-
let projectRoot = "";
|
|
61
|
+
const emittedMaps = /* @__PURE__ */ new Map();
|
|
42
62
|
let useDefineForClassFields = true;
|
|
63
|
+
let tsConfig;
|
|
64
|
+
let projectScan;
|
|
43
65
|
/**
|
|
44
66
|
* Scan a file into the registry, then recursively walk its relative
|
|
45
67
|
* `export *` / `export { … } from './x'` chain so any underlying
|
|
@@ -61,7 +83,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
61
83
|
visited.add(file);
|
|
62
84
|
let code;
|
|
63
85
|
try {
|
|
64
|
-
code = fileContents?.get(file) ?? await
|
|
86
|
+
code = fileContents?.get(file) ?? await scanner.readScanSource(file);
|
|
65
87
|
fileContents?.set(file, code);
|
|
66
88
|
} catch (e) {
|
|
67
89
|
if (debugRegistry.enabled) debugRegistry("scanBarrelExports: failed to read %s: %s", file, e?.message);
|
|
@@ -69,7 +91,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
69
91
|
}
|
|
70
92
|
let program;
|
|
71
93
|
try {
|
|
72
|
-
program =
|
|
94
|
+
program = parseOxc(file, code).program;
|
|
73
95
|
} catch {
|
|
74
96
|
program = void 0;
|
|
75
97
|
}
|
|
@@ -94,15 +116,22 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
94
116
|
}
|
|
95
117
|
}
|
|
96
118
|
async function initFastCompile() {
|
|
119
|
+
emittedMaps.clear();
|
|
97
120
|
if (pluginOptions.jit) return;
|
|
98
|
-
|
|
99
|
-
scannedDtsPackages.clear();
|
|
121
|
+
projectScan = void 0;
|
|
100
122
|
const resolvedTsConfigPath = resolveTsConfigPath();
|
|
101
|
-
projectRoot = dirname(resolvedTsConfigPath);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
123
|
+
const projectRoot = dirname(resolvedTsConfigPath);
|
|
124
|
+
scanner.reset(projectRoot);
|
|
125
|
+
tsConfig = compilerCli.readConfiguration(resolvedTsConfigPath);
|
|
126
|
+
useDefineForClassFields = tsConfig.options?.useDefineForClassFields ?? true;
|
|
127
|
+
}
|
|
128
|
+
/** Scan all source files reachable from the tsconfig into the registry. */
|
|
129
|
+
async function scanProject() {
|
|
130
|
+
const config = tsConfig;
|
|
131
|
+
const extraIncludes = tsconfigResolver.ensureIncludeCache();
|
|
132
|
+
const candidates = /* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes]);
|
|
105
133
|
const tsPaths = config.options?.paths;
|
|
134
|
+
const projectRoot = scanner.projectRoot;
|
|
106
135
|
const baseUrl = getPathsBasePath(config.options, projectRoot);
|
|
107
136
|
const fileContents = /* @__PURE__ */ new Map();
|
|
108
137
|
const scanResults = /* @__PURE__ */ new Map();
|
|
@@ -112,7 +141,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
112
141
|
}
|
|
113
142
|
const results = await Promise.all(Array.from(candidates).map(async (file) => {
|
|
114
143
|
try {
|
|
115
|
-
const code = await
|
|
144
|
+
const code = await scanner.readScanSource(file);
|
|
116
145
|
fileContents.set(file, code);
|
|
117
146
|
const entries = scanFile(code, file);
|
|
118
147
|
scanResults.set(file, entries);
|
|
@@ -165,14 +194,14 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
165
194
|
importWalkVisited.add(file);
|
|
166
195
|
let code;
|
|
167
196
|
try {
|
|
168
|
-
code = fileContents.get(file) ?? await
|
|
197
|
+
code = fileContents.get(file) ?? await scanner.readScanSource(file);
|
|
169
198
|
fileContents.set(file, code);
|
|
170
199
|
} catch {
|
|
171
200
|
return;
|
|
172
201
|
}
|
|
173
202
|
let program;
|
|
174
203
|
try {
|
|
175
|
-
program =
|
|
204
|
+
program = parseOxc(file, code).program;
|
|
176
205
|
} catch {
|
|
177
206
|
program = void 0;
|
|
178
207
|
}
|
|
@@ -182,13 +211,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
182
211
|
scanResults.set(file, entries);
|
|
183
212
|
}
|
|
184
213
|
for (const entry of entries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
185
|
-
|
|
186
|
-
if (scannedDtsPackages.has(pkg)) continue;
|
|
187
|
-
scannedDtsPackages.add(pkg);
|
|
188
|
-
try {
|
|
189
|
-
for (const entry of scanPackageDts(pkg, projectRoot, scannedDtsPackages)) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
190
|
-
} catch {}
|
|
191
|
-
}
|
|
214
|
+
scanner.ensureDtsRegistryForSource(code, file, program);
|
|
192
215
|
const dir = dirname(file);
|
|
193
216
|
const targets = await Promise.all(collectAllImports(code, file, program).map((spec) => {
|
|
194
217
|
if (spec.startsWith(".")) return resolveToSource(resolve(dir, spec.replace(/\.(?:js|mjs)$/u, "")));
|
|
@@ -201,7 +224,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
201
224
|
}));
|
|
202
225
|
await Promise.all(targets.filter((t) => !!t).map((t) => walkImports(t)));
|
|
203
226
|
};
|
|
204
|
-
|
|
227
|
+
const walkRoots = [.../* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes])];
|
|
228
|
+
await Promise.all(walkRoots.map((file) => walkImports(file)));
|
|
205
229
|
const buildStartVisited = /* @__PURE__ */ new Set();
|
|
206
230
|
if (tsPaths) {
|
|
207
231
|
const barrelCandidates = [];
|
|
@@ -213,17 +237,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
213
237
|
}
|
|
214
238
|
debugRegistry("initFastCompile done: %d entries from %d candidate files", registry.size, candidates.size);
|
|
215
239
|
}
|
|
216
|
-
function
|
|
217
|
-
for (const pkg of collectImportedPackages(code, id, program)) {
|
|
218
|
-
if (scannedDtsPackages.has(pkg)) continue;
|
|
219
|
-
scannedDtsPackages.add(pkg);
|
|
220
|
-
try {
|
|
221
|
-
const dtsEntries = scanPackageDts(pkg, projectRoot, scannedDtsPackages);
|
|
222
|
-
for (const entry of dtsEntries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
223
|
-
} catch {}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async function handleFastCompileTransform(code, id) {
|
|
240
|
+
async function handleFastCompileTransform(code, id, resolveImport) {
|
|
227
241
|
if (!ANGULAR_DECORATOR_CALL_RE.test(code)) {
|
|
228
242
|
const stripped = vite.transformWithOxc ? await vite.transformWithOxc(code, id, {
|
|
229
243
|
lang: "ts",
|
|
@@ -262,35 +276,44 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
262
276
|
}
|
|
263
277
|
const inlined = await inlineResourceUrls(code, id);
|
|
264
278
|
code = inlined.code;
|
|
265
|
-
const {
|
|
279
|
+
const { stylePaths } = inlined;
|
|
266
280
|
for (const dep of inlined.resourceDependencies) resourceToSource.set(dep, id);
|
|
267
|
-
const { program: oxcProgram } =
|
|
281
|
+
const { program: oxcProgram } = parseOxc(id, code);
|
|
268
282
|
let resolvedInlineStyles;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
283
|
+
const styleStrings = extractInlineStyles(code, id, oxcProgram);
|
|
284
|
+
if (styleStrings.length > 0) {
|
|
285
|
+
resolvedInlineStyles = /* @__PURE__ */ new Map();
|
|
286
|
+
const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
|
|
287
|
+
const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
|
|
288
|
+
for (let i = 0; i < styleStrings.length; i++) {
|
|
289
|
+
const stylePath = stylePaths.get(i) ?? (scanner.sourceFormatOf(id) ? id + ".ts" : id).replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
|
|
290
|
+
try {
|
|
291
|
+
const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
|
|
292
|
+
filename: stylePath,
|
|
293
|
+
containingFile: id,
|
|
294
|
+
order: i,
|
|
295
|
+
inline: !stylePaths.has(i)
|
|
296
|
+
});
|
|
297
|
+
const processed = await preprocessCSS(preprocessed, stylePath, activeConfig);
|
|
298
|
+
resolvedInlineStyles.set(i, processed.code);
|
|
299
|
+
} catch (e) {
|
|
300
|
+
reportStylesheetError(activeConfig?.logger, stylePath, e, activeConfig?.command === "build");
|
|
285
301
|
}
|
|
286
|
-
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
287
302
|
}
|
|
303
|
+
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
288
304
|
}
|
|
289
|
-
ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
305
|
+
scanner.ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
306
|
+
for (const entry of scanFile(code, id, oxcProgram)) registry.set(entry.className, entry);
|
|
307
|
+
await scanner.resolveImportSpecifiers(collectAllImports(code, id, oxcProgram), id, resolveImport);
|
|
308
|
+
if (declaresNonStandaloneComponent(oxcProgram)) {
|
|
309
|
+
projectScan ??= scanProject();
|
|
310
|
+
await projectScan;
|
|
311
|
+
}
|
|
312
|
+
const activeComponentRegistries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
|
|
290
313
|
let compileRegistry = registry;
|
|
291
|
-
if (
|
|
314
|
+
if (activeComponentRegistries.some((external) => external.size > 0)) {
|
|
292
315
|
compileRegistry = new Map(registry);
|
|
293
|
-
for (const external of
|
|
316
|
+
for (const external of activeComponentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
|
|
294
317
|
}
|
|
295
318
|
const result = compile(code, id, {
|
|
296
319
|
registry: compileRegistry,
|
|
@@ -312,8 +335,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
312
335
|
sourcemap: true
|
|
313
336
|
}, result.map);
|
|
314
337
|
let outputCode = stripped.code;
|
|
315
|
-
if (watchMode && pluginOptions.liveReload) {
|
|
316
|
-
const fileDeclarations =
|
|
338
|
+
if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
|
|
339
|
+
const fileDeclarations = scanner.entriesOf(id);
|
|
317
340
|
if (fileDeclarations.length > 0) {
|
|
318
341
|
const localDepClassNames = fileDeclarations.map((e) => e.className);
|
|
319
342
|
outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
|
|
@@ -325,17 +348,53 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
325
348
|
};
|
|
326
349
|
}
|
|
327
350
|
function resolveTsConfigPath() {
|
|
328
|
-
|
|
329
|
-
|
|
351
|
+
if (sharedCtx) return sharedCtx.resolveTsConfigPath();
|
|
352
|
+
const resolution = tsConfigResolutionContext ?? {
|
|
353
|
+
root: resolvedConfig?.root || ".",
|
|
354
|
+
isProd: isProdMode(resolvedConfig?.mode),
|
|
355
|
+
isLib: !!resolvedConfig?.build?.lib
|
|
356
|
+
};
|
|
357
|
+
return getTsConfigPath(resolution.root, pluginOptions.tsconfigGetter(), resolution.isProd, pluginOptions.isTest, resolution.isLib, pluginOptions.workspaceRoot);
|
|
330
358
|
}
|
|
359
|
+
const compilerApi = {
|
|
360
|
+
angularCompiler: true,
|
|
361
|
+
getTsConfigPath: resolveTsConfigPath,
|
|
362
|
+
getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
|
|
363
|
+
hasEmitted: (id) => emittedMaps.has(normalizePath(id)),
|
|
364
|
+
fastCompile: {
|
|
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),
|
|
368
|
+
async compile(code, id, { resolve, mapToSource }) {
|
|
369
|
+
const transformed = await handleFastCompileTransform(code, id, scanner.toResolveImport(resolve));
|
|
370
|
+
if (!transformed) return;
|
|
371
|
+
const map = transformed.map && mapToSource ? mapToSource(transformed.map) : transformed.map ?? null;
|
|
372
|
+
if (map) emittedMaps.set(normalizePath(id), typeof map === "string" ? map : JSON.stringify(map));
|
|
373
|
+
return {
|
|
374
|
+
code: transformed.code,
|
|
375
|
+
map
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
sharedCtx?.registerCompiler({
|
|
381
|
+
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
382
|
+
getTsConfigPath: compilerApi.getTsConfigPath,
|
|
383
|
+
getSourceMap: compilerApi.getSourceMap,
|
|
384
|
+
hasEmitted: compilerApi.hasEmitted
|
|
385
|
+
});
|
|
331
386
|
return {
|
|
332
387
|
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
333
|
-
api:
|
|
388
|
+
api: compilerApi,
|
|
334
389
|
enforce: "pre",
|
|
335
|
-
async config(config, { command }) {
|
|
390
|
+
async config(config, { command, mode }) {
|
|
336
391
|
watchMode = command === "serve";
|
|
337
392
|
const isProd = isProdMode(config.mode);
|
|
338
|
-
|
|
393
|
+
if (sharedCtx) sharedCtx.initConfig(config, {
|
|
394
|
+
command,
|
|
395
|
+
mode
|
|
396
|
+
});
|
|
397
|
+
else tsConfigResolutionContext = {
|
|
339
398
|
root: config.root || ".",
|
|
340
399
|
isProd,
|
|
341
400
|
isLib: !!config?.build?.lib
|
|
@@ -350,64 +409,61 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
350
409
|
isAstroIntegration: pluginOptions.isAstroIntegration
|
|
351
410
|
});
|
|
352
411
|
return {
|
|
353
|
-
...
|
|
412
|
+
...isRolldown() ? { oxc: {} } : { esbuild: false },
|
|
354
413
|
...depOptimizer
|
|
355
414
|
};
|
|
356
415
|
},
|
|
357
416
|
async configResolved(config) {
|
|
358
417
|
resolvedConfig = config;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
418
|
+
if (sharedCtx) {
|
|
419
|
+
const integrations = await sharedCtx.resolveConfig(config);
|
|
420
|
+
transformFilter = integrations.transformFilter;
|
|
421
|
+
componentRegistries = integrations.componentRegistries;
|
|
422
|
+
stylePreprocessor = integrations.stylePreprocessor;
|
|
423
|
+
} else {
|
|
424
|
+
const integrations = await discoverAnalogIntegrations(config);
|
|
425
|
+
transformFilter = integrations.transformFilter;
|
|
426
|
+
componentRegistries = integrations.componentRegistries;
|
|
427
|
+
stylePreprocessor = integrations.stylePreprocessor;
|
|
428
|
+
tsconfigResolver.setIntegrationIncludes(integrations.include);
|
|
429
|
+
}
|
|
367
430
|
},
|
|
368
431
|
async buildStart() {
|
|
369
432
|
await initFastCompile();
|
|
370
433
|
},
|
|
371
434
|
closeBundle() {
|
|
372
|
-
if (!watchMode)
|
|
435
|
+
if (!(sharedCtx ? sharedCtx.watchMode : watchMode)) {
|
|
436
|
+
emittedMaps.clear();
|
|
437
|
+
releaseCssPreprocessorWorkers();
|
|
438
|
+
}
|
|
373
439
|
},
|
|
374
440
|
async handleHotUpdate(ctx) {
|
|
441
|
+
if (sharedCtx ? sharedCtx.hmr.isIgnoredFile(ctx.file) : isIgnoredHmrFile(ctx.file)) return [];
|
|
375
442
|
if (resourceToSource.has(ctx.file)) {
|
|
376
443
|
const parentSource = resourceToSource.get(ctx.file);
|
|
377
444
|
const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
|
|
378
445
|
if (parentModule) return [parentModule];
|
|
379
446
|
}
|
|
380
|
-
if (
|
|
447
|
+
if (scanner.isCompiledSource(ctx.file)) {
|
|
381
448
|
const [fileId] = ctx.file.split("?");
|
|
382
|
-
const oldEntries =
|
|
383
|
-
|
|
449
|
+
const oldEntries = scanner.entriesOf(fileId);
|
|
450
|
+
scanner.invalidate(fileId);
|
|
384
451
|
await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
|
|
452
|
+
if (JSON.stringify(oldEntries) !== JSON.stringify(scanner.entriesOf(fileId))) {
|
|
453
|
+
const importerModules = [...scanner.importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
|
|
454
|
+
return [...ctx.modules, ...importerModules];
|
|
455
|
+
}
|
|
385
456
|
}
|
|
386
457
|
return ctx.modules;
|
|
387
458
|
},
|
|
388
459
|
resolveId(id, importer) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
markStylePathSafe(resolvedConfig, filePath);
|
|
394
|
-
return filePath + "?inline";
|
|
395
|
-
}
|
|
396
|
-
return toVirtualRawId(filePath);
|
|
397
|
-
}
|
|
398
|
-
const rawRewrite = rewriteHtmlRawImport(id, importer);
|
|
399
|
-
if (rawRewrite) return rawRewrite;
|
|
400
|
-
if (/\.(css|scss|sass|less)\?inline$/.test(id) && importer) {
|
|
401
|
-
const filePath = id.split("?")[0];
|
|
402
|
-
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : normalizePath(resolve(dirname(importer), filePath));
|
|
403
|
-
markStylePathSafe(resolvedConfig, resolved);
|
|
404
|
-
return resolved + "?inline";
|
|
405
|
-
}
|
|
460
|
+
return resolveAngularVirtualId(id, importer, {
|
|
461
|
+
jit: pluginOptions.jit,
|
|
462
|
+
resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig
|
|
463
|
+
});
|
|
406
464
|
},
|
|
407
465
|
async load(id) {
|
|
408
|
-
|
|
409
|
-
if (rawModule !== void 0) return rawModule;
|
|
410
|
-
if (/\.(css|scss|sass|less)\?inline$/.test(id)) markStylePathSafe(resolvedConfig, id.split("?")[0]);
|
|
466
|
+
return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? resolvedConfig);
|
|
411
467
|
},
|
|
412
468
|
transform: {
|
|
413
469
|
filter: { id: {
|
|
@@ -420,9 +476,13 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
420
476
|
]
|
|
421
477
|
} },
|
|
422
478
|
async handler(code, id) {
|
|
423
|
-
|
|
479
|
+
const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
|
|
480
|
+
if (activeTransformFilter && !activeTransformFilter(code, id)) return;
|
|
424
481
|
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
425
|
-
|
|
482
|
+
const resolveImport = scanner.toResolveImport((spec, importer) => this.resolve(spec, importer, { skipSelf: true }));
|
|
483
|
+
const transformed = await handleFastCompileTransform(code, id, resolveImport);
|
|
484
|
+
if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
|
|
485
|
+
return transformed;
|
|
426
486
|
}
|
|
427
487
|
}
|
|
428
488
|
};
|