@umijs/bundler-esbuild 4.0.0-beta.9 → 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 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;
@@ -15,5 +15,5 @@ interface IOpts {
15
15
  extraBabelPresets?: IBabelPlugin[];
16
16
  inlineStyle?: boolean;
17
17
  }
18
- 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>>;
19
19
  export {};
package/dist/build.js CHANGED
@@ -1,61 +1,102 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.build = void 0;
16
- const esbuild_1 = require("@umijs/bundler-utils/compiled/esbuild");
17
- const utils_1 = require("@umijs/utils");
18
- const path_1 = require("path");
19
- const alias_1 = __importDefault(require("./plugins/alias"));
20
- const externals_1 = __importDefault(require("./plugins/externals"));
21
- const less_1 = __importDefault(require("./plugins/less"));
22
- const style_1 = require("./plugins/style");
23
- function build(opts) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- const outputPath = opts.config.outputPath || (0, path_1.join)(opts.cwd, 'dist');
26
- if (opts.clean) {
27
- utils_1.rimraf.sync(outputPath);
28
- }
29
- return yield (0, esbuild_1.build)({
30
- entryPoints: opts.entry,
31
- bundle: true,
32
- format: opts.format || 'iife',
33
- logLevel: 'error',
34
- // splitting: true,
35
- sourcemap: opts.sourcemap,
36
- outdir: outputPath,
37
- metafile: true,
38
- plugins: [
39
- (0, less_1.default)(Object.assign({ modifyVars: opts.config.theme, javascriptEnabled: true }, opts.config.lessLoader)),
40
- opts.config.alias && (0, alias_1.default)(addCwdPrefix(opts.config.alias, opts.cwd)),
41
- opts.config.externals && (0, externals_1.default)(opts.config.externals),
42
- opts.inlineStyle && (0, style_1.inlineStyle)(),
43
- ].filter(Boolean),
44
- define: {
45
- // __dirname sham
46
- __dirname: JSON.stringify('__dirname'),
47
- 'process.env.NODE_ENV': JSON.stringify(opts.mode || 'development'),
48
- },
49
- });
50
- });
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;
51
90
  }
52
- exports.build = build;
53
- // TODO: move to api.describe({ config: { format } })
54
91
  function addCwdPrefix(obj, cwd) {
55
- Object.keys(obj).forEach((key) => {
56
- if (obj[key].startsWith('.')) {
57
- obj[key] = (0, utils_1.winPath)((0, path_1.join)(cwd, obj[key]));
58
- }
59
- });
60
- return obj;
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;
61
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
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const esbuild_1 = __importDefault(require("@umijs/bundler-utils/compiled/esbuild"));
16
- const utils_1 = require("@umijs/utils");
17
- const assert_1 = __importDefault(require("assert"));
18
- const fs_1 = require("fs");
19
- const path_1 = require("path");
20
- const build_1 = require("./build");
21
- const args = (0, utils_1.yParser)(process.argv.slice(2), {});
22
- const command = args._[0];
23
- const cwd = process.cwd();
24
- const entry = tryPaths([
25
- (0, path_1.join)(cwd, 'src/index.tsx'),
26
- (0, path_1.join)(cwd, 'src/index.ts'),
27
- (0, path_1.join)(cwd, 'index.tsx'),
28
- (0, path_1.join)(cwd, 'index.ts'),
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
- let config = {};
31
- const configFile = (0, path_1.join)(cwd, args.config || 'config.ts');
32
- utils_1.register.register({
33
- implementor: esbuild_1.default,
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
- utils_1.register.clearFiles();
36
- if ((0, fs_1.existsSync)(configFile)) {
37
- config = require(configFile).default;
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 === 'build') {
41
- (() => __awaiter(void 0, void 0, void 0, function* () {
42
- process.env.NODE_ENV = 'production';
43
- (0, assert_1.default)(entry, `Build failed: entry not found.`);
44
- try {
45
- yield (0, build_1.build)({
46
- config,
47
- cwd,
48
- entry: {
49
- [getEntryKey(entry)]: entry,
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
- else {
59
- error(`Unsupported command ${command}.`);
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
- console.error(utils_1.chalk.red(msg));
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
- return (0, path_1.basename)(path, (0, path_1.extname)(path));
73
+ return (0, import_path.basename)(path, (0, import_path.extname)(path));
72
74
  }
package/dist/index.js CHANGED
@@ -1,13 +1,23 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
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
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./build"), exports);
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
+ });
@@ -1,7 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Sample = void 0;
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
- return { name: '', setup() { } };
26
+ return { name: "", setup() {
27
+ } };
6
28
  }
7
- exports.Sample = Sample;
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ Sample
32
+ });
@@ -1,72 +1,96 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const enhanced_resolve_1 = __importDefault(require("enhanced-resolve"));
16
- const fs_1 = require("fs");
17
- const sortByAffix_1 = require("../utils/sortByAffix");
18
- const resolver = enhanced_resolve_1.default.create({
19
- mainFields: ['module', 'browser', 'main'],
20
- extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.cjs', '.mjs'],
21
- // TODO: support exports
22
- exportsFields: [],
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
- function resolve(context, path) {
25
- return __awaiter(this, void 0, void 0, function* () {
26
- return new Promise((resolve, reject) => {
27
- resolver(context, path, (err, result) => err ? reject(err) : resolve(result));
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
- // https://esbuild.github.io/plugins/#resolve-callbacks
32
- exports.default = (options = {}) => {
33
- return {
34
- name: 'alias',
35
- setup({ onResolve }) {
36
- const keys = (0, sortByAffix_1.sortByAffix)({ arr: Object.keys(options), affix: '$' });
37
- keys.forEach((key) => {
38
- let value = options[key];
39
- let filter;
40
- if (key.endsWith('$')) {
41
- filter = new RegExp(`^${key}`);
42
- }
43
- else {
44
- filter = new RegExp(`^${key}$`);
45
- }
46
- onResolve({ filter: filter }, (args) => __awaiter(this, void 0, void 0, function* () {
47
- const path = yield resolve(args.importer, args.path.replace(filter, value));
48
- return {
49
- path,
50
- };
51
- }));
52
- if (!key.endsWith('/') &&
53
- (0, fs_1.existsSync)(value) &&
54
- (0, fs_1.statSync)(value).isDirectory()) {
55
- const filter = new RegExp(`^${addSlashAffix(key)}`);
56
- onResolve({ filter }, (args) => __awaiter(this, void 0, void 0, function* () {
57
- const path = yield resolve(args.importer, args.path.replace(filter, addSlashAffix(value)));
58
- return {
59
- path,
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
- if (key.endsWith('/')) {
69
- return key;
70
- }
71
- return `${key}/`;
92
+ if (key.endsWith("/")) {
93
+ return key;
94
+ }
95
+ return `${key}/`;
72
96
  }
@@ -1,3 +1,3 @@
1
1
  import { Plugin } from '@umijs/bundler-utils/compiled/esbuild';
2
- declare const _default: (options?: Record<string, string> | undefined) => Plugin;
2
+ declare const _default: (options?: Record<string, string>) => Plugin;
3
3
  export default _default;