@modern-js/server-utils 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 (31) hide show
  1. package/dist/cjs/common/index.js +41 -22
  2. package/dist/cjs/compilers/babel/index.js +61 -66
  3. package/dist/cjs/compilers/babel/preset/alias.js +43 -17
  4. package/dist/cjs/compilers/babel/preset/index.js +60 -48
  5. package/dist/cjs/compilers/babel/preset/types.js +15 -3
  6. package/dist/cjs/compilers/typescript/index.js +51 -25
  7. package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +44 -18
  8. package/dist/cjs/compilers/typescript/typescriptLoader.js +27 -10
  9. package/dist/cjs/index.js +28 -10
  10. package/dist/esm/common/index.js +6 -2
  11. package/dist/esm/compilers/babel/index.js +18 -33
  12. package/dist/esm/compilers/babel/preset/alias.js +5 -2
  13. package/dist/esm/compilers/babel/preset/index.js +25 -31
  14. package/dist/esm/compilers/babel/preset/types.js +0 -1
  15. package/dist/esm/compilers/typescript/index.js +12 -9
  16. package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +4 -1
  17. package/dist/esm/compilers/typescript/typescriptLoader.js +4 -1
  18. package/dist/esm/index.js +4 -1
  19. package/dist/esm-node/common/index.js +6 -2
  20. package/dist/esm-node/compilers/babel/index.js +14 -31
  21. package/dist/esm-node/compilers/babel/preset/alias.js +5 -2
  22. package/dist/esm-node/compilers/babel/preset/index.js +25 -30
  23. package/dist/esm-node/compilers/babel/preset/types.js +0 -1
  24. package/dist/esm-node/compilers/typescript/index.js +4 -1
  25. package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +4 -1
  26. package/dist/esm-node/compilers/typescript/typescriptLoader.js +4 -1
  27. package/dist/esm-node/index.js +4 -1
  28. package/dist/types/compilers/babel/index.d.ts +0 -2
  29. package/dist/types/compilers/babel/preset/index.d.ts +2 -2
  30. package/dist/types/compilers/babel/preset/types.d.ts +0 -9
  31. package/package.json +10 -9
@@ -1,25 +1,39 @@
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
- FILE_EXTENSIONS: function() {
14
- return FILE_EXTENSIONS;
15
- },
16
- compile: function() {
17
- return compile;
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 });
18
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 common_exports = {};
30
+ __export(common_exports, {
31
+ FILE_EXTENSIONS: () => FILE_EXTENSIONS,
32
+ compile: () => compile
19
33
  });
20
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
21
- const _path = /* @__PURE__ */ _interop_require_wildcard._(require("path"));
22
- const _utils = require("@modern-js/utils");
34
+ module.exports = __toCommonJS(common_exports);
35
+ var path = __toESM(require("path"));
36
+ var import_utils = require("@modern-js/utils");
23
37
  const FILE_EXTENSIONS = [
24
38
  ".js",
25
39
  ".ts",
@@ -27,7 +41,7 @@ const FILE_EXTENSIONS = [
27
41
  ".ejs"
28
42
  ];
29
43
  const validateAbsolutePath = (filename, message) => {
30
- if (!_path.isAbsolute(filename)) {
44
+ if (!path.isAbsolute(filename)) {
31
45
  throw new Error(message);
32
46
  }
33
47
  };
@@ -40,12 +54,17 @@ const compile = async (appDirectory, modernConfig, compileOptions) => {
40
54
  validateAbsolutePaths(sourceDirs, (dir) => `source dir ${dir} is not an absolute path.`);
41
55
  validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
42
56
  const compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_server = modernConfig.server) === null || _modernConfig_server === void 0 ? void 0 : _modernConfig_server.compiler;
43
- const isTsProject = tsconfigPath && await _utils.fs.pathExists(tsconfigPath);
57
+ const isTsProject = tsconfigPath && await import_utils.fs.pathExists(tsconfigPath);
44
58
  if (!isTsProject || compiler === "babel") {
45
- const { compileByBabel } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../compilers/babel")));
59
+ const { compileByBabel } = await Promise.resolve().then(() => __toESM(require("../compilers/babel")));
46
60
  await compileByBabel(appDirectory, modernConfig, compileOptions);
47
61
  } else {
48
- const { compileByTs } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("../compilers/typescript")));
62
+ const { compileByTs } = await Promise.resolve().then(() => __toESM(require("../compilers/typescript")));
49
63
  await compileByTs(appDirectory, modernConfig, compileOptions);
50
64
  }
51
65
  };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ FILE_EXTENSIONS,
69
+ compile
70
+ });
@@ -1,42 +1,52 @@
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
- readTsConfig: function() {
14
- return readTsConfig;
15
- },
16
- existTsConfigFile: function() {
17
- return existTsConfigFile;
18
- },
19
- resolveBabelConfig: function() {
20
- return resolveBabelConfig;
21
- },
22
- compileByBabel: function() {
23
- return compileByBabel;
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var babel_exports = {};
31
+ __export(babel_exports, {
32
+ compileByBabel: () => compileByBabel,
33
+ existTsConfigFile: () => existTsConfigFile,
34
+ readTsConfig: () => readTsConfig,
35
+ resolveBabelConfig: () => resolveBabelConfig
25
36
  });
26
- const _export_star = require("@swc/helpers/_/_export_star");
27
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
28
- const _path = /* @__PURE__ */ _interop_require_wildcard._(require("path"));
29
- const _utils = require("@modern-js/utils");
30
- const _babelcompiler = require("@modern-js/babel-compiler");
31
- const _common = require("../../common");
32
- const _preset = require("./preset");
33
- _export_star._(require("@babel/core"), exports);
37
+ module.exports = __toCommonJS(babel_exports);
38
+ var path = __toESM(require("path"));
39
+ var import_utils = require("@modern-js/utils");
40
+ var import_babel_compiler = require("@modern-js/babel-compiler");
41
+ var import_common = require("../../common");
42
+ var import_preset = require("./preset");
43
+ __reExport(babel_exports, require("@babel/core"), module.exports);
34
44
  const readTsConfig = (tsconfigPath, noExistReturn = null) => {
35
- if (!_utils.fs.existsSync(tsconfigPath)) {
45
+ if (!import_utils.fs.existsSync(tsconfigPath)) {
36
46
  return noExistReturn;
37
47
  }
38
- const content = _utils.fs.readFileSync(tsconfigPath, "utf-8");
39
- return _utils.json5.parse(content);
48
+ const content = import_utils.fs.readFileSync(tsconfigPath, "utf-8");
49
+ return import_utils.json5.parse(content);
40
50
  };
41
51
  const existTsConfigFile = (tsconfigAbsolutePath) => {
42
52
  const tsconfig = readTsConfig(tsconfigAbsolutePath);
@@ -44,60 +54,37 @@ const existTsConfigFile = (tsconfigAbsolutePath) => {
44
54
  };
45
55
  const resolveBabelConfig = (appDirectory, config, option) => {
46
56
  const { alias, babelConfig } = config;
47
- const aliasConfig = (0, _utils.getAliasConfig)(alias, {
57
+ const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
48
58
  appDirectory,
49
59
  ...option
50
60
  });
51
- const babelChain = (0, _preset.getBabelChain)({
61
+ const defaultBabelConfig = (0, import_preset.getBabelConfig)({
52
62
  appDirectory,
53
- enableReactPreset: true,
54
- enableTypescriptPreset: true,
55
63
  alias: aliasConfig
56
- }, {
57
- type: option.type,
58
- syntax: option.syntax
59
64
  });
60
- const envOptions = babelChain.preset("@babel/preset-env").options();
61
- babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
62
- {
63
- ...envOptions[0],
64
- loose: true
65
- }
66
- ]);
67
- babelChain.plugin("babel-plugin-transform-typescript-metadata").use(require.resolve("babel-plugin-transform-typescript-metadata"), []);
68
- babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
69
- {
70
- legacy: true
71
- }
72
- ]);
73
- const internalBabelConfig = {
74
- ...babelChain.toJSON()
75
- };
76
- return (0, _preset.applyUserBabelConfig)(internalBabelConfig, babelConfig);
65
+ return (0, import_preset.applyUserBabelConfig)(defaultBabelConfig, babelConfig);
77
66
  };
78
67
  const compileByBabel = async (appDirectory, config, compileOptions) => {
79
68
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
80
69
  const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
81
70
  const babelConfig = resolveBabelConfig(appDirectory, config, {
82
- tsconfigPath: tsconfigPath ? tsconfigPath : "",
83
- syntax: "es6+",
84
- type: "commonjs"
71
+ tsconfigPath: tsconfigPath ? tsconfigPath : ""
85
72
  });
86
- if (await _utils.fs.pathExists(sourceDir)) {
87
- const basename = _path.basename(sourceDir);
88
- const targetDir = _path.join(distDir, basename);
89
- await _utils.fs.copy(sourceDir, targetDir, {
73
+ if (await import_utils.fs.pathExists(sourceDir)) {
74
+ const basename = path.basename(sourceDir);
75
+ const targetDir = path.join(distDir, basename);
76
+ await import_utils.fs.copy(sourceDir, targetDir, {
90
77
  filter: (src) => ![
91
78
  ".ts",
92
79
  ".js"
93
- ].includes(_path.extname(src)) && src !== tsconfigPath
80
+ ].includes(path.extname(src)) && src !== tsconfigPath
94
81
  });
95
82
  }
96
- return (0, _babelcompiler.compiler)({
83
+ return (0, import_babel_compiler.compiler)({
97
84
  rootDir: appDirectory,
98
85
  distDir,
99
86
  sourceDir,
100
- extensions: _common.FILE_EXTENSIONS
87
+ extensions: import_common.FILE_EXTENSIONS
101
88
  }, babelConfig);
102
89
  }));
103
90
  results.forEach((result) => {
@@ -106,3 +93,11 @@ const compileByBabel = async (appDirectory, config, compileOptions) => {
106
93
  }
107
94
  });
108
95
  };
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ compileByBabel,
99
+ existTsConfigFile,
100
+ readTsConfig,
101
+ resolveBabelConfig,
102
+ ...require("@babel/core")
103
+ });
@@ -1,17 +1,39 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "aliasPlugin", {
6
- enumerable: true,
7
- get: function() {
8
- return aliasPlugin;
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 alias_exports = {};
30
+ __export(alias_exports, {
31
+ aliasPlugin: () => aliasPlugin
10
32
  });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
13
- const _tsconfigpaths = require("@modern-js/utils/tsconfig-paths");
14
- const _utils = require("@modern-js/utils");
33
+ module.exports = __toCommonJS(alias_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
36
+ var import_utils = require("@modern-js/utils");
15
37
  const { resolvePath } = require("@modern-js/babel-plugin-module-resolver");
16
38
  const defaultPaths = {
17
39
  "@": [
@@ -26,7 +48,7 @@ const aliasPlugin = (alias) => {
26
48
  };
27
49
  let tsPaths = {};
28
50
  if (isTsProject) {
29
- tsPaths = (0, _utils.getUserAlias)(mergedPaths);
51
+ tsPaths = (0, import_utils.getUserAlias)(mergedPaths);
30
52
  }
31
53
  tsPaths = Object.keys(tsPaths).reduce((o, key) => {
32
54
  if (typeof tsPaths[key] === "string") {
@@ -46,7 +68,7 @@ const aliasPlugin = (alias) => {
46
68
  if (sourcePath === "." || sourcePath === "./") {
47
69
  return sourcePath;
48
70
  }
49
- const matchPath = (0, _tsconfigpaths.createMatchPath)(absoluteBaseUrl, tsPaths, [
71
+ const matchPath = (0, import_tsconfig_paths.createMatchPath)(absoluteBaseUrl, tsPaths, [
50
72
  "index"
51
73
  ]);
52
74
  const result = matchPath(sourcePath, void 0, void 0, [
@@ -56,9 +78,9 @@ const aliasPlugin = (alias) => {
56
78
  ".tsx"
57
79
  ]);
58
80
  if (result) {
59
- const relativePath = _path.default.relative(_path.default.dirname(currentFile), _path.default.dirname(result));
60
- const fileName = _path.default.basename(result);
61
- const filePath = _path.default.normalize(`${relativePath.length === 0 ? "." : relativePath}/${fileName}`).replace(/\\/, "/");
81
+ const relativePath = import_path.default.relative(import_path.default.dirname(currentFile), import_path.default.dirname(result));
82
+ const fileName = import_path.default.basename(result);
83
+ const filePath = import_path.default.normalize(`${relativePath.length === 0 ? "." : relativePath}/${fileName}`).replace(/\\/, "/");
62
84
  return filePath.startsWith(".") ? filePath : `./${filePath}`;
63
85
  }
64
86
  return resolvePath(sourcePath, currentFile, opts);
@@ -73,7 +95,7 @@ const aliasPlugin = (alias) => {
73
95
  ".mjs"
74
96
  ];
75
97
  return [
76
- "@modern-js/babel-plugin-module-resolver",
98
+ require.resolve("@modern-js/babel-plugin-module-resolver"),
77
99
  {
78
100
  root: absoluteBaseUrl,
79
101
  alias: mergedPaths,
@@ -82,3 +104,7 @@ const aliasPlugin = (alias) => {
82
104
  }
83
105
  ];
84
106
  };
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ aliasPlugin
110
+ });
@@ -1,57 +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
- getBabelChain: function() {
14
- return getBabelChain;
15
- },
16
- applyUserBabelConfig: function() {
17
- return _utils.applyUserBabelConfig;
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 });
18
17
  }
18
+ return to;
19
+ };
20
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var preset_exports = {};
31
+ __export(preset_exports, {
32
+ applyUserBabelConfig: () => import_utils.applyUserBabelConfig,
33
+ getBabelConfig: () => getBabelConfig
19
34
  });
20
- const _export_star = require("@swc/helpers/_/_export_star");
21
- const _babelpresetbase = require("@modern-js/babel-preset-base");
22
- const _alias = require("./alias");
23
- _export_star._(require("./types"), exports);
24
- const _utils = require("@modern-js/utils");
25
- const getBabelChain = (libPresetOption, syntaxOption) => {
26
- const { appDirectory, jsxTransformRuntime, enableReactPreset, enableTypescriptPreset, styledComponentsOptions } = libPresetOption;
27
- const { syntax, type } = syntaxOption;
28
- const chain = (0, _babelpresetbase.getBaseBabelChain)({
29
- appDirectory,
30
- type,
31
- syntax,
32
- presets: {
33
- envOptions: true,
34
- reactOptions: enableReactPreset,
35
- typescriptOptions: enableTypescriptPreset ? {
36
- allowDeclareFields: true,
37
- allExtensions: true
38
- } : false
35
+ module.exports = __toCommonJS(preset_exports);
36
+ var import_node = require("@rsbuild/babel-preset/node");
37
+ var import_alias = require("./alias");
38
+ __reExport(preset_exports, require("./types"), module.exports);
39
+ var import_utils = require("@modern-js/utils");
40
+ const getBabelConfig = (libPresetOption) => {
41
+ var _config_presets, _config_plugins;
42
+ const config = (0, import_node.getBabelConfigForNode)({
43
+ presetEnv: {
44
+ loose: true,
45
+ modules: "commonjs"
39
46
  },
40
- plugins: {
41
- transformRuntime: {
42
- corejs: false,
43
- // for es5 code need helper functions
44
- helpers: syntaxOption.syntax === "es5"
45
- },
46
- styledComponentsOptions
47
- },
48
- jsxTransformRuntime
47
+ pluginDecorators: {
48
+ version: "legacy"
49
+ }
49
50
  });
51
+ (_config_presets = config.presets) === null || _config_presets === void 0 ? void 0 : _config_presets.push([
52
+ require.resolve("@babel/preset-react"),
53
+ {
54
+ runtime: "automatic"
55
+ }
56
+ ]);
50
57
  if (libPresetOption.alias) {
51
- const [name, opt] = (0, _alias.aliasPlugin)(libPresetOption.alias);
52
- chain.plugin(name).use(require.resolve(name), [
53
- opt
54
- ]);
58
+ var _config_plugins1;
59
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push((0, import_alias.aliasPlugin)(libPresetOption.alias));
55
60
  }
56
- return chain;
61
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(require.resolve("babel-plugin-transform-typescript-metadata"));
62
+ return config;
57
63
  };
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ applyUserBabelConfig,
67
+ getBabelConfig,
68
+ ...require("./types")
69
+ });
@@ -1,4 +1,16 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
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 types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -1,18 +1,40 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "compileByTs", {
6
- enumerable: true,
7
- get: function() {
8
- return compileByTs;
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 typescript_exports = {};
30
+ __export(typescript_exports, {
31
+ compileByTs: () => compileByTs
10
32
  });
11
- const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
- const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
13
- const _utils = require("@modern-js/utils");
14
- const _typescriptLoader = require("./typescriptLoader");
15
- const _tsconfigPathsPlugin = require("./tsconfigPathsPlugin");
33
+ module.exports = __toCommonJS(typescript_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ var import_typescriptLoader = require("./typescriptLoader");
37
+ var import_tsconfigPathsPlugin = require("./tsconfigPathsPlugin");
16
38
  const readTsConfigByFile = (tsConfigFile, tsInstance) => {
17
39
  const parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
18
40
  const { options, fileNames, projectReferences } = parsedCmd;
@@ -23,35 +45,35 @@ const readTsConfigByFile = (tsConfigFile, tsInstance) => {
23
45
  };
24
46
  };
25
47
  const copyFiles = async (from, to, appDirectory, tsconfigPath) => {
26
- if (await _utils.fs.pathExists(from)) {
27
- const relativePath = _path.default.relative(appDirectory, from);
28
- const targetDir = _path.default.join(to, relativePath);
29
- await _utils.fs.copy(from, targetDir, {
48
+ if (await import_utils.fs.pathExists(from)) {
49
+ const relativePath = import_path.default.relative(appDirectory, from);
50
+ const targetDir = import_path.default.join(to, relativePath);
51
+ await import_utils.fs.copy(from, targetDir, {
30
52
  filter: (src) => ![
31
53
  ".ts"
32
- ].includes(_path.default.extname(src)) && src !== tsconfigPath
54
+ ].includes(import_path.default.extname(src)) && src !== tsconfigPath
33
55
  });
34
56
  }
35
57
  };
36
58
  const compileByTs = async (appDirectory, config, compileOptions) => {
37
- _utils.logger.info(`Running ts compile...`);
59
+ import_utils.logger.info(`Running ts compile...`);
38
60
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
39
61
  if (!tsconfigPath) {
40
62
  return;
41
63
  }
42
- const ts = new _typescriptLoader.TypescriptLoader({
64
+ const ts = new import_typescriptLoader.TypescriptLoader({
43
65
  appDirectory
44
66
  }).load();
45
67
  const createProgram = ts.createIncrementalProgram || ts.createProgram;
46
68
  const formatHost = getFormatHost(ts);
47
69
  const { alias } = config;
48
- const aliasOption = (0, _utils.getAliasConfig)(alias, {
70
+ const aliasOption = (0, import_utils.getAliasConfig)(alias, {
49
71
  appDirectory,
50
72
  tsconfigPath
51
73
  });
52
74
  const { paths = {}, absoluteBaseUrl = "./" } = aliasOption;
53
75
  const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath, ts);
54
- const sourcePosixPaths = sourceDirs.map((sourceDir) => sourceDir.split(_path.default.sep).join(_path.default.posix.sep));
76
+ const sourcePosixPaths = sourceDirs.map((sourceDir) => sourceDir.split(import_path.default.sep).join(import_path.default.posix.sep));
55
77
  const rootNames = fileNames.filter((fileName) => {
56
78
  return fileName.endsWith(".d.ts") || sourcePosixPaths.some((sourceDir) => {
57
79
  return fileName.includes(sourceDir);
@@ -66,7 +88,7 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
66
88
  ...options
67
89
  }
68
90
  });
69
- const tsconfigPathsPlugin = (0, _tsconfigPathsPlugin.tsconfigPathsBeforeHookFactory)(ts, absoluteBaseUrl, paths);
91
+ const tsconfigPathsPlugin = (0, import_tsconfigPathsPlugin.tsconfigPathsBeforeHookFactory)(ts, absoluteBaseUrl, paths);
70
92
  const emitResult = program.emit(void 0, void 0, void 0, void 0, {
71
93
  before: [
72
94
  tsconfigPathsPlugin
@@ -75,7 +97,7 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
75
97
  const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
76
98
  const { noEmitOnError } = options;
77
99
  if (allDiagnostics.length > 0) {
78
- _utils.logger.error(ts.formatDiagnosticsWithColorAndContext([
100
+ import_utils.logger.error(ts.formatDiagnosticsWithColorAndContext([
79
101
  ...new Set(allDiagnostics)
80
102
  ], formatHost));
81
103
  if (typeof noEmitOnError === "undefined" || noEmitOnError === true) {
@@ -85,12 +107,16 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
85
107
  for (const source of sourceDirs) {
86
108
  await copyFiles(source, distDir, appDirectory, tsconfigPath);
87
109
  }
88
- _utils.logger.info(`Ts compile succeed`);
110
+ import_utils.logger.info(`Ts compile succeed`);
89
111
  };
90
112
  const getFormatHost = (ts) => {
91
113
  return {
92
- getCanonicalFileName: (path) => path,
114
+ getCanonicalFileName: (path2) => path2,
93
115
  getCurrentDirectory: ts.sys.getCurrentDirectory,
94
116
  getNewLine: () => ts.sys.newLine
95
117
  };
96
118
  };
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ compileByTs
122
+ });