@umijs/bundler-esbuild 4.0.0-beta.8 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/dist/build.d.ts +3 -2
- package/dist/build.js +97 -54
- package/dist/cli.js +63 -61
- package/dist/index.js +22 -12
- package/dist/plugins/__sample.js +30 -5
- package/dist/plugins/alias.js +89 -65
- package/dist/plugins/externals.d.ts +1 -1
- package/dist/plugins/externals.js +43 -21
- package/dist/plugins/less-plugin-alias/index.d.ts +9 -0
- package/dist/plugins/less-plugin-alias/index.js +100 -0
- package/dist/plugins/less-plugin-alias/types.d.ts +4 -0
- package/dist/plugins/less-plugin-alias/types.js +17 -0
- package/dist/plugins/less-plugin-alias/utils.d.ts +2 -0
- package/dist/plugins/less-plugin-alias/utils.js +60 -0
- package/dist/plugins/less.d.ts +7 -2
- package/dist/plugins/less.js +203 -49
- package/dist/plugins/nodeGlobalsPolyfill.js +36 -12
- package/dist/plugins/style.d.ts +17 -0
- package/dist/plugins/style.js +171 -0
- package/dist/plugins/watchRebuild.d.ts +4 -0
- package/dist/plugins/watchRebuild.js +67 -0
- package/dist/types.d.ts +11 -3
- package/dist/types.js +40 -13
- package/dist/utils/getBrowserlist.d.ts +1 -0
- package/dist/utils/getBrowserlist.js +33 -0
- package/dist/utils/postcssProcess.d.ts +2 -0
- package/dist/utils/postcssProcess.js +58 -0
- package/dist/utils/sortByAffix.js +38 -14
- package/package.json +28 -25
- package/dist/build.d.ts.map +0 -1
- package/dist/cli.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/plugins/__sample.d.ts.map +0 -1
- package/dist/plugins/alias.d.ts.map +0 -1
- package/dist/plugins/externals.d.ts.map +0 -1
- package/dist/plugins/less.d.ts.map +0 -1
- package/dist/plugins/nodeGlobalsPolyfill.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/sortByAffix.d.ts.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017-present ChenCheng (sorrycc@gmail.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/dist/build.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Format } from '@umijs/bundler-utils/compiled/esbuild';
|
|
1
|
+
import { Format, BuildOptions } from '@umijs/bundler-utils/compiled/esbuild';
|
|
2
2
|
import { IBabelPlugin, IConfig } from './types';
|
|
3
3
|
interface IOpts {
|
|
4
4
|
cwd: string;
|
|
@@ -13,6 +13,7 @@ interface IOpts {
|
|
|
13
13
|
beforeBabelPresets?: any[];
|
|
14
14
|
extraBabelPlugins?: IBabelPlugin[];
|
|
15
15
|
extraBabelPresets?: IBabelPlugin[];
|
|
16
|
+
inlineStyle?: boolean;
|
|
16
17
|
}
|
|
17
|
-
export declare function build(opts: IOpts): Promise<import("@umijs/bundler-utils/compiled/esbuild").BuildResult
|
|
18
|
+
export declare function build(opts: IOpts): Promise<import("@umijs/bundler-utils/compiled/esbuild").BuildResult<BuildOptions>>;
|
|
18
19
|
export {};
|
package/dist/build.js
CHANGED
|
@@ -1,59 +1,102 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
13
18
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/build.ts
|
|
30
|
+
var build_exports = {};
|
|
31
|
+
__export(build_exports, {
|
|
32
|
+
build: () => build
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(build_exports);
|
|
35
|
+
var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
|
|
36
|
+
var import_utils = require("@umijs/utils");
|
|
37
|
+
var import_path = require("path");
|
|
38
|
+
var import_alias = __toESM(require("./plugins/alias"));
|
|
39
|
+
var import_externals = __toESM(require("./plugins/externals"));
|
|
40
|
+
var import_less = __toESM(require("./plugins/less"));
|
|
41
|
+
var import_style = require("./plugins/style");
|
|
42
|
+
async function build(opts) {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const outputPath = opts.config.outputPath || (0, import_path.join)(opts.cwd, "dist");
|
|
45
|
+
if (opts.clean) {
|
|
46
|
+
import_utils.rimraf.sync(outputPath);
|
|
47
|
+
}
|
|
48
|
+
const config = {
|
|
49
|
+
entryPoints: opts.entry,
|
|
50
|
+
bundle: true,
|
|
51
|
+
format: opts.format || "iife",
|
|
52
|
+
logLevel: "error",
|
|
53
|
+
// splitting: true,
|
|
54
|
+
sourcemap: opts.sourcemap,
|
|
55
|
+
outdir: outputPath,
|
|
56
|
+
metafile: true,
|
|
57
|
+
plugins: [
|
|
58
|
+
(0, import_less.default)({
|
|
59
|
+
modifyVars: opts.config.theme,
|
|
60
|
+
javascriptEnabled: true,
|
|
61
|
+
alias: opts.config.alias,
|
|
62
|
+
// ref: https://github.com/umijs/umi-next/pull/214
|
|
63
|
+
inlineStyle: opts.inlineStyle,
|
|
64
|
+
config: opts.config,
|
|
65
|
+
...opts.config.lessLoader
|
|
66
|
+
}),
|
|
67
|
+
opts.config.alias && (0, import_alias.default)(addCwdPrefix(opts.config.alias, opts.cwd)),
|
|
68
|
+
opts.config.externals && (0, import_externals.default)(opts.config.externals),
|
|
69
|
+
(0, import_style.style)({
|
|
70
|
+
inlineStyle: opts.inlineStyle,
|
|
71
|
+
config: opts.config
|
|
72
|
+
})
|
|
73
|
+
].filter(Boolean),
|
|
74
|
+
define: {
|
|
75
|
+
// __dirname sham
|
|
76
|
+
__dirname: JSON.stringify("__dirname"),
|
|
77
|
+
"process.env.NODE_ENV": JSON.stringify(opts.mode || "development"),
|
|
78
|
+
...opts.config.define
|
|
79
|
+
},
|
|
80
|
+
loader: {
|
|
81
|
+
".svg": "dataurl",
|
|
82
|
+
".ttf": "dataurl",
|
|
83
|
+
".wasm": "dataurl",
|
|
84
|
+
...opts.config.loader
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
await ((_b = (_a = opts.config).modifyConfig) == null ? void 0 : _b.call(_a, config));
|
|
88
|
+
const result = await (0, import_esbuild.build)(config);
|
|
89
|
+
return result;
|
|
49
90
|
}
|
|
50
|
-
exports.build = build;
|
|
51
|
-
// TODO: move to api.describe({ config: { format } })
|
|
52
91
|
function addCwdPrefix(obj, cwd) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
92
|
+
Object.keys(obj).forEach((key) => {
|
|
93
|
+
if (obj[key].startsWith(".")) {
|
|
94
|
+
obj[key] = (0, import_utils.winPath)((0, import_path.join)(cwd, obj[key]));
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return obj;
|
|
59
98
|
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
build
|
|
102
|
+
});
|
package/dist/cli.js
CHANGED
|
@@ -1,72 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
10
14
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
|
|
24
|
+
// src/cli.ts
|
|
25
|
+
var import_esbuild = __toESM(require("@umijs/bundler-utils/compiled/esbuild"));
|
|
26
|
+
var import_utils = require("@umijs/utils");
|
|
27
|
+
var import_assert = __toESM(require("assert"));
|
|
28
|
+
var import_fs = require("fs");
|
|
29
|
+
var import_path = require("path");
|
|
30
|
+
var import_build = require("./build");
|
|
31
|
+
var args = (0, import_utils.yParser)(process.argv.slice(2), {});
|
|
32
|
+
var command = args._[0];
|
|
33
|
+
var cwd = process.cwd();
|
|
34
|
+
var entry = (0, import_utils.tryPaths)([
|
|
35
|
+
(0, import_path.join)(cwd, "src/index.tsx"),
|
|
36
|
+
(0, import_path.join)(cwd, "src/index.ts"),
|
|
37
|
+
(0, import_path.join)(cwd, "index.tsx"),
|
|
38
|
+
(0, import_path.join)(cwd, "index.ts")
|
|
29
39
|
]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
var config = {};
|
|
41
|
+
var configFile = (0, import_path.join)(cwd, args.config || "config.ts");
|
|
42
|
+
import_utils.register.register({
|
|
43
|
+
implementor: import_esbuild.default
|
|
34
44
|
});
|
|
35
|
-
|
|
36
|
-
if ((0,
|
|
37
|
-
|
|
45
|
+
import_utils.register.clearFiles();
|
|
46
|
+
if ((0, import_fs.existsSync)(configFile)) {
|
|
47
|
+
config = require(configFile).default;
|
|
38
48
|
}
|
|
39
49
|
Object.assign(config, args);
|
|
40
|
-
if (command ===
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
catch (e) {
|
|
54
|
-
console.error(e);
|
|
50
|
+
if (command === "build") {
|
|
51
|
+
(async () => {
|
|
52
|
+
process.env.NODE_ENV = "production";
|
|
53
|
+
(0, import_assert.default)(entry, `Build failed: entry not found.`);
|
|
54
|
+
try {
|
|
55
|
+
await (0, import_build.build)({
|
|
56
|
+
config,
|
|
57
|
+
cwd,
|
|
58
|
+
entry: {
|
|
59
|
+
[getEntryKey(entry)]: entry
|
|
55
60
|
}
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
});
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.error(e);
|
|
64
|
+
}
|
|
65
|
+
})();
|
|
66
|
+
} else {
|
|
67
|
+
error(`Unsupported command ${command}.`);
|
|
60
68
|
}
|
|
61
69
|
function error(msg) {
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
function tryPaths(paths) {
|
|
65
|
-
for (const path of paths) {
|
|
66
|
-
if ((0, fs_1.existsSync)(path))
|
|
67
|
-
return path;
|
|
68
|
-
}
|
|
70
|
+
console.error(import_utils.chalk.red(msg));
|
|
69
71
|
}
|
|
70
72
|
function getEntryKey(path) {
|
|
71
|
-
|
|
73
|
+
return (0, import_path.basename)(path, (0, import_path.extname)(path));
|
|
72
74
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/index.ts
|
|
17
|
+
var src_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(src_exports);
|
|
19
|
+
__reExport(src_exports, require("./build"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./build")
|
|
23
|
+
});
|
package/dist/plugins/__sample.js
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
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
|
+
// src/plugins/__sample.ts
|
|
20
|
+
var sample_exports = {};
|
|
21
|
+
__export(sample_exports, {
|
|
22
|
+
Sample: () => Sample
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(sample_exports);
|
|
4
25
|
function Sample() {
|
|
5
|
-
|
|
26
|
+
return { name: "", setup() {
|
|
27
|
+
} };
|
|
6
28
|
}
|
|
7
|
-
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
Sample
|
|
32
|
+
});
|
package/dist/plugins/alias.js
CHANGED
|
@@ -1,72 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
10
|
};
|
|
11
|
-
var
|
|
12
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
13
18
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/alias.ts
|
|
30
|
+
var alias_exports = {};
|
|
31
|
+
__export(alias_exports, {
|
|
32
|
+
default: () => alias_default
|
|
23
33
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
module.exports = __toCommonJS(alias_exports);
|
|
35
|
+
var import_enhanced_resolve = __toESM(require("enhanced-resolve"));
|
|
36
|
+
var import_fs = require("fs");
|
|
37
|
+
var import_sortByAffix = require("../utils/sortByAffix");
|
|
38
|
+
var resolver = import_enhanced_resolve.default.create({
|
|
39
|
+
mainFields: ["module", "browser", "main"],
|
|
40
|
+
extensions: [".json", ".js", ".jsx", ".ts", ".tsx", ".cjs", ".mjs"],
|
|
41
|
+
// TODO: support exports
|
|
42
|
+
exportsFields: []
|
|
43
|
+
});
|
|
44
|
+
async function resolve(context, path) {
|
|
45
|
+
return new Promise((resolve2, reject) => {
|
|
46
|
+
resolver(
|
|
47
|
+
context,
|
|
48
|
+
path,
|
|
49
|
+
(err, result) => err ? reject(err) : resolve2(result)
|
|
50
|
+
);
|
|
51
|
+
});
|
|
30
52
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
53
|
+
var alias_default = (options = {}) => {
|
|
54
|
+
return {
|
|
55
|
+
name: "alias",
|
|
56
|
+
setup({ onResolve }) {
|
|
57
|
+
const keys = (0, import_sortByAffix.sortByAffix)({ arr: Object.keys(options), affix: "$" });
|
|
58
|
+
keys.forEach((key) => {
|
|
59
|
+
let value = options[key];
|
|
60
|
+
let filter;
|
|
61
|
+
if (key.endsWith("$")) {
|
|
62
|
+
filter = new RegExp(`^${key}`);
|
|
63
|
+
} else {
|
|
64
|
+
filter = new RegExp(`^${key}$`);
|
|
65
|
+
}
|
|
66
|
+
onResolve({ filter }, async (args) => {
|
|
67
|
+
const path = await resolve(
|
|
68
|
+
args.importer,
|
|
69
|
+
args.path.replace(filter, value)
|
|
70
|
+
);
|
|
71
|
+
return {
|
|
72
|
+
path
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
if (!key.endsWith("/") && (0, import_fs.existsSync)(value) && (0, import_fs.statSync)(value).isDirectory()) {
|
|
76
|
+
const filter2 = new RegExp(`^${addSlashAffix(key)}`);
|
|
77
|
+
onResolve({ filter: filter2 }, async (args) => {
|
|
78
|
+
const path = await resolve(
|
|
79
|
+
args.importer,
|
|
80
|
+
args.path.replace(filter2, addSlashAffix(value))
|
|
81
|
+
);
|
|
82
|
+
return {
|
|
83
|
+
path
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
};
|
|
66
90
|
};
|
|
67
91
|
function addSlashAffix(key) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
if (key.endsWith("/")) {
|
|
93
|
+
return key;
|
|
94
|
+
}
|
|
95
|
+
return `${key}/`;
|
|
72
96
|
}
|