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