@ms-cloudpack/bundler-rollup 0.6.2 → 0.6.4
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/NOTICE.txt +61 -0
- package/lib/getRollupCapabilities.d.ts +9 -0
- package/lib/getRollupCapabilities.d.ts.map +1 -0
- package/lib/{rollupCapabilities.js → getRollupCapabilities.js} +10 -4
- package/lib/getRollupCapabilities.js.map +1 -0
- package/lib/getRollupPlugins.d.ts.map +1 -1
- package/lib/getRollupPlugins.js +7 -1
- package/lib/getRollupPlugins.js.map +1 -1
- package/lib/plugins/json/index.js +1 -1
- package/lib/plugins/json/index.js.map +1 -1
- package/lib/plugins/postcss/index.d.ts +3 -10
- package/lib/plugins/postcss/index.d.ts.map +1 -1
- package/lib/plugins/postcss/index.js +37 -48
- package/lib/plugins/postcss/index.js.map +1 -1
- package/lib/plugins/postcss/less-loader.d.ts +2 -8
- package/lib/plugins/postcss/less-loader.d.ts.map +1 -1
- package/lib/plugins/postcss/less-loader.js +8 -11
- package/lib/plugins/postcss/less-loader.js.map +1 -1
- package/lib/plugins/postcss/loaders.d.ts +15 -21
- package/lib/plugins/postcss/loaders.d.ts.map +1 -1
- package/lib/plugins/postcss/loaders.js +14 -34
- package/lib/plugins/postcss/loaders.js.map +1 -1
- package/lib/plugins/postcss/postcss-loader.d.ts +2 -9
- package/lib/plugins/postcss/postcss-loader.d.ts.map +1 -1
- package/lib/plugins/postcss/postcss-loader.js +30 -36
- package/lib/plugins/postcss/postcss-loader.js.map +1 -1
- package/lib/plugins/postcss/sass-loader.d.ts +5 -8
- package/lib/plugins/postcss/sass-loader.d.ts.map +1 -1
- package/lib/plugins/postcss/sass-loader.js +50 -52
- package/lib/plugins/postcss/sass-loader.js.map +1 -1
- package/lib/plugins/postcss/types.d.ts +96 -25
- package/lib/plugins/postcss/types.d.ts.map +1 -1
- package/lib/plugins/postcss/types.js +0 -1
- package/lib/plugins/postcss/types.js.map +1 -1
- package/lib/plugins/postcss/utils/load-module.d.ts +10 -4
- package/lib/plugins/postcss/utils/load-module.d.ts.map +1 -1
- package/lib/plugins/postcss/utils/load-module.js +10 -11
- package/lib/plugins/postcss/utils/load-module.js.map +1 -1
- package/lib/plugins/postcss/utils/normalize-path.d.ts +7 -2
- package/lib/plugins/postcss/utils/normalize-path.d.ts.map +1 -1
- package/lib/plugins/postcss/utils/normalize-path.js +12 -3
- package/lib/plugins/postcss/utils/normalize-path.js.map +1 -1
- package/lib/rollup.d.ts.map +1 -1
- package/lib/rollup.js +4 -2
- package/lib/rollup.js.map +1 -1
- package/package.json +5 -3
- package/lib/plugins/postcss/utils/humanlize-path.d.ts +0 -3
- package/lib/plugins/postcss/utils/humanlize-path.d.ts.map +0 -1
- package/lib/plugins/postcss/utils/humanlize-path.js +0 -7
- package/lib/plugins/postcss/utils/humanlize-path.js.map +0 -1
- package/lib/rollupCapabilities.d.ts +0 -7
- package/lib/rollupCapabilities.d.ts.map +0 -1
- package/lib/rollupCapabilities.js.map +0 -1
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { BaseLoaderContext, Loader, PostCSSPluginConf, Resource, ResourceResult } from './types.js';
|
|
2
|
+
export type LoadersConstructorOptions = {
|
|
3
|
+
[k in 'loaders' | 'extensions']: PostCSSPluginConf[k];
|
|
4
|
+
} & {
|
|
5
|
+
use: Extract<NonNullable<PostCSSPluginConf['use']>, unknown[]>;
|
|
6
|
+
};
|
|
7
|
+
export declare class Loaders {
|
|
8
|
+
private use;
|
|
9
|
+
private loaders;
|
|
10
|
+
constructor(options: LoadersConstructorOptions);
|
|
11
|
+
registerLoader(loader: Loader<unknown>): this;
|
|
12
|
+
removeLoader(name: string): this;
|
|
13
|
+
isSupported(filepath: string): boolean;
|
|
6
14
|
/**
|
|
7
15
|
* Process the resource with loaders in serial
|
|
8
|
-
* @param {object} resource
|
|
9
|
-
* @param {string} resource.code
|
|
10
|
-
* @param {any} resource.map
|
|
11
|
-
* @param {object} context
|
|
12
|
-
* @param {string} context.id The absolute path to resource
|
|
13
|
-
* @param {boolean | 'inline'} context.sourceMap
|
|
14
|
-
* @param {Set<string>} context.dependencies A set of dependencies to watch
|
|
15
|
-
* @returns {{code: string, map?: any}}
|
|
16
16
|
*/
|
|
17
|
-
process({ code, map }:
|
|
18
|
-
|
|
19
|
-
map: any;
|
|
20
|
-
}, context: any): Promise<{
|
|
21
|
-
code: any;
|
|
22
|
-
map: any;
|
|
23
|
-
}>;
|
|
24
|
-
getLoader(name: any): any;
|
|
17
|
+
process({ code, map }: Resource, context: BaseLoaderContext): Promise<ResourceResult>;
|
|
18
|
+
getLoader(name: string): Loader<unknown> | undefined;
|
|
25
19
|
}
|
|
26
20
|
//# sourceMappingURL=loaders.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loaders.d.ts","sourceRoot":"","sources":["../../../src/plugins/postcss/loaders.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loaders.d.ts","sourceRoot":"","sources":["../../../src/plugins/postcss/loaders.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAEjB,MAAM,EAEN,iBAAiB,EACjB,QAAQ,EACR,cAAc,EACf,MAAM,YAAY,CAAC;AAKpB,MAAM,MAAM,yBAAyB,GAAG;KACrC,CAAC,IAAI,SAAS,GAAG,YAAY,GAAG,iBAAiB,CAAC,CAAC,CAAC;CACtD,GAAG;IACF,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;CAChE,CAAC;AAUF,qBAAa,OAAO;IAClB,OAAO,CAAC,GAAG,CAAsB;IACjC,OAAO,CAAC,OAAO,CAAoB;gBAEvB,OAAO,EAAE,yBAAyB;IA2B9C,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,IAAI;IAU7C,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAKhC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAMtC;;OAEG;IACG,OAAO,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,cAAc,CAAC;IAgB3F,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,SAAS;CAGrD"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
import path from 'path';
|
|
4
|
-
import postcssLoader from './postcss-loader.js';
|
|
5
|
-
import sassLoader from './sass-loader.js';
|
|
6
|
-
import lessLoader from './less-loader.js';
|
|
2
|
+
import { postcssLoader } from './postcss-loader.js';
|
|
3
|
+
import { sassLoader } from './sass-loader.js';
|
|
4
|
+
import { lessLoader } from './less-loader.js';
|
|
7
5
|
const matchFile = (filepath, condition) => {
|
|
8
6
|
if (typeof condition === 'function') {
|
|
9
7
|
return condition(filepath);
|
|
10
8
|
}
|
|
11
9
|
return condition && condition.test(filepath);
|
|
12
10
|
};
|
|
13
|
-
export
|
|
14
|
-
|
|
11
|
+
export class Loaders {
|
|
12
|
+
use;
|
|
13
|
+
loaders;
|
|
14
|
+
constructor(options) {
|
|
15
15
|
this.use = options.use.map((rule) => {
|
|
16
16
|
if (typeof rule === 'string') {
|
|
17
17
|
return [rule];
|
|
@@ -53,36 +53,16 @@ export default class Loaders {
|
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
55
|
* Process the resource with loaders in serial
|
|
56
|
-
* @param {object} resource
|
|
57
|
-
* @param {string} resource.code
|
|
58
|
-
* @param {any} resource.map
|
|
59
|
-
* @param {object} context
|
|
60
|
-
* @param {string} context.id The absolute path to resource
|
|
61
|
-
* @param {boolean | 'inline'} context.sourceMap
|
|
62
|
-
* @param {Set<string>} context.dependencies A set of dependencies to watch
|
|
63
|
-
* @returns {{code: string, map?: any}}
|
|
64
56
|
*/
|
|
65
57
|
async process({ code, map }, context) {
|
|
66
|
-
const loaderFunctions = this.use
|
|
67
|
-
.slice()
|
|
68
|
-
.reverse()
|
|
69
|
-
.map(([name, options]) => {
|
|
70
|
-
const loader = this.getLoader(name);
|
|
71
|
-
const loaderContext = {
|
|
72
|
-
options: options || {},
|
|
73
|
-
...context,
|
|
74
|
-
};
|
|
75
|
-
return (v) => {
|
|
76
|
-
if (loader.alwaysProcess || matchFile(loaderContext.id, loader.test)) {
|
|
77
|
-
return loader.process.call(loaderContext, v);
|
|
78
|
-
}
|
|
79
|
-
// Otherwise directly return input value
|
|
80
|
-
return v;
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
58
|
let result = { code, map };
|
|
84
|
-
for (
|
|
85
|
-
|
|
59
|
+
for (let i = this.use.length - 1; i >= 0; i--) {
|
|
60
|
+
const [name, options = {}] = this.use[i];
|
|
61
|
+
const loader = this.getLoader(name);
|
|
62
|
+
const loaderContext = { options, ...context };
|
|
63
|
+
if (loader && (loader.alwaysProcess || matchFile(loaderContext.id, loader.test))) {
|
|
64
|
+
result = await loader.process.call(loaderContext, result);
|
|
65
|
+
}
|
|
86
66
|
}
|
|
87
67
|
return result;
|
|
88
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loaders.js","sourceRoot":"","sources":["../../../src/plugins/postcss/loaders.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"loaders.js","sourceRoot":"","sources":["../../../src/plugins/postcss/loaders.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAUxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAQ9C,MAAM,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GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YACpC,MAAM,aAAa,GAA2B,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;YAEtE,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,IAAI,SAAS,CAAC,aAAa,CAAC,EAAE,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;gBACjF,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import path from 'path';\nimport type {\n BaseLoaderContext,\n InternalPostCSSLoaderOptions,\n Loader,\n LoaderContext,\n PostCSSPluginConf,\n Resource,\n ResourceResult,\n} from './types.js';\nimport { postcssLoader } from './postcss-loader.js';\nimport { sassLoader } from './sass-loader.js';\nimport { lessLoader } from './less-loader.js';\n\nexport type LoadersConstructorOptions = {\n [k in 'loaders' | 'extensions']: PostCSSPluginConf[k];\n} & {\n use: Extract<NonNullable<PostCSSPluginConf['use']>, unknown[]>;\n};\n\nconst matchFile = (filepath: string, condition: ((filepath: string) => boolean) | RegExp | undefined) => {\n if (typeof condition === 'function') {\n return condition(filepath);\n }\n\n return condition && condition.test(filepath);\n};\n\nexport class Loaders {\n private use: [string, object?][];\n private loaders: Loader<unknown>[];\n\n constructor(options: LoadersConstructorOptions) {\n this.use = options.use.map((rule) => {\n if (typeof rule === 'string') {\n return [rule];\n }\n\n if (Array.isArray(rule)) {\n return rule;\n }\n\n throw new TypeError('The rule in `use` option must be string or Array!');\n });\n this.loaders = [];\n\n const extensions = options.extensions || ['.css', '.sss', '.pcss'];\n const customPostcssLoader: Loader<InternalPostCSSLoaderOptions> = {\n ...postcssLoader,\n test: (filepath) => extensions.some((ext) => path.extname(filepath) === ext),\n };\n this.registerLoader(customPostcssLoader);\n this.registerLoader(sassLoader);\n this.registerLoader(lessLoader);\n if (options.loaders) {\n options.loaders.forEach((loader) => this.registerLoader(loader));\n }\n }\n\n registerLoader(loader: Loader<unknown>): this {\n const existing = this.getLoader(loader.name);\n if (existing) {\n this.removeLoader(loader.name);\n }\n\n this.loaders.push(loader);\n return this;\n }\n\n removeLoader(name: string): this {\n this.loaders = this.loaders.filter((loader) => loader.name !== name);\n return this;\n }\n\n isSupported(filepath: string): boolean {\n return this.loaders.some((loader) => {\n return matchFile(filepath, loader.test);\n });\n }\n\n /**\n * Process the resource with loaders in serial\n */\n async process({ code, map }: Resource, context: BaseLoaderContext): Promise<ResourceResult> {\n let result: ResourceResult = { code, map };\n\n for (let i = this.use.length - 1; i >= 0; i--) {\n const [name, options = {}] = this.use[i];\n const loader = this.getLoader(name);\n const loaderContext: LoaderContext<unknown> = { options, ...context };\n\n if (loader && (loader.alwaysProcess || matchFile(loaderContext.id, loader.test))) {\n result = await loader.process.call(loaderContext, result);\n }\n }\n\n return result;\n }\n\n getLoader(name: string): Loader<unknown> | undefined {\n return this.loaders.find((loader) => loader.name === name);\n }\n}\n"]}
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
alwaysProcess: boolean;
|
|
4
|
-
process({ code, map }: {
|
|
5
|
-
code: any;
|
|
6
|
-
map: any;
|
|
7
|
-
}): any;
|
|
8
|
-
};
|
|
9
|
-
export default _default;
|
|
1
|
+
import type { InternalPostCSSLoaderOptions, Loader } from './types.js';
|
|
2
|
+
export declare const postcssLoader: Loader<InternalPostCSSLoaderOptions>;
|
|
10
3
|
//# sourceMappingURL=postcss-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postcss-loader.d.ts","sourceRoot":"","sources":["../../../src/plugins/postcss/postcss-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"postcss-loader.d.ts","sourceRoot":"","sources":["../../../src/plugins/postcss/postcss-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAiB,4BAA4B,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA2CtF,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,4BAA4B,CAkJ9D,CAAC"}
|
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
import { createRequire } from 'module';
|
|
4
2
|
import postcss from 'postcss';
|
|
5
3
|
import { identifier } from 'safe-identifier';
|
|
6
|
-
import
|
|
7
|
-
import normalizePath from './utils/normalize-path.js';
|
|
4
|
+
import { normalizePath } from './utils/normalize-path.js';
|
|
8
5
|
const require = createRequire(import.meta.url);
|
|
9
6
|
const styleInjectPath = require.resolve('style-inject/dist/style-inject.es').replace(/[\\/]+/g, '/');
|
|
7
|
+
// loadConfig helper removed
|
|
10
8
|
/**
|
|
11
9
|
* Escape CSS class name dashes for JavaScript identifiers
|
|
12
10
|
*/
|
|
13
|
-
function escapeClassNameDashes(
|
|
14
|
-
return
|
|
11
|
+
function escapeClassNameDashes(str) {
|
|
12
|
+
return str.replace(/-+/g, (match) => {
|
|
15
13
|
return `$${match.replace(/-/g, '_')}$`;
|
|
16
14
|
});
|
|
17
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Ensure class name is a valid JavaScript identifier
|
|
18
|
+
*/
|
|
18
19
|
function ensureClassName(name) {
|
|
19
|
-
|
|
20
|
-
return identifier(
|
|
20
|
+
const escapedName = escapeClassNameDashes(name);
|
|
21
|
+
return identifier(escapedName, false);
|
|
21
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Ensure PostCSS option is properly loaded
|
|
25
|
+
*/
|
|
22
26
|
async function ensurePostCSSOption(option) {
|
|
23
27
|
if (typeof option === 'string') {
|
|
24
28
|
try {
|
|
25
29
|
const resolvedPath = require.resolve(option);
|
|
26
|
-
return await import(resolvedPath);
|
|
30
|
+
return (await import(resolvedPath));
|
|
27
31
|
}
|
|
28
32
|
catch {
|
|
29
33
|
return option;
|
|
@@ -34,7 +38,7 @@ async function ensurePostCSSOption(option) {
|
|
|
34
38
|
function isModuleFile(file) {
|
|
35
39
|
return /\.module\.[a-z]{2,6}$/.test(file);
|
|
36
40
|
}
|
|
37
|
-
export
|
|
41
|
+
export const postcssLoader = {
|
|
38
42
|
name: 'postcss',
|
|
39
43
|
alwaysProcess: true,
|
|
40
44
|
async process({ code, map }) {
|
|
@@ -52,10 +56,10 @@ export default {
|
|
|
52
56
|
const isAutoModule = autoModules && isModuleFile(this.id);
|
|
53
57
|
const supportModules = autoModules ? isAutoModule : options.modules;
|
|
54
58
|
if (supportModules) {
|
|
55
|
-
|
|
56
|
-
plugins.unshift(postcssModules.default({
|
|
59
|
+
plugins.unshift((await import('postcss-modules')).default({
|
|
57
60
|
// In tests
|
|
58
61
|
// Skip hash in names since css content on windows and linux would differ because of `new line` (\r?\n)
|
|
62
|
+
// eslint-disable-next-line no-restricted-properties
|
|
59
63
|
generateScopedName: process.env.ROLLUP_POSTCSS_TEST ? '[name]_[local]' : '[name]_[local]__[hash:base64:5]',
|
|
60
64
|
...options.modules,
|
|
61
65
|
getJSON(filepath, json, outpath) {
|
|
@@ -68,36 +72,29 @@ export default {
|
|
|
68
72
|
}
|
|
69
73
|
// If shouldExtract, minimize is done after all CSS are extracted to a file
|
|
70
74
|
if (!shouldExtract && options.minimize) {
|
|
71
|
-
|
|
72
|
-
plugins.push(cssnano.default(options.minimize));
|
|
75
|
+
plugins.push((await import('cssnano')).default(options.minimize));
|
|
73
76
|
}
|
|
74
77
|
const postcssOptions = {
|
|
75
|
-
...this.options.postcss,
|
|
76
78
|
// Allow overriding `to` for some plugins that are relying on this value
|
|
77
79
|
to: options.to || this.id,
|
|
78
|
-
// Followings are never modified by user config config
|
|
79
80
|
from: this.id,
|
|
80
|
-
map: this.sourceMap
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
map: this.sourceMap ? { inline: !shouldExtract, annotation: false } : false,
|
|
82
|
+
parser: await ensurePostCSSOption(options.postcss.parser),
|
|
83
|
+
syntax: await ensurePostCSSOption(options.postcss.syntax),
|
|
84
|
+
stringifier: await ensurePostCSSOption(options.postcss.stringifier),
|
|
85
|
+
// this was spread in before but doesn't appear to exist
|
|
86
|
+
// exec: options.postcss.exec,
|
|
85
87
|
};
|
|
86
|
-
|
|
87
|
-
postcssOptions.parser = await ensurePostCSSOption(postcssOptions.parser);
|
|
88
|
-
postcssOptions.syntax = await ensurePostCSSOption(postcssOptions.syntax);
|
|
89
|
-
postcssOptions.stringifier = await ensurePostCSSOption(postcssOptions.stringifier);
|
|
90
|
-
if (map && postcssOptions.map) {
|
|
88
|
+
if (map && typeof postcssOptions.map === 'object') {
|
|
91
89
|
postcssOptions.map.prev = typeof map === 'string' ? JSON.parse(map) : map;
|
|
92
90
|
}
|
|
93
91
|
if (plugins.length === 0) {
|
|
94
92
|
// Prevent from postcss warning:
|
|
95
93
|
// You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js
|
|
96
|
-
|
|
94
|
+
plugins.push({
|
|
97
95
|
postcssPlugin: 'postcss-noop-plugin',
|
|
98
96
|
Once() { },
|
|
99
97
|
});
|
|
100
|
-
plugins.push(noopPlugin());
|
|
101
98
|
}
|
|
102
99
|
const result = await postcss(plugins).process(code, postcssOptions);
|
|
103
100
|
for (const message of result.messages) {
|
|
@@ -106,13 +103,10 @@ export default {
|
|
|
106
103
|
}
|
|
107
104
|
}
|
|
108
105
|
for (const warning of result.warnings()) {
|
|
109
|
-
|
|
110
|
-
warning.message = warning.text;
|
|
111
|
-
}
|
|
112
|
-
this.warn(warning);
|
|
106
|
+
this.warn({ message: warning.text, ...warning });
|
|
113
107
|
}
|
|
114
108
|
const outputMap = result.map && JSON.parse(result.map.toString());
|
|
115
|
-
if (outputMap
|
|
109
|
+
if (outputMap && typeof outputMap === 'object' && 'sources' in outputMap) {
|
|
116
110
|
outputMap.sources = outputMap.sources.map((v) => normalizePath(v));
|
|
117
111
|
}
|
|
118
112
|
let output = '';
|
|
@@ -126,7 +120,8 @@ export default {
|
|
|
126
120
|
// But skip this when namedExports is a function
|
|
127
121
|
// Since a user like you can manually log that if you want
|
|
128
122
|
if (name !== newName && typeof options.namedExports !== 'function') {
|
|
129
|
-
this
|
|
123
|
+
// Logging this as an absolute path is better for our use case
|
|
124
|
+
this.warn(`Exported "${name}" as "${newName}" in ${this.id}`);
|
|
130
125
|
}
|
|
131
126
|
if (!json[newName]) {
|
|
132
127
|
json[newName] = json[name];
|
|
@@ -154,8 +149,7 @@ export default {
|
|
|
154
149
|
output +=
|
|
155
150
|
typeof options.inject === 'function'
|
|
156
151
|
? options.inject(cssVariableName, this.id)
|
|
157
|
-
: '
|
|
158
|
-
`import styleInject from '${styleInjectPath}';\n` +
|
|
152
|
+
: `\nimport styleInject from '${styleInjectPath}';\n` +
|
|
159
153
|
`styleInject(${cssVariableName}${Object.keys(options.inject).length > 0 ? `,${JSON.stringify(options.inject)}` : ''});`;
|
|
160
154
|
}
|
|
161
155
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postcss-loader.js","sourceRoot":"","sources":["../../../src/plugins/postcss/postcss-loader.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,cAAc;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,aAAa,MAAM,2BAA2B,CAAC;AACtD,OAAO,aAAa,MAAM,2BAA2B,CAAC;AAEtD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAA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,CAAC,eAAe,CAAC;YAC3F,MAAM;gBACJ,OAAO,eAAe,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK;oBAC3D,kBAAkB,MAAM,KAAK;oBAC7B,yBAAyB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAC3D,CAAC;QAED,IAAI,CAAC,aAAa,IAAI,YAAY,EAAE,CAAC;YACnC,MAAM;gBACJ,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU;oBAClC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC;oBAC1C,CAAC,CAAC,IAAI;wBACJ,4BAA4B,eAAe,MAAM;wBACjD,eAAe,eAAe,GAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAClF,IAAI,CAAC;QACb,CAAC;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,GAAG,EAAE,SAAS;YACd,SAAS;SACV,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["/* eslint-disable */\n// @ts-nocheck\nimport { createRequire } from 'module';\nimport postcss from 'postcss';\nimport { identifier } from 'safe-identifier';\nimport humanlizePath from './utils/humanlize-path.js';\nimport normalizePath from './utils/normalize-path.js';\n\nconst require = createRequire(import.meta.url);\n\nconst styleInjectPath = require.resolve('style-inject/dist/style-inject.es').replace(/[\\\\/]+/g, '/');\n\n/**\n * Escape CSS class name dashes for JavaScript identifiers\n */\nfunction escapeClassNameDashes(string) {\n return string.replace(/-+/g, (match) => {\n return `$${match.replace(/-/g, '_')}$`;\n });\n}\n\nfunction ensureClassName(name) {\n name = escapeClassNameDashes(name);\n return identifier(name, false);\n}\n\nasync function ensurePostCSSOption(option) {\n if (typeof option === 'string') {\n try {\n const resolvedPath = require.resolve(option);\n return await import(resolvedPath);\n } catch {\n return option;\n }\n }\n return option;\n}\n\nfunction isModuleFile(file) {\n return /\\.module\\.[a-z]{2,6}$/.test(file);\n}\n\nexport default {\n name: 'postcss',\n alwaysProcess: true,\n async process({ code, map }) {\n // This is modified to not load postcss config.\n if (this.options.config !== false) {\n throw new Error(\n 'This is a fork of rollup-plugin-postcss that does not support loading postcss config. ' +\n 'Please set `config: false` in the plugin options.',\n );\n }\n\n const { options } = this;\n const plugins = [...(options.postcss.plugins || [])];\n\n const shouldExtract = options.extract;\n const shouldInject = options.inject;\n\n const modulesExported = {};\n const autoModules = options.autoModules !== false && options.onlyModules !== true;\n const isAutoModule = autoModules && isModuleFile(this.id);\n const supportModules = autoModules ? isAutoModule : options.modules;\n\n if (supportModules) {\n const postcssModules = await import('postcss-modules');\n plugins.unshift(\n postcssModules.default({\n // In tests\n // Skip hash in names since css content on windows and linux would differ because of `new line` (\\r?\\n)\n generateScopedName: process.env.ROLLUP_POSTCSS_TEST ? '[name]_[local]' : '[name]_[local]__[hash:base64:5]',\n ...options.modules,\n getJSON(filepath, json, outpath) {\n modulesExported[filepath] = json;\n if (typeof options.modules === 'object' && typeof options.modules.getJSON === 'function') {\n return options.modules.getJSON(filepath, json, outpath);\n }\n },\n }),\n );\n }\n\n // If shouldExtract, minimize is done after all CSS are extracted to a file\n if (!shouldExtract && options.minimize) {\n const cssnano = await import('cssnano');\n plugins.push(cssnano.default(options.minimize));\n }\n\n const postcssOptions = {\n ...this.options.postcss,\n // Allow overriding `to` for some plugins that are relying on this value\n to: options.to || this.id,\n // Followings are never modified by user config config\n from: this.id,\n map: this.sourceMap\n ? shouldExtract\n ? { inline: false, annotation: false }\n : { inline: true, annotation: false }\n : false,\n };\n delete postcssOptions.plugins;\n\n postcssOptions.parser = await ensurePostCSSOption(postcssOptions.parser);\n postcssOptions.syntax = await ensurePostCSSOption(postcssOptions.syntax);\n postcssOptions.stringifier = await ensurePostCSSOption(postcssOptions.stringifier);\n\n if (map && postcssOptions.map) {\n postcssOptions.map.prev = typeof map === 'string' ? JSON.parse(map) : map;\n }\n\n if (plugins.length === 0) {\n // Prevent from postcss warning:\n // You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js\n const noopPlugin = () => ({\n postcssPlugin: 'postcss-noop-plugin',\n Once() {},\n });\n plugins.push(noopPlugin());\n }\n\n const result = await postcss(plugins).process(code, postcssOptions);\n\n for (const message of result.messages) {\n if (message.type === 'dependency') {\n this.dependencies.add(message.file);\n }\n }\n\n for (const warning of result.warnings()) {\n if (!warning.message) {\n warning.message = warning.text;\n }\n this.warn(warning);\n }\n\n const outputMap = result.map && JSON.parse(result.map.toString());\n if (outputMap?.sources) {\n outputMap.sources = outputMap.sources.map((v) => normalizePath(v));\n }\n\n let output = '';\n let extracted;\n\n if (options.namedExports) {\n const json = modulesExported[this.id];\n const getClassName = typeof options.namedExports === 'function' ? options.namedExports : ensureClassName;\n\n for (const name in json) {\n const newName = getClassName(name);\n // Log transformed class names\n // But skip this when namedExports is a function\n // Since a user like you can manually log that if you want\n if (name !== newName && typeof options.namedExports !== 'function') {\n this.warn(`Exported \"${name}\" as \"${newName}\" in ${humanlizePath(this.id)}`);\n }\n\n if (!json[newName]) {\n json[newName] = json[name];\n }\n\n output += `export var ${newName} = ${JSON.stringify(json[name])};\\n`;\n }\n }\n\n const cssVariableName = identifier('css', true);\n\n if (shouldExtract) {\n output += `export default ${JSON.stringify(modulesExported[this.id])};`;\n extracted = {\n id: this.id,\n code: result.css,\n map: outputMap,\n };\n } else {\n const module = supportModules ? JSON.stringify(modulesExported[this.id]) : cssVariableName;\n output +=\n `var ${cssVariableName} = ${JSON.stringify(result.css)};\\n` +\n `export default ${module};\\n` +\n `export var stylesheet=${JSON.stringify(result.css)};`;\n }\n\n if (!shouldExtract && shouldInject) {\n output +=\n typeof options.inject === 'function'\n ? options.inject(cssVariableName, this.id)\n : '\\n' +\n `import styleInject from '${styleInjectPath}';\\n` +\n `styleInject(${cssVariableName}${\n Object.keys(options.inject).length > 0 ? `,${JSON.stringify(options.inject)}` : ''\n });`;\n }\n\n return {\n code: output,\n map: outputMap,\n extracted,\n };\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"postcss-loader.js","sourceRoot":"","sources":["../../../src/plugins/postcss/postcss-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAErG,4BAA4B;AAE5B;;GAEG;AACH,SAAS,qBAAqB,CAAC,GAAW;IACxC,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAClC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,CAAC,IAAY;IACnC,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAChD,OAAO,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,mBAAmB,CAAI,MAAe;IACnD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,MA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AAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC;YACxE,SAAS,GAAG;gBACV,EAAE,EAAE,IAAI,CAAC,EAAE;gBACX,IAAI,EAAE,MAAM,CAAC,GAAG;gBAChB,GAAG,EAAE,SAAS;aACf,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC;YAC3F,MAAM;gBACJ,OAAO,eAAe,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK;oBAC3D,kBAAkB,MAAM,KAAK;oBAC7B,yBAAyB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAC3D,CAAC;QAED,IAAI,CAAC,aAAa,IAAI,YAAY,EAAE,CAAC;YACnC,MAAM;gBACJ,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU;oBAClC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC;oBAC1C,CAAC,CAAC,8BAA8B,eAAe,MAAM;wBACnD,eAAe,eAAe,GAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAClF,IAAI,CAAC;QACb,CAAC;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,GAAG,EAAE,SAAS;YACd,SAAS;SACV,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { createRequire } from 'module';\nimport postcss from 'postcss';\nimport { identifier } from 'safe-identifier';\nimport { normalizePath } from './utils/normalize-path.js';\nimport type { ExtractResult, InternalPostCSSLoaderOptions, Loader } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst styleInjectPath = require.resolve('style-inject/dist/style-inject.es').replace(/[\\\\/]+/g, '/');\n\n// loadConfig helper removed\n\n/**\n * Escape CSS class name dashes for JavaScript identifiers\n */\nfunction escapeClassNameDashes(str: string) {\n return str.replace(/-+/g, (match) => {\n return `$${match.replace(/-/g, '_')}$`;\n });\n}\n\n/**\n * Ensure class name is a valid JavaScript identifier\n */\nfunction ensureClassName(name: string): string {\n const escapedName = escapeClassNameDashes(name);\n return identifier(escapedName, false);\n}\n\n/**\n * Ensure PostCSS option is properly loaded\n */\nasync function ensurePostCSSOption<T>(option: unknown): Promise<T | undefined> {\n if (typeof option === 'string') {\n try {\n const resolvedPath = require.resolve(option);\n return (await import(resolvedPath)) as T;\n } catch {\n return option as T;\n }\n }\n return option as T;\n}\n\nfunction isModuleFile(file: string): boolean {\n return /\\.module\\.[a-z]{2,6}$/.test(file);\n}\n\nexport const postcssLoader: Loader<InternalPostCSSLoaderOptions> = {\n name: 'postcss',\n alwaysProcess: true,\n\n async process({ code, map }) {\n // This is modified to not load postcss config.\n if (this.options.config !== false) {\n throw new Error(\n 'This is a fork of rollup-plugin-postcss that does not support loading postcss config. ' +\n 'Please set `config: false` in the plugin options.',\n );\n }\n\n const { options } = this;\n const plugins = [...(options.postcss.plugins || [])];\n const shouldExtract = options.extract;\n const shouldInject = options.inject;\n\n const modulesExported: Record<string, Record<string, string>> = {};\n const autoModules = options.autoModules !== false && options.onlyModules !== true;\n const isAutoModule = autoModules && isModuleFile(this.id);\n const supportModules = autoModules ? isAutoModule : options.modules;\n\n if (supportModules) {\n plugins.unshift(\n (await import('postcss-modules')).default({\n // In tests\n // Skip hash in names since css content on windows and linux would differ because of `new line` (\\r?\\n)\n // eslint-disable-next-line no-restricted-properties\n generateScopedName: process.env.ROLLUP_POSTCSS_TEST ? '[name]_[local]' : '[name]_[local]__[hash:base64:5]',\n ...options.modules,\n getJSON(filepath, json, outpath) {\n modulesExported[filepath] = json;\n if (typeof options.modules === 'object' && typeof options.modules.getJSON === 'function') {\n return options.modules.getJSON(filepath, json, outpath);\n }\n },\n }),\n );\n }\n\n // If shouldExtract, minimize is done after all CSS are extracted to a file\n if (!shouldExtract && options.minimize) {\n plugins.push((await import('cssnano')).default(options.minimize));\n }\n\n const postcssOptions: postcss.ProcessOptions = {\n // Allow overriding `to` for some plugins that are relying on this value\n to: options.to || this.id,\n from: this.id,\n map: this.sourceMap ? { inline: !shouldExtract, annotation: false } : false,\n parser: await ensurePostCSSOption(options.postcss.parser),\n syntax: await ensurePostCSSOption(options.postcss.syntax),\n stringifier: await ensurePostCSSOption(options.postcss.stringifier),\n // this was spread in before but doesn't appear to exist\n // exec: options.postcss.exec,\n };\n\n if (map && typeof postcssOptions.map === 'object') {\n postcssOptions.map.prev = typeof map === 'string' ? (JSON.parse(map) as object) : map;\n }\n\n if (plugins.length === 0) {\n // Prevent from postcss warning:\n // You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js\n plugins.push({\n postcssPlugin: 'postcss-noop-plugin',\n Once() {},\n });\n }\n\n const result = await postcss(plugins).process(code, postcssOptions);\n\n for (const message of result.messages) {\n if (message.type === 'dependency') {\n this.dependencies.add(message.file as string);\n }\n }\n\n for (const warning of result.warnings()) {\n this.warn({ message: warning.text, ...warning });\n }\n\n const outputMap = result.map && (JSON.parse(result.map.toString()) as ExtractResult['map']);\n if (outputMap && typeof outputMap === 'object' && 'sources' in outputMap) {\n outputMap.sources = outputMap.sources.map((v) => normalizePath(v));\n }\n\n let output = '';\n let extracted: ExtractResult | undefined;\n\n if (options.namedExports) {\n const json = modulesExported[this.id];\n const getClassName = typeof options.namedExports === 'function' ? options.namedExports : ensureClassName;\n\n for (const name in json) {\n const newName = getClassName(name);\n // Log transformed class names\n // But skip this when namedExports is a function\n // Since a user like you can manually log that if you want\n if (name !== newName && typeof options.namedExports !== 'function') {\n // Logging this as an absolute path is better for our use case\n this.warn(`Exported \"${name}\" as \"${newName}\" in ${this.id}`);\n }\n\n if (!json[newName]) {\n json[newName] = json[name];\n }\n\n output += `export var ${newName} = ${JSON.stringify(json[name])};\\n`;\n }\n }\n\n const cssVariableName = identifier('css', true);\n\n if (shouldExtract) {\n output += `export default ${JSON.stringify(modulesExported[this.id])};`;\n extracted = {\n id: this.id,\n code: result.css,\n map: outputMap,\n };\n } else {\n const module = supportModules ? JSON.stringify(modulesExported[this.id]) : cssVariableName;\n output +=\n `var ${cssVariableName} = ${JSON.stringify(result.css)};\\n` +\n `export default ${module};\\n` +\n `export var stylesheet=${JSON.stringify(result.css)};`;\n }\n\n if (!shouldExtract && shouldInject) {\n output +=\n typeof options.inject === 'function'\n ? options.inject(cssVariableName, this.id)\n : `\\nimport styleInject from '${styleInjectPath}';\\n` +\n `styleInject(${cssVariableName}${\n Object.keys(options.inject).length > 0 ? `,${JSON.stringify(options.inject)}` : ''\n });`;\n }\n\n return {\n code: output,\n map: outputMap,\n extracted,\n };\n },\n};\n"]}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}): Promise<unknown>;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
1
|
+
import type { Loader } from './types.js';
|
|
2
|
+
import type * as Sass from 'sass';
|
|
3
|
+
type SassOptions = Sass.LegacyOptions<'async'>;
|
|
4
|
+
export declare const sassLoader: Loader<Partial<SassOptions>>;
|
|
5
|
+
export {};
|
|
9
6
|
//# sourceMappingURL=sass-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sass-loader.d.ts","sourceRoot":"","sources":["../../../src/plugins/postcss/sass-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sass-loader.d.ts","sourceRoot":"","sources":["../../../src/plugins/postcss/sass-loader.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,KAAK,IAAI,MAAM,MAAM,CAAC;AAGlC,KAAK,WAAW,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAoB/C,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAoEnD,CAAC"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
// @ts-nocheck
|
|
3
1
|
import path from 'path';
|
|
4
2
|
import pify from 'pify';
|
|
5
3
|
import resolvePackage from 'resolve';
|
|
@@ -7,7 +5,8 @@ import PQueue from 'p-queue';
|
|
|
7
5
|
import { loadModule } from './utils/load-module.js';
|
|
8
6
|
// This queue makes sure node-sass leaves one thread available for executing fs tasks
|
|
9
7
|
// See: https://github.com/sass/node-sass/issues/857
|
|
10
|
-
|
|
8
|
+
// eslint-disable-next-line no-restricted-properties
|
|
9
|
+
const threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4);
|
|
11
10
|
const workQueue = new PQueue({ concurrency: threadPoolSize - 1 });
|
|
12
11
|
const moduleRe = /^~([a-z\d]|@).+/i;
|
|
13
12
|
const getUrlOfPartial = (url) => {
|
|
@@ -17,59 +16,59 @@ const getUrlOfPartial = (url) => {
|
|
|
17
16
|
const resolvePromise = pify(resolvePackage);
|
|
18
17
|
// List of supported SASS modules in the order of preference
|
|
19
18
|
const sassModuleIds = ['sass', 'node-sass'];
|
|
20
|
-
|
|
21
|
-
export default {
|
|
19
|
+
export const sassLoader = {
|
|
22
20
|
name: 'sass',
|
|
23
21
|
test: /\.(sass|scss)$/,
|
|
24
22
|
process({ code }) {
|
|
25
23
|
return new Promise((resolve, reject) => {
|
|
26
24
|
(async () => {
|
|
27
|
-
const sassModule = await loadSassOrThrow();
|
|
25
|
+
const sassModule = await loadSassOrThrow(this.resolveCwd);
|
|
28
26
|
// accessing sassModule.default logs an error in latest versions
|
|
29
|
-
const sass =
|
|
27
|
+
const sass = 'render' in sassModule ? sassModule : sassModule.default;
|
|
28
|
+
// promisified type isn't being inferred properly
|
|
29
|
+
// eslint-disable-next-line etc/no-deprecated
|
|
30
30
|
const render = pify(sass.render.bind(sass));
|
|
31
31
|
const data = this.options.data || '';
|
|
32
|
-
workQueue.add(() =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
await workQueue.add(async () => {
|
|
33
|
+
const result = await render({
|
|
34
|
+
...this.options,
|
|
35
|
+
file: this.id,
|
|
36
|
+
data: data + code,
|
|
37
|
+
indentedSyntax: /\.sass$/.test(this.id),
|
|
38
|
+
sourceMap: this.sourceMap,
|
|
39
|
+
importer: [
|
|
40
|
+
((url, importer, done) => {
|
|
41
|
+
/** Return the original file and pass responsibility back to other custom importers */
|
|
42
|
+
const next = () => done({ file: url });
|
|
43
|
+
if (!moduleRe.test(url))
|
|
44
|
+
return next();
|
|
45
|
+
const moduleUrl = url.slice(1);
|
|
46
|
+
const partialUrl = getUrlOfPartial(moduleUrl);
|
|
47
|
+
const options = {
|
|
48
|
+
basedir: path.dirname(importer),
|
|
49
|
+
extensions: ['.scss', '.sass', '.css'],
|
|
50
|
+
};
|
|
51
|
+
const finishImport = (id) => {
|
|
52
|
+
done({
|
|
53
|
+
// Do not add `.css` extension in order to inline the file
|
|
54
|
+
file: id.replace(/\.css$/, ''),
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
// Give precedence to importing a partial
|
|
58
|
+
resolvePromise(partialUrl, options)
|
|
59
|
+
.then(finishImport)
|
|
60
|
+
.catch((error) => {
|
|
61
|
+
const { code: errCode } = error;
|
|
62
|
+
if (errCode === 'MODULE_NOT_FOUND' || errCode === 'ENOENT') {
|
|
63
|
+
resolvePromise(moduleUrl, options).then(finishImport).catch(next);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
next();
|
|
67
|
+
}
|
|
52
68
|
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
done({ file: url });
|
|
57
|
-
};
|
|
58
|
-
// Give precedence to importing a partial
|
|
59
|
-
resolvePromise(partialUrl, options)
|
|
60
|
-
.then(finishImport)
|
|
61
|
-
.catch((error) => {
|
|
62
|
-
if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ENOENT') {
|
|
63
|
-
resolvePromise(moduleUrl, options).then(finishImport).catch(next);
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
next();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
].concat(this.options.importer || []),
|
|
71
|
-
})
|
|
72
|
-
.then((result) => {
|
|
69
|
+
}),
|
|
70
|
+
].concat(this.options.importer || []),
|
|
71
|
+
});
|
|
73
72
|
for (const file of result.stats.includedFiles) {
|
|
74
73
|
this.dependencies.add(file);
|
|
75
74
|
}
|
|
@@ -77,16 +76,15 @@ export default {
|
|
|
77
76
|
code: result.css.toString(),
|
|
78
77
|
map: result.map && result.map.toString(),
|
|
79
78
|
});
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
})();
|
|
79
|
+
});
|
|
80
|
+
})().catch(reject);
|
|
83
81
|
});
|
|
84
82
|
},
|
|
85
83
|
};
|
|
86
|
-
async function loadSassOrThrow() {
|
|
84
|
+
async function loadSassOrThrow(cwd) {
|
|
87
85
|
// Loading one of the supported modules
|
|
88
86
|
for (const moduleId of sassModuleIds) {
|
|
89
|
-
const module = await loadModule(moduleId);
|
|
87
|
+
const module = await loadModule({ moduleId, cwd });
|
|
90
88
|
if (module) {
|
|
91
89
|
return module;
|
|
92
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sass-loader.js","sourceRoot":"","sources":["../../../src/plugins/postcss/sass-loader.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"sass-loader.js","sourceRoot":"","sources":["../../../src/plugins/postcss/sass-loader.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,cAAc,MAAM,SAAS,CAAC;AACrC,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAOpD,qFAAqF;AACrF,oDAAoD;AACpD,oDAAoD;AACpD,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,CAAC,CAAC;AACnE,MAAM,SAAS,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,cAAc,GAAG,CAAC,EAAE,CAAC,CAAC;AAElE,MAAM,QAAQ,GAAG,kBAAkB,CAAC;AAEpC,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,EAAE;IACtC,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,GAAG,SAAS,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;AAE5C,4DAA4D;AAC5D,MAAM,aAAa,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;AAE5C,MAAM,CAAC,MAAM,UAAU,GAAiC;IACtD,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,gBAAgB;IACtB,OAAO,CAAC,EAAE,IAAI,EAAE;QACd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,CAAC,KAAK,IAAI,EAAE;gBACV,MAAM,UAAU,G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,CAAC;CACF,CAAC;AAEF,KAAK,UAAU,eAAe,CAAC,GAAW;IACxC,uCAAuC;IACvC,KAAK,MAAM,QAAQ,IAAI,aAAa,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,UAAU,CAAc,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;QAChE,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,+CAA+C;IAC/C,MAAM,IAAI,KAAK,CACb,sDAAsD,aAAa;SAChE,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,QAAQ,GAAG,CAAC;SAClC,IAAI,CAAC,IAAI,CAAC,iCAAiC,CAC/C,CAAC;AACJ,CAAC","sourcesContent":["import path from 'path';\nimport pify from 'pify';\nimport resolvePackage from 'resolve';\nimport PQueue from 'p-queue';\nimport { loadModule } from './utils/load-module.js';\nimport type { Loader } from './types.js';\nimport type * as Sass from 'sass';\n\n// eslint-disable-next-line etc/no-deprecated\ntype SassOptions = Sass.LegacyOptions<'async'>;\n\n// This queue makes sure node-sass leaves one thread available for executing fs tasks\n// See: https://github.com/sass/node-sass/issues/857\n// eslint-disable-next-line no-restricted-properties\nconst threadPoolSize = Number(process.env.UV_THREADPOOL_SIZE || 4);\nconst workQueue = new PQueue({ concurrency: threadPoolSize - 1 });\n\nconst moduleRe = /^~([a-z\\d]|@).+/i;\n\nconst getUrlOfPartial = (url: string) => {\n const parsedUrl = path.parse(url);\n return `${parsedUrl.dir}${path.sep}_${parsedUrl.base}`;\n};\n\nconst resolvePromise = pify(resolvePackage);\n\n// List of supported SASS modules in the order of preference\nconst sassModuleIds = ['sass', 'node-sass'];\n\nexport const sassLoader: Loader<Partial<SassOptions>> = {\n name: 'sass',\n test: /\\.(sass|scss)$/,\n process({ code }) {\n return new Promise((resolve, reject) => {\n (async () => {\n const sassModule = await loadSassOrThrow(this.resolveCwd);\n // accessing sassModule.default logs an error in latest versions\n const sass = 'render' in sassModule ? sassModule : sassModule.default;\n // promisified type isn't being inferred properly\n // eslint-disable-next-line etc/no-deprecated\n const render = pify(sass.render.bind(sass)) as (options: SassOptions) => Promise<Sass.LegacyResult>;\n const data = this.options.data || '';\n\n await workQueue.add(async () => {\n const result = await render({\n ...this.options,\n file: this.id,\n data: data + code,\n indentedSyntax: /\\.sass$/.test(this.id),\n sourceMap: this.sourceMap,\n importer: [\n ((url, importer, done) => {\n /** Return the original file and pass responsibility back to other custom importers */\n const next = () => done({ file: url });\n\n if (!moduleRe.test(url)) return next();\n\n const moduleUrl = url.slice(1);\n const partialUrl = getUrlOfPartial(moduleUrl);\n\n const options: resolvePackage.AsyncOpts = {\n basedir: path.dirname(importer),\n extensions: ['.scss', '.sass', '.css'],\n };\n const finishImport = (id: string) => {\n done({\n // Do not add `.css` extension in order to inline the file\n file: id.replace(/\\.css$/, ''),\n });\n };\n\n // Give precedence to importing a partial\n resolvePromise(partialUrl, options)\n .then(finishImport)\n .catch((error) => {\n const { code: errCode } = error as { code?: string };\n if (errCode === 'MODULE_NOT_FOUND' || errCode === 'ENOENT') {\n resolvePromise(moduleUrl, options).then(finishImport).catch(next);\n } else {\n next();\n }\n });\n }) satisfies Sass.LegacyAsyncImporter, // eslint-disable-line etc/no-deprecated\n ].concat(this.options.importer || []),\n });\n for (const file of result.stats.includedFiles) {\n this.dependencies.add(file);\n }\n\n resolve({\n code: result.css.toString(),\n map: result.map && result.map.toString(),\n });\n });\n })().catch(reject);\n });\n },\n};\n\nasync function loadSassOrThrow(cwd: string) {\n // Loading one of the supported modules\n for (const moduleId of sassModuleIds) {\n const module = await loadModule<typeof Sass>({ moduleId, cwd });\n if (module) {\n return module;\n }\n }\n\n // Throwing exception if module can't be loaded\n throw new Error(\n `You need to install one of the following packages: ${sassModuleIds\n .map((moduleId) => `\"${moduleId}\"`)\n .join(', ')} in order to process SASS files`,\n );\n}\n"]}
|