@analogjs/vite-plugin-angular 3.0.0-beta.9 → 3.0.1-beta.1
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 +3 -3
- 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 +5 -2
- package/src/index.d.ts +2 -0
- package/src/index.js +4 -3
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.js +2 -3
- package/src/lib/angular-build-context.d.ts +217 -0
- package/src/lib/angular-build-context.js +374 -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 +25 -11
- 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 +16 -9
- 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 +9 -1251
- 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 +7 -5
- 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 +37 -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 +164 -289
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compilation-api/index.js +1 -2
- package/src/lib/compiler/angular-version.js +0 -1
- package/src/lib/compiler/class-field-lowering.js +1 -2
- package/src/lib/compiler/compile.d.ts +1 -1
- package/src/lib/compiler/compile.js +224 -151
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/constants.js +1 -2
- package/src/lib/compiler/debug.js +1 -2
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +13 -16
- 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 +20 -12
- 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 +8 -4
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +6 -6
- package/src/lib/compiler/jit-metadata.js +1 -2
- package/src/lib/compiler/jit-transform.js +37 -15
- 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 +4 -23
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/metadata.js +2 -3
- package/src/lib/compiler/registry.d.ts +9 -1
- package/src/lib/compiler/registry.js +36 -8
- 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 +11 -20
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +22 -1
- package/src/lib/compiler/style-ast.js +37 -20
- 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 +11 -13
- 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 +50 -11
- package/src/lib/compiler/utils.js.map +1 -1
- package/src/lib/compiler-plugin.js +1 -2
- package/src/lib/component-resolvers.js +1 -2
- package/src/lib/component-scanner.d.ts +101 -0
- package/src/lib/component-scanner.js +331 -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 +352 -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 +30 -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 +22 -0
- package/src/lib/dev-server-mode-plugin.js.map +1 -0
- package/src/lib/encapsulation-plugin.js +1 -2
- package/src/lib/fast-compile-api.d.ts +62 -0
- package/src/lib/fast-compile-api.js +11 -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 +222 -117
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.d.ts +3 -0
- package/src/lib/host.js +5 -4
- package/src/lib/host.js.map +1 -1
- package/src/lib/hot-update-batch.js +1 -2
- package/src/lib/live-reload-plugin.d.ts +8 -5
- package/src/lib/live-reload-plugin.js +45 -10
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +4 -1
- package/src/lib/ngp-compile-api.d.ts +55 -0
- package/src/lib/ngp-compile-api.js +11 -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 +680 -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 +780 -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 +13 -9
- 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 +2 -2
- 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 +14 -6
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-preprocessor.js +1 -2
- package/src/lib/stylesheet-registry.js +1 -2
- package/src/lib/stylesheet-registry.js.map +1 -1
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/utils/compilation-shared.d.ts +1 -4
- package/src/lib/utils/compilation-shared.js +9 -8
- package/src/lib/utils/compilation-shared.js.map +1 -1
- package/src/lib/utils/css-extension-resolver.js +1 -2
- package/src/lib/utils/css-preprocessor-workers.js +1 -2
- package/src/lib/utils/debug-harness.js +1 -2
- package/src/lib/utils/debug-log-file.js +1 -2
- package/src/lib/utils/debug.js +1 -2
- package/src/lib/utils/devkit.js +2 -3
- package/src/lib/utils/hmr-component-updates.d.ts +7 -0
- package/src/lib/utils/hmr-component-updates.js +86 -0
- package/src/lib/utils/hmr-component-updates.js.map +1 -0
- package/src/lib/utils/jit-inline-styles.js +1 -2
- package/src/lib/utils/lsp-type-checker.d.ts +75 -0
- package/src/lib/utils/lsp-type-checker.js +532 -0
- package/src/lib/utils/lsp-type-checker.js.map +1 -0
- package/src/lib/utils/ngp-host-fs.d.ts +43 -0
- package/src/lib/utils/ngp-host-fs.js +128 -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 +19 -7
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/rolldown.js +1 -2
- package/src/lib/utils/safe-module-paths.js +1 -2
- package/src/lib/utils/stylesheet-warning.d.ts +2 -0
- package/src/lib/utils/stylesheet-warning.js +10 -0
- package/src/lib/utils/stylesheet-warning.js.map +1 -0
- package/src/lib/utils/transform-cache.js +1 -2
- package/src/lib/utils/transform-cache.js.map +1 -1
- package/src/lib/utils/tsconfig-resolver.js +2 -3
- package/src/lib/utils/virtual-ids.js +1 -2
- package/src/lib/utils/virtual-resources.js +1 -2
- package/src/lib/utils/virtual-resources.js.map +1 -1
- package/src/lib/virtual-modules-plugin.d.ts +11 -3
- package/src/lib/virtual-modules-plugin.js +70 -15
- package/src/lib/virtual-modules-plugin.js.map +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// packages/vite-plugin-angular/src/lib/fast-compile-api.ts
|
|
2
|
+
/** Finds the fast compile plugin's API among resolved Vite plugins. */
|
|
3
|
+
function findFastCompileApi(plugins) {
|
|
4
|
+
for (const plugin of plugins) {
|
|
5
|
+
const api = plugin.api;
|
|
6
|
+
if (api?.fastCompile) return api.fastCompile;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export { findFastCompileApi };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=fast-compile-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fast-compile-api.js","names":[],"sources":["../../../src/lib/fast-compile-api.ts"],"sourcesContent":["/**\n * The fast compile path's plugin API, for Vite plugins that compile other\n * source formats into Angular components (for example `.tsrx` modules).\n *\n * Such a plugin finds the fast compile plugin by its `api.fastCompile`\n * property, lowers its modules to TypeScript, and hands the result to\n * `compile()`.\n */\n\n/** Resolves an import the way Vite's `this.resolve` does. */\nexport type FastCompileResolve = (\n specifier: string,\n importer: string,\n) => Promise<{\n id: string;\n external?: boolean | 'absolute' | 'relative';\n} | null>;\n\n/** A source format whose modules compile to Angular components. */\nexport interface FastCompileSourceFormat {\n /** Short name used in diagnostics, for example `'tsrx'`. */\n name: string;\n /** Whether a module path (without query) belongs to this format. */\n test(path: string): boolean;\n /**\n * TypeScript for registry scanning. It must declare the same Angular\n * classes, selectors, inputs and outputs as the compiled module; template\n * details may be placeholders.\n */\n toScanSource(code: string, path: string): Promise<string> | string;\n}\n\n/** A source map, as a JSON string or an object. */\nexport type SourceMapInput = string | { [key: string]: unknown };\n\nexport interface FastCompileOptions {\n /** Resolves the module's imports, usually the calling plugin's `this.resolve`. */\n resolve: FastCompileResolve;\n /**\n * Maps the compiled output's source map (which points at `code`) back to\n * the module's original source.\n */\n mapToSource?(map: SourceMapInput): { [key: string]: unknown };\n}\n\nexport interface FastCompileApi {\n /** Registers a source format so registry scans and HMR understand its modules. */\n registerSourceFormat(format: FastCompileSourceFormat): void;\n /**\n * Scans the modules behind `specifiers`, imported by `importer`, into the\n * component registry so `resolveSelector` knows their selectors. Relative\n * imports are scanned from source; packages from their `.d.ts` declarations.\n */\n scanImports(\n specifiers: string[],\n importer: string,\n resolve: FastCompileResolve,\n ): Promise<void>;\n /** The element selector of a component or directive class, if known. */\n resolveSelector(\n className: string,\n moduleSpecifier?: string,\n containingFile?: string,\n ): string | null;\n /** Compiles TypeScript produced for module `id`. */\n compile(\n code: string,\n id: string,\n options: FastCompileOptions,\n ): Promise<{ code: string; map: SourceMapInput | null } | undefined>;\n}\n\n/** Finds the fast compile plugin's API among resolved Vite plugins. */\nexport function findFastCompileApi(\n plugins: readonly { api?: unknown }[],\n): FastCompileApi | undefined {\n for (const plugin of plugins) {\n const api = plugin.api as { fastCompile?: FastCompileApi } | undefined;\n if (api?.fastCompile) {\n return api.fastCompile;\n }\n }\n return undefined;\n}\n"],"mappings":";;AAyEA,SAAgB,mBACd,SAC4B;CAC5B,KAAK,MAAM,UAAU,SAAS;EAC5B,MAAM,MAAM,OAAO;EACnB,IAAI,KAAK,aACP,OAAO,IAAI;CAEf;AAEF"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
|
+
import { type AngularBuildContext, type AngularBuildContextOptions } from "./angular-build-context.js";
|
|
3
|
+
import type { TypeCheckerOption } from "./utils/lsp-type-checker.js";
|
|
2
4
|
export interface FastCompilePluginOptions {
|
|
3
5
|
tsconfigGetter: () => string;
|
|
4
6
|
workspaceRoot: string;
|
|
@@ -8,6 +10,9 @@ export interface FastCompilePluginOptions {
|
|
|
8
10
|
isTest: boolean;
|
|
9
11
|
isAstroIntegration: boolean;
|
|
10
12
|
fastCompileMode?: "full" | "partial";
|
|
13
|
+
disableTypeChecking?: boolean;
|
|
14
|
+
typeChecker?: TypeCheckerOption;
|
|
15
|
+
include?: string[];
|
|
11
16
|
}
|
|
12
17
|
/**
|
|
13
18
|
* Directory that `compilerOptions.paths` targets resolve against. Mirrors
|
|
@@ -19,4 +24,4 @@ export declare function getPathsBasePath(options: {
|
|
|
19
24
|
baseUrl?: string;
|
|
20
25
|
pathsBasePath?: string;
|
|
21
26
|
} | undefined, fallback: string): string;
|
|
22
|
-
export declare function fastCompilePlugin(
|
|
27
|
+
export declare function fastCompilePlugin(optionsOrCtx?: AngularBuildContext | FastCompilePluginOptions | AngularBuildContextOptions): Plugin;
|
|
@@ -1,25 +1,33 @@
|
|
|
1
|
+
import { parseOxc } from "./compiler/utils.js";
|
|
2
|
+
import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
|
|
3
|
+
import "./compiler/index.js";
|
|
4
|
+
import { reportStylesheetError } from "./utils/stylesheet-warning.js";
|
|
1
5
|
import { TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
|
|
2
|
-
import {
|
|
6
|
+
import { isIgnoredHmrFile } from "./utils/compilation-shared.js";
|
|
3
7
|
import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
8
|
+
import { isRolldown } from "./utils/rolldown.js";
|
|
9
|
+
import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
|
|
10
|
+
import { ComponentScanner } from "./component-scanner.js";
|
|
6
11
|
import { ANGULAR_DECORATOR_CALL_RE } from "./compiler/constants.js";
|
|
7
|
-
import {
|
|
12
|
+
import { preprocessStylesheet } from "./stylesheet-registry.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
|
-
import "./
|
|
15
|
-
import {
|
|
20
|
+
import { discoverAnalogIntegrations } from "./analog-plugin-interop.js";
|
|
21
|
+
import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.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
|
-
|
|
22
|
-
|
|
27
|
+
// 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
|
}
|
|
@@ -78,7 +100,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
78
100
|
entries = scanFile(code, file, program);
|
|
79
101
|
scanResults?.set(file, entries);
|
|
80
102
|
}
|
|
81
|
-
|
|
103
|
+
scanner.recordFileEntries(file, entries, overwrite);
|
|
82
104
|
const dir = dirname(file);
|
|
83
105
|
for (const rel of collectRelativeReExports(code, file, program)) {
|
|
84
106
|
const normalizedRel = rel.replace(/\.(?:js|mjs)$/u, "");
|
|
@@ -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,17 +141,23 @@ 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);
|
|
119
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
file,
|
|
150
|
+
entries
|
|
151
|
+
};
|
|
120
152
|
} catch (e) {
|
|
121
153
|
if (debugRegistry.enabled) debugRegistry("initFastCompile: skipping unreadable %s: %s", file, e?.message);
|
|
122
|
-
return
|
|
154
|
+
return {
|
|
155
|
+
file,
|
|
156
|
+
entries: []
|
|
157
|
+
};
|
|
123
158
|
}
|
|
124
159
|
}));
|
|
125
|
-
for (const
|
|
160
|
+
for (const { file, entries } of results) scanner.recordFileEntries(file, entries, true);
|
|
126
161
|
const resolvePathSpecifier = (spec) => {
|
|
127
162
|
if (!tsPaths) return [];
|
|
128
163
|
for (const [key, targets] of Object.entries(tsPaths)) {
|
|
@@ -165,14 +200,14 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
165
200
|
importWalkVisited.add(file);
|
|
166
201
|
let code;
|
|
167
202
|
try {
|
|
168
|
-
code = fileContents.get(file) ?? await
|
|
203
|
+
code = fileContents.get(file) ?? await scanner.readScanSource(file);
|
|
169
204
|
fileContents.set(file, code);
|
|
170
205
|
} catch {
|
|
171
206
|
return;
|
|
172
207
|
}
|
|
173
208
|
let program;
|
|
174
209
|
try {
|
|
175
|
-
program =
|
|
210
|
+
program = parseOxc(file, code).program;
|
|
176
211
|
} catch {
|
|
177
212
|
program = void 0;
|
|
178
213
|
}
|
|
@@ -181,14 +216,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
181
216
|
entries = scanFile(code, file, program);
|
|
182
217
|
scanResults.set(file, entries);
|
|
183
218
|
}
|
|
184
|
-
|
|
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
|
-
}
|
|
219
|
+
scanner.recordFileEntries(file, entries);
|
|
220
|
+
scanner.ensureDtsRegistryForSource(code, file, program);
|
|
192
221
|
const dir = dirname(file);
|
|
193
222
|
const targets = await Promise.all(collectAllImports(code, file, program).map((spec) => {
|
|
194
223
|
if (spec.startsWith(".")) return resolveToSource(resolve(dir, spec.replace(/\.(?:js|mjs)$/u, "")));
|
|
@@ -201,7 +230,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
201
230
|
}));
|
|
202
231
|
await Promise.all(targets.filter((t) => !!t).map((t) => walkImports(t)));
|
|
203
232
|
};
|
|
204
|
-
|
|
233
|
+
const walkRoots = [.../* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes])];
|
|
234
|
+
await Promise.all(walkRoots.map((file) => walkImports(file)));
|
|
205
235
|
const buildStartVisited = /* @__PURE__ */ new Set();
|
|
206
236
|
if (tsPaths) {
|
|
207
237
|
const barrelCandidates = [];
|
|
@@ -213,17 +243,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
213
243
|
}
|
|
214
244
|
debugRegistry("initFastCompile done: %d entries from %d candidate files", registry.size, candidates.size);
|
|
215
245
|
}
|
|
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) {
|
|
246
|
+
async function handleFastCompileTransform(code, id, resolveImport) {
|
|
227
247
|
if (!ANGULAR_DECORATOR_CALL_RE.test(code)) {
|
|
228
248
|
const stripped = vite.transformWithOxc ? await vite.transformWithOxc(code, id, {
|
|
229
249
|
lang: "ts",
|
|
@@ -262,36 +282,41 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
262
282
|
}
|
|
263
283
|
const inlined = await inlineResourceUrls(code, id);
|
|
264
284
|
code = inlined.code;
|
|
265
|
-
const {
|
|
285
|
+
const { stylePaths } = inlined;
|
|
266
286
|
for (const dep of inlined.resourceDependencies) resourceToSource.set(dep, id);
|
|
267
|
-
const { program: oxcProgram } =
|
|
287
|
+
const { program: oxcProgram } = parseOxc(id, code);
|
|
268
288
|
let resolvedInlineStyles;
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
289
|
+
const styleStrings = extractInlineStyles(code, id, oxcProgram);
|
|
290
|
+
if (styleStrings.length > 0) {
|
|
291
|
+
resolvedInlineStyles = /* @__PURE__ */ new Map();
|
|
292
|
+
const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
|
|
293
|
+
const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
|
|
294
|
+
for (let i = 0; i < styleStrings.length; i++) {
|
|
295
|
+
const stylePath = stylePaths.get(i) ?? (scanner.sourceFormatOf(id) ? id + ".ts" : id).replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
|
|
296
|
+
try {
|
|
297
|
+
const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
|
|
298
|
+
filename: stylePath,
|
|
299
|
+
containingFile: id,
|
|
300
|
+
order: i,
|
|
301
|
+
inline: !stylePaths.has(i)
|
|
302
|
+
});
|
|
303
|
+
const processed = await preprocessCSS(preprocessed, stylePath, activeConfig);
|
|
304
|
+
resolvedInlineStyles.set(i, processed.code);
|
|
305
|
+
} catch (e) {
|
|
306
|
+
reportStylesheetError(activeConfig?.logger, stylePath, e, activeConfig?.command === "build");
|
|
285
307
|
}
|
|
286
|
-
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
287
308
|
}
|
|
309
|
+
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
288
310
|
}
|
|
289
|
-
ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
311
|
+
scanner.ensureDtsRegistryForSource(code, id, oxcProgram);
|
|
312
|
+
scanner.recordFileEntries(id, scanFile(code, id, oxcProgram), true);
|
|
313
|
+
await scanner.resolveImportSpecifiers(collectAllImports(code, id, oxcProgram), id, resolveImport);
|
|
314
|
+
if (declaresNonStandaloneComponent(oxcProgram)) {
|
|
315
|
+
projectScan ??= scanProject();
|
|
316
|
+
await projectScan;
|
|
294
317
|
}
|
|
318
|
+
const activeComponentRegistries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
|
|
319
|
+
const compileRegistry = buildCompileRegistry(scanner, oxcProgram, id, activeComponentRegistries);
|
|
295
320
|
const result = compile(code, id, {
|
|
296
321
|
registry: compileRegistry,
|
|
297
322
|
resolvedInlineStyles,
|
|
@@ -312,8 +337,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
312
337
|
sourcemap: true
|
|
313
338
|
}, result.map);
|
|
314
339
|
let outputCode = stripped.code;
|
|
315
|
-
if (watchMode && pluginOptions.liveReload) {
|
|
316
|
-
const fileDeclarations =
|
|
340
|
+
if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
|
|
341
|
+
const fileDeclarations = scanner.entriesOf(id);
|
|
317
342
|
if (fileDeclarations.length > 0) {
|
|
318
343
|
const localDepClassNames = fileDeclarations.map((e) => e.className);
|
|
319
344
|
outputCode += generateHmrCode(fileDeclarations, localDepClassNames);
|
|
@@ -325,17 +350,56 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
325
350
|
};
|
|
326
351
|
}
|
|
327
352
|
function resolveTsConfigPath() {
|
|
328
|
-
|
|
329
|
-
|
|
353
|
+
if (sharedCtx) return sharedCtx.resolveTsConfigPath();
|
|
354
|
+
const resolution = tsConfigResolutionContext ?? {
|
|
355
|
+
root: resolvedConfig?.root || ".",
|
|
356
|
+
isProd: isProdMode(resolvedConfig?.mode),
|
|
357
|
+
isLib: !!resolvedConfig?.build?.lib
|
|
358
|
+
};
|
|
359
|
+
return getTsConfigPath(resolution.root, pluginOptions.tsconfigGetter(), resolution.isProd, pluginOptions.isTest, resolution.isLib, pluginOptions.workspaceRoot);
|
|
330
360
|
}
|
|
361
|
+
const compilerApi = {
|
|
362
|
+
angularCompiler: true,
|
|
363
|
+
getTsConfigPath: resolveTsConfigPath,
|
|
364
|
+
getSourceMap: (id) => emittedMaps.get(normalizePath(id)),
|
|
365
|
+
hasEmitted: (id) => emittedMaps.has(normalizePath(id)),
|
|
366
|
+
fastCompile: {
|
|
367
|
+
registerSourceFormat: (format) => scanner.registerSourceFormat(format),
|
|
368
|
+
scanImports: (specifiers, importer, resolve) => scanner.scanImports(specifiers, importer, resolve),
|
|
369
|
+
resolveSelector: (className, moduleSpecifier, containingFile) => scanner.lookupSelector(className, sharedCtx ? sharedCtx.componentRegistries : componentRegistries, moduleSpecifier !== void 0 && containingFile !== void 0 ? {
|
|
370
|
+
moduleSpecifier,
|
|
371
|
+
containingFile
|
|
372
|
+
} : void 0),
|
|
373
|
+
async compile(code, id, { resolve, mapToSource }) {
|
|
374
|
+
const transformed = await handleFastCompileTransform(code, id, scanner.toResolveImport(resolve));
|
|
375
|
+
if (!transformed) return;
|
|
376
|
+
const map = transformed.map && mapToSource ? mapToSource(transformed.map) : transformed.map ?? null;
|
|
377
|
+
if (map) emittedMaps.set(normalizePath(id), typeof map === "string" ? map : JSON.stringify(map));
|
|
378
|
+
return {
|
|
379
|
+
code: transformed.code,
|
|
380
|
+
map
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
sharedCtx?.registerCompiler({
|
|
386
|
+
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
387
|
+
getTsConfigPath: compilerApi.getTsConfigPath,
|
|
388
|
+
getSourceMap: compilerApi.getSourceMap,
|
|
389
|
+
hasEmitted: compilerApi.hasEmitted
|
|
390
|
+
});
|
|
331
391
|
return {
|
|
332
392
|
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
333
|
-
api:
|
|
393
|
+
api: compilerApi,
|
|
334
394
|
enforce: "pre",
|
|
335
|
-
async config(config, { command }) {
|
|
395
|
+
async config(config, { command, mode }) {
|
|
336
396
|
watchMode = command === "serve";
|
|
337
397
|
const isProd = isProdMode(config.mode);
|
|
338
|
-
|
|
398
|
+
if (sharedCtx) sharedCtx.initConfig(config, {
|
|
399
|
+
command,
|
|
400
|
+
mode
|
|
401
|
+
});
|
|
402
|
+
else tsConfigResolutionContext = {
|
|
339
403
|
root: config.root || ".",
|
|
340
404
|
isProd,
|
|
341
405
|
isLib: !!config?.build?.lib
|
|
@@ -350,64 +414,61 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
350
414
|
isAstroIntegration: pluginOptions.isAstroIntegration
|
|
351
415
|
});
|
|
352
416
|
return {
|
|
353
|
-
...
|
|
417
|
+
...isRolldown() ? { oxc: {} } : { esbuild: false },
|
|
354
418
|
...depOptimizer
|
|
355
419
|
};
|
|
356
420
|
},
|
|
357
421
|
async configResolved(config) {
|
|
358
422
|
resolvedConfig = config;
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
423
|
+
if (sharedCtx) {
|
|
424
|
+
const integrations = await sharedCtx.resolveConfig(config);
|
|
425
|
+
transformFilter = integrations.transformFilter;
|
|
426
|
+
componentRegistries = integrations.componentRegistries;
|
|
427
|
+
stylePreprocessor = integrations.stylePreprocessor;
|
|
428
|
+
} else {
|
|
429
|
+
const integrations = await discoverAnalogIntegrations(config);
|
|
430
|
+
transformFilter = integrations.transformFilter;
|
|
431
|
+
componentRegistries = integrations.componentRegistries;
|
|
432
|
+
stylePreprocessor = integrations.stylePreprocessor;
|
|
433
|
+
tsconfigResolver.setIntegrationIncludes(integrations.include);
|
|
434
|
+
}
|
|
367
435
|
},
|
|
368
436
|
async buildStart() {
|
|
369
437
|
await initFastCompile();
|
|
370
438
|
},
|
|
371
439
|
closeBundle() {
|
|
372
|
-
if (!watchMode)
|
|
440
|
+
if (!(sharedCtx ? sharedCtx.watchMode : watchMode)) {
|
|
441
|
+
emittedMaps.clear();
|
|
442
|
+
releaseCssPreprocessorWorkers();
|
|
443
|
+
}
|
|
373
444
|
},
|
|
374
445
|
async handleHotUpdate(ctx) {
|
|
446
|
+
if (sharedCtx ? sharedCtx.hmr.isIgnoredFile(ctx.file) : isIgnoredHmrFile(ctx.file)) return [];
|
|
375
447
|
if (resourceToSource.has(ctx.file)) {
|
|
376
448
|
const parentSource = resourceToSource.get(ctx.file);
|
|
377
449
|
const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
|
|
378
450
|
if (parentModule) return [parentModule];
|
|
379
451
|
}
|
|
380
|
-
if (
|
|
452
|
+
if (scanner.isCompiledSource(ctx.file)) {
|
|
381
453
|
const [fileId] = ctx.file.split("?");
|
|
382
|
-
const oldEntries =
|
|
383
|
-
|
|
454
|
+
const oldEntries = scanner.entriesOf(fileId);
|
|
455
|
+
scanner.invalidate(fileId);
|
|
384
456
|
await scanBarrelExports(fileId, /* @__PURE__ */ new Set(), true);
|
|
457
|
+
if (JSON.stringify(oldEntries) !== JSON.stringify(scanner.entriesOf(fileId))) {
|
|
458
|
+
const importerModules = [...scanner.importersByFile.get(fileId) ?? []].flatMap((importer) => [...ctx.server.moduleGraph.getModulesByFile(importer) ?? []]);
|
|
459
|
+
return [...ctx.modules, ...importerModules];
|
|
460
|
+
}
|
|
385
461
|
}
|
|
386
462
|
return ctx.modules;
|
|
387
463
|
},
|
|
388
464
|
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
|
-
}
|
|
465
|
+
return resolveAngularVirtualId(id, importer, {
|
|
466
|
+
jit: pluginOptions.jit,
|
|
467
|
+
resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig
|
|
468
|
+
});
|
|
406
469
|
},
|
|
407
470
|
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]);
|
|
471
|
+
return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? resolvedConfig);
|
|
411
472
|
},
|
|
412
473
|
transform: {
|
|
413
474
|
filter: { id: {
|
|
@@ -420,14 +481,58 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
420
481
|
]
|
|
421
482
|
} },
|
|
422
483
|
async handler(code, id) {
|
|
423
|
-
|
|
484
|
+
const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
|
|
485
|
+
if (activeTransformFilter && !activeTransformFilter(code, id)) return;
|
|
424
486
|
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
425
|
-
|
|
487
|
+
const resolveImport = scanner.toResolveImport((spec, importer) => this.resolve(spec, importer, { skipSelf: true }));
|
|
488
|
+
const transformed = await handleFastCompileTransform(code, id, resolveImport);
|
|
489
|
+
if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
|
|
490
|
+
return transformed;
|
|
426
491
|
}
|
|
427
492
|
}
|
|
428
493
|
};
|
|
429
494
|
}
|
|
430
|
-
|
|
495
|
+
/**
|
|
496
|
+
* Builds the registry view for compiling `id`, overlaying external registries,
|
|
497
|
+
* this file's value import bindings (including aliases, default imports, and
|
|
498
|
+
* same-named components from distinct modules), and declarations from `id`
|
|
499
|
+
* itself. Reuses `scanner.registry` directly when no overrides apply.
|
|
500
|
+
*/
|
|
501
|
+
function buildCompileRegistry(scanner, program, id, externalRegistries) {
|
|
502
|
+
let compileRegistry = scanner.registry;
|
|
503
|
+
const ensureOverlay = () => {
|
|
504
|
+
if (compileRegistry === scanner.registry) compileRegistry = new Map(scanner.registry);
|
|
505
|
+
return compileRegistry;
|
|
506
|
+
};
|
|
507
|
+
if (externalRegistries.some((external) => external.size > 0)) {
|
|
508
|
+
const overlay = ensureOverlay();
|
|
509
|
+
for (const external of externalRegistries) for (const [k, v] of external) overlay.set(k, v);
|
|
510
|
+
}
|
|
511
|
+
for (const stmt of program.body || []) {
|
|
512
|
+
if (stmt.type !== "ImportDeclaration" || stmt.importKind === "type" || !stmt.source?.value) continue;
|
|
513
|
+
const moduleSpecifier = stmt.source.value;
|
|
514
|
+
for (const spec of stmt.specifiers || []) {
|
|
515
|
+
if (spec.importKind === "type") continue;
|
|
516
|
+
let importedName;
|
|
517
|
+
let localName;
|
|
518
|
+
if (spec.type === "ImportDefaultSpecifier") {
|
|
519
|
+
importedName = "default";
|
|
520
|
+
localName = spec.local?.name;
|
|
521
|
+
} else if (spec.type === "ImportSpecifier") {
|
|
522
|
+
importedName = spec.imported?.type === "Identifier" ? spec.imported.name : typeof spec.imported?.value === "string" ? spec.imported.value : void 0;
|
|
523
|
+
localName = spec.local?.name;
|
|
524
|
+
}
|
|
525
|
+
if (!importedName || !localName) continue;
|
|
526
|
+
const entry = scanner.lookupEntry(importedName, externalRegistries, {
|
|
527
|
+
moduleSpecifier,
|
|
528
|
+
containingFile: id
|
|
529
|
+
});
|
|
530
|
+
if (entry && compileRegistry.get(localName) !== entry) ensureOverlay().set(localName, entry);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
for (const localEntry of scanner.entriesOf(id)) if (compileRegistry.get(localEntry.className) !== localEntry) ensureOverlay().set(localEntry.className, localEntry);
|
|
534
|
+
return compileRegistry;
|
|
535
|
+
}
|
|
431
536
|
export { fastCompilePlugin, getPathsBasePath };
|
|
432
537
|
|
|
433
538
|
//# sourceMappingURL=fast-compile-plugin.js.map
|