sass-loader 17.0.1 → 17.1.0

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/dist/cjs/index.js CHANGED
@@ -70,8 +70,9 @@ async function loader(content) {
70
70
  for (const includedFile of result.loadedUrls.filter(loadedUrl => loadedUrl.protocol === "file:")) {
71
71
  const normalizedIncludedFile = _nodeUrl.default.fileURLToPath(includedFile);
72
72
 
73
- // Custom `importer` can return only `contents` so includedFile will be relative
74
- if (_nodePath.default.isAbsolute(normalizedIncludedFile)) {
73
+ // Custom `importer` can return only `contents` so includedFile will be relative;
74
+ // a `data:` resource's own file exists nowhere.
75
+ if (_nodePath.default.isAbsolute(normalizedIncludedFile) && !(this.resourcePath.startsWith("data:") && normalizedIncludedFile === (0, _utils.getResourcePath)(this))) {
75
76
  this.addDependency(normalizedIncludedFile);
76
77
  }
77
78
  }
package/dist/cjs/utils.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.errorFactory = errorFactory;
7
7
  exports.getCompileFn = getCompileFn;
8
8
  exports.getModernWebpackImporter = getModernWebpackImporter;
9
+ exports.getResourcePath = getResourcePath;
9
10
  exports.getSassImplementation = getSassImplementation;
10
11
  exports.getSassOptions = getSassOptions;
11
12
  exports.getWebpackResolver = getWebpackResolver;
@@ -176,6 +177,23 @@ function isProductionLikeMode(loaderContext) {
176
177
  return loaderContext.mode === "production" || !loaderContext.mode;
177
178
  }
178
179
 
180
+ /**
181
+ * The path a resource's contents resolve from. A `data:` URI has none of its own,
182
+ * so it reads as a file in the loader's context, with the syntax its media type names.
183
+ * @param {LoaderContext} loaderContext loader context
184
+ * @returns {string} the resource's path, or a file in its context for a `data:` URI
185
+ */
186
+ function getResourcePath(loaderContext) {
187
+ const {
188
+ resourcePath
189
+ } = loaderContext;
190
+ if (!resourcePath.startsWith("data:")) {
191
+ return resourcePath;
192
+ }
193
+ const indented = /^data:text\/x-sass[;,]/i.test(resourcePath);
194
+ return _nodePath.default.join(loaderContext.context, indented ? "stdin.sass" : "stdin.scss");
195
+ }
196
+
179
197
  /**
180
198
  * Derives the sass options from the loader context and normalizes its values with sane defaults.
181
199
  * @param {LoaderContext} loaderContext loader context
@@ -250,9 +268,7 @@ async function getSassOptions(loaderContext, loaderOptions, content, useSourceMa
250
268
  }
251
269
  };
252
270
  }
253
- const {
254
- resourcePath
255
- } = loaderContext;
271
+ const resourcePath = getResourcePath(loaderContext);
256
272
  sassOptions.url = _nodeUrl.default.pathToFileURL(resourcePath);
257
273
 
258
274
  // opt.outputStyle
@@ -471,7 +487,7 @@ function getModernWebpackImporter(loaderContext) {
471
487
  const {
472
488
  fromImport
473
489
  } = context;
474
- const prev = context.containingUrl ? _nodeUrl.default.fileURLToPath(context.containingUrl.toString()) : loaderContext.resourcePath;
490
+ const prev = context.containingUrl ? _nodeUrl.default.fileURLToPath(context.containingUrl.toString()) : getResourcePath(loaderContext);
475
491
  let result;
476
492
  try {
477
493
  result = await resolve(prev, originalUrl, fromImport);
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import path from "node:path";
2
2
  import url from "node:url";
3
3
  import schema from "./options.json" with { type: "json" };
4
- import { errorFactory, getCompileFn, getModernWebpackImporter, getSassImplementation, getSassOptions, normalizeSourceMap, removeBOM } from "./utils.js";
4
+ import { errorFactory, getCompileFn, getModernWebpackImporter, getResourcePath, getSassImplementation, getSassOptions, normalizeSourceMap, removeBOM } from "./utils.js";
5
5
 
6
6
  /** @typedef {import("webpack").LoaderContext<LoaderOptions>} LoaderContext */
7
7
  /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
@@ -64,8 +64,9 @@ async function loader(content) {
64
64
  for (const includedFile of result.loadedUrls.filter(loadedUrl => loadedUrl.protocol === "file:")) {
65
65
  const normalizedIncludedFile = url.fileURLToPath(includedFile);
66
66
 
67
- // Custom `importer` can return only `contents` so includedFile will be relative
68
- if (path.isAbsolute(normalizedIncludedFile)) {
67
+ // Custom `importer` can return only `contents` so includedFile will be relative;
68
+ // a `data:` resource's own file exists nowhere.
69
+ if (path.isAbsolute(normalizedIncludedFile) && !(this.resourcePath.startsWith("data:") && normalizedIncludedFile === getResourcePath(this))) {
69
70
  this.addDependency(normalizedIncludedFile);
70
71
  }
71
72
  }
package/dist/esm/utils.js CHANGED
@@ -163,6 +163,23 @@ function isProductionLikeMode(loaderContext) {
163
163
  return loaderContext.mode === "production" || !loaderContext.mode;
164
164
  }
165
165
 
166
+ /**
167
+ * The path a resource's contents resolve from. A `data:` URI has none of its own,
168
+ * so it reads as a file in the loader's context, with the syntax its media type names.
169
+ * @param {LoaderContext} loaderContext loader context
170
+ * @returns {string} the resource's path, or a file in its context for a `data:` URI
171
+ */
172
+ function getResourcePath(loaderContext) {
173
+ const {
174
+ resourcePath
175
+ } = loaderContext;
176
+ if (!resourcePath.startsWith("data:")) {
177
+ return resourcePath;
178
+ }
179
+ const indented = /^data:text\/x-sass[;,]/i.test(resourcePath);
180
+ return path.join(loaderContext.context, indented ? "stdin.sass" : "stdin.scss");
181
+ }
182
+
166
183
  /**
167
184
  * Derives the sass options from the loader context and normalizes its values with sane defaults.
168
185
  * @param {LoaderContext} loaderContext loader context
@@ -237,9 +254,7 @@ async function getSassOptions(loaderContext, loaderOptions, content, useSourceMa
237
254
  }
238
255
  };
239
256
  }
240
- const {
241
- resourcePath
242
- } = loaderContext;
257
+ const resourcePath = getResourcePath(loaderContext);
243
258
  sassOptions.url = url.pathToFileURL(resourcePath);
244
259
 
245
260
  // opt.outputStyle
@@ -458,7 +473,7 @@ function getModernWebpackImporter(loaderContext) {
458
473
  const {
459
474
  fromImport
460
475
  } = context;
461
- const prev = context.containingUrl ? url.fileURLToPath(context.containingUrl.toString()) : loaderContext.resourcePath;
476
+ const prev = context.containingUrl ? url.fileURLToPath(context.containingUrl.toString()) : getResourcePath(loaderContext);
462
477
  let result;
463
478
  try {
464
479
  result = await resolve(prev, originalUrl, fromImport);
@@ -740,4 +755,4 @@ function errorFactory(error) {
740
755
  obj.stack = undefined;
741
756
  return obj;
742
757
  }
743
- export { errorFactory, getCompileFn, getModernWebpackImporter, getSassImplementation, getSassOptions, getWebpackResolver, normalizeSourceMap, removeBOM };
758
+ export { errorFactory, getCompileFn, getModernWebpackImporter, getResourcePath, getSassImplementation, getSassOptions, getWebpackResolver, normalizeSourceMap, removeBOM };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sass-loader",
3
- "version": "17.0.1",
3
+ "version": "17.1.0",
4
4
  "description": "Sass loader for webpack",
5
5
  "keywords": [
6
6
  "sass",
package/types/utils.d.ts CHANGED
@@ -245,6 +245,13 @@ export function getCompileFn<T extends SassImplementation>(
245
245
  export function getModernWebpackImporter(
246
246
  loaderContext: LoaderContext,
247
247
  ): Importer;
248
+ /**
249
+ * The path a resource's contents resolve from. A `data:` URI has none of its own,
250
+ * so it reads as a file in the loader's context, with the syntax its media type names.
251
+ * @param {LoaderContext} loaderContext loader context
252
+ * @returns {string} the resource's path, or a file in its context for a `data:` URI
253
+ */
254
+ export function getResourcePath(loaderContext: LoaderContext): string;
248
255
  /**
249
256
  * This function is not Webpack-specific and can be used by tools wishing to mimic `sass-loader`'s behaviour, so its signature should not be changed.
250
257
  * @param {SassImplementation | string | undefined} implementation sass implementation