@analogjs/vite-plugin-angular 3.0.0-beta.4 → 3.0.0-beta.40
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
|
@@ -0,0 +1,763 @@
|
|
|
1
|
+
import { activateDeferredDebug, debugCompiler, debugCompilerV, debugEmit, debugEmitV, debugHmr, debugHmrV, debugStyles } from "./utils/debug.js";
|
|
2
|
+
import { isComponentStyleSheet } from "./encapsulation-plugin.js";
|
|
3
|
+
import { describeStylesheetContent, injectViteIgnoreForHmrMetadata } from "./utils/compilation-shared.js";
|
|
4
|
+
import { SourceFileCache, createJitResourceTransformer } from "./utils/devkit.js";
|
|
5
|
+
import { getJsTransformConfigKey } from "./utils/rolldown.js";
|
|
6
|
+
import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createDepOptimizerConfig } from "./utils/plugin-config.js";
|
|
7
|
+
import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
|
|
8
|
+
import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
|
|
9
|
+
import { toJitInlineStyleId } from "./utils/jit-inline-styles.js";
|
|
10
|
+
import { findTemplateOwnerModules, getModulesForChangedFile, handleDirectComponentStyleHmr, isModuleForChangedResource, markModuleSelfAccepting } from "./component-styles-plugin.js";
|
|
11
|
+
import { markStylePathSafe } from "./utils/safe-module-paths.js";
|
|
12
|
+
import { toVirtualRawId } from "./utils/virtual-ids.js";
|
|
13
|
+
import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
|
|
14
|
+
import { createHotUpdateBatcher } from "./hot-update-batch.js";
|
|
15
|
+
import { StyleUrlsResolver, TemplateUrlsResolver } from "./component-resolvers.js";
|
|
16
|
+
import { augmentHostWithCaching, augmentHostWithModuleResolution, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers } from "./host.js";
|
|
17
|
+
import { union } from "es-toolkit";
|
|
18
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
19
|
+
import { createRequire } from "node:module";
|
|
20
|
+
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
21
|
+
import { normalizePath, preprocessCSS } from "vite";
|
|
22
|
+
import * as compilerCli from "@angular/compiler-cli";
|
|
23
|
+
//#region packages/vite-plugin-angular/src/lib/ngtsc-compile-plugin.ts
|
|
24
|
+
var require = createRequire(import.meta.url);
|
|
25
|
+
function evictDeletedFileMetadata(file, { classNamesMap, fileTransformMap }) {
|
|
26
|
+
const normalizedFile = normalizePath(file.split("?")[0]);
|
|
27
|
+
classNamesMap.delete(normalizedFile);
|
|
28
|
+
fileTransformMap.delete(normalizedFile);
|
|
29
|
+
}
|
|
30
|
+
function createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, performCompilation) {
|
|
31
|
+
return async () => {
|
|
32
|
+
invalidateFsCaches();
|
|
33
|
+
invalidateTsconfigCaches();
|
|
34
|
+
await performCompilation();
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Compiles Angular TypeScript sources using `@angular/compiler-cli` (`NgtscProgram`).
|
|
39
|
+
*/
|
|
40
|
+
function ngtscCompilePlugin(ctxOrOptions) {
|
|
41
|
+
const ctx = isAngularBuildContext(ctxOrOptions) ? ctxOrOptions : createAngularBuildContext({
|
|
42
|
+
...ctxOrOptions,
|
|
43
|
+
compilationBackend: "ngtsc"
|
|
44
|
+
});
|
|
45
|
+
const ts = require("typescript");
|
|
46
|
+
let cachedBuilder;
|
|
47
|
+
let nextProgram;
|
|
48
|
+
let cachedHost;
|
|
49
|
+
let cachedHostKey;
|
|
50
|
+
function invalidateFsCaches() {
|
|
51
|
+
ctx.tsconfigResolver.invalidateIncludeCache();
|
|
52
|
+
}
|
|
53
|
+
function invalidateTsconfigCaches() {
|
|
54
|
+
ctx.tsconfigResolver.invalidateTsconfigCaches();
|
|
55
|
+
cachedHost = void 0;
|
|
56
|
+
cachedHostKey = void 0;
|
|
57
|
+
}
|
|
58
|
+
const sourceFileCache = new SourceFileCache();
|
|
59
|
+
const tsSourceFileCache = /* @__PURE__ */ new Map();
|
|
60
|
+
function invalidateSourceFiles(files) {
|
|
61
|
+
for (const file of files) tsSourceFileCache.delete(normalizePath(file));
|
|
62
|
+
sourceFileCache.invalidate(files);
|
|
63
|
+
}
|
|
64
|
+
const { jit, isTest } = ctx.options;
|
|
65
|
+
let viteServer;
|
|
66
|
+
const styleUrlsResolver = new StyleUrlsResolver();
|
|
67
|
+
const templateUrlsResolver = new TemplateUrlsResolver();
|
|
68
|
+
let outputFile;
|
|
69
|
+
const outputFiles = /* @__PURE__ */ new Map();
|
|
70
|
+
const normalizeEmitterLookupId = (file) => {
|
|
71
|
+
const normalizedFile = normalizePath(file);
|
|
72
|
+
if (!normalizedFile.startsWith("/@fs/")) return normalizedFile;
|
|
73
|
+
const fsPath = normalizedFile.slice(4).replace(/^\/([A-Za-z]:\/)/, "$1");
|
|
74
|
+
return normalizePath(fsPath);
|
|
75
|
+
};
|
|
76
|
+
const describeEmitMarkers = (content) => ({
|
|
77
|
+
contentLength: content.length,
|
|
78
|
+
hasCmp: content.includes("ɵcmp"),
|
|
79
|
+
hasFac: content.includes("ɵfac"),
|
|
80
|
+
hasProv: content.includes("ɵprov"),
|
|
81
|
+
hasDecorate: content.includes("__decorate"),
|
|
82
|
+
hasMetadata: content.includes("__metadata")
|
|
83
|
+
});
|
|
84
|
+
const fileEmitter = (file) => {
|
|
85
|
+
const normalizedFile = normalizeEmitterLookupId(file);
|
|
86
|
+
const hadCachedEmit = outputFiles.has(normalizedFile);
|
|
87
|
+
outputFile?.(normalizedFile);
|
|
88
|
+
const emittedResult = outputFiles.get(normalizedFile);
|
|
89
|
+
debugEmitV("fileEmitter lookup", {
|
|
90
|
+
requestFile: file,
|
|
91
|
+
normalizedFile,
|
|
92
|
+
hadCachedEmit,
|
|
93
|
+
hasOutputFileHook: !!outputFile,
|
|
94
|
+
emitted: !!emittedResult,
|
|
95
|
+
knownOutputCount: outputFiles.size,
|
|
96
|
+
contentLength: emittedResult?.content?.length ?? 0,
|
|
97
|
+
errorCount: emittedResult?.errors?.length ?? 0,
|
|
98
|
+
warningCount: emittedResult?.warnings?.length ?? 0
|
|
99
|
+
});
|
|
100
|
+
return emittedResult;
|
|
101
|
+
};
|
|
102
|
+
ctx.hmr.setFileEmitter((file) => fileEmitter(file));
|
|
103
|
+
const compilerApi = {
|
|
104
|
+
angularCompiler: true,
|
|
105
|
+
getTsConfigPath: () => ctx.resolveTsConfigPath(),
|
|
106
|
+
getSourceMap: (id) => outputFiles.get(normalizeEmitterLookupId(id))?.map,
|
|
107
|
+
hasEmitted: (id) => outputFiles.has(normalizeEmitterLookupId(id))
|
|
108
|
+
};
|
|
109
|
+
ctx.registerCompiler({
|
|
110
|
+
name: "@analogjs/vite-plugin-angular",
|
|
111
|
+
getTsConfigPath: compilerApi.getTsConfigPath,
|
|
112
|
+
getSourceMap: compilerApi.getSourceMap,
|
|
113
|
+
hasEmitted: compilerApi.hasEmitted
|
|
114
|
+
});
|
|
115
|
+
let initialCompilation = false;
|
|
116
|
+
let activeBuilds = 0;
|
|
117
|
+
let closeRequested = false;
|
|
118
|
+
const declarationFiles = [];
|
|
119
|
+
const fileTransformMap = /* @__PURE__ */ new Map();
|
|
120
|
+
let styleTransform;
|
|
121
|
+
let pendingCompilation = null;
|
|
122
|
+
let compilationLock = Promise.resolve();
|
|
123
|
+
const hotUpdates = createHotUpdateBatcher((ids) => performCompilation(ctx.resolvedConfig, ids));
|
|
124
|
+
function releaseCompilation() {
|
|
125
|
+
cachedBuilder = void 0;
|
|
126
|
+
nextProgram = void 0;
|
|
127
|
+
cachedHost = void 0;
|
|
128
|
+
cachedHostKey = void 0;
|
|
129
|
+
outputFile = void 0;
|
|
130
|
+
outputFiles.clear();
|
|
131
|
+
fileTransformMap.clear();
|
|
132
|
+
tsSourceFileCache.clear();
|
|
133
|
+
sourceFileCache.clear();
|
|
134
|
+
sourceFileCache.modifiedFiles.clear();
|
|
135
|
+
sourceFileCache.babelFileCache?.clear();
|
|
136
|
+
sourceFileCache.typeScriptFileCache?.clear();
|
|
137
|
+
sourceFileCache.referencedFiles = void 0;
|
|
138
|
+
ctx.tsconfigResolver.invalidateAll();
|
|
139
|
+
releaseCssPreprocessorWorkers();
|
|
140
|
+
ctx.styles.clear();
|
|
141
|
+
}
|
|
142
|
+
async function closeCompilation() {
|
|
143
|
+
closeRequested = false;
|
|
144
|
+
hotUpdates.close();
|
|
145
|
+
await compilationLock;
|
|
146
|
+
declarationFiles.forEach(({ declarationFileDir, declarationPath, data }) => {
|
|
147
|
+
mkdirSync(declarationFileDir, { recursive: true });
|
|
148
|
+
writeFileSync(declarationPath, data, "utf-8");
|
|
149
|
+
});
|
|
150
|
+
declarationFiles.length = 0;
|
|
151
|
+
releaseCompilation();
|
|
152
|
+
}
|
|
153
|
+
function normalizeSourceMapSources(map, id) {
|
|
154
|
+
const sourceMap = JSON.parse(map);
|
|
155
|
+
const sourceDirectory = dirname(id);
|
|
156
|
+
const sourceRoot = sourceMap.sourceRoot ?? "";
|
|
157
|
+
sourceMap.sources = sourceMap.sources?.map((source) => {
|
|
158
|
+
if (isAbsolute(source) || /^[a-z][a-z\d+.-]*:/i.test(source)) return normalizePath(source);
|
|
159
|
+
return normalizePath(resolve(sourceDirectory, sourceRoot, source));
|
|
160
|
+
});
|
|
161
|
+
delete sourceMap.sourceRoot;
|
|
162
|
+
return JSON.stringify(sourceMap);
|
|
163
|
+
}
|
|
164
|
+
async function performCompilation(config, ids) {
|
|
165
|
+
let releaseLock;
|
|
166
|
+
const previousLock = compilationLock;
|
|
167
|
+
compilationLock = new Promise((r) => {
|
|
168
|
+
releaseLock = r;
|
|
169
|
+
});
|
|
170
|
+
try {
|
|
171
|
+
await previousLock;
|
|
172
|
+
await ctx.refreshIntegrations(config);
|
|
173
|
+
await _doPerformCompilation(config, ids);
|
|
174
|
+
} finally {
|
|
175
|
+
releaseLock();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* This method shares mutable state and performs the actual compilation work.
|
|
180
|
+
* It should not be called concurrently. Use `performCompilation` which wraps
|
|
181
|
+
* this method in a lock to ensure only one compilation runs at a time.
|
|
182
|
+
*/
|
|
183
|
+
async function _doPerformCompilation(config, ids) {
|
|
184
|
+
const isProd = config.mode === "production";
|
|
185
|
+
invalidateSourceFiles(new Set(ids ?? []));
|
|
186
|
+
if (ids?.length) for (const id of ids) fileTransformMap.delete(id);
|
|
187
|
+
const resolvedTsConfigPath = ctx.resolveTsConfigPath();
|
|
188
|
+
const cached = ctx.tsconfigResolver.getCachedTsconfigOptions(resolvedTsConfigPath, config);
|
|
189
|
+
const tsCompilerOptions = { ...cached.options };
|
|
190
|
+
let rootNames = [...cached.rootNames];
|
|
191
|
+
if (ctx.shouldExternalizeStyles()) tsCompilerOptions["externalRuntimeStyles"] = true;
|
|
192
|
+
if (ctx.shouldEnableLiveReload()) {
|
|
193
|
+
tsCompilerOptions["_enableHmr"] = true;
|
|
194
|
+
tsCompilerOptions["supportTestBed"] = true;
|
|
195
|
+
}
|
|
196
|
+
debugCompiler("tsCompilerOptions (NgtscProgram path)", {
|
|
197
|
+
liveReload: ctx.options.liveReload,
|
|
198
|
+
viteHmr: ctx.hasViteHmrTransport(),
|
|
199
|
+
externalizeStylesRequested: ctx.externalizeStylesRequested,
|
|
200
|
+
shouldExternalize: ctx.shouldExternalizeStyles(),
|
|
201
|
+
externalRuntimeStyles: !!tsCompilerOptions["externalRuntimeStyles"],
|
|
202
|
+
hmrEnabled: !!tsCompilerOptions["_enableHmr"]
|
|
203
|
+
});
|
|
204
|
+
if (tsCompilerOptions["compilationMode"] === "partial") {
|
|
205
|
+
tsCompilerOptions["supportTestBed"] = true;
|
|
206
|
+
tsCompilerOptions["supportJitMode"] = true;
|
|
207
|
+
}
|
|
208
|
+
if (!isTest && config.build?.lib) {
|
|
209
|
+
tsCompilerOptions["declaration"] = true;
|
|
210
|
+
tsCompilerOptions["declarationMap"] = ctx.watchMode;
|
|
211
|
+
tsCompilerOptions["inlineSources"] = true;
|
|
212
|
+
}
|
|
213
|
+
if (isTest) tsCompilerOptions["supportTestBed"] = true;
|
|
214
|
+
const replacements = ctx.options.fileReplacements.map((rp) => join(ctx.options.workspaceRoot, rp.ssr || rp.with));
|
|
215
|
+
rootNames = union(union(rootNames, ctx.tsconfigResolver.ensureIncludeCache()), replacements);
|
|
216
|
+
const hostKey = JSON.stringify(tsCompilerOptions);
|
|
217
|
+
let host;
|
|
218
|
+
if (cachedHost && cachedHostKey === hostKey) host = cachedHost;
|
|
219
|
+
else {
|
|
220
|
+
host = ts.createIncrementalCompilerHost(tsCompilerOptions, {
|
|
221
|
+
...ts.sys,
|
|
222
|
+
readFile(path, encoding) {
|
|
223
|
+
if (fileTransformMap.has(path)) return fileTransformMap.get(path);
|
|
224
|
+
const file = ts.sys.readFile.call(null, path, encoding);
|
|
225
|
+
if (file) fileTransformMap.set(path, file);
|
|
226
|
+
return file;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
augmentHostWithModuleResolution(host, tsCompilerOptions);
|
|
230
|
+
cachedHost = host;
|
|
231
|
+
cachedHostKey = hostKey;
|
|
232
|
+
if (ctx.watchMode) augmentHostWithCaching(host, tsSourceFileCache);
|
|
233
|
+
}
|
|
234
|
+
if (!jit) {
|
|
235
|
+
const externalizeStyles = !!tsCompilerOptions["externalRuntimeStyles"];
|
|
236
|
+
const stylesheetRegistry = ctx.styles.resetRegistry(externalizeStyles);
|
|
237
|
+
debugStyles("stylesheet registry initialized (NgtscProgram path)", { externalizeStyles });
|
|
238
|
+
augmentHostWithResources(host, styleTransform, {
|
|
239
|
+
inlineStylesExtension: ctx.options.inlineStylesExtension,
|
|
240
|
+
isProd,
|
|
241
|
+
stylesheetRegistry,
|
|
242
|
+
sourceFileCache,
|
|
243
|
+
stylePreprocessor: ctx.stylePreprocessor,
|
|
244
|
+
logger: ctx.resolvedConfig?.logger,
|
|
245
|
+
isBuild: ctx.resolvedConfig?.command === "build"
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new NgtscProgram to analyze/re-analyze
|
|
250
|
+
* the source files and create a file emitter.
|
|
251
|
+
* This is shared between an initial build and a hot update.
|
|
252
|
+
*/
|
|
253
|
+
let typeScriptProgram;
|
|
254
|
+
let angularCompiler;
|
|
255
|
+
let builder;
|
|
256
|
+
const oldBuilder = ids?.some((id) => EXCLUDED_TS_EXT_REGEX.test(id)) ? void 0 : cachedBuilder ?? ts.readBuilderProgram(tsCompilerOptions, host);
|
|
257
|
+
if (!jit) {
|
|
258
|
+
const angularProgram = new compilerCli.NgtscProgram(rootNames, tsCompilerOptions, host, nextProgram);
|
|
259
|
+
angularCompiler = angularProgram.compiler;
|
|
260
|
+
typeScriptProgram = angularProgram.compiler.getCurrentProgram();
|
|
261
|
+
augmentProgramWithVersioning(typeScriptProgram);
|
|
262
|
+
builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(typeScriptProgram, host, oldBuilder);
|
|
263
|
+
nextProgram = angularProgram;
|
|
264
|
+
} else {
|
|
265
|
+
builder = ts.createEmitAndSemanticDiagnosticsBuilderProgram(rootNames, tsCompilerOptions, host, oldBuilder);
|
|
266
|
+
typeScriptProgram = builder.getProgram();
|
|
267
|
+
}
|
|
268
|
+
if (!ctx.watchMode) builder = ts.createAbstractBuilder(typeScriptProgram, host, oldBuilder);
|
|
269
|
+
cachedBuilder = builder;
|
|
270
|
+
if (angularCompiler) {
|
|
271
|
+
await angularCompiler.analyzeAsync();
|
|
272
|
+
if (!ctx.options.disableTypeChecking) typeScriptProgram.getOptionsDiagnostics();
|
|
273
|
+
}
|
|
274
|
+
const beforeTransformers = jit ? [compilerCli.constructorParametersDownlevelTransform(builder.getProgram()), createJitResourceTransformer(() => builder.getProgram().getTypeChecker())] : [];
|
|
275
|
+
const transformers = mergeTransformers({ before: beforeTransformers }, jit ? {} : angularCompiler.prepareEmit().transformers);
|
|
276
|
+
const fileMetadata = getFileMetadata(builder, angularCompiler, ctx.options.liveReload, ctx.options.disableTypeChecking, ctx.hmr.classNames);
|
|
277
|
+
const writeFileCallback = (_filename, content, _a, _b, sourceFiles) => {
|
|
278
|
+
if (!sourceFiles?.length) return;
|
|
279
|
+
const filename = normalizePath(sourceFiles[0].fileName);
|
|
280
|
+
if (filename.includes("ngtypecheck.ts") || filename.includes(".d.") || _filename.endsWith(".d.ts") || _filename.endsWith(".d.mts") || _filename.endsWith(".d.cts")) return;
|
|
281
|
+
if (/\.[cm]?js\.map$/.test(_filename)) {
|
|
282
|
+
const existing = outputFiles.get(filename);
|
|
283
|
+
outputFiles.set(filename, {
|
|
284
|
+
...existing ?? { dependencies: [] },
|
|
285
|
+
map: content
|
|
286
|
+
});
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const metadata = ctx.watchMode ? fileMetadata(filename) : {};
|
|
290
|
+
const existing = outputFiles.get(filename);
|
|
291
|
+
outputFiles.set(filename, {
|
|
292
|
+
...existing ?? {},
|
|
293
|
+
content,
|
|
294
|
+
dependencies: [],
|
|
295
|
+
errors: metadata.errors,
|
|
296
|
+
warnings: metadata.warnings,
|
|
297
|
+
hmrUpdateCode: metadata.hmrUpdateCode,
|
|
298
|
+
hmrEligible: metadata.hmrEligible
|
|
299
|
+
});
|
|
300
|
+
debugEmitV("registered ngtsc output", {
|
|
301
|
+
filename,
|
|
302
|
+
...describeEmitMarkers(content),
|
|
303
|
+
errorCount: metadata.errors?.length ?? 0,
|
|
304
|
+
warningCount: metadata.warnings?.length ?? 0,
|
|
305
|
+
hmrEligible: !!metadata.hmrEligible,
|
|
306
|
+
knownOutputCount: outputFiles.size
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
const writeOutputFile = (id) => {
|
|
310
|
+
const sourceFile = builder.getSourceFile(id);
|
|
311
|
+
if (!sourceFile) return;
|
|
312
|
+
let content = "";
|
|
313
|
+
let map;
|
|
314
|
+
let mapFilename;
|
|
315
|
+
builder.emit(sourceFile, (filename, data) => {
|
|
316
|
+
if (/\.[cm]?js$/.test(filename)) content = data;
|
|
317
|
+
if (/\.[cm]?js\.map$/.test(filename)) {
|
|
318
|
+
map = data;
|
|
319
|
+
mapFilename = filename;
|
|
320
|
+
}
|
|
321
|
+
if (!ctx.watchMode && !isTest && /\.d\.ts/.test(filename) && !filename.includes(".ngtypecheck.")) {
|
|
322
|
+
const declarationPath = resolve(config.root, config.build.outDir, relative(config.root, filename)).replace("/src/", "/");
|
|
323
|
+
const declarationFileDir = declarationPath.replace(basename(filename), "").replace("/src/", "/");
|
|
324
|
+
declarationFiles.push({
|
|
325
|
+
declarationFileDir,
|
|
326
|
+
declarationPath,
|
|
327
|
+
data
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
}, void 0, void 0, transformers);
|
|
331
|
+
writeFileCallback(id, content, false, void 0, [sourceFile]);
|
|
332
|
+
if (map !== void 0 && mapFilename !== void 0) writeFileCallback(mapFilename, map, false, void 0, [sourceFile]);
|
|
333
|
+
if (angularCompiler) angularCompiler.incrementalCompilation.recordSuccessfulEmit(sourceFile);
|
|
334
|
+
};
|
|
335
|
+
if (ctx.watchMode) {
|
|
336
|
+
if (ids && ids.length > 0) ids.forEach((id) => writeOutputFile(id));
|
|
337
|
+
else if (isTest)
|
|
338
|
+
/**
|
|
339
|
+
* Only block the server from starting up
|
|
340
|
+
* during testing.
|
|
341
|
+
*/
|
|
342
|
+
while (builder.emitNextAffectedFile(writeFileCallback, void 0, void 0, transformers));
|
|
343
|
+
}
|
|
344
|
+
if (!isTest)
|
|
345
|
+
/**
|
|
346
|
+
* Perf: Output files on demand so the dev server
|
|
347
|
+
* isn't blocked when emitting files.
|
|
348
|
+
*/
|
|
349
|
+
outputFile = writeOutputFile;
|
|
350
|
+
}
|
|
351
|
+
return {
|
|
352
|
+
name: "@analogjs/vite-plugin-angular",
|
|
353
|
+
api: compilerApi,
|
|
354
|
+
async config(config, { command, mode }) {
|
|
355
|
+
activateDeferredDebug(command);
|
|
356
|
+
const resolution = ctx.initConfig(config, {
|
|
357
|
+
command,
|
|
358
|
+
mode
|
|
359
|
+
});
|
|
360
|
+
const preliminaryTsConfigPath = ctx.resolveTsConfigPath();
|
|
361
|
+
const esbuild = config.esbuild ?? false;
|
|
362
|
+
const oxc = config.oxc ?? false;
|
|
363
|
+
const jsTransformConfigKey = getJsTransformConfigKey();
|
|
364
|
+
const jsTransformConfigValue = jsTransformConfigKey === "oxc" ? oxc : esbuild;
|
|
365
|
+
const depOptimizer = createDepOptimizerConfig({
|
|
366
|
+
tsconfig: preliminaryTsConfigPath,
|
|
367
|
+
isProd: resolution.isProd,
|
|
368
|
+
jit: ctx.options.jit,
|
|
369
|
+
watchMode: ctx.watchMode,
|
|
370
|
+
isTest: ctx.options.isTest,
|
|
371
|
+
isAstroIntegration: ctx.options.isAstroIntegration
|
|
372
|
+
});
|
|
373
|
+
return {
|
|
374
|
+
[jsTransformConfigKey]: jsTransformConfigValue,
|
|
375
|
+
...depOptimizer
|
|
376
|
+
};
|
|
377
|
+
},
|
|
378
|
+
configResolved(config) {
|
|
379
|
+
ctx.setResolvedConfig(config);
|
|
380
|
+
if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, config);
|
|
381
|
+
},
|
|
382
|
+
configureServer(server) {
|
|
383
|
+
viteServer = server;
|
|
384
|
+
hotUpdates.configureServer(server);
|
|
385
|
+
const invalidateCompilationOnFsChange = createFsWatcherCacheInvalidator(invalidateFsCaches, invalidateTsconfigCaches, () => performCompilation(ctx.resolvedConfig));
|
|
386
|
+
server.watcher.on("add", (file) => {
|
|
387
|
+
if (EXCLUDED_TS_EXT_REGEX.test(file)) invalidateSourceFiles(/* @__PURE__ */ new Set([normalizePath(file)]));
|
|
388
|
+
return invalidateCompilationOnFsChange();
|
|
389
|
+
});
|
|
390
|
+
server.watcher.on("unlink", (file) => {
|
|
391
|
+
const id = normalizePath(file);
|
|
392
|
+
outputFiles.delete(id);
|
|
393
|
+
tsSourceFileCache.delete(id);
|
|
394
|
+
sourceFileCache.invalidate(/* @__PURE__ */ new Set([id]));
|
|
395
|
+
evictDeletedFileMetadata(file, {
|
|
396
|
+
classNamesMap: ctx.hmr.classNames,
|
|
397
|
+
fileTransformMap
|
|
398
|
+
});
|
|
399
|
+
return invalidateCompilationOnFsChange();
|
|
400
|
+
});
|
|
401
|
+
server.watcher.on("change", (file) => {
|
|
402
|
+
if (file.includes("tsconfig")) invalidateTsconfigCaches();
|
|
403
|
+
});
|
|
404
|
+
},
|
|
405
|
+
async buildStart() {
|
|
406
|
+
activeBuilds++;
|
|
407
|
+
if (!jit) styleTransform = (code, filename) => preprocessCSS(code, filename, ctx.resolvedConfig);
|
|
408
|
+
if (!ctx.deferInitialCompilation) {
|
|
409
|
+
pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig);
|
|
410
|
+
await pendingCompilation;
|
|
411
|
+
pendingCompilation = null;
|
|
412
|
+
initialCompilation = true;
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
async buildEnd() {
|
|
416
|
+
activeBuilds = Math.max(0, activeBuilds - 1);
|
|
417
|
+
if (activeBuilds > 0) return;
|
|
418
|
+
if (closeRequested) {
|
|
419
|
+
await closeCompilation();
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
if (!ctx.watchMode) releaseCompilation();
|
|
423
|
+
},
|
|
424
|
+
async handleHotUpdate(hmrCtx) {
|
|
425
|
+
if (ctx.hmr.isIgnoredFile(hmrCtx.file)) {
|
|
426
|
+
debugHmr("ignored file change", { file: hmrCtx.file });
|
|
427
|
+
return [];
|
|
428
|
+
}
|
|
429
|
+
if (TS_EXT_REGEX.test(hmrCtx.file)) {
|
|
430
|
+
const [fileId] = hmrCtx.file.split("?");
|
|
431
|
+
debugHmr("TS file changed", {
|
|
432
|
+
file: hmrCtx.file,
|
|
433
|
+
fileId
|
|
434
|
+
});
|
|
435
|
+
await hotUpdates.schedule(hmrCtx.file, [fileId]);
|
|
436
|
+
if (EXCLUDED_TS_EXT_REGEX.test(fileId)) {
|
|
437
|
+
hmrCtx.server.moduleGraph.invalidateAll();
|
|
438
|
+
hmrCtx.server.ws.send({
|
|
439
|
+
type: "full-reload",
|
|
440
|
+
triggeredBy: fileId
|
|
441
|
+
});
|
|
442
|
+
return [];
|
|
443
|
+
}
|
|
444
|
+
let result;
|
|
445
|
+
if (ctx.shouldEnableLiveReload()) {
|
|
446
|
+
result = fileEmitter(fileId);
|
|
447
|
+
debugHmr("TS file emitted", {
|
|
448
|
+
fileId,
|
|
449
|
+
hmrEligible: !!result?.hmrEligible,
|
|
450
|
+
hasClassName: !!ctx.hmr.classNames.get(fileId)
|
|
451
|
+
});
|
|
452
|
+
debugHmrV("ts hmr evaluation", {
|
|
453
|
+
file: hmrCtx.file,
|
|
454
|
+
fileId,
|
|
455
|
+
hasResult: !!result,
|
|
456
|
+
hmrEligible: !!result?.hmrEligible,
|
|
457
|
+
hasClassName: !!ctx.hmr.classNames.get(fileId),
|
|
458
|
+
className: ctx.hmr.classNames.get(fileId),
|
|
459
|
+
updateCode: result?.hmrUpdateCode ? describeStylesheetContent(result.hmrUpdateCode) : void 0,
|
|
460
|
+
errors: result?.errors?.length ?? 0,
|
|
461
|
+
warnings: result?.warnings?.length ?? 0,
|
|
462
|
+
hint: result?.hmrEligible ? "A TS-side component change, including inline template edits, produced an Angular HMR payload." : "No Angular HMR payload was emitted for this TS change; the change may not affect component template state."
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
if (ctx.shouldEnableLiveReload() && result?.hmrEligible && ctx.hmr.classNames.get(fileId)) {
|
|
466
|
+
const relativeFileId = ctx.hmr.toComponentUpdateId(fileId);
|
|
467
|
+
debugHmr("sending component update", { relativeFileId });
|
|
468
|
+
debugHmrV("ts hmr component update payload", {
|
|
469
|
+
file: hmrCtx.file,
|
|
470
|
+
fileId,
|
|
471
|
+
relativeFileId,
|
|
472
|
+
className: ctx.hmr.classNames.get(fileId)
|
|
473
|
+
});
|
|
474
|
+
ctx.hmr.sendComponentUpdate(hmrCtx.server, relativeFileId);
|
|
475
|
+
return hmrCtx.modules.map((mod) => {
|
|
476
|
+
if (mod.id === hmrCtx.file) return markModuleSelfAccepting(mod);
|
|
477
|
+
return mod;
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (/\.(html|htm|css|less|sass|scss)$/.test(hmrCtx.file)) {
|
|
482
|
+
debugHmr("resource file changed", { file: hmrCtx.file });
|
|
483
|
+
fileTransformMap.delete(hmrCtx.file.split("?")[0]);
|
|
484
|
+
const stylesheetRegistry = ctx.styles.registry;
|
|
485
|
+
const fileModules = await getModulesForChangedFile(hmrCtx.server, hmrCtx.file, hmrCtx.modules, stylesheetRegistry);
|
|
486
|
+
/**
|
|
487
|
+
* Check to see if this was a direct request
|
|
488
|
+
* for an external resource (styles, html).
|
|
489
|
+
*/
|
|
490
|
+
const isDirect = fileModules.find((mod) => !!mod.id && mod.id.includes("?direct") && isModuleForChangedResource(mod, hmrCtx.file, stylesheetRegistry));
|
|
491
|
+
const isInline = fileModules.find((mod) => !!mod.id && mod.id.includes("?inline") && isModuleForChangedResource(mod, hmrCtx.file, stylesheetRegistry));
|
|
492
|
+
debugHmrV("resource direct/inline detection", {
|
|
493
|
+
file: hmrCtx.file,
|
|
494
|
+
hasDirect: !!isDirect,
|
|
495
|
+
directId: isDirect?.id,
|
|
496
|
+
hasInline: !!isInline,
|
|
497
|
+
inlineId: isInline?.id
|
|
498
|
+
});
|
|
499
|
+
if (isDirect || isInline) {
|
|
500
|
+
if (ctx.shouldExternalizeStyles() && isDirect?.id && isDirect.file) {
|
|
501
|
+
const isComponentStyle = isDirect.type === "css" && isComponentStyleSheet(isDirect.id);
|
|
502
|
+
debugHmrV("resource direct branch", {
|
|
503
|
+
file: hmrCtx.file,
|
|
504
|
+
directId: isDirect.id,
|
|
505
|
+
directType: isDirect.type,
|
|
506
|
+
shouldExternalize: ctx.shouldExternalizeStyles(),
|
|
507
|
+
isComponentStyle
|
|
508
|
+
});
|
|
509
|
+
if (isComponentStyle) return handleDirectComponentStyleHmr({
|
|
510
|
+
server: hmrCtx.server,
|
|
511
|
+
file: hmrCtx.file,
|
|
512
|
+
directModule: isDirect,
|
|
513
|
+
fileModules,
|
|
514
|
+
stylesheetRegistry,
|
|
515
|
+
stylePreprocessor: ctx.stylePreprocessor
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
return fileModules;
|
|
519
|
+
}
|
|
520
|
+
if (ctx.shouldEnableLiveReload() && /\.(html|htm)$/.test(hmrCtx.file) && fileModules.length === 0) {
|
|
521
|
+
const ownerModules = findTemplateOwnerModules(hmrCtx.server, hmrCtx.file);
|
|
522
|
+
debugHmrV("template owner lookup", {
|
|
523
|
+
file: hmrCtx.file,
|
|
524
|
+
ownerCount: ownerModules.length,
|
|
525
|
+
ownerIds: ownerModules.map((mod) => mod.id),
|
|
526
|
+
hint: ownerModules.length > 0 ? "The external template has candidate TS owner modules that can be recompiled for HMR." : "No TS owner modules were visible for this external template change; HMR will fall through to the generic importer path."
|
|
527
|
+
});
|
|
528
|
+
if (ownerModules.length > 0) {
|
|
529
|
+
const ownerIds = ownerModules.map((mod) => mod.id).filter(Boolean);
|
|
530
|
+
ownerModules.forEach((mod) => hmrCtx.server.moduleGraph.invalidateModule(mod));
|
|
531
|
+
await hotUpdates.schedule(hmrCtx.file, ownerIds);
|
|
532
|
+
const updates = ownerIds.filter((id) => ctx.hmr.classNames.get(id));
|
|
533
|
+
debugHmrV("template owner recompilation result", {
|
|
534
|
+
file: hmrCtx.file,
|
|
535
|
+
ownerIds,
|
|
536
|
+
updates,
|
|
537
|
+
updateClassNames: updates.map((id) => ({
|
|
538
|
+
id,
|
|
539
|
+
className: ctx.hmr.classNames.get(id)
|
|
540
|
+
})),
|
|
541
|
+
hint: updates.length > 0 ? "External template recompilation produced Angular component update targets." : "External template recompilation completed, but no Angular component update targets were surfaced."
|
|
542
|
+
});
|
|
543
|
+
if (updates.length > 0) {
|
|
544
|
+
debugHmr("template owner module invalidation", {
|
|
545
|
+
file: hmrCtx.file,
|
|
546
|
+
ownerIds,
|
|
547
|
+
updateCount: updates.length
|
|
548
|
+
});
|
|
549
|
+
updates.forEach((updateId) => {
|
|
550
|
+
ctx.hmr.sendComponentUpdate(hmrCtx.server, ctx.hmr.toComponentUpdateId(updateId));
|
|
551
|
+
});
|
|
552
|
+
return ownerModules.map((mod) => markModuleSelfAccepting(mod));
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const mods = [];
|
|
557
|
+
const updates = [];
|
|
558
|
+
fileModules.forEach((mod) => {
|
|
559
|
+
mod.importers.forEach((imp) => {
|
|
560
|
+
hmrCtx.server.moduleGraph.invalidateModule(imp);
|
|
561
|
+
if (ctx.shouldExternalizeStyles() && imp.id && ctx.hmr.classNames.get(imp.id)) updates.push(imp.id);
|
|
562
|
+
else mods.push(imp);
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
debugHmrV("resource importer analysis", {
|
|
566
|
+
file: hmrCtx.file,
|
|
567
|
+
fileModuleCount: fileModules.length,
|
|
568
|
+
importerCount: fileModules.reduce((count, mod) => count + mod.importers.size, 0),
|
|
569
|
+
updates,
|
|
570
|
+
mods: mods.map((mod) => mod.id)
|
|
571
|
+
});
|
|
572
|
+
if (mods.length === 0 && updates.length === 0) return mods;
|
|
573
|
+
await hotUpdates.schedule(hmrCtx.file, [...mods.map((mod) => mod.id), ...updates]);
|
|
574
|
+
if (updates.length > 0) {
|
|
575
|
+
debugHmr("resource importer component updates", {
|
|
576
|
+
file: hmrCtx.file,
|
|
577
|
+
updateCount: updates.length
|
|
578
|
+
});
|
|
579
|
+
updates.forEach((updateId) => {
|
|
580
|
+
ctx.hmr.sendComponentUpdate(hmrCtx.server, ctx.hmr.toComponentUpdateId(updateId));
|
|
581
|
+
});
|
|
582
|
+
return fileModules.map((mod) => {
|
|
583
|
+
if (mod.id === hmrCtx.file) return markModuleSelfAccepting(mod);
|
|
584
|
+
return mod;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
return mods;
|
|
588
|
+
}
|
|
589
|
+
debugHmr("full reload — unrecognized file type", { file: hmrCtx.file });
|
|
590
|
+
ctx.hmr.clear();
|
|
591
|
+
return hmrCtx.modules;
|
|
592
|
+
},
|
|
593
|
+
resolveId(id, importer) {
|
|
594
|
+
const virtualId = resolveAngularVirtualId(id, importer, {
|
|
595
|
+
jit,
|
|
596
|
+
resolvedConfig: ctx.resolvedConfig
|
|
597
|
+
});
|
|
598
|
+
if (virtualId !== void 0) return virtualId;
|
|
599
|
+
return ctx.styles.resolveComponentStyleId(id);
|
|
600
|
+
},
|
|
601
|
+
async load(id) {
|
|
602
|
+
const virtualModule = await loadAngularVirtualModule(this, id, ctx.resolvedConfig);
|
|
603
|
+
if (virtualModule !== void 0) return virtualModule;
|
|
604
|
+
return ctx.styles.loadComponentStyle(id);
|
|
605
|
+
},
|
|
606
|
+
transform: {
|
|
607
|
+
filter: { id: {
|
|
608
|
+
include: [TS_EXT_REGEX],
|
|
609
|
+
exclude: [
|
|
610
|
+
/node_modules/,
|
|
611
|
+
"type=script",
|
|
612
|
+
"@ng/component"
|
|
613
|
+
]
|
|
614
|
+
} },
|
|
615
|
+
async handler(code, id) {
|
|
616
|
+
if (ctx.transformFilter && !ctx.transformFilter(code, id)) return;
|
|
617
|
+
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
618
|
+
fileTransformMap.set(id, code);
|
|
619
|
+
/**
|
|
620
|
+
* Re-analyze on each transform
|
|
621
|
+
* for test(Vitest)
|
|
622
|
+
*/
|
|
623
|
+
if (isTest) {
|
|
624
|
+
if (ctx.deferInitialCompilation && !initialCompilation) {
|
|
625
|
+
pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig);
|
|
626
|
+
initialCompilation = true;
|
|
627
|
+
}
|
|
628
|
+
const tsMod = viteServer?.moduleGraph.getModuleById(id);
|
|
629
|
+
if (tsMod) {
|
|
630
|
+
const invalidated = tsMod.lastInvalidationTimestamp;
|
|
631
|
+
if (ctx.testWatchMode && invalidated) pendingCompilation = performCompilation(this.environment?.config ?? ctx.resolvedConfig, [id]);
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
const hasComponent = code.includes("@Component");
|
|
635
|
+
debugCompilerV("transform", {
|
|
636
|
+
id,
|
|
637
|
+
codeLength: code.length,
|
|
638
|
+
hasComponent
|
|
639
|
+
});
|
|
640
|
+
const resolveResourceUrls = hasComponent && (ctx.watchMode || jit);
|
|
641
|
+
const templateUrls = resolveResourceUrls ? templateUrlsResolver.resolve(code, id) : [];
|
|
642
|
+
const styleUrls = resolveResourceUrls ? styleUrlsResolver.resolve(code, id) : [];
|
|
643
|
+
if (resolveResourceUrls && ctx.watchMode) for (const urlSet of [...templateUrls, ...styleUrls]) {
|
|
644
|
+
const [, absoluteFileUrl] = urlSet.split("|");
|
|
645
|
+
this.addWatchFile(absoluteFileUrl);
|
|
646
|
+
}
|
|
647
|
+
if (pendingCompilation) {
|
|
648
|
+
await pendingCompilation;
|
|
649
|
+
pendingCompilation = null;
|
|
650
|
+
}
|
|
651
|
+
await hotUpdates.wait();
|
|
652
|
+
const typescriptResult = fileEmitter(id);
|
|
653
|
+
if (!typescriptResult) {
|
|
654
|
+
debugCompilerV("transform skip (file not emitted by Angular)", { id });
|
|
655
|
+
const isAngular = !id.includes("@ng/component") && /(Component|Directive|Pipe|Injectable|NgModule)\(/.test(code);
|
|
656
|
+
debugEmit("transform emit miss", {
|
|
657
|
+
id,
|
|
658
|
+
normalizedId: normalizeEmitterLookupId(id),
|
|
659
|
+
knownOutputCount: outputFiles.size,
|
|
660
|
+
hasOutputFileHook: !!outputFile,
|
|
661
|
+
isAngular
|
|
662
|
+
});
|
|
663
|
+
if (isAngular) this.warn(`[@analogjs/vite-plugin-angular]: "${id}" contains Angular decorators but is not in the TypeScript program. Ensure it is included in your tsconfig.`);
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
if (typescriptResult.warnings && typescriptResult.warnings.length > 0) this.warn(`${typescriptResult.warnings.join("\n")}`);
|
|
667
|
+
if (typescriptResult.errors && typescriptResult.errors.length > 0) this.error(`${typescriptResult.errors.join("\n")}`);
|
|
668
|
+
let data = typescriptResult.content ?? "";
|
|
669
|
+
debugEmitV("transform emit hit", {
|
|
670
|
+
id,
|
|
671
|
+
normalizedId: normalizeEmitterLookupId(id),
|
|
672
|
+
...describeEmitMarkers(data),
|
|
673
|
+
errorCount: typescriptResult.errors?.length ?? 0,
|
|
674
|
+
warningCount: typescriptResult.warnings?.length ?? 0
|
|
675
|
+
});
|
|
676
|
+
if (jit && data.includes("angular:jit:")) {
|
|
677
|
+
data = data.replace(/angular:jit:style:inline;([A-Za-z0-9+/=]*)/g, (_match, encodedStyles) => toJitInlineStyleId(encodedStyles, isTest));
|
|
678
|
+
templateUrls.forEach((templateUrlSet) => {
|
|
679
|
+
const [templateFile, resolvedTemplateUrl] = templateUrlSet.split("|");
|
|
680
|
+
data = data.replace(`angular:jit:template:file;${templateFile}`, toVirtualRawId(resolvedTemplateUrl));
|
|
681
|
+
});
|
|
682
|
+
styleUrls.forEach((styleUrlSet) => {
|
|
683
|
+
const [styleFile, resolvedStyleUrl] = styleUrlSet.split("|");
|
|
684
|
+
markStylePathSafe(ctx.resolvedConfig, resolvedStyleUrl);
|
|
685
|
+
data = data.replace(`angular:jit:style:file;${styleFile}`, resolvedStyleUrl + "?inline");
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
if (data.includes("HmrLoad")) {
|
|
689
|
+
const hasMetaUrl = data.includes("getReplaceMetadataURL");
|
|
690
|
+
debugHmrV("vite-ignore injection", {
|
|
691
|
+
id,
|
|
692
|
+
dataLength: data.length,
|
|
693
|
+
hasMetaUrl
|
|
694
|
+
});
|
|
695
|
+
if (hasMetaUrl) {
|
|
696
|
+
const patched = injectViteIgnoreForHmrMetadata(data);
|
|
697
|
+
if (patched !== data && !patched.includes("@vite-ignore")) debugHmrV("vite-ignore regex fallback", { id });
|
|
698
|
+
data = patched;
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (typescriptResult.map) data = data.replace(/\s*\/\/# sourceMappingURL=[^\r\n]*\s*$/, "");
|
|
702
|
+
return {
|
|
703
|
+
code: data,
|
|
704
|
+
map: typescriptResult.map ? normalizeSourceMapSources(typescriptResult.map, id) : null
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
},
|
|
708
|
+
async closeBundle() {
|
|
709
|
+
closeRequested = true;
|
|
710
|
+
if (activeBuilds === 0) await closeCompilation();
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* @internal
|
|
716
|
+
*/
|
|
717
|
+
function getFileMetadata(program, angularCompiler, hmrEnabled, disableTypeChecking, classNamesMap = /* @__PURE__ */ new Map()) {
|
|
718
|
+
const ts = require("typescript");
|
|
719
|
+
return (file) => {
|
|
720
|
+
const sourceFile = program.getSourceFile(file);
|
|
721
|
+
if (!sourceFile) return {};
|
|
722
|
+
const diagnostics = getDiagnosticsForSourceFile(sourceFile, !!disableTypeChecking, program, angularCompiler);
|
|
723
|
+
const errors = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Error).map((d) => typeof d.messageText === "object" ? d.messageText.messageText : d.messageText);
|
|
724
|
+
const warnings = diagnostics.filter((d) => d.category === ts.DiagnosticCategory?.Warning).map((d) => d.messageText);
|
|
725
|
+
let hmrUpdateCode = void 0;
|
|
726
|
+
let hmrEligible = false;
|
|
727
|
+
if (hmrEnabled) {
|
|
728
|
+
for (const node of sourceFile.statements) if (ts.isClassDeclaration(node) && node.name != null) {
|
|
729
|
+
hmrUpdateCode = angularCompiler?.emitHmrUpdateModule(node);
|
|
730
|
+
if (hmrUpdateCode) {
|
|
731
|
+
const className = node.name.getText();
|
|
732
|
+
classNamesMap.set(file, className);
|
|
733
|
+
hmrEligible = true;
|
|
734
|
+
debugHmr("NgtscProgram emitHmrUpdateModule", {
|
|
735
|
+
file,
|
|
736
|
+
className
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
return {
|
|
742
|
+
errors,
|
|
743
|
+
warnings,
|
|
744
|
+
hmrUpdateCode,
|
|
745
|
+
hmrEligible
|
|
746
|
+
};
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
function getDiagnosticsForSourceFile(sourceFile, disableTypeChecking, program, angularCompiler) {
|
|
750
|
+
const syntacticDiagnostics = program.getSyntacticDiagnostics(sourceFile);
|
|
751
|
+
if (disableTypeChecking) return syntacticDiagnostics;
|
|
752
|
+
const semanticDiagnostics = program.getSemanticDiagnostics(sourceFile);
|
|
753
|
+
const angularDiagnostics = angularCompiler ? angularCompiler.getDiagnosticsForFile(sourceFile, 1) : [];
|
|
754
|
+
return [
|
|
755
|
+
...syntacticDiagnostics,
|
|
756
|
+
...semanticDiagnostics,
|
|
757
|
+
...angularDiagnostics
|
|
758
|
+
];
|
|
759
|
+
}
|
|
760
|
+
//#endregion
|
|
761
|
+
export { createFsWatcherCacheInvalidator, evictDeletedFileMetadata, getFileMetadata, ngtscCompilePlugin };
|
|
762
|
+
|
|
763
|
+
//# sourceMappingURL=ngtsc-compile-plugin.js.map
|