@modern-js/server-utils 2.5.1-alpha.0 → 2.7.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 +33 -0
- package/dist/cjs/common/index.js +4 -0
- package/dist/cjs/compilers/babel/index.js +4 -0
- package/dist/cjs/compilers/typescript/index.js +8 -4
- package/dist/cjs/compilers/typescript/{tsconfig-paths-plugin.js → tsconfigPathsPlugin.js} +7 -3
- package/dist/cjs/compilers/typescript/{typescript-loader.js → typescriptLoader.js} +3 -3
- package/dist/esm/compilers/typescript/index.js +2 -2
- package/dist/esm-node/compilers/typescript/index.js +2 -2
- package/package.json +9 -9
- package/dist/js/modern/common/index.js +0 -55
- package/dist/js/modern/compilers/babel/index.js +0 -149
- package/dist/js/modern/compilers/typescript/index.js +0 -123
- package/dist/js/modern/compilers/typescript/tsconfig-paths-plugin.js +0 -187
- package/dist/js/modern/compilers/typescript/typescript-loader.js +0 -24
- package/dist/js/modern/index.js +0 -5
- package/dist/js/node/common/index.js +0 -85
- package/dist/js/node/compilers/babel/index.js +0 -178
- package/dist/js/node/compilers/typescript/index.js +0 -150
- package/dist/js/node/compilers/typescript/tsconfig-paths-plugin.js +0 -216
- package/dist/js/node/compilers/typescript/typescript-loader.js +0 -47
- package/dist/js/node/index.js +0 -29
- package/dist/js/treeshaking/common/index.js +0 -204
- package/dist/js/treeshaking/compilers/babel/index.js +0 -368
- package/dist/js/treeshaking/compilers/typescript/index.js +0 -339
- package/dist/js/treeshaking/compilers/typescript/tsconfig-paths-plugin.js +0 -246
- package/dist/js/treeshaking/compilers/typescript/typescript-loader.js +0 -65
- package/dist/js/treeshaking/index.js +0 -3
- /package/dist/esm/compilers/typescript/{tsconfig-paths-plugin.js → tsconfigPathsPlugin.js} +0 -0
- /package/dist/esm/compilers/typescript/{typescript-loader.js → typescriptLoader.js} +0 -0
- /package/dist/esm-node/compilers/typescript/{tsconfig-paths-plugin.js → tsconfigPathsPlugin.js} +0 -0
- /package/dist/esm-node/compilers/typescript/{typescript-loader.js → typescriptLoader.js} +0 -0
- /package/dist/types/compilers/typescript/{tsconfig-paths-plugin.d.ts → tsconfigPathsPlugin.d.ts} +0 -0
- /package/dist/types/compilers/typescript/{typescript-loader.d.ts → typescriptLoader.d.ts} +0 -0
|
@@ -1,368 +0,0 @@
|
|
|
1
|
-
function _arrayLikeToArray(arr, len) {
|
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
-
return arr2;
|
|
5
|
-
}
|
|
6
|
-
function _arrayWithHoles(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return arr;
|
|
8
|
-
}
|
|
9
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
10
|
-
try {
|
|
11
|
-
var info = gen[key](arg);
|
|
12
|
-
var value = info.value;
|
|
13
|
-
} catch (error) {
|
|
14
|
-
reject(error);
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if (info.done) {
|
|
18
|
-
resolve(value);
|
|
19
|
-
} else {
|
|
20
|
-
Promise.resolve(value).then(_next, _throw);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function _asyncToGenerator(fn) {
|
|
24
|
-
return function() {
|
|
25
|
-
var self = this, args = arguments;
|
|
26
|
-
return new Promise(function(resolve, reject) {
|
|
27
|
-
var gen = fn.apply(self, args);
|
|
28
|
-
function _next(value) {
|
|
29
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
30
|
-
}
|
|
31
|
-
function _throw(err) {
|
|
32
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
33
|
-
}
|
|
34
|
-
_next(undefined);
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function _defineProperty(obj, key, value) {
|
|
39
|
-
if (key in obj) {
|
|
40
|
-
Object.defineProperty(obj, key, {
|
|
41
|
-
value: value,
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
writable: true
|
|
45
|
-
});
|
|
46
|
-
} else {
|
|
47
|
-
obj[key] = value;
|
|
48
|
-
}
|
|
49
|
-
return obj;
|
|
50
|
-
}
|
|
51
|
-
function _iterableToArrayLimit(arr, i) {
|
|
52
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
53
|
-
if (_i == null) return;
|
|
54
|
-
var _arr = [];
|
|
55
|
-
var _n = true;
|
|
56
|
-
var _d = false;
|
|
57
|
-
var _s, _e;
|
|
58
|
-
try {
|
|
59
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
60
|
-
_arr.push(_s.value);
|
|
61
|
-
if (i && _arr.length === i) break;
|
|
62
|
-
}
|
|
63
|
-
} catch (err) {
|
|
64
|
-
_d = true;
|
|
65
|
-
_e = err;
|
|
66
|
-
} finally{
|
|
67
|
-
try {
|
|
68
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
69
|
-
} finally{
|
|
70
|
-
if (_d) throw _e;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return _arr;
|
|
74
|
-
}
|
|
75
|
-
function _nonIterableRest() {
|
|
76
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
77
|
-
}
|
|
78
|
-
function _objectSpread(target) {
|
|
79
|
-
for(var i = 1; i < arguments.length; i++){
|
|
80
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
81
|
-
var ownKeys = Object.keys(source);
|
|
82
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
83
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
84
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
85
|
-
}));
|
|
86
|
-
}
|
|
87
|
-
ownKeys.forEach(function(key) {
|
|
88
|
-
_defineProperty(target, key, source[key]);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
return target;
|
|
92
|
-
}
|
|
93
|
-
function ownKeys(object, enumerableOnly) {
|
|
94
|
-
var keys = Object.keys(object);
|
|
95
|
-
if (Object.getOwnPropertySymbols) {
|
|
96
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
97
|
-
if (enumerableOnly) {
|
|
98
|
-
symbols = symbols.filter(function(sym) {
|
|
99
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
keys.push.apply(keys, symbols);
|
|
103
|
-
}
|
|
104
|
-
return keys;
|
|
105
|
-
}
|
|
106
|
-
function _objectSpreadProps(target, source) {
|
|
107
|
-
source = source != null ? source : {};
|
|
108
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
109
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
110
|
-
} else {
|
|
111
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
112
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
return target;
|
|
116
|
-
}
|
|
117
|
-
function _slicedToArray(arr, i) {
|
|
118
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
119
|
-
}
|
|
120
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
121
|
-
if (!o) return;
|
|
122
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
123
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
124
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
125
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
126
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
127
|
-
}
|
|
128
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
|
129
|
-
var f, y, t, g, _ = {
|
|
130
|
-
label: 0,
|
|
131
|
-
sent: function() {
|
|
132
|
-
if (t[0] & 1) throw t[1];
|
|
133
|
-
return t[1];
|
|
134
|
-
},
|
|
135
|
-
trys: [],
|
|
136
|
-
ops: []
|
|
137
|
-
};
|
|
138
|
-
return(g = {
|
|
139
|
-
next: verb(0),
|
|
140
|
-
"throw": verb(1),
|
|
141
|
-
"return": verb(2)
|
|
142
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
143
|
-
return this;
|
|
144
|
-
}), g);
|
|
145
|
-
function verb(n) {
|
|
146
|
-
return function(v) {
|
|
147
|
-
return step([
|
|
148
|
-
n,
|
|
149
|
-
v
|
|
150
|
-
]);
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
function step(op) {
|
|
154
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
155
|
-
while(_)try {
|
|
156
|
-
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;
|
|
157
|
-
if (y = 0, t) op = [
|
|
158
|
-
op[0] & 2,
|
|
159
|
-
t.value
|
|
160
|
-
];
|
|
161
|
-
switch(op[0]){
|
|
162
|
-
case 0:
|
|
163
|
-
case 1:
|
|
164
|
-
t = op;
|
|
165
|
-
break;
|
|
166
|
-
case 4:
|
|
167
|
-
_.label++;
|
|
168
|
-
return {
|
|
169
|
-
value: op[1],
|
|
170
|
-
done: false
|
|
171
|
-
};
|
|
172
|
-
case 5:
|
|
173
|
-
_.label++;
|
|
174
|
-
y = op[1];
|
|
175
|
-
op = [
|
|
176
|
-
0
|
|
177
|
-
];
|
|
178
|
-
continue;
|
|
179
|
-
case 7:
|
|
180
|
-
op = _.ops.pop();
|
|
181
|
-
_.trys.pop();
|
|
182
|
-
continue;
|
|
183
|
-
default:
|
|
184
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
185
|
-
_ = 0;
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
189
|
-
_.label = op[1];
|
|
190
|
-
break;
|
|
191
|
-
}
|
|
192
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
193
|
-
_.label = t[1];
|
|
194
|
-
t = op;
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
if (t && _.label < t[2]) {
|
|
198
|
-
_.label = t[2];
|
|
199
|
-
_.ops.push(op);
|
|
200
|
-
break;
|
|
201
|
-
}
|
|
202
|
-
if (t[2]) _.ops.pop();
|
|
203
|
-
_.trys.pop();
|
|
204
|
-
continue;
|
|
205
|
-
}
|
|
206
|
-
op = body.call(thisArg, _);
|
|
207
|
-
} catch (e) {
|
|
208
|
-
op = [
|
|
209
|
-
6,
|
|
210
|
-
e
|
|
211
|
-
];
|
|
212
|
-
y = 0;
|
|
213
|
-
} finally{
|
|
214
|
-
f = t = 0;
|
|
215
|
-
}
|
|
216
|
-
if (op[0] & 5) throw op[1];
|
|
217
|
-
return {
|
|
218
|
-
value: op[0] ? op[1] : void 0,
|
|
219
|
-
done: true
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
import * as path from "path";
|
|
224
|
-
import { getBabelChain, applyUserBabelConfig } from "@modern-js/babel-preset-lib";
|
|
225
|
-
import { fs, json5, getAliasConfig } from "@modern-js/utils";
|
|
226
|
-
import { compiler } from "@modern-js/babel-compiler";
|
|
227
|
-
import { FILE_EXTENSIONS } from "../../common";
|
|
228
|
-
export * from "@babel/core";
|
|
229
|
-
var readTsConfig = function(tsconfigPath) {
|
|
230
|
-
var noExistReturn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
|
|
231
|
-
if (!fs.existsSync(tsconfigPath)) {
|
|
232
|
-
return noExistReturn;
|
|
233
|
-
}
|
|
234
|
-
var content = fs.readFileSync(tsconfigPath, "utf-8");
|
|
235
|
-
return json5.parse(content);
|
|
236
|
-
};
|
|
237
|
-
var existTsConfigFile = function(tsconfigAbsolutePath) {
|
|
238
|
-
var tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
239
|
-
return Boolean(tsconfig);
|
|
240
|
-
};
|
|
241
|
-
var getBabelConfig = function(libPresetOption, syntaxOption) {
|
|
242
|
-
var chain = getBabelChain(libPresetOption, syntaxOption);
|
|
243
|
-
return _objectSpread({
|
|
244
|
-
sourceType: "unambiguous"
|
|
245
|
-
}, chain.toJSON());
|
|
246
|
-
};
|
|
247
|
-
var resolveBabelConfig = function(appDirectory, config, option) {
|
|
248
|
-
var globalVars = config.globalVars, alias = config.alias, babelConfig = config.babelConfig, define = config.define;
|
|
249
|
-
var globalDefineVars = define && Object.entries(define).reduce(function(object, param) {
|
|
250
|
-
var _param = _slicedToArray(param, 2), key = _param[0], value = _param[1];
|
|
251
|
-
object[key] = JSON.stringify(value);
|
|
252
|
-
return object;
|
|
253
|
-
}, {});
|
|
254
|
-
var aliasConfig = getAliasConfig(alias, _objectSpread({
|
|
255
|
-
appDirectory: appDirectory
|
|
256
|
-
}, option));
|
|
257
|
-
var babelChain = getBabelChain({
|
|
258
|
-
appDirectory: appDirectory,
|
|
259
|
-
enableReactPreset: true,
|
|
260
|
-
enableTypescriptPreset: true,
|
|
261
|
-
alias: aliasConfig,
|
|
262
|
-
envVars: [],
|
|
263
|
-
globalVars: _objectSpread({}, globalVars, globalDefineVars)
|
|
264
|
-
}, {
|
|
265
|
-
type: option.type,
|
|
266
|
-
syntax: option.syntax
|
|
267
|
-
});
|
|
268
|
-
var envOptions = babelChain.preset("@babel/preset-env").options();
|
|
269
|
-
babelChain.preset("@babel/preset-env").use(require.resolve("@babel/preset-env"), [
|
|
270
|
-
_objectSpreadProps(_objectSpread({}, envOptions[0]), {
|
|
271
|
-
loose: true
|
|
272
|
-
})
|
|
273
|
-
]);
|
|
274
|
-
babelChain.plugin("babel-plugin-transform-typescript-metadata").use(require.resolve("babel-plugin-transform-typescript-metadata"), []);
|
|
275
|
-
babelChain.plugin("@babel/plugin-proposal-decorators").use(require.resolve("@babel/plugin-proposal-decorators"), [
|
|
276
|
-
{
|
|
277
|
-
legacy: true
|
|
278
|
-
}
|
|
279
|
-
]);
|
|
280
|
-
babelChain.plugin("@babel/plugin-proposal-class-properties").use(require.resolve("@babel/plugin-proposal-class-properties"), [
|
|
281
|
-
{
|
|
282
|
-
loose: true
|
|
283
|
-
}
|
|
284
|
-
]);
|
|
285
|
-
var internalBabelConfig = _objectSpread({}, babelChain.toJSON());
|
|
286
|
-
return applyUserBabelConfig(internalBabelConfig, babelConfig);
|
|
287
|
-
};
|
|
288
|
-
var compileByBabel = function() {
|
|
289
|
-
var _ref = _asyncToGenerator(function(appDirectory, config, compileOptions) {
|
|
290
|
-
var sourceDirs, distDir, tsconfigPath, results;
|
|
291
|
-
return __generator(this, function(_state) {
|
|
292
|
-
switch(_state.label){
|
|
293
|
-
case 0:
|
|
294
|
-
sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath;
|
|
295
|
-
return [
|
|
296
|
-
4,
|
|
297
|
-
Promise.all(sourceDirs.map(function() {
|
|
298
|
-
var _ref = _asyncToGenerator(function(sourceDir) {
|
|
299
|
-
var babelConfig, basename, targetDir;
|
|
300
|
-
return __generator(this, function(_state) {
|
|
301
|
-
switch(_state.label){
|
|
302
|
-
case 0:
|
|
303
|
-
babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
304
|
-
tsconfigPath: tsconfigPath ? tsconfigPath : "",
|
|
305
|
-
syntax: "es6+",
|
|
306
|
-
type: "commonjs"
|
|
307
|
-
});
|
|
308
|
-
return [
|
|
309
|
-
4,
|
|
310
|
-
fs.pathExists(sourceDir)
|
|
311
|
-
];
|
|
312
|
-
case 1:
|
|
313
|
-
if (!_state.sent()) return [
|
|
314
|
-
3,
|
|
315
|
-
3
|
|
316
|
-
];
|
|
317
|
-
basename = path.basename(sourceDir);
|
|
318
|
-
targetDir = path.join(distDir, basename);
|
|
319
|
-
return [
|
|
320
|
-
4,
|
|
321
|
-
fs.copy(sourceDir, targetDir, {
|
|
322
|
-
filter: function(src) {
|
|
323
|
-
return ![
|
|
324
|
-
".ts",
|
|
325
|
-
".js"
|
|
326
|
-
].includes(path.extname(src)) && src !== tsconfigPath;
|
|
327
|
-
}
|
|
328
|
-
})
|
|
329
|
-
];
|
|
330
|
-
case 2:
|
|
331
|
-
_state.sent();
|
|
332
|
-
_state.label = 3;
|
|
333
|
-
case 3:
|
|
334
|
-
return [
|
|
335
|
-
2,
|
|
336
|
-
compiler({
|
|
337
|
-
rootDir: appDirectory,
|
|
338
|
-
distDir: distDir,
|
|
339
|
-
sourceDir: sourceDir,
|
|
340
|
-
extensions: FILE_EXTENSIONS
|
|
341
|
-
}, babelConfig)
|
|
342
|
-
];
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
});
|
|
346
|
-
return function(sourceDir) {
|
|
347
|
-
return _ref.apply(this, arguments);
|
|
348
|
-
};
|
|
349
|
-
}()))
|
|
350
|
-
];
|
|
351
|
-
case 1:
|
|
352
|
-
results = _state.sent();
|
|
353
|
-
results.forEach(function(result) {
|
|
354
|
-
if (result.code === 1) {
|
|
355
|
-
throw new Error(result.message);
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
return [
|
|
359
|
-
2
|
|
360
|
-
];
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
});
|
|
364
|
-
return function compileByBabel(appDirectory, config, compileOptions) {
|
|
365
|
-
return _ref.apply(this, arguments);
|
|
366
|
-
};
|
|
367
|
-
}();
|
|
368
|
-
export { compileByBabel, existTsConfigFile, getBabelConfig, readTsConfig, resolveBabelConfig };
|
|
@@ -1,339 +0,0 @@
|
|
|
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";
|
|
156
|
-
import { TypescriptLoader } from "./typescript-loader";
|
|
157
|
-
import { tsconfigPathsBeforeHookFactory } from "./tsconfig-paths-plugin";
|
|
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
|
-
};
|
|
166
|
-
};
|
|
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
|
-
];
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
return function copyFiles(from, to, tsconfigPath) {
|
|
205
|
-
return _ref.apply(this, arguments);
|
|
206
|
-
};
|
|
207
|
-
}();
|
|
208
|
-
var compileByTs = function() {
|
|
209
|
-
var _ref = _asyncToGenerator(function(appDirectory, config, compileOptions) {
|
|
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
|
-
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
|
-
_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
|
-
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
|
-
];
|
|
321
|
-
}
|
|
322
|
-
});
|
|
323
|
-
});
|
|
324
|
-
return function compileByTs(appDirectory, config, compileOptions) {
|
|
325
|
-
return _ref.apply(this, arguments);
|
|
326
|
-
};
|
|
327
|
-
}();
|
|
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 };
|