@umijs/bundler-esbuild 4.0.7 → 4.0.8
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/build.d.ts +0 -0
- package/dist/build.js +92 -60
- package/dist/cli.d.ts +0 -0
- package/dist/cli.js +56 -46
- package/dist/index.d.ts +0 -0
- package/dist/index.js +18 -16
- package/dist/plugins/__sample.d.ts +0 -0
- package/dist/plugins/__sample.js +30 -5
- package/dist/plugins/alias.d.ts +0 -0
- package/dist/plugins/alias.js +73 -54
- package/dist/plugins/externals.d.ts +1 -1
- package/dist/plugins/externals.js +45 -21
- package/dist/plugins/less-plugin-alias/index.d.ts +0 -0
- package/dist/plugins/less-plugin-alias/index.js +84 -64
- package/dist/plugins/less-plugin-alias/types.d.ts +0 -0
- package/dist/plugins/less-plugin-alias/types.js +17 -2
- package/dist/plugins/less-plugin-alias/utils.d.ts +0 -0
- package/dist/plugins/less-plugin-alias/utils.js +51 -30
- package/dist/plugins/less.d.ts +0 -0
- package/dist/plugins/less.js +193 -147
- package/dist/plugins/nodeGlobalsPolyfill.d.ts +0 -0
- package/dist/plugins/nodeGlobalsPolyfill.js +36 -12
- package/dist/plugins/style.d.ts +0 -0
- package/dist/plugins/style.js +136 -100
- package/dist/types.d.ts +0 -0
- package/dist/types.js +40 -13
- package/dist/utils/getBrowserlist.d.ts +0 -0
- package/dist/utils/getBrowserlist.js +31 -9
- package/dist/utils/postcssProcess.d.ts +0 -0
- package/dist/utils/postcssProcess.js +59 -22
- package/dist/utils/sortByAffix.d.ts +0 -0
- package/dist/utils/sortByAffix.js +38 -14
- package/package.json +5 -5
|
@@ -1,70 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// index.ts
|
|
20
|
+
var less_plugin_alias_exports = {};
|
|
21
|
+
__export(less_plugin_alias_exports, {
|
|
22
|
+
default: () => LessAliasPlugin
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(less_plugin_alias_exports);
|
|
25
|
+
var import_utils = require("@umijs/utils");
|
|
26
|
+
var import_utils2 = require("./utils");
|
|
5
27
|
function matches(pattern, importee) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
28
|
+
if (pattern instanceof RegExp) {
|
|
29
|
+
return pattern.test(importee);
|
|
30
|
+
}
|
|
31
|
+
if (importee.length < pattern.length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (importee === pattern) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return importee.startsWith(pattern + "/");
|
|
16
38
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
39
|
+
var LessAliasPlugin = class {
|
|
40
|
+
constructor(options) {
|
|
41
|
+
this.options = options;
|
|
42
|
+
}
|
|
43
|
+
install(less, pluginManager) {
|
|
44
|
+
const alias = (0, import_utils2.parseAlias)(this.options.alias);
|
|
45
|
+
function resolveId(filename) {
|
|
46
|
+
if (!filename) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const matchedEntry = alias.find((entry) => matches(entry.find, filename));
|
|
50
|
+
if (!matchedEntry) {
|
|
51
|
+
return filename;
|
|
52
|
+
}
|
|
53
|
+
const resolvedPath = filename.replace(matchedEntry.find, matchedEntry.replacement);
|
|
54
|
+
return resolvedPath;
|
|
20
55
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const matchedEntry = alias.find((entry) => matches(entry.find, filename));
|
|
29
|
-
if (!matchedEntry) {
|
|
30
|
-
return filename;
|
|
31
|
-
}
|
|
32
|
-
const resolvedPath = filename.replace(matchedEntry.find, matchedEntry.replacement);
|
|
33
|
-
return resolvedPath;
|
|
56
|
+
class AliasePlugin extends less.FileManager {
|
|
57
|
+
loadFile(filename, currentDirectory, options, enviroment) {
|
|
58
|
+
let resolved;
|
|
59
|
+
try {
|
|
60
|
+
resolved = resolveId(filename);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
import_utils.logger.error(error);
|
|
34
63
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
resolved = resolveId(filename);
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
utils_1.logger.error(error);
|
|
43
|
-
}
|
|
44
|
-
if (!resolved) {
|
|
45
|
-
const error = new Error(`[less-plugin-alias]: '${filename}' not found.`);
|
|
46
|
-
utils_1.logger.error(error);
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
return super.loadFile(resolved, currentDirectory, options, enviroment);
|
|
50
|
-
}
|
|
51
|
-
loadFileSync(filename, currentDirectory, options, enviroment) {
|
|
52
|
-
let resolved;
|
|
53
|
-
try {
|
|
54
|
-
resolved = resolveId(filename);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
utils_1.logger.error(error);
|
|
58
|
-
}
|
|
59
|
-
if (!resolved) {
|
|
60
|
-
const error = new Error(`[less-plugin-alias]: '${filename}' not found.`);
|
|
61
|
-
utils_1.logger.error(error);
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
64
|
-
return super.loadFileSync(resolved, currentDirectory, options, enviroment);
|
|
65
|
-
}
|
|
64
|
+
if (!resolved) {
|
|
65
|
+
const error = new Error(`[less-plugin-alias]: '${filename}' not found.`);
|
|
66
|
+
import_utils.logger.error(error);
|
|
67
|
+
throw error;
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
return super.loadFile(resolved, currentDirectory, options, enviroment);
|
|
70
|
+
}
|
|
71
|
+
loadFileSync(filename, currentDirectory, options, enviroment) {
|
|
72
|
+
let resolved;
|
|
73
|
+
try {
|
|
74
|
+
resolved = resolveId(filename);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
import_utils.logger.error(error);
|
|
77
|
+
}
|
|
78
|
+
if (!resolved) {
|
|
79
|
+
const error = new Error(`[less-plugin-alias]: '${filename}' not found.`);
|
|
80
|
+
import_utils.logger.error(error);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
return super.loadFileSync(resolved, currentDirectory, options, enviroment);
|
|
84
|
+
}
|
|
68
85
|
}
|
|
69
|
-
|
|
70
|
-
|
|
86
|
+
pluginManager.addFileManager(new AliasePlugin());
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {});
|
|
File without changes
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
File without changes
|
|
@@ -1,35 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// utils.ts
|
|
20
|
+
var utils_exports = {};
|
|
21
|
+
__export(utils_exports, {
|
|
22
|
+
parseAlias: () => parseAlias
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
4
25
|
function hoistAlias(alias) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return getFinalReplacement(newAlias, replacement, i);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return replacement;
|
|
26
|
+
function getFinalReplacement(oAlias, replacement, index) {
|
|
27
|
+
const newAlias = oAlias.slice();
|
|
28
|
+
newAlias.splice(index, 1);
|
|
29
|
+
for (let i = 0; i < newAlias.length; i++) {
|
|
30
|
+
if (newAlias[i].find.test(replacement)) {
|
|
31
|
+
replacement = replacement.replace(newAlias[i].find, newAlias[i].replacement);
|
|
32
|
+
return getFinalReplacement(newAlias, replacement, i);
|
|
33
|
+
}
|
|
17
34
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
return replacement;
|
|
36
|
+
}
|
|
37
|
+
alias.forEach((rule, index, alias2) => {
|
|
38
|
+
rule.replacement = getFinalReplacement(alias2, rule.replacement, index);
|
|
39
|
+
});
|
|
40
|
+
return alias;
|
|
22
41
|
}
|
|
23
42
|
function parseAlias(alias) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return hoistAlias(wholeAlias);
|
|
43
|
+
const wholeAlias = [
|
|
44
|
+
{ find: /^~/, replacement: "" }
|
|
45
|
+
];
|
|
46
|
+
const userAlias = Object.entries(alias).map(([name, target]) => ({
|
|
47
|
+
find: new RegExp(`^~?${name.replace(/(?<!\$)$/, "(?=/|$)")}`),
|
|
48
|
+
replacement: target
|
|
49
|
+
}));
|
|
50
|
+
wholeAlias.unshift(...userAlias);
|
|
51
|
+
return hoistAlias(wholeAlias);
|
|
34
52
|
}
|
|
35
|
-
|
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
54
|
+
0 && (module.exports = {
|
|
55
|
+
parseAlias
|
|
56
|
+
});
|
package/dist/plugins/less.d.ts
CHANGED
|
File without changes
|
package/dist/plugins/less.js
CHANGED
|
@@ -1,160 +1,206 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __objRest = (source, exclude) => {
|
|
25
|
+
var target = {};
|
|
26
|
+
for (var prop in source)
|
|
27
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
if (source != null && __getOwnPropSymbols)
|
|
30
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
+
target[prop] = source[prop];
|
|
33
|
+
}
|
|
34
|
+
return target;
|
|
35
|
+
};
|
|
36
|
+
var __export = (target, all) => {
|
|
37
|
+
for (var name in all)
|
|
38
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
39
|
+
};
|
|
40
|
+
var __copyProps = (to, from, except, desc) => {
|
|
41
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
42
|
+
for (let key of __getOwnPropNames(from))
|
|
43
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
44
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
45
|
+
}
|
|
46
|
+
return to;
|
|
4
47
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const less_plugin_alias_1 = __importDefault(require("./less-plugin-alias"));
|
|
14
|
-
const resolver = enhanced_resolve_1.default.create({
|
|
15
|
-
mainFields: ['module', 'browser', 'main'],
|
|
16
|
-
extensions: [
|
|
17
|
-
'.json',
|
|
18
|
-
'.js',
|
|
19
|
-
'.jsx',
|
|
20
|
-
'.ts',
|
|
21
|
-
'.tsx',
|
|
22
|
-
'.cjs',
|
|
23
|
-
'.mjs',
|
|
24
|
-
'.less',
|
|
25
|
-
'.css',
|
|
26
|
-
],
|
|
27
|
-
// TODO: support exports
|
|
28
|
-
exportsFields: [],
|
|
48
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
49
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
|
+
|
|
51
|
+
// less.ts
|
|
52
|
+
var less_exports = {};
|
|
53
|
+
__export(less_exports, {
|
|
54
|
+
aliasLessImportPath: () => aliasLessImportPath,
|
|
55
|
+
default: () => less_default
|
|
29
56
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
module.exports = __toCommonJS(less_exports);
|
|
58
|
+
var import_less = __toESM(require("@umijs/bundler-utils/compiled/less"));
|
|
59
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
60
|
+
var import_fs = require("fs");
|
|
61
|
+
var import_path = __toESM(require("path"));
|
|
62
|
+
var import_postcssProcess = require("../utils/postcssProcess");
|
|
63
|
+
var import_sortByAffix = require("../utils/sortByAffix");
|
|
64
|
+
var import_less_plugin_alias = __toESM(require("./less-plugin-alias"));
|
|
65
|
+
var resolver = import_enhanced_resolve.default.create({
|
|
66
|
+
mainFields: ["module", "browser", "main"],
|
|
67
|
+
extensions: [
|
|
68
|
+
".json",
|
|
69
|
+
".js",
|
|
70
|
+
".jsx",
|
|
71
|
+
".ts",
|
|
72
|
+
".tsx",
|
|
73
|
+
".cjs",
|
|
74
|
+
".mjs",
|
|
75
|
+
".less",
|
|
76
|
+
".css"
|
|
77
|
+
],
|
|
78
|
+
exportsFields: []
|
|
79
|
+
});
|
|
80
|
+
async function resolve(context, path2) {
|
|
81
|
+
return new Promise((resolve2, reject) => {
|
|
82
|
+
resolver(context, path2, (err, result) => err ? reject(err) : resolve2(result));
|
|
83
|
+
});
|
|
34
84
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
85
|
+
var aliasLessImports = async (ctx, alias, importer) => {
|
|
86
|
+
const importRegex = /@import(?:\s+\((.*)\))?\s+['"](.*)['"]/;
|
|
87
|
+
const globalImportRegex = /@import(?:\s+\((.*)\))?\s+['"](.*)['"]/g;
|
|
88
|
+
const match = ctx.match(globalImportRegex) || [];
|
|
89
|
+
for (const el of match) {
|
|
90
|
+
const [imp, _, filePath] = el.match(importRegex) || [];
|
|
91
|
+
let aliaPath = await aliasLessImportPath(filePath, alias, importer);
|
|
92
|
+
if (aliaPath) {
|
|
93
|
+
ctx = ctx.replace(imp, el.replace(filePath, aliaPath));
|
|
45
94
|
}
|
|
46
|
-
|
|
95
|
+
}
|
|
96
|
+
return ctx;
|
|
47
97
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
aliaPath = pathSegments.join('/');
|
|
59
|
-
aliaPath = path_1.default.extname(aliaPath) ? aliaPath : `${aliaPath}.less`;
|
|
60
|
-
return await resolve(importer, aliaPath);
|
|
61
|
-
}
|
|
98
|
+
var aliasLessImportPath = async (filePath, alias, importer) => {
|
|
99
|
+
let aliaPath = filePath.startsWith("~") ? filePath.replace("~", "") : filePath;
|
|
100
|
+
const keys = (0, import_sortByAffix.sortByAffix)({ arr: Object.keys(alias), affix: "$" });
|
|
101
|
+
for (const key of keys) {
|
|
102
|
+
const pathSegments = aliaPath.split("/");
|
|
103
|
+
if (pathSegments[0] === key) {
|
|
104
|
+
pathSegments[0] = alias[key];
|
|
105
|
+
aliaPath = pathSegments.join("/");
|
|
106
|
+
aliaPath = import_path.default.extname(aliaPath) ? aliaPath : `${aliaPath}.less`;
|
|
107
|
+
return await resolve(importer, aliaPath);
|
|
62
108
|
}
|
|
63
|
-
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
64
111
|
};
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
sideEffects: false,
|
|
105
|
-
}));
|
|
106
|
-
onLoad({ filter: /.*/, namespace: 'less-file' }, async (args) => ({
|
|
107
|
-
contents: `
|
|
112
|
+
var less_default = (options = {}) => {
|
|
113
|
+
const _a = options, { alias, inlineStyle, config } = _a, lessOptions = __objRest(_a, ["alias", "inlineStyle", "config"]);
|
|
114
|
+
return {
|
|
115
|
+
name: "less",
|
|
116
|
+
setup({ onResolve, onLoad }) {
|
|
117
|
+
onResolve({ filter: /\.less$/, namespace: "file" }, async (args) => {
|
|
118
|
+
let filePath = args.path;
|
|
119
|
+
let isMatchedAlias = false;
|
|
120
|
+
if (!!alias) {
|
|
121
|
+
const aliasMatchPath = await aliasLessImportPath(filePath, alias, args.path);
|
|
122
|
+
if (aliasMatchPath) {
|
|
123
|
+
isMatchedAlias = true;
|
|
124
|
+
filePath = aliasMatchPath;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
if (!isMatchedAlias) {
|
|
128
|
+
const isImportFromDeps = !import_path.default.isAbsolute(filePath) && !filePath.startsWith(".");
|
|
129
|
+
if (isImportFromDeps) {
|
|
130
|
+
filePath = await resolve(process.cwd(), filePath);
|
|
131
|
+
} else {
|
|
132
|
+
filePath = import_path.default.resolve(process.cwd(), import_path.default.relative(process.cwd(), args.resolveDir), args.path);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
path: filePath,
|
|
137
|
+
namespace: inlineStyle ? "less-file" : "file"
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
if (inlineStyle) {
|
|
141
|
+
onResolve({ filter: /\.less$/, namespace: "less-file" }, (args) => {
|
|
142
|
+
return { path: args.path, namespace: "less-content" };
|
|
143
|
+
});
|
|
144
|
+
onResolve({ filter: /^__style_helper__$/, namespace: "less-file" }, (args) => ({
|
|
145
|
+
path: args.path,
|
|
146
|
+
namespace: "style-helper",
|
|
147
|
+
sideEffects: false
|
|
148
|
+
}));
|
|
149
|
+
onLoad({ filter: /.*/, namespace: "less-file" }, async (args) => ({
|
|
150
|
+
contents: `
|
|
108
151
|
import { injectStyle } from "__style_helper__"
|
|
109
152
|
import css from ${JSON.stringify(args.path)}
|
|
110
153
|
injectStyle(css)
|
|
111
154
|
export default{}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
column: error.column,
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
resolveDir: dir,
|
|
155
|
-
};
|
|
155
|
+
`
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
onLoad({ filter: /\.less$/, namespace: inlineStyle ? "less-content" : "file" }, async (args) => {
|
|
159
|
+
let content = await import_fs.promises.readFile(args.path, "utf-8");
|
|
160
|
+
if (!!alias) {
|
|
161
|
+
content = await aliasLessImports(content, alias, args.path);
|
|
162
|
+
}
|
|
163
|
+
const dir = import_path.default.dirname(args.path);
|
|
164
|
+
const filename = import_path.default.basename(args.path);
|
|
165
|
+
try {
|
|
166
|
+
const result = await import_less.default.render(content, __spreadProps(__spreadValues({
|
|
167
|
+
plugins: [
|
|
168
|
+
new import_less_plugin_alias.default({
|
|
169
|
+
alias: alias || {}
|
|
170
|
+
})
|
|
171
|
+
],
|
|
172
|
+
filename,
|
|
173
|
+
rootpath: dir
|
|
174
|
+
}, lessOptions), {
|
|
175
|
+
paths: [...lessOptions.paths || [], dir]
|
|
176
|
+
}));
|
|
177
|
+
const postcssrResult = await (0, import_postcssProcess.postcssProcess)(config, result.css, args.path);
|
|
178
|
+
return {
|
|
179
|
+
contents: postcssrResult.css,
|
|
180
|
+
loader: inlineStyle ? "text" : "css",
|
|
181
|
+
resolveDir: dir
|
|
182
|
+
};
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return {
|
|
185
|
+
errors: [
|
|
186
|
+
{
|
|
187
|
+
text: error.message,
|
|
188
|
+
location: {
|
|
189
|
+
namespace: "file",
|
|
190
|
+
file: error.filename,
|
|
191
|
+
line: error.line,
|
|
192
|
+
column: error.column
|
|
156
193
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
194
|
+
}
|
|
195
|
+
],
|
|
196
|
+
resolveDir: dir
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
};
|
|
160
202
|
};
|
|
203
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
+
0 && (module.exports = {
|
|
205
|
+
aliasLessImportPath
|
|
206
|
+
});
|
|
File without changes
|