@analogjs/vite-plugin-angular 3.0.0-beta.4 → 3.0.0-beta.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ngp/LICENSE +21 -0
- package/ngp/api.mjs +46048 -0
- package/ngp/build.json +4 -0
- package/ngp/ng_analyze.cjs +504 -0
- package/ngp/ng_analyze_bg.wasm +0 -0
- package/package.json +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 +10 -5
- 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 -1246
- 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 +158 -143
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +11 -13
- 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 +14 -7
- package/src/lib/compiler/utils.js +38 -9
- package/src/lib/compiler/utils.js.map +1 -1
- 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-plugin.d.ts +6 -1
- package/src/lib/fast-compile-plugin.js +209 -79
- 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-plugin.d.ts +4 -0
- package/src/lib/ngp-compile-plugin.js +410 -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 +763 -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 +55 -0
- package/src/lib/utils/lsp-type-checker.js +502 -0
- package/src/lib/utils/lsp-type-checker.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,32 @@
|
|
|
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 { EXCLUDED_TS_EXT_REGEX, 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, collectImportedPackages, collectRelativeReExports, scanPackageDts } from "./compiler/dts-reader.js";
|
|
15
|
+
import { declaresNonStandaloneComponent, scanFile } from "./compiler/registry.js";
|
|
16
|
+
import { collectAllImports, collectImportedPackages, collectReExports, collectRelativeReExports, scanPackageDts } 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 { markStylePathSafe } from "./utils/safe-module-paths.js";
|
|
16
21
|
import { promises } from "node:fs";
|
|
17
|
-
import { dirname,
|
|
22
|
+
import { dirname, resolve } from "node:path";
|
|
18
23
|
import * as vite from "vite";
|
|
19
24
|
import { normalizePath, preprocessCSS } from "vite";
|
|
20
25
|
import * as compilerCli from "@angular/compiler-cli";
|
|
21
|
-
import { parseSync } from "oxc-parser";
|
|
22
26
|
//#region packages/vite-plugin-angular/src/lib/fast-compile-plugin.ts
|
|
27
|
+
function isFastCompilePluginOptions(value) {
|
|
28
|
+
return typeof value === "object" && value !== null && !isAngularBuildContext(value) && "tsconfigGetter" in value && typeof value.tsconfigGetter === "function";
|
|
29
|
+
}
|
|
23
30
|
/**
|
|
24
31
|
* Directory that `compilerOptions.paths` targets resolve against. Mirrors
|
|
25
32
|
* TypeScript: `baseUrl` when set, otherwise the directory of the config
|
|
@@ -29,17 +36,34 @@ import { parseSync } from "oxc-parser";
|
|
|
29
36
|
function getPathsBasePath(options, fallback) {
|
|
30
37
|
return options?.baseUrl ?? options?.pathsBasePath ?? fallback;
|
|
31
38
|
}
|
|
32
|
-
function fastCompilePlugin(
|
|
39
|
+
function fastCompilePlugin(optionsOrCtx) {
|
|
40
|
+
const sharedCtx = isAngularBuildContext(optionsOrCtx) ? optionsOrCtx : isFastCompilePluginOptions(optionsOrCtx) ? void 0 : createAngularBuildContext({
|
|
41
|
+
...optionsOrCtx,
|
|
42
|
+
compilationBackend: "fast"
|
|
43
|
+
});
|
|
44
|
+
const pluginOptions = sharedCtx ? sharedCtx.options : optionsOrCtx;
|
|
45
|
+
const tsconfigResolver = sharedCtx?.tsconfigResolver ?? new TsconfigResolver({
|
|
46
|
+
workspaceRoot: pluginOptions.workspaceRoot,
|
|
47
|
+
include: pluginOptions.include ?? [],
|
|
48
|
+
liveReload: pluginOptions.liveReload,
|
|
49
|
+
isTest: pluginOptions.isTest
|
|
50
|
+
});
|
|
33
51
|
let resolvedConfig;
|
|
34
52
|
let transformFilter;
|
|
35
53
|
let componentRegistries = [];
|
|
54
|
+
let stylePreprocessor;
|
|
36
55
|
let tsConfigResolutionContext = null;
|
|
37
56
|
let watchMode = false;
|
|
38
57
|
const registry = /* @__PURE__ */ new Map();
|
|
39
58
|
const resourceToSource = /* @__PURE__ */ new Map();
|
|
40
59
|
const scannedDtsPackages = /* @__PURE__ */ new Set();
|
|
60
|
+
const emittedMaps = /* @__PURE__ */ new Map();
|
|
41
61
|
let projectRoot = "";
|
|
42
62
|
let useDefineForClassFields = true;
|
|
63
|
+
let tsConfig;
|
|
64
|
+
const lazyScans = /* @__PURE__ */ new Map();
|
|
65
|
+
const importersByFile = /* @__PURE__ */ new Map();
|
|
66
|
+
let projectScan;
|
|
43
67
|
/**
|
|
44
68
|
* Scan a file into the registry, then recursively walk its relative
|
|
45
69
|
* `export *` / `export { … } from './x'` chain so any underlying
|
|
@@ -69,7 +93,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
69
93
|
}
|
|
70
94
|
let program;
|
|
71
95
|
try {
|
|
72
|
-
program =
|
|
96
|
+
program = parseOxc(file, code).program;
|
|
73
97
|
} catch {
|
|
74
98
|
program = void 0;
|
|
75
99
|
}
|
|
@@ -94,14 +118,23 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
120
|
async function initFastCompile() {
|
|
121
|
+
emittedMaps.clear();
|
|
97
122
|
if (pluginOptions.jit) return;
|
|
98
123
|
registry.clear();
|
|
99
124
|
scannedDtsPackages.clear();
|
|
125
|
+
lazyScans.clear();
|
|
126
|
+
importersByFile.clear();
|
|
127
|
+
projectScan = void 0;
|
|
100
128
|
const resolvedTsConfigPath = resolveTsConfigPath();
|
|
101
129
|
projectRoot = dirname(resolvedTsConfigPath);
|
|
102
|
-
|
|
103
|
-
useDefineForClassFields =
|
|
104
|
-
|
|
130
|
+
tsConfig = compilerCli.readConfiguration(resolvedTsConfigPath);
|
|
131
|
+
useDefineForClassFields = tsConfig.options?.useDefineForClassFields ?? true;
|
|
132
|
+
}
|
|
133
|
+
/** Scan all source files reachable from the tsconfig into the registry. */
|
|
134
|
+
async function scanProject() {
|
|
135
|
+
const config = tsConfig;
|
|
136
|
+
const extraIncludes = tsconfigResolver.ensureIncludeCache();
|
|
137
|
+
const candidates = /* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes]);
|
|
105
138
|
const tsPaths = config.options?.paths;
|
|
106
139
|
const baseUrl = getPathsBasePath(config.options, projectRoot);
|
|
107
140
|
const fileContents = /* @__PURE__ */ new Map();
|
|
@@ -172,7 +205,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
172
205
|
}
|
|
173
206
|
let program;
|
|
174
207
|
try {
|
|
175
|
-
program =
|
|
208
|
+
program = parseOxc(file, code).program;
|
|
176
209
|
} catch {
|
|
177
210
|
program = void 0;
|
|
178
211
|
}
|
|
@@ -201,7 +234,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
201
234
|
}));
|
|
202
235
|
await Promise.all(targets.filter((t) => !!t).map((t) => walkImports(t)));
|
|
203
236
|
};
|
|
204
|
-
|
|
237
|
+
const walkRoots = [.../* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes])];
|
|
238
|
+
await Promise.all(walkRoots.map((file) => walkImports(file)));
|
|
205
239
|
const buildStartVisited = /* @__PURE__ */ new Set();
|
|
206
240
|
if (tsPaths) {
|
|
207
241
|
const barrelCandidates = [];
|
|
@@ -223,7 +257,67 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
223
257
|
} catch {}
|
|
224
258
|
}
|
|
225
259
|
}
|
|
226
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Scan the source files `id` imports into the registry on demand and record
|
|
262
|
+
* `id` as their importer, so a metadata change in any of them recompiles it.
|
|
263
|
+
*/
|
|
264
|
+
async function resolveImportedDeclarations(code, id, program, resolveImport) {
|
|
265
|
+
await Promise.all(collectAllImports(code, id, program).map(async (spec) => {
|
|
266
|
+
const file = await resolveImport(spec, id);
|
|
267
|
+
if (!file) return;
|
|
268
|
+
for (const scanned of await scanOnDemand(file, resolveImport)) {
|
|
269
|
+
let importers = importersByFile.get(scanned);
|
|
270
|
+
if (!importers) {
|
|
271
|
+
importers = /* @__PURE__ */ new Set();
|
|
272
|
+
importersByFile.set(scanned, importers);
|
|
273
|
+
}
|
|
274
|
+
importers.add(id);
|
|
275
|
+
}
|
|
276
|
+
}));
|
|
277
|
+
}
|
|
278
|
+
function scanOnDemand(file, resolveImport) {
|
|
279
|
+
let scan = lazyScans.get(file);
|
|
280
|
+
if (!scan) {
|
|
281
|
+
scan = scanWithReExports(file, resolveImport);
|
|
282
|
+
lazyScans.set(file, scan);
|
|
283
|
+
}
|
|
284
|
+
return scan;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Scan a file and everything it re-exports, resolving specifiers through
|
|
288
|
+
* Vite so path aliases work. Tuple barrels and NgModules can list classes
|
|
289
|
+
* their file imports without re-exporting, so their imports are followed
|
|
290
|
+
* too. Returns every file scanned.
|
|
291
|
+
*/
|
|
292
|
+
async function scanWithReExports(file, resolveImport) {
|
|
293
|
+
const visited = /* @__PURE__ */ new Set();
|
|
294
|
+
const visit = async (current) => {
|
|
295
|
+
if (visited.has(current)) return;
|
|
296
|
+
visited.add(current);
|
|
297
|
+
let code;
|
|
298
|
+
let program;
|
|
299
|
+
try {
|
|
300
|
+
code = await promises.readFile(current, "utf-8");
|
|
301
|
+
program = parseOxc(current, code).program;
|
|
302
|
+
} catch {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
const entries = scanFile(code, current, program);
|
|
306
|
+
for (const entry of entries) if (!registry.has(entry.className)) registry.set(entry.className, entry);
|
|
307
|
+
ensureDtsRegistryForSource(code, current, program);
|
|
308
|
+
const specifiers = entries.some((e) => e.kind === "tuple" || e.kind === "ngmodule") ? collectAllImports(code, current, program) : collectReExports(code, current, program);
|
|
309
|
+
for (const spec of specifiers) {
|
|
310
|
+
const dep = await resolveImport(spec, current);
|
|
311
|
+
if (dep) await visit(dep);
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
await visit(file);
|
|
315
|
+
return visited;
|
|
316
|
+
}
|
|
317
|
+
function registryEntriesOf(file) {
|
|
318
|
+
return [...registry.values()].filter((e) => e.fileName === file);
|
|
319
|
+
}
|
|
320
|
+
async function handleFastCompileTransform(code, id, resolveImport) {
|
|
227
321
|
if (!ANGULAR_DECORATOR_CALL_RE.test(code)) {
|
|
228
322
|
const stripped = vite.transformWithOxc ? await vite.transformWithOxc(code, id, {
|
|
229
323
|
lang: "ts",
|
|
@@ -262,35 +356,44 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
262
356
|
}
|
|
263
357
|
const inlined = await inlineResourceUrls(code, id);
|
|
264
358
|
code = inlined.code;
|
|
265
|
-
const {
|
|
359
|
+
const { stylePaths } = inlined;
|
|
266
360
|
for (const dep of inlined.resourceDependencies) resourceToSource.set(dep, id);
|
|
267
|
-
const { program: oxcProgram } =
|
|
361
|
+
const { program: oxcProgram } = parseOxc(id, code);
|
|
268
362
|
let resolvedInlineStyles;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
363
|
+
const styleStrings = extractInlineStyles(code, id, oxcProgram);
|
|
364
|
+
if (styleStrings.length > 0) {
|
|
365
|
+
resolvedInlineStyles = /* @__PURE__ */ new Map();
|
|
366
|
+
const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
|
|
367
|
+
const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
|
|
368
|
+
for (let i = 0; i < styleStrings.length; i++) {
|
|
369
|
+
const stylePath = stylePaths.get(i) ?? id.replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
|
|
370
|
+
try {
|
|
371
|
+
const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
|
|
372
|
+
filename: stylePath,
|
|
373
|
+
containingFile: id,
|
|
374
|
+
order: i,
|
|
375
|
+
inline: !stylePaths.has(i)
|
|
376
|
+
});
|
|
377
|
+
const processed = await preprocessCSS(preprocessed, stylePath, activeConfig);
|
|
378
|
+
resolvedInlineStyles.set(i, processed.code);
|
|
379
|
+
} catch (e) {
|
|
380
|
+
reportStylesheetError(activeConfig?.logger, stylePath, e, activeConfig?.command === "build");
|
|
285
381
|
}
|
|
286
|
-
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
287
382
|
}
|
|
383
|
+
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
288
384
|
}
|
|
289
385
|
ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
386
|
+
for (const entry of scanFile(code, id, oxcProgram)) registry.set(entry.className, entry);
|
|
387
|
+
await resolveImportedDeclarations(code, id, oxcProgram, resolveImport);
|
|
388
|
+
if (declaresNonStandaloneComponent(oxcProgram)) {
|
|
389
|
+
projectScan ??= scanProject();
|
|
390
|
+
await projectScan;
|
|
391
|
+
}
|
|
392
|
+
const activeComponentRegistries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
|
|
290
393
|
let compileRegistry = registry;
|
|
291
|
-
if (
|
|
394
|
+
if (activeComponentRegistries.some((external) => external.size > 0)) {
|
|
292
395
|
compileRegistry = new Map(registry);
|
|
293
|
-
for (const external of
|
|
396
|
+
for (const external of activeComponentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
|
|
294
397
|
}
|
|
295
398
|
const result = compile(code, id, {
|
|
296
399
|
registry: compileRegistry,
|
|
@@ -312,8 +415,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
312
415
|
sourcemap: true
|
|
313
416
|
}, result.map);
|
|
314
417
|
let outputCode = stripped.code;
|
|
315
|
-
if (watchMode && pluginOptions.liveReload) {
|
|
316
|
-
const fileDeclarations =
|
|
418
|
+
if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
|
|
419
|
+
const fileDeclarations = registryEntriesOf(id);
|
|
317
420
|
if (fileDeclarations.length > 0) {
|
|
318
421
|
const localDepClassNames = fileDeclarations.map((e) => e.className);
|
|
319
422
|
outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
|
|
@@ -325,17 +428,38 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
325
428
|
};
|
|
326
429
|
}
|
|
327
430
|
function resolveTsConfigPath() {
|
|
328
|
-
|
|
329
|
-
|
|
431
|
+
if (sharedCtx) return sharedCtx.resolveTsConfigPath();
|
|
432
|
+
const resolution = tsConfigResolutionContext ?? {
|
|
433
|
+
root: resolvedConfig?.root || ".",
|
|
434
|
+
isProd: isProdMode(resolvedConfig?.mode),
|
|
435
|
+
isLib: !!resolvedConfig?.build?.lib
|
|
436
|
+
};
|
|
437
|
+
return getTsConfigPath(resolution.root, pluginOptions.tsconfigGetter(), resolution.isProd, pluginOptions.isTest, resolution.isLib, pluginOptions.workspaceRoot);
|
|
330
438
|
}
|
|
439
|
+
const compilerApi = {
|
|
440
|
+
angularCompiler: true,
|
|
441
|
+
getTsConfigPath: resolveTsConfigPath,
|
|
442
|
+
getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
|
|
443
|
+
hasEmitted: (id) => emittedMaps.has(normalizePath(id))
|
|
444
|
+
};
|
|
445
|
+
sharedCtx?.registerCompiler({
|
|
446
|
+
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
447
|
+
getTsConfigPath: compilerApi.getTsConfigPath,
|
|
448
|
+
getSourceMap: compilerApi.getSourceMap,
|
|
449
|
+
hasEmitted: compilerApi.hasEmitted
|
|
450
|
+
});
|
|
331
451
|
return {
|
|
332
452
|
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
333
|
-
api:
|
|
453
|
+
api: compilerApi,
|
|
334
454
|
enforce: "pre",
|
|
335
|
-
async config(config, { command }) {
|
|
455
|
+
async config(config, { command, mode }) {
|
|
336
456
|
watchMode = command === "serve";
|
|
337
457
|
const isProd = isProdMode(config.mode);
|
|
338
|
-
|
|
458
|
+
if (sharedCtx) sharedCtx.initConfig(config, {
|
|
459
|
+
command,
|
|
460
|
+
mode
|
|
461
|
+
});
|
|
462
|
+
else tsConfigResolutionContext = {
|
|
339
463
|
root: config.root || ".",
|
|
340
464
|
isProd,
|
|
341
465
|
isLib: !!config?.build?.lib
|
|
@@ -350,28 +474,36 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
350
474
|
isAstroIntegration: pluginOptions.isAstroIntegration
|
|
351
475
|
});
|
|
352
476
|
return {
|
|
353
|
-
...
|
|
477
|
+
...isRolldown() ? { oxc: {} } : { esbuild: false },
|
|
354
478
|
...depOptimizer
|
|
355
479
|
};
|
|
356
480
|
},
|
|
357
481
|
async configResolved(config) {
|
|
358
482
|
resolvedConfig = config;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
483
|
+
if (sharedCtx) {
|
|
484
|
+
const integrations = await sharedCtx.resolveConfig(config);
|
|
485
|
+
transformFilter = integrations.transformFilter;
|
|
486
|
+
componentRegistries = integrations.componentRegistries;
|
|
487
|
+
stylePreprocessor = integrations.stylePreprocessor;
|
|
488
|
+
} else {
|
|
489
|
+
const integrations = await discoverAnalogIntegrations(config);
|
|
490
|
+
transformFilter = integrations.transformFilter;
|
|
491
|
+
componentRegistries = integrations.componentRegistries;
|
|
492
|
+
stylePreprocessor = integrations.stylePreprocessor;
|
|
493
|
+
tsconfigResolver.setIntegrationIncludes(integrations.include);
|
|
494
|
+
}
|
|
367
495
|
},
|
|
368
496
|
async buildStart() {
|
|
369
497
|
await initFastCompile();
|
|
370
498
|
},
|
|
371
499
|
closeBundle() {
|
|
372
|
-
if (!watchMode)
|
|
500
|
+
if (!(sharedCtx ? sharedCtx.watchMode : watchMode)) {
|
|
501
|
+
emittedMaps.clear();
|
|
502
|
+
releaseCssPreprocessorWorkers();
|
|
503
|
+
}
|
|
373
504
|
},
|
|
374
505
|
async handleHotUpdate(ctx) {
|
|
506
|
+
if (sharedCtx ? sharedCtx.hmr.isIgnoredFile(ctx.file) : isIgnoredHmrFile(ctx.file)) return [];
|
|
375
507
|
if (resourceToSource.has(ctx.file)) {
|
|
376
508
|
const parentSource = resourceToSource.get(ctx.file);
|
|
377
509
|
const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
|
|
@@ -379,35 +511,25 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
379
511
|
}
|
|
380
512
|
if (TS_EXT_REGEX.test(ctx.file)) {
|
|
381
513
|
const [fileId] = ctx.file.split("?");
|
|
382
|
-
const oldEntries =
|
|
383
|
-
for (const
|
|
514
|
+
const oldEntries = registryEntriesOf(fileId);
|
|
515
|
+
for (const entry of oldEntries) registry.delete(entry.className);
|
|
384
516
|
await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
|
|
517
|
+
lazyScans.clear();
|
|
518
|
+
if (JSON.stringify(oldEntries) !== JSON.stringify(registryEntriesOf(fileId))) {
|
|
519
|
+
const importerModules = [...importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
|
|
520
|
+
return [...ctx.modules, ...importerModules];
|
|
521
|
+
}
|
|
385
522
|
}
|
|
386
523
|
return ctx.modules;
|
|
387
524
|
},
|
|
388
525
|
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
|
-
}
|
|
526
|
+
return resolveAngularVirtualId(id, importer, {
|
|
527
|
+
jit: pluginOptions.jit,
|
|
528
|
+
resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig
|
|
529
|
+
});
|
|
406
530
|
},
|
|
407
531
|
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]);
|
|
532
|
+
return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? resolvedConfig);
|
|
411
533
|
},
|
|
412
534
|
transform: {
|
|
413
535
|
filter: { id: {
|
|
@@ -420,9 +542,17 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
420
542
|
]
|
|
421
543
|
} },
|
|
422
544
|
async handler(code, id) {
|
|
423
|
-
|
|
545
|
+
const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
|
|
546
|
+
if (activeTransformFilter && !activeTransformFilter(code, id)) return;
|
|
424
547
|
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
425
|
-
|
|
548
|
+
const transformed = await handleFastCompileTransform(code, id, async (spec, importer) => {
|
|
549
|
+
const resolved = await this.resolve(spec, importer, { skipSelf: true });
|
|
550
|
+
if (!resolved || resolved.external) return null;
|
|
551
|
+
const file = normalizePath(resolved.id.split("?")[0]);
|
|
552
|
+
return TS_EXT_REGEX.test(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
|
|
553
|
+
});
|
|
554
|
+
if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
|
|
555
|
+
return transformed;
|
|
426
556
|
}
|
|
427
557
|
}
|
|
428
558
|
};
|