@modern-js/server-utils 2.4.0 → 2.5.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 +18 -0
- package/dist/{js/node → cjs}/common/index.js +5 -25
- package/dist/{js/node → cjs}/compilers/babel/index.js +23 -54
- package/dist/{js/node → cjs}/compilers/typescript/index.js +11 -44
- package/dist/{js/node → cjs}/compilers/typescript/tsconfig-paths-plugin.js +3 -3
- package/dist/{js/node → cjs}/compilers/typescript/typescript-loader.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/common/index.js +2 -2
- package/dist/{js/treeshaking → esm}/compilers/babel/index.js +0 -0
- package/dist/{js/treeshaking → esm}/compilers/typescript/index.js +3 -3
- package/dist/{js/treeshaking → esm}/compilers/typescript/tsconfig-paths-plugin.js +3 -3
- package/dist/{js/treeshaking → esm}/compilers/typescript/typescript-loader.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/modern → esm-node}/common/index.js +5 -25
- package/dist/{js/modern → esm-node}/compilers/babel/index.js +23 -56
- package/dist/{js/modern → esm-node}/compilers/typescript/index.js +11 -46
- package/dist/{js/modern → esm-node}/compilers/typescript/tsconfig-paths-plugin.js +3 -3
- package/dist/{js/modern → esm-node}/compilers/typescript/typescript-loader.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/package.json +12 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @modern-js/server-utils
|
|
2
2
|
|
|
3
|
+
## 2.5.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 89ca6cc: refactor: merge build-config into scripts/build
|
|
8
|
+
|
|
9
|
+
refactor: 把 build-config 合并进 scripts/build
|
|
10
|
+
|
|
11
|
+
- 30614fa: chore: modify package.json entry fields and build config
|
|
12
|
+
chore: 更改 package.json entry 字段以及构建配置
|
|
13
|
+
- Updated dependencies [89ca6cc]
|
|
14
|
+
- Updated dependencies [30614fa]
|
|
15
|
+
- Updated dependencies [1b0ce87]
|
|
16
|
+
- Updated dependencies [11c053b]
|
|
17
|
+
- @modern-js/babel-preset-lib@2.5.0
|
|
18
|
+
- @modern-js/babel-compiler@2.5.0
|
|
19
|
+
- @modern-js/utils@2.5.0
|
|
20
|
+
|
|
3
21
|
## 2.4.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
mod
|
|
22
22
|
));
|
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
-
var __async = (__this, __arguments, generator) => {
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
var fulfilled = (value) => {
|
|
27
|
-
try {
|
|
28
|
-
step(generator.next(value));
|
|
29
|
-
} catch (e) {
|
|
30
|
-
reject(e);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
var rejected = (value) => {
|
|
34
|
-
try {
|
|
35
|
-
step(generator.throw(value));
|
|
36
|
-
} catch (e) {
|
|
37
|
-
reject(e);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
24
|
var common_exports = {};
|
|
45
25
|
__export(common_exports, {
|
|
46
26
|
FILE_EXTENSIONS: () => FILE_EXTENSIONS,
|
|
@@ -62,7 +42,7 @@ const validateAbsolutePaths = (filenames, messageFunc) => {
|
|
|
62
42
|
(filename) => validateAbsolutePath(filename, messageFunc(filename))
|
|
63
43
|
);
|
|
64
44
|
};
|
|
65
|
-
const compile = (appDirectory, modernConfig, compileOptions) =>
|
|
45
|
+
const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
66
46
|
var _a;
|
|
67
47
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
68
48
|
validateAbsolutePaths(
|
|
@@ -71,13 +51,13 @@ const compile = (appDirectory, modernConfig, compileOptions) => __async(void 0,
|
|
|
71
51
|
);
|
|
72
52
|
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
73
53
|
const compiler = (_a = modernConfig == null ? void 0 : modernConfig.server) == null ? void 0 : _a.compiler;
|
|
74
|
-
const isTsProject = tsconfigPath &&
|
|
54
|
+
const isTsProject = tsconfigPath && await import_utils.fs.pathExists(tsconfigPath);
|
|
75
55
|
if (!isTsProject || compiler === "babel") {
|
|
76
|
-
|
|
56
|
+
await (0, import_babel.compileByBabel)(appDirectory, modernConfig, compileOptions);
|
|
77
57
|
} else {
|
|
78
|
-
|
|
58
|
+
await (0, import_typescript.compileByTs)(appDirectory, modernConfig, compileOptions);
|
|
79
59
|
}
|
|
80
|
-
}
|
|
60
|
+
};
|
|
81
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
82
62
|
0 && (module.exports = {
|
|
83
63
|
FILE_EXTENSIONS,
|
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
7
|
var __export = (target, all) => {
|
|
25
8
|
for (var name in all)
|
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -39,26 +22,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
39
22
|
mod
|
|
40
23
|
));
|
|
41
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
42
|
-
var __async = (__this, __arguments, generator) => {
|
|
43
|
-
return new Promise((resolve, reject) => {
|
|
44
|
-
var fulfilled = (value) => {
|
|
45
|
-
try {
|
|
46
|
-
step(generator.next(value));
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
var rejected = (value) => {
|
|
52
|
-
try {
|
|
53
|
-
step(generator.throw(value));
|
|
54
|
-
} catch (e) {
|
|
55
|
-
reject(e);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
59
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
25
|
var babel_exports = {};
|
|
63
26
|
__export(babel_exports, {
|
|
64
27
|
compileByBabel: () => compileByBabel,
|
|
@@ -87,9 +50,10 @@ const existTsConfigFile = (tsconfigAbsolutePath) => {
|
|
|
87
50
|
};
|
|
88
51
|
const getBabelConfig = (libPresetOption, syntaxOption) => {
|
|
89
52
|
const chain = (0, import_babel_preset_lib.getBabelChain)(libPresetOption, syntaxOption);
|
|
90
|
-
return
|
|
91
|
-
sourceType: "unambiguous"
|
|
92
|
-
|
|
53
|
+
return {
|
|
54
|
+
sourceType: "unambiguous",
|
|
55
|
+
...chain.toJSON()
|
|
56
|
+
};
|
|
93
57
|
};
|
|
94
58
|
const resolveBabelConfig = (appDirectory, config, option) => {
|
|
95
59
|
const { globalVars, alias, babelConfig, define } = config;
|
|
@@ -97,9 +61,10 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
97
61
|
object[key] = JSON.stringify(value);
|
|
98
62
|
return object;
|
|
99
63
|
}, {});
|
|
100
|
-
const aliasConfig = (0, import_utils.getAliasConfig)(alias,
|
|
101
|
-
appDirectory
|
|
102
|
-
|
|
64
|
+
const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
|
|
65
|
+
appDirectory,
|
|
66
|
+
...option
|
|
67
|
+
});
|
|
103
68
|
const babelChain = (0, import_babel_preset_lib.getBabelChain)(
|
|
104
69
|
{
|
|
105
70
|
appDirectory,
|
|
@@ -107,7 +72,10 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
107
72
|
enableTypescriptPreset: true,
|
|
108
73
|
alias: aliasConfig,
|
|
109
74
|
envVars: [],
|
|
110
|
-
globalVars:
|
|
75
|
+
globalVars: {
|
|
76
|
+
...globalVars,
|
|
77
|
+
...globalDefineVars
|
|
78
|
+
}
|
|
111
79
|
},
|
|
112
80
|
{
|
|
113
81
|
type: option.type,
|
|
@@ -116,9 +84,10 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
116
84
|
);
|
|
117
85
|
const envOptions = babelChain.preset("@babel/preset-env").options();
|
|
118
86
|
babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
|
|
119
|
-
|
|
87
|
+
{
|
|
88
|
+
...envOptions[0],
|
|
120
89
|
loose: true
|
|
121
|
-
}
|
|
90
|
+
}
|
|
122
91
|
]);
|
|
123
92
|
babelChain.plugin("babel-plugin-transform-typescript-metadata").use(
|
|
124
93
|
require.resolve("babel-plugin-transform-typescript-metadata"),
|
|
@@ -132,22 +101,22 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
132
101
|
loose: true
|
|
133
102
|
}
|
|
134
103
|
]);
|
|
135
|
-
const internalBabelConfig =
|
|
104
|
+
const internalBabelConfig = { ...babelChain.toJSON() };
|
|
136
105
|
return (0, import_babel_preset_lib.applyUserBabelConfig)(internalBabelConfig, babelConfig);
|
|
137
106
|
};
|
|
138
|
-
const compileByBabel = (appDirectory, config, compileOptions) =>
|
|
107
|
+
const compileByBabel = async (appDirectory, config, compileOptions) => {
|
|
139
108
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
140
|
-
const results =
|
|
141
|
-
sourceDirs.map((sourceDir) =>
|
|
109
|
+
const results = await Promise.all(
|
|
110
|
+
sourceDirs.map(async (sourceDir) => {
|
|
142
111
|
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
143
112
|
tsconfigPath: tsconfigPath ? tsconfigPath : "",
|
|
144
113
|
syntax: "es6+",
|
|
145
114
|
type: "commonjs"
|
|
146
115
|
});
|
|
147
|
-
if (
|
|
116
|
+
if (await import_utils.fs.pathExists(sourceDir)) {
|
|
148
117
|
const basename = path.basename(sourceDir);
|
|
149
118
|
const targetDir = path.join(distDir, basename);
|
|
150
|
-
|
|
119
|
+
await import_utils.fs.copy(sourceDir, targetDir, {
|
|
151
120
|
filter: (src) => ![".ts", ".js"].includes(path.extname(src)) && src !== tsconfigPath
|
|
152
121
|
});
|
|
153
122
|
}
|
|
@@ -160,14 +129,14 @@ const compileByBabel = (appDirectory, config, compileOptions) => __async(void 0,
|
|
|
160
129
|
},
|
|
161
130
|
babelConfig
|
|
162
131
|
);
|
|
163
|
-
})
|
|
132
|
+
})
|
|
164
133
|
);
|
|
165
134
|
results.forEach((result) => {
|
|
166
135
|
if (result.code === 1) {
|
|
167
136
|
throw new Error(result.message);
|
|
168
137
|
}
|
|
169
138
|
});
|
|
170
|
-
}
|
|
139
|
+
};
|
|
171
140
|
// Annotate the CommonJS export names for ESM import in node:
|
|
172
141
|
0 && (module.exports = {
|
|
173
142
|
compileByBabel,
|
|
@@ -2,22 +2,8 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
-
var __spreadValues = (a, b) => {
|
|
11
|
-
for (var prop in b || (b = {}))
|
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
if (__getOwnPropSymbols)
|
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
-
if (__propIsEnum.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
}
|
|
19
|
-
return a;
|
|
20
|
-
};
|
|
21
7
|
var __export = (target, all) => {
|
|
22
8
|
for (var name in all)
|
|
23
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -35,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
35
21
|
mod
|
|
36
22
|
));
|
|
37
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var __async = (__this, __arguments, generator) => {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
var fulfilled = (value) => {
|
|
41
|
-
try {
|
|
42
|
-
step(generator.next(value));
|
|
43
|
-
} catch (e) {
|
|
44
|
-
reject(e);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var rejected = (value) => {
|
|
48
|
-
try {
|
|
49
|
-
step(generator.throw(value));
|
|
50
|
-
} catch (e) {
|
|
51
|
-
reject(e);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
55
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
24
|
var typescript_exports = {};
|
|
59
25
|
__export(typescript_exports, {
|
|
60
26
|
compileByTs: () => compileByTs
|
|
@@ -74,16 +40,16 @@ const readTsConfigByFile = (tsConfigFile) => {
|
|
|
74
40
|
const { options, fileNames, projectReferences } = parsedCmd;
|
|
75
41
|
return { options, fileNames, projectReferences };
|
|
76
42
|
};
|
|
77
|
-
const copyFiles = (from, to, tsconfigPath) =>
|
|
78
|
-
if (
|
|
43
|
+
const copyFiles = async (from, to, tsconfigPath) => {
|
|
44
|
+
if (await import_utils.fs.pathExists(from)) {
|
|
79
45
|
const basename = import_path.default.basename(from);
|
|
80
46
|
const targetDir = import_path.default.join(to, basename);
|
|
81
|
-
|
|
47
|
+
await import_utils.fs.copy(from, targetDir, {
|
|
82
48
|
filter: (src) => ![".ts"].includes(import_path.default.extname(src)) && src !== tsconfigPath
|
|
83
49
|
});
|
|
84
50
|
}
|
|
85
|
-
}
|
|
86
|
-
const compileByTs = (appDirectory, config, compileOptions) =>
|
|
51
|
+
};
|
|
52
|
+
const compileByTs = async (appDirectory, config, compileOptions) => {
|
|
87
53
|
import_utils.logger.info(`Running ts compile...`);
|
|
88
54
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
89
55
|
if (!tsconfigPath) {
|
|
@@ -112,10 +78,11 @@ const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, nu
|
|
|
112
78
|
const program = createProgram.call(ts2, {
|
|
113
79
|
rootNames,
|
|
114
80
|
projectReferences,
|
|
115
|
-
options:
|
|
81
|
+
options: {
|
|
116
82
|
rootDir: appDirectory,
|
|
117
|
-
outDir: distDir
|
|
118
|
-
|
|
83
|
+
outDir: distDir,
|
|
84
|
+
...options
|
|
85
|
+
}
|
|
119
86
|
});
|
|
120
87
|
const tsconfigPathsPlugin = (0, import_tsconfig_paths_plugin.tsconfigPathsBeforeHookFactory)(
|
|
121
88
|
ts2,
|
|
@@ -133,10 +100,10 @@ const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, nu
|
|
|
133
100
|
process.exit(1);
|
|
134
101
|
}
|
|
135
102
|
for (const source of sourceDirs) {
|
|
136
|
-
|
|
103
|
+
await copyFiles(source, distDir, tsconfigPath);
|
|
137
104
|
}
|
|
138
105
|
import_utils.logger.info(`Ts compile succeed`);
|
|
139
|
-
}
|
|
106
|
+
};
|
|
140
107
|
const getFormatHost = (ts2) => {
|
|
141
108
|
return {
|
|
142
109
|
getCanonicalFileName: (path2) => path2,
|
|
@@ -162,7 +162,7 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
162
162
|
}
|
|
163
163
|
newNode.flags = node.flags;
|
|
164
164
|
return newNode;
|
|
165
|
-
} catch
|
|
165
|
+
} catch {
|
|
166
166
|
return node;
|
|
167
167
|
}
|
|
168
168
|
}
|
|
@@ -194,7 +194,7 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
194
194
|
if (packagePath) {
|
|
195
195
|
return result;
|
|
196
196
|
}
|
|
197
|
-
} catch
|
|
197
|
+
} catch {
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
try {
|
|
@@ -204,7 +204,7 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
204
204
|
if (packagePath) {
|
|
205
205
|
return text;
|
|
206
206
|
}
|
|
207
|
-
} catch
|
|
207
|
+
} catch {
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
210
|
const resolvedPath = import_path.posix.relative((0, import_path.dirname)(sf.fileName), result) || "./";
|
|
File without changes
|
|
File without changes
|
|
@@ -144,7 +144,7 @@ var validateAbsolutePaths = function(filenames, messageFunc) {
|
|
|
144
144
|
};
|
|
145
145
|
var compile = function() {
|
|
146
146
|
var _ref = _asyncToGenerator(function(appDirectory, modernConfig, compileOptions) {
|
|
147
|
-
var
|
|
147
|
+
var _modernConfig_server, sourceDirs, distDir, tsconfigPath, compiler, isTsProject, _tmp;
|
|
148
148
|
return __generator(this, function(_state) {
|
|
149
149
|
switch(_state.label){
|
|
150
150
|
case 0:
|
|
@@ -153,7 +153,7 @@ var compile = function() {
|
|
|
153
153
|
return "source dir ".concat(dir, " is not an absolute path.");
|
|
154
154
|
});
|
|
155
155
|
validateAbsolutePath(distDir, "dist dir ".concat(distDir, " is not an absolute path."));
|
|
156
|
-
compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (
|
|
156
|
+
compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_server = modernConfig.server) === null || _modernConfig_server === void 0 ? void 0 : _modernConfig_server.compiler;
|
|
157
157
|
_tmp = tsconfigPath;
|
|
158
158
|
if (!_tmp) return [
|
|
159
159
|
3,
|
|
File without changes
|
|
@@ -207,7 +207,7 @@ var copyFiles = function() {
|
|
|
207
207
|
}();
|
|
208
208
|
var compileByTs = function() {
|
|
209
209
|
var _ref = _asyncToGenerator(function(appDirectory, config, compileOptions) {
|
|
210
|
-
var sourceDirs, distDir, tsconfigPath, ts2, createProgram, formatHost, alias, aliasOption,
|
|
210
|
+
var sourceDirs, distDir, tsconfigPath, ts2, createProgram, formatHost, alias, aliasOption, _aliasOption_paths, paths, _aliasOption_absoluteBaseUrl, absoluteBaseUrl, _readTsConfigByFile, options, fileNames, projectReferences, sourcePosixPaths, rootNames, program, tsconfigPathsPlugin, emitResult, allDiagnostics, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, source, err;
|
|
211
211
|
return __generator(this, function(_state) {
|
|
212
212
|
switch(_state.label){
|
|
213
213
|
case 0:
|
|
@@ -228,8 +228,8 @@ var compileByTs = function() {
|
|
|
228
228
|
appDirectory: appDirectory,
|
|
229
229
|
tsconfigPath: tsconfigPath
|
|
230
230
|
});
|
|
231
|
-
|
|
232
|
-
|
|
231
|
+
_aliasOption_paths = aliasOption.paths, paths = _aliasOption_paths === void 0 ? {} : _aliasOption_paths, _aliasOption_absoluteBaseUrl = aliasOption.absoluteBaseUrl, absoluteBaseUrl = _aliasOption_absoluteBaseUrl === void 0 ? "./" : _aliasOption_absoluteBaseUrl;
|
|
232
|
+
_readTsConfigByFile = readTsConfigByFile(tsconfigPath), options = _readTsConfigByFile.options, fileNames = _readTsConfigByFile.fileNames, projectReferences = _readTsConfigByFile.projectReferences;
|
|
233
233
|
sourcePosixPaths = sourceDirs.map(function(sourceDir) {
|
|
234
234
|
return sourceDir.split(path.sep).join(path.posix.sep);
|
|
235
235
|
});
|
|
@@ -102,7 +102,7 @@ var createAliasMatcher = function(baseUrl, alias) {
|
|
|
102
102
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
103
103
|
try {
|
|
104
104
|
for(var _iterator = aliasPairs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
105
|
-
var
|
|
105
|
+
var _step_value = _slicedToArray(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
106
106
|
if (_instanceof(key, RegExp)) {
|
|
107
107
|
if (key.test(requestedModule)) {
|
|
108
108
|
cacheMap.set(requestedModule, value);
|
|
@@ -173,8 +173,8 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
173
173
|
}
|
|
174
174
|
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
175
175
|
try {
|
|
176
|
-
var
|
|
177
|
-
var importPathWithQuotes1 = node === null || node === void 0 ? void 0 : (
|
|
176
|
+
var _node_moduleSpecifier;
|
|
177
|
+
var importPathWithQuotes1 = node === null || node === void 0 ? void 0 : (_node_moduleSpecifier = node.moduleSpecifier) === null || _node_moduleSpecifier === void 0 ? void 0 : _node_moduleSpecifier.getText();
|
|
178
178
|
if (!importPathWithQuotes1) {
|
|
179
179
|
return node;
|
|
180
180
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -1,23 +1,3 @@
|
|
|
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
1
|
import * as path from "path";
|
|
22
2
|
import { fs } from "@modern-js/utils";
|
|
23
3
|
import { compileByTs } from "../compilers/typescript";
|
|
@@ -33,7 +13,7 @@ const validateAbsolutePaths = (filenames, messageFunc) => {
|
|
|
33
13
|
(filename) => validateAbsolutePath(filename, messageFunc(filename))
|
|
34
14
|
);
|
|
35
15
|
};
|
|
36
|
-
const compile = (appDirectory, modernConfig, compileOptions) =>
|
|
16
|
+
const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
37
17
|
var _a;
|
|
38
18
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
39
19
|
validateAbsolutePaths(
|
|
@@ -42,13 +22,13 @@ const compile = (appDirectory, modernConfig, compileOptions) => __async(void 0,
|
|
|
42
22
|
);
|
|
43
23
|
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
44
24
|
const compiler = (_a = modernConfig == null ? void 0 : modernConfig.server) == null ? void 0 : _a.compiler;
|
|
45
|
-
const isTsProject = tsconfigPath &&
|
|
25
|
+
const isTsProject = tsconfigPath && await fs.pathExists(tsconfigPath);
|
|
46
26
|
if (!isTsProject || compiler === "babel") {
|
|
47
|
-
|
|
27
|
+
await compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
48
28
|
} else {
|
|
49
|
-
|
|
29
|
+
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
50
30
|
}
|
|
51
|
-
}
|
|
31
|
+
};
|
|
52
32
|
export {
|
|
53
33
|
FILE_EXTENSIONS,
|
|
54
34
|
compile
|
|
@@ -1,42 +1,3 @@
|
|
|
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
1
|
import * as path from "path";
|
|
41
2
|
import {
|
|
42
3
|
getBabelChain,
|
|
@@ -59,9 +20,10 @@ const existTsConfigFile = (tsconfigAbsolutePath) => {
|
|
|
59
20
|
};
|
|
60
21
|
const getBabelConfig = (libPresetOption, syntaxOption) => {
|
|
61
22
|
const chain = getBabelChain(libPresetOption, syntaxOption);
|
|
62
|
-
return
|
|
63
|
-
sourceType: "unambiguous"
|
|
64
|
-
|
|
23
|
+
return {
|
|
24
|
+
sourceType: "unambiguous",
|
|
25
|
+
...chain.toJSON()
|
|
26
|
+
};
|
|
65
27
|
};
|
|
66
28
|
const resolveBabelConfig = (appDirectory, config, option) => {
|
|
67
29
|
const { globalVars, alias, babelConfig, define } = config;
|
|
@@ -69,9 +31,10 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
69
31
|
object[key] = JSON.stringify(value);
|
|
70
32
|
return object;
|
|
71
33
|
}, {});
|
|
72
|
-
const aliasConfig = getAliasConfig(alias,
|
|
73
|
-
appDirectory
|
|
74
|
-
|
|
34
|
+
const aliasConfig = getAliasConfig(alias, {
|
|
35
|
+
appDirectory,
|
|
36
|
+
...option
|
|
37
|
+
});
|
|
75
38
|
const babelChain = getBabelChain(
|
|
76
39
|
{
|
|
77
40
|
appDirectory,
|
|
@@ -79,7 +42,10 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
79
42
|
enableTypescriptPreset: true,
|
|
80
43
|
alias: aliasConfig,
|
|
81
44
|
envVars: [],
|
|
82
|
-
globalVars:
|
|
45
|
+
globalVars: {
|
|
46
|
+
...globalVars,
|
|
47
|
+
...globalDefineVars
|
|
48
|
+
}
|
|
83
49
|
},
|
|
84
50
|
{
|
|
85
51
|
type: option.type,
|
|
@@ -88,9 +54,10 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
88
54
|
);
|
|
89
55
|
const envOptions = babelChain.preset("@babel/preset-env").options();
|
|
90
56
|
babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
|
|
91
|
-
|
|
57
|
+
{
|
|
58
|
+
...envOptions[0],
|
|
92
59
|
loose: true
|
|
93
|
-
}
|
|
60
|
+
}
|
|
94
61
|
]);
|
|
95
62
|
babelChain.plugin("babel-plugin-transform-typescript-metadata").use(
|
|
96
63
|
require.resolve("babel-plugin-transform-typescript-metadata"),
|
|
@@ -104,22 +71,22 @@ const resolveBabelConfig = (appDirectory, config, option) => {
|
|
|
104
71
|
loose: true
|
|
105
72
|
}
|
|
106
73
|
]);
|
|
107
|
-
const internalBabelConfig =
|
|
74
|
+
const internalBabelConfig = { ...babelChain.toJSON() };
|
|
108
75
|
return applyUserBabelConfig(internalBabelConfig, babelConfig);
|
|
109
76
|
};
|
|
110
|
-
const compileByBabel = (appDirectory, config, compileOptions) =>
|
|
77
|
+
const compileByBabel = async (appDirectory, config, compileOptions) => {
|
|
111
78
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
112
|
-
const results =
|
|
113
|
-
sourceDirs.map((sourceDir) =>
|
|
79
|
+
const results = await Promise.all(
|
|
80
|
+
sourceDirs.map(async (sourceDir) => {
|
|
114
81
|
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
115
82
|
tsconfigPath: tsconfigPath ? tsconfigPath : "",
|
|
116
83
|
syntax: "es6+",
|
|
117
84
|
type: "commonjs"
|
|
118
85
|
});
|
|
119
|
-
if (
|
|
86
|
+
if (await fs.pathExists(sourceDir)) {
|
|
120
87
|
const basename = path.basename(sourceDir);
|
|
121
88
|
const targetDir = path.join(distDir, basename);
|
|
122
|
-
|
|
89
|
+
await fs.copy(sourceDir, targetDir, {
|
|
123
90
|
filter: (src) => ![".ts", ".js"].includes(path.extname(src)) && src !== tsconfigPath
|
|
124
91
|
});
|
|
125
92
|
}
|
|
@@ -132,14 +99,14 @@ const compileByBabel = (appDirectory, config, compileOptions) => __async(void 0,
|
|
|
132
99
|
},
|
|
133
100
|
babelConfig
|
|
134
101
|
);
|
|
135
|
-
})
|
|
102
|
+
})
|
|
136
103
|
);
|
|
137
104
|
results.forEach((result) => {
|
|
138
105
|
if (result.code === 1) {
|
|
139
106
|
throw new Error(result.message);
|
|
140
107
|
}
|
|
141
108
|
});
|
|
142
|
-
}
|
|
109
|
+
};
|
|
143
110
|
export {
|
|
144
111
|
compileByBabel,
|
|
145
112
|
existTsConfigFile,
|
|
@@ -1,39 +1,3 @@
|
|
|
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
1
|
import path from "path";
|
|
38
2
|
import { logger, getAliasConfig, fs } from "@modern-js/utils";
|
|
39
3
|
import ts from "typescript";
|
|
@@ -48,16 +12,16 @@ const readTsConfigByFile = (tsConfigFile) => {
|
|
|
48
12
|
const { options, fileNames, projectReferences } = parsedCmd;
|
|
49
13
|
return { options, fileNames, projectReferences };
|
|
50
14
|
};
|
|
51
|
-
const copyFiles = (from, to, tsconfigPath) =>
|
|
52
|
-
if (
|
|
15
|
+
const copyFiles = async (from, to, tsconfigPath) => {
|
|
16
|
+
if (await fs.pathExists(from)) {
|
|
53
17
|
const basename = path.basename(from);
|
|
54
18
|
const targetDir = path.join(to, basename);
|
|
55
|
-
|
|
19
|
+
await fs.copy(from, targetDir, {
|
|
56
20
|
filter: (src) => ![".ts"].includes(path.extname(src)) && src !== tsconfigPath
|
|
57
21
|
});
|
|
58
22
|
}
|
|
59
|
-
}
|
|
60
|
-
const compileByTs = (appDirectory, config, compileOptions) =>
|
|
23
|
+
};
|
|
24
|
+
const compileByTs = async (appDirectory, config, compileOptions) => {
|
|
61
25
|
logger.info(`Running ts compile...`);
|
|
62
26
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
63
27
|
if (!tsconfigPath) {
|
|
@@ -86,10 +50,11 @@ const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, nu
|
|
|
86
50
|
const program = createProgram.call(ts2, {
|
|
87
51
|
rootNames,
|
|
88
52
|
projectReferences,
|
|
89
|
-
options:
|
|
53
|
+
options: {
|
|
90
54
|
rootDir: appDirectory,
|
|
91
|
-
outDir: distDir
|
|
92
|
-
|
|
55
|
+
outDir: distDir,
|
|
56
|
+
...options
|
|
57
|
+
}
|
|
93
58
|
});
|
|
94
59
|
const tsconfigPathsPlugin = tsconfigPathsBeforeHookFactory(
|
|
95
60
|
ts2,
|
|
@@ -107,10 +72,10 @@ const compileByTs = (appDirectory, config, compileOptions) => __async(void 0, nu
|
|
|
107
72
|
process.exit(1);
|
|
108
73
|
}
|
|
109
74
|
for (const source of sourceDirs) {
|
|
110
|
-
|
|
75
|
+
await copyFiles(source, distDir, tsconfigPath);
|
|
111
76
|
}
|
|
112
77
|
logger.info(`Ts compile succeed`);
|
|
113
|
-
}
|
|
78
|
+
};
|
|
114
79
|
const getFormatHost = (ts2) => {
|
|
115
80
|
return {
|
|
116
81
|
getCanonicalFileName: (path2) => path2,
|
|
@@ -134,7 +134,7 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
134
134
|
}
|
|
135
135
|
newNode.flags = node.flags;
|
|
136
136
|
return newNode;
|
|
137
|
-
} catch
|
|
137
|
+
} catch {
|
|
138
138
|
return node;
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -166,7 +166,7 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
166
166
|
if (packagePath) {
|
|
167
167
|
return result;
|
|
168
168
|
}
|
|
169
|
-
} catch
|
|
169
|
+
} catch {
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
try {
|
|
@@ -176,7 +176,7 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
176
176
|
if (packagePath) {
|
|
177
177
|
return text;
|
|
178
178
|
}
|
|
179
|
-
} catch
|
|
179
|
+
} catch {
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
const resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -11,20 +11,19 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.5.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
|
-
"main": "./dist/
|
|
18
|
-
"module": "./dist/
|
|
19
|
-
"jsnext:modern": "./dist/js/modern/index.js",
|
|
17
|
+
"main": "./dist/cjs/index.js",
|
|
18
|
+
"module": "./dist/esm/index.js",
|
|
20
19
|
"exports": {
|
|
21
20
|
".": {
|
|
22
21
|
"node": {
|
|
23
22
|
"jsnext:source": "./src/index.ts",
|
|
24
|
-
"import": "./dist/
|
|
25
|
-
"require": "./dist/
|
|
23
|
+
"import": "./dist/esm-node/index.js",
|
|
24
|
+
"require": "./dist/cjs/index.js"
|
|
26
25
|
},
|
|
27
|
-
"default": "./dist/
|
|
26
|
+
"default": "./dist/esm/index.js"
|
|
28
27
|
}
|
|
29
28
|
},
|
|
30
29
|
"dependencies": {
|
|
@@ -36,9 +35,9 @@
|
|
|
36
35
|
"@babel/runtime": "^7.18.0",
|
|
37
36
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
38
37
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
39
|
-
"@modern-js/babel-compiler": "2.
|
|
40
|
-
"@modern-js/babel-preset-lib": "2.
|
|
41
|
-
"@modern-js/utils": "2.
|
|
38
|
+
"@modern-js/babel-compiler": "2.5.0",
|
|
39
|
+
"@modern-js/babel-preset-lib": "2.5.0",
|
|
40
|
+
"@modern-js/utils": "2.5.0"
|
|
42
41
|
},
|
|
43
42
|
"devDependencies": {
|
|
44
43
|
"@types/babel__core": "^7.1.15",
|
|
@@ -47,9 +46,9 @@
|
|
|
47
46
|
"jest": "^27",
|
|
48
47
|
"ts-jest": "^27.0.4",
|
|
49
48
|
"typescript": "^4",
|
|
50
|
-
"@modern-js/server-core": "2.
|
|
51
|
-
"@scripts/build": "2.
|
|
52
|
-
"@scripts/jest-config": "2.
|
|
49
|
+
"@modern-js/server-core": "2.5.0",
|
|
50
|
+
"@scripts/build": "2.5.0",
|
|
51
|
+
"@scripts/jest-config": "2.5.0"
|
|
53
52
|
},
|
|
54
53
|
"sideEffects": false,
|
|
55
54
|
"publishConfig": {
|