@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 +102 -0
- package/dist/js/modern/common/index.js +42 -17
- package/dist/js/modern/compilers/babel/index.js +128 -82
- 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 +68 -28
- package/dist/js/node/compilers/babel/index.js +151 -113
- package/dist/js/node/compilers/typescript/index.js +118 -75
- package/dist/js/node/compilers/typescript/tsconfig-paths-plugin.js +102 -55
- package/dist/js/node/compilers/typescript/typescript-loader.js +26 -14
- package/dist/js/node/index.js +22 -24
- package/dist/js/treeshaking/common/index.js +199 -60
- package/dist/js/treeshaking/compilers/babel/index.js +362 -136
- 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
|
@@ -1,156 +1,339 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
+
try {
|
|
3
|
+
var info = gen[key](arg);
|
|
4
|
+
var value = info.value;
|
|
5
|
+
} catch (error) {
|
|
6
|
+
reject(error);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
if (info.done) {
|
|
10
|
+
resolve(value);
|
|
11
|
+
} else {
|
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function _asyncToGenerator(fn) {
|
|
16
|
+
return function() {
|
|
17
|
+
var self = this, args = arguments;
|
|
18
|
+
return new Promise(function(resolve, reject) {
|
|
19
|
+
var gen = fn.apply(self, args);
|
|
20
|
+
function _next(value) {
|
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
+
}
|
|
23
|
+
function _throw(err) {
|
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
+
}
|
|
26
|
+
_next(undefined);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function _defineProperty(obj, key, value) {
|
|
31
|
+
if (key in obj) {
|
|
32
|
+
Object.defineProperty(obj, key, {
|
|
33
|
+
value: value,
|
|
34
|
+
enumerable: true,
|
|
35
|
+
configurable: true,
|
|
36
|
+
writable: true
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
return obj;
|
|
42
|
+
}
|
|
43
|
+
function _objectSpread(target) {
|
|
44
|
+
for(var i = 1; i < arguments.length; i++){
|
|
45
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
46
|
+
var ownKeys = Object.keys(source);
|
|
47
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
48
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
ownKeys.forEach(function(key) {
|
|
53
|
+
_defineProperty(target, key, source[key]);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
59
|
+
var f, y, t, g, _ = {
|
|
60
|
+
label: 0,
|
|
61
|
+
sent: function() {
|
|
62
|
+
if (t[0] & 1) throw t[1];
|
|
63
|
+
return t[1];
|
|
64
|
+
},
|
|
65
|
+
trys: [],
|
|
66
|
+
ops: []
|
|
67
|
+
};
|
|
68
|
+
return(g = {
|
|
69
|
+
next: verb(0),
|
|
70
|
+
"throw": verb(1),
|
|
71
|
+
"return": verb(2)
|
|
72
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
73
|
+
return this;
|
|
74
|
+
}), g);
|
|
75
|
+
function verb(n) {
|
|
76
|
+
return function(v) {
|
|
77
|
+
return step([
|
|
78
|
+
n,
|
|
79
|
+
v
|
|
80
|
+
]);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function step(op) {
|
|
84
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
85
|
+
while(_)try {
|
|
86
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
87
|
+
if (y = 0, t) op = [
|
|
88
|
+
op[0] & 2,
|
|
89
|
+
t.value
|
|
90
|
+
];
|
|
91
|
+
switch(op[0]){
|
|
92
|
+
case 0:
|
|
93
|
+
case 1:
|
|
94
|
+
t = op;
|
|
95
|
+
break;
|
|
96
|
+
case 4:
|
|
97
|
+
_.label++;
|
|
98
|
+
return {
|
|
99
|
+
value: op[1],
|
|
100
|
+
done: false
|
|
101
|
+
};
|
|
102
|
+
case 5:
|
|
103
|
+
_.label++;
|
|
104
|
+
y = op[1];
|
|
105
|
+
op = [
|
|
106
|
+
0
|
|
107
|
+
];
|
|
108
|
+
continue;
|
|
109
|
+
case 7:
|
|
110
|
+
op = _.ops.pop();
|
|
111
|
+
_.trys.pop();
|
|
112
|
+
continue;
|
|
113
|
+
default:
|
|
114
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
115
|
+
_ = 0;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
119
|
+
_.label = op[1];
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
123
|
+
_.label = t[1];
|
|
124
|
+
t = op;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
if (t && _.label < t[2]) {
|
|
128
|
+
_.label = t[2];
|
|
129
|
+
_.ops.push(op);
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
if (t[2]) _.ops.pop();
|
|
133
|
+
_.trys.pop();
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
op = body.call(thisArg, _);
|
|
137
|
+
} catch (e) {
|
|
138
|
+
op = [
|
|
139
|
+
6,
|
|
140
|
+
e
|
|
141
|
+
];
|
|
142
|
+
y = 0;
|
|
143
|
+
} finally{
|
|
144
|
+
f = t = 0;
|
|
145
|
+
}
|
|
146
|
+
if (op[0] & 5) throw op[1];
|
|
147
|
+
return {
|
|
148
|
+
value: op[0] ? op[1] : void 0,
|
|
149
|
+
done: true
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
import path from "path";
|
|
154
|
+
import { logger, getAliasConfig, fs } from "@modern-js/utils";
|
|
155
|
+
import ts from "typescript";
|
|
8
156
|
import { TypescriptLoader } from "./typescript-loader";
|
|
9
157
|
import { tsconfigPathsBeforeHookFactory } from "./tsconfig-paths-plugin";
|
|
10
|
-
var readTsConfigByFile = function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
fileNames: fileNames,
|
|
19
|
-
projectReferences: projectReferences
|
|
20
|
-
};
|
|
158
|
+
var readTsConfigByFile = function(tsConfigFile) {
|
|
159
|
+
var parsedCmd = ts.getParsedCommandLineOfConfigFile(tsConfigFile, void 0, ts.sys);
|
|
160
|
+
var options = parsedCmd.options, fileNames = parsedCmd.fileNames, projectReferences = parsedCmd.projectReferences;
|
|
161
|
+
return {
|
|
162
|
+
options: options,
|
|
163
|
+
fileNames: fileNames,
|
|
164
|
+
projectReferences: projectReferences
|
|
165
|
+
};
|
|
21
166
|
};
|
|
22
|
-
var copyFiles =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
167
|
+
var copyFiles = function() {
|
|
168
|
+
var _ref = _asyncToGenerator(function(from, to, tsconfigPath) {
|
|
169
|
+
var basename, targetDir;
|
|
170
|
+
return __generator(this, function(_state) {
|
|
171
|
+
switch(_state.label){
|
|
172
|
+
case 0:
|
|
173
|
+
return [
|
|
174
|
+
4,
|
|
175
|
+
fs.pathExists(from)
|
|
176
|
+
];
|
|
177
|
+
case 1:
|
|
178
|
+
if (!_state.sent()) return [
|
|
179
|
+
3,
|
|
180
|
+
3
|
|
181
|
+
];
|
|
182
|
+
basename = path.basename(from);
|
|
183
|
+
targetDir = path.join(to, basename);
|
|
184
|
+
return [
|
|
185
|
+
4,
|
|
186
|
+
fs.copy(from, targetDir, {
|
|
187
|
+
filter: function(src) {
|
|
188
|
+
return ![
|
|
189
|
+
".ts"
|
|
190
|
+
].includes(path.extname(src)) && src !== tsconfigPath;
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
];
|
|
194
|
+
case 2:
|
|
195
|
+
_state.sent();
|
|
196
|
+
_state.label = 3;
|
|
197
|
+
case 3:
|
|
198
|
+
return [
|
|
199
|
+
2
|
|
200
|
+
];
|
|
35
201
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return !['.ts'].includes(path.extname(src)) && src !== tsconfigPath;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
case 7:
|
|
45
|
-
case "end":
|
|
46
|
-
return _context.stop();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}, _callee);
|
|
50
|
-
}));
|
|
51
|
-
return function copyFiles(_x, _x2, _x3) {
|
|
52
|
-
return _ref2.apply(this, arguments);
|
|
53
|
-
};
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
return function copyFiles(from, to, tsconfigPath) {
|
|
205
|
+
return _ref.apply(this, arguments);
|
|
206
|
+
};
|
|
54
207
|
}();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
208
|
+
var compileByTs = function() {
|
|
209
|
+
var _ref = _asyncToGenerator(function(appDirectory, config, compileOptions) {
|
|
210
|
+
var sourceDirs, distDir, tsconfigPath, ts2, createProgram, formatHost, alias, aliasOption, _paths, paths, _absoluteBaseUrl, absoluteBaseUrl, ref, options, fileNames, projectReferences, sourcePosixPaths, rootNames, program, tsconfigPathsPlugin, emitResult, allDiagnostics, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, source, err;
|
|
211
|
+
return __generator(this, function(_state) {
|
|
212
|
+
switch(_state.label){
|
|
213
|
+
case 0:
|
|
214
|
+
logger.info("Running ts compile...");
|
|
215
|
+
sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath;
|
|
216
|
+
if (!tsconfigPath) {
|
|
217
|
+
return [
|
|
218
|
+
2
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
ts2 = new TypescriptLoader({
|
|
222
|
+
appDirectory: appDirectory
|
|
223
|
+
}).load();
|
|
224
|
+
createProgram = ts2.createIncrementalProgram || ts2.createProgram;
|
|
225
|
+
formatHost = getFormatHost(ts2);
|
|
226
|
+
alias = config.alias;
|
|
227
|
+
aliasOption = getAliasConfig(alias, {
|
|
228
|
+
appDirectory: appDirectory,
|
|
229
|
+
tsconfigPath: tsconfigPath
|
|
230
|
+
});
|
|
231
|
+
_paths = aliasOption.paths, paths = _paths === void 0 ? {} : _paths, _absoluteBaseUrl = aliasOption.absoluteBaseUrl, absoluteBaseUrl = _absoluteBaseUrl === void 0 ? "./" : _absoluteBaseUrl;
|
|
232
|
+
ref = readTsConfigByFile(tsconfigPath), options = ref.options, fileNames = ref.fileNames, projectReferences = ref.projectReferences;
|
|
233
|
+
sourcePosixPaths = sourceDirs.map(function(sourceDir) {
|
|
234
|
+
return sourceDir.split(path.sep).join(path.posix.sep);
|
|
235
|
+
});
|
|
236
|
+
rootNames = fileNames.filter(function(fileName) {
|
|
237
|
+
return fileName.endsWith(".d.ts") || sourcePosixPaths.some(function(sourceDir) {
|
|
238
|
+
return fileName.includes(sourceDir);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
program = createProgram.call(ts2, {
|
|
242
|
+
rootNames: rootNames,
|
|
243
|
+
projectReferences: projectReferences,
|
|
244
|
+
options: _objectSpread({
|
|
245
|
+
rootDir: appDirectory,
|
|
246
|
+
outDir: distDir
|
|
247
|
+
}, options)
|
|
248
|
+
});
|
|
249
|
+
tsconfigPathsPlugin = tsconfigPathsBeforeHookFactory(ts2, absoluteBaseUrl, paths);
|
|
250
|
+
emitResult = program.emit(void 0, void 0, void 0, void 0, {
|
|
251
|
+
before: [
|
|
252
|
+
tsconfigPathsPlugin
|
|
253
|
+
]
|
|
254
|
+
});
|
|
255
|
+
allDiagnostics = ts2.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
256
|
+
if (allDiagnostics.length > 0) {
|
|
257
|
+
logger.error(ts2.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost));
|
|
258
|
+
process.exit(1);
|
|
259
|
+
}
|
|
260
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
261
|
+
_state.label = 1;
|
|
262
|
+
case 1:
|
|
263
|
+
_state.trys.push([
|
|
264
|
+
1,
|
|
265
|
+
6,
|
|
266
|
+
7,
|
|
267
|
+
8
|
|
268
|
+
]);
|
|
269
|
+
_iterator = sourceDirs[Symbol.iterator]();
|
|
270
|
+
_state.label = 2;
|
|
271
|
+
case 2:
|
|
272
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
273
|
+
3,
|
|
274
|
+
5
|
|
275
|
+
];
|
|
276
|
+
source = _step.value;
|
|
277
|
+
return [
|
|
278
|
+
4,
|
|
279
|
+
copyFiles(source, distDir, tsconfigPath)
|
|
280
|
+
];
|
|
281
|
+
case 3:
|
|
282
|
+
_state.sent();
|
|
283
|
+
_state.label = 4;
|
|
284
|
+
case 4:
|
|
285
|
+
_iteratorNormalCompletion = true;
|
|
286
|
+
return [
|
|
287
|
+
3,
|
|
288
|
+
2
|
|
289
|
+
];
|
|
290
|
+
case 5:
|
|
291
|
+
return [
|
|
292
|
+
3,
|
|
293
|
+
8
|
|
294
|
+
];
|
|
295
|
+
case 6:
|
|
296
|
+
err = _state.sent();
|
|
297
|
+
_didIteratorError = true;
|
|
298
|
+
_iteratorError = err;
|
|
299
|
+
return [
|
|
300
|
+
3,
|
|
301
|
+
8
|
|
302
|
+
];
|
|
303
|
+
case 7:
|
|
304
|
+
try {
|
|
305
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
306
|
+
_iterator.return();
|
|
307
|
+
}
|
|
308
|
+
} finally{
|
|
309
|
+
if (_didIteratorError) {
|
|
310
|
+
throw _iteratorError;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return [
|
|
314
|
+
7
|
|
315
|
+
];
|
|
316
|
+
case 8:
|
|
317
|
+
logger.info("Ts compile succeed");
|
|
318
|
+
return [
|
|
319
|
+
2
|
|
320
|
+
];
|
|
115
321
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
break;
|
|
122
|
-
case 27:
|
|
123
|
-
_context2.next = 32;
|
|
124
|
-
break;
|
|
125
|
-
case 29:
|
|
126
|
-
_context2.prev = 29;
|
|
127
|
-
_context2.t0 = _context2["catch"](19);
|
|
128
|
-
_iterator.e(_context2.t0);
|
|
129
|
-
case 32:
|
|
130
|
-
_context2.prev = 32;
|
|
131
|
-
_iterator.f();
|
|
132
|
-
return _context2.finish(32);
|
|
133
|
-
case 35:
|
|
134
|
-
logger.info("Ts compile succeed");
|
|
135
|
-
case 36:
|
|
136
|
-
case "end":
|
|
137
|
-
return _context2.stop();
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}, _callee2, null, [[19, 29, 32, 35]]);
|
|
141
|
-
}));
|
|
142
|
-
return function compileByTs(_x4, _x5, _x6) {
|
|
143
|
-
return _ref3.apply(this, arguments);
|
|
144
|
-
};
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
return function compileByTs(appDirectory, config, compileOptions) {
|
|
325
|
+
return _ref.apply(this, arguments);
|
|
326
|
+
};
|
|
145
327
|
}();
|
|
146
|
-
var getFormatHost = function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
328
|
+
var getFormatHost = function(ts2) {
|
|
329
|
+
return {
|
|
330
|
+
getCanonicalFileName: function(path2) {
|
|
331
|
+
return path2;
|
|
332
|
+
},
|
|
333
|
+
getCurrentDirectory: ts2.sys.getCurrentDirectory,
|
|
334
|
+
getNewLine: function() {
|
|
335
|
+
return ts2.sys.newLine;
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
export { compileByTs };
|