@modern-js/module-tools 2.35.1 → 2.37.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/dist/build.js +43 -16
- package/dist/builder/build.d.ts +0 -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 +75 -60
- 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 +286 -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 +18 -0
- package/dist/builder/esbuild/resolve.js +140 -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 +223 -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 +130 -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.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.js +69 -36
- 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.d.ts +4 -4
- 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 +98 -64
- 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 +57 -37
- package/dist/utils/tspath.js +114 -0
- package/package.json +61 -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,268 @@
|
|
|
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 esbuild_exports = {};
|
|
30
|
+
__export(esbuild_exports, {
|
|
31
|
+
EsbuildCompiler: () => EsbuildCompiler,
|
|
32
|
+
createCompiler: () => createCompiler
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(esbuild_exports);
|
|
35
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
36
|
+
var import_esbuild = require("esbuild");
|
|
37
|
+
var tapable = __toESM(require("tapable"));
|
|
38
|
+
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_utils2 = require("../../utils");
|
|
40
|
+
var import_feature = require("../feature");
|
|
41
|
+
var import_build = require("../../constants/build");
|
|
42
|
+
var import_adapter = require("./adapter");
|
|
43
|
+
var import_transform = require("./transform");
|
|
44
|
+
var import_sourcemap = require("./sourcemap");
|
|
45
|
+
var import_hook = require("./hook");
|
|
46
|
+
var import_resolve = require("./resolve");
|
|
47
|
+
var import_watch = require("./watch");
|
|
48
|
+
class EsbuildCompiler {
|
|
49
|
+
async init() {
|
|
50
|
+
if (this.context.watch) {
|
|
51
|
+
(0, import_watch.initWatcher)(this);
|
|
52
|
+
}
|
|
53
|
+
const internal = await (0, import_feature.getInternalList)(this.context);
|
|
54
|
+
const user = this.config.hooks;
|
|
55
|
+
this.hookList = [
|
|
56
|
+
...user,
|
|
57
|
+
...internal
|
|
58
|
+
];
|
|
59
|
+
await Promise.all(this.hookList.map((item) => item.apply(this)));
|
|
60
|
+
}
|
|
61
|
+
addWatchFile(id) {
|
|
62
|
+
if (!this.watchedFiles.has(id)) {
|
|
63
|
+
var _this_watcher_add, _this_watcher;
|
|
64
|
+
(_this_watcher = this.watcher) === null || _this_watcher === void 0 ? void 0 : (_this_watcher_add = _this_watcher.add) === null || _this_watcher_add === void 0 ? void 0 : _this_watcher_add.call(_this_watcher, id);
|
|
65
|
+
this.watchedFiles.add(id);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
convertConfigToEsbuild(config) {
|
|
69
|
+
const { input, buildType, define, target, sourceMap, platform, splitting, outDir, sourceDir, minify, jsx, esbuildOptions, format, asset, tsconfig, banner, footer } = config;
|
|
70
|
+
const bundle = buildType === "bundle";
|
|
71
|
+
const entryNames = bundle ? "[name]" : "[dir]/[name]";
|
|
72
|
+
const absWorkingDir = this.context.root;
|
|
73
|
+
let esbuildFormat = format === "umd" ? "esm" : format;
|
|
74
|
+
if (bundle && format === "cjs" && splitting) {
|
|
75
|
+
esbuildFormat = "esm";
|
|
76
|
+
}
|
|
77
|
+
const esbuildTarget = target === "es5" ? void 0 : target;
|
|
78
|
+
const jsExtensions = [
|
|
79
|
+
".jsx",
|
|
80
|
+
".tsx",
|
|
81
|
+
".js",
|
|
82
|
+
".ts",
|
|
83
|
+
".json"
|
|
84
|
+
];
|
|
85
|
+
const buildOptions = {
|
|
86
|
+
banner: import_utils.lodash.pick(banner, [
|
|
87
|
+
"js",
|
|
88
|
+
"css"
|
|
89
|
+
]),
|
|
90
|
+
footer: import_utils.lodash.pick(footer, [
|
|
91
|
+
"js",
|
|
92
|
+
"css"
|
|
93
|
+
]),
|
|
94
|
+
entryPoints: input,
|
|
95
|
+
metafile: true,
|
|
96
|
+
define,
|
|
97
|
+
bundle: buildType === "bundle",
|
|
98
|
+
format: esbuildFormat,
|
|
99
|
+
target: esbuildTarget,
|
|
100
|
+
sourcemap: sourceMap ? "external" : false,
|
|
101
|
+
resolveExtensions: jsExtensions,
|
|
102
|
+
splitting,
|
|
103
|
+
charset: "utf8",
|
|
104
|
+
logLimit: 5,
|
|
105
|
+
absWorkingDir,
|
|
106
|
+
platform,
|
|
107
|
+
tsconfig: import_utils.fs.existsSync(tsconfig) ? tsconfig : void 0,
|
|
108
|
+
write: false,
|
|
109
|
+
logLevel: "silent",
|
|
110
|
+
outdir: outDir,
|
|
111
|
+
outbase: sourceDir,
|
|
112
|
+
entryNames,
|
|
113
|
+
plugins: [
|
|
114
|
+
(0, import_adapter.adapterPlugin)(this)
|
|
115
|
+
],
|
|
116
|
+
minify: minify === "esbuild",
|
|
117
|
+
jsx,
|
|
118
|
+
supported: {
|
|
119
|
+
"dynamic-import": buildType === "bundle" || format !== "cjs"
|
|
120
|
+
},
|
|
121
|
+
assetNames: `${asset.path}/[name].[hash]`
|
|
122
|
+
};
|
|
123
|
+
return esbuildOptions(buildOptions);
|
|
124
|
+
}
|
|
125
|
+
getTransformContext(path) {
|
|
126
|
+
if (this.transformContextMap.has(path)) {
|
|
127
|
+
return this.transformContextMap.get(path);
|
|
128
|
+
}
|
|
129
|
+
const context2 = new import_transform.TransformContext(Boolean(this.context.config.sourceMap));
|
|
130
|
+
this.transformContextMap.set(path, context2);
|
|
131
|
+
return context2;
|
|
132
|
+
}
|
|
133
|
+
getSourcemapContext(path) {
|
|
134
|
+
if (this.sourcemapContextMap.has(path)) {
|
|
135
|
+
return this.sourcemapContextMap.get(path);
|
|
136
|
+
}
|
|
137
|
+
const context2 = new import_sourcemap.SourcemapContext(Boolean(this.context.config.sourceMap));
|
|
138
|
+
this.sourcemapContextMap.set(path, context2);
|
|
139
|
+
return context2;
|
|
140
|
+
}
|
|
141
|
+
emitAsset(name, chunk) {
|
|
142
|
+
if (typeof chunk === "string") {
|
|
143
|
+
this.outputChunk.set(name, {
|
|
144
|
+
type: "asset",
|
|
145
|
+
contents: chunk,
|
|
146
|
+
fileName: name
|
|
147
|
+
});
|
|
148
|
+
} else {
|
|
149
|
+
this.outputChunk.set(name, chunk);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async close() {
|
|
153
|
+
try {
|
|
154
|
+
var _this_instance, _this_instance1;
|
|
155
|
+
await ((_this_instance = this.instance) === null || _this_instance === void 0 ? void 0 : _this_instance.cancel());
|
|
156
|
+
await ((_this_instance1 = this.instance) === null || _this_instance1 === void 0 ? void 0 : _this_instance1.dispose());
|
|
157
|
+
} catch (err) {
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async build() {
|
|
161
|
+
const { buildOptions, context: { watch } } = this;
|
|
162
|
+
try {
|
|
163
|
+
if (watch) {
|
|
164
|
+
this.instance = await (0, import_esbuild.context)(buildOptions);
|
|
165
|
+
this.result = await this.instance.rebuild();
|
|
166
|
+
} else {
|
|
167
|
+
this.result = await (0, import_esbuild.build)(buildOptions);
|
|
168
|
+
}
|
|
169
|
+
if (this.result.warnings.length) {
|
|
170
|
+
const warnings = this.result.warnings.filter((warning) => {
|
|
171
|
+
if (warning.text.includes(`This call to "require" will not be bundled because`) || warning.text.includes(`Indirect calls to "require" will not be bundled`) || warning.text.includes(`Converting "require" to "esm" is currently not supported`)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
});
|
|
176
|
+
const messages = await (0, import_esbuild.formatMessages)(warnings, {
|
|
177
|
+
kind: "warning"
|
|
178
|
+
});
|
|
179
|
+
messages.forEach((m) => {
|
|
180
|
+
import_utils.logger.warn(m);
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
} catch (error) {
|
|
184
|
+
if (watch) {
|
|
185
|
+
var _this_instance;
|
|
186
|
+
(_this_instance = this.instance) === null || _this_instance === void 0 ? void 0 : _this_instance.cancel();
|
|
187
|
+
import_utils.logger.error(error);
|
|
188
|
+
} else {
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
async reBuild(type, config) {
|
|
194
|
+
const { instance } = this;
|
|
195
|
+
try {
|
|
196
|
+
const start = Date.now();
|
|
197
|
+
if (type === "link") {
|
|
198
|
+
await this.build();
|
|
199
|
+
} else {
|
|
200
|
+
this.result = await (instance === null || instance === void 0 ? void 0 : instance.rebuild());
|
|
201
|
+
}
|
|
202
|
+
const time = import_utils.chalk.gray(`(${Date.now() - start}ms)`);
|
|
203
|
+
import_utils.logger.success((0, import_utils2.withLogTitle)(config.buildType, `Build ${config.format},${config.target} files ${time}`));
|
|
204
|
+
} catch (error) {
|
|
205
|
+
import_utils.logger.error(error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
constructor(context2) {
|
|
209
|
+
(0, import_define_property._)(this, "instance", void 0);
|
|
210
|
+
(0, import_define_property._)(this, "result", void 0);
|
|
211
|
+
(0, import_define_property._)(this, "hookList", void 0);
|
|
212
|
+
(0, import_define_property._)(this, "reBuildCount", void 0);
|
|
213
|
+
(0, import_define_property._)(this, "buildOptions", void 0);
|
|
214
|
+
(0, import_define_property._)(this, "context", void 0);
|
|
215
|
+
(0, import_define_property._)(this, "config", void 0);
|
|
216
|
+
(0, import_define_property._)(this, "hooks", void 0);
|
|
217
|
+
(0, import_define_property._)(this, "api", void 0);
|
|
218
|
+
(0, import_define_property._)(this, "outputChunk", /* @__PURE__ */ new Map());
|
|
219
|
+
(0, import_define_property._)(this, "watchedFiles", /* @__PURE__ */ new Set());
|
|
220
|
+
(0, import_define_property._)(this, "css_resolve", void 0);
|
|
221
|
+
(0, import_define_property._)(this, "node_resolve", void 0);
|
|
222
|
+
(0, import_define_property._)(this, "watcher", void 0);
|
|
223
|
+
(0, import_define_property._)(this, "virtualModule", /* @__PURE__ */ new Map());
|
|
224
|
+
(0, import_define_property._)(this, "transformContextMap", /* @__PURE__ */ new Map());
|
|
225
|
+
(0, import_define_property._)(this, "sourcemapContextMap", /* @__PURE__ */ new Map());
|
|
226
|
+
const { api, config, root } = context2;
|
|
227
|
+
this.reBuildCount = 0;
|
|
228
|
+
this.context = context2;
|
|
229
|
+
this.api = api;
|
|
230
|
+
this.config = config;
|
|
231
|
+
this.buildOptions = this.convertConfigToEsbuild(config);
|
|
232
|
+
this.hooks = Object.freeze({
|
|
233
|
+
load: new tapable.AsyncSeriesBailHook([
|
|
234
|
+
"loadArgs"
|
|
235
|
+
]),
|
|
236
|
+
transform: (0, import_hook.createTransformHook)(this),
|
|
237
|
+
renderChunk: (0, import_hook.createRenderChunkHook)(this)
|
|
238
|
+
});
|
|
239
|
+
const resolveOptions = {
|
|
240
|
+
root,
|
|
241
|
+
platform: config.platform,
|
|
242
|
+
alias: config.alias,
|
|
243
|
+
tsconfig: config.tsconfig,
|
|
244
|
+
mainFields: config.resolve.mainFields
|
|
245
|
+
};
|
|
246
|
+
this.css_resolve = (0, import_resolve.createCssResolver)({
|
|
247
|
+
...resolveOptions,
|
|
248
|
+
resolveType: "css",
|
|
249
|
+
extensions: import_build.cssExtensions,
|
|
250
|
+
preferRelative: true
|
|
251
|
+
});
|
|
252
|
+
this.node_resolve = (0, import_resolve.createJsResolver)({
|
|
253
|
+
...resolveOptions,
|
|
254
|
+
resolveType: "js",
|
|
255
|
+
extensions: config.resolve.jsExtensions
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
const createCompiler = async (context2) => {
|
|
260
|
+
const compiler = new EsbuildCompiler(context2);
|
|
261
|
+
await compiler.init();
|
|
262
|
+
return compiler;
|
|
263
|
+
};
|
|
264
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
265
|
+
0 && (module.exports = {
|
|
266
|
+
EsbuildCompiler,
|
|
267
|
+
createCompiler
|
|
268
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ImportKind, Platform } from 'esbuild';
|
|
2
|
+
/**
|
|
3
|
+
* supports require js plugin in less file
|
|
4
|
+
*/
|
|
5
|
+
export declare const cssExtensions: string[];
|
|
6
|
+
export declare const createJsResolver: (options: ResolverOptions) => (id: string, dir: string, kind?: ImportKind) => string | false;
|
|
7
|
+
export declare const createCssResolver: (options: ResolverOptions) => (id: string, dir: string, kind?: ImportKind) => string;
|
|
8
|
+
interface ResolverOptions {
|
|
9
|
+
platform: Platform;
|
|
10
|
+
resolveType: 'js' | 'css';
|
|
11
|
+
extensions: string[];
|
|
12
|
+
root: string;
|
|
13
|
+
alias: Record<string, string>;
|
|
14
|
+
tsconfig: string;
|
|
15
|
+
mainFields: string[];
|
|
16
|
+
preferRelative?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,140 @@
|
|
|
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 resolve_exports = {};
|
|
30
|
+
__export(resolve_exports, {
|
|
31
|
+
createCssResolver: () => createCssResolver,
|
|
32
|
+
createJsResolver: () => createJsResolver,
|
|
33
|
+
cssExtensions: () => cssExtensions
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(resolve_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"));
|
|
37
|
+
var import_enhanced_resolve = require("enhanced-resolve");
|
|
38
|
+
var import_tsconfig_paths_webpack_plugin = __toESM(require("tsconfig-paths-webpack-plugin"));
|
|
39
|
+
const cssExtensions = [
|
|
40
|
+
".less",
|
|
41
|
+
".css",
|
|
42
|
+
".sass",
|
|
43
|
+
".scss",
|
|
44
|
+
".js"
|
|
45
|
+
];
|
|
46
|
+
function createEnhancedResolve(options) {
|
|
47
|
+
const plugins = [];
|
|
48
|
+
const { tsconfig } = options;
|
|
49
|
+
if (import_fs.default.existsSync(tsconfig)) {
|
|
50
|
+
plugins.push(new import_tsconfig_paths_webpack_plugin.default({
|
|
51
|
+
configFile: tsconfig
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
const resolveOptions = {
|
|
55
|
+
aliasFields: options.platform === "browser" ? [
|
|
56
|
+
"browser"
|
|
57
|
+
] : [],
|
|
58
|
+
FileSystem: new import_enhanced_resolve.CachedInputFileSystem(import_fs.default, 4e3),
|
|
59
|
+
mainFields: options.mainFields,
|
|
60
|
+
mainFiles: [
|
|
61
|
+
"index"
|
|
62
|
+
],
|
|
63
|
+
extensions: options.extensions,
|
|
64
|
+
preferRelative: options.preferRelative,
|
|
65
|
+
addMatchAll: false,
|
|
66
|
+
plugins,
|
|
67
|
+
alias: options.alias
|
|
68
|
+
};
|
|
69
|
+
const resolveSync = (dir, id) => import_enhanced_resolve.create.sync({
|
|
70
|
+
...resolveOptions,
|
|
71
|
+
conditionNames: [
|
|
72
|
+
options.platform,
|
|
73
|
+
"require",
|
|
74
|
+
"module"
|
|
75
|
+
]
|
|
76
|
+
})(dir, id);
|
|
77
|
+
const esmResolveSync = (dir, id) => import_enhanced_resolve.create.sync({
|
|
78
|
+
...resolveOptions,
|
|
79
|
+
conditionNames: [
|
|
80
|
+
options.platform,
|
|
81
|
+
"import",
|
|
82
|
+
"module"
|
|
83
|
+
]
|
|
84
|
+
})(dir, id);
|
|
85
|
+
return {
|
|
86
|
+
resolveSync,
|
|
87
|
+
esmResolveSync
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const createJsResolver = (options) => {
|
|
91
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
92
|
+
const { resolveSync, esmResolveSync } = createEnhancedResolve(options);
|
|
93
|
+
const resolver = (id, dir, kind) => {
|
|
94
|
+
const cacheKey = id + dir + (kind || "");
|
|
95
|
+
const cacheResult = resolveCache.get(cacheKey);
|
|
96
|
+
if (cacheResult) {
|
|
97
|
+
return cacheResult;
|
|
98
|
+
}
|
|
99
|
+
let result;
|
|
100
|
+
if (kind === "import-statement" || kind === "dynamic-import") {
|
|
101
|
+
result = esmResolveSync(dir, id);
|
|
102
|
+
} else {
|
|
103
|
+
result = resolveSync(dir, id);
|
|
104
|
+
}
|
|
105
|
+
if (result) {
|
|
106
|
+
resolveCache.set(cacheKey, result);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
return resolver;
|
|
111
|
+
};
|
|
112
|
+
const createCssResolver = (options) => {
|
|
113
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
114
|
+
const { resolveSync } = createEnhancedResolve(options);
|
|
115
|
+
const resolver = (id, dir, kind) => {
|
|
116
|
+
const cacheKey = id + dir + (kind || "");
|
|
117
|
+
const cacheResult = resolveCache.get(cacheKey);
|
|
118
|
+
if (cacheResult) {
|
|
119
|
+
return cacheResult;
|
|
120
|
+
}
|
|
121
|
+
let result;
|
|
122
|
+
try {
|
|
123
|
+
result = resolveSync(dir, id);
|
|
124
|
+
} catch (err) {
|
|
125
|
+
result = resolveSync(dir, id.replace(/^~/, ""));
|
|
126
|
+
}
|
|
127
|
+
if (!result) {
|
|
128
|
+
throw new Error(`can not resolve ${id} from ${dir}`);
|
|
129
|
+
}
|
|
130
|
+
resolveCache.set(cacheKey, result);
|
|
131
|
+
return result;
|
|
132
|
+
};
|
|
133
|
+
return resolver;
|
|
134
|
+
};
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
createCssResolver,
|
|
138
|
+
createJsResolver,
|
|
139
|
+
cssExtensions
|
|
140
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SourceMap, ISourcemapContext } from '../../types';
|
|
2
|
+
export declare class SourcemapContext implements ISourcemapContext {
|
|
3
|
+
private enableSourceMap?;
|
|
4
|
+
private sourceMapChain;
|
|
5
|
+
private sourceMapDirty;
|
|
6
|
+
private cachedInlineSourceMap;
|
|
7
|
+
private cachedSourceMap;
|
|
8
|
+
private pluginIdMap;
|
|
9
|
+
constructor(enableSourceMap?: boolean | undefined);
|
|
10
|
+
private markSourceMapStatus;
|
|
11
|
+
addSourceMap(pluginId: number, map?: SourceMap): void;
|
|
12
|
+
getInlineSourceMap(): string;
|
|
13
|
+
getSourceMap(): SourceMap | undefined;
|
|
14
|
+
getSourceMapChain(): SourceMap[];
|
|
15
|
+
genPluginId(name: string): number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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 sourcemap_exports = {};
|
|
20
|
+
__export(sourcemap_exports, {
|
|
21
|
+
SourcemapContext: () => SourcemapContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sourcemap_exports);
|
|
24
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
25
|
+
var import_utils = require("../../utils");
|
|
26
|
+
class SourcemapContext {
|
|
27
|
+
markSourceMapStatus(dirty) {
|
|
28
|
+
this.sourceMapDirty = dirty;
|
|
29
|
+
}
|
|
30
|
+
addSourceMap(pluginId, map) {
|
|
31
|
+
if (this.enableSourceMap && this.sourceMapChain[pluginId] !== map) {
|
|
32
|
+
this.sourceMapChain[pluginId] = map;
|
|
33
|
+
this.markSourceMapStatus(true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getInlineSourceMap() {
|
|
37
|
+
if (this.sourceMapDirty && this.enableSourceMap) {
|
|
38
|
+
const effectMapList = this.getSourceMapChain().reverse();
|
|
39
|
+
if (effectMapList.length > 0) {
|
|
40
|
+
this.cachedInlineSourceMap = (0, import_utils.mergeMaps)(effectMapList).toComment();
|
|
41
|
+
} else {
|
|
42
|
+
this.cachedInlineSourceMap = "";
|
|
43
|
+
}
|
|
44
|
+
this.markSourceMapStatus(false);
|
|
45
|
+
}
|
|
46
|
+
return this.cachedInlineSourceMap;
|
|
47
|
+
}
|
|
48
|
+
getSourceMap() {
|
|
49
|
+
if (this.sourceMapDirty && this.enableSourceMap) {
|
|
50
|
+
const effectMapList = this.getSourceMapChain().reverse();
|
|
51
|
+
if (effectMapList.length > 0) {
|
|
52
|
+
this.cachedSourceMap = (0, import_utils.mergeMaps)(effectMapList).toMap();
|
|
53
|
+
}
|
|
54
|
+
this.markSourceMapStatus(false);
|
|
55
|
+
}
|
|
56
|
+
return this.cachedSourceMap;
|
|
57
|
+
}
|
|
58
|
+
getSourceMapChain() {
|
|
59
|
+
return this.sourceMapChain.filter((m) => Boolean(m && m.mappings));
|
|
60
|
+
}
|
|
61
|
+
genPluginId(name) {
|
|
62
|
+
if (this.pluginIdMap.has(name)) {
|
|
63
|
+
return this.pluginIdMap.get(name);
|
|
64
|
+
}
|
|
65
|
+
const id = this.sourceMapChain.length;
|
|
66
|
+
this.pluginIdMap.set(name, id);
|
|
67
|
+
return id;
|
|
68
|
+
}
|
|
69
|
+
constructor(enableSourceMap) {
|
|
70
|
+
(0, import_define_property._)(this, "enableSourceMap", void 0);
|
|
71
|
+
(0, import_define_property._)(this, "sourceMapChain", void 0);
|
|
72
|
+
(0, import_define_property._)(this, "sourceMapDirty", void 0);
|
|
73
|
+
(0, import_define_property._)(this, "cachedInlineSourceMap", void 0);
|
|
74
|
+
(0, import_define_property._)(this, "cachedSourceMap", void 0);
|
|
75
|
+
(0, import_define_property._)(this, "pluginIdMap", void 0);
|
|
76
|
+
this.enableSourceMap = enableSourceMap;
|
|
77
|
+
this.sourceMapChain = [];
|
|
78
|
+
this.sourceMapDirty = false;
|
|
79
|
+
this.cachedInlineSourceMap = "";
|
|
80
|
+
this.pluginIdMap = /* @__PURE__ */ new Map();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
SourcemapContext
|
|
86
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ITransformContext, CacheValue } from '../../types';
|
|
2
|
+
import { SourcemapContext } from './sourcemap';
|
|
3
|
+
export declare class TransformContext extends SourcemapContext implements ITransformContext {
|
|
4
|
+
private cachedTransformResult;
|
|
5
|
+
addTransformResult(pluginId: number, result: CacheValue): void;
|
|
6
|
+
getValidCache(pluginId: number, code: string): CacheValue | undefined;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 transform_exports = {};
|
|
20
|
+
__export(transform_exports, {
|
|
21
|
+
TransformContext: () => TransformContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(transform_exports);
|
|
24
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
25
|
+
var import_sourcemap = require("./sourcemap");
|
|
26
|
+
class TransformContext extends import_sourcemap.SourcemapContext {
|
|
27
|
+
addTransformResult(pluginId, result) {
|
|
28
|
+
this.cachedTransformResult.set(pluginId, result);
|
|
29
|
+
this.addSourceMap(pluginId, result.map);
|
|
30
|
+
}
|
|
31
|
+
getValidCache(pluginId, code) {
|
|
32
|
+
const cache = this.cachedTransformResult.get(pluginId);
|
|
33
|
+
if (cache && cache.originCode === code) {
|
|
34
|
+
return cache;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
constructor(...args) {
|
|
38
|
+
super(...args);
|
|
39
|
+
(0, import_define_property._)(this, "cachedTransformResult", /* @__PURE__ */ new Map());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
TransformContext
|
|
45
|
+
});
|