@analogjs/vite-plugin-angular 3.0.0-beta.9 → 3.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +3 -3
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -1
- package/ngp/LICENSE +21 -0
- package/ngp/api.mjs +46806 -0
- package/ngp/build.json +4 -0
- package/ngp/ng_analyze.cjs +601 -0
- package/ngp/ng_analyze_bg.wasm +0 -0
- package/package.json +5 -2
- package/src/index.d.ts +2 -0
- package/src/index.js +4 -3
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.js +2 -3
- package/src/lib/angular-build-context.d.ts +217 -0
- package/src/lib/angular-build-context.js +374 -0
- package/src/lib/angular-build-context.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +6 -4
- package/src/lib/angular-build-optimizer-plugin.js +25 -11
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +5 -3
- package/src/lib/angular-jit-plugin.js +16 -9
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +6 -109
- package/src/lib/angular-vite-plugin.js +9 -1251
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +3 -2
- package/src/lib/angular-vitest-plugin.js +7 -5
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/companion-plugins.d.ts +7 -0
- package/src/lib/companion-plugins.js +37 -0
- package/src/lib/companion-plugins.js.map +1 -0
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +11 -2
- package/src/lib/compilation-api/compilation-api-plugin.js +164 -289
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -1
- package/src/lib/compilation-api/index.js +1 -2
- package/src/lib/compiler/angular-version.js +0 -1
- package/src/lib/compiler/class-field-lowering.js +1 -2
- package/src/lib/compiler/compile.d.ts +1 -1
- package/src/lib/compiler/compile.js +224 -151
- package/src/lib/compiler/compile.js.map +1 -1
- package/src/lib/compiler/constants.js +1 -2
- package/src/lib/compiler/debug.js +1 -2
- package/src/lib/compiler/defer.d.ts +2 -3
- package/src/lib/compiler/defer.js +13 -16
- package/src/lib/compiler/defer.js.map +1 -1
- package/src/lib/compiler/dts-reader.d.ts +6 -1
- package/src/lib/compiler/dts-reader.js +20 -12
- package/src/lib/compiler/dts-reader.js.map +1 -1
- package/src/lib/compiler/hmr.d.ts +4 -0
- package/src/lib/compiler/hmr.js +8 -4
- package/src/lib/compiler/hmr.js.map +1 -1
- package/src/lib/compiler/index.d.ts +2 -2
- package/src/lib/compiler/index.js +6 -6
- package/src/lib/compiler/jit-metadata.js +1 -2
- package/src/lib/compiler/jit-transform.js +37 -15
- package/src/lib/compiler/jit-transform.js.map +1 -1
- package/src/lib/compiler/js-emitter.d.ts +0 -3
- package/src/lib/compiler/js-emitter.js +4 -23
- package/src/lib/compiler/js-emitter.js.map +1 -1
- package/src/lib/compiler/metadata.js +2 -3
- package/src/lib/compiler/registry.d.ts +9 -1
- package/src/lib/compiler/registry.js +36 -8
- package/src/lib/compiler/registry.js.map +1 -1
- package/src/lib/compiler/resource-inliner.d.ts +8 -9
- package/src/lib/compiler/resource-inliner.js +11 -20
- package/src/lib/compiler/resource-inliner.js.map +1 -1
- package/src/lib/compiler/style-ast.d.ts +22 -1
- package/src/lib/compiler/style-ast.js +37 -20
- package/src/lib/compiler/style-ast.js.map +1 -1
- package/src/lib/compiler/type-elision.d.ts +4 -3
- package/src/lib/compiler/type-elision.js +11 -13
- package/src/lib/compiler/type-elision.js.map +1 -1
- package/src/lib/compiler/utils.d.ts +9 -7
- package/src/lib/compiler/utils.js +50 -11
- package/src/lib/compiler/utils.js.map +1 -1
- package/src/lib/compiler-plugin.js +1 -2
- package/src/lib/component-resolvers.js +1 -2
- package/src/lib/component-scanner.d.ts +101 -0
- package/src/lib/component-scanner.js +331 -0
- package/src/lib/component-scanner.js.map +1 -0
- package/src/lib/component-styles-plugin.d.ts +52 -0
- package/src/lib/component-styles-plugin.js +352 -0
- package/src/lib/component-styles-plugin.js.map +1 -0
- package/src/lib/compose-angular-plugins.d.ts +12 -0
- package/src/lib/compose-angular-plugins.js +30 -0
- package/src/lib/compose-angular-plugins.js.map +1 -0
- package/src/lib/dev-server-mode-plugin.d.ts +7 -0
- package/src/lib/dev-server-mode-plugin.js +22 -0
- package/src/lib/dev-server-mode-plugin.js.map +1 -0
- package/src/lib/encapsulation-plugin.js +1 -2
- package/src/lib/fast-compile-api.d.ts +62 -0
- package/src/lib/fast-compile-api.js +11 -0
- package/src/lib/fast-compile-api.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +6 -1
- package/src/lib/fast-compile-plugin.js +222 -117
- package/src/lib/fast-compile-plugin.js.map +1 -1
- package/src/lib/host.d.ts +3 -0
- package/src/lib/host.js +5 -4
- package/src/lib/host.js.map +1 -1
- package/src/lib/hot-update-batch.js +1 -2
- package/src/lib/live-reload-plugin.d.ts +8 -5
- package/src/lib/live-reload-plugin.js +45 -10
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +4 -1
- package/src/lib/ngp-compile-api.d.ts +55 -0
- package/src/lib/ngp-compile-api.js +11 -0
- package/src/lib/ngp-compile-api.js.map +1 -0
- package/src/lib/ngp-compile-plugin.d.ts +4 -0
- package/src/lib/ngp-compile-plugin.js +680 -0
- package/src/lib/ngp-compile-plugin.js.map +1 -0
- package/src/lib/ngtsc-compile-plugin.d.ts +23 -0
- package/src/lib/ngtsc-compile-plugin.js +780 -0
- package/src/lib/ngtsc-compile-plugin.js.map +1 -0
- package/src/lib/nx-folder-plugin.d.ts +6 -5
- package/src/lib/nx-folder-plugin.js +13 -9
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +6 -0
- package/src/lib/plugins/file-replacements.plugin.js +2 -2
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +5 -1
- package/src/lib/router-plugin.js +14 -6
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-preprocessor.js +1 -2
- package/src/lib/stylesheet-registry.js +1 -2
- package/src/lib/stylesheet-registry.js.map +1 -1
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +2 -3
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +1 -2
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/utils/compilation-shared.d.ts +1 -4
- package/src/lib/utils/compilation-shared.js +9 -8
- package/src/lib/utils/compilation-shared.js.map +1 -1
- package/src/lib/utils/css-extension-resolver.js +1 -2
- package/src/lib/utils/css-preprocessor-workers.js +1 -2
- package/src/lib/utils/debug-harness.js +1 -2
- package/src/lib/utils/debug-log-file.js +1 -2
- package/src/lib/utils/debug.js +1 -2
- package/src/lib/utils/devkit.js +2 -3
- package/src/lib/utils/hmr-component-updates.d.ts +7 -0
- package/src/lib/utils/hmr-component-updates.js +86 -0
- package/src/lib/utils/hmr-component-updates.js.map +1 -0
- package/src/lib/utils/jit-inline-styles.js +1 -2
- package/src/lib/utils/lsp-type-checker.d.ts +75 -0
- package/src/lib/utils/lsp-type-checker.js +532 -0
- package/src/lib/utils/lsp-type-checker.js.map +1 -0
- package/src/lib/utils/ngp-host-fs.d.ts +43 -0
- package/src/lib/utils/ngp-host-fs.js +128 -0
- package/src/lib/utils/ngp-host-fs.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +15 -8
- package/src/lib/utils/plugin-config.js +19 -7
- package/src/lib/utils/plugin-config.js.map +1 -1
- package/src/lib/utils/rolldown.js +1 -2
- package/src/lib/utils/safe-module-paths.js +1 -2
- package/src/lib/utils/stylesheet-warning.d.ts +2 -0
- package/src/lib/utils/stylesheet-warning.js +10 -0
- package/src/lib/utils/stylesheet-warning.js.map +1 -0
- package/src/lib/utils/transform-cache.js +1 -2
- package/src/lib/utils/transform-cache.js.map +1 -1
- package/src/lib/utils/tsconfig-resolver.js +2 -3
- package/src/lib/utils/virtual-ids.js +1 -2
- package/src/lib/utils/virtual-resources.js +1 -2
- package/src/lib/utils/virtual-resources.js.map +1 -1
- package/src/lib/virtual-modules-plugin.d.ts +11 -3
- package/src/lib/virtual-modules-plugin.js +70 -15
- package/src/lib/virtual-modules-plugin.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compilation-shared.js","names":[],"sources":["../../../../src/lib/utils/compilation-shared.ts"],"sourcesContent":["/**\n * Shared utilities used by both angular-vite-plugin.ts and\n * compilation-api/compilation-api-plugin.ts.\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { basename, isAbsolute, resolve } from 'node:path';\nimport { createHash } from 'node:crypto';\nimport { normalizePath } from 'vite';\n\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheetResult,\n rewriteRelativeCssImports,\n} from '../stylesheet-registry.js';\nimport { normalizeStylesheetDependencies } from '../style-preprocessor.js';\nimport type { StylePreprocessor } from '../style-preprocessor.js';\nimport type { FileReplacement } from '../plugins/file-replacements.plugin.js';\nimport { debugStylesV } from './debug.js';\n\nexport enum DiagnosticModes {\n None = 0,\n Option = 1 << 0,\n Syntactic = 1 << 1,\n Semantic = 1 << 2,\n All = Option | Syntactic | Semantic,\n}\n\nexport function injectViteIgnoreForHmrMetadata(code: string): string {\n let patched = code.replace(\n /\\bimport\\(([a-zA-Z_$][\\w$]*\\.\\u0275\\u0275getReplaceMetadataURL)/g,\n 'import(/* @vite-ignore */ $1',\n );\n\n if (patched === code) {\n patched = patched.replace(\n /import\\((\\S+getReplaceMetadataURL)/g,\n 'import(/* @vite-ignore */ $1',\n );\n }\n\n return patched;\n}\n\nexport function isIgnoredHmrFile(file: string): boolean {\n return file.endsWith('.tsbuildinfo');\n}\n\n/**\n * Convert Analog/Angular CLI-style file replacements into the flat record\n * expected by `AngularHostOptions.fileReplacements`.\n *\n * Only browser replacements (`{ replace, with }`) are converted. SSR-only\n * replacements (`{ replace, ssr }`) are left for the Vite runtime plugin to\n * handle — they should not be baked into the Angular compilation host because\n * that would apply them to both browser and server builds.\n *\n * Relative paths are resolved against `workspaceRoot` so that the host\n * receives the same absolute paths it would get from the Angular CLI.\n */\nexport function toAngularCompilationFileReplacements(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Record<string, string> | undefined {\n const mappedReplacements = replacements.flatMap((replacement) => {\n if (!('with' in replacement)) {\n return [];\n }\n\n return [\n [\n isAbsolute(replacement.replace)\n ? replacement.replace\n : resolve(workspaceRoot, replacement.replace),\n isAbsolute(replacement.with)\n ? replacement.with\n : resolve(workspaceRoot, replacement.with),\n ] as const,\n ];\n });\n\n return mappedReplacements.length\n ? Object.fromEntries(mappedReplacements)\n : undefined;\n}\n\n/**\n * Map Angular's `templateUpdates` (keyed by `encodedFilePath@ClassName`)\n * back to absolute file paths with their associated HMR code and component\n * class name.\n *\n * Angular's private Compilation API emits template update keys in the form\n * `encodeURIComponent(relativePath + '@' + className)`. We decode and resolve\n * them so the caller can look up updates by the same normalized absolute path\n * used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).\n */\nexport function mapTemplateUpdatesToFiles(\n templateUpdates: ReadonlyMap<string, string> | undefined,\n): Map<\n string,\n {\n className: string;\n code: string;\n }\n> {\n const updatesByFile = new Map<string, { className: string; code: string }>();\n\n templateUpdates?.forEach((code, encodedUpdateId) => {\n const [file, className = ''] =\n decodeURIComponent(encodedUpdateId).split('@');\n const resolvedFile = normalizePath(resolve(process.cwd(), file));\n\n updatesByFile.set(resolvedFile, {\n className,\n code,\n });\n });\n\n return updatesByFile;\n}\n\nexport function describeStylesheetContent(code: string): {\n length: number;\n digest: string;\n preview: string;\n} {\n return {\n length: code.length,\n digest: createHash('sha256').update(code).digest('hex').slice(0, 12),\n preview: code.replace(/\\s+/g, ' ').trim().slice(0, 160),\n };\n}\n\n/**\n * Refreshes any already-served stylesheet records that map back to a changed\n * source file.\n *\n * This is the critical bridge for externalized Angular component styles during\n * HMR. Angular's resource watcher can notice that `/src/...component.css`\n * changed before Angular recompilation has had a chance to repopulate the\n * stylesheet registry. If we emit a CSS update against the existing virtual\n * stylesheet id without first refreshing the registry content, the browser gets\n * a hot update containing stale CSS. By rewriting the existing served records\n * from disk up front, HMR always pushes the latest source content.\n */\nexport function refreshStylesheetRegistryForFile(\n file: string,\n stylesheetRegistry?: AnalogStylesheetRegistry,\n stylePreprocessor?: StylePreprocessor,\n): void {\n const normalizedFile = normalizePath(file.split('?')[0]);\n if (!stylesheetRegistry || !existsSync(normalizedFile)) {\n return;\n }\n\n const publicIds = stylesheetRegistry.getPublicIdsForSource(normalizedFile);\n if (publicIds.length === 0) {\n return;\n }\n\n const rawCss = readFileSync(normalizedFile, 'utf-8');\n const preprocessed = preprocessStylesheetResult(\n rawCss,\n normalizedFile,\n stylePreprocessor,\n );\n const servedCss = rewriteRelativeCssImports(\n preprocessed.code,\n normalizedFile,\n );\n\n for (const publicId of publicIds) {\n stylesheetRegistry.registerServedStylesheet(\n {\n publicId,\n sourcePath: normalizedFile,\n originalCode: rawCss,\n normalizedCode: servedCss,\n dependencies: normalizeStylesheetDependencies(\n preprocessed.dependencies,\n ),\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n },\n [\n normalizedFile,\n normalizePath(normalizedFile),\n basename(normalizedFile),\n normalizedFile.replace(/^\\//, ''),\n ],\n );\n }\n\n debugStylesV('stylesheet registry refreshed from source file', {\n file: normalizedFile,\n publicIds,\n dependencies: preprocessed.dependencies,\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n source: describeStylesheetContent(rawCss),\n served: describeStylesheetContent(servedCss),\n });\n}\n\n/**\n * Checks for vitest run from the command line\n * @returns boolean\n */\nexport function isTestWatchMode(args = process.argv): boolean {\n // vitest --run\n const hasRun = args.find((arg) => arg.includes('--run'));\n if (hasRun) {\n return false;\n }\n\n // vitest run\n if (args.includes('run')) {\n return false;\n }\n\n // vitest --no-run\n const hasNoRun = args.find((arg) => arg.includes('--no-run'));\n if (hasNoRun) {\n return true;\n }\n\n // check for --watch=false or --no-watch\n const hasWatch = args.find((arg) => arg.includes('watch'));\n if (hasWatch && ['false', 'no'].some((neg) => hasWatch.includes(neg))) {\n return false;\n }\n\n // check for --watch false\n const watchIndex = args.findIndex((arg) => arg.includes('watch'));\n const watchArg = args[watchIndex + 1];\n if (watchArg && watchArg === 'false') {\n return false;\n }\n\n return true;\n}\n\nexport function getBrowserModeCliOverride(\n args = process.argv.slice(2),\n): boolean | undefined {\n let enabled: boolean | undefined;\n\n for (let i = 0; i < args.length; i++) {\n if (args[i] === '--') {\n break;\n }\n\n const [flag, inlineValue] = args[i].split('=', 2);\n if (flag === '--no-browser' || flag === '--no-browser.enabled') {\n enabled = false;\n } else if (flag === '--browser' || flag === '--browser.enabled') {\n const value = inlineValue ?? args[i + 1];\n if (value === 'false' || (flag === '--browser' && value === 'no')) {\n enabled = false;\n } else if (\n flag === '--browser.enabled' ||\n value === undefined ||\n value.startsWith('-') ||\n value === 'true' ||\n value === 'yes'\n ) {\n enabled = true;\n }\n }\n }\n\n return enabled;\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAY,kBAAL,yBAAA,iBAAA;CACL,gBAAA,gBAAA,UAAA,KAAA;CACA,gBAAA,gBAAA,YAAA,KAAA;CACA,gBAAA,gBAAA,eAAA,KAAA;CACA,gBAAA,gBAAA,cAAA,KAAA;CACA,gBAAA,gBAAA,SAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,+BAA+B,MAAsB;CACnE,IAAI,UAAU,KAAK,QACjB,oEACA,8BACF;CAEA,IAAI,YAAY,MACd,UAAU,QAAQ,QAChB,uCACA,8BACF;CAGF,OAAO;AACT;AAEA,SAAgB,iBAAiB,MAAuB;CACtD,OAAO,KAAK,SAAS,cAAc;AACrC;;;;;;;;;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C,UAAU;OACL,IAAI,SAAS,eAAe,SAAS,qBAAqB;GAC/D,MAAM,QAAQ,eAAe,KAAK,IAAI;GACtC,IAAI,UAAU,WAAY,SAAS,eAAe,UAAU,MAC1D,UAAU;QACL,IACL,SAAS,uBACT,UAAU,KAAA,KACV,MAAM,WAAW,GAAG,KACpB,UAAU,UACV,UAAU,OAEV,UAAU;EAEd;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"compilation-shared.js","names":[],"sources":["../../../../src/lib/utils/compilation-shared.ts"],"sourcesContent":["/**\n * Shared utilities used by both angular-vite-plugin.ts and\n * compilation-api/compilation-api-plugin.ts.\n */\n\nimport { existsSync, readFileSync } from 'node:fs';\nimport { basename, isAbsolute, resolve } from 'node:path';\nimport { createHash } from 'node:crypto';\nimport { normalizePath } from 'vite';\n\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheetResult,\n rewriteRelativeCssImports,\n} from '../stylesheet-registry.js';\nimport { normalizeStylesheetDependencies } from '../style-preprocessor.js';\nimport type { StylePreprocessor } from '../style-preprocessor.js';\nimport type { FileReplacement } from '../plugins/file-replacements.plugin.js';\nimport { debugStylesV } from './debug.js';\n\nexport enum DiagnosticModes {\n None = 0,\n Option = 1 << 0,\n Syntactic = 1 << 1,\n Semantic = 1 << 2,\n All = Option | Syntactic | Semantic,\n}\n\nexport function injectViteIgnoreForHmrMetadata(code: string): string {\n let patched = code.replace(\n /\\bimport\\(([a-zA-Z_$][\\w$]*\\.\\u0275\\u0275getReplaceMetadataURL)/g,\n 'import(/* @vite-ignore */ $1',\n );\n\n if (patched === code) {\n patched = patched.replace(\n /import\\((\\S+getReplaceMetadataURL)/g,\n 'import(/* @vite-ignore */ $1',\n );\n }\n\n return patched;\n}\n\nexport function isIgnoredHmrFile(file: string): boolean {\n return file.endsWith('.tsbuildinfo');\n}\n\n/**\n * Convert Analog/Angular CLI-style file replacements into the flat record\n * expected by `AngularHostOptions.fileReplacements`.\n *\n * Only browser replacements (`{ replace, with }`) are converted. SSR-only\n * replacements (`{ replace, ssr }`) are left for the Vite runtime plugin to\n * handle — they should not be baked into the Angular compilation host because\n * that would apply them to both browser and server builds.\n *\n * Relative paths are resolved against `workspaceRoot` so that the host\n * receives the same absolute paths it would get from the Angular CLI.\n */\nexport function toAngularCompilationFileReplacements(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Record<string, string> | undefined {\n const mappedReplacements = replacements.flatMap((replacement) => {\n if (!('with' in replacement)) {\n return [];\n }\n\n return [\n [\n isAbsolute(replacement.replace)\n ? replacement.replace\n : resolve(workspaceRoot, replacement.replace),\n isAbsolute(replacement.with)\n ? replacement.with\n : resolve(workspaceRoot, replacement.with),\n ] as const,\n ];\n });\n\n return mappedReplacements.length\n ? Object.fromEntries(mappedReplacements)\n : undefined;\n}\n\n/**\n * Map Angular's `templateUpdates` (keyed by `encodedFilePath@ClassName`)\n * back to absolute file paths with their associated HMR code and component\n * class name.\n *\n * Angular's private Compilation API emits template update keys in the form\n * `encodeURIComponent(relativePath + '@' + className)`. We decode and resolve\n * them so the caller can look up updates by the same normalized absolute path\n * used elsewhere in the plugin (`outputFiles`, `classNames`, etc.).\n */\nexport function mapTemplateUpdatesToFiles(\n templateUpdates: ReadonlyMap<string, string> | undefined,\n): Map<string, Map<string, string>> {\n const updatesByFile = new Map<string, Map<string, string>>();\n\n templateUpdates?.forEach((code, encodedUpdateId) => {\n const [file, className = ''] =\n decodeURIComponent(encodedUpdateId).split('@');\n const resolvedFile = normalizePath(resolve(process.cwd(), file));\n\n let fileUpdates = updatesByFile.get(resolvedFile);\n if (!fileUpdates) {\n fileUpdates = new Map<string, string>();\n updatesByFile.set(resolvedFile, fileUpdates);\n }\n fileUpdates.set(className, code);\n });\n\n return updatesByFile;\n}\n\nexport function describeStylesheetContent(code: string): {\n length: number;\n digest: string;\n preview: string;\n} {\n return {\n length: code.length,\n digest: createHash('sha256').update(code).digest('hex').slice(0, 12),\n preview: code.replace(/\\s+/g, ' ').trim().slice(0, 160),\n };\n}\n\n/**\n * Refreshes any already-served stylesheet records that map back to a changed\n * source file.\n *\n * This is the critical bridge for externalized Angular component styles during\n * HMR. Angular's resource watcher can notice that `/src/...component.css`\n * changed before Angular recompilation has had a chance to repopulate the\n * stylesheet registry. If we emit a CSS update against the existing virtual\n * stylesheet id without first refreshing the registry content, the browser gets\n * a hot update containing stale CSS. By rewriting the existing served records\n * from disk up front, HMR always pushes the latest source content.\n */\nexport function refreshStylesheetRegistryForFile(\n file: string,\n stylesheetRegistry?: AnalogStylesheetRegistry,\n stylePreprocessor?: StylePreprocessor,\n): void {\n const normalizedFile = normalizePath(file.split('?')[0]);\n if (!stylesheetRegistry || !existsSync(normalizedFile)) {\n return;\n }\n\n const publicIds = stylesheetRegistry.getPublicIdsForSource(normalizedFile);\n if (publicIds.length === 0) {\n return;\n }\n\n const rawCss = readFileSync(normalizedFile, 'utf-8');\n const preprocessed = preprocessStylesheetResult(\n rawCss,\n normalizedFile,\n stylePreprocessor,\n );\n const servedCss = rewriteRelativeCssImports(\n preprocessed.code,\n normalizedFile,\n );\n\n for (const publicId of publicIds) {\n stylesheetRegistry.registerServedStylesheet(\n {\n publicId,\n sourcePath: normalizedFile,\n originalCode: rawCss,\n normalizedCode: servedCss,\n dependencies: normalizeStylesheetDependencies(\n preprocessed.dependencies,\n ),\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n },\n [\n normalizedFile,\n normalizePath(normalizedFile),\n basename(normalizedFile),\n normalizedFile.replace(/^\\//, ''),\n ],\n );\n }\n\n debugStylesV('stylesheet registry refreshed from source file', {\n file: normalizedFile,\n publicIds,\n dependencies: preprocessed.dependencies,\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n source: describeStylesheetContent(rawCss),\n served: describeStylesheetContent(servedCss),\n });\n}\n\n/**\n * Checks for vitest run from the command line\n * @returns boolean\n */\nexport function isTestWatchMode(args = process.argv): boolean {\n // vitest --run\n const hasRun = args.find((arg) => arg.includes('--run'));\n if (hasRun) {\n return false;\n }\n\n // vitest run\n if (args.includes('run')) {\n return false;\n }\n\n // vitest --no-run\n const hasNoRun = args.find((arg) => arg.includes('--no-run'));\n if (hasNoRun) {\n return true;\n }\n\n // check for --watch=false or --no-watch\n const hasWatch = args.find((arg) => arg.includes('watch'));\n if (hasWatch && ['false', 'no'].some((neg) => hasWatch.includes(neg))) {\n return false;\n }\n\n // check for --watch false\n const watchIndex = args.findIndex((arg) => arg.includes('watch'));\n const watchArg = args[watchIndex + 1];\n if (watchArg && watchArg === 'false') {\n return false;\n }\n\n return true;\n}\n\nexport function getBrowserModeCliOverride(\n args = process.argv.slice(2),\n): boolean | undefined {\n let enabled: boolean | undefined;\n\n for (let i = 0; i < args.length; i++) {\n if (args[i] === '--') {\n break;\n }\n\n const [flag, inlineValue] = args[i].split('=', 2);\n if (flag === '--no-browser' || flag === '--no-browser.enabled') {\n enabled = false;\n } else if (flag === '--browser' || flag === '--browser.enabled') {\n const value = inlineValue ?? args[i + 1];\n if (value === 'false' || (flag === '--browser' && value === 'no')) {\n enabled = false;\n } else if (\n flag === '--browser.enabled' ||\n value === undefined ||\n value.startsWith('-') ||\n value === 'true' ||\n value === 'yes'\n ) {\n enabled = true;\n }\n }\n }\n\n return enabled;\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAY,kBAAL,yBAAA,iBAAA;CACL,gBAAA,gBAAA,UAAA,KAAA;CACA,gBAAA,gBAAA,YAAA,KAAA;CACA,gBAAA,gBAAA,eAAA,KAAA;CACA,gBAAA,gBAAA,cAAA,KAAA;CACA,gBAAA,gBAAA,SAAA,KAAA;;AACF,EAAA,CAAA,CAAA;AAEA,SAAgB,+BAA+B,MAAsB;CACnE,IAAI,UAAU,KAAK,QACjB,oEACA,8BACF;CAEA,IAAI,YAAY,MACd,UAAU,QAAQ,QAChB,uCACA,8BACF;CAGF,OAAO;AACT;AAEA,SAAgB,iBAAiB,MAAuB;CACtD,OAAO,KAAK,SAAS,cAAc;AACrC;;;;;;;;;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MACd;EAGF,MAAM,CAAC,MAAM,eAAe,KAAK,EAAE,CAAC,MAAM,KAAK,CAAC;EAChD,IAAI,SAAS,kBAAkB,SAAS,wBACtC,UAAU;OACL,IAAI,SAAS,eAAe,SAAS,qBAAqB;GAC/D,MAAM,QAAQ,eAAe,KAAK,IAAI;GACtC,IAAI,UAAU,WAAY,SAAS,eAAe,UAAU,MAC1D,UAAU;QACL,IACL,SAAS,uBACT,UAAU,KAAA,KACV,MAAM,WAAW,GAAG,KACpB,UAAU,UACV,UAAU,OAEV,UAAU;EAEd;CACF;CAEA,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as vite from "vite";
|
|
2
|
-
|
|
2
|
+
// packages/vite-plugin-angular/src/lib/utils/css-extension-resolver.ts
|
|
3
3
|
/**
|
|
4
4
|
* Resolves bare-specifier `.css` imports with the `style` package-export
|
|
5
5
|
* condition in scope, without leaking `style` into Vite's global
|
|
@@ -67,7 +67,6 @@ function cssExtensionStyleResolverPlugin() {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
//#endregion
|
|
71
70
|
export { cssExtensionStyleResolverPlugin };
|
|
72
71
|
|
|
73
72
|
//# sourceMappingURL=css-extension-resolver.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/vite-plugin-angular/src/lib/utils/css-preprocessor-workers.ts
|
|
2
2
|
var PREPROCESSOR_PROCESS_RE = /sass-embedded|dart-sass|sass\.snapshot|[\\/]lessc(?:$|[\s])|[\\/]stylus(?:$|[\s])/i;
|
|
3
3
|
function getActiveHandles() {
|
|
4
4
|
const getHandles = process._getActiveHandles;
|
|
@@ -23,7 +23,6 @@ function releaseCssPreprocessorWorkers() {
|
|
|
23
23
|
handle.unref?.();
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { releaseCssPreprocessorWorkers };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=css-preprocessor-workers.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DEBUG_LOG_DIR, DEBUG_LOG_FILENAME, wrapInstancesForFileLog, wrapInstancesForScopedFileLog } from "./debug-log-file.js";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { enable } from "obug";
|
|
4
|
-
|
|
4
|
+
// packages/vite-plugin-angular/src/lib/utils/debug-harness.ts
|
|
5
5
|
/**
|
|
6
6
|
* Duplicates of this file (keep in sync):
|
|
7
7
|
* packages/platform/src/lib/utils/debug-harness.ts
|
|
@@ -82,7 +82,6 @@ function createDebugHarness(config) {
|
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
//#endregion
|
|
86
85
|
export { createDebugHarness };
|
|
87
86
|
|
|
88
87
|
//# sourceMappingURL=debug-harness.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { format } from "node:util";
|
|
4
|
-
|
|
4
|
+
// packages/vite-plugin-angular/src/lib/utils/debug-log-file.ts
|
|
5
5
|
/**
|
|
6
6
|
* Duplicates of this file (keep in sync):
|
|
7
7
|
* packages/platform/src/lib/utils/debug-log-file.ts
|
|
@@ -51,7 +51,6 @@ function wrapInstancesForScopedFileLog(instances, dirPath) {
|
|
|
51
51
|
wrapLog(dbg, scopedPath);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
//#endregion
|
|
55
54
|
export { DEBUG_LOG_DIR, DEBUG_LOG_FILENAME, wrapInstancesForFileLog, wrapInstancesForScopedFileLog };
|
|
56
55
|
|
|
57
56
|
//# sourceMappingURL=debug-log-file.js.map
|
package/src/lib/utils/debug.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createDebugHarness } from "./debug-harness.js";
|
|
2
2
|
import { createDebug } from "obug";
|
|
3
|
-
|
|
3
|
+
// packages/vite-plugin-angular/src/lib/utils/debug.ts
|
|
4
4
|
var debugHmr = createDebug("analog:angular:hmr");
|
|
5
5
|
var debugStyles = createDebug("analog:angular:styles");
|
|
6
6
|
var debugCompiler = createDebug("analog:angular:compiler");
|
|
@@ -29,7 +29,6 @@ var harness = createDebugHarness({
|
|
|
29
29
|
var applyDebugOption = harness.applyDebugOption;
|
|
30
30
|
var activateDeferredDebug = harness.activateDeferredDebug;
|
|
31
31
|
harness._resetDeferredDebug;
|
|
32
|
-
//#endregion
|
|
33
32
|
export { activateDeferredDebug, applyDebugOption, debugCompilationApi, debugCompiler, debugCompilerV, debugEmit, debugEmitV, debugHmr, debugHmrV, debugStylePipeline, debugStyles, debugStylesV };
|
|
34
33
|
|
|
35
34
|
//# sourceMappingURL=debug.js.map
|
package/src/lib/utils/devkit.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { dirname, join } from "node:path";
|
|
2
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
3
|
import { VERSION } from "@angular/compiler-cli";
|
|
4
|
-
|
|
4
|
+
// packages/vite-plugin-angular/src/lib/utils/devkit.ts
|
|
5
5
|
var require = createRequire(import.meta.url);
|
|
6
6
|
var angularMajor = Number(VERSION.major);
|
|
7
7
|
var angularMinor = Number(VERSION.minor);
|
|
@@ -51,7 +51,6 @@ var JavaScriptTransformer = class extends AngularJavaScriptTransformerClass {
|
|
|
51
51
|
return super.close();
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
//#endregion
|
|
55
54
|
export { JavaScriptTransformer, SourceFileCache, angularFullVersion, angularMajor, angularMinor, angularPatch, createAngularCompilation, createJitResourceTransformer };
|
|
56
55
|
|
|
57
56
|
//# sourceMappingURL=devkit.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Applies the Angular CLI's HMR rule to an edited file. Returns the
|
|
3
|
+
* components whose `template`, `templateUrl`, `styles`, `styleUrl` or
|
|
4
|
+
* `stylesUrl` fields are the only changes, or `null` when the edit
|
|
5
|
+
* needs a full reload.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findHmrComponentUpdates(filename: string, staleText: string, updatedText: string, components: ReadonlySet<string>): string[] | null;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
// packages/vite-plugin-angular/src/lib/utils/hmr-component-updates.ts
|
|
3
|
+
var HMR_FIELDS = /* @__PURE__ */ new Set([
|
|
4
|
+
"template",
|
|
5
|
+
"templateUrl",
|
|
6
|
+
"styles",
|
|
7
|
+
"styleUrl",
|
|
8
|
+
"stylesUrl"
|
|
9
|
+
]);
|
|
10
|
+
function parse(filename, text) {
|
|
11
|
+
const { program, errors } = parseSync(filename, text);
|
|
12
|
+
return errors.length ? null : {
|
|
13
|
+
text,
|
|
14
|
+
body: program.body
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function classOf(statement) {
|
|
18
|
+
if (statement.type === "ClassDeclaration") return statement;
|
|
19
|
+
return statement.declaration?.type === "ClassDeclaration" ? statement.declaration : void 0;
|
|
20
|
+
}
|
|
21
|
+
function statementStart(statement) {
|
|
22
|
+
return Math.min(statement.start, classOf(statement)?.decorators[0]?.start ?? statement.start);
|
|
23
|
+
}
|
|
24
|
+
function statementText(source, statement) {
|
|
25
|
+
return source.text.slice(statementStart(statement), statement.end);
|
|
26
|
+
}
|
|
27
|
+
function classHeader(source, statement, cls) {
|
|
28
|
+
const [decorator] = cls.decorators;
|
|
29
|
+
return source.text.slice(statementStart(statement), decorator.start) + source.text.slice(decorator.end, cls.body.start) + source.text.slice(cls.body.end, statement.end);
|
|
30
|
+
}
|
|
31
|
+
function decoratorMetadata(source, decorator) {
|
|
32
|
+
const call = decorator.expression;
|
|
33
|
+
const metadata = call.arguments?.[0];
|
|
34
|
+
if (call.arguments?.length !== 1 || metadata.type !== "ObjectExpression") return null;
|
|
35
|
+
const fields = [];
|
|
36
|
+
for (const property of metadata.properties) {
|
|
37
|
+
if (property.type !== "Property" || property.kind !== "init" || property.computed || property.shorthand || property.method) return null;
|
|
38
|
+
fields.push([String(property.key.name ?? property.key.value), source.text.slice(property.value.start, property.value.end)]);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
callee: source.text.slice(call.callee.start, call.callee.end),
|
|
42
|
+
fields
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function fieldsText(fields, hmr) {
|
|
46
|
+
const selected = fields.filter(([name]) => HMR_FIELDS.has(name) === hmr);
|
|
47
|
+
if (hmr) selected.sort(([a], [b]) => a.localeCompare(b));
|
|
48
|
+
return JSON.stringify(selected);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Whether a component changed only in its HMR fields, or `null` when
|
|
52
|
+
* anything else in the statement changed.
|
|
53
|
+
*/
|
|
54
|
+
function componentChanged(stale, staleStatement, updated, updatedStatement) {
|
|
55
|
+
const staleClass = classOf(staleStatement);
|
|
56
|
+
const updatedClass = classOf(updatedStatement);
|
|
57
|
+
if (staleStatement.type !== updatedStatement.type || staleClass?.decorators.length !== 1 || updatedClass.decorators.length !== 1 || classHeader(stale, staleStatement, staleClass) !== classHeader(updated, updatedStatement, updatedClass) || stale.text.slice(staleClass.body.start, staleClass.body.end) !== updated.text.slice(updatedClass.body.start, updatedClass.body.end)) return null;
|
|
58
|
+
const staleMeta = decoratorMetadata(stale, staleClass.decorators[0]);
|
|
59
|
+
const updatedMeta = decoratorMetadata(updated, updatedClass.decorators[0]);
|
|
60
|
+
if (!staleMeta || !updatedMeta || staleMeta.callee !== updatedMeta.callee || fieldsText(staleMeta.fields, false) !== fieldsText(updatedMeta.fields, false)) return null;
|
|
61
|
+
return fieldsText(staleMeta.fields, true) !== fieldsText(updatedMeta.fields, true);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Applies the Angular CLI's HMR rule to an edited file. Returns the
|
|
65
|
+
* components whose `template`, `templateUrl`, `styles`, `styleUrl` or
|
|
66
|
+
* `stylesUrl` fields are the only changes, or `null` when the edit
|
|
67
|
+
* needs a full reload.
|
|
68
|
+
*/
|
|
69
|
+
function findHmrComponentUpdates(filename, staleText, updatedText, components) {
|
|
70
|
+
const stale = parse(filename, staleText);
|
|
71
|
+
const updated = parse(filename, updatedText);
|
|
72
|
+
if (!stale || !updated || stale.body.length !== updated.body.length) return null;
|
|
73
|
+
const changed = [];
|
|
74
|
+
for (let i = 0; i < updated.body.length; i++) {
|
|
75
|
+
const name = classOf(updated.body[i])?.id?.name;
|
|
76
|
+
if (name && components.has(name)) {
|
|
77
|
+
const result = componentChanged(stale, stale.body[i], updated, updated.body[i]);
|
|
78
|
+
if (result === null) return null;
|
|
79
|
+
if (result) changed.push(name);
|
|
80
|
+
} else if (statementText(stale, stale.body[i]) !== statementText(updated, updated.body[i])) return null;
|
|
81
|
+
}
|
|
82
|
+
return changed.length ? changed : null;
|
|
83
|
+
}
|
|
84
|
+
export { findHmrComponentUpdates };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=hmr-component-updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr-component-updates.js","names":[],"sources":["../../../../src/lib/utils/hmr-component-updates.ts"],"sourcesContent":["import { parseSync } from 'oxc-parser';\n\n// Component metadata fields the Angular CLI updates in place\nconst HMR_FIELDS = new Set([\n 'template',\n 'templateUrl',\n 'styles',\n 'styleUrl',\n 'stylesUrl',\n]);\n\ninterface Source {\n text: string;\n body: any[];\n}\n\ntype Fields = [name: string, value: string][];\n\nfunction parse(filename: string, text: string): Source | null {\n const { program, errors } = parseSync(filename, text);\n return errors.length ? null : { text, body: program.body };\n}\n\nfunction classOf(statement: any) {\n if (statement.type === 'ClassDeclaration') return statement;\n return statement.declaration?.type === 'ClassDeclaration'\n ? statement.declaration\n : undefined;\n}\n\n// Decorators written before `export` fall outside the statement span\nfunction statementStart(statement: any) {\n return Math.min(\n statement.start,\n classOf(statement)?.decorators[0]?.start ?? statement.start,\n );\n}\n\nfunction statementText(source: Source, statement: any) {\n return source.text.slice(statementStart(statement), statement.end);\n}\n\n// The statement without its decorator and class body\nfunction classHeader(source: Source, statement: any, cls: any) {\n const [decorator] = cls.decorators;\n return (\n source.text.slice(statementStart(statement), decorator.start) +\n source.text.slice(decorator.end, cls.body.start) +\n source.text.slice(cls.body.end, statement.end)\n );\n}\n\nfunction decoratorMetadata(source: Source, decorator: any) {\n const call = decorator.expression;\n const metadata = call.arguments?.[0];\n if (call.arguments?.length !== 1 || metadata.type !== 'ObjectExpression') {\n return null;\n }\n const fields: Fields = [];\n for (const property of metadata.properties) {\n if (\n property.type !== 'Property' ||\n property.kind !== 'init' ||\n property.computed ||\n property.shorthand ||\n property.method\n ) {\n return null;\n }\n fields.push([\n String(property.key.name ?? property.key.value),\n source.text.slice(property.value.start, property.value.end),\n ]);\n }\n return {\n callee: source.text.slice(call.callee.start, call.callee.end),\n fields,\n };\n}\n\nfunction fieldsText(fields: Fields, hmr: boolean) {\n const selected = fields.filter(([name]) => HMR_FIELDS.has(name) === hmr);\n // HMR fields can move; other fields must keep their order\n if (hmr) selected.sort(([a], [b]) => a.localeCompare(b));\n return JSON.stringify(selected);\n}\n\n/**\n * Whether a component changed only in its HMR fields, or `null` when\n * anything else in the statement changed.\n */\nfunction componentChanged(\n stale: Source,\n staleStatement: any,\n updated: Source,\n updatedStatement: any,\n): boolean | null {\n const staleClass = classOf(staleStatement);\n const updatedClass = classOf(updatedStatement);\n if (\n staleStatement.type !== updatedStatement.type ||\n staleClass?.decorators.length !== 1 ||\n updatedClass.decorators.length !== 1 ||\n classHeader(stale, staleStatement, staleClass) !==\n classHeader(updated, updatedStatement, updatedClass) ||\n stale.text.slice(staleClass.body.start, staleClass.body.end) !==\n updated.text.slice(updatedClass.body.start, updatedClass.body.end)\n ) {\n return null;\n }\n const staleMeta = decoratorMetadata(stale, staleClass.decorators[0]);\n const updatedMeta = decoratorMetadata(updated, updatedClass.decorators[0]);\n if (\n !staleMeta ||\n !updatedMeta ||\n staleMeta.callee !== updatedMeta.callee ||\n fieldsText(staleMeta.fields, false) !==\n fieldsText(updatedMeta.fields, false)\n ) {\n return null;\n }\n return (\n fieldsText(staleMeta.fields, true) !== fieldsText(updatedMeta.fields, true)\n );\n}\n\n/**\n * Applies the Angular CLI's HMR rule to an edited file. Returns the\n * components whose `template`, `templateUrl`, `styles`, `styleUrl` or\n * `stylesUrl` fields are the only changes, or `null` when the edit\n * needs a full reload.\n */\nexport function findHmrComponentUpdates(\n filename: string,\n staleText: string,\n updatedText: string,\n components: ReadonlySet<string>,\n): string[] | null {\n const stale = parse(filename, staleText);\n const updated = parse(filename, updatedText);\n if (!stale || !updated || stale.body.length !== updated.body.length) {\n return null;\n }\n const changed: string[] = [];\n for (let i = 0; i < updated.body.length; i++) {\n const name = classOf(updated.body[i])?.id?.name;\n if (name && components.has(name)) {\n const result = componentChanged(\n stale,\n stale.body[i],\n updated,\n updated.body[i],\n );\n if (result === null) return null;\n if (result) changed.push(name);\n } else if (\n statementText(stale, stale.body[i]) !==\n statementText(updated, updated.body[i])\n ) {\n return null;\n }\n }\n return changed.length ? changed : null;\n}\n"],"mappings":";;AAGA,IAAM,6BAAa,IAAI,IAAI;CACzB;CACA;CACA;CACA;CACA;AACF,CAAC;AASD,SAAS,MAAM,UAAkB,MAA6B;CAC5D,MAAM,EAAE,SAAS,WAAW,UAAU,UAAU,IAAI;CACpD,OAAO,OAAO,SAAS,OAAO;EAAE;EAAM,MAAM,QAAQ;CAAK;AAC3D;AAEA,SAAS,QAAQ,WAAgB;CAC/B,IAAI,UAAU,SAAS,oBAAoB,OAAO;CAClD,OAAO,UAAU,aAAa,SAAS,qBACnC,UAAU,cACV,KAAA;AACN;AAGA,SAAS,eAAe,WAAgB;CACtC,OAAO,KAAK,IACV,UAAU,OACV,QAAQ,SAAS,CAAC,EAAE,WAAW,EAAE,EAAE,SAAS,UAAU,KACxD;AACF;AAEA,SAAS,cAAc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-1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
|
|
2
|
+
// packages/vite-plugin-angular/src/lib/utils/jit-inline-styles.ts
|
|
3
3
|
var JIT_INLINE_STYLE_PREFIX = "virtual:angular:jit:style:inline;";
|
|
4
4
|
var inlineStyles = /* @__PURE__ */ new Map();
|
|
5
5
|
function toJitInlineStyleId(encodedStyles, isTest) {
|
|
@@ -14,7 +14,6 @@ function getJitInlineStyles(idSuffix) {
|
|
|
14
14
|
function hashJitInlineStyles(encodedStyles) {
|
|
15
15
|
return createHash("sha256").update(encodedStyles).digest("hex").slice(0, 16);
|
|
16
16
|
}
|
|
17
|
-
//#endregion
|
|
18
17
|
export { JIT_INLINE_STYLE_PREFIX, getJitInlineStyles, hashJitInlineStyles, toJitInlineStyleId };
|
|
19
18
|
|
|
20
19
|
//# sourceMappingURL=jit-inline-styles.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface TcbTemplateSource {
|
|
2
|
+
templateFile?: string;
|
|
3
|
+
templateExpression?: {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
type TemplateSources = Record<string, TcbTemplateSource>;
|
|
9
|
+
interface TcbLineRange {
|
|
10
|
+
startLine: number;
|
|
11
|
+
endLine: number;
|
|
12
|
+
filePath: string;
|
|
13
|
+
sourceCode: string;
|
|
14
|
+
templateSources: TemplateSources;
|
|
15
|
+
}
|
|
16
|
+
/** NGP's footer comment mapping TCB ids to the template they were generated from. */
|
|
17
|
+
export declare const TCB_TEMPLATE_SOURCES_PREFIX = "ngp-tcb-template-sources:";
|
|
18
|
+
export declare function readSpanComment(value: string): {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
} | null;
|
|
22
|
+
export type TypeCheckerOption = "tsgo" | "tsrs" | {
|
|
23
|
+
command: string;
|
|
24
|
+
args?: string[];
|
|
25
|
+
};
|
|
26
|
+
interface TypeCheckerCommand {
|
|
27
|
+
command: string;
|
|
28
|
+
args: string[];
|
|
29
|
+
}
|
|
30
|
+
/** LSP `FileChangeType`: 1 created, 2 changed, 3 deleted. */
|
|
31
|
+
export type FileChangeType = 1 | 2 | 3;
|
|
32
|
+
/** A reported location, with a one-based line and character. */
|
|
33
|
+
export interface SourceLocation {
|
|
34
|
+
file: string;
|
|
35
|
+
line: number;
|
|
36
|
+
character: number;
|
|
37
|
+
}
|
|
38
|
+
/** Hooks for checking files that don't exist on disk. */
|
|
39
|
+
export interface LspTypeCheckerHost {
|
|
40
|
+
/**
|
|
41
|
+
* The text of files that exist only in memory, by normalized path. They're
|
|
42
|
+
* opened before any check, so imports of them resolve.
|
|
43
|
+
*/
|
|
44
|
+
inMemoryFiles(): ReadonlyMap<string, string>;
|
|
45
|
+
/** Maps a reported location to the source it was generated from. */
|
|
46
|
+
mapLocation(location: SourceLocation): SourceLocation;
|
|
47
|
+
}
|
|
48
|
+
export declare function resolveTypeChecker(tsconfig: string, option: TypeCheckerOption): TypeCheckerCommand;
|
|
49
|
+
export declare class LspTypeChecker {
|
|
50
|
+
private readonly host?;
|
|
51
|
+
private proc;
|
|
52
|
+
private seq;
|
|
53
|
+
private pending;
|
|
54
|
+
private versions;
|
|
55
|
+
private queued;
|
|
56
|
+
/** The text last sent for each open in-memory file. */
|
|
57
|
+
private inMemoryText;
|
|
58
|
+
private buffer;
|
|
59
|
+
private exitError;
|
|
60
|
+
readonly ready: Promise<void>;
|
|
61
|
+
constructor(tsconfig: string, option?: TypeCheckerOption, host?: LspTypeCheckerHost);
|
|
62
|
+
private onData;
|
|
63
|
+
private send;
|
|
64
|
+
private notify;
|
|
65
|
+
private request;
|
|
66
|
+
updateDocument(filePath: string, text: string);
|
|
67
|
+
checkFile(filePath: string, sourceLineCount?: number, lines?: string[], tcbRanges?: TcbLineRange[], inMemory?: boolean): Promise<string[]>;
|
|
68
|
+
private formatLocation;
|
|
69
|
+
/** Reports a change on disk; an open copy is closed so the checker rereads the file. */
|
|
70
|
+
notifyFileChanged(filePath: string, type: FileChangeType);
|
|
71
|
+
queueFile(filePath: string, sourceCode: string, tcbCode?: string | null);
|
|
72
|
+
flushQueue(watchMode?: boolean): Promise<string[]>;
|
|
73
|
+
close();
|
|
74
|
+
}
|
|
75
|
+
export {};
|