@modern-js/server-utils 2.14.0 → 2.16.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @modern-js/server-utils
2
2
 
3
+ ## 2.16.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 4e876ab: chore: package.json include the monorepo-relative directory
8
+
9
+ chore: 在 package.json 中声明 monorepo 的子路径
10
+
11
+ - Updated dependencies [5954330]
12
+ - Updated dependencies [7596520]
13
+ - Updated dependencies [4e876ab]
14
+ - @modern-js/utils@2.16.0
15
+ - @modern-js/babel-compiler@2.16.0
16
+ - @modern-js/babel-preset-lib@2.16.0
17
+
18
+ ## 2.15.0
19
+
20
+ ### Patch Changes
21
+
22
+ - @modern-js/babel-preset-lib@2.15.0
23
+ - @modern-js/babel-compiler@2.15.0
24
+ - @modern-js/utils@2.15.0
25
+
3
26
  ## 2.14.0
4
27
 
5
28
  ### Patch Changes
@@ -1,69 +1,86 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var common_exports = {};
29
- __export(common_exports, {
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
30
13
  FILE_EXTENSIONS: () => FILE_EXTENSIONS,
31
14
  compile: () => compile
32
15
  });
33
- module.exports = __toCommonJS(common_exports);
34
- var path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_typescript = require("../compilers/typescript");
37
- var import_babel = require("../compilers/babel");
38
- const FILE_EXTENSIONS = [".js", ".ts", ".mjs", ".ejs"];
16
+ const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
17
+ const _utils = require("@modern-js/utils");
18
+ const _typescript = require("../compilers/typescript");
19
+ const _babel = require("../compilers/babel");
20
+ function _getRequireWildcardCache(nodeInterop) {
21
+ if (typeof WeakMap !== "function")
22
+ return null;
23
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
24
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
25
+ return (_getRequireWildcardCache = function(nodeInterop2) {
26
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
27
+ })(nodeInterop);
28
+ }
29
+ function _interop_require_wildcard(obj, nodeInterop) {
30
+ if (!nodeInterop && obj && obj.__esModule) {
31
+ return obj;
32
+ }
33
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
34
+ return {
35
+ default: obj
36
+ };
37
+ }
38
+ var cache = _getRequireWildcardCache(nodeInterop);
39
+ if (cache && cache.has(obj)) {
40
+ return cache.get(obj);
41
+ }
42
+ var newObj = {};
43
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
44
+ for (var key in obj) {
45
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
46
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
47
+ if (desc && (desc.get || desc.set)) {
48
+ Object.defineProperty(newObj, key, desc);
49
+ } else {
50
+ newObj[key] = obj[key];
51
+ }
52
+ }
53
+ }
54
+ newObj.default = obj;
55
+ if (cache) {
56
+ cache.set(obj, newObj);
57
+ }
58
+ return newObj;
59
+ }
60
+ const FILE_EXTENSIONS = [
61
+ ".js",
62
+ ".ts",
63
+ ".mjs",
64
+ ".ejs"
65
+ ];
39
66
  const validateAbsolutePath = (filename, message) => {
40
- if (!path.isAbsolute(filename)) {
67
+ if (!_path.isAbsolute(filename)) {
41
68
  throw new Error(message);
42
69
  }
43
70
  };
44
71
  const validateAbsolutePaths = (filenames, messageFunc) => {
45
- filenames.forEach(
46
- (filename) => validateAbsolutePath(filename, messageFunc(filename))
47
- );
72
+ filenames.forEach((filename) => validateAbsolutePath(filename, messageFunc(filename)));
48
73
  };
49
74
  const compile = async (appDirectory, modernConfig, compileOptions) => {
50
- var _a;
75
+ var _modernConfig_server;
51
76
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
52
- validateAbsolutePaths(
53
- sourceDirs,
54
- (dir) => `source dir ${dir} is not an absolute path.`
55
- );
77
+ validateAbsolutePaths(sourceDirs, (dir) => `source dir ${dir} is not an absolute path.`);
56
78
  validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
57
- const compiler = (_a = modernConfig == null ? void 0 : modernConfig.server) == null ? void 0 : _a.compiler;
58
- const isTsProject = tsconfigPath && await import_utils.fs.pathExists(tsconfigPath);
79
+ const compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_server = modernConfig.server) === null || _modernConfig_server === void 0 ? void 0 : _modernConfig_server.compiler;
80
+ const isTsProject = tsconfigPath && await _utils.fs.pathExists(tsconfigPath);
59
81
  if (!isTsProject || compiler === "babel") {
60
- await (0, import_babel.compileByBabel)(appDirectory, modernConfig, compileOptions);
82
+ await (0, _babel.compileByBabel)(appDirectory, modernConfig, compileOptions);
61
83
  } else {
62
- await (0, import_typescript.compileByTs)(appDirectory, modernConfig, compileOptions);
84
+ await (0, _typescript.compileByTs)(appDirectory, modernConfig, compileOptions);
63
85
  }
64
86
  };
65
- // Annotate the CommonJS export names for ESM import in node:
66
- 0 && (module.exports = {
67
- FILE_EXTENSIONS,
68
- compile
69
- });
@@ -1,59 +1,93 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
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 babel_exports = {};
30
- __export(babel_exports, {
31
- compileByBabel: () => compileByBabel,
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ readTsConfig: () => readTsConfig,
32
14
  existTsConfigFile: () => existTsConfigFile,
33
15
  getBabelConfig: () => getBabelConfig,
34
- readTsConfig: () => readTsConfig,
35
- resolveBabelConfig: () => resolveBabelConfig
16
+ resolveBabelConfig: () => resolveBabelConfig,
17
+ compileByBabel: () => compileByBabel
36
18
  });
37
- module.exports = __toCommonJS(babel_exports);
38
- var path = __toESM(require("path"));
39
- var import_babel_preset_lib = require("@modern-js/babel-preset-lib");
40
- var import_utils = require("@modern-js/utils");
41
- var import_babel_compiler = require("@modern-js/babel-compiler");
42
- var import_common = require("../../common");
43
- __reExport(babel_exports, require("@babel/core"), module.exports);
19
+ const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
20
+ const _babelpresetlib = require("@modern-js/babel-preset-lib");
21
+ const _utils = require("@modern-js/utils");
22
+ const _babelcompiler = require("@modern-js/babel-compiler");
23
+ const _common = require("../../common");
24
+ _export_star(require("@babel/core"), exports);
25
+ function _export_star(from, to) {
26
+ Object.keys(from).forEach(function(k) {
27
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
28
+ Object.defineProperty(to, k, {
29
+ enumerable: true,
30
+ get: function() {
31
+ return from[k];
32
+ }
33
+ });
34
+ }
35
+ });
36
+ return from;
37
+ }
38
+ function _getRequireWildcardCache(nodeInterop) {
39
+ if (typeof WeakMap !== "function")
40
+ return null;
41
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
42
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
43
+ return (_getRequireWildcardCache = function(nodeInterop2) {
44
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
45
+ })(nodeInterop);
46
+ }
47
+ function _interop_require_wildcard(obj, nodeInterop) {
48
+ if (!nodeInterop && obj && obj.__esModule) {
49
+ return obj;
50
+ }
51
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
52
+ return {
53
+ default: obj
54
+ };
55
+ }
56
+ var cache = _getRequireWildcardCache(nodeInterop);
57
+ if (cache && cache.has(obj)) {
58
+ return cache.get(obj);
59
+ }
60
+ var newObj = {};
61
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
62
+ for (var key in obj) {
63
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
64
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
65
+ if (desc && (desc.get || desc.set)) {
66
+ Object.defineProperty(newObj, key, desc);
67
+ } else {
68
+ newObj[key] = obj[key];
69
+ }
70
+ }
71
+ }
72
+ newObj.default = obj;
73
+ if (cache) {
74
+ cache.set(obj, newObj);
75
+ }
76
+ return newObj;
77
+ }
44
78
  const readTsConfig = (tsconfigPath, noExistReturn = null) => {
45
- if (!import_utils.fs.existsSync(tsconfigPath)) {
79
+ if (!_utils.fs.existsSync(tsconfigPath)) {
46
80
  return noExistReturn;
47
81
  }
48
- const content = import_utils.fs.readFileSync(tsconfigPath, "utf-8");
49
- return import_utils.json5.parse(content);
82
+ const content = _utils.fs.readFileSync(tsconfigPath, "utf-8");
83
+ return _utils.json5.parse(content);
50
84
  };
51
85
  const existTsConfigFile = (tsconfigAbsolutePath) => {
52
86
  const tsconfig = readTsConfig(tsconfigAbsolutePath);
53
87
  return Boolean(tsconfig);
54
88
  };
55
89
  const getBabelConfig = (libPresetOption, syntaxOption) => {
56
- const chain = (0, import_babel_preset_lib.getBabelChain)(libPresetOption, syntaxOption);
90
+ const chain = (0, _babelpresetlib.getBabelChain)(libPresetOption, syntaxOption);
57
91
  return {
58
92
  sourceType: "unambiguous",
59
93
  ...chain.toJSON()
@@ -61,23 +95,20 @@ const getBabelConfig = (libPresetOption, syntaxOption) => {
61
95
  };
62
96
  const resolveBabelConfig = (appDirectory, config, option) => {
63
97
  const { alias, babelConfig } = config;
64
- const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
98
+ const aliasConfig = (0, _utils.getAliasConfig)(alias, {
65
99
  appDirectory,
66
100
  ...option
67
101
  });
68
- const babelChain = (0, import_babel_preset_lib.getBabelChain)(
69
- {
70
- appDirectory,
71
- enableReactPreset: true,
72
- enableTypescriptPreset: true,
73
- alias: aliasConfig,
74
- envVars: []
75
- },
76
- {
77
- type: option.type,
78
- syntax: option.syntax
79
- }
80
- );
102
+ const babelChain = (0, _babelpresetlib.getBabelChain)({
103
+ appDirectory,
104
+ enableReactPreset: true,
105
+ enableTypescriptPreset: true,
106
+ alias: aliasConfig,
107
+ envVars: []
108
+ }, {
109
+ type: option.type,
110
+ syntax: option.syntax
111
+ });
81
112
  const envOptions = babelChain.preset("@babel/preset-env").options();
82
113
  babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
83
114
  {
@@ -85,59 +116,50 @@ const resolveBabelConfig = (appDirectory, config, option) => {
85
116
  loose: true
86
117
  }
87
118
  ]);
88
- babelChain.plugin("babel-plugin-transform-typescript-metadata").use(
89
- require.resolve("babel-plugin-transform-typescript-metadata"),
90
- []
91
- );
119
+ babelChain.plugin("babel-plugin-transform-typescript-metadata").use(require.resolve("babel-plugin-transform-typescript-metadata"), []);
92
120
  babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
93
- { legacy: true }
121
+ {
122
+ legacy: true
123
+ }
94
124
  ]);
95
125
  babelChain.plugin("@babel/plugin-proposal-class-properties").use(require.resolve("@babel/plugin-proposal-class-properties"), [
96
126
  {
97
127
  loose: true
98
128
  }
99
129
  ]);
100
- const internalBabelConfig = { ...babelChain.toJSON() };
101
- return (0, import_babel_preset_lib.applyUserBabelConfig)(internalBabelConfig, babelConfig);
130
+ const internalBabelConfig = {
131
+ ...babelChain.toJSON()
132
+ };
133
+ return (0, _babelpresetlib.applyUserBabelConfig)(internalBabelConfig, babelConfig);
102
134
  };
103
135
  const compileByBabel = async (appDirectory, config, compileOptions) => {
104
136
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
105
- const results = await Promise.all(
106
- sourceDirs.map(async (sourceDir) => {
107
- const babelConfig = resolveBabelConfig(appDirectory, config, {
108
- tsconfigPath: tsconfigPath ? tsconfigPath : "",
109
- syntax: "es6+",
110
- type: "commonjs"
137
+ const results = await Promise.all(sourceDirs.map(async (sourceDir) => {
138
+ const babelConfig = resolveBabelConfig(appDirectory, config, {
139
+ tsconfigPath: tsconfigPath ? tsconfigPath : "",
140
+ syntax: "es6+",
141
+ type: "commonjs"
142
+ });
143
+ if (await _utils.fs.pathExists(sourceDir)) {
144
+ const basename = _path.basename(sourceDir);
145
+ const targetDir = _path.join(distDir, basename);
146
+ await _utils.fs.copy(sourceDir, targetDir, {
147
+ filter: (src) => ![
148
+ ".ts",
149
+ ".js"
150
+ ].includes(_path.extname(src)) && src !== tsconfigPath
111
151
  });
112
- if (await import_utils.fs.pathExists(sourceDir)) {
113
- const basename = path.basename(sourceDir);
114
- const targetDir = path.join(distDir, basename);
115
- await import_utils.fs.copy(sourceDir, targetDir, {
116
- filter: (src) => ![".ts", ".js"].includes(path.extname(src)) && src !== tsconfigPath
117
- });
118
- }
119
- return (0, import_babel_compiler.compiler)(
120
- {
121
- rootDir: appDirectory,
122
- distDir,
123
- sourceDir,
124
- extensions: import_common.FILE_EXTENSIONS
125
- },
126
- babelConfig
127
- );
128
- })
129
- );
152
+ }
153
+ return (0, _babelcompiler.compiler)({
154
+ rootDir: appDirectory,
155
+ distDir,
156
+ sourceDir,
157
+ extensions: _common.FILE_EXTENSIONS
158
+ }, babelConfig);
159
+ }));
130
160
  results.forEach((result) => {
131
161
  if (result.code === 1) {
132
162
  throw new Error(result.message);
133
163
  }
134
164
  });
135
165
  };
136
- // Annotate the CommonJS export names for ESM import in node:
137
- 0 && (module.exports = {
138
- compileByBabel,
139
- existTsConfigFile,
140
- getBabelConfig,
141
- readTsConfig,
142
- resolveBabelConfig
143
- });
@@ -1,85 +1,66 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var typescript_exports = {};
29
- __export(typescript_exports, {
30
- compileByTs: () => compileByTs
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "compileByTs", {
6
+ enumerable: true,
7
+ get: () => compileByTs
31
8
  });
32
- module.exports = __toCommonJS(typescript_exports);
33
- var import_path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
35
- var import_typescript = __toESM(require("typescript"));
36
- var import_typescriptLoader = require("./typescriptLoader");
37
- var import_tsconfigPathsPlugin = require("./tsconfigPathsPlugin");
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ const _typescript = /* @__PURE__ */ _interop_require_default(require("typescript"));
12
+ const _typescriptLoader = require("./typescriptLoader");
13
+ const _tsconfigPathsPlugin = require("./tsconfigPathsPlugin");
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
38
19
  const readTsConfigByFile = (tsConfigFile) => {
39
- const parsedCmd = import_typescript.default.getParsedCommandLineOfConfigFile(
40
- tsConfigFile,
41
- void 0,
42
- import_typescript.default.sys
43
- );
20
+ const parsedCmd = _typescript.default.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, _typescript.default.sys);
44
21
  const { options, fileNames, projectReferences } = parsedCmd;
45
- return { options, fileNames, projectReferences };
22
+ return {
23
+ options,
24
+ fileNames,
25
+ projectReferences
26
+ };
46
27
  };
47
28
  const copyFiles = async (from, to, appDirectory, tsconfigPath) => {
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, {
52
- filter: (src) => ![".ts"].includes(import_path.default.extname(src)) && src !== tsconfigPath
29
+ if (await _utils.fs.pathExists(from)) {
30
+ const relativePath = _path.default.relative(appDirectory, from);
31
+ const targetDir = _path.default.join(to, relativePath);
32
+ await _utils.fs.copy(from, targetDir, {
33
+ filter: (src) => ![
34
+ ".ts"
35
+ ].includes(_path.default.extname(src)) && src !== tsconfigPath
53
36
  });
54
37
  }
55
38
  };
56
39
  const compileByTs = async (appDirectory, config, compileOptions) => {
57
- import_utils.logger.info(`Running ts compile...`);
40
+ _utils.logger.info(`Running ts compile...`);
58
41
  const { sourceDirs, distDir, tsconfigPath } = compileOptions;
59
42
  if (!tsconfigPath) {
60
43
  return;
61
44
  }
62
- const ts2 = new import_typescriptLoader.TypescriptLoader({
45
+ const ts = new _typescriptLoader.TypescriptLoader({
63
46
  appDirectory
64
47
  }).load();
65
- const createProgram = ts2.createIncrementalProgram || ts2.createProgram;
66
- const formatHost = getFormatHost(ts2);
48
+ const createProgram = ts.createIncrementalProgram || ts.createProgram;
49
+ const formatHost = getFormatHost(ts);
67
50
  const { alias } = config;
68
- const aliasOption = (0, import_utils.getAliasConfig)(alias, {
51
+ const aliasOption = (0, _utils.getAliasConfig)(alias, {
69
52
  appDirectory,
70
53
  tsconfigPath
71
54
  });
72
55
  const { paths = {}, absoluteBaseUrl = "./" } = aliasOption;
73
56
  const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath);
74
- const sourcePosixPaths = sourceDirs.map(
75
- (sourceDir) => sourceDir.split(import_path.default.sep).join(import_path.default.posix.sep)
76
- );
57
+ const sourcePosixPaths = sourceDirs.map((sourceDir) => sourceDir.split(_path.default.sep).join(_path.default.posix.sep));
77
58
  const rootNames = fileNames.filter((fileName) => {
78
59
  return fileName.endsWith(".d.ts") || sourcePosixPaths.some((sourceDir) => {
79
60
  return fileName.includes(sourceDir);
80
61
  });
81
62
  });
82
- const program = createProgram.call(ts2, {
63
+ const program = createProgram.call(ts, {
83
64
  rootNames,
84
65
  projectReferences,
85
66
  options: {
@@ -88,23 +69,18 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
88
69
  ...options
89
70
  }
90
71
  });
91
- const tsconfigPathsPlugin = (0, import_tsconfigPathsPlugin.tsconfigPathsBeforeHookFactory)(
92
- ts2,
93
- absoluteBaseUrl,
94
- paths
95
- );
72
+ const tsconfigPathsPlugin = (0, _tsconfigPathsPlugin.tsconfigPathsBeforeHookFactory)(ts, absoluteBaseUrl, paths);
96
73
  const emitResult = program.emit(void 0, void 0, void 0, void 0, {
97
- before: [tsconfigPathsPlugin]
74
+ before: [
75
+ tsconfigPathsPlugin
76
+ ]
98
77
  });
99
- const allDiagnostics = ts2.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
78
+ const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
100
79
  const { noEmitOnError } = options;
101
80
  if (allDiagnostics.length > 0) {
102
- import_utils.logger.error(
103
- ts2.formatDiagnosticsWithColorAndContext(
104
- [...new Set(allDiagnostics)],
105
- formatHost
106
- )
107
- );
81
+ _utils.logger.error(ts.formatDiagnosticsWithColorAndContext([
82
+ ...new Set(allDiagnostics)
83
+ ], formatHost));
108
84
  if (typeof noEmitOnError === "undefined" || noEmitOnError === true) {
109
85
  process.exit(1);
110
86
  }
@@ -112,16 +88,12 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
112
88
  for (const source of sourceDirs) {
113
89
  await copyFiles(source, distDir, appDirectory, tsconfigPath);
114
90
  }
115
- import_utils.logger.info(`Ts compile succeed`);
91
+ _utils.logger.info(`Ts compile succeed`);
116
92
  };
117
- const getFormatHost = (ts2) => {
93
+ const getFormatHost = (ts) => {
118
94
  return {
119
- getCanonicalFileName: (path2) => path2,
120
- getCurrentDirectory: ts2.sys.getCurrentDirectory,
121
- getNewLine: () => ts2.sys.newLine
95
+ getCanonicalFileName: (path) => path,
96
+ getCurrentDirectory: ts.sys.getCurrentDirectory,
97
+ getNewLine: () => ts.sys.newLine
122
98
  };
123
99
  };
124
- // Annotate the CommonJS export names for ESM import in node:
125
- 0 && (module.exports = {
126
- compileByTs
127
- });