@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.
Files changed (223) hide show
  1. package/dist/build.js +43 -16
  2. package/dist/builder/build.d.ts +0 -10
  3. package/dist/builder/build.js +96 -208
  4. package/dist/builder/clear.d.ts +1 -4
  5. package/dist/builder/clear.js +32 -28
  6. package/dist/builder/copy.js +75 -60
  7. package/dist/builder/dts/index.js +27 -19
  8. package/dist/builder/dts/rollup.d.ts +6 -14
  9. package/dist/builder/dts/rollup.js +60 -37
  10. package/dist/builder/dts/tsc.d.ts +3 -2
  11. package/dist/builder/dts/tsc.js +50 -37
  12. package/dist/builder/esbuild/adapter.d.ts +3 -0
  13. package/dist/builder/esbuild/adapter.js +286 -0
  14. package/dist/builder/esbuild/hook.d.ts +4 -0
  15. package/dist/builder/esbuild/hook.js +103 -0
  16. package/dist/builder/esbuild/index.d.ts +35 -0
  17. package/dist/builder/esbuild/index.js +268 -0
  18. package/dist/builder/esbuild/resolve.d.ts +18 -0
  19. package/dist/builder/esbuild/resolve.js +140 -0
  20. package/dist/builder/esbuild/sourcemap.d.ts +16 -0
  21. package/dist/builder/esbuild/sourcemap.js +86 -0
  22. package/dist/builder/esbuild/transform.d.ts +7 -0
  23. package/dist/builder/esbuild/transform.js +45 -0
  24. package/dist/builder/esbuild/watch.d.ts +2 -0
  25. package/dist/builder/esbuild/watch.js +115 -0
  26. package/dist/builder/esbuild/write-file.d.ts +2 -0
  27. package/dist/builder/esbuild/write-file.js +89 -0
  28. package/dist/builder/feature/asset.d.ts +19 -0
  29. package/dist/builder/feature/asset.js +149 -0
  30. package/dist/builder/feature/format-cjs.d.ts +5 -0
  31. package/dist/builder/feature/format-cjs.js +53 -0
  32. package/dist/builder/feature/index.d.ts +2 -0
  33. package/dist/builder/feature/index.js +74 -0
  34. package/dist/builder/feature/json.d.ts +5 -0
  35. package/dist/builder/feature/json.js +47 -0
  36. package/dist/builder/feature/redirect.d.ts +5 -0
  37. package/dist/builder/feature/redirect.js +223 -0
  38. package/dist/builder/feature/style/index.d.ts +5 -0
  39. package/dist/builder/feature/style/index.js +94 -0
  40. package/dist/builder/feature/style/lessAliasPlugin.d.ts +12 -0
  41. package/dist/builder/feature/style/lessAliasPlugin.js +70 -0
  42. package/dist/builder/feature/style/lessRender.d.ts +2 -0
  43. package/dist/builder/feature/style/lessRender.js +64 -0
  44. package/dist/builder/feature/style/postcssTransformer.d.ts +6 -0
  45. package/dist/builder/feature/style/postcssTransformer.js +95 -0
  46. package/dist/builder/feature/style/postcssUrlPlugin.d.ts +6 -0
  47. package/dist/builder/feature/style/postcssUrlPlugin.js +58 -0
  48. package/dist/builder/feature/style/sassRender.d.ts +2 -0
  49. package/dist/builder/feature/style/sassRender.js +85 -0
  50. package/dist/builder/feature/style/transformStyle.d.ts +13 -0
  51. package/dist/builder/feature/style/transformStyle.js +101 -0
  52. package/dist/builder/feature/style/utils.d.ts +18 -0
  53. package/dist/builder/feature/style/utils.js +130 -0
  54. package/dist/builder/feature/swc.d.ts +9 -0
  55. package/dist/builder/feature/swc.js +170 -0
  56. package/dist/builder/feature/terser.d.ts +5 -0
  57. package/dist/builder/feature/terser.js +83 -0
  58. package/dist/builder/index.js +59 -28
  59. package/dist/builder/platform.js +38 -23
  60. package/dist/cli.js +58 -29
  61. package/dist/command.js +62 -38
  62. package/dist/config/defineConfig.js +25 -17
  63. package/dist/config/legacySchema.js +35 -32
  64. package/dist/config/merge.js +69 -36
  65. package/dist/config/normalize.js +63 -46
  66. package/dist/config/schema.d.ts +48 -0
  67. package/dist/config/schema.js +53 -34
  68. package/dist/config/transformLegacyConfig.js +67 -61
  69. package/dist/config/valid.d.ts +2 -2
  70. package/dist/config/valid.js +44 -21
  71. package/dist/constants/build.d.ts +5 -1
  72. package/dist/constants/build.js +88 -46
  73. package/dist/constants/color.js +27 -20
  74. package/dist/constants/dts.js +27 -20
  75. package/dist/constants/file.d.ts +2 -2
  76. package/dist/constants/file.js +48 -25
  77. package/dist/constants/legacy-preset.js +45 -32
  78. package/dist/constants/loader.d.ts +2 -0
  79. package/dist/constants/loader.js +53 -0
  80. package/dist/constants/log.d.ts +0 -8
  81. package/dist/constants/log.js +27 -41
  82. package/dist/constants/preset.d.ts +4 -4
  83. package/dist/constants/preset.js +55 -62
  84. package/dist/debug.d.ts +4 -0
  85. package/dist/debug.js +37 -0
  86. package/dist/dev.js +42 -25
  87. package/dist/error.js +49 -42
  88. package/dist/hooks/build.d.ts +1 -2
  89. package/dist/hooks/build.js +36 -28
  90. package/dist/hooks/dev.js +32 -17
  91. package/dist/hooks/index.d.ts +1 -1
  92. package/dist/hooks/index.js +31 -16
  93. package/dist/hooks/misc.d.ts +5 -2
  94. package/dist/hooks/misc.js +31 -12
  95. package/dist/index.d.ts +2 -1
  96. package/dist/index.js +39 -32
  97. package/dist/locale/en.js +32 -17
  98. package/dist/locale/index.d.ts +2 -1
  99. package/dist/locale/index.js +31 -24
  100. package/dist/locale/zh.js +32 -17
  101. package/dist/plugins.js +28 -13
  102. package/dist/types/color.js +15 -5
  103. package/dist/types/command.d.ts +3 -3
  104. package/dist/types/command.js +15 -5
  105. package/dist/types/config/copy.js +15 -5
  106. package/dist/types/config/dev.js +15 -5
  107. package/dist/types/config/index.d.ts +87 -52
  108. package/dist/types/config/index.js +24 -6
  109. package/dist/types/config/style.d.ts +58 -6
  110. package/dist/types/config/style.js +15 -5
  111. package/dist/types/context.js +15 -5
  112. package/dist/types/dts.d.ts +14 -3
  113. package/dist/types/dts.js +15 -5
  114. package/dist/types/esbuild.d.ts +107 -0
  115. package/dist/types/esbuild.js +32 -0
  116. package/dist/types/hooks.js +15 -5
  117. package/dist/types/index.d.ts +1 -0
  118. package/dist/types/index.js +32 -11
  119. package/dist/types/legacyConfig/index.js +15 -5
  120. package/dist/types/legacyConfig/output.d.ts +4 -4
  121. package/dist/types/legacyConfig/output.js +15 -5
  122. package/dist/types/legacyConfig/source.js +15 -5
  123. package/dist/types/legacyConfig/tools.js +15 -5
  124. package/dist/utils/assert.d.ts +5 -0
  125. package/dist/utils/assert.js +50 -0
  126. package/dist/utils/builder.d.ts +10 -14
  127. package/dist/utils/builder.js +59 -59
  128. package/dist/utils/common.d.ts +1 -1
  129. package/dist/utils/common.js +25 -17
  130. package/dist/utils/dts.d.ts +26 -9
  131. package/dist/utils/dts.js +98 -64
  132. package/dist/utils/hash.d.ts +2 -0
  133. package/dist/utils/hash.js +31 -0
  134. package/dist/utils/index.d.ts +11 -0
  135. package/dist/utils/index.js +42 -0
  136. package/dist/utils/input.js +47 -24
  137. package/dist/utils/log.d.ts +1 -2
  138. package/dist/utils/log.js +36 -20
  139. package/dist/utils/map.d.ts +13 -0
  140. package/dist/utils/map.js +58 -0
  141. package/dist/utils/onExit.js +35 -11
  142. package/dist/utils/print.d.ts +2 -2
  143. package/dist/utils/print.js +52 -49
  144. package/dist/utils/style.d.ts +5 -23
  145. package/dist/utils/style.js +57 -37
  146. package/dist/utils/tspath.js +114 -0
  147. package/package.json +61 -50
  148. package/vitest.config.ts +20 -0
  149. package/dist/build.js.map +0 -1
  150. package/dist/builder/build.js.map +0 -1
  151. package/dist/builder/clear.js.map +0 -1
  152. package/dist/builder/copy.js.map +0 -1
  153. package/dist/builder/dts/index.js.map +0 -1
  154. package/dist/builder/dts/rollup.js.map +0 -1
  155. package/dist/builder/dts/tsc.js.map +0 -1
  156. package/dist/builder/index.js.map +0 -1
  157. package/dist/builder/platform.js.map +0 -1
  158. package/dist/cli.js.map +0 -1
  159. package/dist/command.js.map +0 -1
  160. package/dist/config/defineConfig.js.map +0 -1
  161. package/dist/config/legacySchema.js.map +0 -1
  162. package/dist/config/merge.js.map +0 -1
  163. package/dist/config/normalize.js.map +0 -1
  164. package/dist/config/schema.js.map +0 -1
  165. package/dist/config/transformLegacyConfig.js.map +0 -1
  166. package/dist/config/valid.js.map +0 -1
  167. package/dist/constants/build.js.map +0 -1
  168. package/dist/constants/color.js.map +0 -1
  169. package/dist/constants/dts.js.map +0 -1
  170. package/dist/constants/file.js.map +0 -1
  171. package/dist/constants/legacy-preset.js.map +0 -1
  172. package/dist/constants/log.js.map +0 -1
  173. package/dist/constants/preset.js.map +0 -1
  174. package/dist/dev.js.map +0 -1
  175. package/dist/error.js.map +0 -1
  176. package/dist/hooks/build.js.map +0 -1
  177. package/dist/hooks/dev.js.map +0 -1
  178. package/dist/hooks/index.js.map +0 -1
  179. package/dist/hooks/misc.js.map +0 -1
  180. package/dist/index.js.map +0 -1
  181. package/dist/locale/en.js.map +0 -1
  182. package/dist/locale/index.js.map +0 -1
  183. package/dist/locale/zh.js.map +0 -1
  184. package/dist/plugins.js.map +0 -1
  185. package/dist/types/color.js.map +0 -1
  186. package/dist/types/command.js.map +0 -1
  187. package/dist/types/config/copy.js.map +0 -1
  188. package/dist/types/config/dev.js.map +0 -1
  189. package/dist/types/config/index.js.map +0 -1
  190. package/dist/types/config/style.js.map +0 -1
  191. package/dist/types/context.js.map +0 -1
  192. package/dist/types/dts.js.map +0 -1
  193. package/dist/types/hooks.js.map +0 -1
  194. package/dist/types/index.js.map +0 -1
  195. package/dist/types/legacyConfig/index.js.map +0 -1
  196. package/dist/types/legacyConfig/output.js.map +0 -1
  197. package/dist/types/legacyConfig/source.js.map +0 -1
  198. package/dist/types/legacyConfig/tools.js.map +0 -1
  199. package/dist/types/utils.d.ts +0 -5
  200. package/dist/types/utils.js +0 -4
  201. package/dist/utils/builder.js.map +0 -1
  202. package/dist/utils/common.js.map +0 -1
  203. package/dist/utils/context.d.ts +0 -7
  204. package/dist/utils/context.js +0 -23
  205. package/dist/utils/context.js.map +0 -1
  206. package/dist/utils/dts.js.map +0 -1
  207. package/dist/utils/input.js.map +0 -1
  208. package/dist/utils/language.d.ts +0 -1
  209. package/dist/utils/language.js +0 -22
  210. package/dist/utils/language.js.map +0 -1
  211. package/dist/utils/libuild-plugin.d.ts +0 -3
  212. package/dist/utils/libuild-plugin.js +0 -31
  213. package/dist/utils/libuild-plugin.js.map +0 -1
  214. package/dist/utils/log.js.map +0 -1
  215. package/dist/utils/onExit.js.map +0 -1
  216. package/dist/utils/path.d.ts +0 -1
  217. package/dist/utils/path.js +0 -19
  218. package/dist/utils/path.js.map +0 -1
  219. package/dist/utils/print.js.map +0 -1
  220. package/dist/utils/style.js.map +0 -1
  221. package/dist/utils/tspathsTransform.js +0 -91
  222. package/dist/utils/tspathsTransform.js.map +0 -1
  223. /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
@@ -0,0 +1,286 @@
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 adapter_exports = {};
30
+ __export(adapter_exports, {
31
+ adapterPlugin: () => adapterPlugin
32
+ });
33
+ module.exports = __toCommonJS(adapter_exports);
34
+ var import_path = require("path");
35
+ var import_module = __toESM(require("module"));
36
+ var import_utils = require("@modern-js/utils");
37
+ var import_pluginutils = require("@rollup/pluginutils");
38
+ var import_utils2 = require("../../utils");
39
+ var import_loader = require("../../constants/loader");
40
+ var import_debug = require("../../debug");
41
+ var import_write_file = require("./write-file");
42
+ const globalNamespace = "globals";
43
+ const HTTP_PATTERNS = /^(https?:)?\/\//;
44
+ const DATAURL_PATTERNS = /^data:/;
45
+ const HASH_PATTERNS = /#[^#]+$/;
46
+ const DATAURL_JAVASCRIPT_PATTERNS = /^data:text\/javascript/;
47
+ const adapterPlugin = (compiler) => {
48
+ const { context } = compiler;
49
+ const { config, root } = context;
50
+ return {
51
+ name: "esbuild:adapter",
52
+ setup(build) {
53
+ build.onStart(async () => {
54
+ compiler.outputChunk = /* @__PURE__ */ new Map();
55
+ });
56
+ build.onResolve({
57
+ filter: /.*/
58
+ }, async (args) => {
59
+ if (args.kind === "url-token") {
60
+ return {
61
+ path: args.path,
62
+ external: true
63
+ };
64
+ }
65
+ for (const [key] of Object.entries(config.umdGlobals)) {
66
+ if (args.path === key) {
67
+ (0, import_debug.debugResolve)("resolve umdGlobals:", key);
68
+ return {
69
+ path: args.path,
70
+ namespace: globalNamespace
71
+ };
72
+ }
73
+ }
74
+ if (/^node:/.test(args.path)) {
75
+ return {
76
+ path: args.path.slice(5),
77
+ external: true
78
+ };
79
+ }
80
+ if (DATAURL_JAVASCRIPT_PATTERNS.test(args.path)) {
81
+ return {
82
+ path: args.path,
83
+ namespace: "dataurl"
84
+ };
85
+ }
86
+ const isUrl = (source) => HTTP_PATTERNS.test(source) || DATAURL_PATTERNS.test(source) || HASH_PATTERNS.test(source);
87
+ if (isUrl(args.path)) {
88
+ return {
89
+ path: args.path,
90
+ external: true
91
+ };
92
+ }
93
+ const { externals, sideEffects: userSideEffects } = config;
94
+ const regExternal = externals.filter((item) => !(0, import_utils.isString)(item));
95
+ const externalList = externals.filter(import_utils.isString).concat(config.platform === "node" ? import_module.default.builtinModules : []);
96
+ const externalMap = externalList.reduce((map, item) => {
97
+ map.set(item, true);
98
+ return map;
99
+ }, /* @__PURE__ */ new Map());
100
+ const getIsExternal = (name) => {
101
+ if (externalMap.get(name)) {
102
+ return true;
103
+ }
104
+ if (regExternal.some((reg) => reg.test(name))) {
105
+ return true;
106
+ }
107
+ return false;
108
+ };
109
+ const getSideEffects = async (filePath, isExternal2) => {
110
+ let pkgPath = "";
111
+ let sideEffects2 = userSideEffects;
112
+ let moduleSideEffects = true;
113
+ if (typeof userSideEffects === "undefined") {
114
+ let curDir = (0, import_path.dirname)(filePath);
115
+ try {
116
+ while (curDir !== (0, import_path.dirname)(curDir)) {
117
+ if (import_utils.fs.existsSync((0, import_path.resolve)(curDir, "package.json"))) {
118
+ pkgPath = (0, import_path.resolve)(curDir, "package.json");
119
+ break;
120
+ }
121
+ curDir = (0, import_path.dirname)(curDir);
122
+ }
123
+ sideEffects2 = JSON.parse(import_utils.fs.readFileSync(pkgPath, "utf-8")).sideEffects;
124
+ } catch (err) {
125
+ }
126
+ if (!pkgPath) {
127
+ return void 0;
128
+ }
129
+ }
130
+ if (typeof sideEffects2 === "boolean") {
131
+ moduleSideEffects = sideEffects2;
132
+ } else if (Array.isArray(sideEffects2)) {
133
+ moduleSideEffects = (0, import_pluginutils.createFilter)(sideEffects2.map((glob) => {
134
+ if (typeof glob === "string") {
135
+ if (!glob.includes("/")) {
136
+ return `**/${glob}`;
137
+ }
138
+ }
139
+ return glob;
140
+ }), null, pkgPath ? {
141
+ resolve: (0, import_path.dirname)(pkgPath)
142
+ } : void 0)(filePath);
143
+ } else if (typeof sideEffects2 === "function") {
144
+ moduleSideEffects = sideEffects2(filePath, isExternal2);
145
+ }
146
+ return moduleSideEffects;
147
+ };
148
+ const getResultPath = (id, dir2, kind) => {
149
+ return id.endsWith(".css") ? compiler.css_resolve(id, dir2) : compiler.node_resolve(id, dir2, kind);
150
+ };
151
+ const { originalFilePath, rawQuery } = (0, import_utils2.resolvePathAndQuery)(args.path);
152
+ const suffix = (rawQuery !== null && rawQuery !== void 0 ? rawQuery : "").length > 0 ? `?${rawQuery}` : "";
153
+ const isExternal = getIsExternal(originalFilePath);
154
+ var _args_resolveDir;
155
+ const dir = (_args_resolveDir = args.resolveDir) !== null && _args_resolveDir !== void 0 ? _args_resolveDir : args.importer ? (0, import_path.dirname)(args.importer) : root;
156
+ const resultPath = isExternal ? args.path : getResultPath(originalFilePath, dir, args.kind);
157
+ if (resultPath === false) {
158
+ (0, import_debug.debugResolve)("empty resolve:", args);
159
+ return {
160
+ path: "/empty-stub",
161
+ sideEffects: false
162
+ };
163
+ }
164
+ const sideEffects = await getSideEffects(resultPath, isExternal);
165
+ const result = {
166
+ path: resultPath,
167
+ external: isExternal,
168
+ namespace: isExternal ? void 0 : "file",
169
+ sideEffects,
170
+ suffix
171
+ };
172
+ (0, import_debug.debugResolve)("onResolve args:", args);
173
+ (0, import_debug.debugResolve)("onResolve result:", result);
174
+ return result;
175
+ });
176
+ build.onLoad({
177
+ filter: /.*/
178
+ }, async (args) => {
179
+ if (args.namespace === globalNamespace) {
180
+ const value = config.umdGlobals[args.path];
181
+ return {
182
+ contents: `module.exports = (typeof globalThis !== "undefined" ? globalThis : Function('return this')() || global || self)[${JSON.stringify(value)}]`
183
+ };
184
+ }
185
+ if (args.suffix) {
186
+ args.path += args.suffix;
187
+ }
188
+ if (args.namespace !== "file") {
189
+ return;
190
+ }
191
+ if (args.path === "/empty-stub") {
192
+ return {
193
+ contents: "module.exports = {}"
194
+ };
195
+ }
196
+ compiler.addWatchFile(args.path);
197
+ let result = await compiler.hooks.load.promise(args);
198
+ if (!result) {
199
+ if (DATAURL_JAVASCRIPT_PATTERNS.test(args.path)) {
200
+ return;
201
+ }
202
+ result = {
203
+ contents: await import_utils.fs.promises.readFile(args.path)
204
+ };
205
+ }
206
+ if (!result.contents || result.loader === "copy") {
207
+ return result;
208
+ }
209
+ const context2 = compiler.getTransformContext(args.path);
210
+ context2.addSourceMap(context2.genPluginId("adapter"), result.map);
211
+ const transformResult = await compiler.hooks.transform.promise({
212
+ code: result.contents.toString(),
213
+ path: args.path,
214
+ loader: result.loader
215
+ });
216
+ const ext = (0, import_path.extname)(args.path);
217
+ var _transformResult_loader;
218
+ const loader = (_transformResult_loader = transformResult.loader) !== null && _transformResult_loader !== void 0 ? _transformResult_loader : import_loader.loaderMap[ext];
219
+ const inlineSourceMap = context2.getInlineSourceMap();
220
+ var _result_resolveDir;
221
+ return {
222
+ contents: transformResult.code + inlineSourceMap,
223
+ loader,
224
+ resolveDir: (_result_resolveDir = result.resolveDir) !== null && _result_resolveDir !== void 0 ? _result_resolveDir : (0, import_path.dirname)(args.path)
225
+ };
226
+ });
227
+ build.onEnd(async (result) => {
228
+ if (result.errors.length) {
229
+ return;
230
+ }
231
+ const { outputs } = result.metafile;
232
+ const needSourceMap = Boolean(config.sourceMap);
233
+ for (const [key, value] of Object.entries(outputs)) {
234
+ var _result_outputFiles, _result_outputFiles1;
235
+ if (key.endsWith(".map")) {
236
+ continue;
237
+ }
238
+ const absPath = (0, import_path.resolve)(root, key);
239
+ const item = (_result_outputFiles = result.outputFiles) === null || _result_outputFiles === void 0 ? void 0 : _result_outputFiles.find((x) => x.path === absPath);
240
+ const mapping = (_result_outputFiles1 = result.outputFiles) === null || _result_outputFiles1 === void 0 ? void 0 : _result_outputFiles1.find((x) => x.path.endsWith(".map") && x.path.replace(/\.map$/, "") === absPath);
241
+ if (!item) {
242
+ continue;
243
+ }
244
+ if (absPath.endsWith(".js")) {
245
+ compiler.emitAsset(absPath, {
246
+ type: "chunk",
247
+ contents: item.text,
248
+ map: (0, import_utils2.normalizeSourceMap)(mapping === null || mapping === void 0 ? void 0 : mapping.text, {
249
+ needSourceMap
250
+ }),
251
+ fileName: absPath,
252
+ entryPoint: value === null || value === void 0 ? void 0 : value.entryPoint
253
+ });
254
+ } else {
255
+ compiler.emitAsset(absPath, {
256
+ type: "asset",
257
+ contents: Buffer.from(item.contents),
258
+ fileName: absPath,
259
+ entryPoint: value === null || value === void 0 ? void 0 : value.entryPoint
260
+ });
261
+ }
262
+ }
263
+ for (const [key, value] of compiler.outputChunk.entries()) {
264
+ const context2 = compiler.getSourcemapContext(value.fileName);
265
+ if (value.type === "chunk" && config.sourceMap) {
266
+ context2.addSourceMap(context2.genPluginId("adapter"), value.map);
267
+ }
268
+ const processedResult = await compiler.hooks.renderChunk.promise(value);
269
+ if (processedResult.type === "chunk" && config.sourceMap) {
270
+ processedResult.map = context2.getSourceMap();
271
+ }
272
+ compiler.outputChunk.set(key, processedResult);
273
+ }
274
+ if (config.metafile) {
275
+ const now = Date.now();
276
+ compiler.emitAsset((0, import_path.resolve)(config.outDir, `metafile-${now}.json`), JSON.stringify(result.metafile, null, 2));
277
+ }
278
+ await (0, import_write_file.writeFile)(compiler);
279
+ });
280
+ }
281
+ };
282
+ };
283
+ // Annotate the CommonJS export names for ESM import in node:
284
+ 0 && (module.exports = {
285
+ adapterPlugin
286
+ });
@@ -0,0 +1,4 @@
1
+ import * as tapable from 'tapable';
2
+ import { Source, Chunk, ICompiler } from '../../types';
3
+ export declare function createTransformHook(compiler: ICompiler): tapable.AsyncSeriesWaterfallHook<Source, tapable.UnsetAdditionalOptions>;
4
+ export declare function createRenderChunkHook(compiler: ICompiler): tapable.AsyncSeriesWaterfallHook<Chunk, tapable.UnsetAdditionalOptions>;
@@ -0,0 +1,103 @@
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 hook_exports = {};
30
+ __export(hook_exports, {
31
+ createRenderChunkHook: () => createRenderChunkHook,
32
+ createTransformHook: () => createTransformHook
33
+ });
34
+ module.exports = __toCommonJS(hook_exports);
35
+ var import_util = require("util");
36
+ var tapable = __toESM(require("tapable"));
37
+ function createTransformHook(compiler) {
38
+ const hook = new tapable.AsyncSeriesWaterfallHook([
39
+ "args"
40
+ ]);
41
+ if (!compiler.config.transformCache) {
42
+ return hook;
43
+ }
44
+ const originTapPromise = hook.tapPromise;
45
+ let hook_fn_id = 1;
46
+ const cacheFn = (options, fn) => {
47
+ fn.id = hook_fn_id++;
48
+ originTapPromise.call(hook, options, async (args) => {
49
+ const originCode = args.code;
50
+ const { id } = fn;
51
+ const context = compiler.getTransformContext(args.path);
52
+ const cache = context.getValidCache(id, args.code);
53
+ if (cache) {
54
+ return cache;
55
+ }
56
+ delete args.map;
57
+ const result = await fn(args);
58
+ context.addTransformResult(id, {
59
+ ...result,
60
+ originCode
61
+ });
62
+ return result;
63
+ });
64
+ };
65
+ hook.tap = cacheFn;
66
+ hook.tapPromise = cacheFn;
67
+ return hook;
68
+ }
69
+ function createRenderChunkHook(compiler) {
70
+ const hook = new tapable.AsyncSeriesWaterfallHook([
71
+ "chunk"
72
+ ]);
73
+ if (!compiler.context.config.sourceMap) {
74
+ return hook;
75
+ }
76
+ const originTapPromise = hook.tapPromise;
77
+ let hook_fn_id = 1;
78
+ const wrapper = (options, fn) => {
79
+ fn.id = hook_fn_id++;
80
+ originTapPromise.call(hook, options, async (chunk) => {
81
+ const context = compiler.getSourcemapContext(chunk.fileName);
82
+ if (chunk.type === "chunk") {
83
+ delete chunk.map;
84
+ }
85
+ const result = await fn(chunk);
86
+ if (chunk.type === "chunk") {
87
+ context.addSourceMap(fn.id, result.map);
88
+ }
89
+ return result;
90
+ });
91
+ };
92
+ hook.tap = wrapper;
93
+ hook.tapPromise = wrapper;
94
+ hook.tapAsync = function(options, fn) {
95
+ wrapper(options, (0, import_util.promisify)(fn));
96
+ };
97
+ return hook;
98
+ }
99
+ // Annotate the CommonJS export names for ESM import in node:
100
+ 0 && (module.exports = {
101
+ createRenderChunkHook,
102
+ createTransformHook
103
+ });
@@ -0,0 +1,35 @@
1
+ import { BuildResult, BuildOptions, BuildContext, ImportKind } from 'esbuild';
2
+ import { FSWatcher } from '@modern-js/utils';
3
+ import { BaseBuildConfig, BuilderHooks, Chunk, ICompiler, ModuleTools, PluginAPI, Context, HookList } from '../../types';
4
+ import { TransformContext } from './transform';
5
+ import { SourcemapContext } from './sourcemap';
6
+ export declare class EsbuildCompiler implements ICompiler {
7
+ instance?: BuildContext;
8
+ result?: BuildResult;
9
+ hookList?: HookList;
10
+ reBuildCount: number;
11
+ buildOptions: BuildOptions;
12
+ context: Context;
13
+ config: BaseBuildConfig;
14
+ hooks: BuilderHooks;
15
+ api: PluginAPI<ModuleTools>;
16
+ outputChunk: Map<string, Chunk>;
17
+ watchedFiles: Set<string>;
18
+ css_resolve: (id: string, dir: string) => string;
19
+ node_resolve: (id: string, dir: string, kind: ImportKind) => string | false;
20
+ watcher?: FSWatcher;
21
+ virtualModule: Map<string, string>;
22
+ private transformContextMap;
23
+ private sourcemapContextMap;
24
+ constructor(context: Context);
25
+ init(): Promise<void>;
26
+ addWatchFile(id: string): void;
27
+ convertConfigToEsbuild(config: BaseBuildConfig): BuildOptions;
28
+ getTransformContext(path: string): TransformContext;
29
+ getSourcemapContext(path: string): SourcemapContext;
30
+ emitAsset(name: string, chunk: string | Chunk): void;
31
+ close(): Promise<void>;
32
+ build(): Promise<void>;
33
+ reBuild(type: 'link' | 'change', config: BaseBuildConfig): Promise<void>;
34
+ }
35
+ export declare const createCompiler: (context: Context) => Promise<EsbuildCompiler>;