@modern-js/module-tools 2.35.0 → 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 (227) hide show
  1. package/compiled/postcss-nesting/index.js +2 -2
  2. package/compiled/postcss-nesting/package.json +1 -1
  3. package/dist/build.js +43 -16
  4. package/dist/builder/build.d.ts +1 -10
  5. package/dist/builder/build.js +96 -208
  6. package/dist/builder/clear.d.ts +1 -4
  7. package/dist/builder/clear.js +32 -28
  8. package/dist/builder/copy.js +79 -64
  9. package/dist/builder/dts/index.js +27 -19
  10. package/dist/builder/dts/rollup.d.ts +6 -14
  11. package/dist/builder/dts/rollup.js +60 -37
  12. package/dist/builder/dts/tsc.d.ts +3 -2
  13. package/dist/builder/dts/tsc.js +50 -37
  14. package/dist/builder/esbuild/adapter.d.ts +3 -0
  15. package/dist/builder/esbuild/adapter.js +275 -0
  16. package/dist/builder/esbuild/hook.d.ts +4 -0
  17. package/dist/builder/esbuild/hook.js +103 -0
  18. package/dist/builder/esbuild/index.d.ts +35 -0
  19. package/dist/builder/esbuild/index.js +268 -0
  20. package/dist/builder/esbuild/resolve.d.ts +17 -0
  21. package/dist/builder/esbuild/resolve.js +125 -0
  22. package/dist/builder/esbuild/sourcemap.d.ts +16 -0
  23. package/dist/builder/esbuild/sourcemap.js +86 -0
  24. package/dist/builder/esbuild/transform.d.ts +7 -0
  25. package/dist/builder/esbuild/transform.js +45 -0
  26. package/dist/builder/esbuild/watch.d.ts +2 -0
  27. package/dist/builder/esbuild/watch.js +115 -0
  28. package/dist/builder/esbuild/write-file.d.ts +2 -0
  29. package/dist/builder/esbuild/write-file.js +89 -0
  30. package/dist/builder/feature/asset.d.ts +19 -0
  31. package/dist/builder/feature/asset.js +149 -0
  32. package/dist/builder/feature/format-cjs.d.ts +5 -0
  33. package/dist/builder/feature/format-cjs.js +53 -0
  34. package/dist/builder/feature/index.d.ts +2 -0
  35. package/dist/builder/feature/index.js +74 -0
  36. package/dist/builder/feature/json.d.ts +5 -0
  37. package/dist/builder/feature/json.js +47 -0
  38. package/dist/builder/feature/redirect.d.ts +5 -0
  39. package/dist/builder/feature/redirect.js +217 -0
  40. package/dist/builder/feature/style/index.d.ts +5 -0
  41. package/dist/builder/feature/style/index.js +94 -0
  42. package/dist/builder/feature/style/lessAliasPlugin.d.ts +12 -0
  43. package/dist/builder/feature/style/lessAliasPlugin.js +70 -0
  44. package/dist/builder/feature/style/lessRender.d.ts +2 -0
  45. package/dist/builder/feature/style/lessRender.js +64 -0
  46. package/dist/builder/feature/style/postcssTransformer.d.ts +6 -0
  47. package/dist/builder/feature/style/postcssTransformer.js +95 -0
  48. package/dist/builder/feature/style/postcssUrlPlugin.d.ts +6 -0
  49. package/dist/builder/feature/style/postcssUrlPlugin.js +58 -0
  50. package/dist/builder/feature/style/sassRender.d.ts +2 -0
  51. package/dist/builder/feature/style/sassRender.js +85 -0
  52. package/dist/builder/feature/style/transformStyle.d.ts +13 -0
  53. package/dist/builder/feature/style/transformStyle.js +101 -0
  54. package/dist/builder/feature/style/utils.d.ts +18 -0
  55. package/dist/builder/feature/style/utils.js +124 -0
  56. package/dist/builder/feature/swc.d.ts +9 -0
  57. package/dist/builder/feature/swc.js +170 -0
  58. package/dist/builder/feature/terser.d.ts +5 -0
  59. package/dist/builder/feature/terser.js +83 -0
  60. package/dist/builder/index.d.ts +1 -0
  61. package/dist/builder/index.js +59 -28
  62. package/dist/builder/platform.js +38 -23
  63. package/dist/cli.js +58 -29
  64. package/dist/command.js +62 -38
  65. package/dist/config/defineConfig.js +25 -17
  66. package/dist/config/legacySchema.js +35 -32
  67. package/dist/config/merge.d.ts +1 -0
  68. package/dist/config/merge.js +69 -36
  69. package/dist/config/normalize.d.ts +1 -0
  70. package/dist/config/normalize.js +63 -46
  71. package/dist/config/schema.d.ts +48 -0
  72. package/dist/config/schema.js +53 -34
  73. package/dist/config/transformLegacyConfig.js +67 -61
  74. package/dist/config/valid.d.ts +2 -2
  75. package/dist/config/valid.js +44 -21
  76. package/dist/constants/build.d.ts +5 -1
  77. package/dist/constants/build.js +88 -46
  78. package/dist/constants/color.js +27 -20
  79. package/dist/constants/dts.js +27 -20
  80. package/dist/constants/file.d.ts +2 -2
  81. package/dist/constants/file.js +48 -25
  82. package/dist/constants/legacy-preset.js +45 -32
  83. package/dist/constants/loader.d.ts +2 -0
  84. package/dist/constants/loader.js +53 -0
  85. package/dist/constants/log.d.ts +0 -8
  86. package/dist/constants/log.js +27 -41
  87. package/dist/constants/preset.js +55 -62
  88. package/dist/debug.d.ts +4 -0
  89. package/dist/debug.js +37 -0
  90. package/dist/dev.js +42 -25
  91. package/dist/error.js +49 -42
  92. package/dist/hooks/build.d.ts +1 -2
  93. package/dist/hooks/build.js +36 -28
  94. package/dist/hooks/dev.js +32 -17
  95. package/dist/hooks/index.d.ts +1 -1
  96. package/dist/hooks/index.js +31 -16
  97. package/dist/hooks/misc.d.ts +5 -2
  98. package/dist/hooks/misc.js +31 -12
  99. package/dist/index.d.ts +2 -1
  100. package/dist/index.js +39 -32
  101. package/dist/locale/en.js +32 -17
  102. package/dist/locale/index.d.ts +2 -1
  103. package/dist/locale/index.js +31 -24
  104. package/dist/locale/zh.js +32 -17
  105. package/dist/plugins.js +28 -13
  106. package/dist/types/color.js +15 -5
  107. package/dist/types/command.d.ts +3 -3
  108. package/dist/types/command.js +15 -5
  109. package/dist/types/config/copy.js +15 -5
  110. package/dist/types/config/dev.js +15 -5
  111. package/dist/types/config/index.d.ts +87 -52
  112. package/dist/types/config/index.js +24 -6
  113. package/dist/types/config/style.d.ts +58 -6
  114. package/dist/types/config/style.js +15 -5
  115. package/dist/types/context.js +15 -5
  116. package/dist/types/dts.d.ts +14 -3
  117. package/dist/types/dts.js +15 -5
  118. package/dist/types/esbuild.d.ts +107 -0
  119. package/dist/types/esbuild.js +32 -0
  120. package/dist/types/hooks.js +15 -5
  121. package/dist/types/index.d.ts +1 -0
  122. package/dist/types/index.js +32 -11
  123. package/dist/types/legacyConfig/index.js +15 -5
  124. package/dist/types/legacyConfig/output.d.ts +4 -4
  125. package/dist/types/legacyConfig/output.js +15 -5
  126. package/dist/types/legacyConfig/source.js +15 -5
  127. package/dist/types/legacyConfig/tools.js +15 -5
  128. package/dist/utils/assert.d.ts +5 -0
  129. package/dist/utils/assert.js +50 -0
  130. package/dist/utils/builder.d.ts +10 -14
  131. package/dist/utils/builder.js +59 -59
  132. package/dist/utils/common.d.ts +1 -1
  133. package/dist/utils/common.js +25 -17
  134. package/dist/utils/dts.d.ts +26 -9
  135. package/dist/utils/dts.js +100 -66
  136. package/dist/utils/hash.d.ts +2 -0
  137. package/dist/utils/hash.js +31 -0
  138. package/dist/utils/index.d.ts +11 -0
  139. package/dist/utils/index.js +42 -0
  140. package/dist/utils/input.js +47 -24
  141. package/dist/utils/log.d.ts +1 -2
  142. package/dist/utils/log.js +36 -20
  143. package/dist/utils/map.d.ts +13 -0
  144. package/dist/utils/map.js +58 -0
  145. package/dist/utils/onExit.js +35 -11
  146. package/dist/utils/print.d.ts +2 -2
  147. package/dist/utils/print.js +52 -49
  148. package/dist/utils/style.d.ts +5 -23
  149. package/dist/utils/style.js +63 -43
  150. package/dist/utils/tspath.js +114 -0
  151. package/package.json +64 -50
  152. package/vitest.config.ts +20 -0
  153. package/dist/build.js.map +0 -1
  154. package/dist/builder/build.js.map +0 -1
  155. package/dist/builder/clear.js.map +0 -1
  156. package/dist/builder/copy.js.map +0 -1
  157. package/dist/builder/dts/index.js.map +0 -1
  158. package/dist/builder/dts/rollup.js.map +0 -1
  159. package/dist/builder/dts/tsc.js.map +0 -1
  160. package/dist/builder/index.js.map +0 -1
  161. package/dist/builder/platform.js.map +0 -1
  162. package/dist/cli.js.map +0 -1
  163. package/dist/command.js.map +0 -1
  164. package/dist/config/defineConfig.js.map +0 -1
  165. package/dist/config/legacySchema.js.map +0 -1
  166. package/dist/config/merge.js.map +0 -1
  167. package/dist/config/normalize.js.map +0 -1
  168. package/dist/config/schema.js.map +0 -1
  169. package/dist/config/transformLegacyConfig.js.map +0 -1
  170. package/dist/config/valid.js.map +0 -1
  171. package/dist/constants/build.js.map +0 -1
  172. package/dist/constants/color.js.map +0 -1
  173. package/dist/constants/dts.js.map +0 -1
  174. package/dist/constants/file.js.map +0 -1
  175. package/dist/constants/legacy-preset.js.map +0 -1
  176. package/dist/constants/log.js.map +0 -1
  177. package/dist/constants/preset.js.map +0 -1
  178. package/dist/dev.js.map +0 -1
  179. package/dist/error.js.map +0 -1
  180. package/dist/hooks/build.js.map +0 -1
  181. package/dist/hooks/dev.js.map +0 -1
  182. package/dist/hooks/index.js.map +0 -1
  183. package/dist/hooks/misc.js.map +0 -1
  184. package/dist/index.js.map +0 -1
  185. package/dist/locale/en.js.map +0 -1
  186. package/dist/locale/index.js.map +0 -1
  187. package/dist/locale/zh.js.map +0 -1
  188. package/dist/plugins.js.map +0 -1
  189. package/dist/types/color.js.map +0 -1
  190. package/dist/types/command.js.map +0 -1
  191. package/dist/types/config/copy.js.map +0 -1
  192. package/dist/types/config/dev.js.map +0 -1
  193. package/dist/types/config/index.js.map +0 -1
  194. package/dist/types/config/style.js.map +0 -1
  195. package/dist/types/context.js.map +0 -1
  196. package/dist/types/dts.js.map +0 -1
  197. package/dist/types/hooks.js.map +0 -1
  198. package/dist/types/index.js.map +0 -1
  199. package/dist/types/legacyConfig/index.js.map +0 -1
  200. package/dist/types/legacyConfig/output.js.map +0 -1
  201. package/dist/types/legacyConfig/source.js.map +0 -1
  202. package/dist/types/legacyConfig/tools.js.map +0 -1
  203. package/dist/types/utils.d.ts +0 -5
  204. package/dist/types/utils.js +0 -4
  205. package/dist/utils/builder.js.map +0 -1
  206. package/dist/utils/common.js.map +0 -1
  207. package/dist/utils/context.d.ts +0 -7
  208. package/dist/utils/context.js +0 -23
  209. package/dist/utils/context.js.map +0 -1
  210. package/dist/utils/dts.js.map +0 -1
  211. package/dist/utils/input.js.map +0 -1
  212. package/dist/utils/language.d.ts +0 -1
  213. package/dist/utils/language.js +0 -22
  214. package/dist/utils/language.js.map +0 -1
  215. package/dist/utils/libuild-plugin.d.ts +0 -3
  216. package/dist/utils/libuild-plugin.js +0 -31
  217. package/dist/utils/libuild-plugin.js.map +0 -1
  218. package/dist/utils/log.js.map +0 -1
  219. package/dist/utils/onExit.js.map +0 -1
  220. package/dist/utils/path.d.ts +0 -1
  221. package/dist/utils/path.js +0 -19
  222. package/dist/utils/path.js.map +0 -1
  223. package/dist/utils/print.js.map +0 -1
  224. package/dist/utils/style.js.map +0 -1
  225. package/dist/utils/tspathsTransform.js +0 -91
  226. package/dist/utils/tspathsTransform.js.map +0 -1
  227. /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
-
6
- //# sourceMappingURL=output.js.map
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var output_exports = {};
16
+ module.exports = __toCommonJS(output_exports);
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
-
6
- //# sourceMappingURL=source.js.map
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var source_exports = {};
16
+ module.exports = __toCommonJS(source_exports);
@@ -1,6 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
-
6
- //# sourceMappingURL=tools.js.map
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var tools_exports = {};
16
+ module.exports = __toCommonJS(tools_exports);
@@ -0,0 +1,5 @@
1
+ export declare function isStyleExt(path: string): boolean;
2
+ export declare function isJsExt(path: string): boolean;
3
+ export declare function isJsLoader(loader?: string): boolean;
4
+ export declare function isTsExt(path: string): boolean;
5
+ export declare function isTsLoader(loader?: string): boolean;
@@ -0,0 +1,50 @@
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 assert_exports = {};
20
+ __export(assert_exports, {
21
+ isJsExt: () => isJsExt,
22
+ isJsLoader: () => isJsLoader,
23
+ isStyleExt: () => isStyleExt,
24
+ isTsExt: () => isTsExt,
25
+ isTsLoader: () => isTsLoader
26
+ });
27
+ module.exports = __toCommonJS(assert_exports);
28
+ function isStyleExt(path) {
29
+ return /\.(c|le|sa|sc)ss(\?.*)?$/.test(path);
30
+ }
31
+ function isJsExt(path) {
32
+ return /\.(m|c)?(j|t)sx?(\?.*)?$/.test(path);
33
+ }
34
+ function isJsLoader(loader) {
35
+ return loader === "js" || loader === "ts" || loader === "tsx" || loader === "jsx";
36
+ }
37
+ function isTsExt(path) {
38
+ return /\.(m|c)?tsx?(\?.*)?$/.test(path);
39
+ }
40
+ function isTsLoader(loader) {
41
+ return loader === "ts" || loader === "tsx";
42
+ }
43
+ // Annotate the CommonJS export names for ESM import in node:
44
+ 0 && (module.exports = {
45
+ isJsExt,
46
+ isJsLoader,
47
+ isStyleExt,
48
+ isTsExt,
49
+ isTsLoader
50
+ });
@@ -1,4 +1,10 @@
1
- import type { ExternalHelpers, BuildType, Format, Target } from '../types/config';
1
+ import type { ExternalHelpers } from '../types/config';
2
+ type Query = Record<string, string | boolean>;
3
+ type ResolveResult = {
4
+ originalFilePath: string;
5
+ query: Query;
6
+ rawQuery?: string;
7
+ };
2
8
  export declare const getAllDeps: <T>(appDirectory: string, options?: {
3
9
  dependencies?: boolean;
4
10
  devDependencies?: boolean;
@@ -8,16 +14,6 @@ export declare const checkSwcHelpers: (options: {
8
14
  appDirectory: string;
9
15
  externalHelpers: ExternalHelpers;
10
16
  }) => Promise<void>;
11
- export declare const matchSwcTransformCondition: (condtionOptions: {
12
- sourceType: 'commonjs' | 'module';
13
- buildType: BuildType;
14
- format: Format;
15
- disableSwcTransform?: boolean;
16
- }) => boolean;
17
- export declare const matchEs5PluginCondition: (condtionOptions: {
18
- sourceType: 'commonjs' | 'module';
19
- buildType: BuildType;
20
- format: Format;
21
- target: Target;
22
- disableSwcTransform?: boolean;
23
- }) => boolean;
17
+ export declare const normalizeSlashes: (file: string) => string;
18
+ export declare const resolvePathAndQuery: (originalPath: string) => ResolveResult;
19
+ export {};
@@ -1,35 +1,45 @@
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
- getAllDeps: function() {
14
- return getAllDeps;
15
- },
16
- checkSwcHelpers: function() {
17
- return checkSwcHelpers;
18
- },
19
- matchSwcTransformCondition: function() {
20
- return matchSwcTransformCondition;
21
- },
22
- matchEs5PluginCondition: function() {
23
- return matchEs5PluginCondition;
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 });
24
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 builder_exports = {};
30
+ __export(builder_exports, {
31
+ checkSwcHelpers: () => checkSwcHelpers,
32
+ getAllDeps: () => getAllDeps,
33
+ normalizeSlashes: () => normalizeSlashes,
34
+ resolvePathAndQuery: () => resolvePathAndQuery
25
35
  });
26
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
27
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
28
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
29
- const _utils = require("@modern-js/utils");
36
+ module.exports = __toCommonJS(builder_exports);
37
+ var import_path = __toESM(require("path"));
38
+ var import_querystring = __toESM(require("querystring"));
39
+ var import_utils = require("@modern-js/utils");
30
40
  const getAllDeps = async (appDirectory, options = {}) => {
31
41
  try {
32
- const json = JSON.parse(_utils.fs.readFileSync(_path.default.resolve(appDirectory, "./package.json"), "utf8"));
42
+ const json = JSON.parse(import_utils.fs.readFileSync(import_path.default.resolve(appDirectory, "./package.json"), "utf8"));
33
43
  let deps = [];
34
44
  if (options.dependencies) {
35
45
  deps = [
@@ -51,7 +61,7 @@ const getAllDeps = async (appDirectory, options = {}) => {
51
61
  }
52
62
  return deps;
53
63
  } catch (e) {
54
- _utils.logger.warn("package.json is broken");
64
+ import_utils.logger.warn("package.json is broken");
55
65
  return [];
56
66
  }
57
67
  };
@@ -66,41 +76,31 @@ const checkSwcHelpers = async (options) => {
66
76
  });
67
77
  const swcHelpersPkgName = "@swc/helpers";
68
78
  if (!deps.includes(swcHelpersPkgName)) {
69
- const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../locale")));
79
+ const local = await Promise.resolve().then(() => __toESM(require("../locale")));
70
80
  throw new Error(local.i18n.t(local.localeKeys.errors.externalHelpers));
71
81
  }
72
82
  };
73
- const matchSwcTransformCondition = (condtionOptions) => {
74
- const { sourceType, buildType, format, disableSwcTransform } = condtionOptions;
75
- if (disableSwcTransform) {
76
- return false;
77
- }
78
- if (sourceType === "commonjs") {
79
- return false;
80
- }
81
- if (buildType === "bundleless") {
82
- return true;
83
- }
84
- if (format === "esm" || format === "iife") {
85
- return true;
86
- }
87
- return false;
83
+ const normalizeSlashes = (file) => {
84
+ return file.split(import_path.default.win32.sep).join("/");
88
85
  };
89
- const matchEs5PluginCondition = (condtionOptions) => {
90
- const { sourceType, buildType, format, target, disableSwcTransform } = condtionOptions;
91
- if (target !== "es5") {
92
- return false;
93
- }
94
- if (disableSwcTransform) {
95
- return true;
96
- }
97
- if (sourceType === "commonjs") {
98
- return true;
99
- }
100
- if (buildType === "bundle" && format === "cjs") {
101
- return true;
86
+ const resolvePathAndQuery = (originalPath) => {
87
+ const [filePath, queryStr] = originalPath.split("?");
88
+ const query = import_querystring.default.parse(queryStr !== null && queryStr !== void 0 ? queryStr : "");
89
+ for (const key of Object.keys(query)) {
90
+ if (query[key] === "") {
91
+ query[key] = true;
92
+ }
102
93
  }
103
- return false;
94
+ return {
95
+ query,
96
+ originalFilePath: filePath,
97
+ rawQuery: queryStr
98
+ };
104
99
  };
105
-
106
- //# sourceMappingURL=builder.js.map
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ checkSwcHelpers,
103
+ getAllDeps,
104
+ normalizeSlashes,
105
+ resolvePathAndQuery
106
+ });
@@ -1,5 +1,5 @@
1
1
  /**
2
- * transform ['a', 'b'] to {a: undefined, b: undefined}
2
+ * transform ['a', 'b'] to { a: undefined, b: undefined }
3
3
  */
4
4
  export declare const transformUndefineObject: (arr: string[]) => Record<string, undefined>;
5
5
  export declare function mapValue<T = any, U = any>(obj: Record<string, T>, mapper: (x: T) => U): Record<string, U>;
@@ -1,22 +1,27 @@
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
- transformUndefineObject: function() {
14
- return transformUndefineObject;
15
- },
16
- mapValue: function() {
17
- return mapValue;
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 common_exports = {};
20
+ __export(common_exports, {
21
+ mapValue: () => mapValue,
22
+ transformUndefineObject: () => transformUndefineObject
19
23
  });
24
+ module.exports = __toCommonJS(common_exports);
20
25
  const transformUndefineObject = (arr) => {
21
26
  return arr.reduce((o, key) => {
22
27
  return {
@@ -31,5 +36,8 @@ function mapValue(obj, mapper) {
31
36
  mapper(value)
32
37
  ]));
33
38
  }
34
-
35
- //# sourceMappingURL=common.js.map
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ mapValue,
42
+ transformUndefineObject
43
+ });
@@ -1,20 +1,37 @@
1
- import type { ITsconfig, BundlelessGeneratorDtsConfig, BuildType, TsTarget } from '../types';
1
+ import type { ITsconfig, GeneratorDtsConfig, BuildType, TsTarget } from '../types';
2
2
  export declare const getProjectTsconfig: (tsconfigPath: string) => Promise<ITsconfig>;
3
- export declare const generatorTsConfig: (config: BundlelessGeneratorDtsConfig) => Promise<{
3
+ export declare const generateDtsInfo: (config: GeneratorDtsConfig) => Promise<{
4
4
  userTsconfig: ITsconfig;
5
- generatedTsconfig: {
6
- tempTsconfigPath: string;
7
- tempDistAbsRootPath: string;
8
- tempDistAbsSrcPath: string;
9
- };
5
+ tempTsconfigPath: string;
6
+ tempDistAbsRootPath: string;
7
+ tempDistAbsSrcPath: string;
10
8
  }>;
11
9
  export declare const getTscBinPath: (appDirectory: string) => Promise<string>;
12
- export declare const resolveAlias: (config: BundlelessGeneratorDtsConfig, options: {
10
+ export declare const resolveAlias: (config: GeneratorDtsConfig, options: {
11
+ userTsconfig: ITsconfig;
12
+ tempTsconfigPath: string;
13
+ tempDistAbsRootPath: string;
14
+ tempDistAbsSrcPath: string;
15
+ }, watchFilenames?: string[]) => Promise<{
16
+ path: string;
17
+ content: string;
18
+ }[]>;
19
+ export declare const writeDtsFiles: (config: GeneratorDtsConfig, options: {
13
20
  userTsconfig: ITsconfig;
14
21
  tempTsconfigPath: string;
15
22
  tempDistAbsRootPath: string;
16
23
  tempDistAbsSrcPath: string;
17
- }, watchFilenames?: string[]) => Promise<void>;
24
+ }, result: {
25
+ path: string;
26
+ content: string;
27
+ }[]) => Promise<void>;
28
+ export declare const addBannerAndFooter: (result: {
29
+ path: string;
30
+ content: string;
31
+ }[], banner?: string, footer?: string) => {
32
+ path: string;
33
+ content: string;
34
+ }[];
18
35
  export declare const printOrThrowDtsErrors: (error: unknown, options: {
19
36
  abortOnError?: boolean;
20
37
  buildType: BuildType;
package/dist/utils/dts.js CHANGED
@@ -1,60 +1,69 @@
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
- getProjectTsconfig: function() {
14
- return getProjectTsconfig;
15
- },
16
- generatorTsConfig: function() {
17
- return generatorTsConfig;
18
- },
19
- getTscBinPath: function() {
20
- return getTscBinPath;
21
- },
22
- resolveAlias: function() {
23
- return resolveAlias;
24
- },
25
- printOrThrowDtsErrors: function() {
26
- return printOrThrowDtsErrors;
27
- },
28
- tsTargetAtOrAboveES2022: function() {
29
- return tsTargetAtOrAboveES2022;
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 });
30
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 dts_exports = {};
30
+ __export(dts_exports, {
31
+ addBannerAndFooter: () => addBannerAndFooter,
32
+ generateDtsInfo: () => generateDtsInfo,
33
+ getProjectTsconfig: () => getProjectTsconfig,
34
+ getTscBinPath: () => getTscBinPath,
35
+ printOrThrowDtsErrors: () => printOrThrowDtsErrors,
36
+ resolveAlias: () => resolveAlias,
37
+ tsTargetAtOrAboveES2022: () => tsTargetAtOrAboveES2022,
38
+ writeDtsFiles: () => writeDtsFiles
31
39
  });
32
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
33
- const _path = require("path");
34
- const _utils = require("@modern-js/utils");
40
+ module.exports = __toCommonJS(dts_exports);
41
+ var import_path = require("path");
42
+ var import_utils = require("@modern-js/utils");
43
+ var import_magic_string = __toESM(require("magic-string"));
35
44
  const getProjectTsconfig = async (tsconfigPath) => {
36
- if (!_utils.fs.existsSync(tsconfigPath)) {
45
+ if (!import_utils.fs.existsSync(tsconfigPath)) {
37
46
  return {};
38
47
  }
39
- return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, "utf-8"));
48
+ return import_utils.json5.parse(import_utils.fs.readFileSync(tsconfigPath, "utf-8"));
40
49
  };
41
- const generatorTsConfig = async (config) => {
42
- var _userTsconfig_references, _userTsconfig;
50
+ const generateDtsInfo = async (config) => {
51
+ var _userTsconfig_references;
43
52
  const { appDirectory, sourceDir: absSourceDir, tsconfigPath } = config;
44
53
  const userTsconfig = await getProjectTsconfig(tsconfigPath);
45
- const { dtsTempDirectory } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../constants/dts")));
46
- const tempDistAbsRootPath = (0, _path.join)(appDirectory, `${dtsTempDirectory}/${(0, _utils.nanoid)()}`);
47
- const tempDistAbsOurDir = (0, _path.join)(tempDistAbsRootPath, (0, _path.relative)(appDirectory, absSourceDir));
48
- const tempTsconfigPath = (0, _path.join)(tempDistAbsRootPath, (0, _path.basename)(tsconfigPath));
49
- _utils.fs.ensureFileSync(tempTsconfigPath);
50
- const extendsPath = (0, _path.join)((0, _path.relative)((0, _path.dirname)(tempTsconfigPath), (0, _path.dirname)(tsconfigPath)), (0, _path.basename)(tempTsconfigPath));
51
- const references = (_userTsconfig = userTsconfig) === null || _userTsconfig === void 0 ? void 0 : (_userTsconfig_references = _userTsconfig.references) === null || _userTsconfig_references === void 0 ? void 0 : _userTsconfig_references.map((reference) => {
54
+ const { dtsTempDirectory } = await Promise.resolve().then(() => __toESM(require("../constants/dts")));
55
+ const tempDistAbsRootPath = (0, import_path.join)(appDirectory, `${dtsTempDirectory}/${(0, import_utils.nanoid)()}`);
56
+ const tempDistAbsOurDir = (0, import_path.join)(tempDistAbsRootPath, (0, import_path.relative)(appDirectory, absSourceDir));
57
+ const tempTsconfigPath = (0, import_path.join)(tempDistAbsRootPath, (0, import_path.basename)(tsconfigPath));
58
+ import_utils.fs.ensureFileSync(tempTsconfigPath);
59
+ const extendsPath = (0, import_path.join)((0, import_path.relative)((0, import_path.dirname)(tempTsconfigPath), (0, import_path.dirname)(tsconfigPath)), (0, import_path.basename)(tempTsconfigPath));
60
+ const references = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_references = userTsconfig.references) === null || _userTsconfig_references === void 0 ? void 0 : _userTsconfig_references.map((reference) => {
52
61
  const { path } = reference;
53
62
  if (path) {
54
- const userTsconfigDir = (0, _path.dirname)(tsconfigPath);
55
- const generatedTsconfigDir = (0, _path.dirname)(tempTsconfigPath);
63
+ const userTsconfigDir = (0, import_path.dirname)(tsconfigPath);
64
+ const generatedTsconfigDir = (0, import_path.dirname)(tempTsconfigPath);
56
65
  return {
57
- path: (0, _path.isAbsolute)(path) ? path : (0, _path.relative)(generatedTsconfigDir, (0, _path.resolve)(userTsconfigDir, path))
66
+ path: (0, import_path.isAbsolute)(path) ? path : (0, import_path.relative)(generatedTsconfigDir, (0, import_path.resolve)(userTsconfigDir, path))
58
67
  };
59
68
  }
60
69
  return reference;
@@ -74,20 +83,18 @@ const generatorTsConfig = async (config) => {
74
83
  },
75
84
  references
76
85
  };
77
- _utils.fs.writeJSONSync(tempTsconfigPath, resetConfig);
86
+ import_utils.fs.writeJSONSync(tempTsconfigPath, resetConfig);
78
87
  return {
79
88
  userTsconfig,
80
- generatedTsconfig: {
81
- tempTsconfigPath,
82
- tempDistAbsRootPath,
83
- tempDistAbsSrcPath: tempDistAbsOurDir
84
- }
89
+ tempTsconfigPath,
90
+ tempDistAbsRootPath,
91
+ tempDistAbsSrcPath: tempDistAbsOurDir
85
92
  };
86
93
  };
87
94
  const getTscBinPath = async (appDirectory) => {
88
- const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../../compiled/find-up")));
95
+ const { default: findUp, exists: pathExists } = await Promise.resolve().then(() => __toESM(require("../../compiled/find-up")));
89
96
  const tscBinFile = await findUp(async (directory) => {
90
- const targetFilePath = (0, _path.join)(directory, "./node_modules/.bin/tsc");
97
+ const targetFilePath = (0, import_path.join)(directory, "./node_modules/.bin/tsc");
91
98
  const hasTscBinFile = await pathExists(targetFilePath);
92
99
  if (hasTscBinFile) {
93
100
  return targetFilePath;
@@ -96,7 +103,7 @@ const getTscBinPath = async (appDirectory) => {
96
103
  }, {
97
104
  cwd: appDirectory
98
105
  });
99
- if (!tscBinFile || !_utils.fs.existsSync(tscBinFile)) {
106
+ if (!tscBinFile || !import_utils.fs.existsSync(tscBinFile)) {
100
107
  throw new Error("Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.");
101
108
  }
102
109
  return tscBinFile;
@@ -104,10 +111,9 @@ const getTscBinPath = async (appDirectory) => {
104
111
  const resolveAlias = async (config, options, watchFilenames = []) => {
105
112
  var _userTsconfig_compilerOptions;
106
113
  const { userTsconfig, tempDistAbsSrcPath, tempDistAbsRootPath } = options;
107
- const { transformDtsAlias } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./tspathsTransform")));
108
- const { distAbsPath } = config;
109
- const dtsDistPath = `${tempDistAbsSrcPath}/**/*.d.ts`;
110
- const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : _utils.globby.sync(dtsDistPath, {
114
+ const { transformDtsAlias } = await Promise.resolve().then(() => __toESM(require("./tspath")));
115
+ const dtsDistPath = `${(0, import_utils.slash)(tempDistAbsSrcPath)}/**/*.d.ts`;
116
+ const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : import_utils.globby.sync(dtsDistPath, {
111
117
  absolute: true
112
118
  });
113
119
  var _userTsconfig_compilerOptions_paths;
@@ -116,15 +122,34 @@ const resolveAlias = async (config, options, watchFilenames = []) => {
116
122
  baseUrl: tempDistAbsRootPath,
117
123
  paths: (_userTsconfig_compilerOptions_paths = (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.paths) !== null && _userTsconfig_compilerOptions_paths !== void 0 ? _userTsconfig_compilerOptions_paths : {}
118
124
  });
125
+ return result;
126
+ };
127
+ const writeDtsFiles = async (config, options, result) => {
128
+ const { distPath } = config;
129
+ const { tempDistAbsSrcPath } = options;
119
130
  for (const r of result) {
120
- _utils.fs.writeFileSync(r.path, r.content);
131
+ import_utils.fs.writeFileSync(r.path, r.content);
121
132
  }
122
- await _utils.fs.ensureDir(distAbsPath);
123
- await _utils.fs.copy(tempDistAbsSrcPath, distAbsPath);
133
+ await import_utils.fs.ensureDir(distPath);
134
+ await import_utils.fs.copy(tempDistAbsSrcPath, distPath);
135
+ };
136
+ const addBannerAndFooter = (result, banner, footer) => {
137
+ return result.map(({ path, content }) => {
138
+ const ms = new import_magic_string.default(content);
139
+ banner && ms.prepend(`${banner}
140
+ `);
141
+ footer && ms.append(`
142
+ ${footer}
143
+ `);
144
+ return {
145
+ path,
146
+ content: ms.toString()
147
+ };
148
+ });
124
149
  };
125
150
  const printOrThrowDtsErrors = async (error, options) => {
126
- const { InternalDTSError } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../error")));
127
- const local = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../locale")));
151
+ const { InternalDTSError } = await Promise.resolve().then(() => __toESM(require("../error")));
152
+ const local = await Promise.resolve().then(() => __toESM(require("../locale")));
128
153
  const { abortOnError, buildType } = options !== null && options !== void 0 ? options : {};
129
154
  if (error instanceof Error) {
130
155
  if (abortOnError) {
@@ -132,13 +157,22 @@ const printOrThrowDtsErrors = async (error, options) => {
132
157
  buildType
133
158
  });
134
159
  } else {
135
- _utils.logger.warn(_utils.chalk.bgYellowBright(local.i18n.t(local.localeKeys.warns.dts.abortOnError)));
136
- _utils.logger.error(new InternalDTSError(error, {
160
+ import_utils.logger.warn(import_utils.chalk.bgYellowBright(local.i18n.t(local.localeKeys.warns.dts.abortOnError)));
161
+ import_utils.logger.error(new InternalDTSError(error, {
137
162
  buildType
138
163
  }));
139
164
  }
140
165
  }
141
166
  };
142
167
  const tsTargetAtOrAboveES2022 = (target) => target === "es2022" || target === "esnext";
143
-
144
- //# sourceMappingURL=dts.js.map
168
+ // Annotate the CommonJS export names for ESM import in node:
169
+ 0 && (module.exports = {
170
+ addBannerAndFooter,
171
+ generateDtsInfo,
172
+ getProjectTsconfig,
173
+ getTscBinPath,
174
+ printOrThrowDtsErrors,
175
+ resolveAlias,
176
+ tsTargetAtOrAboveES2022,
177
+ writeDtsFiles
178
+ });
@@ -0,0 +1,2 @@
1
+ /// <reference types="node" />
2
+ export declare function getHash(content: Buffer | string, encoding: any, type?: string): string;