@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
|
@@ -1,65 +1,204 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
31
|
+
var f, y, t, g, _ = {
|
|
32
|
+
label: 0,
|
|
33
|
+
sent: function() {
|
|
34
|
+
if (t[0] & 1) throw t[1];
|
|
35
|
+
return t[1];
|
|
36
|
+
},
|
|
37
|
+
trys: [],
|
|
38
|
+
ops: []
|
|
39
|
+
};
|
|
40
|
+
return(g = {
|
|
41
|
+
next: verb(0),
|
|
42
|
+
"throw": verb(1),
|
|
43
|
+
"return": verb(2)
|
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
45
|
+
return this;
|
|
46
|
+
}), g);
|
|
47
|
+
function verb(n) {
|
|
48
|
+
return function(v) {
|
|
49
|
+
return step([
|
|
50
|
+
n,
|
|
51
|
+
v
|
|
52
|
+
]);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while(_)try {
|
|
58
|
+
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;
|
|
59
|
+
if (y = 0, t) op = [
|
|
60
|
+
op[0] & 2,
|
|
61
|
+
t.value
|
|
62
|
+
];
|
|
63
|
+
switch(op[0]){
|
|
64
|
+
case 0:
|
|
65
|
+
case 1:
|
|
66
|
+
t = op;
|
|
67
|
+
break;
|
|
68
|
+
case 4:
|
|
69
|
+
_.label++;
|
|
70
|
+
return {
|
|
71
|
+
value: op[1],
|
|
72
|
+
done: false
|
|
73
|
+
};
|
|
74
|
+
case 5:
|
|
75
|
+
_.label++;
|
|
76
|
+
y = op[1];
|
|
77
|
+
op = [
|
|
78
|
+
0
|
|
79
|
+
];
|
|
80
|
+
continue;
|
|
81
|
+
case 7:
|
|
82
|
+
op = _.ops.pop();
|
|
83
|
+
_.trys.pop();
|
|
84
|
+
continue;
|
|
85
|
+
default:
|
|
86
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
87
|
+
_ = 0;
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
91
|
+
_.label = op[1];
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
95
|
+
_.label = t[1];
|
|
96
|
+
t = op;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t && _.label < t[2]) {
|
|
100
|
+
_.label = t[2];
|
|
101
|
+
_.ops.push(op);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t[2]) _.ops.pop();
|
|
105
|
+
_.trys.pop();
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
op = body.call(thisArg, _);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
op = [
|
|
111
|
+
6,
|
|
112
|
+
e
|
|
113
|
+
];
|
|
114
|
+
y = 0;
|
|
115
|
+
} finally{
|
|
116
|
+
f = t = 0;
|
|
117
|
+
}
|
|
118
|
+
if (op[0] & 5) throw op[1];
|
|
119
|
+
return {
|
|
120
|
+
value: op[0] ? op[1] : void 0,
|
|
121
|
+
done: true
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
import * as path from "path";
|
|
126
|
+
import { fs } from "@modern-js/utils";
|
|
5
127
|
import { compileByTs } from "../compilers/typescript";
|
|
6
128
|
import { compileByBabel } from "../compilers/babel";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
129
|
+
var FILE_EXTENSIONS = [
|
|
130
|
+
".js",
|
|
131
|
+
".ts",
|
|
132
|
+
".mjs",
|
|
133
|
+
".ejs"
|
|
134
|
+
];
|
|
135
|
+
var validateAbsolutePath = function(filename, message) {
|
|
136
|
+
if (!path.isAbsolute(filename)) {
|
|
137
|
+
throw new Error(message);
|
|
138
|
+
}
|
|
12
139
|
};
|
|
13
|
-
var validateAbsolutePaths = function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
140
|
+
var validateAbsolutePaths = function(filenames, messageFunc) {
|
|
141
|
+
filenames.forEach(function(filename) {
|
|
142
|
+
return validateAbsolutePath(filename, messageFunc(filename));
|
|
143
|
+
});
|
|
17
144
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
145
|
+
var compile = function() {
|
|
146
|
+
var _ref = _asyncToGenerator(function(appDirectory, modernConfig, compileOptions) {
|
|
147
|
+
var ref, sourceDirs, distDir, tsconfigPath, compiler, isTsProject, _tmp;
|
|
148
|
+
return __generator(this, function(_state) {
|
|
149
|
+
switch(_state.label){
|
|
150
|
+
case 0:
|
|
151
|
+
sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath;
|
|
152
|
+
validateAbsolutePaths(sourceDirs, function(dir) {
|
|
153
|
+
return "source dir ".concat(dir, " is not an absolute path.");
|
|
154
|
+
});
|
|
155
|
+
validateAbsolutePath(distDir, "dist dir ".concat(distDir, " is not an absolute path."));
|
|
156
|
+
compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.server) === null || ref === void 0 ? void 0 : ref.compiler;
|
|
157
|
+
_tmp = tsconfigPath;
|
|
158
|
+
if (!_tmp) return [
|
|
159
|
+
3,
|
|
160
|
+
2
|
|
161
|
+
];
|
|
162
|
+
return [
|
|
163
|
+
4,
|
|
164
|
+
fs.pathExists(tsconfigPath)
|
|
165
|
+
];
|
|
166
|
+
case 1:
|
|
167
|
+
_tmp = _state.sent();
|
|
168
|
+
_state.label = 2;
|
|
169
|
+
case 2:
|
|
170
|
+
isTsProject = _tmp;
|
|
171
|
+
if (!(!isTsProject || compiler === "babel")) return [
|
|
172
|
+
3,
|
|
173
|
+
4
|
|
174
|
+
];
|
|
175
|
+
return [
|
|
176
|
+
4,
|
|
177
|
+
compileByBabel(appDirectory, modernConfig, compileOptions)
|
|
178
|
+
];
|
|
179
|
+
case 3:
|
|
180
|
+
_state.sent();
|
|
181
|
+
return [
|
|
182
|
+
3,
|
|
183
|
+
6
|
|
184
|
+
];
|
|
185
|
+
case 4:
|
|
186
|
+
return [
|
|
187
|
+
4,
|
|
188
|
+
compileByTs(appDirectory, modernConfig, compileOptions)
|
|
189
|
+
];
|
|
190
|
+
case 5:
|
|
191
|
+
_state.sent();
|
|
192
|
+
_state.label = 6;
|
|
193
|
+
case 6:
|
|
194
|
+
return [
|
|
195
|
+
2
|
|
196
|
+
];
|
|
46
197
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return compileByTs(appDirectory, modernConfig, compileOptions);
|
|
55
|
-
case 17:
|
|
56
|
-
case "end":
|
|
57
|
-
return _context.stop();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}, _callee);
|
|
61
|
-
}));
|
|
62
|
-
return function compile(_x, _x2, _x3) {
|
|
63
|
-
return _ref.apply(this, arguments);
|
|
64
|
-
};
|
|
65
|
-
}();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
return function compile(appDirectory, modernConfig, compileOptions) {
|
|
201
|
+
return _ref.apply(this, arguments);
|
|
202
|
+
};
|
|
203
|
+
}();
|
|
204
|
+
export { FILE_EXTENSIONS, compile };
|