@modern-js/module-tools 2.35.0 → 2.36.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/compiled/postcss-nesting/index.js +2 -2
- package/compiled/postcss-nesting/package.json +1 -1
- package/dist/build.js +43 -16
- package/dist/builder/build.d.ts +1 -10
- package/dist/builder/build.js +96 -208
- package/dist/builder/clear.d.ts +1 -4
- package/dist/builder/clear.js +32 -28
- package/dist/builder/copy.js +79 -64
- package/dist/builder/dts/index.js +27 -19
- package/dist/builder/dts/rollup.d.ts +6 -14
- package/dist/builder/dts/rollup.js +60 -37
- package/dist/builder/dts/tsc.d.ts +3 -2
- package/dist/builder/dts/tsc.js +50 -37
- package/dist/builder/esbuild/adapter.d.ts +3 -0
- package/dist/builder/esbuild/adapter.js +275 -0
- package/dist/builder/esbuild/hook.d.ts +4 -0
- package/dist/builder/esbuild/hook.js +103 -0
- package/dist/builder/esbuild/index.d.ts +35 -0
- package/dist/builder/esbuild/index.js +268 -0
- package/dist/builder/esbuild/resolve.d.ts +17 -0
- package/dist/builder/esbuild/resolve.js +125 -0
- package/dist/builder/esbuild/sourcemap.d.ts +16 -0
- package/dist/builder/esbuild/sourcemap.js +86 -0
- package/dist/builder/esbuild/transform.d.ts +7 -0
- package/dist/builder/esbuild/transform.js +45 -0
- package/dist/builder/esbuild/watch.d.ts +2 -0
- package/dist/builder/esbuild/watch.js +115 -0
- package/dist/builder/esbuild/write-file.d.ts +2 -0
- package/dist/builder/esbuild/write-file.js +89 -0
- package/dist/builder/feature/asset.d.ts +19 -0
- package/dist/builder/feature/asset.js +149 -0
- package/dist/builder/feature/format-cjs.d.ts +5 -0
- package/dist/builder/feature/format-cjs.js +53 -0
- package/dist/builder/feature/index.d.ts +2 -0
- package/dist/builder/feature/index.js +74 -0
- package/dist/builder/feature/json.d.ts +5 -0
- package/dist/builder/feature/json.js +47 -0
- package/dist/builder/feature/redirect.d.ts +5 -0
- package/dist/builder/feature/redirect.js +217 -0
- package/dist/builder/feature/style/index.d.ts +5 -0
- package/dist/builder/feature/style/index.js +94 -0
- package/dist/builder/feature/style/lessAliasPlugin.d.ts +12 -0
- package/dist/builder/feature/style/lessAliasPlugin.js +70 -0
- package/dist/builder/feature/style/lessRender.d.ts +2 -0
- package/dist/builder/feature/style/lessRender.js +64 -0
- package/dist/builder/feature/style/postcssTransformer.d.ts +6 -0
- package/dist/builder/feature/style/postcssTransformer.js +95 -0
- package/dist/builder/feature/style/postcssUrlPlugin.d.ts +6 -0
- package/dist/builder/feature/style/postcssUrlPlugin.js +58 -0
- package/dist/builder/feature/style/sassRender.d.ts +2 -0
- package/dist/builder/feature/style/sassRender.js +85 -0
- package/dist/builder/feature/style/transformStyle.d.ts +13 -0
- package/dist/builder/feature/style/transformStyle.js +101 -0
- package/dist/builder/feature/style/utils.d.ts +18 -0
- package/dist/builder/feature/style/utils.js +124 -0
- package/dist/builder/feature/swc.d.ts +9 -0
- package/dist/builder/feature/swc.js +170 -0
- package/dist/builder/feature/terser.d.ts +5 -0
- package/dist/builder/feature/terser.js +83 -0
- package/dist/builder/index.d.ts +1 -0
- package/dist/builder/index.js +59 -28
- package/dist/builder/platform.js +38 -23
- package/dist/cli.js +58 -29
- package/dist/command.js +62 -38
- package/dist/config/defineConfig.js +25 -17
- package/dist/config/legacySchema.js +35 -32
- package/dist/config/merge.d.ts +1 -0
- package/dist/config/merge.js +69 -36
- package/dist/config/normalize.d.ts +1 -0
- package/dist/config/normalize.js +63 -46
- package/dist/config/schema.d.ts +48 -0
- package/dist/config/schema.js +53 -34
- package/dist/config/transformLegacyConfig.js +67 -61
- package/dist/config/valid.d.ts +2 -2
- package/dist/config/valid.js +44 -21
- package/dist/constants/build.d.ts +5 -1
- package/dist/constants/build.js +88 -46
- package/dist/constants/color.js +27 -20
- package/dist/constants/dts.js +27 -20
- package/dist/constants/file.d.ts +2 -2
- package/dist/constants/file.js +48 -25
- package/dist/constants/legacy-preset.js +45 -32
- package/dist/constants/loader.d.ts +2 -0
- package/dist/constants/loader.js +53 -0
- package/dist/constants/log.d.ts +0 -8
- package/dist/constants/log.js +27 -41
- package/dist/constants/preset.js +55 -62
- package/dist/debug.d.ts +4 -0
- package/dist/debug.js +37 -0
- package/dist/dev.js +42 -25
- package/dist/error.js +49 -42
- package/dist/hooks/build.d.ts +1 -2
- package/dist/hooks/build.js +36 -28
- package/dist/hooks/dev.js +32 -17
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +31 -16
- package/dist/hooks/misc.d.ts +5 -2
- package/dist/hooks/misc.js +31 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +39 -32
- package/dist/locale/en.js +32 -17
- package/dist/locale/index.d.ts +2 -1
- package/dist/locale/index.js +31 -24
- package/dist/locale/zh.js +32 -17
- package/dist/plugins.js +28 -13
- package/dist/types/color.js +15 -5
- package/dist/types/command.d.ts +3 -3
- package/dist/types/command.js +15 -5
- package/dist/types/config/copy.js +15 -5
- package/dist/types/config/dev.js +15 -5
- package/dist/types/config/index.d.ts +87 -52
- package/dist/types/config/index.js +24 -6
- package/dist/types/config/style.d.ts +58 -6
- package/dist/types/config/style.js +15 -5
- package/dist/types/context.js +15 -5
- package/dist/types/dts.d.ts +14 -3
- package/dist/types/dts.js +15 -5
- package/dist/types/esbuild.d.ts +107 -0
- package/dist/types/esbuild.js +32 -0
- package/dist/types/hooks.js +15 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +32 -11
- package/dist/types/legacyConfig/index.js +15 -5
- package/dist/types/legacyConfig/output.d.ts +4 -4
- package/dist/types/legacyConfig/output.js +15 -5
- package/dist/types/legacyConfig/source.js +15 -5
- package/dist/types/legacyConfig/tools.js +15 -5
- package/dist/utils/assert.d.ts +5 -0
- package/dist/utils/assert.js +50 -0
- package/dist/utils/builder.d.ts +10 -14
- package/dist/utils/builder.js +59 -59
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +25 -17
- package/dist/utils/dts.d.ts +26 -9
- package/dist/utils/dts.js +100 -66
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +31 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +42 -0
- package/dist/utils/input.js +47 -24
- package/dist/utils/log.d.ts +1 -2
- package/dist/utils/log.js +36 -20
- package/dist/utils/map.d.ts +13 -0
- package/dist/utils/map.js +58 -0
- package/dist/utils/onExit.js +35 -11
- package/dist/utils/print.d.ts +2 -2
- package/dist/utils/print.js +52 -49
- package/dist/utils/style.d.ts +5 -23
- package/dist/utils/style.js +63 -43
- package/dist/utils/tspath.js +114 -0
- package/package.json +64 -50
- package/vitest.config.ts +20 -0
- package/dist/build.js.map +0 -1
- package/dist/builder/build.js.map +0 -1
- package/dist/builder/clear.js.map +0 -1
- package/dist/builder/copy.js.map +0 -1
- package/dist/builder/dts/index.js.map +0 -1
- package/dist/builder/dts/rollup.js.map +0 -1
- package/dist/builder/dts/tsc.js.map +0 -1
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/platform.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/command.js.map +0 -1
- package/dist/config/defineConfig.js.map +0 -1
- package/dist/config/legacySchema.js.map +0 -1
- package/dist/config/merge.js.map +0 -1
- package/dist/config/normalize.js.map +0 -1
- package/dist/config/schema.js.map +0 -1
- package/dist/config/transformLegacyConfig.js.map +0 -1
- package/dist/config/valid.js.map +0 -1
- package/dist/constants/build.js.map +0 -1
- package/dist/constants/color.js.map +0 -1
- package/dist/constants/dts.js.map +0 -1
- package/dist/constants/file.js.map +0 -1
- package/dist/constants/legacy-preset.js.map +0 -1
- package/dist/constants/log.js.map +0 -1
- package/dist/constants/preset.js.map +0 -1
- package/dist/dev.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/hooks/build.js.map +0 -1
- package/dist/hooks/dev.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/misc.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locale/en.js.map +0 -1
- package/dist/locale/index.js.map +0 -1
- package/dist/locale/zh.js.map +0 -1
- package/dist/plugins.js.map +0 -1
- package/dist/types/color.js.map +0 -1
- package/dist/types/command.js.map +0 -1
- package/dist/types/config/copy.js.map +0 -1
- package/dist/types/config/dev.js.map +0 -1
- package/dist/types/config/index.js.map +0 -1
- package/dist/types/config/style.js.map +0 -1
- package/dist/types/context.js.map +0 -1
- package/dist/types/dts.js.map +0 -1
- package/dist/types/hooks.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/legacyConfig/index.js.map +0 -1
- package/dist/types/legacyConfig/output.js.map +0 -1
- package/dist/types/legacyConfig/source.js.map +0 -1
- package/dist/types/legacyConfig/tools.js.map +0 -1
- package/dist/types/utils.d.ts +0 -5
- package/dist/types/utils.js +0 -4
- package/dist/utils/builder.js.map +0 -1
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/context.d.ts +0 -7
- package/dist/utils/context.js +0 -23
- package/dist/utils/context.js.map +0 -1
- package/dist/utils/dts.js.map +0 -1
- package/dist/utils/input.js.map +0 -1
- package/dist/utils/language.d.ts +0 -1
- package/dist/utils/language.js +0 -22
- package/dist/utils/language.js.map +0 -1
- package/dist/utils/libuild-plugin.d.ts +0 -3
- package/dist/utils/libuild-plugin.js +0 -31
- package/dist/utils/libuild-plugin.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/onExit.js.map +0 -1
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +0 -19
- package/dist/utils/path.js.map +0 -1
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/style.js.map +0 -1
- package/dist/utils/tspathsTransform.js +0 -91
- package/dist/utils/tspathsTransform.js.map +0 -1
- /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var postcssTransformer_exports = {};
|
|
30
|
+
__export(postcssTransformer_exports, {
|
|
31
|
+
isCssModule: () => isCssModule,
|
|
32
|
+
postcssTransformer: () => postcssTransformer
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(postcssTransformer_exports);
|
|
35
|
+
var import_postcss = __toESM(require("postcss"));
|
|
36
|
+
var import_utils = require("../../../utils");
|
|
37
|
+
var import_postcssUrlPlugin = require("./postcssUrlPlugin");
|
|
38
|
+
const cssLangs = `\\.(css|less|sass|scss)($|\\?)`;
|
|
39
|
+
const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
|
|
40
|
+
const isCssModule = (filePath, autoModules) => {
|
|
41
|
+
return typeof autoModules === "boolean" ? autoModules && cssModuleRE.test(filePath) : autoModules.test(filePath);
|
|
42
|
+
};
|
|
43
|
+
const postcssTransformer = async (css, entryPath, compilation) => {
|
|
44
|
+
const postcssConfig = compilation.config.style.postcss;
|
|
45
|
+
const { plugins = [], processOptions = {} } = postcssConfig;
|
|
46
|
+
const { modules: modulesOption = {}, autoModules = true } = compilation.config.style;
|
|
47
|
+
const { getJSON: userGetJSON } = modulesOption;
|
|
48
|
+
let modules = {};
|
|
49
|
+
const finalPlugins = [
|
|
50
|
+
(0, import_postcssUrlPlugin.postcssUrlPlugin)({
|
|
51
|
+
entryPath,
|
|
52
|
+
compilation
|
|
53
|
+
}),
|
|
54
|
+
...plugins
|
|
55
|
+
];
|
|
56
|
+
if (isCssModule(entryPath, autoModules)) {
|
|
57
|
+
finalPlugins.push((await Promise.resolve().then(() => __toESM(require("postcss-modules")))).default({
|
|
58
|
+
generateScopedName(name, filename, _css) {
|
|
59
|
+
const hash = (0, import_utils.getHash)(filename, "utf-8").substring(0, 5);
|
|
60
|
+
return `${name}_${hash}`;
|
|
61
|
+
},
|
|
62
|
+
async resolve(id) {
|
|
63
|
+
return id;
|
|
64
|
+
},
|
|
65
|
+
...modulesOption,
|
|
66
|
+
getJSON(cssFileName, _modules, outputFileName) {
|
|
67
|
+
if (userGetJSON) {
|
|
68
|
+
userGetJSON(cssFileName, _modules, outputFileName);
|
|
69
|
+
}
|
|
70
|
+
modules = _modules;
|
|
71
|
+
}
|
|
72
|
+
}));
|
|
73
|
+
}
|
|
74
|
+
let loader = "css";
|
|
75
|
+
let { css: code } = await (0, import_postcss.default)(finalPlugins).process(css, {
|
|
76
|
+
from: entryPath,
|
|
77
|
+
...processOptions
|
|
78
|
+
});
|
|
79
|
+
if (Object.values(modules).length) {
|
|
80
|
+
const normalizedPath = (0, import_utils.normalizeSlashes)(entryPath);
|
|
81
|
+
const key = (0, import_utils.getHash)(code, "utf-8").slice(0, 5);
|
|
82
|
+
compilation.virtualModule.set(key, code);
|
|
83
|
+
code = `import "${normalizedPath}?css_virtual&hash=${key}";export default ${JSON.stringify(modules)}`;
|
|
84
|
+
loader = "js";
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
code,
|
|
88
|
+
loader
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
isCssModule,
|
|
94
|
+
postcssTransformer
|
|
95
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var postcssUrlPlugin_exports = {};
|
|
20
|
+
__export(postcssUrlPlugin_exports, {
|
|
21
|
+
postcssUrlPlugin: () => postcssUrlPlugin
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(postcssUrlPlugin_exports);
|
|
24
|
+
var import_path = require("path");
|
|
25
|
+
var import_asset = require("../asset");
|
|
26
|
+
var import_utils = require("./utils");
|
|
27
|
+
const Processed = Symbol("processed");
|
|
28
|
+
const HTTP_PATTERNS = /^(https?:)?\/\//;
|
|
29
|
+
const DATAURL_PATTERNS = /^data:/;
|
|
30
|
+
const HASH_PATTERNS = /#[^#]+$/;
|
|
31
|
+
const postcssUrlPlugin = (options) => {
|
|
32
|
+
return {
|
|
33
|
+
postcssPlugin: "postcss-url",
|
|
34
|
+
async Declaration(decl) {
|
|
35
|
+
const isProcessed = decl[Processed];
|
|
36
|
+
decl.value = await (0, import_utils.rewriteCssUrls)(decl.value, false, async (URL) => {
|
|
37
|
+
if (URL && !HTTP_PATTERNS.test(URL) && !HASH_PATTERNS.test(URL) && !DATAURL_PATTERNS.test(URL) && !isProcessed) {
|
|
38
|
+
let filePath = URL;
|
|
39
|
+
const { outDir, sourceDir, buildType } = options.compilation.config;
|
|
40
|
+
const { css_resolve } = options.compilation;
|
|
41
|
+
filePath = css_resolve(URL, (0, import_path.dirname)(options.entryPath));
|
|
42
|
+
const rebaseFrom = buildType === "bundle" ? outDir : (0, import_path.join)(outDir, (0, import_path.relative)(sourceDir, (0, import_path.dirname)(options.entryPath)));
|
|
43
|
+
const { contents: fileUrl } = await import_asset.getAssetContents.apply(options.compilation, [
|
|
44
|
+
filePath,
|
|
45
|
+
rebaseFrom
|
|
46
|
+
]);
|
|
47
|
+
decl[Processed] = true;
|
|
48
|
+
return fileUrl.toString();
|
|
49
|
+
}
|
|
50
|
+
return URL;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
postcssUrlPlugin
|
|
58
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var sassRender_exports = {};
|
|
30
|
+
__export(sassRender_exports, {
|
|
31
|
+
sassRender: () => sassRender
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(sassRender_exports);
|
|
34
|
+
var import_fs = require("fs");
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("./utils");
|
|
37
|
+
const sassRender = async function(content, _, stdinDir, options, resolvePathMap, implementation) {
|
|
38
|
+
const sass = await (0, import_utils.loadProcessor)("sass", this.context.root, implementation);
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
sass.render({
|
|
41
|
+
data: content,
|
|
42
|
+
importer: [
|
|
43
|
+
(url, dir, done) => {
|
|
44
|
+
if (url.startsWith("data:")) {
|
|
45
|
+
done({
|
|
46
|
+
contents: url
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
let filePath = null;
|
|
50
|
+
const baseUrl = import_path.default.basename(url);
|
|
51
|
+
const dirUrl = import_path.default.dirname(url);
|
|
52
|
+
const removeUnderScoreBaseUrl = baseUrl.replace(/^_/, "");
|
|
53
|
+
const prependUnderScoreBaseUrl = `_${removeUnderScoreBaseUrl}`;
|
|
54
|
+
try {
|
|
55
|
+
const id = import_path.default.join(dirUrl, prependUnderScoreBaseUrl);
|
|
56
|
+
filePath = this.css_resolve(id, dir === "stdin" ? stdinDir : resolvePathMap.get(dir));
|
|
57
|
+
} catch (err) {
|
|
58
|
+
const id = import_path.default.join(dirUrl, removeUnderScoreBaseUrl);
|
|
59
|
+
filePath = this.css_resolve(id, dir === "stdin" ? stdinDir : resolvePathMap.get(dir));
|
|
60
|
+
}
|
|
61
|
+
resolvePathMap.set(url, import_path.default.dirname(filePath));
|
|
62
|
+
if (url.startsWith("./")) {
|
|
63
|
+
resolvePathMap.set(url.replace(/^\.\//, ""), import_path.default.dirname(filePath));
|
|
64
|
+
}
|
|
65
|
+
(0, import_utils.rebaseUrls)(filePath, stdinDir, this.css_resolve).then((value) => {
|
|
66
|
+
done({
|
|
67
|
+
contents: value.contents || (0, import_fs.readFileSync)(value.file, "utf-8")
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
...options
|
|
73
|
+
}, (err, res) => {
|
|
74
|
+
if (err) {
|
|
75
|
+
reject(err);
|
|
76
|
+
} else {
|
|
77
|
+
resolve(res);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
sassRender
|
|
85
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PartialMessage } from 'esbuild';
|
|
3
|
+
import { ICompiler, Source } from '../../../types';
|
|
4
|
+
export type PreprocessRender = (content: string, stdinPath: string, stdinDir: string, preprocessOptions: any, resolvePathMap: Map<string, string>, implementation?: object | string) => Promise<{
|
|
5
|
+
css: Buffer | string;
|
|
6
|
+
errors?: PartialMessage[];
|
|
7
|
+
warnings?: PartialMessage[];
|
|
8
|
+
map?: Buffer | string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function transformStyle(this: ICompiler, source: Source): Promise<{
|
|
11
|
+
code: string;
|
|
12
|
+
loader: "js" | "css";
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var transformStyle_exports = {};
|
|
30
|
+
__export(transformStyle_exports, {
|
|
31
|
+
transformStyle: () => transformStyle
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(transformStyle_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_postcssTransformer = require("./postcssTransformer");
|
|
36
|
+
var import_lessRender = require("./lessRender");
|
|
37
|
+
var import_sassRender = require("./sassRender");
|
|
38
|
+
const cssLangs = `\\.(css|less|sass|scss)($|\\?)`;
|
|
39
|
+
const cssLangRE = new RegExp(cssLangs);
|
|
40
|
+
const cssRender = async function(content) {
|
|
41
|
+
return {
|
|
42
|
+
css: content
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const renderMap = {
|
|
46
|
+
less: import_lessRender.lessRender,
|
|
47
|
+
sass: import_sassRender.sassRender,
|
|
48
|
+
scss: import_sassRender.sassRender,
|
|
49
|
+
css: cssRender
|
|
50
|
+
};
|
|
51
|
+
async function transformStyle(source) {
|
|
52
|
+
var _source_path_match;
|
|
53
|
+
const lang = (_source_path_match = source.path.match(cssLangRE)) === null || _source_path_match === void 0 ? void 0 : _source_path_match[1];
|
|
54
|
+
if (!lang) {
|
|
55
|
+
throw new Error(`UNSUPPORTED_CSS_LANG: not supported css lang${lang}`);
|
|
56
|
+
}
|
|
57
|
+
const { less, sass } = this.config.style;
|
|
58
|
+
let options;
|
|
59
|
+
let additionalData;
|
|
60
|
+
let implementation;
|
|
61
|
+
if (lang === "less") {
|
|
62
|
+
options = less === null || less === void 0 ? void 0 : less.lessOptions;
|
|
63
|
+
additionalData = less === null || less === void 0 ? void 0 : less.additionalData;
|
|
64
|
+
implementation = less === null || less === void 0 ? void 0 : less.implementation;
|
|
65
|
+
}
|
|
66
|
+
if (lang === "scss" || lang === "sass") {
|
|
67
|
+
options = sass === null || sass === void 0 ? void 0 : sass.sassOptions;
|
|
68
|
+
additionalData = sass === null || sass === void 0 ? void 0 : sass.additionalData;
|
|
69
|
+
implementation = sass === null || sass === void 0 ? void 0 : sass.implementation;
|
|
70
|
+
}
|
|
71
|
+
const preprocessRender = renderMap[lang];
|
|
72
|
+
const stdinDir = import_path.default.dirname(source.path);
|
|
73
|
+
const resolvePathMap = /* @__PURE__ */ new Map();
|
|
74
|
+
let content = "";
|
|
75
|
+
if (typeof additionalData === "string") {
|
|
76
|
+
content = `${additionalData}
|
|
77
|
+
`;
|
|
78
|
+
} else if (typeof additionalData === "function") {
|
|
79
|
+
content = `${additionalData(source.path)}
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
content += source.code;
|
|
83
|
+
const renderResult = await preprocessRender.apply(this, [
|
|
84
|
+
content,
|
|
85
|
+
source.path,
|
|
86
|
+
stdinDir,
|
|
87
|
+
options,
|
|
88
|
+
resolvePathMap,
|
|
89
|
+
implementation
|
|
90
|
+
]);
|
|
91
|
+
const css = renderResult.css.toString();
|
|
92
|
+
const { code, loader } = await (0, import_postcssTransformer.postcssTransformer)(css !== null && css !== void 0 ? css : "", source.path, this);
|
|
93
|
+
return {
|
|
94
|
+
code,
|
|
95
|
+
loader
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
transformStyle
|
|
101
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* make sure load processor in user project root other than root
|
|
3
|
+
* @param lang
|
|
4
|
+
* @param root
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadProcessor(lang: string, root: string, implementation?: object | string): any;
|
|
8
|
+
type CssUrlReplacer = (url: string, importer?: string) => string | Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* relative url() inside \@imported sass and less files must be rebased to use
|
|
11
|
+
* root file as base.
|
|
12
|
+
*/
|
|
13
|
+
export declare function rebaseUrls(filepath: string, rootDir: string, resolver: (id: string, dir: string) => string): Promise<{
|
|
14
|
+
file: string;
|
|
15
|
+
contents?: string;
|
|
16
|
+
}>;
|
|
17
|
+
export declare function rewriteCssUrls(css: string, type: false | string, replacer: CssUrlReplacer): Promise<string>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var utils_exports = {};
|
|
30
|
+
__export(utils_exports, {
|
|
31
|
+
loadProcessor: () => loadProcessor,
|
|
32
|
+
rebaseUrls: () => rebaseUrls,
|
|
33
|
+
rewriteCssUrls: () => rewriteCssUrls
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(utils_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_path = __toESM(require("path"));
|
|
38
|
+
var import_utils = require("../../../utils");
|
|
39
|
+
const cache = {};
|
|
40
|
+
function loadProcessor(lang, root, implementation) {
|
|
41
|
+
if (cache[lang]) {
|
|
42
|
+
return cache[lang];
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
if (typeof implementation === "string") {
|
|
46
|
+
return cache[lang] = require(implementation);
|
|
47
|
+
}
|
|
48
|
+
if (typeof implementation === "object") {
|
|
49
|
+
return cache[lang] = implementation;
|
|
50
|
+
}
|
|
51
|
+
const loadPath = require.resolve(lang, {
|
|
52
|
+
paths: [
|
|
53
|
+
root
|
|
54
|
+
]
|
|
55
|
+
});
|
|
56
|
+
return cache[lang] = require(loadPath);
|
|
57
|
+
} catch (err) {
|
|
58
|
+
throw new Error(`${lang} require failed, please install it or use implemention`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const dataUrlRE = /^\s*data:/i;
|
|
62
|
+
const cssUrlRE = RegExp(`(?<=^|[^\\w\\-\\u0080-\\uffff])url\\(\\s*('[^']+'|"[^"]+"|[^'")]+)\\s*\\)`);
|
|
63
|
+
const externalRE = /^(https?:)?\/\//;
|
|
64
|
+
const isDataUrl = (url) => dataUrlRE.test(url);
|
|
65
|
+
const isExternalUrl = (url) => externalRE.test(url);
|
|
66
|
+
async function rebaseUrls(filepath, rootDir, resolver) {
|
|
67
|
+
const file = import_path.default.resolve(filepath);
|
|
68
|
+
const fileDir = import_path.default.dirname(file);
|
|
69
|
+
if (fileDir === rootDir) {
|
|
70
|
+
return {
|
|
71
|
+
file
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const content = import_fs.default.readFileSync(file, "utf-8");
|
|
75
|
+
if (!cssUrlRE.test(content)) {
|
|
76
|
+
return {
|
|
77
|
+
file
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const rebased = await rewriteCssUrls(content, import_path.default.extname(file).slice(1), (url) => {
|
|
81
|
+
if (url.startsWith("/")) {
|
|
82
|
+
return url;
|
|
83
|
+
}
|
|
84
|
+
return resolver(url, fileDir);
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
file,
|
|
88
|
+
contents: rebased
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function rewriteCssUrls(css, type, replacer) {
|
|
92
|
+
return asyncReplace(css, cssUrlRE, async (match) => {
|
|
93
|
+
const matched = match[0];
|
|
94
|
+
let rawUrl = match[1];
|
|
95
|
+
let wrap = "";
|
|
96
|
+
const first = rawUrl[0];
|
|
97
|
+
if (first === `"` || first === `'`) {
|
|
98
|
+
wrap = first;
|
|
99
|
+
rawUrl = rawUrl.slice(1, -1);
|
|
100
|
+
}
|
|
101
|
+
if (type === "less" && rawUrl.startsWith("@") || (type === "sass" || type === "scss") && rawUrl.startsWith("$") || isExternalUrl(rawUrl) || isDataUrl(rawUrl) || rawUrl.startsWith("#")) {
|
|
102
|
+
return matched;
|
|
103
|
+
}
|
|
104
|
+
return `url(${wrap}${(0, import_utils.normalizeSlashes)(await replacer(rawUrl))}${wrap})`;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async function asyncReplace(input, re, replacer) {
|
|
108
|
+
let match;
|
|
109
|
+
let remaining = input;
|
|
110
|
+
let rewritten = "";
|
|
111
|
+
while (match = re.exec(remaining)) {
|
|
112
|
+
rewritten += remaining.slice(0, match.index);
|
|
113
|
+
rewritten += await replacer(match);
|
|
114
|
+
remaining = remaining.slice(match.index + match[0].length);
|
|
115
|
+
}
|
|
116
|
+
rewritten += remaining;
|
|
117
|
+
return rewritten;
|
|
118
|
+
}
|
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
+
0 && (module.exports = {
|
|
121
|
+
loadProcessor,
|
|
122
|
+
rebaseUrls,
|
|
123
|
+
rewriteCssUrls
|
|
124
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ICompiler, ITsconfig } from '../../types';
|
|
2
|
+
export declare const swcTransform: (userTsconfig: ITsconfig) => {
|
|
3
|
+
name: string;
|
|
4
|
+
apply(compiler: ICompiler): void;
|
|
5
|
+
};
|
|
6
|
+
export declare const swcRenderChunk: {
|
|
7
|
+
name: string;
|
|
8
|
+
apply(compiler: ICompiler): void;
|
|
9
|
+
};
|