@modern-js/server-utils 2.35.1 → 2.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/cjs/common/index.js +41 -22
  2. package/dist/cjs/compilers/babel/index.js +60 -42
  3. package/dist/cjs/compilers/babel/preset/alias.js +42 -16
  4. package/dist/cjs/compilers/babel/preset/index.js +33 -22
  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 +14 -8
  12. package/dist/esm/compilers/babel/preset/alias.js +4 -1
  13. package/dist/esm/compilers/babel/preset/index.js +11 -7
  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 +10 -4
  21. package/dist/esm-node/compilers/babel/preset/alias.js +4 -1
  22. package/dist/esm-node/compilers/babel/preset/index.js +6 -2
  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/package.json +8 -8
@@ -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,11 +54,11 @@ 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 babelChain = (0, import_preset.getBabelChain)({
52
62
  appDirectory,
53
63
  enableReactPreset: true,
54
64
  enableTypescriptPreset: true,
@@ -73,7 +83,7 @@ const resolveBabelConfig = (appDirectory, config, option) => {
73
83
  const internalBabelConfig = {
74
84
  ...babelChain.toJSON()
75
85
  };
76
- return (0, _preset.applyUserBabelConfig)(internalBabelConfig, babelConfig);
86
+ return (0, import_preset.applyUserBabelConfig)(internalBabelConfig, babelConfig);
77
87
  };
78
88
  const compileByBabel = async (appDirectory, config, compileOptions) => {
79
89
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
@@ -83,21 +93,21 @@ const compileByBabel = async (appDirectory, config, compileOptions) => {
83
93
  syntax: "es6+",
84
94
  type: "commonjs"
85
95
  });
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, {
96
+ if (await import_utils.fs.pathExists(sourceDir)) {
97
+ const basename = path.basename(sourceDir);
98
+ const targetDir = path.join(distDir, basename);
99
+ await import_utils.fs.copy(sourceDir, targetDir, {
90
100
  filter: (src) => ![
91
101
  ".ts",
92
102
  ".js"
93
- ].includes(_path.extname(src)) && src !== tsconfigPath
103
+ ].includes(path.extname(src)) && src !== tsconfigPath
94
104
  });
95
105
  }
96
- return (0, _babelcompiler.compiler)({
106
+ return (0, import_babel_compiler.compiler)({
97
107
  rootDir: appDirectory,
98
108
  distDir,
99
109
  sourceDir,
100
- extensions: _common.FILE_EXTENSIONS
110
+ extensions: import_common.FILE_EXTENSIONS
101
111
  }, babelConfig);
102
112
  }));
103
113
  results.forEach((result) => {
@@ -106,3 +116,11 @@ const compileByBabel = async (appDirectory, config, compileOptions) => {
106
116
  }
107
117
  });
108
118
  };
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ compileByBabel,
122
+ existTsConfigFile,
123
+ readTsConfig,
124
+ resolveBabelConfig,
125
+ ...require("@babel/core")
126
+ });
@@ -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);
@@ -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,31 +1,36 @@
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
- getBabelChain: function() {
14
- return getBabelChain;
15
- },
16
- applyUserBabelConfig: function() {
17
- return _utils.applyUserBabelConfig;
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var preset_exports = {};
21
+ __export(preset_exports, {
22
+ applyUserBabelConfig: () => import_utils.applyUserBabelConfig,
23
+ getBabelChain: () => getBabelChain
19
24
  });
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
+ module.exports = __toCommonJS(preset_exports);
26
+ var import_babel_preset_base = require("@modern-js/babel-preset-base");
27
+ var import_alias = require("./alias");
28
+ __reExport(preset_exports, require("./types"), module.exports);
29
+ var import_utils = require("@modern-js/utils");
25
30
  const getBabelChain = (libPresetOption, syntaxOption) => {
26
31
  const { appDirectory, jsxTransformRuntime, enableReactPreset, enableTypescriptPreset, styledComponentsOptions } = libPresetOption;
27
32
  const { syntax, type } = syntaxOption;
28
- const chain = (0, _babelpresetbase.getBaseBabelChain)({
33
+ const chain = (0, import_babel_preset_base.getBaseBabelChain)({
29
34
  appDirectory,
30
35
  type,
31
36
  syntax,
@@ -48,10 +53,16 @@ const getBabelChain = (libPresetOption, syntaxOption) => {
48
53
  jsxTransformRuntime
49
54
  });
50
55
  if (libPresetOption.alias) {
51
- const [name, opt] = (0, _alias.aliasPlugin)(libPresetOption.alias);
56
+ const [name, opt] = (0, import_alias.aliasPlugin)(libPresetOption.alias);
52
57
  chain.plugin(name).use(require.resolve(name), [
53
58
  opt
54
59
  ]);
55
60
  }
56
61
  return chain;
57
62
  };
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ applyUserBabelConfig,
66
+ getBabelChain,
67
+ ...require("./types")
68
+ });
@@ -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
+ });
@@ -1,24 +1,46 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "tsconfigPathsBeforeHookFactory", {
6
- enumerable: true,
7
- get: function() {
8
- return tsconfigPathsBeforeHookFactory;
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 tsconfigPathsPlugin_exports = {};
30
+ __export(tsconfigPathsPlugin_exports, {
31
+ tsconfigPathsBeforeHookFactory: () => tsconfigPathsBeforeHookFactory
10
32
  });
11
- const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
- const _os = /* @__PURE__ */ _interop_require_wildcard._(require("os"));
13
- const _path = /* @__PURE__ */ _interop_require_wildcard._(require("path"));
14
- const _typescript = /* @__PURE__ */ _interop_require_wildcard._(require("typescript"));
15
- const _tsconfigpaths = require("@modern-js/utils/tsconfig-paths");
33
+ module.exports = __toCommonJS(tsconfigPathsPlugin_exports);
34
+ var os = __toESM(require("os"));
35
+ var import_path = __toESM(require("path"));
36
+ var ts = __toESM(require("typescript"));
37
+ var import_tsconfig_paths = require("@modern-js/utils/tsconfig-paths");
16
38
  const isRegExpKey = (str) => {
17
39
  return str.startsWith("^") || str.endsWith("$");
18
40
  };
19
41
  const resolveAliasPath = (baseUrl, filePath) => {
20
42
  if (filePath.startsWith(".") || filePath.startsWith("..")) {
21
- return _path.default.resolve(baseUrl, filePath);
43
+ return import_path.default.resolve(baseUrl, filePath);
22
44
  }
23
45
  return filePath;
24
46
  };
@@ -60,7 +82,7 @@ const createAliasMatcher = (baseUrl, alias) => {
60
82
  };
61
83
  };
62
84
  const isDynamicImport = (tsBinary, node) => {
63
- return tsBinary.isCallExpression(node) && node.expression.kind === _typescript.SyntaxKind.ImportKeyword;
85
+ return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
64
86
  };
65
87
  function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
66
88
  const tsPaths = {};
@@ -73,7 +95,7 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
73
95
  }
74
96
  });
75
97
  const matchAliasPath = createAliasMatcher(baseUrl, alias);
76
- const matchTsPath = (0, _tsconfigpaths.createMatchPath)(baseUrl, tsPaths, [
98
+ const matchTsPath = (0, import_tsconfig_paths.createMatchPath)(baseUrl, tsPaths, [
77
99
  "main"
78
100
  ]);
79
101
  const matchPath = (requestedModule, readJSONSync, fileExists, extensions) => {
@@ -142,10 +164,10 @@ function getNotAliasedPath(sf, matcher, text) {
142
164
  if (!result) {
143
165
  return;
144
166
  }
145
- if (_os.platform() === "win32") {
167
+ if (os.platform() === "win32") {
146
168
  result = result.replace(/\\/g, "/");
147
169
  }
148
- if (!_path.default.isAbsolute(result)) {
170
+ if (!import_path.default.isAbsolute(result)) {
149
171
  if (!result.startsWith(".") && !result.startsWith("..")) {
150
172
  try {
151
173
  const packagePath = require.resolve(result, {
@@ -173,6 +195,10 @@ function getNotAliasedPath(sf, matcher, text) {
173
195
  } catch {
174
196
  }
175
197
  }
176
- const resolvedPath = _path.posix.relative((0, _path.dirname)(sf.fileName), result) || "./";
198
+ const resolvedPath = import_path.posix.relative((0, import_path.dirname)(sf.fileName), result) || "./";
177
199
  return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
178
200
  }
201
+ // Annotate the CommonJS export names for ESM import in node:
202
+ 0 && (module.exports = {
203
+ tsconfigPathsBeforeHookFactory
204
+ });
@@ -1,14 +1,27 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "TypescriptLoader", {
6
- enumerable: true,
7
- get: function() {
8
- return TypescriptLoader;
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 });
9
15
  }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var typescriptLoader_exports = {};
20
+ __export(typescriptLoader_exports, {
21
+ TypescriptLoader: () => TypescriptLoader
10
22
  });
11
- const _define_property = require("@swc/helpers/_/_define_property");
23
+ module.exports = __toCommonJS(typescriptLoader_exports);
24
+ var import_define_property = require("@swc/helpers/_/_define_property");
12
25
  class TypescriptLoader {
13
26
  load() {
14
27
  if (this.tsBinary) {
@@ -27,8 +40,12 @@ class TypescriptLoader {
27
40
  }
28
41
  }
29
42
  constructor({ appDirectory }) {
30
- _define_property._(this, "tsBinary", void 0);
31
- _define_property._(this, "appDirectory", void 0);
43
+ (0, import_define_property._)(this, "tsBinary", void 0);
44
+ (0, import_define_property._)(this, "appDirectory", void 0);
32
45
  this.appDirectory = appDirectory;
33
46
  }
34
47
  }
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ TypescriptLoader
51
+ });
package/dist/cjs/index.js CHANGED
@@ -1,13 +1,31 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "compile", {
6
- enumerable: true,
7
- get: function() {
8
- return _common.compile;
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 });
9
15
  }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ compile: () => import_common.compile
23
+ });
24
+ module.exports = __toCommonJS(src_exports);
25
+ __reExport(src_exports, require("./compilers/babel"), module.exports);
26
+ var import_common = require("./common");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ compile,
30
+ ...require("./compilers/babel")
10
31
  });
11
- const _export_star = require("@swc/helpers/_/_export_star");
12
- _export_star._(require("./compilers/babel"), exports);
13
- const _common = require("./common");
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import * as path from "path";
4
4
  import { fs } from "@modern-js/utils";
5
- export var FILE_EXTENSIONS = [
5
+ var FILE_EXTENSIONS = [
6
6
  ".js",
7
7
  ".ts",
8
8
  ".mjs",
@@ -18,7 +18,7 @@ var validateAbsolutePaths = function(filenames, messageFunc) {
18
18
  return validateAbsolutePath(filename, messageFunc(filename));
19
19
  });
20
20
  };
21
- export var compile = function() {
21
+ var compile = function() {
22
22
  var _ref = _async_to_generator(function(appDirectory, modernConfig, compileOptions) {
23
23
  var _modernConfig_server, sourceDirs, distDir, tsconfigPath, compiler, isTsProject, _tmp, compileByBabel, compileByTs;
24
24
  return _ts_generator(this, function(_state) {
@@ -91,3 +91,7 @@ export var compile = function() {
91
91
  return _ref.apply(this, arguments);
92
92
  };
93
93
  }();
94
+ export {
95
+ FILE_EXTENSIONS,
96
+ compile
97
+ };
@@ -8,7 +8,7 @@ import { compiler } from "@modern-js/babel-compiler";
8
8
  import { FILE_EXTENSIONS } from "../../common";
9
9
  import { getBabelChain, applyUserBabelConfig } from "./preset";
10
10
  export * from "@babel/core";
11
- export var readTsConfig = function(tsconfigPath) {
11
+ var readTsConfig = function(tsconfigPath) {
12
12
  var noExistReturn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
13
13
  if (!fs.existsSync(tsconfigPath)) {
14
14
  return noExistReturn;
@@ -16,17 +16,17 @@ export var readTsConfig = function(tsconfigPath) {
16
16
  var content = fs.readFileSync(tsconfigPath, "utf-8");
17
17
  return json5.parse(content);
18
18
  };
19
- export var existTsConfigFile = function(tsconfigAbsolutePath) {
19
+ var existTsConfigFile = function(tsconfigAbsolutePath) {
20
20
  var tsconfig = readTsConfig(tsconfigAbsolutePath);
21
21
  return Boolean(tsconfig);
22
22
  };
23
- export var resolveBabelConfig = function(appDirectory, config, option) {
23
+ var resolveBabelConfig = function(appDirectory, config, option) {
24
24
  var alias = config.alias, babelConfig = config.babelConfig;
25
25
  var aliasConfig = getAliasConfig(alias, _object_spread({
26
- appDirectory: appDirectory
26
+ appDirectory
27
27
  }, option));
28
28
  var babelChain = getBabelChain({
29
- appDirectory: appDirectory,
29
+ appDirectory,
30
30
  enableReactPreset: true,
31
31
  enableTypescriptPreset: true,
32
32
  alias: aliasConfig
@@ -49,7 +49,7 @@ export var resolveBabelConfig = function(appDirectory, config, option) {
49
49
  var internalBabelConfig = _object_spread({}, babelChain.toJSON());
50
50
  return applyUserBabelConfig(internalBabelConfig, babelConfig);
51
51
  };
52
- export var compileByBabel = function() {
52
+ var compileByBabel = function() {
53
53
  var _ref = _async_to_generator(function(appDirectory, config, compileOptions) {
54
54
  var sourceDirs, distDir, tsconfigPath, results;
55
55
  return _ts_generator(this, function(_state) {
@@ -100,8 +100,8 @@ export var compileByBabel = function() {
100
100
  2,
101
101
  compiler({
102
102
  rootDir: appDirectory,
103
- distDir: distDir,
104
- sourceDir: sourceDir,
103
+ distDir,
104
+ sourceDir,
105
105
  extensions: FILE_EXTENSIONS
106
106
  }, babelConfig)
107
107
  ];
@@ -130,3 +130,9 @@ export var compileByBabel = function() {
130
130
  return _ref.apply(this, arguments);
131
131
  };
132
132
  }();
133
+ export {
134
+ compileByBabel,
135
+ existTsConfigFile,
136
+ readTsConfig,
137
+ resolveBabelConfig
138
+ };
@@ -10,7 +10,7 @@ var defaultPaths = {
10
10
  "./src"
11
11
  ]
12
12
  };
13
- export var aliasPlugin = function(alias) {
13
+ var aliasPlugin = function(alias) {
14
14
  var absoluteBaseUrl = alias.absoluteBaseUrl, isTsPath = alias.isTsPath, _alias_isTsProject = alias.isTsProject, isTsProject = _alias_isTsProject === void 0 ? false : _alias_isTsProject;
15
15
  var mergedPaths = isTsPath ? alias.paths || {} : _object_spread({}, defaultPaths, alias.paths || {});
16
16
  var tsPaths = {};
@@ -65,3 +65,6 @@ export var aliasPlugin = function(alias) {
65
65
  }
66
66
  ];
67
67
  };
68
+ export {
69
+ aliasPlugin
70
+ };
@@ -1,13 +1,13 @@
1
1
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
2
2
  import { getBaseBabelChain } from "@modern-js/babel-preset-base";
3
3
  import { aliasPlugin } from "./alias";
4
- export var getBabelChain = function(libPresetOption, syntaxOption) {
4
+ var getBabelChain = function(libPresetOption, syntaxOption) {
5
5
  var appDirectory = libPresetOption.appDirectory, jsxTransformRuntime = libPresetOption.jsxTransformRuntime, enableReactPreset = libPresetOption.enableReactPreset, enableTypescriptPreset = libPresetOption.enableTypescriptPreset, styledComponentsOptions = libPresetOption.styledComponentsOptions;
6
6
  var syntax = syntaxOption.syntax, type = syntaxOption.type;
7
7
  var chain = getBaseBabelChain({
8
- appDirectory: appDirectory,
9
- type: type,
10
- syntax: syntax,
8
+ appDirectory,
9
+ type,
10
+ syntax,
11
11
  presets: {
12
12
  envOptions: true,
13
13
  reactOptions: enableReactPreset,
@@ -22,9 +22,9 @@ export var getBabelChain = function(libPresetOption, syntaxOption) {
22
22
  // for es5 code need helper functions
23
23
  helpers: syntaxOption.syntax === "es5"
24
24
  },
25
- styledComponentsOptions: styledComponentsOptions
25
+ styledComponentsOptions
26
26
  },
27
- jsxTransformRuntime: jsxTransformRuntime
27
+ jsxTransformRuntime
28
28
  });
29
29
  if (libPresetOption.alias) {
30
30
  var _aliasPlugin = _sliced_to_array(aliasPlugin(libPresetOption.alias), 2), name = _aliasPlugin[0], opt = _aliasPlugin[1];
@@ -35,4 +35,8 @@ export var getBabelChain = function(libPresetOption, syntaxOption) {
35
35
  return chain;
36
36
  };
37
37
  export * from "./types";
38
- export { applyUserBabelConfig } from "@modern-js/utils";
38
+ import { applyUserBabelConfig } from "@modern-js/utils";
39
+ export {
40
+ applyUserBabelConfig,
41
+ getBabelChain
42
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -10,9 +10,9 @@ var readTsConfigByFile = function(tsConfigFile, tsInstance) {
10
10
  var parsedCmd = tsInstance.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, tsInstance.sys);
11
11
  var options = parsedCmd.options, fileNames = parsedCmd.fileNames, projectReferences = parsedCmd.projectReferences;
12
12
  return {
13
- options: options,
14
- fileNames: fileNames,
15
- projectReferences: projectReferences
13
+ options,
14
+ fileNames,
15
+ projectReferences
16
16
  };
17
17
  };
18
18
  var copyFiles = function() {
@@ -57,7 +57,7 @@ var copyFiles = function() {
57
57
  return _ref.apply(this, arguments);
58
58
  };
59
59
  }();
60
- export var compileByTs = function() {
60
+ var compileByTs = function() {
61
61
  var _ref = _async_to_generator(function(appDirectory, config, compileOptions) {
62
62
  var sourceDirs, distDir, tsconfigPath, ts, createProgram, formatHost, alias, aliasOption, _aliasOption_paths, paths, _aliasOption_absoluteBaseUrl, absoluteBaseUrl, _readTsConfigByFile, options, fileNames, projectReferences, sourcePosixPaths, rootNames, program, tsconfigPathsPlugin, emitResult, allDiagnostics, noEmitOnError, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, source, err;
63
63
  return _ts_generator(this, function(_state) {
@@ -71,14 +71,14 @@ export var compileByTs = function() {
71
71
  ];
72
72
  }
73
73
  ts = new TypescriptLoader({
74
- appDirectory: appDirectory
74
+ appDirectory
75
75
  }).load();
76
76
  createProgram = ts.createIncrementalProgram || ts.createProgram;
77
77
  formatHost = getFormatHost(ts);
78
78
  alias = config.alias;
79
79
  aliasOption = getAliasConfig(alias, {
80
- appDirectory: appDirectory,
81
- tsconfigPath: tsconfigPath
80
+ appDirectory,
81
+ tsconfigPath
82
82
  });
83
83
  _aliasOption_paths = aliasOption.paths, paths = _aliasOption_paths === void 0 ? {} : _aliasOption_paths, _aliasOption_absoluteBaseUrl = aliasOption.absoluteBaseUrl, absoluteBaseUrl = _aliasOption_absoluteBaseUrl === void 0 ? "./" : _aliasOption_absoluteBaseUrl;
84
84
  _readTsConfigByFile = readTsConfigByFile(tsconfigPath, ts), options = _readTsConfigByFile.options, fileNames = _readTsConfigByFile.fileNames, projectReferences = _readTsConfigByFile.projectReferences;
@@ -91,8 +91,8 @@ export var compileByTs = function() {
91
91
  });
92
92
  });
93
93
  program = createProgram.call(ts, {
94
- rootNames: rootNames,
95
- projectReferences: projectReferences,
94
+ rootNames,
95
+ projectReferences,
96
96
  options: _object_spread({
97
97
  rootDir: appDirectory,
98
98
  outDir: distDir
@@ -192,3 +192,6 @@ var getFormatHost = function(ts) {
192
192
  }
193
193
  };
194
194
  };
195
+ export {
196
+ compileByTs
197
+ };
@@ -71,7 +71,7 @@ var createAliasMatcher = function(baseUrl, alias) {
71
71
  var isDynamicImport = function(tsBinary, node) {
72
72
  return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
73
73
  };
74
- export function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
74
+ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
75
75
  var tsPaths = {};
76
76
  var alias = {};
77
77
  Object.keys(paths).forEach(function(key) {
@@ -183,3 +183,6 @@ function getNotAliasedPath(sf, matcher, text) {
183
183
  var resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
184
184
  return resolvedPath[0] === "." ? resolvedPath : "./".concat(resolvedPath);
185
185
  }
186
+ export {
187
+ tsconfigPathsBeforeHookFactory
188
+ };
@@ -1,7 +1,7 @@
1
1
  import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
2
2
  import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
3
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
- export var TypescriptLoader = /* @__PURE__ */ function() {
4
+ var TypescriptLoader = /* @__PURE__ */ function() {
5
5
  "use strict";
6
6
  function TypescriptLoader2(param) {
7
7
  var appDirectory = param.appDirectory;
@@ -33,3 +33,6 @@ export var TypescriptLoader = /* @__PURE__ */ function() {
33
33
  ]);
34
34
  return TypescriptLoader2;
35
35
  }();
36
+ export {
37
+ TypescriptLoader
38
+ };
package/dist/esm/index.js CHANGED
@@ -1,2 +1,5 @@
1
1
  export * from "./compilers/babel";
2
- export { compile } from "./common";
2
+ import { compile } from "./common";
3
+ export {
4
+ compile
5
+ };
@@ -1,6 +1,6 @@
1
1
  import * as path from "path";
2
2
  import { fs } from "@modern-js/utils";
3
- export const FILE_EXTENSIONS = [
3
+ const FILE_EXTENSIONS = [
4
4
  ".js",
5
5
  ".ts",
6
6
  ".mjs",
@@ -14,7 +14,7 @@ const validateAbsolutePath = (filename, message) => {
14
14
  const validateAbsolutePaths = (filenames, messageFunc) => {
15
15
  filenames.forEach((filename) => validateAbsolutePath(filename, messageFunc(filename)));
16
16
  };
17
- export const compile = async (appDirectory, modernConfig, compileOptions) => {
17
+ const compile = async (appDirectory, modernConfig, compileOptions) => {
18
18
  var _modernConfig_server;
19
19
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
20
20
  validateAbsolutePaths(sourceDirs, (dir) => `source dir ${dir} is not an absolute path.`);
@@ -29,3 +29,7 @@ export const compile = async (appDirectory, modernConfig, compileOptions) => {
29
29
  await compileByTs(appDirectory, modernConfig, compileOptions);
30
30
  }
31
31
  };
32
+ export {
33
+ FILE_EXTENSIONS,
34
+ compile
35
+ };
@@ -4,18 +4,18 @@ import { compiler } from "@modern-js/babel-compiler";
4
4
  import { FILE_EXTENSIONS } from "../../common";
5
5
  import { getBabelChain, applyUserBabelConfig } from "./preset";
6
6
  export * from "@babel/core";
7
- export const readTsConfig = (tsconfigPath, noExistReturn = null) => {
7
+ const readTsConfig = (tsconfigPath, noExistReturn = null) => {
8
8
  if (!fs.existsSync(tsconfigPath)) {
9
9
  return noExistReturn;
10
10
  }
11
11
  const content = fs.readFileSync(tsconfigPath, "utf-8");
12
12
  return json5.parse(content);
13
13
  };
14
- export const existTsConfigFile = (tsconfigAbsolutePath) => {
14
+ const existTsConfigFile = (tsconfigAbsolutePath) => {
15
15
  const tsconfig = readTsConfig(tsconfigAbsolutePath);
16
16
  return Boolean(tsconfig);
17
17
  };
18
- export const resolveBabelConfig = (appDirectory, config, option) => {
18
+ const resolveBabelConfig = (appDirectory, config, option) => {
19
19
  const { alias, babelConfig } = config;
20
20
  const aliasConfig = getAliasConfig(alias, {
21
21
  appDirectory,
@@ -48,7 +48,7 @@ export const resolveBabelConfig = (appDirectory, config, option) => {
48
48
  };
49
49
  return applyUserBabelConfig(internalBabelConfig, babelConfig);
50
50
  };
51
- export const compileByBabel = async (appDirectory, config, compileOptions) => {
51
+ const compileByBabel = async (appDirectory, config, compileOptions) => {
52
52
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
53
53
  const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
54
54
  const babelConfig = resolveBabelConfig(appDirectory, config, {
@@ -79,3 +79,9 @@ export const compileByBabel = async (appDirectory, config, compileOptions) => {
79
79
  }
80
80
  });
81
81
  };
82
+ export {
83
+ compileByBabel,
84
+ existTsConfigFile,
85
+ readTsConfig,
86
+ resolveBabelConfig
87
+ };
@@ -7,7 +7,7 @@ const defaultPaths = {
7
7
  "./src"
8
8
  ]
9
9
  };
10
- export const aliasPlugin = (alias) => {
10
+ const aliasPlugin = (alias) => {
11
11
  const { absoluteBaseUrl, isTsPath, isTsProject = false } = alias;
12
12
  const mergedPaths = isTsPath ? alias.paths || {} : {
13
13
  ...defaultPaths,
@@ -71,3 +71,6 @@ export const aliasPlugin = (alias) => {
71
71
  }
72
72
  ];
73
73
  };
74
+ export {
75
+ aliasPlugin
76
+ };
@@ -1,6 +1,6 @@
1
1
  import { getBaseBabelChain } from "@modern-js/babel-preset-base";
2
2
  import { aliasPlugin } from "./alias";
3
- export const getBabelChain = (libPresetOption, syntaxOption) => {
3
+ const getBabelChain = (libPresetOption, syntaxOption) => {
4
4
  const { appDirectory, jsxTransformRuntime, enableReactPreset, enableTypescriptPreset, styledComponentsOptions } = libPresetOption;
5
5
  const { syntax, type } = syntaxOption;
6
6
  const chain = getBaseBabelChain({
@@ -34,4 +34,8 @@ export const getBabelChain = (libPresetOption, syntaxOption) => {
34
34
  return chain;
35
35
  };
36
36
  export * from "./types";
37
- export { applyUserBabelConfig } from "@modern-js/utils";
37
+ import { applyUserBabelConfig } from "@modern-js/utils";
38
+ export {
39
+ applyUserBabelConfig,
40
+ getBabelChain
41
+ };
@@ -1 +0,0 @@
1
- export {};
@@ -22,7 +22,7 @@ const copyFiles = async (from, to, appDirectory, tsconfigPath) => {
22
22
  });
23
23
  }
24
24
  };
25
- export const compileByTs = async (appDirectory, config, compileOptions) => {
25
+ const compileByTs = async (appDirectory, config, compileOptions) => {
26
26
  logger.info(`Running ts compile...`);
27
27
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
28
28
  if (!tsconfigPath) {
@@ -83,3 +83,6 @@ const getFormatHost = (ts) => {
83
83
  getNewLine: () => ts.sys.newLine
84
84
  };
85
85
  };
86
+ export {
87
+ compileByTs
88
+ };
@@ -51,7 +51,7 @@ const createAliasMatcher = (baseUrl, alias) => {
51
51
  const isDynamicImport = (tsBinary, node) => {
52
52
  return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
53
53
  };
54
- export function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
54
+ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
55
55
  const tsPaths = {};
56
56
  const alias = {};
57
57
  Object.keys(paths).forEach((key) => {
@@ -165,3 +165,6 @@ function getNotAliasedPath(sf, matcher, text) {
165
165
  const resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
166
166
  return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
167
167
  }
168
+ export {
169
+ tsconfigPathsBeforeHookFactory
170
+ };
@@ -1,5 +1,5 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- export class TypescriptLoader {
2
+ class TypescriptLoader {
3
3
  load() {
4
4
  if (this.tsBinary) {
5
5
  return this.tsBinary;
@@ -22,3 +22,6 @@ export class TypescriptLoader {
22
22
  this.appDirectory = appDirectory;
23
23
  }
24
24
  }
25
+ export {
26
+ TypescriptLoader
27
+ };
@@ -1,2 +1,5 @@
1
1
  export * from "./compilers/babel";
2
- export { compile } from "./common";
2
+ import { compile } from "./common";
3
+ export {
4
+ compile
5
+ };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.35.1",
18
+ "version": "2.36.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -37,10 +37,10 @@
37
37
  "@babel/preset-typescript": "^7.22.15",
38
38
  "babel-plugin-transform-typescript-metadata": "^0.3.2",
39
39
  "@swc/helpers": "0.5.1",
40
- "@modern-js/babel-compiler": "2.35.1",
41
- "@modern-js/babel-preset-base": "2.35.1",
42
- "@modern-js/utils": "2.35.1",
43
- "@modern-js/babel-plugin-module-resolver": "2.35.1"
40
+ "@modern-js/babel-compiler": "2.36.0",
41
+ "@modern-js/babel-preset-base": "2.36.0",
42
+ "@modern-js/utils": "2.36.0",
43
+ "@modern-js/babel-plugin-module-resolver": "2.36.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/babel__core": "^7.20.0",
@@ -49,9 +49,9 @@
49
49
  "jest": "^29",
50
50
  "ts-jest": "^29.1.0",
51
51
  "typescript": "^5",
52
- "@scripts/build": "2.35.1",
53
- "@scripts/jest-config": "2.35.1",
54
- "@modern-js/server-core": "2.35.1"
52
+ "@modern-js/server-core": "2.36.0",
53
+ "@scripts/build": "2.36.0",
54
+ "@scripts/jest-config": "2.36.0"
55
55
  },
56
56
  "sideEffects": false,
57
57
  "publishConfig": {