@analogjs/vite-plugin-angular 3.0.0-alpha.9 → 3.0.0-alpha.90
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/README.md +121 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/migrations/migrations.json +9 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
- package/package.json +49 -8
- package/src/index.d.ts +7 -2
- package/src/index.js +3 -1
- package/src/index.js.map +1 -1
- package/src/lib/analog-plugin-interop.d.ts +78 -0
- package/src/lib/analog-plugin-interop.js +97 -0
- package/src/lib/analog-plugin-interop.js.map +1 -0
- package/src/lib/angular-build-optimizer-plugin.d.ts +8 -4
- package/src/lib/angular-build-optimizer-plugin.js +66 -31
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +3 -3
- package/src/lib/angular-jit-plugin.js +28 -6
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +79 -69
- package/src/lib/angular-vite-plugin.js +774 -352
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +26 -21
- package/src/lib/angular-vitest-plugin.js +34 -25
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compilation-api/compilation-api-plugin.d.ts +24 -0
- package/src/lib/compilation-api/compilation-api-plugin.js +547 -0
- package/src/lib/compilation-api/compilation-api-plugin.js.map +1 -0
- package/src/lib/compilation-api/index.d.ts +1 -0
- package/src/lib/compilation-api/index.js +1 -0
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +31 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +131 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +50 -0
- package/src/lib/compiler/compile.js +814 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +24 -0
- package/src/lib/compiler/constants.js +59 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +20 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +57 -0
- package/src/lib/compiler/defer.js +154 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +45 -0
- package/src/lib/compiler/dts-reader.js +395 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +69 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +8 -0
- package/src/lib/compiler/index.js +8 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +168 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +204 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +446 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +36 -0
- package/src/lib/compiler/metadata.js +710 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +56 -0
- package/src/lib/compiler/registry.js +176 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +43 -0
- package/src/lib/compiler/resource-inliner.js +230 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +9 -0
- package/src/lib/compiler/style-ast.js +54 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/type-elision.d.ts +28 -0
- package/src/lib/compiler/type-elision.js +211 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +40 -0
- package/src/lib/compiler/utils.js +76 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/compiler-plugin.d.ts +13 -12
- package/src/lib/compiler-plugin.js +18 -18
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +20 -4
- package/src/lib/component-resolvers.js +34 -20
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/encapsulation-plugin.d.ts +23 -0
- package/src/lib/encapsulation-plugin.js +68 -0
- package/src/lib/encapsulation-plugin.js.map +1 -0
- package/src/lib/fast-compile-plugin.d.ts +23 -0
- package/src/lib/fast-compile-plugin.js +433 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +59 -17
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +5 -5
- package/src/lib/live-reload-plugin.js +10 -0
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +9 -9
- package/src/lib/nx-folder-plugin.d.ts +5 -5
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
- package/src/lib/plugins/file-replacements.plugin.js +6 -1
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +1 -1
- package/src/lib/router-plugin.js +14 -2
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-preprocessor.d.ts +35 -0
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +74 -0
- package/src/lib/stylesheet-registry.js +174 -0
- package/src/lib/stylesheet-registry.js.map +1 -0
- package/src/lib/tools/package.json +1 -3
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +7 -5
- 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 +16 -19
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/utils/compilation-shared.d.ts +62 -0
- package/src/lib/utils/compilation-shared.js +138 -0
- package/src/lib/utils/compilation-shared.js.map +1 -0
- package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
- package/src/lib/utils/css-extension-resolver.d.ts +32 -0
- package/src/lib/utils/css-extension-resolver.js +73 -0
- package/src/lib/utils/css-extension-resolver.js.map +1 -0
- package/src/lib/utils/css-preprocessor-workers.d.ts +6 -0
- package/src/lib/utils/css-preprocessor-workers.js +29 -0
- package/src/lib/utils/css-preprocessor-workers.js.map +1 -0
- package/src/lib/utils/debug-harness.d.ts +23 -0
- package/src/lib/utils/debug-harness.js +88 -0
- package/src/lib/utils/debug-harness.js.map +1 -0
- package/src/lib/utils/debug-log-file.d.ts +5 -0
- package/src/lib/utils/debug-log-file.js +56 -0
- package/src/lib/utils/debug-log-file.js.map +1 -0
- package/src/lib/utils/debug.d.ts +26 -0
- package/src/lib/utils/debug.js +35 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +14 -6
- package/src/lib/utils/devkit.js +40 -2
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/hmr-candidates.d.ts +28 -28
- package/src/lib/utils/jit-inline-styles.d.ts +3 -0
- package/src/lib/utils/jit-inline-styles.js +16 -0
- package/src/lib/utils/jit-inline-styles.js.map +1 -0
- package/src/lib/utils/plugin-config.d.ts +41 -0
- package/src/lib/utils/plugin-config.js +85 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- package/src/lib/utils/rolldown.d.ts +1 -1
- package/src/lib/utils/rolldown.js.map +1 -1
- package/src/lib/utils/safe-module-paths.d.ts +16 -0
- package/src/lib/utils/safe-module-paths.js +29 -0
- package/src/lib/utils/safe-module-paths.js.map +1 -0
- package/src/lib/utils/source-file-cache.d.ts +8 -15
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/transform-cache.d.ts +43 -0
- package/src/lib/utils/transform-cache.js +97 -0
- package/src/lib/utils/transform-cache.js.map +1 -0
- package/src/lib/utils/tsconfig-resolver.d.ts +34 -0
- package/src/lib/utils/tsconfig-resolver.js +205 -0
- package/src/lib/utils/tsconfig-resolver.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +4 -0
- package/src/lib/utils/virtual-ids.js +23 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +19 -0
- package/src/lib/utils/virtual-resources.js +38 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
- package/src/lib/virtual-modules-plugin.d.ts +5 -0
- package/src/lib/virtual-modules-plugin.js +23 -0
- package/src/lib/virtual-modules-plugin.js.map +1 -0
- package/src/test-setup.d.ts +2 -0
- package/setup-vitest.d.ts +0 -4
- package/setup-vitest.js +0 -176
- package/setup-vitest.js.map +0 -1
- package/src/lib/tools/src/index.d.ts +0 -0
package/src/lib/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","names":[],"sources":["../../../../../packages/vite-plugin-angular/src/lib/host.ts"],"sourcesContent":["import type { CompilerHost } from '@angular/compiler-cli';\nimport { normalizePath } from 'vite';\n\nimport * as ts from 'typescript';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport type { SourceFileCache } from './utils/source-file-cache.js';\n\nexport function augmentHostWithResources(\n host: ts.CompilerHost,\n transform: (\n code: string,\n id: string,\n options?: { ssr?: boolean },\n ) => ReturnType<any> | null,\n options: {\n inlineStylesExtension: string;\n isProd?: boolean;\n inlineComponentStyles?: Map<string, string>;\n externalComponentStyles?: Map<string, string>;\n sourceFileCache?: SourceFileCache;\n },\n): void {\n const resourceHost = host as CompilerHost;\n\n resourceHost.readResource = async function (fileName: string) {\n const filePath = normalizePath(fileName);\n\n const content = (this as any).readFile(filePath);\n\n if (content === undefined) {\n throw new Error('Unable to locate component resource: ' + fileName);\n }\n\n return content;\n };\n\n resourceHost.getModifiedResourceFiles = function () {\n return options?.sourceFileCache?.modifiedFiles;\n };\n\n resourceHost.transformResource = async function (data, context) {\n // Only style resources are supported currently\n if (context.type !== 'style') {\n return null;\n }\n\n if (options.inlineComponentStyles) {\n const id = createHash('sha256')\n .update(context.containingFile)\n .update(context.className)\n .update(String(context.order))\n .update(data)\n .digest('hex');\n const filename = id + '.' + options.inlineStylesExtension;\n options.inlineComponentStyles.set(filename, data);\n return { content: filename };\n }\n\n // Resource file only exists for external stylesheets\n const filename =\n context.resourceFile ??\n context.containingFile.replace(\n '.ts',\n `.${options?.inlineStylesExtension}`,\n );\n\n let stylesheetResult;\n\n try {\n stylesheetResult = await transform(data, `${filename}?direct`);\n } catch (e) {\n console.error(`${e}`);\n }\n\n return { content: stylesheetResult?.code || '' };\n };\n\n resourceHost.resourceNameToFileName = function (\n resourceName,\n containingFile,\n ) {\n const resolvedPath = path.join(path.dirname(containingFile), resourceName);\n\n // All resource names that have template file extensions are assumed to be templates\n if (!options.externalComponentStyles || !hasStyleExtension(resolvedPath)) {\n return resolvedPath;\n }\n\n // For external stylesheets, create a unique identifier and store the mapping\n let externalId = options.externalComponentStyles.get(resolvedPath);\n externalId ??= createHash('sha256').update(resolvedPath).digest('hex');\n\n const filename = externalId + path.extname(resolvedPath);\n\n options.externalComponentStyles.set(filename, resolvedPath);\n\n return filename;\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] =\n baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n file.version ??= createHash('sha256').update(file.text).digest('hex');\n }\n\n return files;\n };\n}\n\nexport function augmentHostWithCaching(\n host: ts.CompilerHost,\n cache: Map<string, ts.SourceFile>,\n): void {\n const baseGetSourceFile = host.getSourceFile;\n host.getSourceFile = function (\n fileName,\n languageVersion,\n onError,\n shouldCreateNewSourceFile,\n ...parameters\n ) {\n if (!shouldCreateNewSourceFile && cache.has(fileName)) {\n return cache.get(fileName);\n }\n\n const file = baseGetSourceFile.call(\n host,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n\n if (file) {\n cache.set(fileName, file);\n }\n\n return file;\n };\n}\n\nexport function mergeTransformers(\n first: ts.CustomTransformers,\n second: ts.CustomTransformers,\n): ts.CustomTransformers {\n const result: ts.CustomTransformers = {};\n\n if (first.before || second.before) {\n result.before = [...(first.before || []), ...(second.before || [])];\n }\n\n if (first.after || second.after) {\n result.after = [...(first.after || []), ...(second.after || [])];\n }\n\n if (first.afterDeclarations || second.afterDeclarations) {\n result.afterDeclarations = [\n ...(first.afterDeclarations || []),\n ...(second.afterDeclarations || []),\n ];\n }\n\n return result;\n}\n\nfunction hasStyleExtension(file: string): boolean {\n const extension = path.extname(file).toLowerCase();\n\n switch (extension) {\n case '.css':\n case '.scss':\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";;;;AASA,SAAgB,yBACd,MACA,WAKA,SAOM;CACN,MAAM,eAAe;AAErB,cAAa,eAAe,eAAgB,UAAkB;EAC5D,MAAM,WAAW,cAAc,SAAS;EAExC,MAAM,UAAW,KAAa,SAAS,SAAS;AAEhD,MAAI,YAAY,KAAA,EACd,OAAM,IAAI,MAAM,0CAA0C,SAAS;AAGrE,SAAO;;AA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K,CAAC,OAAO,MAAM;AAGvE,SAAO;;;AAIX,SAAgB,uBACd,MACA,OACM;CACN,MAAM,oBAAoB,KAAK;AAC/B,MAAK,gBAAgB,SACnB,UACA,iBACA,SACA,2BACA,GAAG,YACH;AACA,MAAI,CAAC,6BAA6B,MAAM,IAAI,SAAS,CACnD,QAAO,MAAM,IAAI,SAAS;EAG5B,MAAM,OAAO,kBAAkB,KAC7B,MACA,UACA,iBACA,SACA,MACA,GAAG,WACJ;AAED,MAAI,KACF,OAAM,IAAI,UAAU,KAAK;AAG3B,SAAO;;;AAIX,SAAgB,kBACd,OACA,QACuB;CACvB,MAAM,SAAgC,EAAE;AAExC,KAAI,MAAM,UAAU,OAAO,OACzB,QAAO,SAAS,CAAC,GAAI,MAAM,UAAU,EAAE,EAAG,GAAI,OAAO,UAAU,EAAE,CAAE;AAGrE,KAAI,MAAM,SAAS,OAAO,MACxB,QAAO,QAAQ,CAAC,GAAI,MAAM,SAAS,EAAE,EAAG,GAAI,OAAO,SAAS,EAAE,CAAE;AAGlE,KAAI,MAAM,qBAAqB,OAAO,kBACpC,QAAO,oBAAoB,CACzB,GAAI,MAAM,qBAAqB,EAAE,EACjC,GAAI,OAAO,qBAAqB,EAAE,CACnC;AAGH,QAAO;;AAGT,SAAS,kBAAkB,MAAuB;AAGhD,SAFkB,KAAK,QAAQ,KAAK,CAAC,aAAa,EAElD;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,QACE,QAAO"}
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../../../src/lib/host.ts"],"sourcesContent":["import type { CompilerHost } from '@angular/compiler-cli';\nimport { normalizePath } from 'vite';\n\nimport * as ts from 'typescript';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport {\n normalizeStylesheetDependencies,\n type StylePreprocessor,\n} from './style-preprocessor.js';\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheetResult,\n registerStylesheetContent,\n} from './stylesheet-registry.js';\nimport { debugStyles } from './utils/debug.js';\nimport type { SourceFileCache } from './utils/source-file-cache.js';\n\nexport function augmentHostWithResources(\n host: ts.CompilerHost,\n transform: (\n code: string,\n id: string,\n options?: { ssr?: boolean },\n ) => ReturnType<any> | null,\n options: {\n inlineStylesExtension: string;\n isProd?: boolean;\n stylesheetRegistry?: AnalogStylesheetRegistry;\n sourceFileCache?: SourceFileCache;\n stylePreprocessor?: StylePreprocessor;\n },\n): void {\n const resourceHost = host as CompilerHost;\n\n resourceHost.readResource = async function (fileName: string) {\n const filePath = normalizePath(fileName);\n\n const content = (this as any).readFile(filePath);\n\n if (content === undefined) {\n throw new Error('Unable to locate component resource: ' + fileName);\n }\n\n return content;\n };\n\n resourceHost.getModifiedResourceFiles = function () {\n return options?.sourceFileCache?.modifiedFiles;\n };\n\n resourceHost.transformResource = async function (data, context) {\n // Only style resources are supported currently\n if (context.type !== 'style') {\n return null;\n }\n\n const filename =\n context.resourceFile ??\n context.containingFile.replace(\n '.ts',\n `.${options?.inlineStylesExtension}`,\n );\n const preprocessed = preprocessStylesheetResult(\n data,\n filename,\n options.stylePreprocessor,\n {\n filename,\n containingFile: context.containingFile,\n resourceFile: context.resourceFile ?? undefined,\n className: context.className,\n order: context.order,\n inline: !context.resourceFile,\n },\n );\n\n // Externalized path: store preprocessed CSS for Vite's serve-time pipeline.\n // CSS must NOT be transformed here — the load hook returns it into\n // Vite's transform pipeline where PostCSS / Tailwind process it once.\n if (options.stylesheetRegistry) {\n const stylesheetId = registerStylesheetContent(\n options.stylesheetRegistry,\n {\n code: preprocessed.code,\n dependencies: normalizeStylesheetDependencies(\n preprocessed.dependencies,\n ),\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n containingFile: context.containingFile,\n className: context.className,\n order: context.order,\n inlineStylesExtension: options.inlineStylesExtension,\n resourceFile: context.resourceFile ?? undefined,\n },\n );\n debugStyles('NgtscProgram: stylesheet deferred to Vite pipeline', {\n stylesheetId,\n resourceFile: context.resourceFile ?? '(inline)',\n dependencies: preprocessed.dependencies,\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n });\n return { content: stylesheetId };\n }\n\n // Non-externalized: CSS is returned directly to the Angular compiler\n // and never re-enters Vite's pipeline, so transform eagerly.\n debugStyles('NgtscProgram: stylesheet processed inline via transform', {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n dataLength: preprocessed.code.length,\n });\n let stylesheetResult;\n\n try {\n stylesheetResult = await transform(\n preprocessed.code,\n `${filename}?direct`,\n );\n } catch (e) {\n debugStyles('NgtscProgram: stylesheet transform error', {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n error: String(e),\n });\n }\n\n if (!stylesheetResult?.code) {\n return null;\n }\n\n return { content: stylesheetResult.code };\n };\n\n resourceHost.resourceNameToFileName = function (\n resourceName,\n containingFile,\n fallbackResolve,\n ) {\n // Angular's fallbackResolve callback expects (resourceUrl, containingFile),\n // NOT (directory, resourceName). Use it correctly or fall back to\n // path.join for simple relative paths.\n let resolved: string | null = null;\n if (fallbackResolve) {\n resolved = fallbackResolve(path.dirname(containingFile), resourceName);\n }\n const resolvedPath = normalizePath(\n resolved ?? path.join(path.dirname(containingFile), resourceName),\n );\n\n // All resource names that have template file extensions are assumed to be templates\n if (!options.stylesheetRegistry || !hasStyleExtension(resolvedPath)) {\n return resolvedPath;\n }\n\n // Register the hash-based external mapping so the resolveId hook can\n // resolve Angular's compiled stylesheet references back to the source.\n const externalId = createHash('sha256').update(resolvedPath).digest('hex');\n const filename = externalId + path.extname(resolvedPath);\n\n options.stylesheetRegistry.registerExternalRequest(filename, resolvedPath);\n debugStyles('NgtscProgram: external stylesheet ID mapped for resolveId', {\n resourceName,\n resolvedPath,\n filename,\n });\n\n // Return the real path so Angular can read the file during analysis.\n // Previously, returning the hash-based filename caused \"Could not find\n // stylesheet file\" errors because the hash doesn't exist on disk,\n // preventing AOT compilation for any component with styleUrls. (#2293)\n return resolvedPath;\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] =\n baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n file.version ??= createHash('sha256').update(file.text).digest('hex');\n }\n\n return files;\n };\n}\n\nexport function augmentHostWithCaching(\n host: ts.CompilerHost,\n cache: Map<string, ts.SourceFile>,\n): void {\n const baseGetSourceFile = host.getSourceFile;\n host.getSourceFile = function (\n fileName,\n languageVersion,\n onError,\n shouldCreateNewSourceFile,\n ...parameters\n ) {\n if (!shouldCreateNewSourceFile && cache.has(fileName)) {\n return cache.get(fileName);\n }\n\n const file = baseGetSourceFile.call(\n host,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n\n if (file) {\n cache.set(fileName, file);\n }\n\n return file;\n };\n}\n\nexport function mergeTransformers(\n first: ts.CustomTransformers,\n second: ts.CustomTransformers,\n): ts.CustomTransformers {\n const result: ts.CustomTransformers = {};\n\n if (first.before || second.before) {\n result.before = [...(first.before || []), ...(second.before || [])];\n }\n\n if (first.after || second.after) {\n result.after = [...(first.after || []), ...(second.after || [])];\n }\n\n if (first.afterDeclarations || second.afterDeclarations) {\n result.afterDeclarations = [\n ...(first.afterDeclarations || []),\n ...(second.afterDeclarations || []),\n ];\n }\n\n return result;\n}\n\nfunction hasStyleExtension(file: string): boolean {\n const extension = path.extname(file).toLowerCase();\n\n switch (extension) {\n case '.css':\n case '.scss':\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,yBACd,MACA,WAKA,SAOM;CACN,MAAM,eAAe;AAErB,cAAa,eAAe,eAAgB,UAAkB;EAC5D,MAAM,WAAW,cAAc,SAAS;EAExC,MAAM,UAAW,KAAa,SAAS,SAAS;AAEhD,MAAI,YAAY,KAAA,EACd,OAAM,IAAI,MAAM,0CAA0C,SAAS;AAGrE,SAAO;;AAGT,cAAa,2BAA2B,WAAY;AAClD,SAAO,SAAS,iBAAiB;;AAGnC,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AAO,oBAAoB,CACzB,GAAI,MAAM,qBAAqB,EAAE,EACjC,GAAI,OAAO,qBAAqB,EAAE,CACnC;AAGH,QAAO;;AAGT,SAAS,kBAAkB,MAAuB;AAGhD,SAFkB,KAAK,QAAQ,KAAK,CAAC,aAAa,EAElD;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,QACE,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
import { EmitFileResult } from
|
|
3
|
-
export declare function liveReloadPlugin({ classNames, fileEmitter
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
import { EmitFileResult } from "./models.js";
|
|
3
|
+
export declare function liveReloadPlugin({ classNames, fileEmitter }: {
|
|
4
|
+
classNames: Map<string, string>;
|
|
5
|
+
fileEmitter: (file: string) => EmitFileResult | undefined;
|
|
6
6
|
}): Plugin;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { debugHmr } from "./utils/debug.js";
|
|
1
2
|
import { resolve } from "node:path";
|
|
2
3
|
import { normalizePath } from "vite";
|
|
3
4
|
//#region packages/vite-plugin-angular/src/lib/live-reload-plugin.ts
|
|
@@ -8,6 +9,10 @@ function liveReloadPlugin({ classNames, fileEmitter }) {
|
|
|
8
9
|
name: "analogjs-live-reload-plugin",
|
|
9
10
|
apply: "serve",
|
|
10
11
|
configureServer(server) {
|
|
12
|
+
if (server.config.server.hmr === false) {
|
|
13
|
+
debugHmr("middleware disabled: vite server.hmr is false");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
11
16
|
const angularComponentMiddleware = async (req, res, next) => {
|
|
12
17
|
if (req.url === void 0 || res.writableEnded) return;
|
|
13
18
|
if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
|
|
@@ -23,12 +28,17 @@ function liveReloadPlugin({ classNames, fileEmitter }) {
|
|
|
23
28
|
const [fileId] = decodeURIComponent(componentId).split("@");
|
|
24
29
|
const resolvedId = normalizePath(resolve(process.cwd(), fileId));
|
|
25
30
|
if (!(!!server.moduleGraph.getModuleById(resolvedId)?.lastInvalidationTimestamp && classNames.get(resolvedId))) {
|
|
31
|
+
debugHmr("middleware: skipped (not invalidated)", { resolvedId });
|
|
26
32
|
res.setHeader("Content-Type", "text/javascript");
|
|
27
33
|
res.setHeader("Cache-Control", "no-cache");
|
|
28
34
|
res.end("");
|
|
29
35
|
return;
|
|
30
36
|
}
|
|
31
37
|
const result = fileEmitter(resolvedId);
|
|
38
|
+
debugHmr("middleware: served component update", {
|
|
39
|
+
resolvedId,
|
|
40
|
+
hasCode: !!result?.hmrUpdateCode
|
|
41
|
+
});
|
|
32
42
|
res.setHeader("Content-Type", "text/javascript");
|
|
33
43
|
res.setHeader("Cache-Control", "no-cache");
|
|
34
44
|
res.end(`${result?.hmrUpdateCode || ""}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-reload-plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\nimport { debugHmr } from './utils/debug.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n if (server.config.server.hmr === false) {\n debugHmr('middleware disabled: vite server.hmr is false');\n return;\n }\n\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n debugHmr('middleware: skipped (not invalidated)', { resolvedId });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n debugHmr('middleware: served component update', {\n resolvedId,\n hasCode: !!result?.hmrUpdateCode,\n });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;;AAOA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;AACrC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B,aAAa,IAAI,IAAI;AAEpD,QAAI,CAAC,YACH;AAYF,WATe,YACb,cACE,QACE,QAAQ,KAAK,EACb,mBAAmB,YAAY,CAAC,MAAM,IAAI,CAAC,GAC5C,CACF,CACF,EAEc,iBAAiB;;;EAKrC"}
|
package/src/lib/models.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type ts from
|
|
1
|
+
import type ts from "typescript";
|
|
2
2
|
export interface EmitFileResult {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
content?: string;
|
|
4
|
+
map?: string;
|
|
5
|
+
dependencies: readonly string[];
|
|
6
|
+
hash?: Uint8Array;
|
|
7
|
+
errors?: (string | ts.DiagnosticMessageChain)[];
|
|
8
|
+
warnings?: (string | ts.DiagnosticMessageChain)[];
|
|
9
|
+
hmrUpdateCode?: string | null;
|
|
10
|
+
hmrEligible?: boolean | null;
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
* Ignores anything in the .nx folder from triggering HMR
|
|
4
|
+
*
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
7
|
export declare function nxFolderPlugin(): Plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-folder-plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"nx-folder-plugin.js","names":[],"sources":["../../../src/lib/nx-folder-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin } from 'vite';\n\n/**\n * Ignores anything in the .nx folder from triggering HMR\n *\n * @returns\n */\nexport function nxFolderPlugin(): Plugin {\n return {\n name: 'analogjs-nx-folder-plugin',\n apply: 'serve',\n handleHotUpdate(ctx) {\n if (ctx.file.includes(normalizePath('/.nx/'))) {\n return [];\n }\n\n return ctx.modules;\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,iBAAyB;AACvC,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,KAAK;AACnB,OAAI,IAAI,KAAK,SAAS,cAAc,QAAQ,CAAC,CAC3C,QAAO,EAAE;AAGX,UAAO,IAAI;;EAEd"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
export declare function replaceFiles(replacements: FileReplacement[], workspaceRoot: string): Plugin | false;
|
|
3
3
|
export type FileReplacement = FileReplacementWith | FileReplacementSSR;
|
|
4
4
|
export interface FileReplacementBase {
|
|
5
|
-
|
|
5
|
+
replace: string;
|
|
6
6
|
}
|
|
7
7
|
export interface FileReplacementWith extends FileReplacementBase {
|
|
8
|
-
|
|
8
|
+
with: string;
|
|
9
9
|
}
|
|
10
10
|
export interface FileReplacementSSR extends FileReplacementBase {
|
|
11
|
-
|
|
11
|
+
ssr: string;
|
|
12
12
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { debugCompiler } from "../utils/debug.js";
|
|
1
2
|
import { isAbsolute, resolve } from "node:path";
|
|
2
3
|
//#region packages/vite-plugin-angular/src/lib/plugins/file-replacements.plugin.ts
|
|
3
4
|
function replaceFiles(replacements, workspaceRoot) {
|
|
@@ -24,7 +25,11 @@ function replaceFiles(replacements, workspaceRoot) {
|
|
|
24
25
|
else if (foundReplace.ssr) return null;
|
|
25
26
|
return { id: foundReplace.with };
|
|
26
27
|
} catch (err) {
|
|
27
|
-
|
|
28
|
+
debugCompiler("file replacement error", {
|
|
29
|
+
error: String(err),
|
|
30
|
+
source,
|
|
31
|
+
importer
|
|
32
|
+
});
|
|
28
33
|
return null;
|
|
29
34
|
}
|
|
30
35
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-replacements.plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"file-replacements.plugin.js","names":[],"sources":["../../../../src/lib/plugins/file-replacements.plugin.ts"],"sourcesContent":["// source: https://github.com/Myrmod/vitejs-theming/blob/master/build-plugins/rollup/replace-files.js\nimport { isAbsolute, resolve } from 'node:path';\nimport { Plugin } from 'vite';\nimport { debugCompiler } from '../utils/debug.js';\n\nexport function replaceFiles(\n replacements: FileReplacement[],\n workspaceRoot: string,\n): Plugin | false {\n if (!replacements?.length) {\n return false;\n }\n\n return {\n name: 'rollup-plugin-replace-files',\n enforce: 'pre',\n async resolveId(source, importer, options) {\n const resolved = await this.resolve(source, importer, {\n ...options,\n skipSelf: true,\n });\n /**\n * The reason we're using endsWith here is because the resolved id\n * will be the absolute path to the file. We want to check if the\n * file ends with the file we're trying to replace, which will be essentially\n * the path from the root of our workspace.\n */\n const mappedReplacements = replacements.map((fr: FileReplacement) => {\n const frSSR = fr as FileReplacementSSR;\n const frWith = fr as FileReplacementWith;\n\n return {\n ...fr,\n ssr: frSSR.ssr\n ? isAbsolute(frSSR.ssr)\n ? frSSR.ssr\n : resolve(workspaceRoot, frSSR.ssr)\n : '',\n with: frWith.with\n ? isAbsolute(frWith.with)\n ? frWith.with\n : resolve(workspaceRoot, frWith.with)\n : '',\n };\n });\n const foundReplace = mappedReplacements.find((replacement) =>\n resolved?.id?.endsWith(replacement.replace),\n );\n if (foundReplace) {\n try {\n if (this.environment.name === 'ssr' && foundReplace.ssr) {\n // return new file id for ssr\n return {\n id: foundReplace.ssr,\n };\n } else if (foundReplace.ssr) {\n return null;\n }\n\n // return new file id\n return {\n id: foundReplace.with,\n };\n } catch (err) {\n debugCompiler('file replacement error', {\n error: String(err),\n source,\n importer,\n });\n return null;\n }\n }\n return null;\n },\n };\n}\n\nexport type FileReplacement = FileReplacementWith | FileReplacementSSR;\n\nexport interface FileReplacementBase {\n replace: string;\n}\nexport interface FileReplacementWith extends FileReplacementBase {\n with: string;\n}\n\nexport interface FileReplacementSSR extends FileReplacementBase {\n ssr: string;\n}\n"],"mappings":";;;AAKA,SAAgB,aACd,cACA,eACgB;AAChB,KAAI,CAAC,cAAc,OACjB,QAAO;AAGT,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,UAAU,QAAQ,UAAU,SAAS;GACzC,MAAM,WAAW,MAAM,KAAK,QAAQ,QAAQ,UAAU;IACpD,GAAG;IACH,UAAU;IACX,CAAC;GAyBF,MAAM,eAlBqB,aAAa,KAAK,OAAwB;IACnE,MAAM,QAAQ;IACd,MAAM,SAAS;AAEf,WAAO;KACL,GAAG;KACH,KAAK,MAAM,MACP,WAAW,MAAM,IAAI,GACnB,MAAM,MACN,QAAQ,eAAe,MAAM,IAAI,GACnC;KACJ,MAAM,OAAO,OACT,WAAW,OAAO,KAAK,GACrB,OAAO,OACP,QAAQ,eAAe,OAAO,KAAK,GACrC;KACL;KACD,CACsC,MAAM,gBAC5C,UAAU,IAAI,SAAS,YAAY,QAAQ,CAC5C;AACD,OAAI,aACF,KAAI;AACF,QAAI,KAAK,YAAY,SAAS,SAAS,aAAa,IAElD,QAAO,EACL,IAAI,aAAa,KAClB;aACQ,aAAa,IACtB,QAAO;AAIT,WAAO,EACL,IAAI,aAAa,MAClB;YACM,KAAK;AACZ,kBAAc,0BAA0B;KACtC,OAAO,OAAO,IAAI;KAClB;KACA;KACD,CAAC;AACF,WAAO;;AAGX,UAAO;;EAEV"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Plugin } from
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
2
|
export declare function routerPlugin(): Plugin;
|
package/src/lib/router-plugin.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { JavaScriptTransformer } from "./utils/devkit.js";
|
|
2
|
+
import { createPersistentTransformCache, resolveTransformCacheDir, withMemoryLayer } from "./utils/transform-cache.js";
|
|
2
3
|
//#region packages/vite-plugin-angular/src/lib/router-plugin.ts
|
|
3
4
|
function routerPlugin() {
|
|
4
|
-
const
|
|
5
|
+
const memoryCache = /* @__PURE__ */ new Map();
|
|
6
|
+
const memoryOnly = {
|
|
7
|
+
get: (key) => memoryCache.get(key),
|
|
8
|
+
put: (key, value) => {
|
|
9
|
+
memoryCache.set(key, value);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const persistentDir = resolveTransformCacheDir(process.cwd());
|
|
13
|
+
const javascriptTransformer = new JavaScriptTransformer({ jit: true }, 1, persistentDir ? withMemoryLayer(createPersistentTransformCache(persistentDir)) : memoryOnly);
|
|
5
14
|
/**
|
|
6
15
|
* Transforms Angular packages the didn't get picked up by Vite's pre-optimization.
|
|
7
16
|
*/
|
|
@@ -9,6 +18,9 @@ function routerPlugin() {
|
|
|
9
18
|
name: "analogjs-router-optimization",
|
|
10
19
|
enforce: "pre",
|
|
11
20
|
apply: "serve",
|
|
21
|
+
buildEnd() {
|
|
22
|
+
return javascriptTransformer.close();
|
|
23
|
+
},
|
|
12
24
|
transform: {
|
|
13
25
|
filter: { id: /fesm(.*?)\.mjs/ },
|
|
14
26
|
async handler(_code, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-plugin.js","names":[],"sources":["
|
|
1
|
+
{"version":3,"file":"router-plugin.js","names":[],"sources":["../../../src/lib/router-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { JavaScriptTransformer } from './utils/devkit.js';\nimport {\n createPersistentTransformCache,\n resolveTransformCacheDir,\n withMemoryLayer,\n type TransformCacheStore,\n} from './utils/transform-cache.js';\n\nexport function routerPlugin(): Plugin {\n const memoryCache = new Map<string, Uint8Array>();\n const memoryOnly: TransformCacheStore = {\n get: (key: string) => memoryCache.get(key),\n put: (key: string, value: Uint8Array) => {\n memoryCache.set(key, value);\n },\n };\n const persistentDir = resolveTransformCacheDir(process.cwd());\n const javascriptTransformer = new JavaScriptTransformer(\n { jit: true },\n 1,\n persistentDir\n ? withMemoryLayer(createPersistentTransformCache(persistentDir))\n : memoryOnly,\n );\n\n /**\n * Transforms Angular packages the didn't get picked up by Vite's pre-optimization.\n */\n return {\n name: 'analogjs-router-optimization',\n enforce: 'pre',\n apply: 'serve',\n buildEnd() {\n return javascriptTransformer.close();\n },\n transform: {\n filter: {\n id: /fesm(.*?)\\.mjs/,\n },\n async handler(_code: string, id: string) {\n const path = id.split('?')[0];\n const contents = await javascriptTransformer.transformFile(path);\n\n return {\n code: Buffer.from(contents).toString('utf-8'),\n };\n },\n },\n };\n}\n"],"mappings":";;;AASA,SAAgB,eAAuB;CACrC,MAAM,8BAAc,IAAI,KAAyB;CACjD,MAAM,aAAkC;EACtC,MAAM,QAAgB,YAAY,IAAI,IAAI;EAC1C,MAAM,KAAa,UAAsB;AACvC,eAAY,IAAI,KAAK,MAAM;;EAE9B;CACD,MAAM,gBAAgB,yBAAyB,QAAQ,KAAK,CAAC;CAC7D,MAAM,wBAAwB,IAAI,sBAChC,EAAE,KAAK,MAAM,EACb,GACA,gBACI,gBAAgB,+BAA+B,cAAc,CAAC,GAC9D,WACL;;;;AAKD,QAAO;EACL,MAAM;EACN,SAAS;EACT,OAAO;EACP,WAAW;AACT,UAAO,sBAAsB,OAAO;;EAEtC,WAAW;GACT,QAAQ,EACN,IAAI,kBACL;GACD,MAAM,QAAQ,OAAe,IAAY;IACvC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;IAC3B,MAAM,WAAW,MAAM,sBAAsB,cAAc,KAAK;AAEhE,WAAO,EACL,MAAM,OAAO,KAAK,SAAS,CAAC,SAAS,QAAQ,EAC9C;;GAEJ;EACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface StylesheetTransformContext {
|
|
2
|
+
filename: string;
|
|
3
|
+
containingFile?: string;
|
|
4
|
+
resourceFile?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
order?: number;
|
|
7
|
+
inline: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface StylesheetDependency {
|
|
10
|
+
id: string;
|
|
11
|
+
kind?: "file" | "virtual" | "token" | "bridge" | "manifest" | "runtime";
|
|
12
|
+
owner?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface StylesheetDiagnostic {
|
|
15
|
+
severity: "warning" | "error";
|
|
16
|
+
code: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
export interface StylesheetTransformResult {
|
|
20
|
+
code: string;
|
|
21
|
+
dependencies?: Array<string | StylesheetDependency>;
|
|
22
|
+
diagnostics?: StylesheetDiagnostic[];
|
|
23
|
+
tags?: string[];
|
|
24
|
+
}
|
|
25
|
+
export interface StylesheetRegistryReader {
|
|
26
|
+
getPublicIdsForSource(sourcePath: string): string[];
|
|
27
|
+
getRequestIdsForSource(sourcePath: string): string[];
|
|
28
|
+
getDependenciesForSource(sourcePath: string): StylesheetDependency[];
|
|
29
|
+
getDiagnosticsForSource(sourcePath: string): StylesheetDiagnostic[];
|
|
30
|
+
getTagsForSource(sourcePath: string): string[];
|
|
31
|
+
}
|
|
32
|
+
export type StylePreprocessor = (code: string, filename: string, context?: StylesheetTransformContext) => string | StylesheetTransformResult;
|
|
33
|
+
export declare function normalizeStylesheetTransformResult(value: string | StylesheetTransformResult | undefined, fallbackCode: string): StylesheetTransformResult;
|
|
34
|
+
export declare function normalizeStylesheetDependencies(dependencies: Array<string | StylesheetDependency> | undefined): StylesheetDependency[];
|
|
35
|
+
export declare function composeStylePreprocessors(preprocessors: Array<StylePreprocessor | false | null | undefined>): StylePreprocessor | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region packages/vite-plugin-angular/src/lib/style-preprocessor.ts
|
|
2
|
+
function normalizeStylesheetTransformResult(value, fallbackCode) {
|
|
3
|
+
if (value == null) return { code: fallbackCode };
|
|
4
|
+
if (typeof value === "string") return { code: value };
|
|
5
|
+
return {
|
|
6
|
+
code: value.code ?? fallbackCode,
|
|
7
|
+
dependencies: normalizeStylesheetDependencies(value.dependencies),
|
|
8
|
+
diagnostics: value.diagnostics ?? [],
|
|
9
|
+
tags: value.tags ?? []
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function normalizeStylesheetDependencies(dependencies) {
|
|
13
|
+
return (dependencies ?? []).map((dependency) => typeof dependency === "string" ? { id: dependency } : dependency);
|
|
14
|
+
}
|
|
15
|
+
function composeStylePreprocessors(preprocessors) {
|
|
16
|
+
const active = preprocessors.filter((preprocessor) => !!preprocessor);
|
|
17
|
+
if (!active.length) return;
|
|
18
|
+
return (code, filename, context) => {
|
|
19
|
+
let current = normalizeStylesheetTransformResult(void 0, code);
|
|
20
|
+
for (const preprocessor of active) {
|
|
21
|
+
const next = normalizeStylesheetTransformResult(preprocessor(current.code, filename, context), current.code);
|
|
22
|
+
current = {
|
|
23
|
+
code: next.code,
|
|
24
|
+
dependencies: [...current.dependencies ?? [], ...next.dependencies ?? []],
|
|
25
|
+
diagnostics: [...current.diagnostics ?? [], ...next.diagnostics ?? []],
|
|
26
|
+
tags: [...current.tags ?? [], ...next.tags ?? []]
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return current;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { composeStylePreprocessors, normalizeStylesheetDependencies, normalizeStylesheetTransformResult };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=style-preprocessor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"style-preprocessor.js","names":[],"sources":["../../../src/lib/style-preprocessor.ts"],"sourcesContent":["export interface StylesheetTransformContext {\n filename: string;\n containingFile?: string;\n resourceFile?: string;\n className?: string;\n order?: number;\n inline: boolean;\n}\n\nexport interface StylesheetDependency {\n id: string;\n kind?: 'file' | 'virtual' | 'token' | 'bridge' | 'manifest' | 'runtime';\n owner?: string;\n}\n\nexport interface StylesheetDiagnostic {\n severity: 'warning' | 'error';\n code: string;\n message: string;\n}\n\nexport interface StylesheetTransformResult {\n code: string;\n dependencies?: Array<string | StylesheetDependency>;\n diagnostics?: StylesheetDiagnostic[];\n tags?: string[];\n}\n\nexport interface StylesheetRegistryReader {\n getPublicIdsForSource(sourcePath: string): string[];\n getRequestIdsForSource(sourcePath: string): string[];\n getDependenciesForSource(sourcePath: string): StylesheetDependency[];\n getDiagnosticsForSource(sourcePath: string): StylesheetDiagnostic[];\n getTagsForSource(sourcePath: string): string[];\n}\n\nexport type StylePreprocessor = (\n code: string,\n filename: string,\n context?: StylesheetTransformContext,\n) => string | StylesheetTransformResult;\n\nexport function normalizeStylesheetTransformResult(\n value: string | StylesheetTransformResult | undefined,\n fallbackCode: string,\n): StylesheetTransformResult {\n if (value == null) {\n return { code: fallbackCode };\n }\n\n if (typeof value === 'string') {\n return { code: value };\n }\n\n return {\n code: value.code ?? fallbackCode,\n dependencies: normalizeStylesheetDependencies(value.dependencies),\n diagnostics: value.diagnostics ?? [],\n tags: value.tags ?? [],\n };\n}\n\nexport function normalizeStylesheetDependencies(\n dependencies: Array<string | StylesheetDependency> | undefined,\n): StylesheetDependency[] {\n return (dependencies ?? []).map((dependency) =>\n typeof dependency === 'string' ? { id: dependency } : dependency,\n );\n}\n\nexport function composeStylePreprocessors(\n preprocessors: Array<StylePreprocessor | false | null | undefined>,\n): StylePreprocessor | undefined {\n const active = preprocessors.filter(\n (preprocessor): preprocessor is StylePreprocessor => !!preprocessor,\n );\n\n if (!active.length) {\n return undefined;\n }\n\n return (code, filename, context) => {\n let current = normalizeStylesheetTransformResult(undefined, code);\n\n for (const preprocessor of active) {\n const next = normalizeStylesheetTransformResult(\n preprocessor(current.code, filename, context),\n current.code,\n );\n current = {\n code: next.code,\n dependencies: [\n ...(current.dependencies ?? []),\n ...(next.dependencies ?? []),\n ],\n diagnostics: [\n ...(current.diagnostics ?? []),\n ...(next.diagnostics ?? []),\n ],\n tags: [...(current.tags ?? []), ...(next.tags ?? [])],\n };\n }\n\n return current;\n };\n}\n"],"mappings":";AA0CA,SAAgB,mCACd,OACA,cAC2B;AAC3B,KAAI,SAAS,KACX,QAAO,EAAE,MAAM,cAAc;AAG/B,KAAI,OAAO,UAAU,SACnB,QAAO,EAAE,MAAM,OAAO;AAGxB,QAAO;EACL,MAAM,MAAM,QAAQ;EACpB,cAAc,gCAAgC,MAAM,aAAa;EACjE,aAAa,MAAM,eAAe,EAAE;EACpC,MAAM,MAAM,QAAQ,EAAE;EACvB;;AAGH,SAAgB,gCACd,cACwB;AACxB,SAAQ,gBAAgB,EAAE,EAAE,KAAK,eAC/B,OAAO,eAAe,WAAW,EAAE,IAAI,YAAY,GAAG,WACvD;;AAGH,SAAgB,0BACd,eAC+B;CAC/B,MAAM,SAAS,cAAc,QAC1B,iBAAoD,CAAC,CAAC,aACxD;AAED,KAAI,CAAC,OAAO,OACV;AAGF,SAAQ,MAAM,UAAU,YAAY;EAClC,IAAI,UAAU,mCAAmC,KAAA,GAAW,KAAK;AAEjE,OAAK,MAAM,gBAAgB,QAAQ;GACjC,MAAM,OAAO,mCACX,aAAa,QAAQ,MAAM,UAAU,QAAQ,EAC7C,QAAQ,KACT;AACD,aAAU;IACR,MAAM,KAAK;IACX,cAAc,CACZ,GAAI,QAAQ,gBAAgB,EAAE,EAC9B,GAAI,KAAK,gBAAgB,EAAE,CAC5B;IACD,aAAa,CACX,GAAI,QAAQ,eAAe,EAAE,EAC7B,GAAI,KAAK,eAAe,EAAE,CAC3B;IACD,MAAM,CAAC,GAAI,QAAQ,QAAQ,EAAE,EAAG,GAAI,KAAK,QAAQ,EAAE,CAAE;IACtD;;AAGH,SAAO"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { StylePreprocessor, StylesheetDependency, StylesheetDiagnostic, StylesheetTransformResult, StylesheetTransformContext } from "./style-preprocessor.js";
|
|
2
|
+
export interface AnalogStylesheetRecord {
|
|
3
|
+
publicId: string;
|
|
4
|
+
sourcePath?: string;
|
|
5
|
+
originalCode?: string;
|
|
6
|
+
normalizedCode: string;
|
|
7
|
+
dependencies?: StylesheetDependency[];
|
|
8
|
+
diagnostics?: StylesheetDiagnostic[];
|
|
9
|
+
tags?: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare class AnalogStylesheetRegistry {
|
|
12
|
+
private servedById;
|
|
13
|
+
private servedAliasToId;
|
|
14
|
+
private externalRequestToSource;
|
|
15
|
+
/**
|
|
16
|
+
* Maps a real source stylesheet path back to the generated public stylesheet
|
|
17
|
+
* ids Analog serves for Angular. This is stable across requests and lets HMR
|
|
18
|
+
* reason about "which virtual stylesheet came from this source file?"
|
|
19
|
+
*/
|
|
20
|
+
private sourceToPublicIds;
|
|
21
|
+
/**
|
|
22
|
+
* Tracks the live request ids Vite/Angular have actually served for a source
|
|
23
|
+
* stylesheet, including both `?direct&ngcomp=...` CSS modules and
|
|
24
|
+
* `?ngcomp=...` JS wrapper modules. HMR must use these live request ids
|
|
25
|
+
* because Angular component styles are no longer addressed by their original
|
|
26
|
+
* file paths once externalized.
|
|
27
|
+
*/
|
|
28
|
+
private sourceToRequestIds;
|
|
29
|
+
private sourceToDependencies;
|
|
30
|
+
private sourceToDiagnostics;
|
|
31
|
+
private sourceToTags;
|
|
32
|
+
/**
|
|
33
|
+
* Canonicalizes browser-facing stylesheet request ids so Vite timestamp
|
|
34
|
+
* variants (`?t=...`) and path-shape variants (`abc.css?...` vs
|
|
35
|
+
* `/abc.css?...`) all collapse onto one logical module identity.
|
|
36
|
+
*
|
|
37
|
+
* This is critical for Angular component stylesheet HMR because the browser
|
|
38
|
+
* can keep both timestamped and non-timestamped requests alive for the same
|
|
39
|
+
* externalized stylesheet. If Analog tracks them as distinct resources, HMR
|
|
40
|
+
* can update one module while the browser continues rendering another stale
|
|
41
|
+
* module for the same public stylesheet id.
|
|
42
|
+
*/
|
|
43
|
+
private normalizeRequestId;
|
|
44
|
+
get servedCount(): number;
|
|
45
|
+
get externalCount(): number;
|
|
46
|
+
hasServed(requestId: string): boolean;
|
|
47
|
+
getServedContent(requestId: string): string | undefined;
|
|
48
|
+
getServedSourcePath(requestId: string): string | undefined;
|
|
49
|
+
resolveExternalSource(requestId: string): string | undefined;
|
|
50
|
+
getPublicIdsForSource(sourcePath: string): string[];
|
|
51
|
+
getRequestIdsForSource(sourcePath: string): string[];
|
|
52
|
+
getDependenciesForSource(sourcePath: string): StylesheetDependency[];
|
|
53
|
+
getDiagnosticsForSource(sourcePath: string): StylesheetDiagnostic[];
|
|
54
|
+
getTagsForSource(sourcePath: string): string[];
|
|
55
|
+
registerExternalRequest(requestId: string, sourcePath: string): void;
|
|
56
|
+
registerActiveRequest(requestId: string): void;
|
|
57
|
+
registerServedStylesheet(record: AnalogStylesheetRecord, aliases?: string[]): void;
|
|
58
|
+
private recomputeSourceMetadata;
|
|
59
|
+
private resolveServedRecord;
|
|
60
|
+
}
|
|
61
|
+
export declare function preprocessStylesheet(code: string, filename: string, stylePreprocessor?: StylePreprocessor, context?: StylesheetTransformContext): string;
|
|
62
|
+
export declare function preprocessStylesheetResult(code: string, filename: string, stylePreprocessor?: StylePreprocessor, context?: StylesheetTransformContext): StylesheetTransformResult;
|
|
63
|
+
export declare function rewriteRelativeCssImports(code: string, filename: string): string;
|
|
64
|
+
export declare function registerStylesheetContent(registry: AnalogStylesheetRegistry, { code, dependencies, diagnostics, tags, containingFile, className, order, inlineStylesExtension, resourceFile }: {
|
|
65
|
+
code: string;
|
|
66
|
+
dependencies?: StylesheetDependency[];
|
|
67
|
+
diagnostics?: StylesheetDiagnostic[];
|
|
68
|
+
tags?: string[];
|
|
69
|
+
containingFile: string;
|
|
70
|
+
className?: string;
|
|
71
|
+
order?: number;
|
|
72
|
+
inlineStylesExtension: string;
|
|
73
|
+
resourceFile?: string;
|
|
74
|
+
}): string;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { normalizeStylesheetTransformResult } from "./style-preprocessor.js";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { dirname, normalize, resolve } from "node:path";
|
|
4
|
+
import { normalizePath } from "vite";
|
|
5
|
+
//#region packages/vite-plugin-angular/src/lib/stylesheet-registry.ts
|
|
6
|
+
var AnalogStylesheetRegistry = class {
|
|
7
|
+
servedById = /* @__PURE__ */ new Map();
|
|
8
|
+
servedAliasToId = /* @__PURE__ */ new Map();
|
|
9
|
+
externalRequestToSource = /* @__PURE__ */ new Map();
|
|
10
|
+
/**
|
|
11
|
+
* Maps a real source stylesheet path back to the generated public stylesheet
|
|
12
|
+
* ids Analog serves for Angular. This is stable across requests and lets HMR
|
|
13
|
+
* reason about "which virtual stylesheet came from this source file?"
|
|
14
|
+
*/
|
|
15
|
+
sourceToPublicIds = /* @__PURE__ */ new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Tracks the live request ids Vite/Angular have actually served for a source
|
|
18
|
+
* stylesheet, including both `?direct&ngcomp=...` CSS modules and
|
|
19
|
+
* `?ngcomp=...` JS wrapper modules. HMR must use these live request ids
|
|
20
|
+
* because Angular component styles are no longer addressed by their original
|
|
21
|
+
* file paths once externalized.
|
|
22
|
+
*/
|
|
23
|
+
sourceToRequestIds = /* @__PURE__ */ new Map();
|
|
24
|
+
sourceToDependencies = /* @__PURE__ */ new Map();
|
|
25
|
+
sourceToDiagnostics = /* @__PURE__ */ new Map();
|
|
26
|
+
sourceToTags = /* @__PURE__ */ new Map();
|
|
27
|
+
/**
|
|
28
|
+
* Canonicalizes browser-facing stylesheet request ids so Vite timestamp
|
|
29
|
+
* variants (`?t=...`) and path-shape variants (`abc.css?...` vs
|
|
30
|
+
* `/abc.css?...`) all collapse onto one logical module identity.
|
|
31
|
+
*
|
|
32
|
+
* This is critical for Angular component stylesheet HMR because the browser
|
|
33
|
+
* can keep both timestamped and non-timestamped requests alive for the same
|
|
34
|
+
* externalized stylesheet. If Analog tracks them as distinct resources, HMR
|
|
35
|
+
* can update one module while the browser continues rendering another stale
|
|
36
|
+
* module for the same public stylesheet id.
|
|
37
|
+
*/
|
|
38
|
+
normalizeRequestId(requestId) {
|
|
39
|
+
const [rawPathname, rawSearch = ""] = requestId.split("?");
|
|
40
|
+
const normalizedPathname = rawPathname.replace(/^\//, "");
|
|
41
|
+
if (!rawSearch) return normalizedPathname;
|
|
42
|
+
const normalizedSearch = rawSearch.split("&").filter((segment) => segment.length > 0).filter((segment) => {
|
|
43
|
+
const [key] = segment.split("=");
|
|
44
|
+
return key !== "t";
|
|
45
|
+
}).join("&");
|
|
46
|
+
return normalizedSearch ? `${normalizedPathname}?${normalizedSearch}` : normalizedPathname;
|
|
47
|
+
}
|
|
48
|
+
get servedCount() {
|
|
49
|
+
return this.servedById.size;
|
|
50
|
+
}
|
|
51
|
+
get externalCount() {
|
|
52
|
+
return this.externalRequestToSource.size;
|
|
53
|
+
}
|
|
54
|
+
hasServed(requestId) {
|
|
55
|
+
return this.resolveServedRecord(requestId) !== void 0;
|
|
56
|
+
}
|
|
57
|
+
getServedContent(requestId) {
|
|
58
|
+
return this.resolveServedRecord(requestId)?.normalizedCode;
|
|
59
|
+
}
|
|
60
|
+
getServedSourcePath(requestId) {
|
|
61
|
+
return this.resolveServedRecord(requestId)?.sourcePath;
|
|
62
|
+
}
|
|
63
|
+
resolveExternalSource(requestId) {
|
|
64
|
+
const normalizedRequestId = this.normalizeRequestId(requestId);
|
|
65
|
+
return this.externalRequestToSource.get(normalizedRequestId);
|
|
66
|
+
}
|
|
67
|
+
getPublicIdsForSource(sourcePath) {
|
|
68
|
+
return [...this.sourceToPublicIds.get(sourcePath) ?? []];
|
|
69
|
+
}
|
|
70
|
+
getRequestIdsForSource(sourcePath) {
|
|
71
|
+
return [...this.sourceToRequestIds.get(sourcePath) ?? []];
|
|
72
|
+
}
|
|
73
|
+
getDependenciesForSource(sourcePath) {
|
|
74
|
+
return [...this.sourceToDependencies.get(sourcePath) ?? []];
|
|
75
|
+
}
|
|
76
|
+
getDiagnosticsForSource(sourcePath) {
|
|
77
|
+
return [...this.sourceToDiagnostics.get(sourcePath) ?? []];
|
|
78
|
+
}
|
|
79
|
+
getTagsForSource(sourcePath) {
|
|
80
|
+
return [...this.sourceToTags.get(sourcePath) ?? []];
|
|
81
|
+
}
|
|
82
|
+
registerExternalRequest(requestId, sourcePath) {
|
|
83
|
+
this.externalRequestToSource.set(this.normalizeRequestId(requestId), sourcePath);
|
|
84
|
+
}
|
|
85
|
+
registerActiveRequest(requestId) {
|
|
86
|
+
const normalizedRequestId = this.normalizeRequestId(requestId);
|
|
87
|
+
const requestPath = normalizedRequestId.split("?")[0];
|
|
88
|
+
const sourcePath = this.resolveExternalSource(requestPath) ?? this.resolveExternalSource(requestPath.replace(/^\//, "")) ?? this.getServedSourcePath(requestPath) ?? this.getServedSourcePath(requestPath.replace(/^\//, ""));
|
|
89
|
+
if (!sourcePath) return;
|
|
90
|
+
const requestIds = this.sourceToRequestIds.get(sourcePath) ?? /* @__PURE__ */ new Set();
|
|
91
|
+
requestIds.add(normalizedRequestId);
|
|
92
|
+
if (normalizedRequestId.includes("?direct&ngcomp=")) requestIds.add(normalizedRequestId.replace("?direct&ngcomp=", "?ngcomp="));
|
|
93
|
+
this.sourceToRequestIds.set(sourcePath, requestIds);
|
|
94
|
+
}
|
|
95
|
+
registerServedStylesheet(record, aliases = []) {
|
|
96
|
+
const publicId = this.normalizeRequestId(record.publicId);
|
|
97
|
+
this.servedById.set(publicId, {
|
|
98
|
+
...record,
|
|
99
|
+
publicId
|
|
100
|
+
});
|
|
101
|
+
this.servedAliasToId.set(publicId, publicId);
|
|
102
|
+
for (const alias of aliases) this.servedAliasToId.set(this.normalizeRequestId(alias), publicId);
|
|
103
|
+
if (record.sourcePath) {
|
|
104
|
+
const publicIds = this.sourceToPublicIds.get(record.sourcePath) ?? /* @__PURE__ */ new Set();
|
|
105
|
+
publicIds.add(publicId);
|
|
106
|
+
this.sourceToPublicIds.set(record.sourcePath, publicIds);
|
|
107
|
+
this.recomputeSourceMetadata(record.sourcePath);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
recomputeSourceMetadata(sourcePath) {
|
|
111
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
112
|
+
const diagnostics = /* @__PURE__ */ new Map();
|
|
113
|
+
const tags = /* @__PURE__ */ new Set();
|
|
114
|
+
for (const publicId of this.sourceToPublicIds.get(sourcePath) ?? []) {
|
|
115
|
+
const record = this.servedById.get(publicId);
|
|
116
|
+
if (!record) continue;
|
|
117
|
+
for (const dependency of record.dependencies ?? []) {
|
|
118
|
+
const key = `${dependency.kind ?? "unknown"}:${dependency.id}:${dependency.owner ?? ""}`;
|
|
119
|
+
dependencies.set(key, dependency);
|
|
120
|
+
}
|
|
121
|
+
for (const diagnostic of record.diagnostics ?? []) {
|
|
122
|
+
const key = `${diagnostic.severity}:${diagnostic.code}:${diagnostic.message}`;
|
|
123
|
+
diagnostics.set(key, diagnostic);
|
|
124
|
+
}
|
|
125
|
+
for (const tag of record.tags ?? []) tags.add(tag);
|
|
126
|
+
}
|
|
127
|
+
this.sourceToDependencies.set(sourcePath, [...dependencies.values()]);
|
|
128
|
+
this.sourceToDiagnostics.set(sourcePath, [...diagnostics.values()]);
|
|
129
|
+
this.sourceToTags.set(sourcePath, [...tags]);
|
|
130
|
+
}
|
|
131
|
+
resolveServedRecord(requestId) {
|
|
132
|
+
const normalizedRequestId = this.normalizeRequestId(requestId);
|
|
133
|
+
const publicId = this.servedAliasToId.get(normalizedRequestId) ?? this.servedAliasToId.get(normalizedRequestId.split("?")[0]) ?? normalizedRequestId.split("?")[0];
|
|
134
|
+
return this.servedById.get(publicId);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
function preprocessStylesheet(code, filename, stylePreprocessor, context) {
|
|
138
|
+
return preprocessStylesheetResult(code, filename, stylePreprocessor, context).code;
|
|
139
|
+
}
|
|
140
|
+
function preprocessStylesheetResult(code, filename, stylePreprocessor, context) {
|
|
141
|
+
return normalizeStylesheetTransformResult(stylePreprocessor?.(code, filename, context), code);
|
|
142
|
+
}
|
|
143
|
+
function rewriteRelativeCssImports(code, filename) {
|
|
144
|
+
const cssDir = dirname(filename);
|
|
145
|
+
return code.replace(/@import\s+(?:url\(\s*(["']?)(\.[^'")\s;]+)\1\s*\)|(["'])(\.[^'"]+)\3)/g, (_match, urlQuote, urlPath, stringQuote, stringPath) => {
|
|
146
|
+
const absPath = resolve(cssDir, urlPath ?? stringPath);
|
|
147
|
+
if (typeof urlPath === "string") return `@import url(${urlQuote}${absPath}${urlQuote})`;
|
|
148
|
+
return `@import ${stringQuote}${absPath}${stringQuote}`;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function registerStylesheetContent(registry, { code, dependencies, diagnostics, tags, containingFile, className, order, inlineStylesExtension, resourceFile }) {
|
|
152
|
+
const stylesheetId = `${createHash("sha256").update(containingFile).update(className ?? "").update(String(order ?? 0)).update(code).digest("hex")}.${inlineStylesExtension}`;
|
|
153
|
+
const sourcePath = resourceFile ?? containingFile.replace(".ts", `.${inlineStylesExtension}`);
|
|
154
|
+
const normalizedSourcePath = normalizePath(normalize(sourcePath));
|
|
155
|
+
const aliases = [
|
|
156
|
+
sourcePath,
|
|
157
|
+
normalizedSourcePath,
|
|
158
|
+
sourcePath.replace(/^\//, ""),
|
|
159
|
+
normalizedSourcePath.replace(/^\//, "")
|
|
160
|
+
];
|
|
161
|
+
registry.registerServedStylesheet({
|
|
162
|
+
publicId: stylesheetId,
|
|
163
|
+
sourcePath: normalizedSourcePath,
|
|
164
|
+
normalizedCode: code,
|
|
165
|
+
dependencies,
|
|
166
|
+
diagnostics,
|
|
167
|
+
tags
|
|
168
|
+
}, aliases);
|
|
169
|
+
return stylesheetId;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
export { AnalogStylesheetRegistry, preprocessStylesheet, preprocessStylesheetResult, registerStylesheetContent, rewriteRelativeCssImports };
|
|
173
|
+
|
|
174
|
+
//# sourceMappingURL=stylesheet-registry.js.map
|