@modern-js/server-utils 2.0.0-beta.2 → 2.0.0-beta.4

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,107 @@
1
1
  # @modern-js/server-utils
2
2
 
3
+ ## 2.0.0-beta.4
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - 9b915e0c10: fix: tsconfig-paths plugin's new node use old node flag
12
+ fix: tsconfig-paths 插件转换的新节点使用旧节点的 flag
13
+ - 7879e8f: refactor: remove enableModernMode config
14
+
15
+ refactor: 不再支持 enableModernMode 配置项
16
+
17
+ - d4e8e6fb90: fix: modernjs dev server can't start normaly
18
+ fix: modernjs dev 服务端不能正常启动
19
+ - a8642da58f: fix(server-utils): incorrect babel-compiler version
20
+
21
+ fix(server-utils): 修复引用错误的 babel-compiler 版本的问题
22
+
23
+ - c2bb0f1745: chore(server-utils): using pre-bundled tsconfig-paths
24
+
25
+ chore(server-utils): 使用预打包的 tsconfig-paths 依赖
26
+
27
+ - 14b712da84: fix: use consistent alias type and default value across packages
28
+
29
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
30
+
31
+ - Updated dependencies [7879e8f]
32
+ - Updated dependencies [6aca875]
33
+ - Updated dependencies [2e6031955e]
34
+ - Updated dependencies [7b7d12c]
35
+ - Updated dependencies [92f0eade39]
36
+ - Updated dependencies [edd1cfb1af]
37
+ - Updated dependencies [cc971eabfc]
38
+ - Updated dependencies [5b9049f2e9]
39
+ - Updated dependencies [92004d1906]
40
+ - Updated dependencies [b8bbe036c7]
41
+ - Updated dependencies [d5a31df781]
42
+ - Updated dependencies [dda38c9c3e]
43
+ - Updated dependencies [3bbea92b2a]
44
+ - Updated dependencies [b710adb843]
45
+ - Updated dependencies [f179749375]
46
+ - Updated dependencies [ea7cf06]
47
+ - Updated dependencies [bbe4c4a]
48
+ - Updated dependencies [e4558a0]
49
+ - Updated dependencies [abf3421a75]
50
+ - Updated dependencies [543be9558e]
51
+ - Updated dependencies [14b712da84]
52
+ - @modern-js/utils@2.0.0-beta.4
53
+ - @modern-js/plugin@2.0.0-beta.4
54
+ - @modern-js/babel-preset-lib@2.0.0-beta.4
55
+ - @modern-js/babel-compiler@2.0.0-beta.4
56
+
57
+ ## 2.0.0-beta.3
58
+
59
+ ### Major Changes
60
+
61
+ - dda38c9c3e: chore: v2
62
+
63
+ ### Patch Changes
64
+
65
+ - 9b915e0c10: fix: tsconfig-paths plugin's new node use old node flag
66
+ fix: tsconfig-paths 插件转换的新节点使用旧节点的 flag
67
+ - d4e8e6f: fix: modernjs dev server can't start normaly
68
+ fix: modernjs dev 服务端不能正常启动
69
+ - a8642da58f: fix(server-utils): incorrect babel-compiler version
70
+
71
+ fix(server-utils): 修复引用错误的 babel-compiler 版本的问题
72
+
73
+ - c2bb0f1: chore(server-utils): using pre-bundled tsconfig-paths
74
+
75
+ chore(server-utils): 使用预打包的 tsconfig-paths 依赖
76
+
77
+ - 14b712da84: fix: use consistent alias type and default value across packages
78
+
79
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
80
+
81
+ - Updated dependencies [6aca875]
82
+ - Updated dependencies [2e60319]
83
+ - Updated dependencies [92f0eade39]
84
+ - Updated dependencies [edd1cfb1af]
85
+ - Updated dependencies [cc971eabfc]
86
+ - Updated dependencies [5b9049f2e9]
87
+ - Updated dependencies [92004d1906]
88
+ - Updated dependencies [b8bbe036c7]
89
+ - Updated dependencies [d5a31df781]
90
+ - Updated dependencies [dda38c9c3e]
91
+ - Updated dependencies [3bbea92b2a]
92
+ - Updated dependencies [b710adb]
93
+ - Updated dependencies [f179749375]
94
+ - Updated dependencies [ea7cf06]
95
+ - Updated dependencies [bbe4c4a]
96
+ - Updated dependencies [e4558a0]
97
+ - Updated dependencies [abf3421a75]
98
+ - Updated dependencies [543be9558e]
99
+ - Updated dependencies [14b712da84]
100
+ - @modern-js/utils@2.0.0-beta.3
101
+ - @modern-js/plugin@2.0.0-beta.3
102
+ - @modern-js/babel-preset-lib@2.0.0-beta.3
103
+ - @modern-js/babel-compiler@2.0.0-beta.3
104
+
3
105
  ## 2.0.0-beta.2
4
106
 
5
107
  ### Major Changes
@@ -1,30 +1,55 @@
1
- import * as path from 'path';
2
- import { fs } from '@modern-js/utils';
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import * as path from "path";
22
+ import { fs } from "@modern-js/utils";
3
23
  import { compileByTs } from "../compilers/typescript";
4
24
  import { compileByBabel } from "../compilers/babel";
5
- export const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
25
+ const FILE_EXTENSIONS = [".js", ".ts", ".mjs", ".ejs"];
6
26
  const validateAbsolutePath = (filename, message) => {
7
27
  if (!path.isAbsolute(filename)) {
8
28
  throw new Error(message);
9
29
  }
10
30
  };
11
31
  const validateAbsolutePaths = (filenames, messageFunc) => {
12
- filenames.forEach(filename => validateAbsolutePath(filename, messageFunc(filename)));
32
+ filenames.forEach(
33
+ (filename) => validateAbsolutePath(filename, messageFunc(filename))
34
+ );
13
35
  };
14
- export const compile = async (appDirectory, modernConfig, compileOptions) => {
15
- var _modernConfig$server;
16
- const {
36
+ const compile = (appDirectory, modernConfig, compileOptions) => __async(void 0, null, function* () {
37
+ var _a;
38
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
39
+ validateAbsolutePaths(
17
40
  sourceDirs,
18
- distDir,
19
- tsconfigPath
20
- } = compileOptions;
21
- validateAbsolutePaths(sourceDirs, dir => `source dir ${dir} is not an absolute path.`);
41
+ (dir) => `source dir ${dir} is not an absolute path.`
42
+ );
22
43
  validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
23
- const compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$server = modernConfig.server) === null || _modernConfig$server === void 0 ? void 0 : _modernConfig$server.compiler;
24
- const isTsProject = tsconfigPath && (await fs.pathExists(tsconfigPath));
25
- if (!isTsProject || compiler === 'babel') {
26
- await compileByBabel(appDirectory, modernConfig, compileOptions);
44
+ const compiler = (_a = modernConfig == null ? void 0 : modernConfig.server) == null ? void 0 : _a.compiler;
45
+ const isTsProject = tsconfigPath && (yield fs.pathExists(tsconfigPath));
46
+ if (!isTsProject || compiler === "babel") {
47
+ yield compileByBabel(appDirectory, modernConfig, compileOptions);
27
48
  } else {
28
- await compileByTs(appDirectory, modernConfig, compileOptions);
49
+ yield compileByTs(appDirectory, modernConfig, compileOptions);
29
50
  }
30
- };
51
+ });
52
+ export {
53
+ FILE_EXTENSIONS,
54
+ compile
55
+ };
@@ -1,103 +1,149 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import * as path from 'path';
5
- import { getBabelChain, applyUserBabelConfig } from '@modern-js/babel-preset-lib';
6
- import { fs, json5, getAliasConfig } from '@modern-js/utils';
7
- import { compiler } from '@modern-js/babel-compiler';
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __async = (__this, __arguments, generator) => {
21
+ return new Promise((resolve, reject) => {
22
+ var fulfilled = (value) => {
23
+ try {
24
+ step(generator.next(value));
25
+ } catch (e) {
26
+ reject(e);
27
+ }
28
+ };
29
+ var rejected = (value) => {
30
+ try {
31
+ step(generator.throw(value));
32
+ } catch (e) {
33
+ reject(e);
34
+ }
35
+ };
36
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
+ step((generator = generator.apply(__this, __arguments)).next());
38
+ });
39
+ };
40
+ import * as path from "path";
41
+ import {
42
+ getBabelChain,
43
+ applyUserBabelConfig
44
+ } from "@modern-js/babel-preset-lib";
45
+ import { fs, json5, getAliasConfig } from "@modern-js/utils";
46
+ import { compiler } from "@modern-js/babel-compiler";
8
47
  import { FILE_EXTENSIONS } from "../../common";
9
- export * from '@babel/core';
10
- export const readTsConfig = (tsconfigPath, noExistReturn = null) => {
11
- // 如果不存在,则返回 noExistReturn
48
+ export * from "@babel/core";
49
+ const readTsConfig = (tsconfigPath, noExistReturn = null) => {
12
50
  if (!fs.existsSync(tsconfigPath)) {
13
51
  return noExistReturn;
14
52
  }
15
- const content = fs.readFileSync(tsconfigPath, 'utf-8');
53
+ const content = fs.readFileSync(tsconfigPath, "utf-8");
16
54
  return json5.parse(content);
17
55
  };
18
- export const existTsConfigFile = tsconfigAbsolutePath => {
56
+ const existTsConfigFile = (tsconfigAbsolutePath) => {
19
57
  const tsconfig = readTsConfig(tsconfigAbsolutePath);
20
58
  return Boolean(tsconfig);
21
59
  };
22
- export const getBabelConfig = (libPresetOption, syntaxOption) => {
60
+ const getBabelConfig = (libPresetOption, syntaxOption) => {
23
61
  const chain = getBabelChain(libPresetOption, syntaxOption);
24
- return _objectSpread({
25
- sourceType: 'unambiguous'
62
+ return __spreadValues({
63
+ sourceType: "unambiguous"
26
64
  }, chain.toJSON());
27
65
  };
28
- export const resolveBabelConfig = (appDirectory, config, option
29
- // FIXME: babel type can't pass type checking
30
- ) => {
31
- const {
32
- define,
33
- globalVars,
34
- alias,
35
- babelConfig
36
- } = config;
37
-
38
- // alias config
39
- const aliasConfig = getAliasConfig(alias, _objectSpread({
66
+ const resolveBabelConfig = (appDirectory, config, option) => {
67
+ const { globalVars, alias, babelConfig, define } = config;
68
+ const globalDefineVars = define && Object.entries(define).reduce((object, [key, value]) => {
69
+ object[key] = JSON.stringify(value);
70
+ return object;
71
+ }, {});
72
+ const aliasConfig = getAliasConfig(alias, __spreadValues({
40
73
  appDirectory
41
74
  }, option));
42
-
43
- // babel config
44
- const babelChain = getBabelChain({
45
- appDirectory,
46
- enableReactPreset: true,
47
- enableTypescriptPreset: true,
48
- alias: aliasConfig,
49
- // FIXME: handle the define envVars
50
- envVars: define,
51
- globalVars: globalVars
52
- }, {
53
- type: option.type,
54
- syntax: option.syntax
55
- });
56
- const envOptions = babelChain.preset('@babel/preset-env').options();
57
- babelChain.preset('@babel/preset-env').use(require.resolve('@babel/preset-env'), [_objectSpread(_objectSpread({}, envOptions[0]), {}, {
58
- loose: true
59
- })]);
60
- babelChain.plugin('babel-plugin-transform-typescript-metadata').use(require.resolve('babel-plugin-transform-typescript-metadata'), []);
61
- babelChain.plugin('@babel/plugin-proposal-decorators').use(require.resolve('@babel/plugin-proposal-decorators'), [{
62
- legacy: true
63
- }]);
64
-
65
- // resolve "Definitely assigned fields cannot be initialized here, but only in the constructor."
66
- babelChain.plugin('@babel/plugin-proposal-class-properties').use(require.resolve('@babel/plugin-proposal-class-properties'), [{
67
- loose: true
68
- }]);
69
- const internalBabelConfig = _objectSpread({}, babelChain.toJSON());
75
+ const babelChain = getBabelChain(
76
+ {
77
+ appDirectory,
78
+ enableReactPreset: true,
79
+ enableTypescriptPreset: true,
80
+ alias: aliasConfig,
81
+ envVars: [],
82
+ globalVars: __spreadValues(__spreadValues({}, globalVars), globalDefineVars)
83
+ },
84
+ {
85
+ type: option.type,
86
+ syntax: option.syntax
87
+ }
88
+ );
89
+ const envOptions = babelChain.preset("@babel/preset-env").options();
90
+ babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
91
+ __spreadProps(__spreadValues({}, envOptions[0]), {
92
+ loose: true
93
+ })
94
+ ]);
95
+ babelChain.plugin("babel-plugin-transform-typescript-metadata").use(
96
+ require.resolve("babel-plugin-transform-typescript-metadata"),
97
+ []
98
+ );
99
+ babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
100
+ { legacy: true }
101
+ ]);
102
+ babelChain.plugin("@babel/plugin-proposal-class-properties").use(require.resolve("@babel/plugin-proposal-class-properties"), [
103
+ {
104
+ loose: true
105
+ }
106
+ ]);
107
+ const internalBabelConfig = __spreadValues({}, babelChain.toJSON());
70
108
  return applyUserBabelConfig(internalBabelConfig, babelConfig);
71
109
  };
72
- export const compileByBabel = async (appDirectory, config, compileOptions) => {
73
- const {
74
- sourceDirs,
75
- distDir,
76
- tsconfigPath
77
- } = compileOptions;
78
- const results = await Promise.all(sourceDirs.map(async sourceDir => {
79
- const babelConfig = resolveBabelConfig(appDirectory, config, {
80
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
81
- syntax: 'es6+',
82
- type: 'commonjs'
83
- });
84
- if (await fs.pathExists(sourceDir)) {
85
- const basename = path.basename(sourceDir);
86
- const targetDir = path.join(distDir, basename);
87
- await fs.copy(sourceDir, targetDir, {
88
- filter: src => !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath
110
+ const compileByBabel = (appDirectory, config, compileOptions) => __async(void 0, null, function* () {
111
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
112
+ const results = yield Promise.all(
113
+ sourceDirs.map((sourceDir) => __async(void 0, null, function* () {
114
+ const babelConfig = resolveBabelConfig(appDirectory, config, {
115
+ tsconfigPath: tsconfigPath ? tsconfigPath : "",
116
+ syntax: "es6+",
117
+ type: "commonjs"
89
118
  });
90
- }
91
- return compiler({
92
- rootDir: appDirectory,
93
- distDir,
94
- sourceDir,
95
- extensions: FILE_EXTENSIONS
96
- }, babelConfig);
97
- }));
98
- results.forEach(result => {
119
+ if (yield fs.pathExists(sourceDir)) {
120
+ const basename = path.basename(sourceDir);
121
+ const targetDir = path.join(distDir, basename);
122
+ yield fs.copy(sourceDir, targetDir, {
123
+ filter: (src) => ![".ts", ".js"].includes(path.extname(src)) && src !== tsconfigPath
124
+ });
125
+ }
126
+ return compiler(
127
+ {
128
+ rootDir: appDirectory,
129
+ distDir,
130
+ sourceDir,
131
+ extensions: FILE_EXTENSIONS
132
+ },
133
+ babelConfig
134
+ );
135
+ }))
136
+ );
137
+ results.forEach((result) => {
99
138
  if (result.code === 1) {
100
139
  throw new Error(result.message);
101
140
  }
102
141
  });
103
- };
142
+ });
143
+ export {
144
+ compileByBabel,
145
+ existTsConfigFile,
146
+ getBabelConfig,
147
+ readTsConfig,
148
+ resolveBabelConfig
149
+ };
@@ -1,97 +1,123 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import path from 'path';
5
- import { logger, getAliasConfig, fs } from '@modern-js/utils';
6
- import ts from 'typescript';
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
36
+ };
37
+ import path from "path";
38
+ import { logger, getAliasConfig, fs } from "@modern-js/utils";
39
+ import ts from "typescript";
7
40
  import { TypescriptLoader } from "./typescript-loader";
8
41
  import { tsconfigPathsBeforeHookFactory } from "./tsconfig-paths-plugin";
9
- const readTsConfigByFile = tsConfigFile => {
10
- const parsedCmd = ts.getParsedCommandLineOfConfigFile(tsConfigFile, undefined, ts.sys);
11
- const {
12
- options,
13
- fileNames,
14
- projectReferences
15
- } = parsedCmd;
16
- return {
17
- options,
18
- fileNames,
19
- projectReferences
20
- };
42
+ const readTsConfigByFile = (tsConfigFile) => {
43
+ const parsedCmd = ts.getParsedCommandLineOfConfigFile(
44
+ tsConfigFile,
45
+ void 0,
46
+ ts.sys
47
+ );
48
+ const { options, fileNames, projectReferences } = parsedCmd;
49
+ return { options, fileNames, projectReferences };
21
50
  };
22
- const copyFiles = async (from, to, tsconfigPath) => {
23
- if (await fs.pathExists(from)) {
51
+ const copyFiles = (from, to, tsconfigPath) => __async(void 0, null, function* () {
52
+ if (yield fs.pathExists(from)) {
24
53
  const basename = path.basename(from);
25
54
  const targetDir = path.join(to, basename);
26
- await fs.copy(from, targetDir, {
27
- filter: src => !['.ts'].includes(path.extname(src)) && src !== tsconfigPath
55
+ yield fs.copy(from, targetDir, {
56
+ filter: (src) => ![".ts"].includes(path.extname(src)) && src !== tsconfigPath
28
57
  });
29
58
  }
30
- };
31
- export const compileByTs = async (appDirectory, config, compileOptions) => {
59
+ });
60
+ const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, null, function* () {
32
61
  logger.info(`Running ts compile...`);
33
- const {
34
- sourceDirs,
35
- distDir,
36
- tsconfigPath
37
- } = compileOptions;
62
+ const { sourceDirs, distDir, tsconfigPath } = compileOptions;
38
63
  if (!tsconfigPath) {
39
64
  return;
40
65
  }
41
- const ts = new TypescriptLoader({
66
+ const ts2 = new TypescriptLoader({
42
67
  appDirectory
43
68
  }).load();
44
- const createProgram = ts.createIncrementalProgram || ts.createProgram;
45
- const formatHost = getFormatHost(ts);
46
- const {
47
- alias
48
- } = config;
69
+ const createProgram = ts2.createIncrementalProgram || ts2.createProgram;
70
+ const formatHost = getFormatHost(ts2);
71
+ const { alias } = config;
49
72
  const aliasOption = getAliasConfig(alias, {
50
73
  appDirectory,
51
74
  tsconfigPath
52
75
  });
53
- const {
54
- paths = {},
55
- absoluteBaseUrl = './'
56
- } = aliasOption;
57
- const {
58
- options,
59
- fileNames,
60
- projectReferences
61
- } = readTsConfigByFile(tsconfigPath);
62
- const sourcePosixPaths = sourceDirs.map(sourceDir => sourceDir.split(path.sep).join(path.posix.sep));
63
- const rootNames = fileNames.filter(fileName => {
64
- return fileName.endsWith('.d.ts') || sourcePosixPaths.some(sourceDir => {
76
+ const { paths = {}, absoluteBaseUrl = "./" } = aliasOption;
77
+ const { options, fileNames, projectReferences } = readTsConfigByFile(tsconfigPath);
78
+ const sourcePosixPaths = sourceDirs.map(
79
+ (sourceDir) => sourceDir.split(path.sep).join(path.posix.sep)
80
+ );
81
+ const rootNames = fileNames.filter((fileName) => {
82
+ return fileName.endsWith(".d.ts") || sourcePosixPaths.some((sourceDir) => {
65
83
  return fileName.includes(sourceDir);
66
84
  });
67
85
  });
68
- const program = createProgram.call(ts, {
86
+ const program = createProgram.call(ts2, {
69
87
  rootNames,
70
88
  projectReferences,
71
- options: _objectSpread({
89
+ options: __spreadValues({
72
90
  rootDir: appDirectory,
73
91
  outDir: distDir
74
92
  }, options)
75
93
  });
76
- const tsconfigPathsPlugin = tsconfigPathsBeforeHookFactory(ts, absoluteBaseUrl, paths);
77
- const emitResult = program.emit(undefined, undefined, undefined, undefined, {
94
+ const tsconfigPathsPlugin = tsconfigPathsBeforeHookFactory(
95
+ ts2,
96
+ absoluteBaseUrl,
97
+ paths
98
+ );
99
+ const emitResult = program.emit(void 0, void 0, void 0, void 0, {
78
100
  before: [tsconfigPathsPlugin]
79
101
  });
80
- const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
102
+ const allDiagnostics = ts2.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
81
103
  if (allDiagnostics.length > 0) {
82
- logger.error(ts.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost));
83
- // eslint-disable-next-line no-process-exit
104
+ logger.error(
105
+ ts2.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost)
106
+ );
84
107
  process.exit(1);
85
108
  }
86
109
  for (const source of sourceDirs) {
87
- await copyFiles(source, distDir, tsconfigPath);
110
+ yield copyFiles(source, distDir, tsconfigPath);
88
111
  }
89
112
  logger.info(`Ts compile succeed`);
90
- };
91
- const getFormatHost = ts => {
113
+ });
114
+ const getFormatHost = (ts2) => {
92
115
  return {
93
- getCanonicalFileName: path => path,
94
- getCurrentDirectory: ts.sys.getCurrentDirectory,
95
- getNewLine: () => ts.sys.newLine
116
+ getCanonicalFileName: (path2) => path2,
117
+ getCurrentDirectory: ts2.sys.getCurrentDirectory,
118
+ getNewLine: () => ts2.sys.newLine
96
119
  };
97
- };
120
+ };
121
+ export {
122
+ compileByTs
123
+ };