ng-packagr 22.2.0-next.4 → 22.2.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ng-packagr",
3
- "version": "22.2.0-next.4",
3
+ "version": "22.2.0-next.6",
4
4
  "description": "Compile and package Angular libraries in Angular Package Format (APF)",
5
5
  "keywords": [
6
6
  "apf",
@@ -44,12 +44,12 @@
44
44
  "jsonc-parser": "^3.3.1",
45
45
  "less": "^4.2.0",
46
46
  "ora": "^9.0.0",
47
- "piscina": "^5.0.0",
48
47
  "postcss": "^8.4.47",
49
48
  "rolldown": "^1.2.0",
50
49
  "rolldown-plugin-dts": "^0.28.0",
51
50
  "rxjs": "^7.8.1",
52
- "sass": "^1.81.0",
51
+ "sass": "^1.103.1",
52
+ "sass-embedded": "^1.103.1",
53
53
  "tinyglobby": "^0.2.12"
54
54
  },
55
55
  "peerDependencies": {
@@ -99,6 +99,7 @@ class ComponentStylesheetBundler {
99
99
  if (!this.incremental) {
100
100
  return;
101
101
  }
102
+ (0, sass_language_1.resetSassWorkerPoolCaches)();
102
103
  const normalizedFiles = new Set();
103
104
  for (const file of files) {
104
105
  const normalized = (0, path_1.ensureUnixPath)(file);
@@ -1 +1 @@
1
- {"version":3,"file":"component-stylesheets.js","sourceRoot":"","sources":["../../../../src/lib/styles/component-stylesheets.ts"],"names":[],"mappings":";;;;;;AACA,6CAAyC;AACzC,0DAA6B;AAC7B,wCAA+C;AAC/C,uDAA6F;AAC7F,mCAAsC;AACtC,2DAA4D;AAC5D,iEAAsG;AACtG,+DAAqE;AAWrE;;;;GAIG;AACH,MAAa,0BAA0B;IAWlB;IACA;IACA;IAZV,aAAa,GAAG,IAAI,mBAAW,EAAkB,CAAC;IAClD,eAAe,GAAG,IAAI,mBAAW,EAAkB,CAAC;IACpD,UAAU,GAAG,IAAI,yCAAqB,EAAE,CAAC;IAElD;;;;O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AAW,GAAiB,EAAE,CAAC;QAErC,IAAI,aAAa,IAAI,MAAM,EAAE,CAAC;YAC5B,KAAK,MAAM,UAAU,IAAI,MAAM,CAAC,WAAW,EAAE,CAAC;gBAC5C,MAAM,QAAQ,GAAG,mBAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;gBAEhD,IAAI,UAAU,CAAC,IAAI,KAAK,qCAAmB,CAAC,KAAK,IAAI,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;oBACnF,4GAA4G;oBAE5G,wGAAwG;oBACxG,MAAM,gBAAgB,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC;oBAE5C,oFAAoF;oBACpF,wHAAwH;oBACxH,wEAAwE;oBACxE,8CAA8C;oBAC9C,gBAAgB,CAAC,IAAI,GAAG,mBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;oBAE/E,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBACrC,CAAC;qBAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;oBACrC,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC;gBAC7B,CAAC;qBAAM,CAAC;oBACN,MAAM,IAAI,KAAK,CACb,kCAAkC,QAAQ,qDAAqD,CAChG,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC7B,CAAC;QAED,OAAO;YACL,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ;YACR,WAAW;YACX,QAAQ;YACR,eAAe;SAChB,CAAC;IACJ,CAAC;CACF;AArMD,gEAqMC","sourcesContent":["import { Message, Metafile, OutputFile } from 'esbuild';\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport { ensureUnixPath } from '../utils/path';\nimport { BuildOutputFileType, BundleContextResult, BundlerContext } from './bundler-context';\nimport { MemoryCache } from './cache';\nimport { MemoryLoadResultCache } from './load-result-cache';\nimport { BundleStylesheetOptions, createStylesheetBundleOptions } from './stylesheets/bundle-options';\nimport { shutdownSassWorkerPool } from './stylesheets/sass-language';\n\nexport interface ComponentStylesheetResult {\n errors: Message[] | undefined;\n warnings: Message[];\n contents: string;\n outputFiles: OutputFile[];\n metafile: Metafile | undefined;\n referencedFiles: Set<string> | undefined;\n}\n\n/**\n * Bundles component stylesheets. A stylesheet can be either an inline stylesheet that\n * is contained within the Component's metadata definition or an external file referenced\n * from the Component's metadata definition.\n */\nexport class ComponentStylesheetBundler {\n readonly #fileContexts = new MemoryCache<BundlerContext>();\n readonly #inlineContexts = new MemoryCache<BundlerContext>();\n readonly #loadCache = new MemoryLoadResultCache();\n\n /**\n * @param options An object containing the stylesheet bundling options.\n * @param defaultInlineLanguage The default language to use for inline component styles.\n * @param incremental True if incremental watch mode is enabled.\n */\n constructor(\n private readonly options: BundleStylesheetOptions,\n private readonly defaultInlineLanguage: string,\n private readonly incremental: boolean,\n ) {}\n\n async bundleFile(entry: string): Promise<ComponentStylesheetResult> {\n entry = ensureUnixPath(entry);\n\n const bundlerContext = await this.#fileContexts.getOrCreate(entry, () => {\n return new BundlerContext(\n this.options.workspaceRoot,\n this.incremental,\n loadCache => {\n const buildOptions = createStylesheetBundleOptions(this.options, loadCache);\n\n buildOptions.entryPoints = [entry];\n\n return buildOptions;\n },\n /* useContext */ false,\n /* initialFilter */ undefined,\n this.#loadCache,\n );\n });\n\n return this.extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles);\n }\n\n async bundleInline(\n data: string,\n filename: string,\n language: string = this.defaultInlineLanguage,\n ): Promise<ComponentStylesheetResult> {\n filename = ensureUnixPath(filename);\n\n // Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve\n // to the actual stylesheet file path.\n // TODO: Consider xxhash instead for hashing\n const id = createHash('sha256').update(data).digest('hex');\n const entry = [language, id, filename].join(';');\n\n const bundlerContext = await this.#inlineContexts.getOrCreate(entry, () => {\n const namespace = 'angular:styles/component';\n\n return new BundlerContext(\n this.options.workspaceRoot,\n this.incremental,\n loadCache => {\n const buildOptions = createStylesheetBundleOptions(this.options, loadCache, {\n [entry]: data,\n });\n buildOptions.entryPoints = [`${namespace};${entry}`];\n\n buildOptions.plugins.push({\n name: 'angular-component-styles',\n setup(build) {\n build.onResolve({ filter: /^angular:styles\\/component;/ }, args => {\n if (args.kind !== 'entry-point') {\n return null;\n }\n\n return {\n path: entry,\n namespace,\n };\n });\n build.onLoad({ filter: /^css;/, namespace }, () => {\n return {\n contents: data,\n loader: 'css',\n resolveDir: path.dirname(filename),\n };\n });\n },\n });\n\n return buildOptions;\n },\n /* useContext */ false,\n /* initialFilter */ undefined,\n this.#loadCache,\n );\n });\n\n // Extract the result of the bundling from the output files\n return this.extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles);\n }\n\n /**\n * Invalidates both file and inline based component style bundling state for a set of modified files.\n * @param files The group of files that have been modified\n * @returns An array of file based stylesheet entries if any were invalidated; otherwise, undefined.\n */\n invalidate(files: Iterable<string> | ReadonlySet<string>): string[] | undefined {\n if (!this.incremental) {\n return;\n }\n\n const normalizedFiles = new Set<string>();\n for (const file of files) {\n const normalized = ensureUnixPath(file);\n normalizedFiles.add(normalized);\n if (!path.isAbsolute(normalized)) {\n normalizedFiles.add(ensureUnixPath(path.join(this.options.workspaceRoot, normalized)));\n }\n }\n\n let entries: string[] | undefined;\n\n for (const [entry, bundler] of this.#fileContexts.entries()) {\n if (bundler.invalidate(normalizedFiles)) {\n entries ??= [];\n entries.push(entry);\n }\n }\n for (const [entry, bundler] of this.#inlineContexts.entries()) {\n // Entry is format: [language, id, filename].join(';')\n const firstSemi = entry.indexOf(';');\n const secondSemi = firstSemi !== -1 ? entry.indexOf(';', firstSemi + 1) : -1;\n const filename = secondSemi !== -1 ? entry.slice(secondSemi + 1) : '';\n if (filename && normalizedFiles.has(ensureUnixPath(filename))) {\n this.#inlineContexts.delete(entry);\n void bundler.dispose();\n } else {\n bundler.invalidate(normalizedFiles);\n }\n }\n\n return entries;\n }\n\n async dispose(): Promise<void> {\n const contexts = [...this.#fileContexts.values(), ...this.#inlineContexts.values()];\n this.#fileContexts.clear();\n this.#inlineContexts.clear();\n this.#loadCache.clear();\n\n await Promise.allSettled([shutdownSassWorkerPool(), ...contexts.map(context => context.dispose())]);\n }\n\n private extractResult(\n result: BundleContextResult,\n referencedFiles: Set<string> | undefined,\n ): ComponentStylesheetResult {\n let contents = '';\n let metafile;\n const outputFiles: OutputFile[] = [];\n\n if ('outputFiles' in result) {\n for (const outputFile of result.outputFiles) {\n const filename = path.basename(outputFile.path);\n\n if (outputFile.type === BuildOutputFileType.Media || filename.endsWith('.css.map')) {\n // The output files could also contain resources (images/fonts/etc.) that were referenced and the map files.\n\n // Clone the output file to avoid amending the original path which would causes problems during rebuild.\n const clonedOutputFile = outputFile.clone();\n\n // Needed for Bazel as otherwise the files will not be written in the correct place,\n // this is because esbuild will resolve the output file from the outdir which is currently set to `workspaceRoot` twice,\n // once in the stylesheet and the other in the application code bundler.\n // Ex: `../../../../../app.component.css.map`.\n clonedOutputFile.path = path.join(this.options.workspaceRoot, outputFile.path);\n\n outputFiles.push(clonedOutputFile);\n } else if (filename.endsWith('.css')) {\n contents = outputFile.text;\n } else {\n throw new Error(\n `Unexpected non CSS/Media file \"${filename}\" outputted during component stylesheet processing.`,\n );\n }\n }\n\n metafile = result.metafile;\n }\n\n return {\n errors: result.errors,\n warnings: result.warnings,\n contents,\n outputFiles,\n metafile,\n referencedFiles,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"component-stylesheets.js","sourceRoot":"","sources":["../../../../src/lib/styles/component-stylesheets.ts"],"names":[],"mappings":";;;;;;AACA,6CAAyC;AACzC,0DAA6B;AAC7B,wCAA+C;AAC/C,uDAA6F;AAC7F,mCAAsC;AACtC,2DAA4D;AAC5D,i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AE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,QAAQ;YACR,WAAW;YACX,QAAQ;YACR,eAAe;SAChB,CAAC;IACJ,CAAC;CACF;AAvMD,gEAuMC","sourcesContent":["import { Message, Metafile, OutputFile } from 'esbuild';\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport { ensureUnixPath } from '../utils/path';\nimport { BuildOutputFileType, BundleContextResult, BundlerContext } from './bundler-context';\nimport { MemoryCache } from './cache';\nimport { MemoryLoadResultCache } from './load-result-cache';\nimport { BundleStylesheetOptions, createStylesheetBundleOptions } from './stylesheets/bundle-options';\nimport { resetSassWorkerPoolCaches, shutdownSassWorkerPool } from './stylesheets/sass-language';\n\nexport interface ComponentStylesheetResult {\n errors: Message[] | undefined;\n warnings: Message[];\n contents: string;\n outputFiles: OutputFile[];\n metafile: Metafile | undefined;\n referencedFiles: Set<string> | undefined;\n}\n\n/**\n * Bundles component stylesheets. A stylesheet can be either an inline stylesheet that\n * is contained within the Component's metadata definition or an external file referenced\n * from the Component's metadata definition.\n */\nexport class ComponentStylesheetBundler {\n readonly #fileContexts = new MemoryCache<BundlerContext>();\n readonly #inlineContexts = new MemoryCache<BundlerContext>();\n readonly #loadCache = new MemoryLoadResultCache();\n\n /**\n * @param options An object containing the stylesheet bundling options.\n * @param defaultInlineLanguage The default language to use for inline component styles.\n * @param incremental True if incremental watch mode is enabled.\n */\n constructor(\n private readonly options: BundleStylesheetOptions,\n private readonly defaultInlineLanguage: string,\n private readonly incremental: boolean,\n ) {}\n\n async bundleFile(entry: string): Promise<ComponentStylesheetResult> {\n entry = ensureUnixPath(entry);\n\n const bundlerContext = await this.#fileContexts.getOrCreate(entry, () => {\n return new BundlerContext(\n this.options.workspaceRoot,\n this.incremental,\n loadCache => {\n const buildOptions = createStylesheetBundleOptions(this.options, loadCache);\n\n buildOptions.entryPoints = [entry];\n\n return buildOptions;\n },\n /* useContext */ false,\n /* initialFilter */ undefined,\n this.#loadCache,\n );\n });\n\n return this.extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles);\n }\n\n async bundleInline(\n data: string,\n filename: string,\n language: string = this.defaultInlineLanguage,\n ): Promise<ComponentStylesheetResult> {\n filename = ensureUnixPath(filename);\n\n // Use a hash of the inline stylesheet content to ensure a consistent identifier. External stylesheets will resolve\n // to the actual stylesheet file path.\n // TODO: Consider xxhash instead for hashing\n const id = createHash('sha256').update(data).digest('hex');\n const entry = [language, id, filename].join(';');\n\n const bundlerContext = await this.#inlineContexts.getOrCreate(entry, () => {\n const namespace = 'angular:styles/component';\n\n return new BundlerContext(\n this.options.workspaceRoot,\n this.incremental,\n loadCache => {\n const buildOptions = createStylesheetBundleOptions(this.options, loadCache, {\n [entry]: data,\n });\n buildOptions.entryPoints = [`${namespace};${entry}`];\n\n buildOptions.plugins.push({\n name: 'angular-component-styles',\n setup(build) {\n build.onResolve({ filter: /^angular:styles\\/component;/ }, args => {\n if (args.kind !== 'entry-point') {\n return null;\n }\n\n return {\n path: entry,\n namespace,\n };\n });\n build.onLoad({ filter: /^css;/, namespace }, () => {\n return {\n contents: data,\n loader: 'css',\n resolveDir: path.dirname(filename),\n };\n });\n },\n });\n\n return buildOptions;\n },\n /* useContext */ false,\n /* initialFilter */ undefined,\n this.#loadCache,\n );\n });\n\n // Extract the result of the bundling from the output files\n return this.extractResult(await bundlerContext.bundle(), bundlerContext.watchFiles);\n }\n\n /**\n * Invalidates both file and inline based component style bundling state for a set of modified files.\n * @param files The group of files that have been modified\n * @returns An array of file based stylesheet entries if any were invalidated; otherwise, undefined.\n */\n invalidate(files: Iterable<string> | ReadonlySet<string>): string[] | undefined {\n if (!this.incremental) {\n return;\n }\n\n resetSassWorkerPoolCaches();\n\n const normalizedFiles = new Set<string>();\n for (const file of files) {\n const normalized = ensureUnixPath(file);\n normalizedFiles.add(normalized);\n if (!path.isAbsolute(normalized)) {\n normalizedFiles.add(ensureUnixPath(path.join(this.options.workspaceRoot, normalized)));\n }\n }\n\n let entries: string[] | undefined;\n\n for (const [entry, bundler] of this.#fileContexts.entries()) {\n if (bundler.invalidate(normalizedFiles)) {\n entries ??= [];\n entries.push(entry);\n }\n }\n for (const [entry, bundler] of this.#inlineContexts.entries()) {\n // Entry is format: [language, id, filename].join(';')\n const firstSemi = entry.indexOf(';');\n const secondSemi = firstSemi !== -1 ? entry.indexOf(';', firstSemi + 1) : -1;\n const filename = secondSemi !== -1 ? entry.slice(secondSemi + 1) : '';\n if (filename && normalizedFiles.has(ensureUnixPath(filename))) {\n this.#inlineContexts.delete(entry);\n void bundler.dispose();\n } else {\n bundler.invalidate(normalizedFiles);\n }\n }\n\n return entries;\n }\n\n async dispose(): Promise<void> {\n const contexts = [...this.#fileContexts.values(), ...this.#inlineContexts.values()];\n this.#fileContexts.clear();\n this.#inlineContexts.clear();\n this.#loadCache.clear();\n\n await Promise.allSettled([shutdownSassWorkerPool(), ...contexts.map(context => context.dispose())]);\n }\n\n private extractResult(\n result: BundleContextResult,\n referencedFiles: Set<string> | undefined,\n ): ComponentStylesheetResult {\n let contents = '';\n let metafile;\n const outputFiles: OutputFile[] = [];\n\n if ('outputFiles' in result) {\n for (const outputFile of result.outputFiles) {\n const filename = path.basename(outputFile.path);\n\n if (outputFile.type === BuildOutputFileType.Media || filename.endsWith('.css.map')) {\n // The output files could also contain resources (images/fonts/etc.) that were referenced and the map files.\n\n // Clone the output file to avoid amending the original path which would causes problems during rebuild.\n const clonedOutputFile = outputFile.clone();\n\n // Needed for Bazel as otherwise the files will not be written in the correct place,\n // this is because esbuild will resolve the output file from the outdir which is currently set to `workspaceRoot` twice,\n // once in the stylesheet and the other in the application code bundler.\n // Ex: `../../../../../app.component.css.map`.\n clonedOutputFile.path = path.join(this.options.workspaceRoot, outputFile.path);\n\n outputFiles.push(clonedOutputFile);\n } else if (filename.endsWith('.css')) {\n contents = outputFile.text;\n } else {\n throw new Error(\n `Unexpected non CSS/Media file \"${filename}\" outputted during component stylesheet processing.`,\n );\n }\n }\n\n metafile = result.metafile;\n }\n\n return {\n errors: result.errors,\n warnings: result.warnings,\n contents,\n outputFiles,\n metafile,\n referencedFiles,\n };\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { CanonicalizeContext, Importer, ImporterResult } from 'sass';
1
+ import type { CanonicalizeContext, Importer, ImporterResult } from 'sass-embedded';
2
2
  /**
3
3
  * A preprocessed cache entry for the files and directories within a previously searched
4
4
  * directory when performing Sass import resolution.
@@ -26,9 +26,7 @@ declare abstract class UrlRebasingImporter implements Importer<'sync'> {
26
26
  * which can be used to generate a final sourcemap that contains original sources.
27
27
  */
28
28
  constructor(entryDirectory: string);
29
- abstract canonicalize(url: string, options: {
30
- fromImport: boolean;
31
- }): URL | null;
29
+ abstract canonicalize(url: string, options: CanonicalizeContext): URL | null;
32
30
  load(canonicalUrl: URL): ImporterResult | null;
33
31
  }
34
32
  /**
@@ -39,9 +37,7 @@ declare abstract class UrlRebasingImporter implements Importer<'sync'> {
39
37
  export declare class RelativeUrlRebasingImporter extends UrlRebasingImporter {
40
38
  private directoryCache;
41
39
  constructor(entryDirectory: string, directoryCache?: Map<string, DirectoryEntry>);
42
- canonicalize(url: string, options: {
43
- fromImport: boolean;
44
- }): URL | null;
40
+ canonicalize(url: string, options: CanonicalizeContext): URL | null;
45
41
  /**
46
42
  * Attempts to resolve a provided URL to a stylesheet file using the Sass compiler's resolution algorithm.
47
43
  * Based on https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart
@@ -61,14 +57,15 @@ export declare class RelativeUrlRebasingImporter extends UrlRebasingImporter {
61
57
  private checkFound;
62
58
  }
63
59
  /**
64
- * Provides the Sass importer logic to resolve module (npm package) stylesheet imports via both import and
65
- * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
66
- * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
60
+ * Provides the Sass importer logic to resolve module (npm package) stylesheet imports asynchronously
61
+ * and also rebase any `url()` function usage within those stylesheets.
67
62
  */
68
- export declare class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {
63
+ export declare class AsyncModuleUrlRebasingImporter implements Importer<'async'> {
69
64
  private finder;
70
- constructor(entryDirectory: string, directoryCache: Map<string, DirectoryEntry>, finder: (specifier: string, options: CanonicalizeContext) => URL | null);
71
- canonicalize(url: string, options: CanonicalizeContext): URL | null;
65
+ private relativeImporter;
66
+ constructor(entryDirectory: string, directoryCache: Map<string, DirectoryEntry>, finder: (specifier: string, options: CanonicalizeContext) => Promise<URL | null> | URL | null);
67
+ canonicalize(url: string, options: CanonicalizeContext): Promise<URL | null>;
68
+ load(canonicalUrl: URL): ImporterResult | null;
72
69
  }
73
70
  /**
74
71
  * Provides the Sass importer logic to resolve load paths located stylesheet imports via both import and
@@ -78,15 +75,6 @@ export declare class ModuleUrlRebasingImporter extends RelativeUrlRebasingImport
78
75
  export declare class LoadPathsUrlRebasingImporter extends RelativeUrlRebasingImporter {
79
76
  private loadPaths;
80
77
  constructor(entryDirectory: string, directoryCache: Map<string, DirectoryEntry>, loadPaths: Iterable<string>);
81
- canonicalize(url: string, options: {
82
- fromImport: boolean;
83
- }): URL | null;
78
+ canonicalize(url: string, options: CanonicalizeContext): URL | null;
84
79
  }
85
- /**
86
- * Workaround for Sass not calling instance methods with `this`.
87
- * The `canonicalize` and `load` methods will be bound to the class instance.
88
- * @param importer A Sass importer to bind.
89
- * @returns The bound Sass importer.
90
- */
91
- export declare function sassBindWorkaround<T extends Importer>(importer: T): T;
92
80
  export {};
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LoadPathsUrlRebasingImporter = exports.ModuleUrlRebasingImporter = exports.RelativeUrlRebasingImporter = void 0;
4
- exports.sassBindWorkaround = sassBindWorkaround;
3
+ exports.LoadPathsUrlRebasingImporter = exports.AsyncModuleUrlRebasingImporter = exports.RelativeUrlRebasingImporter = void 0;
5
4
  const node_fs_1 = require("node:fs");
6
5
  const node_path_1 = require("node:path");
7
6
  const node_url_1 = require("node:url");
@@ -26,6 +25,7 @@ class UrlRebasingImporter {
26
25
  */
27
26
  constructor(entryDirectory) {
28
27
  this.entryDirectory = entryDirectory;
28
+ this.load = this.load.bind(this);
29
29
  }
30
30
  load(canonicalUrl) {
31
31
  const stylesheetPath = (0, node_url_1.fileURLToPath)(canonicalUrl);
@@ -92,6 +92,7 @@ class RelativeUrlRebasingImporter extends UrlRebasingImporter {
92
92
  constructor(entryDirectory, directoryCache = new Map()) {
93
93
  super(entryDirectory);
94
94
  this.directoryCache = directoryCache;
95
+ this.canonicalize = this.canonicalize.bind(this);
95
96
  }
96
97
  canonicalize(url, options) {
97
98
  return this.resolveImport(url, options.fromImport, true);
@@ -248,26 +249,30 @@ class RelativeUrlRebasingImporter extends UrlRebasingImporter {
248
249
  }
249
250
  exports.RelativeUrlRebasingImporter = RelativeUrlRebasingImporter;
250
251
  /**
251
- * Provides the Sass importer logic to resolve module (npm package) stylesheet imports via both import and
252
- * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
253
- * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.
252
+ * Provides the Sass importer logic to resolve module (npm package) stylesheet imports asynchronously
253
+ * and also rebase any `url()` function usage within those stylesheets.
254
254
  */
255
- class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {
255
+ class AsyncModuleUrlRebasingImporter {
256
256
  finder;
257
+ relativeImporter;
257
258
  constructor(entryDirectory, directoryCache, finder) {
258
- super(entryDirectory, directoryCache);
259
259
  this.finder = finder;
260
+ this.relativeImporter = new RelativeUrlRebasingImporter(entryDirectory, directoryCache);
261
+ this.canonicalize = this.canonicalize.bind(this);
262
+ this.load = this.load.bind(this);
260
263
  }
261
- canonicalize(url, options) {
264
+ async canonicalize(url, options) {
262
265
  if (url.startsWith('file://')) {
263
- return super.canonicalize(url, options);
266
+ return this.relativeImporter.canonicalize(url, options);
264
267
  }
265
- let result = this.finder(url, options);
266
- result &&= super.canonicalize(result.href, options);
267
- return result;
268
+ const result = await this.finder(url, options);
269
+ return result ? this.relativeImporter.canonicalize(result.href, options) : null;
270
+ }
271
+ load(canonicalUrl) {
272
+ return this.relativeImporter.load(canonicalUrl);
268
273
  }
269
274
  }
270
- exports.ModuleUrlRebasingImporter = ModuleUrlRebasingImporter;
275
+ exports.AsyncModuleUrlRebasingImporter = AsyncModuleUrlRebasingImporter;
271
276
  /**
272
277
  * Provides the Sass importer logic to resolve load paths located stylesheet imports via both import and
273
278
  * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that
@@ -294,15 +299,4 @@ class LoadPathsUrlRebasingImporter extends RelativeUrlRebasingImporter {
294
299
  }
295
300
  }
296
301
  exports.LoadPathsUrlRebasingImporter = LoadPathsUrlRebasingImporter;
297
- /**
298
- * Workaround for Sass not calling instance methods with `this`.
299
- * The `canonicalize` and `load` methods will be bound to the class instance.
300
- * @param importer A Sass importer to bind.
301
- * @returns The bound Sass importer.
302
- */
303
- function sassBindWorkaround(importer) {
304
- importer.canonicalize = importer.canonicalize.bind(importer);
305
- importer.load = importer.load.bind(importer);
306
- return importer;
307
- }
308
302
  //# sourceMappingURL=rebasing-importer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rebasing-importer.js","sourceRoot":"","sources":["../../../../../src/lib/styles/sass/rebasing-importer.ts"],"names":[],"mappings":";;;AA8VA,gDAKC;AAnWD,qCAA8D;AAC9D,yCAAuE;AACvE,uCAAwD;AAExD,mCAAmC;AAWnC;;;;;;;;;;GAUG;AACH,MAAe,mBAAmB;IAMZ;IALpB;;;;OAIG;IACH,YAAoB,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;IAAG,CAAC;IAI9C,IAAI,CAAC,YAAiB;QACpB,MAAM,cAAc,GAAG,IAAA,wBAAa,EAAC,YAAY,CAAC,CAAC;QACnD,MAAM,mBAAmB,GAAG,IAAA,mBAAO,EAAC,cAAc,CAAC,CAAC;QACp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rC,CAAC;IAEQ,YAAY,CAAC,GAAW,EAAE,OAAgC;QACjE,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,MAAM,GAAG,IAAI,CAAC;QAClB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,IAAA,wBAAa,EAAC,IAAA,gBAAI,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC9E,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxBD,oEAwBC;AAED;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAqB,QAAW;IAChE,QAAQ,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7D,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAE7C,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs';\nimport { basename, dirname, extname, join, relative } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport type { CanonicalizeContext, Importer, ImporterResult, Syntax } from 'sass';\nimport { findUrls } from './lexer';\n\n/**\n * A preprocessed cache entry for the files and directories within a previously searched\n * directory when performing Sass import resolution.\n */\nexport interface DirectoryEntry {\n files: Set<string>;\n directories: Set<string>;\n}\n\n/**\n * A Sass Importer base class that provides the load logic to rebase all `url()` functions\n * within a stylesheet. The rebasing will ensure that the URLs in the output of the Sass compiler\n * reflect the final filesystem location of the output CSS file.\n *\n * This class provides the core of the rebasing functionality. To ensure that each file is processed\n * by this importer's load implementation, the Sass compiler requires the importer's canonicalize\n * function to return a non-null value with the resolved location of the requested stylesheet.\n * Concrete implementations of this class must provide this canonicalize functionality for rebasing\n * to be effective.\n */\nabstract class UrlRebasingImporter implements Importer<'sync'> {\n /**\n * @param entryDirectory The directory of the entry stylesheet that was passed to the Sass compiler.\n * @param rebaseSourceMaps When provided, rebased files will have an intermediate sourcemap added to the Map\n * which can be used to generate a final sourcemap that contains original sources.\n */\n constructor(private entryDirectory: string) {}\n\n abstract canonicalize(url: string, options: { fromImport: boolean }): URL | null;\n\n load(canonicalUrl: URL): ImporterResult | null {\n const stylesheetPath = fileURLToPath(canonicalUrl);\n const stylesheetDirectory = dirname(stylesheetPath);\n let contents = readFileSync(stylesheetPath, 'utf-8');\n\n // Rebase any URLs that are found\n let updatedContents: string;\n for (const { start, end, value } of findUrls(contents)) {\n // Skip if value is empty or Webpack-specific prefix\n if (value.length === 0 || value[0] === '~' || value[0] === '^') {\n continue;\n }\n\n // Skip if root-relative, absolute or protocol relative url\n if (/^((?:\\w+:)?\\/\\/|data:|chrome:|\\/)/.test(value)) {\n continue;\n }\n\n // Skip if a fragment identifier but not a Sass interpolation\n if (value[0] === '#' && value[1] !== '{') {\n continue;\n }\n\n // Skip if value is value contains a function call\n if (/#\\{.+\\(.+\\)\\}/.test(value)) {\n continue;\n }\n\n // Sass variable usage either starts with a `$` or contains a namespace and a `.$`\n const valueNormalized = value[0] === '$' || /^\\w+\\.\\$/.test(value) ? `#{${value}}` : value;\n const rebasedPath = relative(this.entryDirectory, stylesheetDirectory);\n\n // Normalize path separators and escape characters\n // https://developer.mozilla.org/en-US/docs/Web/CSS/url#syntax\n const rebasedUrl = rebasedPath.replace(/\\\\/g, '/').replace(/[()\\s'\"]/g, '\\\\$&');\n\n // eslint-disable-next-line no-useless-assignment\n updatedContents ??= contents;\n updatedContents = contents.slice(0, start) + `\"${rebasedUrl}||file:${valueNormalized}\"` + contents.slice(end);\n }\n\n if (updatedContents) {\n contents = updatedContents;\n }\n\n let syntax: Syntax | undefined;\n switch (extname(stylesheetPath).toLowerCase()) {\n case '.css':\n syntax = 'css';\n break;\n case '.sass':\n syntax = 'indented';\n break;\n default:\n syntax = 'scss';\n break;\n }\n\n return {\n contents,\n syntax,\n sourceMapUrl: canonicalUrl,\n };\n }\n}\n\n/**\n * Provides the Sass importer logic to resolve relative stylesheet imports via both import and use rules\n * and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that\n * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.\n */\nexport class RelativeUrlRebasingImporter extends UrlRebasingImporter {\n constructor(\n entryDirectory: string,\n private directoryCache = new Map<string, DirectoryEntry>(),\n ) {\n super(entryDirectory);\n }\n\n canonicalize(url: string, options: { fromImport: boolean }): URL | null {\n return this.resolveImport(url, options.fromImport, true);\n }\n\n /**\n * Attempts to resolve a provided URL to a stylesheet file using the Sass compiler's resolution algorithm.\n * Based on https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart\n * @param url The file protocol URL to resolve.\n * @param fromImport If true, URL was from an import rule; otherwise from a use rule.\n * @param checkDirectory If true, try checking for a directory with the base name containing an index file.\n * @returns A full resolved URL of the stylesheet file or `null` if not found.\n */\n private resolveImport(url: string, fromImport: boolean, checkDirectory: boolean): URL | null {\n let stylesheetPath;\n try {\n stylesheetPath = fileURLToPath(url);\n } catch {\n // Only file protocol URLs are supported by this importer\n return null;\n }\n\n const directory = dirname(stylesheetPath);\n const extension = extname(stylesheetPath);\n const hasStyleExtension = extension === '.scss' || extension === '.sass' || extension === '.css';\n // Remove the style extension if present to allow adding the `.import` suffix\n const filename = basename(stylesheetPath, hasStyleExtension ? extension : undefined);\n\n const importPotentials = new Set<string>();\n const defaultPotentials = new Set<string>();\n\n if (hasStyleExtension) {\n if (fromImport) {\n importPotentials.add(filename + '.import' + extension);\n importPotentials.add('_' + filename + '.import' + extension);\n }\n defaultPotentials.add(filename + extension);\n defaultPotentials.add('_' + filename + extension);\n } else {\n if (fromImport) {\n importPotentials.add(filename + '.import.scss');\n importPotentials.add(filename + '.import.sass');\n importPotentials.add(filename + '.import.css');\n importPotentials.add('_' + filename + '.import.scss');\n importPotentials.add('_' + filename + '.import.sass');\n importPotentials.add('_' + filename + '.import.css');\n }\n defaultPotentials.add(filename + '.scss');\n defaultPotentials.add(filename + '.sass');\n defaultPotentials.add(filename + '.css');\n defaultPotentials.add('_' + filename + '.scss');\n defaultPotentials.add('_' + filename + '.sass');\n defaultPotentials.add('_' + filename + '.css');\n }\n\n let foundDefaults;\n let foundImports;\n let hasPotentialIndex = false;\n\n let cachedEntries = this.directoryCache.get(directory);\n if (cachedEntries) {\n // If there is a preprocessed cache of the directory, perform an intersection of the potentials\n // and the directory files.\n const { files, directories } = cachedEntries;\n foundDefaults = [...defaultPotentials].filter(potential => files.has(potential));\n foundImports = [...importPotentials].filter(potential => files.has(potential));\n hasPotentialIndex = checkDirectory && !hasStyleExtension && directories.has(filename);\n } else {\n // If no preprocessed cache exists, get the entries from the file system and, while searching,\n // generate the cache for later requests.\n let entries;\n try {\n entries = readdirSync(directory, { withFileTypes: true });\n } catch (error) {\n // If the containing directory does not exist return null to indicate it cannot be resolved\n if (error.code === 'ENOENT') {\n return null;\n }\n\n throw new Error(`Error reading directory [\"${directory}\"] while resolving Sass import`, {\n cause: error,\n });\n }\n\n foundDefaults = [];\n foundImports = [];\n cachedEntries = { files: new Set<string>(), directories: new Set<string>() };\n for (const entry of entries) {\n let isDirectory: boolean;\n let isFile: boolean;\n\n if (entry.isSymbolicLink()) {\n const stats = statSync(join(directory, entry.name));\n isDirectory = stats.isDirectory();\n isFile = stats.isFile();\n } else {\n isDirectory = entry.isDirectory();\n isFile = entry.isFile();\n }\n\n if (isDirectory) {\n cachedEntries.directories.add(entry.name);\n\n // Record if the name should be checked as a directory with an index file\n if (checkDirectory && !hasStyleExtension && entry.name === filename) {\n hasPotentialIndex = true;\n }\n }\n\n if (!isFile) {\n continue;\n }\n\n cachedEntries.files.add(entry.name);\n\n if (importPotentials.has(entry.name)) {\n foundImports.push(entry.name);\n }\n\n if (defaultPotentials.has(entry.name)) {\n foundDefaults.push(entry.name);\n }\n }\n\n this.directoryCache.set(directory, cachedEntries);\n }\n\n // `foundImports` will only contain elements if `options.fromImport` is true\n const result = this.checkFound(foundImports) ?? this.checkFound(foundDefaults);\n if (result !== null) {\n return pathToFileURL(join(directory, result));\n }\n\n if (hasPotentialIndex) {\n // Check for index files using filename as a directory\n return this.resolveImport(url + '/index', fromImport, false);\n }\n\n return null;\n }\n\n /**\n * Checks an array of potential stylesheet files to determine if there is a valid\n * stylesheet file. More than one discovered file may indicate an error.\n * @param found An array of discovered stylesheet files.\n * @returns A fully resolved path for a stylesheet file or `null` if not found.\n * @throws If there are ambiguous files discovered.\n */\n private checkFound(found: string[]): string | null {\n if (found.length === 0) {\n // Not found\n return null;\n }\n\n // More than one found file may be an error\n if (found.length > 1) {\n // Presence of CSS files alongside a Sass file does not cause an error\n const foundWithoutCss = found.filter(element => extname(element) !== '.css');\n // If the length is zero then there are two or more css files\n // If the length is more than one than there are two or more sass/scss files\n if (foundWithoutCss.length !== 1) {\n throw new Error('Ambiguous import detected.');\n }\n\n // Return the non-CSS file (sass/scss files have priority)\n // https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart#L44-L47\n return foundWithoutCss[0];\n }\n\n return found[0];\n }\n}\n\n/**\n * Provides the Sass importer logic to resolve module (npm package) stylesheet imports via both import and\n * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that\n * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.\n */\nexport class ModuleUrlRebasingImporter extends RelativeUrlRebasingImporter {\n constructor(\n entryDirectory: string,\n directoryCache: Map<string, DirectoryEntry>,\n private finder: (specifier: string, options: CanonicalizeContext) => URL | null,\n ) {\n super(entryDirectory, directoryCache);\n }\n\n override canonicalize(url: string, options: CanonicalizeContext): URL | null {\n if (url.startsWith('file://')) {\n return super.canonicalize(url, options);\n }\n\n let result = this.finder(url, options);\n result &&= super.canonicalize(result.href, options);\n\n return result;\n }\n}\n\n/**\n * Provides the Sass importer logic to resolve load paths located stylesheet imports via both import and\n * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that\n * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.\n */\nexport class LoadPathsUrlRebasingImporter extends RelativeUrlRebasingImporter {\n constructor(\n entryDirectory: string,\n directoryCache: Map<string, DirectoryEntry>,\n private loadPaths: Iterable<string>,\n ) {\n super(entryDirectory, directoryCache);\n }\n\n override canonicalize(url: string, options: { fromImport: boolean }): URL | null {\n if (url.startsWith('file://')) {\n return super.canonicalize(url, options);\n }\n\n let result = null;\n for (const loadPath of this.loadPaths) {\n result = super.canonicalize(pathToFileURL(join(loadPath, url)).href, options);\n if (result !== null) {\n break;\n }\n }\n\n return result;\n }\n}\n\n/**\n * Workaround for Sass not calling instance methods with `this`.\n * The `canonicalize` and `load` methods will be bound to the class instance.\n * @param importer A Sass importer to bind.\n * @returns The bound Sass importer.\n */\nexport function sassBindWorkaround<T extends Importer>(importer: T): T {\n importer.canonicalize = importer.canonicalize.bind(importer);\n importer.load = importer.load.bind(importer);\n\n return importer;\n}\n"]}
1
+ {"version":3,"file":"rebasing-importer.js","sourceRoot":"","sources":["../../../../../src/lib/styles/sass/rebasing-importer.ts"],"names":[],"mappings":";;;AAAA,qCAA8D;AAC9D,yCAAuE;AACvE,uCAAwD;AAExD,mCAAmC;AAWnC;;;;;;;;;;GAUG;AACH,MAAe,mBAAmB;IAMZ;IALpB;;;;OAIG;IACH,YAAoB,cAAsB;QAAtB,mBAAc,GAAd,cAAc,CAAQ;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;IAID,IAAI,CAAC,Y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GAAG,EAAE,OAAO,CAAC,CAAC;QAC1D,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAClF,CAAC;IAED,IAAI,CAAC,YAAiB;QACpB,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IAClD,CAAC;CACF;AA1BD,wEA0BC;AAED;;;;GAIG;AACH,MAAa,4BAA6B,SAAQ,2BAA2B;IAIjE;IAHV,YACE,cAAsB,EACtB,cAA2C,EACnC,SAA2B;QAEnC,KAAK,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;QAF9B,cAAS,GAAT,SAAS,CAAkB;IAGrC,CAAC;IAEQ,YAAY,CAAC,GAAW,EAAE,OAA4B;QAC7D,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,MAAM,GAAG,IAAI,CAAC;QAClB,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,IAAA,wBAAa,EAAC,IAAA,gBAAI,EAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC9E,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;gBACpB,MAAM;YACR,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAxBD,oEAwBC","sourcesContent":["import { readFileSync, readdirSync, statSync } from 'node:fs';\nimport { basename, dirname, extname, join, relative } from 'node:path';\nimport { fileURLToPath, pathToFileURL } from 'node:url';\nimport type { CanonicalizeContext, Importer, ImporterResult, Syntax } from 'sass-embedded';\nimport { findUrls } from './lexer';\n\n/**\n * A preprocessed cache entry for the files and directories within a previously searched\n * directory when performing Sass import resolution.\n */\nexport interface DirectoryEntry {\n files: Set<string>;\n directories: Set<string>;\n}\n\n/**\n * A Sass Importer base class that provides the load logic to rebase all `url()` functions\n * within a stylesheet. The rebasing will ensure that the URLs in the output of the Sass compiler\n * reflect the final filesystem location of the output CSS file.\n *\n * This class provides the core of the rebasing functionality. To ensure that each file is processed\n * by this importer's load implementation, the Sass compiler requires the importer's canonicalize\n * function to return a non-null value with the resolved location of the requested stylesheet.\n * Concrete implementations of this class must provide this canonicalize functionality for rebasing\n * to be effective.\n */\nabstract class UrlRebasingImporter implements Importer<'sync'> {\n /**\n * @param entryDirectory The directory of the entry stylesheet that was passed to the Sass compiler.\n * @param rebaseSourceMaps When provided, rebased files will have an intermediate sourcemap added to the Map\n * which can be used to generate a final sourcemap that contains original sources.\n */\n constructor(private entryDirectory: string) {\n this.load = this.load.bind(this);\n }\n\n abstract canonicalize(url: string, options: CanonicalizeContext): URL | null;\n\n load(canonicalUrl: URL): ImporterResult | null {\n const stylesheetPath = fileURLToPath(canonicalUrl);\n const stylesheetDirectory = dirname(stylesheetPath);\n let contents = readFileSync(stylesheetPath, 'utf-8');\n\n // Rebase any URLs that are found\n let updatedContents: string;\n for (const { start, end, value } of findUrls(contents)) {\n // Skip if value is empty or Webpack-specific prefix\n if (value.length === 0 || value[0] === '~' || value[0] === '^') {\n continue;\n }\n\n // Skip if root-relative, absolute or protocol relative url\n if (/^((?:\\w+:)?\\/\\/|data:|chrome:|\\/)/.test(value)) {\n continue;\n }\n\n // Skip if a fragment identifier but not a Sass interpolation\n if (value[0] === '#' && value[1] !== '{') {\n continue;\n }\n\n // Skip if value is value contains a function call\n if (/#\\{.+\\(.+\\)\\}/.test(value)) {\n continue;\n }\n\n // Sass variable usage either starts with a `$` or contains a namespace and a `.$`\n const valueNormalized = value[0] === '$' || /^\\w+\\.\\$/.test(value) ? `#{${value}}` : value;\n const rebasedPath = relative(this.entryDirectory, stylesheetDirectory);\n\n // Normalize path separators and escape characters\n // https://developer.mozilla.org/en-US/docs/Web/CSS/url#syntax\n const rebasedUrl = rebasedPath.replace(/\\\\/g, '/').replace(/[()\\s'\"]/g, '\\\\$&');\n\n // eslint-disable-next-line no-useless-assignment\n updatedContents ??= contents;\n updatedContents = contents.slice(0, start) + `\"${rebasedUrl}||file:${valueNormalized}\"` + contents.slice(end);\n }\n\n if (updatedContents) {\n contents = updatedContents;\n }\n\n let syntax: Syntax | undefined;\n switch (extname(stylesheetPath).toLowerCase()) {\n case '.css':\n syntax = 'css';\n break;\n case '.sass':\n syntax = 'indented';\n break;\n default:\n syntax = 'scss';\n break;\n }\n\n return {\n contents,\n syntax,\n sourceMapUrl: canonicalUrl,\n };\n }\n}\n\n/**\n * Provides the Sass importer logic to resolve relative stylesheet imports via both import and use rules\n * and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that\n * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.\n */\nexport class RelativeUrlRebasingImporter extends UrlRebasingImporter {\n constructor(\n entryDirectory: string,\n private directoryCache = new Map<string, DirectoryEntry>(),\n ) {\n super(entryDirectory);\n this.canonicalize = this.canonicalize.bind(this);\n }\n\n canonicalize(url: string, options: CanonicalizeContext): URL | null {\n return this.resolveImport(url, options.fromImport, true);\n }\n\n /**\n * Attempts to resolve a provided URL to a stylesheet file using the Sass compiler's resolution algorithm.\n * Based on https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart\n * @param url The file protocol URL to resolve.\n * @param fromImport If true, URL was from an import rule; otherwise from a use rule.\n * @param checkDirectory If true, try checking for a directory with the base name containing an index file.\n * @returns A full resolved URL of the stylesheet file or `null` if not found.\n */\n private resolveImport(url: string, fromImport: boolean, checkDirectory: boolean): URL | null {\n let stylesheetPath;\n try {\n stylesheetPath = fileURLToPath(url);\n } catch {\n // Only file protocol URLs are supported by this importer\n return null;\n }\n\n const directory = dirname(stylesheetPath);\n const extension = extname(stylesheetPath);\n const hasStyleExtension = extension === '.scss' || extension === '.sass' || extension === '.css';\n // Remove the style extension if present to allow adding the `.import` suffix\n const filename = basename(stylesheetPath, hasStyleExtension ? extension : undefined);\n\n const importPotentials = new Set<string>();\n const defaultPotentials = new Set<string>();\n\n if (hasStyleExtension) {\n if (fromImport) {\n importPotentials.add(filename + '.import' + extension);\n importPotentials.add('_' + filename + '.import' + extension);\n }\n defaultPotentials.add(filename + extension);\n defaultPotentials.add('_' + filename + extension);\n } else {\n if (fromImport) {\n importPotentials.add(filename + '.import.scss');\n importPotentials.add(filename + '.import.sass');\n importPotentials.add(filename + '.import.css');\n importPotentials.add('_' + filename + '.import.scss');\n importPotentials.add('_' + filename + '.import.sass');\n importPotentials.add('_' + filename + '.import.css');\n }\n defaultPotentials.add(filename + '.scss');\n defaultPotentials.add(filename + '.sass');\n defaultPotentials.add(filename + '.css');\n defaultPotentials.add('_' + filename + '.scss');\n defaultPotentials.add('_' + filename + '.sass');\n defaultPotentials.add('_' + filename + '.css');\n }\n\n let foundDefaults;\n let foundImports;\n let hasPotentialIndex = false;\n\n let cachedEntries = this.directoryCache.get(directory);\n if (cachedEntries) {\n // If there is a preprocessed cache of the directory, perform an intersection of the potentials\n // and the directory files.\n const { files, directories } = cachedEntries;\n foundDefaults = [...defaultPotentials].filter(potential => files.has(potential));\n foundImports = [...importPotentials].filter(potential => files.has(potential));\n hasPotentialIndex = checkDirectory && !hasStyleExtension && directories.has(filename);\n } else {\n // If no preprocessed cache exists, get the entries from the file system and, while searching,\n // generate the cache for later requests.\n let entries;\n try {\n entries = readdirSync(directory, { withFileTypes: true });\n } catch (error) {\n // If the containing directory does not exist return null to indicate it cannot be resolved\n if (error.code === 'ENOENT') {\n return null;\n }\n\n throw new Error(`Error reading directory [\"${directory}\"] while resolving Sass import`, {\n cause: error,\n });\n }\n\n foundDefaults = [];\n foundImports = [];\n cachedEntries = { files: new Set<string>(), directories: new Set<string>() };\n for (const entry of entries) {\n let isDirectory: boolean;\n let isFile: boolean;\n\n if (entry.isSymbolicLink()) {\n const stats = statSync(join(directory, entry.name));\n isDirectory = stats.isDirectory();\n isFile = stats.isFile();\n } else {\n isDirectory = entry.isDirectory();\n isFile = entry.isFile();\n }\n\n if (isDirectory) {\n cachedEntries.directories.add(entry.name);\n\n // Record if the name should be checked as a directory with an index file\n if (checkDirectory && !hasStyleExtension && entry.name === filename) {\n hasPotentialIndex = true;\n }\n }\n\n if (!isFile) {\n continue;\n }\n\n cachedEntries.files.add(entry.name);\n\n if (importPotentials.has(entry.name)) {\n foundImports.push(entry.name);\n }\n\n if (defaultPotentials.has(entry.name)) {\n foundDefaults.push(entry.name);\n }\n }\n\n this.directoryCache.set(directory, cachedEntries);\n }\n\n // `foundImports` will only contain elements if `options.fromImport` is true\n const result = this.checkFound(foundImports) ?? this.checkFound(foundDefaults);\n if (result !== null) {\n return pathToFileURL(join(directory, result));\n }\n\n if (hasPotentialIndex) {\n // Check for index files using filename as a directory\n return this.resolveImport(url + '/index', fromImport, false);\n }\n\n return null;\n }\n\n /**\n * Checks an array of potential stylesheet files to determine if there is a valid\n * stylesheet file. More than one discovered file may indicate an error.\n * @param found An array of discovered stylesheet files.\n * @returns A fully resolved path for a stylesheet file or `null` if not found.\n * @throws If there are ambiguous files discovered.\n */\n private checkFound(found: string[]): string | null {\n if (found.length === 0) {\n // Not found\n return null;\n }\n\n // More than one found file may be an error\n if (found.length > 1) {\n // Presence of CSS files alongside a Sass file does not cause an error\n const foundWithoutCss = found.filter(element => extname(element) !== '.css');\n // If the length is zero then there are two or more css files\n // If the length is more than one than there are two or more sass/scss files\n if (foundWithoutCss.length !== 1) {\n throw new Error('Ambiguous import detected.');\n }\n\n // Return the non-CSS file (sass/scss files have priority)\n // https://github.com/sass/dart-sass/blob/44d6bb6ac72fe6b93f5bfec371a1fffb18e6b76d/lib/src/importer/utils.dart#L44-L47\n return foundWithoutCss[0];\n }\n\n return found[0];\n }\n}\n\n/**\n * Provides the Sass importer logic to resolve module (npm package) stylesheet imports asynchronously\n * and also rebase any `url()` function usage within those stylesheets.\n */\nexport class AsyncModuleUrlRebasingImporter implements Importer<'async'> {\n private relativeImporter: RelativeUrlRebasingImporter;\n\n constructor(\n entryDirectory: string,\n directoryCache: Map<string, DirectoryEntry>,\n private finder: (specifier: string, options: CanonicalizeContext) => Promise<URL | null> | URL | null,\n ) {\n this.relativeImporter = new RelativeUrlRebasingImporter(entryDirectory, directoryCache);\n this.canonicalize = this.canonicalize.bind(this);\n this.load = this.load.bind(this);\n }\n\n async canonicalize(url: string, options: CanonicalizeContext): Promise<URL | null> {\n if (url.startsWith('file://')) {\n return this.relativeImporter.canonicalize(url, options);\n }\n\n const result = await this.finder(url, options);\n\n return result ? this.relativeImporter.canonicalize(result.href, options) : null;\n }\n\n load(canonicalUrl: URL): ImporterResult | null {\n return this.relativeImporter.load(canonicalUrl);\n }\n}\n\n/**\n * Provides the Sass importer logic to resolve load paths located stylesheet imports via both import and\n * use rules and also rebase any `url()` function usage within those stylesheets. The rebasing will ensure that\n * the URLs in the output of the Sass compiler reflect the final filesystem location of the output CSS file.\n */\nexport class LoadPathsUrlRebasingImporter extends RelativeUrlRebasingImporter {\n constructor(\n entryDirectory: string,\n directoryCache: Map<string, DirectoryEntry>,\n private loadPaths: Iterable<string>,\n ) {\n super(entryDirectory, directoryCache);\n }\n\n override canonicalize(url: string, options: CanonicalizeContext): URL | null {\n if (url.startsWith('file://')) {\n return super.canonicalize(url, options);\n }\n\n let result = null;\n for (const loadPath of this.loadPaths) {\n result = super.canonicalize(pathToFileURL(join(loadPath, url)).href, options);\n if (result !== null) {\n break;\n }\n }\n\n return result;\n }\n}\n"]}
@@ -1,41 +1,22 @@
1
- import type { CompileResult, Deprecation, SourceSpan, StringOptions } from 'sass';
2
- export interface SerializableVersion {
3
- major: number;
4
- minor: number;
5
- patch: number;
6
- }
7
- export interface SerializableDeprecation extends Omit<Deprecation, 'obsoleteIn' | 'deprecatedIn'> {
8
- /** The version this deprecation first became active in. */
9
- deprecatedIn: SerializableVersion | null;
10
- /** The version this deprecation became obsolete in. */
11
- obsoleteIn: SerializableVersion | null;
12
- }
13
- export type SerializableWarningMessage = ({
14
- deprecation: true;
15
- deprecationType: SerializableDeprecation;
16
- } | {
17
- deprecation: false;
18
- }) & {
19
- message: string;
20
- span?: Omit<SourceSpan, 'url'> & {
21
- url?: string;
22
- };
23
- stack?: string;
24
- };
1
+ import type { CompileResult, StringOptions } from 'sass-embedded';
2
+ /**
3
+ * When `NG_BUILD_SASS_EMBEDDED` is set to `0` or `false`, or when running within a
4
+ * WebContainer environment, the native embedded Sass compiler is disabled
5
+ * and the pure-JavaScript Sass compiler is used instead.
6
+ */
7
+ export declare const useSassEmbedded: boolean;
25
8
  /**
26
- * A Sass renderer implementation that provides an interface that can be used by Webpack's
27
- * `sass-loader`. The implementation uses a Worker thread to perform the Sass rendering
28
- * with the `dart-sass` package. The `dart-sass` synchronous render function is used within
29
- * the worker which can be up to two times faster than the asynchronous variant.
9
+ * A Sass renderer implementation that uses the persistent Dart Sass embedded compiler
10
+ * daemon (`sass-embedded`) communicating over standard input/output with protocol buffers,
11
+ * or falls back to the pure-JS Dart Sass async compiler (`sass.initAsyncCompiler()`).
30
12
  */
31
- export declare class SassWorkerImplementation {
13
+ export declare class SassCompiler {
32
14
  #private;
33
15
  private readonly rebase;
34
- readonly maxThreads: number;
35
- constructor(rebase?: boolean, maxThreads?: number);
16
+ constructor(rebase?: boolean);
36
17
  /**
37
18
  * Provides information about the Sass implementation.
38
- * This mimics enough of the `dart-sass` value to be used with the `sass-loader`.
19
+ * This mimics enough of the `sass-embedded` or `sass` value to be used with the `sass-loader`.
39
20
  */
40
21
  get info(): string;
41
22
  /**
@@ -43,18 +24,20 @@ export declare class SassWorkerImplementation {
43
24
  */
44
25
  compileString(): never;
45
26
  /**
46
- * Asynchronously request a Sass stylesheet to be renderered.
27
+ * Asynchronously request a Sass stylesheet to be rendered using the native embedded compiler
28
+ * or the pure-JS async compiler fallback.
47
29
  *
48
30
  * @param source The contents to compile.
49
- * @param options The `dart-sass` options to use when rendering the stylesheet.
31
+ * @param options The `sass` / `sass-embedded` options to use when rendering the stylesheet.
50
32
  */
51
33
  compileStringAsync(source: string, options: StringOptions<'async'>): Promise<CompileResult>;
52
34
  /**
53
- * Shutdown the Sass render worker.
54
- * Executing this method will stop any pending render requests.
35
+ * Clear the directory cache.
36
+ */
37
+ clearCache(): void;
38
+ /**
39
+ * Shutdown the Sass compiler.
55
40
  * @returns A void promise that resolves when closing is complete.
56
41
  */
57
42
  close(): Promise<void>;
58
- private processImporters;
59
- private isFileImporter;
60
43
  }