@analogjs/vite-plugin-angular 3.0.0-beta.37 → 3.0.0-beta.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/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 +4 -2
- 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 -124
- package/src/lib/angular-vite-plugin.js +8 -1276
- 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 +5 -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 -285
- package/src/lib/compilation-api/compilation-api-plugin.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 +3 -1
- package/src/lib/fast-compile-plugin.js +93 -49
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.js +3 -3
- package/src/lib/live-reload-plugin.d.ts +3 -1
- package/src/lib/live-reload-plugin.js +11 -5
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/ngp-compile-plugin.d.ts +2 -1
- package/src/lib/ngp-compile-plugin.js +90 -24
- package/src/lib/ngp-compile-plugin.js.map +1 -1
- package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
- package/src/lib/ngtsc-compile-plugin.js +762 -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/lsp-type-checker.js +1 -1
- package/src/lib/utils/plugin-config.d.ts +6 -8
- package/src/lib/utils/plugin-config.js +8 -4
- package/src/lib/utils/plugin-config.js.map +1 -1
- 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 @@
|
|
|
1
|
+
{"version":3,"file":"component-styles-plugin.js","names":[],"sources":["../../../src/lib/component-styles-plugin.ts"],"sourcesContent":["import { existsSync, readFileSync } from 'node:fs';\nimport { union } from 'es-toolkit';\nimport {\n normalizePath,\n type ModuleNode,\n type Plugin,\n type ViteDevServer,\n} from 'vite';\n\nimport {\n ensureAngularBuildContext,\n getFilenameFromPath,\n type AngularBuildContext,\n type AngularBuildContextOptions,\n} from './angular-build-context.js';\nimport {\n getComponentStyleSheetMeta,\n isComponentStyleSheet,\n} from './encapsulation-plugin.js';\nimport type {\n StylePreprocessor,\n StylesheetDependency,\n} from './style-preprocessor.js';\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheet,\n rewriteRelativeCssImports,\n} from './stylesheet-registry.js';\nimport { describeStylesheetContent } from './utils/compilation-shared.js';\nimport { debugHmr, debugHmrV, debugStylesV } from './utils/debug.js';\n\nexport interface ComponentStylesheetPipelineDiagnosis {\n file: string;\n sourcePath?: string;\n source?: ReturnType<typeof describeStylesheetContent>;\n registry?: ReturnType<typeof describeStylesheetContent>;\n dependencies: StylesheetDependency[];\n diagnostics: ReturnType<AnalogStylesheetRegistry['getDiagnosticsForSource']>;\n tags: string[];\n directModuleId?: string;\n directModuleUrl?: string;\n trackedRequestIds: string[];\n wrapperCount: number;\n anomalies: string[];\n hints: string[];\n}\n\n/**\n * Self-contained Vite plugin that resolves and serves externalized Angular\n * component stylesheets (`?ngcomp=...`) from the shared `AngularBuildContext`\n * stylesheet registry and refreshes served records on source CSS edits.\n */\nexport function componentStylesPlugin(\n ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions,\n): Plugin {\n const ctx = ensureAngularBuildContext(ctxOrOptions);\n\n return {\n name: '@analogjs/vite-plugin-angular:component-styles',\n enforce: 'pre',\n async configResolved(config) {\n await ctx.resolveConfig(config);\n },\n resolveId(id) {\n return ctx.styles.resolveComponentStyleId(id);\n },\n load(id) {\n return ctx.styles.loadComponentStyle(id);\n },\n handleHotUpdate(hmrCtx) {\n if (/\\.(css|less|sass|scss)$/.test(hmrCtx.file)) {\n debugHmr('stylesheet file changed', { file: hmrCtx.file });\n ctx.styles.refreshForFile(hmrCtx.file);\n }\n return undefined;\n },\n };\n}\n\nexport function markModuleSelfAccepting(mod: ModuleNode): ModuleNode {\n // support Vite 6\n if ('_clientModule' in mod) {\n (mod as unknown as { _clientModule: { isSelfAccepting: boolean } })[\n '_clientModule'\n ].isSelfAccepting = true;\n }\n\n return {\n ...mod,\n isSelfAccepting: true,\n } as ModuleNode;\n}\n\n/**\n * Returns every live Vite module that can legitimately represent a changed\n * Angular resource file.\n *\n * For normal files, `getModulesByFile()` is enough. For Angular component\n * stylesheets, it is not: the browser often holds virtual hashed requests\n * (`/abc123.css?direct&ngcomp=...` and `/abc123.css?ngcomp=...`) that are no\n * longer discoverable from the original source path alone. We therefore merge:\n * - watcher event modules\n * - module-graph modules by source file\n * - registry-tracked live request ids resolved back through the module graph\n */\nexport async function getModulesForChangedFile(\n server: ViteDevServer,\n file: string,\n eventModules: readonly ModuleNode[] = [],\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): Promise<ModuleNode[]> {\n const normalizedFile = normalizePath(file.split('?')[0]);\n const modules = new Map<string, ModuleNode>();\n\n for (const mod of eventModules) {\n if (mod.id) {\n modules.set(mod.id, mod);\n }\n }\n\n server.moduleGraph.getModulesByFile(normalizedFile)?.forEach((mod) => {\n if (mod.id) {\n modules.set(mod.id, mod);\n }\n });\n\n const stylesheetRequestIds =\n stylesheetRegistry?.getRequestIdsForSource(normalizedFile) ?? [];\n const requestIdHits: Array<{\n requestId: string;\n candidate: string;\n via: 'url' | 'id';\n moduleId?: string;\n }> = [];\n for (const requestId of stylesheetRequestIds) {\n const candidates = [\n requestId,\n requestId.startsWith('/') ? requestId : `/${requestId}`,\n ];\n\n for (const candidate of candidates) {\n // `getModuleByUrl()` is the important lookup here. Angular's wrapper\n // module is served by URL and can be absent from a straight `getModuleById`\n // lookup during CSS HMR, even though it is the browser-visible module\n // that must be refreshed. We keep `getModuleById()` as a compatibility\n // fallback for the simpler direct CSS case.\n const mod =\n (await server.moduleGraph.getModuleByUrl(candidate)) ??\n server.moduleGraph.getModuleById(candidate);\n requestIdHits.push({\n requestId,\n candidate,\n via: mod?.url === candidate ? 'url' : 'id',\n moduleId: mod?.id ?? undefined,\n });\n if (mod?.id) {\n modules.set(mod.id, mod);\n }\n }\n }\n\n debugHmrV('getModulesForChangedFile registry lookup', {\n file: normalizedFile,\n stylesheetRequestIds,\n requestIdHits,\n resolvedModuleIds: [...modules.keys()],\n });\n\n return [...modules.values()];\n}\n\nexport function isModuleForChangedResource(\n mod: ModuleNode,\n changedFile: string,\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): boolean {\n const normalizedChangedFile = normalizePath(changedFile.split('?')[0]);\n\n if (normalizePath((mod.file ?? '').split('?')[0]) === normalizedChangedFile) {\n return true;\n }\n\n if (!mod.id) {\n return false;\n }\n\n // Virtual Angular stylesheet modules do not report the original source file\n // as `mod.file`; they point at the served hashed stylesheet asset instead.\n // Recover the source file through the stylesheet registry so HMR can still\n // answer \"does this live module belong to the resource that just changed?\"\n const requestPath = getFilenameFromPath(mod.id);\n const sourcePath =\n stylesheetRegistry?.resolveExternalSource(requestPath) ??\n stylesheetRegistry?.resolveExternalSource(requestPath.replace(/^\\//, '')) ??\n stylesheetRegistry?.getServedSourcePath(requestPath) ??\n stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\\//, ''));\n\n return (\n normalizePath((sourcePath ?? '').split('?')[0]) === normalizedChangedFile\n );\n}\n\nfunction resolveDirectStylesheetSourcePath(\n normalizedFile: string,\n directModule: ModuleNode,\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): { directRequestPath?: string; sourcePath: string | undefined } {\n const directRequestPath = directModule.id\n ? getFilenameFromPath(directModule.id)\n : undefined;\n const sourcePath = directRequestPath\n ? (stylesheetRegistry?.resolveExternalSource(directRequestPath) ??\n stylesheetRegistry?.resolveExternalSource(\n directRequestPath.replace(/^\\//, ''),\n ) ??\n stylesheetRegistry?.getServedSourcePath(directRequestPath) ??\n stylesheetRegistry?.getServedSourcePath(\n directRequestPath.replace(/^\\//, ''),\n ))\n : normalizedFile;\n\n return { directRequestPath, sourcePath };\n}\n\nexport function diagnoseComponentStylesheetPipeline(\n changedFile: string,\n directModule: ModuleNode,\n stylesheetRegistry: AnalogStylesheetRegistry | undefined,\n wrapperModules: ModuleNode[],\n stylePreprocessor?: StylePreprocessor,\n): ComponentStylesheetPipelineDiagnosis {\n const normalizedFile = normalizePath(changedFile.split('?')[0]);\n const sourceExists = existsSync(normalizedFile);\n const sourceCode = sourceExists\n ? readFileSync(normalizedFile, 'utf-8')\n : undefined;\n\n const { directRequestPath, sourcePath } = resolveDirectStylesheetSourcePath(\n normalizedFile,\n directModule,\n stylesheetRegistry,\n );\n const registryCode = directRequestPath\n ? stylesheetRegistry?.getServedContent(directRequestPath)\n : undefined;\n const trackedRequestIds =\n stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? '') ?? [];\n const dependencies =\n stylesheetRegistry?.getDependenciesForSource(sourcePath ?? '') ?? [];\n const diagnostics =\n stylesheetRegistry?.getDiagnosticsForSource(sourcePath ?? '') ?? [];\n const tags = stylesheetRegistry?.getTagsForSource(sourcePath ?? '') ?? [];\n\n const anomalies: string[] = [];\n const hints: string[] = [];\n\n if (!sourceExists) {\n anomalies.push('source_file_missing');\n hints.push(\n 'The stylesheet watcher fired for a file that no longer exists on disk.',\n );\n }\n\n if (!registryCode) {\n anomalies.push('registry_content_missing');\n hints.push(\n 'The stylesheet registry has no served content for the direct module request path.',\n );\n }\n\n const registryDescription = registryCode\n ? describeStylesheetContent(registryCode)\n : undefined;\n let sourceDescription:\n | ReturnType<typeof describeStylesheetContent>\n | undefined;\n\n if (sourceCode !== undefined) {\n try {\n // Compare against the same served representation that the registry stores,\n // not the raw file on disk. Analog intentionally prepends `@reference`\n // and rewrites relative imports before the stylesheet reaches Vite, so a\n // raw-source hash comparison would flag a false positive on every healthy\n // update.\n let expectedRegistryCode = preprocessStylesheet(\n sourceCode,\n normalizedFile,\n stylePreprocessor,\n );\n expectedRegistryCode = rewriteRelativeCssImports(\n expectedRegistryCode,\n normalizedFile,\n );\n sourceDescription = describeStylesheetContent(expectedRegistryCode);\n } catch {\n anomalies.push('source_preprocess_failed');\n hints.push(\n 'Diagnostic preprocessing of the source stylesheet failed; falling back to raw source summary.',\n );\n sourceDescription = describeStylesheetContent(sourceCode);\n }\n }\n\n if (\n sourceDescription &&\n registryDescription &&\n !anomalies.includes('source_preprocess_failed') &&\n sourceDescription.digest !== registryDescription.digest\n ) {\n anomalies.push('source_registry_mismatch');\n hints.push(\n 'The source file changed, but the served stylesheet content in the registry is still stale.',\n );\n }\n\n if (trackedRequestIds.length === 0) {\n anomalies.push('no_tracked_requests');\n hints.push(\n 'No live stylesheet requests are tracked for this source file, so HMR has no browser-facing target.',\n );\n }\n\n if (\n trackedRequestIds.some((id) => id.includes('?ngcomp=')) &&\n wrapperModules.length === 0\n ) {\n anomalies.push('tracked_wrapper_missing_from_module_graph');\n hints.push(\n 'A wrapper request id is known, but Vite did not expose a live wrapper module during this HMR pass.',\n );\n }\n\n if (\n trackedRequestIds.every((id) => !id.includes('?ngcomp=')) &&\n wrapperModules.length === 0\n ) {\n anomalies.push('wrapper_not_yet_tracked');\n hints.push(\n 'Only direct stylesheet requests were tracked during this HMR pass; the wrapper request may be appearing too late.',\n );\n }\n\n return {\n file: changedFile,\n sourcePath,\n source: sourceDescription,\n registry: registryDescription,\n dependencies,\n diagnostics,\n tags,\n directModuleId: directModule.id ?? undefined,\n directModuleUrl: directModule.url,\n trackedRequestIds,\n wrapperCount: wrapperModules.length,\n anomalies,\n hints,\n };\n}\n\nexport async function findComponentStylesheetWrapperModules(\n server: ViteDevServer,\n changedFile: string,\n directModule: ModuleNode,\n fileModules: ModuleNode[],\n stylesheetRegistry?: AnalogStylesheetRegistry,\n): Promise<ModuleNode[]> {\n const wrapperModules = new Map<string, ModuleNode>();\n\n // Fast path: if the wrapper JS module is already present in the resolved\n // fileModules set for this HMR cycle, use it directly.\n for (const mod of fileModules) {\n if (\n mod.id &&\n mod.type === 'js' &&\n isComponentStyleSheet(mod.id) &&\n isModuleForChangedResource(mod, changedFile, stylesheetRegistry)\n ) {\n wrapperModules.set(mod.id, mod);\n }\n }\n\n const directRequestIds = new Set<string>();\n if (directModule.id) {\n directRequestIds.add(directModule.id);\n }\n if (directModule.url) {\n directRequestIds.add(directModule.url);\n }\n\n const requestPath = directModule.id\n ? getFilenameFromPath(directModule.id)\n : undefined;\n const sourcePath = requestPath\n ? (stylesheetRegistry?.resolveExternalSource(requestPath) ??\n stylesheetRegistry?.resolveExternalSource(\n requestPath.replace(/^\\//, ''),\n ) ??\n stylesheetRegistry?.getServedSourcePath(requestPath) ??\n stylesheetRegistry?.getServedSourcePath(requestPath.replace(/^\\//, '')))\n : undefined;\n\n // HMR timing matters here. On a pure CSS edit, the browser often already has\n // the `?ngcomp=...` wrapper module loaded, but the registry may only know\n // about the `?direct&ngcomp=...` request at the moment the file watcher\n // fires. Pull in any already-tracked wrapper ids for the same source file,\n // then derive wrapper candidates from the known direct request ids.\n for (const requestId of stylesheetRegistry?.getRequestIdsForSource(\n sourcePath ?? '',\n ) ?? []) {\n if (requestId.includes('?ngcomp=')) {\n directRequestIds.add(requestId);\n }\n }\n\n const candidateWrapperIds = [...directRequestIds]\n .filter((id) => id.includes('?direct&ngcomp='))\n .map((id) => id.replace('?direct&ngcomp=', '?ngcomp='));\n\n const lookupHits: Array<{\n candidate: string;\n via?: 'url' | 'id';\n moduleId?: string;\n moduleType?: string;\n }> = [];\n\n for (const candidate of candidateWrapperIds) {\n // Wrapper modules are served by URL and can be absent from a straight\n // module-id lookup during HMR. Prefer URL resolution first, then fall back\n // to id lookup for compatibility with simpler module graph states.\n const mod =\n (await server.moduleGraph.getModuleByUrl(candidate)) ??\n server.moduleGraph.getModuleById(candidate);\n lookupHits.push({\n candidate,\n via: mod?.url === candidate ? 'url' : mod ? 'id' : undefined,\n moduleId: mod?.id ?? undefined,\n moduleType: mod?.type,\n });\n if (\n mod?.id &&\n mod.type === 'js' &&\n isComponentStyleSheet(mod.id) &&\n isModuleForChangedResource(mod, changedFile, stylesheetRegistry)\n ) {\n wrapperModules.set(mod.id, mod);\n }\n }\n\n debugHmrV('component stylesheet wrapper lookup', {\n file: changedFile,\n sourcePath,\n directModuleId: directModule.id,\n directModuleUrl: directModule.url,\n candidateWrapperIds,\n lookupHits,\n });\n\n if (wrapperModules.size === 0) {\n debugHmrV('component stylesheet wrapper lookup empty', {\n file: changedFile,\n sourcePath,\n directModuleId: directModule.id,\n directModuleUrl: directModule.url,\n candidateWrapperIds,\n });\n }\n\n return [...wrapperModules.values()];\n}\n\nexport function findTemplateOwnerModules(\n server: ViteDevServer,\n resourceFile: string,\n): ModuleNode[] {\n const normalizedResourceFile = normalizePath(resourceFile.split('?')[0]);\n const candidateTsFiles = [\n normalizedResourceFile.replace(/\\.(html|htm)$/i, '.ts'),\n ];\n\n const modules = new Map<string, ModuleNode>();\n for (const candidate of candidateTsFiles) {\n const owners = server.moduleGraph.getModulesByFile(candidate);\n owners?.forEach((mod) => {\n if (mod.id) {\n modules.set(mod.id, mod);\n }\n });\n }\n\n return [...modules.values()];\n}\n\nfunction sendCssUpdate(\n server: ViteDevServer,\n update: {\n path: string;\n acceptedPath: string;\n },\n): void {\n const timestamp = Date.now();\n debugHmrV('ws send: css-update', {\n ...update,\n timestamp,\n });\n server.ws.send({\n type: 'update',\n updates: [\n {\n type: 'css-update',\n timestamp,\n path: update.path,\n acceptedPath: update.acceptedPath,\n },\n ],\n });\n}\n\nfunction sendFullReload(\n server: ViteDevServer,\n details: Record<string, unknown>,\n): void {\n debugHmrV('ws send: full-reload', details);\n server.ws.send('analog:debug-full-reload', details);\n server.ws.send({ type: 'full-reload' });\n}\n\ntype ComponentStylesheetHmrOutcome = 'css-update' | 'full-reload';\n\nfunction logComponentStylesheetHmrOutcome(details: {\n file: string;\n encapsulation: string | undefined;\n diagnosis: ComponentStylesheetPipelineDiagnosis;\n outcome: ComponentStylesheetHmrOutcome;\n directModuleId?: string;\n wrapperIds?: string[];\n}): void {\n const pitfalls: string[] = [];\n const rejectedPreferredPaths: string[] = [];\n const hints: string[] = [];\n\n if (details.encapsulation === 'shadow') {\n pitfalls.push('shadow-encapsulation');\n rejectedPreferredPaths.push('css-update');\n hints.push(\n 'Shadow DOM styles cannot rely on Vite CSS patching because Angular applies them inside a shadow root.',\n );\n }\n\n if (details.diagnosis.anomalies.includes('wrapper_not_yet_tracked')) {\n pitfalls.push('wrapper-not-yet-tracked');\n rejectedPreferredPaths.push('css-update');\n hints.push(\n 'The direct stylesheet module exists, but the browser-visible Angular wrapper module was not available in the live graph during this HMR pass.',\n );\n }\n\n if (\n details.diagnosis.anomalies.includes(\n 'tracked_wrapper_missing_from_module_graph',\n )\n ) {\n pitfalls.push('tracked-wrapper-missing-from-module-graph');\n rejectedPreferredPaths.push('css-update');\n hints.push(\n 'A wrapper request id is known, but Vite could not resolve a live wrapper module for targeted CSS HMR.',\n );\n }\n\n debugHmrV('component stylesheet hmr outcome', {\n file: details.file,\n outcome: details.outcome,\n encapsulation: details.encapsulation,\n directModuleId: details.directModuleId,\n wrapperIds: details.wrapperIds ?? [],\n preferredPath:\n details.encapsulation === 'shadow' ? 'full-reload' : 'css-update',\n rejectedPreferredPaths: [...new Set(rejectedPreferredPaths)],\n pitfalls: [...new Set(pitfalls)],\n anomalies: details.diagnosis.anomalies,\n hints: [...new Set([...details.diagnosis.hints, ...hints])],\n });\n}\n\nexport async function handleDirectComponentStyleHmr(options: {\n server: ViteDevServer;\n file: string;\n directModule: ModuleNode;\n fileModules: ModuleNode[];\n stylesheetRegistry?: AnalogStylesheetRegistry;\n stylePreprocessor?: StylePreprocessor;\n}): Promise<ModuleNode[]> {\n const {\n server,\n file,\n directModule,\n fileModules,\n stylesheetRegistry,\n stylePreprocessor,\n } = options;\n const { encapsulation } = getComponentStyleSheetMeta(directModule.id!);\n\n // Angular exposes one component stylesheet through two module shapes:\n // 1. a `?direct&ngcomp=...` CSS module that Vite can patch with a normal `css-update`\n // 2. a `?ngcomp=...` JS wrapper module that embeds `__vite__css` for Angular's runtime\n //\n // Value: invalidate the browser-visible wrapper before patching the direct CSS\n // module so Angular re-evaluates the same live wrapper it is actually using.\n const wrapperModules = await findComponentStylesheetWrapperModules(\n server,\n file,\n directModule,\n fileModules,\n stylesheetRegistry,\n );\n const normalizedFile = normalizePath(file.split('?')[0]);\n const { sourcePath } = resolveDirectStylesheetSourcePath(\n normalizedFile,\n directModule,\n stylesheetRegistry,\n );\n const trackedRequestIds =\n stylesheetRegistry?.getRequestIdsForSource(sourcePath ?? '') ?? [];\n\n let stylesheetDiagnosis: ComponentStylesheetPipelineDiagnosis | undefined;\n if (debugHmrV.enabled) {\n try {\n stylesheetDiagnosis = diagnoseComponentStylesheetPipeline(\n file,\n directModule,\n stylesheetRegistry,\n wrapperModules,\n stylePreprocessor,\n );\n } catch (error) {\n debugHmrV('component stylesheet pipeline diagnosis failed', {\n file,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n debugStylesV('HMR: component stylesheet changed', {\n file: directModule.file,\n encapsulation,\n });\n debugHmrV('component stylesheet wrapper modules', {\n file,\n wrapperCount: wrapperModules.length,\n wrapperIds: wrapperModules.map((mod) => mod.id),\n availableModuleIds: fileModules.map((mod) => mod.id),\n });\n if (stylesheetDiagnosis) {\n debugHmrV('component stylesheet pipeline diagnosis', stylesheetDiagnosis);\n }\n\n // Drop Vite's cached direct-module transform before wrapper lookup and patching continue.\n server.moduleGraph.invalidateModule(directModule);\n debugHmrV('component stylesheet direct module invalidated', {\n file,\n directModuleId: directModule.id,\n directModuleUrl: directModule.url,\n reason:\n 'Ensure Vite drops stale direct CSS transform results before wrapper or fallback handling continues.',\n });\n\n // CSS-only HMR is safe only when the browser-visible wrapper is known and the\n // component is not using Shadow DOM.\n const trackedWrapperRequestIds = trackedRequestIds.filter((id) =>\n id.includes('?ngcomp='),\n );\n const canUseCssUpdate =\n encapsulation !== 'shadow' &&\n (wrapperModules.length > 0 || trackedWrapperRequestIds.length > 0);\n\n if (canUseCssUpdate) {\n wrapperModules.forEach((mod) => server.moduleGraph.invalidateModule(mod));\n debugHmrV('sending css-update for component stylesheet', {\n file,\n path: directModule.url,\n acceptedPath: directModule.file,\n wrapperCount: wrapperModules.length,\n trackedWrapperRequestIds,\n hint:\n wrapperModules.length > 0\n ? 'Live wrapper modules were found and invalidated before sending the CSS update.'\n : 'No live wrapper ModuleNode was available, but the wrapper request id is already tracked, so Analog is trusting the browser-visible wrapper identity and patching the direct stylesheet instead of forcing a reload.',\n });\n sendCssUpdate(server, {\n path: directModule.url,\n acceptedPath: directModule.file!,\n });\n if (stylesheetDiagnosis) {\n logComponentStylesheetHmrOutcome({\n file,\n encapsulation,\n diagnosis: stylesheetDiagnosis,\n outcome: 'css-update',\n directModuleId: directModule.id ?? undefined,\n wrapperIds: wrapperModules\n .map((mod) => mod.id)\n .filter((id): id is string => id !== null),\n });\n }\n\n return union(\n fileModules\n .filter((mod) => {\n // Component stylesheets will have 2 modules (*.component.scss and *.component.scss?direct&ngcomp=xyz&e=x)\n // We remove the module with the query params to prevent vite double logging the stylesheet name\n return mod.file !== file || mod.id !== directModule.id;\n })\n .map((mod) => {\n if (mod.file === file) {\n return markModuleSelfAccepting(mod);\n }\n return mod;\n }) as ModuleNode[],\n wrapperModules.map((mod) => markModuleSelfAccepting(mod)),\n );\n }\n\n // If the browser-visible `?ngcomp=...` wrapper cannot be trusted, prefer\n // correctness over a partial patch and reload.\n debugHmrV('component stylesheet hmr fallback: full reload', {\n file,\n encapsulation,\n reason:\n trackedWrapperRequestIds.length === 0\n ? 'missing-wrapper-module'\n : encapsulation === 'shadow'\n ? 'shadow-encapsulation'\n : 'tracked-wrapper-still-not-patchable',\n directId: directModule.id,\n trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(file) ?? [],\n });\n if (stylesheetDiagnosis) {\n logComponentStylesheetHmrOutcome({\n file,\n encapsulation,\n diagnosis: stylesheetDiagnosis,\n outcome: 'full-reload',\n directModuleId: directModule.id ?? undefined,\n wrapperIds: wrapperModules\n .map((mod) => mod.id)\n .filter((id): id is string => id !== null),\n });\n }\n sendFullReload(server, {\n file,\n encapsulation,\n reason:\n wrapperModules.length === 0\n ? 'missing-wrapper-module'\n : 'shadow-encapsulation',\n directId: directModule.id,\n trackedRequestIds: stylesheetRegistry?.getRequestIdsForSource(file) ?? [],\n });\n return [];\n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,sBACd,cACQ;CACR,MAAM,MAAM,0BAA0B,YAAY;CAElD,OAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,eAAe,QAAQ;GAC3B,MAAM,IAAI,cAAc,MAAM;EAChC;EACA,UAAU,IAAI;GACZ,OAAO,IAAI,OAAO,wBAAwB,EAAE;EAC9C;EACA,KAAK,IAAI;GACP,OAAO,IAAI,OAAO,mBAAmB,EAAE;EACzC;EACA,gBAAgB,QAAQ;GACtB,IAAI,0BAA0B,KAAK,OAAO,IAAI,GAAG;IAC/C,SAAS,2BAA2B,EAAE,MAAM,OAAO,KAAK,CAAC;IACzD,IAAI,OAAO,eAAe,OAAO,IAAI;GACvC;EAEF;CACF;AACF;AAEA,SAAgB,wBAAwB,KAA6B;CAEnE,IAAI,mBAAmB,KACrB,IACE,gBACD,CAAC,kBAAkB;CAGtB,OAAO;EACL,GAAG;EACH,iBAAiB;CACnB;AACF;;;;;;;;;;;;;AAcA,eAAsB,yBACpB,QACA,MACA,eAAsC,CAAC,GACvC,oBACuB;CACvB,MAAM,iBAAiB,cAAc,KAAK,MAAM,GAAG,CAAC,CAAC,EAAE;CACvD,MAAM,0BAAU,IAAI,IAAwB;CAE5C,KAAK,MAAM,OAAO,cAChB,IAAI,IAAI,IACN,QAAQ,IAAI,IAAI,IAAI,GAAG;CAI3B,OAAO,YAAY,iBAAiB,cAAc,CAAC,EAAE,SAAS,QAAQ;EACpE,IAAI,IAAI,IACN,QAAQ,IAAI,IAAI,IAAI,GAAG;CAE3B,CAAC;CAED,MAAM,uBACJ,oBAAoB,uBAAuB,cAAc,KAAK,CAAC;CACjE,MAAM,gBAKD,CAAC;CACN,KAAK,MAAM,aAAa,sBAAsB;EAC5C,MAAM,aAAa,CACjB,WACA,UAAU,WAAW,GAAG,IAAI,YAAY,IAAI,WAC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a;GACnB,cAAc,aAAa;GAC3B,cAAc,eAAe;GAC7B;GACA,MACE,eAAe,SAAS,IACpB,mFACA;EACR,CAAC;EACD,cAAc,QAAQ;GACpB,MAAM,aAAa;GACnB,cAAc,aAAa;EAC7B,CAAC;EACD,IAAI,qBACF,iCAAiC;GAC/B;GACA;GACA,WAAW;GACX,SAAS;GACT,gBAAgB,aAAa,MAAM,KAAA;GACnC,YAAY,eACT,KAAK,QAAQ,IAAI,EAAE,CAAC,CACpB,QAAQ,OAAqB,OAAO,IAAI;EAC7C,CAAC;EAGH,OAAO,MACL,YACG,QAAQ,QAAQ;GAGf,OAAO,IAAI,SAAS,QAAQ,IAAI,OAAO,aAAa;EACtD,CAAC,CAAC,CACD,KAAK,QAAQ;GACZ,IAAI,IAAI,SAAS,MACf,OAAO,wBAAwB,GAAG;GAEpC,OAAO;EACT,CAAC,GACH,eAAe,KAAK,QAAQ,wBAAwB,GAAG,CAAC,CAC1D;CACF;CAIA,UAAU,kDAAkD;EAC1D;EACA;EACA,QACE,yBAAyB,WAAW,IAChC,2BACA,kBAAkB,WAChB,yBACA;EACR,UAAU,aAAa;EACvB,mBAAmB,oBAAoB,uBAAuB,IAAI,KAAK,CAAC;CAC1E,CAAC;CACD,IAAI,qBACF,iCAAiC;EAC/B;EACA;EACA,WAAW;EACX,SAAS;EACT,gBAAgB,aAAa,MAAM,KAAA;EACnC,YAAY,eACT,KAAK,QAAQ,IAAI,EAAE,CAAC,CACpB,QAAQ,OAAqB,OAAO,IAAI;CAC7C,CAAC;CAEH,eAAe,QAAQ;EACrB;EACA;EACA,QACE,eAAe,WAAW,IACtB,2BACA;EACN,UAAU,aAAa;EACvB,mBAAmB,oBAAoB,uBAAuB,IAAI,KAAK,CAAC;CAC1E,CAAC;CACD,OAAO,CAAC;AACV"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import { type AngularBuildContext, type AngularBuildContextOptions } from "./angular-build-context.js";
|
|
3
|
+
/**
|
|
4
|
+
* Instantiates the compiler plugin matching `ctx.options.compilation` and
|
|
5
|
+
* registers its `AngularCompilerCapabilities` onto `ctx`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function selectAngularCompilerPlugin(ctx: AngularBuildContext): Plugin;
|
|
8
|
+
/**
|
|
9
|
+
* Composes the selected Angular compiler plugin and Analog's companion plugins
|
|
10
|
+
* around an `AngularBuildContext` (or options object).
|
|
11
|
+
*/
|
|
12
|
+
export declare function composeAngularPlugins(ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions): Plugin[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ensureAngularBuildContext } from "./angular-build-context.js";
|
|
2
|
+
import { composeWithCompanions } from "./companion-plugins.js";
|
|
3
|
+
import { compilationApiPlugin } from "./compilation-api/compilation-api-plugin.js";
|
|
4
|
+
import { fastCompilePlugin } from "./fast-compile-plugin.js";
|
|
5
|
+
import { ngpCompilePlugin } from "./ngp-compile-plugin.js";
|
|
6
|
+
import { ngtscCompilePlugin } from "./ngtsc-compile-plugin.js";
|
|
7
|
+
//#region packages/vite-plugin-angular/src/lib/compose-angular-plugins.ts
|
|
8
|
+
/**
|
|
9
|
+
* Instantiates the compiler plugin matching `ctx.options.compilation` and
|
|
10
|
+
* registers its `AngularCompilerCapabilities` onto `ctx`.
|
|
11
|
+
*/
|
|
12
|
+
function selectAngularCompilerPlugin(ctx) {
|
|
13
|
+
switch (ctx.options.compilation) {
|
|
14
|
+
case "fast": return fastCompilePlugin(ctx);
|
|
15
|
+
case "ngp": return ngpCompilePlugin(ctx);
|
|
16
|
+
case "compilation-api": return compilationApiPlugin(ctx);
|
|
17
|
+
default: return ngtscCompilePlugin(ctx);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Composes the selected Angular compiler plugin and Analog's companion plugins
|
|
22
|
+
* around an `AngularBuildContext` (or options object).
|
|
23
|
+
*/
|
|
24
|
+
function composeAngularPlugins(ctxOrOptions) {
|
|
25
|
+
const ctx = ensureAngularBuildContext(ctxOrOptions);
|
|
26
|
+
return composeWithCompanions(ctx, selectAngularCompilerPlugin(ctx));
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { composeAngularPlugins, selectAngularCompilerPlugin };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=compose-angular-plugins.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compose-angular-plugins.js","names":[],"sources":["../../../src/lib/compose-angular-plugins.ts"],"sourcesContent":["import type { Plugin } from 'vite';\n\nimport {\n ensureAngularBuildContext,\n type AngularBuildContext,\n type AngularBuildContextOptions,\n} from './angular-build-context.js';\nimport { compilationApiPlugin } from './compilation-api/compilation-api-plugin.js';\nimport { composeWithCompanions } from './companion-plugins.js';\nimport { fastCompilePlugin } from './fast-compile-plugin.js';\nimport { ngpCompilePlugin } from './ngp-compile-plugin.js';\nimport { ngtscCompilePlugin } from './ngtsc-compile-plugin.js';\n\n/**\n * Instantiates the compiler plugin matching `ctx.options.compilation` and\n * registers its `AngularCompilerCapabilities` onto `ctx`.\n */\nexport function selectAngularCompilerPlugin(ctx: AngularBuildContext): Plugin {\n switch (ctx.options.compilation) {\n case 'fast':\n return fastCompilePlugin(ctx);\n case 'ngp':\n return ngpCompilePlugin(ctx);\n case 'compilation-api':\n return compilationApiPlugin(ctx);\n case 'ngtsc':\n default:\n return ngtscCompilePlugin(ctx);\n }\n}\n\n/**\n * Composes the selected Angular compiler plugin and Analog's companion plugins\n * around an `AngularBuildContext` (or options object).\n */\nexport function composeAngularPlugins(\n ctxOrOptions?: AngularBuildContext | AngularBuildContextOptions,\n): Plugin[] {\n const ctx = ensureAngularBuildContext(ctxOrOptions);\n return composeWithCompanions(ctx, selectAngularCompilerPlugin(ctx));\n}\n"],"mappings":";;;;;;;;;;;AAiBA,SAAgB,4BAA4B,KAAkC;CAC5E,QAAQ,IAAI,QAAQ,aAApB;EACE,KAAK,QACH,OAAO,kBAAkB,GAAG;EAC9B,KAAK,OACH,OAAO,iBAAiB,GAAG;EAC7B,KAAK,mBACH,OAAO,qBAAqB,GAAG;EAEjC,SACE,OAAO,mBAAmB,GAAG;CACjC;AACF;;;;;AAMA,SAAgB,sBACd,cACU;CACV,MAAM,MAAM,0BAA0B,YAAY;CAClD,OAAO,sBAAsB,KAAK,4BAA4B,GAAG,CAAC;AACpE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
/**
|
|
3
|
+
* Defines `ngServerMode: 'true'` for server environments during `vite serve`.
|
|
4
|
+
* Runs after other plugins' `configEnvironment` hooks so an explicit
|
|
5
|
+
* `consumer` configured by a downstream plugin is respected.
|
|
6
|
+
*/
|
|
7
|
+
export declare function devServerModePlugin(): Plugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isServerEnvironment } from "./utils/plugin-config.js";
|
|
2
|
+
//#region packages/vite-plugin-angular/src/lib/dev-server-mode-plugin.ts
|
|
3
|
+
/**
|
|
4
|
+
* Defines `ngServerMode: 'true'` for server environments during `vite serve`.
|
|
5
|
+
* Runs after other plugins' `configEnvironment` hooks so an explicit
|
|
6
|
+
* `consumer` configured by a downstream plugin is respected.
|
|
7
|
+
*/
|
|
8
|
+
function devServerModePlugin() {
|
|
9
|
+
return {
|
|
10
|
+
name: "@analogjs/vite-plugin-angular-dev-server-mode",
|
|
11
|
+
apply: "serve",
|
|
12
|
+
configEnvironment: {
|
|
13
|
+
order: "post",
|
|
14
|
+
handler(name, config) {
|
|
15
|
+
if (isServerEnvironment(name, config)) return { define: { ngServerMode: "true" } };
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { devServerModePlugin };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=dev-server-mode-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server-mode-plugin.js","names":[],"sources":["../../../src/lib/dev-server-mode-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { isServerEnvironment } from './utils/plugin-config.js';\n\n/**\n * Defines `ngServerMode: 'true'` for server environments during `vite serve`.\n * Runs after other plugins' `configEnvironment` hooks so an explicit\n * `consumer` configured by a downstream plugin is respected.\n */\nexport function devServerModePlugin(): Plugin {\n return {\n name: '@analogjs/vite-plugin-angular-dev-server-mode',\n apply: 'serve',\n configEnvironment: {\n order: 'post',\n handler(name, config) {\n if (isServerEnvironment(name, config)) {\n return { define: { ngServerMode: 'true' } };\n }\n return undefined;\n },\n },\n };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,sBAA8B;CAC5C,OAAO;EACL,MAAM;EACN,OAAO;EACP,mBAAmB;GACjB,OAAO;GACP,QAAQ,MAAM,QAAQ;IACpB,IAAI,oBAAoB,MAAM,MAAM,GAClC,OAAO,EAAE,QAAQ,EAAE,cAAc,OAAO,EAAE;GAG9C;EACF;CACF;AACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Plugin } from "vite";
|
|
2
|
+
import { type AngularBuildContext, type AngularBuildContextOptions } from "./angular-build-context.js";
|
|
2
3
|
import type { TypeCheckerOption } from "./utils/lsp-type-checker.js";
|
|
3
4
|
export interface FastCompilePluginOptions {
|
|
4
5
|
tsconfigGetter: () => string;
|
|
@@ -11,6 +12,7 @@ export interface FastCompilePluginOptions {
|
|
|
11
12
|
fastCompileMode?: "full" | "partial";
|
|
12
13
|
disableTypeChecking?: boolean;
|
|
13
14
|
typeChecker?: TypeCheckerOption;
|
|
15
|
+
include?: string[];
|
|
14
16
|
}
|
|
15
17
|
/**
|
|
16
18
|
* Directory that `compilerOptions.paths` targets resolve against. Mirrors
|
|
@@ -22,4 +24,4 @@ export declare function getPathsBasePath(options: {
|
|
|
22
24
|
baseUrl?: string;
|
|
23
25
|
pathsBasePath?: string;
|
|
24
26
|
} | undefined, fallback: string): string;
|
|
25
|
-
export declare function fastCompilePlugin(
|
|
27
|
+
export declare function fastCompilePlugin(optionsOrCtx?: AngularBuildContext | FastCompilePluginOptions | AngularBuildContextOptions): Plugin;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { warnStylesheetError } from "./utils/stylesheet-warning.js";
|
|
2
|
-
import { EXCLUDED_TS_EXT_REGEX, TS_EXT_REGEX, createDepOptimizerConfig, getTsConfigPath, isProdMode } from "./utils/plugin-config.js";
|
|
3
|
-
import { preprocessStylesheet } from "./stylesheet-registry.js";
|
|
4
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 { warnStylesheetError } from "./utils/stylesheet-warning.js";
|
|
7
|
+
import { TsconfigResolver } from "./utils/tsconfig-resolver.js";
|
|
8
|
+
import { createAngularBuildContext, isAngularBuildContext } from "./angular-build-context.js";
|
|
5
9
|
import { releaseCssPreprocessorWorkers } from "./utils/css-preprocessor-workers.js";
|
|
6
|
-
import {
|
|
7
|
-
import { loadVirtualRawModule, rewriteHtmlRawImport } from "./utils/virtual-resources.js";
|
|
10
|
+
import { loadAngularVirtualModule, resolveAngularVirtualId } from "./virtual-modules-plugin.js";
|
|
8
11
|
import { ANGULAR_DECORATOR_CALL_RE } from "./compiler/constants.js";
|
|
9
12
|
import { parseOxc } from "./compiler/utils.js";
|
|
10
13
|
import { debugRegistry } from "./compiler/debug.js";
|
|
@@ -15,13 +18,15 @@ import { jitTransform } from "./compiler/jit-transform.js";
|
|
|
15
18
|
import { generateHmrCode } from "./compiler/hmr.js";
|
|
16
19
|
import { extractInlineStyles, inlineResourceUrls } from "./compiler/resource-inliner.js";
|
|
17
20
|
import "./compiler/index.js";
|
|
18
|
-
import { markStylePathSafe } from "./utils/safe-module-paths.js";
|
|
19
21
|
import { promises } from "node:fs";
|
|
20
|
-
import { dirname,
|
|
22
|
+
import { dirname, resolve } from "node:path";
|
|
21
23
|
import * as vite from "vite";
|
|
22
24
|
import { normalizePath, preprocessCSS } from "vite";
|
|
23
25
|
import * as compilerCli from "@angular/compiler-cli";
|
|
24
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
|
+
}
|
|
25
30
|
/**
|
|
26
31
|
* Directory that `compilerOptions.paths` targets resolve against. Mirrors
|
|
27
32
|
* TypeScript: `baseUrl` when set, otherwise the directory of the config
|
|
@@ -31,7 +36,18 @@ import * as compilerCli from "@angular/compiler-cli";
|
|
|
31
36
|
function getPathsBasePath(options, fallback) {
|
|
32
37
|
return options?.baseUrl ?? options?.pathsBasePath ?? fallback;
|
|
33
38
|
}
|
|
34
|
-
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
|
+
});
|
|
35
51
|
let resolvedConfig;
|
|
36
52
|
let transformFilter;
|
|
37
53
|
let componentRegistries = [];
|
|
@@ -41,6 +57,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
41
57
|
const registry = /* @__PURE__ */ new Map();
|
|
42
58
|
const resourceToSource = /* @__PURE__ */ new Map();
|
|
43
59
|
const scannedDtsPackages = /* @__PURE__ */ new Set();
|
|
60
|
+
const emittedMaps = /* @__PURE__ */ new Map();
|
|
44
61
|
let projectRoot = "";
|
|
45
62
|
let useDefineForClassFields = true;
|
|
46
63
|
let tsConfig;
|
|
@@ -101,6 +118,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
101
118
|
}
|
|
102
119
|
}
|
|
103
120
|
async function initFastCompile() {
|
|
121
|
+
emittedMaps.clear();
|
|
104
122
|
if (pluginOptions.jit) return;
|
|
105
123
|
registry.clear();
|
|
106
124
|
scannedDtsPackages.clear();
|
|
@@ -115,7 +133,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
115
133
|
/** Scan all source files reachable from the tsconfig into the registry. */
|
|
116
134
|
async function scanProject() {
|
|
117
135
|
const config = tsConfig;
|
|
118
|
-
const
|
|
136
|
+
const extraIncludes = tsconfigResolver.ensureIncludeCache();
|
|
137
|
+
const candidates = /* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes]);
|
|
119
138
|
const tsPaths = config.options?.paths;
|
|
120
139
|
const baseUrl = getPathsBasePath(config.options, projectRoot);
|
|
121
140
|
const fileContents = /* @__PURE__ */ new Map();
|
|
@@ -215,7 +234,8 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
215
234
|
}));
|
|
216
235
|
await Promise.all(targets.filter((t) => !!t).map((t) => walkImports(t)));
|
|
217
236
|
};
|
|
218
|
-
|
|
237
|
+
const walkRoots = [.../* @__PURE__ */ new Set([...config.rootNames, ...extraIncludes])];
|
|
238
|
+
await Promise.all(walkRoots.map((file) => walkImports(file)));
|
|
219
239
|
const buildStartVisited = /* @__PURE__ */ new Set();
|
|
220
240
|
if (tsPaths) {
|
|
221
241
|
const barrelCandidates = [];
|
|
@@ -343,19 +363,21 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
343
363
|
const styleStrings = extractInlineStyles(code, id, oxcProgram);
|
|
344
364
|
if (styleStrings.length > 0) {
|
|
345
365
|
resolvedInlineStyles = /* @__PURE__ */ new Map();
|
|
366
|
+
const activeConfig = sharedCtx?.resolvedConfig ?? resolvedConfig;
|
|
367
|
+
const activeStylePreprocessor = sharedCtx?.stylePreprocessor ?? stylePreprocessor;
|
|
346
368
|
for (let i = 0; i < styleStrings.length; i++) {
|
|
347
369
|
const stylePath = stylePaths.get(i) ?? id.replace(/\.ts$/, `.inline-${i}.${pluginOptions.inlineStylesExtension || "css"}`);
|
|
348
370
|
try {
|
|
349
|
-
const preprocessed = preprocessStylesheet(styleStrings[i], stylePath,
|
|
371
|
+
const preprocessed = preprocessStylesheet(styleStrings[i], stylePath, activeStylePreprocessor, {
|
|
350
372
|
filename: stylePath,
|
|
351
373
|
containingFile: id,
|
|
352
374
|
order: i,
|
|
353
375
|
inline: !stylePaths.has(i)
|
|
354
376
|
});
|
|
355
|
-
const processed = await preprocessCSS(preprocessed, stylePath,
|
|
377
|
+
const processed = await preprocessCSS(preprocessed, stylePath, activeConfig);
|
|
356
378
|
resolvedInlineStyles.set(i, processed.code);
|
|
357
379
|
} catch (e) {
|
|
358
|
-
warnStylesheetError(
|
|
380
|
+
warnStylesheetError(activeConfig?.logger, stylePath, e);
|
|
359
381
|
}
|
|
360
382
|
}
|
|
361
383
|
if (resolvedInlineStyles.size === 0) resolvedInlineStyles = void 0;
|
|
@@ -367,10 +389,11 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
367
389
|
projectScan ??= scanProject();
|
|
368
390
|
await projectScan;
|
|
369
391
|
}
|
|
392
|
+
const activeComponentRegistries = sharedCtx ? sharedCtx.componentRegistries : componentRegistries;
|
|
370
393
|
let compileRegistry = registry;
|
|
371
|
-
if (
|
|
394
|
+
if (activeComponentRegistries.some((external) => external.size > 0)) {
|
|
372
395
|
compileRegistry = new Map(registry);
|
|
373
|
-
for (const external of
|
|
396
|
+
for (const external of activeComponentRegistries) for (const [k, v] of external) compileRegistry.set(k, v);
|
|
374
397
|
}
|
|
375
398
|
const result = compile(code, id, {
|
|
376
399
|
registry: compileRegistry,
|
|
@@ -392,7 +415,7 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
392
415
|
sourcemap: true
|
|
393
416
|
}, result.map);
|
|
394
417
|
let outputCode = stripped.code;
|
|
395
|
-
if (watchMode && pluginOptions.liveReload) {
|
|
418
|
+
if ((sharedCtx ? sharedCtx.watchMode : watchMode) && pluginOptions.liveReload) {
|
|
396
419
|
const fileDeclarations = registryEntriesOf(id);
|
|
397
420
|
if (fileDeclarations.length > 0) {
|
|
398
421
|
const localDepClassNames = fileDeclarations.map((e) => e.className);
|
|
@@ -405,17 +428,38 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
405
428
|
};
|
|
406
429
|
}
|
|
407
430
|
function resolveTsConfigPath() {
|
|
408
|
-
|
|
409
|
-
|
|
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);
|
|
410
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
|
+
});
|
|
411
451
|
return {
|
|
412
452
|
name: "@analogjs/vite-plugin-angular-fast-compile",
|
|
413
|
-
api:
|
|
453
|
+
api: compilerApi,
|
|
414
454
|
enforce: "pre",
|
|
415
|
-
async config(config, { command }) {
|
|
455
|
+
async config(config, { command, mode }) {
|
|
416
456
|
watchMode = command === "serve";
|
|
417
457
|
const isProd = isProdMode(config.mode);
|
|
418
|
-
|
|
458
|
+
if (sharedCtx) sharedCtx.initConfig(config, {
|
|
459
|
+
command,
|
|
460
|
+
mode
|
|
461
|
+
});
|
|
462
|
+
else tsConfigResolutionContext = {
|
|
419
463
|
root: config.root || ".",
|
|
420
464
|
isProd,
|
|
421
465
|
isLib: !!config?.build?.lib
|
|
@@ -430,24 +474,36 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
430
474
|
isAstroIntegration: pluginOptions.isAstroIntegration
|
|
431
475
|
});
|
|
432
476
|
return {
|
|
433
|
-
...
|
|
477
|
+
...isRolldown() ? { oxc: {} } : { esbuild: false },
|
|
434
478
|
...depOptimizer
|
|
435
479
|
};
|
|
436
480
|
},
|
|
437
481
|
async configResolved(config) {
|
|
438
482
|
resolvedConfig = config;
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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
|
+
}
|
|
443
495
|
},
|
|
444
496
|
async buildStart() {
|
|
445
497
|
await initFastCompile();
|
|
446
498
|
},
|
|
447
499
|
closeBundle() {
|
|
448
|
-
if (!watchMode)
|
|
500
|
+
if (!(sharedCtx ? sharedCtx.watchMode : watchMode)) {
|
|
501
|
+
emittedMaps.clear();
|
|
502
|
+
releaseCssPreprocessorWorkers();
|
|
503
|
+
}
|
|
449
504
|
},
|
|
450
505
|
async handleHotUpdate(ctx) {
|
|
506
|
+
if (sharedCtx ? sharedCtx.hmr.isIgnoredFile(ctx.file) : isIgnoredHmrFile(ctx.file)) return [];
|
|
451
507
|
if (resourceToSource.has(ctx.file)) {
|
|
452
508
|
const parentSource = resourceToSource.get(ctx.file);
|
|
453
509
|
const parentModule = ctx.server.moduleGraph.getModuleById(parentSource);
|
|
@@ -467,28 +523,13 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
467
523
|
return ctx.modules;
|
|
468
524
|
},
|
|
469
525
|
resolveId(id, importer) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
markStylePathSafe(resolvedConfig, filePath);
|
|
475
|
-
return filePath + "?inline";
|
|
476
|
-
}
|
|
477
|
-
return toVirtualRawId(filePath);
|
|
478
|
-
}
|
|
479
|
-
const rawRewrite = rewriteHtmlRawImport(id, importer);
|
|
480
|
-
if (rawRewrite) return rawRewrite;
|
|
481
|
-
if (/\.(css|scss|sass|less)\?inline$/.test(id) && importer) {
|
|
482
|
-
const filePath = id.split("?")[0];
|
|
483
|
-
const resolved = isAbsolute(filePath) ? normalizePath(filePath) : normalizePath(resolve(dirname(importer), filePath));
|
|
484
|
-
markStylePathSafe(resolvedConfig, resolved);
|
|
485
|
-
return resolved + "?inline";
|
|
486
|
-
}
|
|
526
|
+
return resolveAngularVirtualId(id, importer, {
|
|
527
|
+
jit: pluginOptions.jit,
|
|
528
|
+
resolvedConfig: sharedCtx?.resolvedConfig ?? resolvedConfig
|
|
529
|
+
});
|
|
487
530
|
},
|
|
488
531
|
async load(id) {
|
|
489
|
-
|
|
490
|
-
if (rawModule !== void 0) return rawModule;
|
|
491
|
-
if (/\.(css|scss|sass|less)\?inline$/.test(id)) markStylePathSafe(resolvedConfig, id.split("?")[0]);
|
|
532
|
+
return loadAngularVirtualModule(this, id, sharedCtx?.resolvedConfig ?? resolvedConfig);
|
|
492
533
|
},
|
|
493
534
|
transform: {
|
|
494
535
|
filter: { id: {
|
|
@@ -501,14 +542,17 @@ function fastCompilePlugin(pluginOptions) {
|
|
|
501
542
|
]
|
|
502
543
|
} },
|
|
503
544
|
async handler(code, id) {
|
|
504
|
-
|
|
545
|
+
const activeTransformFilter = sharedCtx?.transformFilter ?? transformFilter;
|
|
546
|
+
if (activeTransformFilter && !activeTransformFilter(code, id)) return;
|
|
505
547
|
if (id.includes(".ts?")) id = id.replace(/\?(.*)/, "");
|
|
506
|
-
|
|
548
|
+
const transformed = await handleFastCompileTransform(code, id, async (spec, importer) => {
|
|
507
549
|
const resolved = await this.resolve(spec, importer, { skipSelf: true });
|
|
508
550
|
if (!resolved || resolved.external) return null;
|
|
509
551
|
const file = normalizePath(resolved.id.split("?")[0]);
|
|
510
552
|
return TS_EXT_REGEX.test(file) && !EXCLUDED_TS_EXT_REGEX.test(file) && !file.includes("/node_modules/") ? file : null;
|
|
511
553
|
});
|
|
554
|
+
if (transformed?.map) emittedMaps.set(normalizePath(id), typeof transformed.map === "string" ? transformed.map : JSON.stringify(transformed.map));
|
|
555
|
+
return transformed;
|
|
512
556
|
}
|
|
513
557
|
}
|
|
514
558
|
};
|