@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,115 @@
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 watch_exports = {};
30
+ __export(watch_exports, {
31
+ initWatcher: () => initWatcher
32
+ });
33
+ module.exports = __toCommonJS(watch_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ const initWatcher = (compiler) => {
37
+ const { config, api } = compiler;
38
+ const watch = import_utils.chokidar.watch([
39
+ compiler.context.root
40
+ ], {
41
+ useFsEvents: false,
42
+ ignored: [
43
+ "**/node_modules",
44
+ "**/.gitignore",
45
+ "**/.git",
46
+ compiler.config.outDir
47
+ ],
48
+ cwd: compiler.context.root
49
+ });
50
+ compiler.watcher = watch;
51
+ let running = false;
52
+ let needReRun = false;
53
+ const handleLink = async (filePath, type) => {
54
+ const { config: config2, context: { root } } = compiler;
55
+ const { buildType, input, sourceDir } = config2;
56
+ const absFilePath = import_path.default.resolve(root, filePath);
57
+ let shouldRebuild = false;
58
+ if (buildType === "bundleless" && Array.isArray(input)) {
59
+ if (type === "add") {
60
+ shouldRebuild = absFilePath.startsWith(sourceDir);
61
+ } else {
62
+ shouldRebuild = input.some((item) => item === filePath);
63
+ }
64
+ }
65
+ if (shouldRebuild) {
66
+ const text = type === "add" ? "added" : "unlinked";
67
+ import_utils.logger.info(`${import_utils.chalk.underline(filePath)} ${text}`);
68
+ if (type === "unlink") {
69
+ input.splice(input.indexOf(filePath), 1);
70
+ } else {
71
+ input.push(filePath);
72
+ }
73
+ if (running) {
74
+ needReRun = true;
75
+ } else {
76
+ running = true;
77
+ await compiler.reBuild("link", config2);
78
+ running = false;
79
+ if (needReRun) {
80
+ needReRun = false;
81
+ await compiler.reBuild("link", config2);
82
+ }
83
+ }
84
+ }
85
+ };
86
+ const handleAdd = async (filePath) => {
87
+ return handleLink(filePath, "add");
88
+ };
89
+ const handleUnlink = async (filePath) => {
90
+ return handleLink(filePath, "unlink");
91
+ };
92
+ const handleChange = async (filePath, _events) => {
93
+ const { context: { root }, watchedFiles } = compiler;
94
+ if (watchedFiles.has(import_path.default.resolve(root, filePath))) {
95
+ import_utils.logger.info(`File changed: ${import_utils.chalk.dim(filePath)}`);
96
+ const runner = api.useHookRunners();
97
+ runner.buildWatchJs({
98
+ buildConfig: config
99
+ });
100
+ await compiler.reBuild("change", config);
101
+ }
102
+ };
103
+ watch.on("ready", () => {
104
+ watch.on("change", handleChange);
105
+ watch.on("add", handleAdd);
106
+ watch.on("unlink", handleUnlink);
107
+ });
108
+ watch.once("restart", () => {
109
+ watch.removeListener("change", handleChange);
110
+ });
111
+ };
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ initWatcher
115
+ });
@@ -0,0 +1,2 @@
1
+ import { ICompiler } from '../../types';
2
+ export declare const writeFile: (compiler: ICompiler) => Promise<void>;
@@ -0,0 +1,89 @@
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 write_file_exports = {};
30
+ __export(write_file_exports, {
31
+ writeFile: () => writeFile
32
+ });
33
+ module.exports = __toCommonJS(write_file_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ var import_convert_source_map = __toESM(require("convert-source-map"));
37
+ const SOURCE_MAPPING_URL = "sourceMappingURL";
38
+ let preOutputChunk = null;
39
+ function appendSourceMapURLLink(options) {
40
+ return `${options.code}
41
+ //# ${SOURCE_MAPPING_URL}=${options.filename}.map`;
42
+ }
43
+ function appendSourceMapInline(options) {
44
+ return `${options.code}
45
+ //# ${SOURCE_MAPPING_URL}=data:application/json;charset=utf-8;base64,${options.map}`;
46
+ }
47
+ function chunkHasChanged(key, chunk) {
48
+ if (preOutputChunk) {
49
+ const preChunk = preOutputChunk.get(key);
50
+ if (preChunk && preChunk.contents === chunk.contents) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ const writeFile = async (compiler) => {
57
+ for (const [key, value] of compiler.outputChunk.entries()) {
58
+ if (!chunkHasChanged(key, value)) {
59
+ continue;
60
+ }
61
+ const absPath = import_path.default.resolve(compiler.config.outDir, key);
62
+ await import_utils.fs.ensureDir(import_path.default.dirname(absPath));
63
+ if (value.type === "chunk" && value.map) {
64
+ if (compiler.config.sourceMap === false || compiler.config.sourceMap === "external") {
65
+ await import_utils.fs.writeFile(absPath, value.contents);
66
+ } else if (compiler.config.sourceMap === true) {
67
+ await import_utils.fs.writeFile(absPath, appendSourceMapURLLink({
68
+ code: value.contents,
69
+ filename: import_path.default.basename(absPath)
70
+ }));
71
+ } else if (compiler.config.sourceMap === "inline") {
72
+ await import_utils.fs.writeFile(absPath, appendSourceMapInline({
73
+ code: value.contents,
74
+ map: import_convert_source_map.default.fromObject(value.map).toBase64()
75
+ }));
76
+ }
77
+ if (compiler.config.sourceMap === true || compiler.config.sourceMap === "external") {
78
+ await import_utils.fs.writeFile(`${absPath}.map`, JSON.stringify(value.map));
79
+ }
80
+ } else {
81
+ await import_utils.fs.writeFile(absPath, value.contents);
82
+ }
83
+ }
84
+ preOutputChunk = compiler.outputChunk;
85
+ };
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ writeFile
89
+ });
@@ -0,0 +1,19 @@
1
+ /// <reference types="node" />
2
+ import { ICompiler, LoadResult, SvgrOptions } from '../../types';
3
+ export declare const asset: {
4
+ name: string;
5
+ apply(compiler: ICompiler): void;
6
+ };
7
+ /**
8
+ *
9
+ * @param this Compiler
10
+ * @param assetPath Absolute path of the asset
11
+ * @param rebaseFrom Absolute path of the file which use asset
12
+ * @param calledOnLoad called in load hooks
13
+ * @returns dataurl or path
14
+ */
15
+ export declare function getAssetContents(this: ICompiler, assetPath: string, rebaseFrom: string, calledOnLoad?: boolean): Promise<{
16
+ contents: string | Buffer;
17
+ loader: "copy" | "text";
18
+ }>;
19
+ export declare function loadSvgr(path: string, options: boolean | SvgrOptions): Promise<LoadResult | undefined>;
@@ -0,0 +1,149 @@
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 name2 in all)
10
+ __defProp(target, name2, { get: all[name2], 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 asset_exports = {};
30
+ __export(asset_exports, {
31
+ asset: () => asset,
32
+ getAssetContents: () => getAssetContents,
33
+ loadSvgr: () => loadSvgr
34
+ });
35
+ module.exports = __toCommonJS(asset_exports);
36
+ var import_path = require("path");
37
+ var import_fs = __toESM(require("fs"));
38
+ var import_pluginutils = require("@rollup/pluginutils");
39
+ var import_core = require("@svgr/core");
40
+ var import_plugin_svgo = __toESM(require("@svgr/plugin-svgo"));
41
+ var import_plugin_jsx = __toESM(require("@svgr/plugin-jsx"));
42
+ var import_file = require("../../constants/file");
43
+ var import_utils = require("../../utils");
44
+ const name = "asset";
45
+ const SVG_REGEXP = /\.svg$/;
46
+ const asset = {
47
+ name,
48
+ apply(compiler) {
49
+ compiler.hooks.load.tapPromise({
50
+ name
51
+ }, async (args) => {
52
+ if (import_file.assetExt.find((ext) => ext === (0, import_path.extname)(args.path))) {
53
+ const { buildType, outDir, sourceDir, asset: asset2 } = compiler.config;
54
+ const svgrResult = await loadSvgr(args.path, asset2.svgr);
55
+ if (svgrResult) {
56
+ return svgrResult;
57
+ }
58
+ const rebaseFrom = buildType === "bundle" ? outDir : (0, import_path.join)(outDir, (0, import_path.relative)(sourceDir, (0, import_path.dirname)(args.path)));
59
+ const { contents, loader } = await getAssetContents.apply(compiler, [
60
+ args.path,
61
+ rebaseFrom,
62
+ true
63
+ ]);
64
+ return {
65
+ contents,
66
+ loader
67
+ };
68
+ }
69
+ });
70
+ }
71
+ };
72
+ function encodeSVG(buffer) {
73
+ return encodeURIComponent(buffer.toString("utf-8").replace(/[\n\r]/gim, "").replace(/\t/gim, " ").replace(/<!--(.*(?=-->))-->/gim, "").replace(/'/gim, "\\i")).replace(/\(/g, "%28").replace(/\)/g, "%29");
74
+ }
75
+ async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
76
+ const fileContent = await import_fs.default.promises.readFile(assetPath);
77
+ const { buildType, format, outDir } = this.config;
78
+ const { limit, path, publicPath } = this.config.asset;
79
+ const hash = (0, import_utils.getHash)(fileContent, null).slice(0, 8);
80
+ const outputFileName = (0, import_path.basename)(assetPath).split(".").join(`.${hash}.`);
81
+ const outputFilePath = (0, import_path.resolve)(outDir, path, outputFileName);
82
+ const relativePath = (0, import_path.relative)(rebaseFrom, outputFilePath);
83
+ const normalizedRelativePath = (0, import_utils.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
84
+ const normalizedPublicPath = `${typeof publicPath === "function" ? publicPath(assetPath) : publicPath}${path}/${outputFileName}`;
85
+ let emitAsset = true;
86
+ let contents = normalizedPublicPath;
87
+ let loader = "text";
88
+ if (buildType === "bundle") {
89
+ if (fileContent.length <= limit) {
90
+ const mimetype = (await Promise.resolve().then(() => __toESM(require("@modern-js/utils/mime-types")))).default.lookup(assetPath);
91
+ const isSVG = mimetype === "image/svg+xml";
92
+ const data = isSVG ? encodeSVG(fileContent) : fileContent.toString("base64");
93
+ const encoding = isSVG ? "" : ";base64";
94
+ contents = `data:${mimetype}${encoding},${data}`;
95
+ loader = "text";
96
+ emitAsset = false;
97
+ } else if ((format === "esm" || format === "cjs") && !publicPath) {
98
+ contents = calledOnLoad ? fileContent : normalizedRelativePath;
99
+ loader = calledOnLoad ? "copy" : "text";
100
+ emitAsset = !calledOnLoad;
101
+ }
102
+ } else {
103
+ contents = normalizedRelativePath;
104
+ }
105
+ if (emitAsset) {
106
+ this.emitAsset(outputFilePath, {
107
+ type: "asset",
108
+ fileName: outputFilePath,
109
+ contents: fileContent,
110
+ originalFileName: assetPath
111
+ });
112
+ }
113
+ return {
114
+ contents,
115
+ loader
116
+ };
117
+ }
118
+ async function loadSvgr(path, options) {
119
+ if (!options) {
120
+ return;
121
+ }
122
+ const config = typeof options === "boolean" ? {} : options;
123
+ const filter = (0, import_pluginutils.createFilter)(config.include || SVG_REGEXP, config.exclude);
124
+ if (!filter(path)) {
125
+ return;
126
+ }
127
+ const loader = "jsx";
128
+ const text = import_fs.default.readFileSync(path, "utf8");
129
+ const jsCode = await (0, import_core.transform)(text, config, {
130
+ filePath: path,
131
+ caller: {
132
+ name: "svgr",
133
+ defaultPlugins: [
134
+ import_plugin_svgo.default,
135
+ import_plugin_jsx.default
136
+ ]
137
+ }
138
+ });
139
+ return {
140
+ contents: jsCode,
141
+ loader
142
+ };
143
+ }
144
+ // Annotate the CommonJS export names for ESM import in node:
145
+ 0 && (module.exports = {
146
+ asset,
147
+ getAssetContents,
148
+ loadSvgr
149
+ });
@@ -0,0 +1,5 @@
1
+ import { ICompiler } from '../../types';
2
+ export declare const formatCjs: {
3
+ name: string;
4
+ apply: (compiler: ICompiler) => void;
5
+ };
@@ -0,0 +1,53 @@
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 name2 in all)
8
+ __defProp(target, name2, { get: all[name2], 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 format_cjs_exports = {};
20
+ __export(format_cjs_exports, {
21
+ formatCjs: () => formatCjs
22
+ });
23
+ module.exports = __toCommonJS(format_cjs_exports);
24
+ var import_sucrase = require("sucrase");
25
+ const name = "format-cjs";
26
+ const apply = (compiler) => {
27
+ compiler.hooks.renderChunk.tapPromise({
28
+ name
29
+ }, async (chunk) => {
30
+ if (chunk.fileName.endsWith(".js") && chunk.type === "chunk") {
31
+ const code = chunk.contents.toString();
32
+ const result = (0, import_sucrase.transform)(code, {
33
+ transforms: [
34
+ "imports"
35
+ ]
36
+ });
37
+ return {
38
+ ...chunk,
39
+ contents: result.code,
40
+ map: result.sourceMap
41
+ };
42
+ }
43
+ return chunk;
44
+ });
45
+ };
46
+ const formatCjs = {
47
+ name,
48
+ apply
49
+ };
50
+ // Annotate the CommonJS export names for ESM import in node:
51
+ 0 && (module.exports = {
52
+ formatCjs
53
+ });
@@ -0,0 +1,2 @@
1
+ import { HookList, Context } from '../../types';
2
+ export declare function getInternalList(context: Context): Promise<HookList>;
@@ -0,0 +1,74 @@
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 feature_exports = {};
30
+ __export(feature_exports, {
31
+ getInternalList: () => getInternalList
32
+ });
33
+ module.exports = __toCommonJS(feature_exports);
34
+ var import_dts = require("../../utils/dts");
35
+ var import_format_cjs = require("./format-cjs");
36
+ var import_style = require("./style");
37
+ var import_terser = require("./terser");
38
+ var import_asset = require("./asset");
39
+ async function getInternalList(context) {
40
+ var _userTsconfig_compilerOptions;
41
+ const internal = [];
42
+ const { config } = context;
43
+ internal.push(import_asset.asset, import_style.css);
44
+ if (config.buildType === "bundle" && config.format === "cjs" && config.splitting) {
45
+ internal.push(import_format_cjs.formatCjs);
46
+ }
47
+ if (config.buildType === "bundleless") {
48
+ const { redirect } = await Promise.resolve().then(() => __toESM(require("./redirect")));
49
+ const { json } = await Promise.resolve().then(() => __toESM(require("./json")));
50
+ internal.push(redirect, json);
51
+ }
52
+ const userTsconfig = await (0, import_dts.getProjectTsconfig)(context.config.tsconfig);
53
+ var _userTsconfig_compilerOptions_emitDecoratorMetadata;
54
+ const emitDecoratorMetadata = (_userTsconfig_compilerOptions_emitDecoratorMetadata = userTsconfig === null || userTsconfig === void 0 ? void 0 : (_userTsconfig_compilerOptions = userTsconfig.compilerOptions) === null || _userTsconfig_compilerOptions === void 0 ? void 0 : _userTsconfig_compilerOptions.emitDecoratorMetadata) !== null && _userTsconfig_compilerOptions_emitDecoratorMetadata !== void 0 ? _userTsconfig_compilerOptions_emitDecoratorMetadata : false;
55
+ const { transformImport, transformLodash, externalHelpers, format, target } = context.config;
56
+ const enbaleSwcTransform = transformImport.length > 0 || transformLodash || externalHelpers || emitDecoratorMetadata;
57
+ const enableSwcRenderChunk = enbaleSwcTransform ? format === "umd" : format === "umd" || target === "es5";
58
+ if (enbaleSwcTransform) {
59
+ const { swcTransform } = await Promise.resolve().then(() => __toESM(require("./swc")));
60
+ internal.push(swcTransform(userTsconfig));
61
+ }
62
+ if (enableSwcRenderChunk) {
63
+ const { swcRenderChunk } = await Promise.resolve().then(() => __toESM(require("./swc")));
64
+ internal.push(swcRenderChunk);
65
+ }
66
+ if (config.minify && config.minify !== "esbuild") {
67
+ internal.push(import_terser.minify);
68
+ }
69
+ return internal;
70
+ }
71
+ // Annotate the CommonJS export names for ESM import in node:
72
+ 0 && (module.exports = {
73
+ getInternalList
74
+ });
@@ -0,0 +1,5 @@
1
+ import { ICompiler } from '../../types';
2
+ export declare const json: {
3
+ name: string;
4
+ apply(compiler: ICompiler): void;
5
+ };
@@ -0,0 +1,47 @@
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 name2 in all)
8
+ __defProp(target, name2, { get: all[name2], 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 json_exports = {};
20
+ __export(json_exports, {
21
+ json: () => json
22
+ });
23
+ module.exports = __toCommonJS(json_exports);
24
+ var import_fs = require("fs");
25
+ const isJsonExt = (path) => {
26
+ return path.endsWith(".json");
27
+ };
28
+ const name = "json";
29
+ const json = {
30
+ name,
31
+ apply(compiler) {
32
+ compiler.hooks.load.tapPromise({
33
+ name
34
+ }, async (args) => {
35
+ if (isJsonExt(args.path)) {
36
+ return {
37
+ contents: (0, import_fs.readFileSync)(args.path),
38
+ loader: "copy"
39
+ };
40
+ }
41
+ });
42
+ }
43
+ };
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ json
47
+ });
@@ -0,0 +1,5 @@
1
+ import { ICompiler } from '../../types';
2
+ export declare const redirect: {
3
+ name: string;
4
+ apply(compiler: ICompiler): void;
5
+ };