@modern-js/server-utils 2.0.0-beta.3 → 2.0.0-beta.6
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 +109 -0
- package/dist/js/modern/common/index.js +42 -17
- package/dist/js/modern/compilers/babel/index.js +124 -78
- package/dist/js/modern/compilers/typescript/index.js +87 -61
- package/dist/js/modern/compilers/typescript/tsconfig-paths-plugin.js +77 -47
- package/dist/js/modern/compilers/typescript/typescript-loader.js +10 -10
- package/dist/js/modern/index.js +4 -1
- package/dist/js/node/common/index.js +73 -28
- package/dist/js/node/compilers/babel/index.js +152 -108
- package/dist/js/node/compilers/typescript/index.js +120 -75
- package/dist/js/node/compilers/typescript/tsconfig-paths-plugin.js +106 -55
- package/dist/js/node/compilers/typescript/typescript-loader.js +30 -14
- package/dist/js/node/index.js +25 -23
- package/dist/js/treeshaking/common/index.js +199 -60
- package/dist/js/treeshaking/compilers/babel/index.js +362 -140
- package/dist/js/treeshaking/compilers/typescript/index.js +332 -149
- package/dist/js/treeshaking/compilers/typescript/tsconfig-paths-plugin.js +229 -154
- package/dist/js/treeshaking/compilers/typescript/typescript-loader.js +63 -28
- package/dist/js/treeshaking/index.js +2 -1
- package/package.json +8 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,114 @@
|
|
|
1
1
|
# @modern-js/server-utils
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.6
|
|
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
|
+
- 7879e8f711: 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 [7879e8f711]
|
|
32
|
+
- Updated dependencies [6aca875011]
|
|
33
|
+
- Updated dependencies [2e6031955e]
|
|
34
|
+
- Updated dependencies [7b7d12cf8f]
|
|
35
|
+
- Updated dependencies [7efeed4]
|
|
36
|
+
- Updated dependencies [92f0eade39]
|
|
37
|
+
- Updated dependencies [edd1cfb1af]
|
|
38
|
+
- Updated dependencies [cc971eabfc]
|
|
39
|
+
- Updated dependencies [5b9049f2e9]
|
|
40
|
+
- Updated dependencies [92004d1906]
|
|
41
|
+
- Updated dependencies [b8bbe036c7]
|
|
42
|
+
- Updated dependencies [d5a31df781]
|
|
43
|
+
- Updated dependencies [dda38c9c3e]
|
|
44
|
+
- Updated dependencies [3bbea92b2a]
|
|
45
|
+
- Updated dependencies [b710adb843]
|
|
46
|
+
- Updated dependencies [f179749375]
|
|
47
|
+
- Updated dependencies [ea7cf06257]
|
|
48
|
+
- Updated dependencies [bbe4c4ab64]
|
|
49
|
+
- Updated dependencies [e4558a0bc4]
|
|
50
|
+
- Updated dependencies [abf3421a75]
|
|
51
|
+
- Updated dependencies [543be9558e]
|
|
52
|
+
- Updated dependencies [14b712da84]
|
|
53
|
+
- @modern-js/utils@2.0.0-beta.6
|
|
54
|
+
- @modern-js/plugin@2.0.0-beta.6
|
|
55
|
+
- @modern-js/babel-preset-lib@2.0.0-beta.6
|
|
56
|
+
- @modern-js/babel-compiler@2.0.0-beta.6
|
|
57
|
+
|
|
58
|
+
## 2.0.0-beta.4
|
|
59
|
+
|
|
60
|
+
### Major Changes
|
|
61
|
+
|
|
62
|
+
- dda38c9c3e: chore: v2
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- 9b915e0c10: fix: tsconfig-paths plugin's new node use old node flag
|
|
67
|
+
fix: tsconfig-paths 插件转换的新节点使用旧节点的 flag
|
|
68
|
+
- 7879e8f: refactor: remove enableModernMode config
|
|
69
|
+
|
|
70
|
+
refactor: 不再支持 enableModernMode 配置项
|
|
71
|
+
|
|
72
|
+
- d4e8e6fb90: fix: modernjs dev server can't start normaly
|
|
73
|
+
fix: modernjs dev 服务端不能正常启动
|
|
74
|
+
- a8642da58f: fix(server-utils): incorrect babel-compiler version
|
|
75
|
+
|
|
76
|
+
fix(server-utils): 修复引用错误的 babel-compiler 版本的问题
|
|
77
|
+
|
|
78
|
+
- c2bb0f1745: chore(server-utils): using pre-bundled tsconfig-paths
|
|
79
|
+
|
|
80
|
+
chore(server-utils): 使用预打包的 tsconfig-paths 依赖
|
|
81
|
+
|
|
82
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
83
|
+
|
|
84
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
85
|
+
|
|
86
|
+
- Updated dependencies [7879e8f]
|
|
87
|
+
- Updated dependencies [6aca875]
|
|
88
|
+
- Updated dependencies [2e6031955e]
|
|
89
|
+
- Updated dependencies [7b7d12c]
|
|
90
|
+
- Updated dependencies [92f0eade39]
|
|
91
|
+
- Updated dependencies [edd1cfb1af]
|
|
92
|
+
- Updated dependencies [cc971eabfc]
|
|
93
|
+
- Updated dependencies [5b9049f2e9]
|
|
94
|
+
- Updated dependencies [92004d1906]
|
|
95
|
+
- Updated dependencies [b8bbe036c7]
|
|
96
|
+
- Updated dependencies [d5a31df781]
|
|
97
|
+
- Updated dependencies [dda38c9c3e]
|
|
98
|
+
- Updated dependencies [3bbea92b2a]
|
|
99
|
+
- Updated dependencies [b710adb843]
|
|
100
|
+
- Updated dependencies [f179749375]
|
|
101
|
+
- Updated dependencies [ea7cf06]
|
|
102
|
+
- Updated dependencies [bbe4c4a]
|
|
103
|
+
- Updated dependencies [e4558a0]
|
|
104
|
+
- Updated dependencies [abf3421a75]
|
|
105
|
+
- Updated dependencies [543be9558e]
|
|
106
|
+
- Updated dependencies [14b712da84]
|
|
107
|
+
- @modern-js/utils@2.0.0-beta.4
|
|
108
|
+
- @modern-js/plugin@2.0.0-beta.4
|
|
109
|
+
- @modern-js/babel-preset-lib@2.0.0-beta.4
|
|
110
|
+
- @modern-js/babel-compiler@2.0.0-beta.4
|
|
111
|
+
|
|
3
112
|
## 2.0.0-beta.3
|
|
4
113
|
|
|
5
114
|
### Major Changes
|
|
@@ -1,30 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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(
|
|
32
|
+
filenames.forEach(
|
|
33
|
+
(filename) => validateAbsolutePath(filename, messageFunc(filename))
|
|
34
|
+
);
|
|
13
35
|
};
|
|
14
|
-
|
|
15
|
-
var
|
|
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
|
-
|
|
19
|
-
|
|
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 =
|
|
24
|
-
const isTsProject = tsconfigPath && (
|
|
25
|
-
if (!isTsProject || compiler ===
|
|
26
|
-
|
|
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
|
-
|
|
49
|
+
yield compileByTs(appDirectory, modernConfig, compileOptions);
|
|
29
50
|
}
|
|
30
|
-
};
|
|
51
|
+
});
|
|
52
|
+
export {
|
|
53
|
+
FILE_EXTENSIONS,
|
|
54
|
+
compile
|
|
55
|
+
};
|
|
@@ -1,103 +1,149 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
10
|
-
|
|
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,
|
|
53
|
+
const content = fs.readFileSync(tsconfigPath, "utf-8");
|
|
16
54
|
return json5.parse(content);
|
|
17
55
|
};
|
|
18
|
-
|
|
56
|
+
const existTsConfigFile = (tsconfigAbsolutePath) => {
|
|
19
57
|
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
20
58
|
return Boolean(tsconfig);
|
|
21
59
|
};
|
|
22
|
-
|
|
60
|
+
const getBabelConfig = (libPresetOption, syntaxOption) => {
|
|
23
61
|
const chain = getBabelChain(libPresetOption, syntaxOption);
|
|
24
|
-
return
|
|
25
|
-
sourceType:
|
|
62
|
+
return __spreadValues({
|
|
63
|
+
sourceType: "unambiguous"
|
|
26
64
|
}, chain.toJSON());
|
|
27
65
|
};
|
|
28
|
-
|
|
29
|
-
const {
|
|
30
|
-
globalVars,
|
|
31
|
-
alias,
|
|
32
|
-
babelConfig,
|
|
33
|
-
define
|
|
34
|
-
} = config;
|
|
66
|
+
const resolveBabelConfig = (appDirectory, config, option) => {
|
|
67
|
+
const { globalVars, alias, babelConfig, define } = config;
|
|
35
68
|
const globalDefineVars = define && Object.entries(define).reduce((object, [key, value]) => {
|
|
36
69
|
object[key] = JSON.stringify(value);
|
|
37
70
|
return object;
|
|
38
71
|
}, {});
|
|
39
|
-
|
|
40
|
-
const aliasConfig = getAliasConfig(alias, _objectSpread({
|
|
72
|
+
const aliasConfig = getAliasConfig(alias, __spreadValues({
|
|
41
73
|
appDirectory
|
|
42
74
|
}, option));
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
babelChain.preset(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 =
|
|
23
|
-
if (
|
|
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
|
-
|
|
27
|
-
filter: src => ![
|
|
55
|
+
yield fs.copy(from, targetDir, {
|
|
56
|
+
filter: (src) => ![".ts"].includes(path.extname(src)) && src !== tsconfigPath
|
|
28
57
|
});
|
|
29
58
|
}
|
|
30
|
-
};
|
|
31
|
-
|
|
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
|
|
66
|
+
const ts2 = new TypescriptLoader({
|
|
42
67
|
appDirectory
|
|
43
68
|
}).load();
|
|
44
|
-
const createProgram =
|
|
45
|
-
const formatHost = getFormatHost(
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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(
|
|
86
|
+
const program = createProgram.call(ts2, {
|
|
69
87
|
rootNames,
|
|
70
88
|
projectReferences,
|
|
71
|
-
options:
|
|
89
|
+
options: __spreadValues({
|
|
72
90
|
rootDir: appDirectory,
|
|
73
91
|
outDir: distDir
|
|
74
92
|
}, options)
|
|
75
93
|
});
|
|
76
|
-
const tsconfigPathsPlugin = tsconfigPathsBeforeHookFactory(
|
|
77
|
-
|
|
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 =
|
|
102
|
+
const allDiagnostics = ts2.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
81
103
|
if (allDiagnostics.length > 0) {
|
|
82
|
-
logger.error(
|
|
83
|
-
|
|
104
|
+
logger.error(
|
|
105
|
+
ts2.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost)
|
|
106
|
+
);
|
|
84
107
|
process.exit(1);
|
|
85
108
|
}
|
|
86
109
|
for (const source of sourceDirs) {
|
|
87
|
-
|
|
110
|
+
yield copyFiles(source, distDir, tsconfigPath);
|
|
88
111
|
}
|
|
89
112
|
logger.info(`Ts compile succeed`);
|
|
90
|
-
};
|
|
91
|
-
const getFormatHost =
|
|
113
|
+
});
|
|
114
|
+
const getFormatHost = (ts2) => {
|
|
92
115
|
return {
|
|
93
|
-
getCanonicalFileName:
|
|
94
|
-
getCurrentDirectory:
|
|
95
|
-
getNewLine: () =>
|
|
116
|
+
getCanonicalFileName: (path2) => path2,
|
|
117
|
+
getCurrentDirectory: ts2.sys.getCurrentDirectory,
|
|
118
|
+
getNewLine: () => ts2.sys.newLine
|
|
96
119
|
};
|
|
97
|
-
};
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
compileByTs
|
|
123
|
+
};
|