@modern-js/module-tools 2.35.1 → 2.36.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 (225) hide show
  1. package/dist/build.js +43 -16
  2. package/dist/builder/build.d.ts +1 -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 +275 -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 +17 -0
  19. package/dist/builder/esbuild/resolve.js +125 -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 +217 -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 +124 -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.d.ts +1 -0
  59. package/dist/builder/index.js +59 -28
  60. package/dist/builder/platform.js +38 -23
  61. package/dist/cli.js +58 -29
  62. package/dist/command.js +62 -38
  63. package/dist/config/defineConfig.js +25 -17
  64. package/dist/config/legacySchema.js +35 -32
  65. package/dist/config/merge.d.ts +1 -0
  66. package/dist/config/merge.js +69 -36
  67. package/dist/config/normalize.d.ts +1 -0
  68. package/dist/config/normalize.js +63 -46
  69. package/dist/config/schema.d.ts +48 -0
  70. package/dist/config/schema.js +53 -34
  71. package/dist/config/transformLegacyConfig.js +67 -61
  72. package/dist/config/valid.d.ts +2 -2
  73. package/dist/config/valid.js +44 -21
  74. package/dist/constants/build.d.ts +5 -1
  75. package/dist/constants/build.js +88 -46
  76. package/dist/constants/color.js +27 -20
  77. package/dist/constants/dts.js +27 -20
  78. package/dist/constants/file.d.ts +2 -2
  79. package/dist/constants/file.js +48 -25
  80. package/dist/constants/legacy-preset.js +45 -32
  81. package/dist/constants/loader.d.ts +2 -0
  82. package/dist/constants/loader.js +53 -0
  83. package/dist/constants/log.d.ts +0 -8
  84. package/dist/constants/log.js +27 -41
  85. package/dist/constants/preset.js +55 -62
  86. package/dist/debug.d.ts +4 -0
  87. package/dist/debug.js +37 -0
  88. package/dist/dev.js +42 -25
  89. package/dist/error.js +49 -42
  90. package/dist/hooks/build.d.ts +1 -2
  91. package/dist/hooks/build.js +36 -28
  92. package/dist/hooks/dev.js +32 -17
  93. package/dist/hooks/index.d.ts +1 -1
  94. package/dist/hooks/index.js +31 -16
  95. package/dist/hooks/misc.d.ts +5 -2
  96. package/dist/hooks/misc.js +31 -12
  97. package/dist/index.d.ts +2 -1
  98. package/dist/index.js +39 -32
  99. package/dist/locale/en.js +32 -17
  100. package/dist/locale/index.d.ts +2 -1
  101. package/dist/locale/index.js +31 -24
  102. package/dist/locale/zh.js +32 -17
  103. package/dist/plugins.js +28 -13
  104. package/dist/types/color.js +15 -5
  105. package/dist/types/command.d.ts +3 -3
  106. package/dist/types/command.js +15 -5
  107. package/dist/types/config/copy.js +15 -5
  108. package/dist/types/config/dev.js +15 -5
  109. package/dist/types/config/index.d.ts +87 -52
  110. package/dist/types/config/index.js +24 -6
  111. package/dist/types/config/style.d.ts +58 -6
  112. package/dist/types/config/style.js +15 -5
  113. package/dist/types/context.js +15 -5
  114. package/dist/types/dts.d.ts +14 -3
  115. package/dist/types/dts.js +15 -5
  116. package/dist/types/esbuild.d.ts +107 -0
  117. package/dist/types/esbuild.js +32 -0
  118. package/dist/types/hooks.js +15 -5
  119. package/dist/types/index.d.ts +1 -0
  120. package/dist/types/index.js +32 -11
  121. package/dist/types/legacyConfig/index.js +15 -5
  122. package/dist/types/legacyConfig/output.d.ts +4 -4
  123. package/dist/types/legacyConfig/output.js +15 -5
  124. package/dist/types/legacyConfig/source.js +15 -5
  125. package/dist/types/legacyConfig/tools.js +15 -5
  126. package/dist/utils/assert.d.ts +5 -0
  127. package/dist/utils/assert.js +50 -0
  128. package/dist/utils/builder.d.ts +10 -14
  129. package/dist/utils/builder.js +59 -59
  130. package/dist/utils/common.d.ts +1 -1
  131. package/dist/utils/common.js +25 -17
  132. package/dist/utils/dts.d.ts +26 -9
  133. package/dist/utils/dts.js +98 -64
  134. package/dist/utils/hash.d.ts +2 -0
  135. package/dist/utils/hash.js +31 -0
  136. package/dist/utils/index.d.ts +11 -0
  137. package/dist/utils/index.js +42 -0
  138. package/dist/utils/input.js +47 -24
  139. package/dist/utils/log.d.ts +1 -2
  140. package/dist/utils/log.js +36 -20
  141. package/dist/utils/map.d.ts +13 -0
  142. package/dist/utils/map.js +58 -0
  143. package/dist/utils/onExit.js +35 -11
  144. package/dist/utils/print.d.ts +2 -2
  145. package/dist/utils/print.js +52 -49
  146. package/dist/utils/style.d.ts +5 -23
  147. package/dist/utils/style.js +57 -37
  148. package/dist/utils/tspath.js +114 -0
  149. package/package.json +64 -50
  150. package/vitest.config.ts +20 -0
  151. package/dist/build.js.map +0 -1
  152. package/dist/builder/build.js.map +0 -1
  153. package/dist/builder/clear.js.map +0 -1
  154. package/dist/builder/copy.js.map +0 -1
  155. package/dist/builder/dts/index.js.map +0 -1
  156. package/dist/builder/dts/rollup.js.map +0 -1
  157. package/dist/builder/dts/tsc.js.map +0 -1
  158. package/dist/builder/index.js.map +0 -1
  159. package/dist/builder/platform.js.map +0 -1
  160. package/dist/cli.js.map +0 -1
  161. package/dist/command.js.map +0 -1
  162. package/dist/config/defineConfig.js.map +0 -1
  163. package/dist/config/legacySchema.js.map +0 -1
  164. package/dist/config/merge.js.map +0 -1
  165. package/dist/config/normalize.js.map +0 -1
  166. package/dist/config/schema.js.map +0 -1
  167. package/dist/config/transformLegacyConfig.js.map +0 -1
  168. package/dist/config/valid.js.map +0 -1
  169. package/dist/constants/build.js.map +0 -1
  170. package/dist/constants/color.js.map +0 -1
  171. package/dist/constants/dts.js.map +0 -1
  172. package/dist/constants/file.js.map +0 -1
  173. package/dist/constants/legacy-preset.js.map +0 -1
  174. package/dist/constants/log.js.map +0 -1
  175. package/dist/constants/preset.js.map +0 -1
  176. package/dist/dev.js.map +0 -1
  177. package/dist/error.js.map +0 -1
  178. package/dist/hooks/build.js.map +0 -1
  179. package/dist/hooks/dev.js.map +0 -1
  180. package/dist/hooks/index.js.map +0 -1
  181. package/dist/hooks/misc.js.map +0 -1
  182. package/dist/index.js.map +0 -1
  183. package/dist/locale/en.js.map +0 -1
  184. package/dist/locale/index.js.map +0 -1
  185. package/dist/locale/zh.js.map +0 -1
  186. package/dist/plugins.js.map +0 -1
  187. package/dist/types/color.js.map +0 -1
  188. package/dist/types/command.js.map +0 -1
  189. package/dist/types/config/copy.js.map +0 -1
  190. package/dist/types/config/dev.js.map +0 -1
  191. package/dist/types/config/index.js.map +0 -1
  192. package/dist/types/config/style.js.map +0 -1
  193. package/dist/types/context.js.map +0 -1
  194. package/dist/types/dts.js.map +0 -1
  195. package/dist/types/hooks.js.map +0 -1
  196. package/dist/types/index.js.map +0 -1
  197. package/dist/types/legacyConfig/index.js.map +0 -1
  198. package/dist/types/legacyConfig/output.js.map +0 -1
  199. package/dist/types/legacyConfig/source.js.map +0 -1
  200. package/dist/types/legacyConfig/tools.js.map +0 -1
  201. package/dist/types/utils.d.ts +0 -5
  202. package/dist/types/utils.js +0 -4
  203. package/dist/utils/builder.js.map +0 -1
  204. package/dist/utils/common.js.map +0 -1
  205. package/dist/utils/context.d.ts +0 -7
  206. package/dist/utils/context.js +0 -23
  207. package/dist/utils/context.js.map +0 -1
  208. package/dist/utils/dts.js.map +0 -1
  209. package/dist/utils/input.js.map +0 -1
  210. package/dist/utils/language.d.ts +0 -1
  211. package/dist/utils/language.js +0 -22
  212. package/dist/utils/language.js.map +0 -1
  213. package/dist/utils/libuild-plugin.d.ts +0 -3
  214. package/dist/utils/libuild-plugin.js +0 -31
  215. package/dist/utils/libuild-plugin.js.map +0 -1
  216. package/dist/utils/log.js.map +0 -1
  217. package/dist/utils/onExit.js.map +0 -1
  218. package/dist/utils/path.d.ts +0 -1
  219. package/dist/utils/path.js +0 -19
  220. package/dist/utils/path.js.map +0 -1
  221. package/dist/utils/print.js.map +0 -1
  222. package/dist/utils/style.js.map +0 -1
  223. package/dist/utils/tspathsTransform.js +0 -91
  224. package/dist/utils/tspathsTransform.js.map +0 -1
  225. /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
package/dist/build.js CHANGED
@@ -1,36 +1,63 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "build", {
6
- enumerable: true,
7
- get: function() {
8
- return build;
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 });
9
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 build_exports = {};
30
+ __export(build_exports, {
31
+ build: () => build
10
32
  });
11
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
- const _utils = require("@modern-js/utils");
13
- const debug = (0, _utils.createDebugger)("module-tools");
33
+ module.exports = __toCommonJS(build_exports);
34
+ var import_debug = require("./debug");
14
35
  const build = async (api, options, context) => {
15
36
  if (options.platform) {
16
- const { buildPlatform } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./builder/platform")));
37
+ const { buildPlatform } = await Promise.resolve().then(() => __toESM(require("./builder/platform")));
17
38
  await buildPlatform(options, api, context);
18
39
  return;
19
40
  }
20
41
  const runner = api.useHookRunners();
21
- const { normalizeBuildConfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./config/normalize")));
42
+ (0, import_debug.debug)("normalize build config");
43
+ const { normalizeBuildConfig } = await Promise.resolve().then(() => __toESM(require("./config/normalize")));
22
44
  const resolvedBuildConfig = await normalizeBuildConfig(api, context, options);
23
- debug("resolvedBuildConfig", resolvedBuildConfig);
45
+ (0, import_debug.debug)("normalize build config done");
46
+ (0, import_debug.debug)("normalizedBuildConfig", resolvedBuildConfig);
47
+ (0, import_debug.debug)("run beforeBuild hooks");
24
48
  await runner.beforeBuild({
25
49
  config: resolvedBuildConfig,
26
50
  cliOptions: options
27
51
  });
28
- const builder = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./builder")));
52
+ (0, import_debug.debug)("run beforeBuild hooks done");
53
+ const builder = await Promise.resolve().then(() => __toESM(require("./builder")));
29
54
  await builder.run({
30
55
  cmdOptions: options,
31
56
  resolvedBuildConfig,
32
57
  context
33
58
  }, api);
34
59
  };
35
-
36
- //# sourceMappingURL=build.js.map
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ build
63
+ });
@@ -1,19 +1,10 @@
1
+ /// <reference types="mocha" />
1
2
  import type { BuildCommandOptions, BaseBuildConfig, ModuleTools, PluginAPI, DTSOptions, ModuleContext } from '../types';
2
3
  export declare const runBuildTask: (options: {
3
4
  buildConfig: BaseBuildConfig;
4
5
  buildCmdOptions: BuildCommandOptions;
5
6
  context: ModuleContext;
6
7
  }, api: PluginAPI<ModuleTools>) => Promise<void>;
7
- export declare const buildInTsProject: (options: {
8
- buildConfig: BaseBuildConfig;
9
- buildCmdOptions: BuildCommandOptions;
10
- context: ModuleContext;
11
- }, api: PluginAPI<ModuleTools>) => Promise<void>;
12
- export declare const buildInJsProject: (options: {
13
- buildConfig: BaseBuildConfig;
14
- buildCmdOptions: BuildCommandOptions;
15
- context: ModuleContext;
16
- }, api: PluginAPI<ModuleTools>) => Promise<void>;
17
8
  export declare const generatorDts: (config: BaseBuildConfig, api: PluginAPI<ModuleTools>, options: {
18
9
  watch: boolean;
19
10
  dts: DTSOptions;
@@ -1,251 +1,135 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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) => {
6
9
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- runBuildTask: function() {
14
- return runBuildTask;
15
- },
16
- buildInTsProject: function() {
17
- return buildInTsProject;
18
- },
19
- buildInJsProject: function() {
20
- return buildInJsProject;
21
- },
22
- generatorDts: function() {
23
- return generatorDts;
24
- },
25
- buildLib: function() {
26
- return buildLib;
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 });
27
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 build_exports = {};
30
+ __export(build_exports, {
31
+ buildLib: () => buildLib,
32
+ generatorDts: () => generatorDts,
33
+ runBuildTask: () => runBuildTask
28
34
  });
29
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
30
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
31
- const _path = require("path");
32
- const _utils = require("@modern-js/utils");
33
- const _pmap = /* @__PURE__ */ _interop_require_default._(require("../../compiled/p-map"));
34
- const _copy = require("./copy");
35
+ module.exports = __toCommonJS(build_exports);
36
+ var import_utils = require("@modern-js/utils");
37
+ var import_utils2 = require("../utils");
38
+ var import_p_map = __toESM(require("../../compiled/p-map"));
39
+ var import_debug = require("../debug");
40
+ var import_copy = require("./copy");
41
+ var import_esbuild = require("./esbuild");
35
42
  const runBuildTask = async (options, api) => {
36
43
  const { buildConfig, context, buildCmdOptions } = options;
37
- const { appDirectory, isTsProject } = context;
38
- await (0, _copy.copyTask)(buildConfig, {
44
+ const { appDirectory } = context;
45
+ await (0, import_copy.copyTask)(buildConfig, {
39
46
  appDirectory,
40
47
  watch: buildCmdOptions.watch
41
48
  });
42
- if (isTsProject) {
43
- await buildInTsProject(options, api);
44
- } else {
45
- await buildInJsProject(options, api);
46
- }
47
- };
48
- const buildInTsProject = async (options, api) => {
49
- const { buildConfig, buildCmdOptions } = options;
50
49
  const dts = buildCmdOptions.dts ? buildConfig.dts : false;
51
- const skipBuildLib = buildConfig.dts ? buildConfig.dts.only : false;
52
- var _buildCmdOptions_watch;
53
- const watch = (_buildCmdOptions_watch = buildCmdOptions.watch) !== null && _buildCmdOptions_watch !== void 0 ? _buildCmdOptions_watch : false;
54
- if (dts === false) {
55
- !skipBuildLib && await buildLib(buildConfig, api, {
56
- watch
57
- });
58
- } else {
50
+ const { watch } = buildCmdOptions;
51
+ const existTsconfig = await import_utils.fs.pathExists(buildConfig.tsconfig);
52
+ if (dts && existTsconfig) {
59
53
  const tasks = dts.only ? [
60
54
  generatorDts
61
55
  ] : [
62
56
  buildLib,
63
57
  generatorDts
64
58
  ];
65
- await (0, _pmap.default)(tasks, async (task) => {
59
+ await (0, import_p_map.default)(tasks, async (task) => {
66
60
  await task(buildConfig, api, {
67
61
  watch,
68
62
  dts
69
63
  });
70
64
  });
65
+ } else {
66
+ if (dts && dts.only) {
67
+ return;
68
+ }
69
+ await buildLib(buildConfig, api, {
70
+ watch
71
+ });
71
72
  }
72
73
  };
73
- const buildInJsProject = async (options, api) => {
74
- const { buildConfig, buildCmdOptions } = options;
75
- const dts = buildCmdOptions.dts ? buildConfig.dts : false;
76
- var _buildCmdOptions_watch;
77
- const watch = (_buildCmdOptions_watch = buildCmdOptions.watch) !== null && _buildCmdOptions_watch !== void 0 ? _buildCmdOptions_watch : false;
78
- if (dts !== false && dts.only) {
79
- return;
80
- }
81
- await buildLib(buildConfig, api, {
82
- watch
83
- });
84
- };
85
74
  const generatorDts = async (config, api, options) => {
86
- const { runRollup, runTsc } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./dts")));
75
+ const { runRollup, runTsc } = await Promise.resolve().then(() => __toESM(require("./dts")));
87
76
  const { watch, dts } = options;
88
- const { buildType, input, sourceDir, alias, externals } = config;
77
+ const { buildType, input, sourceDir, alias, externals, tsconfig, footer: { dts: footer }, banner: { dts: banner } } = config;
89
78
  const { appDirectory } = api.useAppContext();
90
- const { tsconfigPath, distPath, abortOnError, respectExternal } = dts;
79
+ const { distPath, abortOnError, respectExternal } = dts;
80
+ var _dts_tsconfigPath;
81
+ const tsconfigPath = (_dts_tsconfigPath = dts.tsconfigPath) !== null && _dts_tsconfigPath !== void 0 ? _dts_tsconfigPath : tsconfig;
82
+ const generatorDtsConfig = {
83
+ distPath,
84
+ watch,
85
+ externals,
86
+ input,
87
+ tsconfigPath,
88
+ abortOnError,
89
+ respectExternal,
90
+ appDirectory,
91
+ footer,
92
+ banner,
93
+ alias,
94
+ sourceDir
95
+ };
96
+ const prevTime = Date.now();
97
+ (0, import_debug.debug)(`${(0, import_debug.label)("dts")} Build Start`);
91
98
  if (buildType === "bundle") {
92
- await runRollup(api, {
93
- distDir: distPath,
94
- watch,
95
- externals,
96
- input,
97
- tsconfigPath,
98
- abortOnError,
99
- respectExternal,
100
- appDirectory
101
- });
99
+ await runRollup(api, generatorDtsConfig);
102
100
  } else {
103
- await runTsc(api, {
104
- appDirectory,
105
- alias,
106
- distAbsPath: distPath,
107
- watch,
108
- tsconfigPath,
109
- sourceDir,
110
- abortOnError
111
- });
101
+ await runTsc(api, generatorDtsConfig);
112
102
  }
103
+ (0, import_debug.debug)(`${(0, import_debug.label)("dts")} Build success in ${Date.now() - prevTime}ms`);
113
104
  };
114
105
  const buildLib = async (config, api, options) => {
115
106
  const { watch } = options;
116
- const { target, buildType, sourceMap, format, outDir: distPath, asset, jsx, input, platform, splitting, minify, sourceDir, umdGlobals, umdModuleName, define, alias, style, externals, autoExternal, dts, metafile, sideEffects, redirect, esbuildOptions, externalHelpers, transformImport, transformLodash, sourceType, disableSwcTransform } = config;
107
+ const { target, buildType, format, externalHelpers } = config;
117
108
  const { appDirectory } = api.useAppContext();
118
- const root = (0, _utils.slash)(appDirectory);
119
- const outdir = (0, _utils.slash)(distPath);
120
- const assetOutDir = asset.path ? (0, _utils.slash)(asset.path) : asset.path;
121
- const { less, sass, postcss, inject, modules, autoModules } = style;
122
- const { umdPlugin, swcTransformPlugin, transformPlugin: legacyTransformPlugin, es5Plugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/libuild-plugin-swc")));
123
- const { checkSwcHelpers, matchEs5PluginCondition, matchSwcTransformCondition } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/builder")));
124
- const { getProjectTsconfig } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/dts")));
125
- const tsconfigPath = dts ? dts.tsconfigPath : (0, _path.resolve)(appDirectory, "tsconfig.json");
126
- const userTsconfig = await getProjectTsconfig(tsconfigPath);
127
- const plugins = [];
128
- if (matchSwcTransformCondition({
129
- sourceType,
130
- buildType,
131
- format,
132
- disableSwcTransform
133
- })) {
134
- var _userTsconfig_compilerOptions, _userTsconfig_compilerOptions1, _userTsconfig_compilerOptions2;
135
- const { tsTargetAtOrAboveES2022 } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/dts")));
136
- const tsUseDefineForClassFields = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.useDefineForClassFields;
137
- let tsTarget = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions1 = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions1 === void 0 ? void 0 : _userTsconfig_compilerOptions1.target;
138
- tsTarget = tsTarget ? tsTarget.toLowerCase() : void 0;
139
- let useDefineForClassFields;
140
- if (tsUseDefineForClassFields !== void 0) {
141
- useDefineForClassFields = tsUseDefineForClassFields;
142
- } else if (tsTarget !== void 0) {
143
- useDefineForClassFields = tsTargetAtOrAboveES2022(tsTarget);
144
- } else {
145
- useDefineForClassFields = true;
146
- }
147
- plugins.push(swcTransformPlugin({
148
- pluginImport: transformImport,
149
- transformLodash,
150
- externalHelpers: Boolean(externalHelpers),
151
- emitDecoratorMetadata: userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions2 = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions2 === void 0 ? void 0 : _userTsconfig_compilerOptions2.emitDecoratorMetadata,
152
- useDefineForClassFields
153
- }));
154
- } else {
155
- var _userTsconfig_compilerOptions3;
156
- if (matchEs5PluginCondition({
157
- sourceType,
158
- buildType,
159
- format,
160
- target,
161
- disableSwcTransform
162
- })) {
163
- plugins.push(es5Plugin());
164
- }
165
- if (userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions3 = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions3 === void 0 ? void 0 : _userTsconfig_compilerOptions3.emitDecoratorMetadata) {
166
- plugins.push(legacyTransformPlugin({
167
- jsc: {
168
- transform: {
169
- legacyDecorator: true,
170
- decoratorMetadata: true
171
- }
172
- }
173
- }));
174
- }
175
- }
176
- if (format === "umd") {
177
- plugins.push(umdPlugin(umdModuleName));
178
- }
109
+ const root = (0, import_utils.slash)(appDirectory);
110
+ const { checkSwcHelpers } = await Promise.resolve().then(() => __toESM(require("../utils/builder")));
179
111
  await checkSwcHelpers({
180
112
  appDirectory,
181
113
  externalHelpers
182
114
  });
183
- if (asset.svgr) {
184
- const { svgrPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/libuild-plugin-svgr")));
185
- const options2 = typeof asset.svgr === "boolean" ? {} : asset.svgr;
186
- plugins.push(svgrPlugin(options2));
187
- }
188
- const { watchPlugin } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/libuild-plugin")));
189
- plugins.push(watchPlugin(api, config));
190
- const buildConfig = {
191
- root,
192
- watch,
193
- target,
194
- sourceMap,
195
- format,
196
- outdir,
197
- define,
198
- style: {
199
- less,
200
- sass,
201
- postcss,
202
- inject,
203
- modules,
204
- autoModules
205
- },
206
- resolve: {
207
- alias
208
- },
209
- asset: {
210
- ...asset,
211
- outdir: assetOutDir
212
- },
213
- plugins,
214
- jsx,
215
- input,
216
- platform,
217
- splitting,
218
- minify,
219
- sourceDir,
220
- metafile: metafile && buildType === "bundle",
221
- globals: umdGlobals,
222
- external: externals,
223
- autoExternal,
224
- redirect,
225
- bundle: buildType === "bundle",
226
- sideEffects,
227
- // outbase for [dir]/[name]
228
- outbase: sourceDir,
229
- esbuildOptions
230
- };
231
115
  try {
232
- const { Libuilder } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/libuild")));
233
- const { addOutputChunk } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/print")));
234
- const runner = api.useHookRunners();
235
- const modifiedBuildConfig = await runner.modifyLibuild(buildConfig, {
236
- onLast: (c) => c
116
+ const prevTime = Date.now();
117
+ (0, import_debug.debug)(`${(0, import_debug.label)(config.format)} Build Start`);
118
+ const compiler = await (0, import_esbuild.createCompiler)({
119
+ config,
120
+ watch,
121
+ root: appDirectory,
122
+ api
237
123
  });
238
- const builder = await Libuilder.create(modifiedBuildConfig);
239
- await builder.build();
240
- addOutputChunk(builder.outputChunk, root, buildType === "bundle");
124
+ await compiler.build();
125
+ (0, import_debug.debug)(`${(0, import_debug.label)(config.format)} Build success in ${Date.now() - prevTime}ms`);
126
+ const { addOutputChunk } = await Promise.resolve().then(() => __toESM(require("../utils/print")));
127
+ addOutputChunk(compiler.outputChunk, root, buildType === "bundle");
241
128
  if (watch) {
242
- const { watchSectionTitle } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../utils/log")));
243
- const { SectionTitleStatus } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/log")));
244
- const titleText = `[${buildType === "bundle" ? "Bundle" : "Bundleless"}: ${format}_${target}]`;
245
- _utils.logger.info(await watchSectionTitle(titleText, SectionTitleStatus.Success));
129
+ import_utils.logger.success((0, import_utils2.withLogTitle)(buildType, `Build ${format},${target} files`));
246
130
  }
247
131
  } catch (e) {
248
- const { InternalBuildError } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../error")));
132
+ const { InternalBuildError } = await Promise.resolve().then(() => __toESM(require("../error")));
249
133
  throw new InternalBuildError(e, {
250
134
  target,
251
135
  format,
@@ -253,5 +137,9 @@ const buildLib = async (config, api, options) => {
253
137
  });
254
138
  }
255
139
  };
256
-
257
- //# sourceMappingURL=build.js.map
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ buildLib,
143
+ generatorDts,
144
+ runBuildTask
145
+ });
@@ -1,6 +1,3 @@
1
1
  import type { BaseBuildConfig } from '../types';
2
2
  export declare const clearDtsTemp: () => Promise<void>;
3
- export declare const clearBuildConfigPaths: (configs: BaseBuildConfig[], options?: {
4
- noClear?: boolean;
5
- projectAbsRootPath?: string;
6
- }) => Promise<void>;
3
+ export declare const clearBuildConfigPaths: (configs: BaseBuildConfig[], projectAbsRootPath: string) => Promise<void>;
@@ -1,40 +1,44 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
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) => {
6
7
  for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- clearDtsTemp: function() {
14
- return clearDtsTemp;
15
- },
16
- clearBuildConfigPaths: function() {
17
- return clearBuildConfigPaths;
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 });
18
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var clear_exports = {};
20
+ __export(clear_exports, {
21
+ clearBuildConfigPaths: () => clearBuildConfigPaths,
22
+ clearDtsTemp: () => clearDtsTemp
19
23
  });
20
- const _utils = require("@modern-js/utils");
21
- const _locale = require("../locale");
22
- const _dts = require("../constants/dts");
24
+ module.exports = __toCommonJS(clear_exports);
25
+ var import_utils = require("@modern-js/utils");
26
+ var import_locale = require("../locale");
27
+ var import_dts = require("../constants/dts");
23
28
  const clearDtsTemp = async () => {
24
- await _utils.fs.remove(_dts.dtsTempDirectory);
29
+ await import_utils.fs.remove(import_dts.dtsTempDirectory);
25
30
  };
26
- const clearBuildConfigPaths = async (configs, options) => {
27
- const { noClear = false, projectAbsRootPath = process.cwd() } = options !== null && options !== void 0 ? options : {};
28
- if (noClear) {
29
- return;
30
- }
31
+ const clearBuildConfigPaths = async (configs, projectAbsRootPath) => {
31
32
  for (const config of configs) {
32
33
  if (projectAbsRootPath === config.outDir) {
33
- _utils.logger.warn(_utils.chalk.bgYellowBright(_locale.i18n.t(_locale.localeKeys.warns.clearRootPath)));
34
+ import_utils.logger.warn(import_utils.chalk.bgYellowBright(import_locale.i18n.t(import_locale.localeKeys.warns.clearRootPath)));
34
35
  } else {
35
- await _utils.fs.remove(config.outDir);
36
+ await import_utils.fs.remove(config.outDir);
36
37
  }
37
38
  }
38
39
  };
39
-
40
- //# sourceMappingURL=clear.js.map
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ clearBuildConfigPaths,
43
+ clearDtsTemp
44
+ });