@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
|
@@ -1,246 +1,261 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
5
7
|
}
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
8
11
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
12
|
+
function _array_without_holes(arr) {
|
|
13
|
+
if (Array.isArray(arr))
|
|
14
|
+
return _array_like_to_array(arr);
|
|
11
15
|
}
|
|
12
16
|
function _instanceof(left, right) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
18
|
+
return !!right[Symbol.hasInstance](left);
|
|
19
|
+
} else {
|
|
20
|
+
return left instanceof right;
|
|
21
|
+
}
|
|
18
22
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
23
|
+
function _iterable_to_array(iter) {
|
|
24
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
25
|
+
return Array.from(iter);
|
|
21
26
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
function _iterable_to_array_limit(arr, i) {
|
|
28
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
29
|
+
if (_i == null)
|
|
30
|
+
return;
|
|
31
|
+
var _arr = [];
|
|
32
|
+
var _n = true;
|
|
33
|
+
var _d = false;
|
|
34
|
+
var _s, _e;
|
|
35
|
+
try {
|
|
36
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
37
|
+
_arr.push(_s.value);
|
|
38
|
+
if (i && _arr.length === i)
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_d = true;
|
|
43
|
+
_e = err;
|
|
44
|
+
} finally {
|
|
29
45
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
_d = true;
|
|
36
|
-
_e = err;
|
|
37
|
-
} finally{
|
|
38
|
-
try {
|
|
39
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
40
|
-
} finally{
|
|
41
|
-
if (_d) throw _e;
|
|
42
|
-
}
|
|
46
|
+
if (!_n && _i["return"] != null)
|
|
47
|
+
_i["return"]();
|
|
48
|
+
} finally {
|
|
49
|
+
if (_d)
|
|
50
|
+
throw _e;
|
|
43
51
|
}
|
|
44
|
-
|
|
52
|
+
}
|
|
53
|
+
return _arr;
|
|
45
54
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
55
|
+
function _non_iterable_rest() {
|
|
56
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
48
57
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
58
|
+
function _non_iterable_spread() {
|
|
59
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
51
60
|
}
|
|
52
|
-
function
|
|
53
|
-
|
|
61
|
+
function _sliced_to_array(arr, i) {
|
|
62
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
54
63
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
64
|
+
function _to_consumable_array(arr) {
|
|
65
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
57
66
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
68
|
+
if (!o)
|
|
69
|
+
return;
|
|
70
|
+
if (typeof o === "string")
|
|
71
|
+
return _array_like_to_array(o, minLen);
|
|
72
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
73
|
+
if (n === "Object" && o.constructor)
|
|
74
|
+
n = o.constructor.name;
|
|
75
|
+
if (n === "Map" || n === "Set")
|
|
76
|
+
return Array.from(n);
|
|
77
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
78
|
+
return _array_like_to_array(o, minLen);
|
|
65
79
|
}
|
|
66
80
|
import * as os from "os";
|
|
67
81
|
import path, { dirname, posix } from "path";
|
|
68
82
|
import * as ts from "typescript";
|
|
69
83
|
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
70
84
|
var isRegExpKey = function(str) {
|
|
71
|
-
|
|
85
|
+
return str.startsWith("^") || str.endsWith("$");
|
|
72
86
|
};
|
|
73
87
|
var resolveAliasPath = function(baseUrl, filePath) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
88
|
+
if (filePath.startsWith(".") || filePath.startsWith("..")) {
|
|
89
|
+
return path.resolve(baseUrl, filePath);
|
|
90
|
+
}
|
|
91
|
+
return filePath;
|
|
78
92
|
};
|
|
79
93
|
var createAliasMatcher = function(baseUrl, alias) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
+
var aliasPairs = Object.keys(alias).reduce(function(o, key) {
|
|
95
|
+
if (isRegExpKey(key)) {
|
|
96
|
+
var regexp = new RegExp(key);
|
|
97
|
+
var aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
98
|
+
o.push([
|
|
99
|
+
regexp,
|
|
100
|
+
aliasPath
|
|
101
|
+
]);
|
|
102
|
+
} else {
|
|
103
|
+
var aliasPath1 = resolveAliasPath(baseUrl, alias[key]);
|
|
104
|
+
o.push([
|
|
105
|
+
key,
|
|
106
|
+
aliasPath1
|
|
107
|
+
]);
|
|
108
|
+
}
|
|
109
|
+
return o;
|
|
110
|
+
}, []);
|
|
111
|
+
var cacheMap = /* @__PURE__ */ new Map();
|
|
112
|
+
return function(requestedModule) {
|
|
113
|
+
if (cacheMap.has(requestedModule)) {
|
|
114
|
+
return cacheMap.get(requestedModule);
|
|
115
|
+
}
|
|
116
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
117
|
+
try {
|
|
118
|
+
for (var _iterator = aliasPairs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
119
|
+
var _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
120
|
+
if (_instanceof(key, RegExp)) {
|
|
121
|
+
if (key.test(requestedModule)) {
|
|
122
|
+
cacheMap.set(requestedModule, value);
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
94
125
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return function(requestedModule) {
|
|
99
|
-
if (cacheMap.has(requestedModule)) {
|
|
100
|
-
return cacheMap.get(requestedModule);
|
|
126
|
+
if (requestedModule === key) {
|
|
127
|
+
cacheMap.set(requestedModule, value);
|
|
128
|
+
return value;
|
|
101
129
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if (requestedModule === key) {
|
|
113
|
-
cacheMap.set(requestedModule, value);
|
|
114
|
-
return value;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
} catch (err) {
|
|
118
|
-
_didIteratorError = true;
|
|
119
|
-
_iteratorError = err;
|
|
120
|
-
} finally{
|
|
121
|
-
try {
|
|
122
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
123
|
-
_iterator.return();
|
|
124
|
-
}
|
|
125
|
-
} finally{
|
|
126
|
-
if (_didIteratorError) {
|
|
127
|
-
throw _iteratorError;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
_didIteratorError = true;
|
|
133
|
+
_iteratorError = err;
|
|
134
|
+
} finally {
|
|
135
|
+
try {
|
|
136
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
137
|
+
_iterator.return();
|
|
130
138
|
}
|
|
131
|
-
|
|
139
|
+
} finally {
|
|
140
|
+
if (_didIteratorError) {
|
|
141
|
+
throw _iteratorError;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
132
146
|
};
|
|
133
147
|
var isDynamicImport = function(tsBinary, node) {
|
|
134
|
-
|
|
148
|
+
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
135
149
|
};
|
|
136
|
-
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
150
|
+
export function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
151
|
+
var tsPaths = {};
|
|
152
|
+
var alias = {};
|
|
153
|
+
Object.keys(paths).forEach(function(key) {
|
|
154
|
+
if (Array.isArray(paths[key])) {
|
|
155
|
+
tsPaths[key] = paths[key];
|
|
156
|
+
} else {
|
|
157
|
+
alias[key] = paths[key];
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
var matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
161
|
+
var matchTsPath = createMatchPath(baseUrl, tsPaths, [
|
|
162
|
+
"main"
|
|
163
|
+
]);
|
|
164
|
+
var matchPath = function(requestedModule, readJSONSync, fileExists, extensions) {
|
|
165
|
+
var result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
166
|
+
if (result) {
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
return matchAliasPath(requestedModule);
|
|
170
|
+
};
|
|
171
|
+
if (Object.keys(paths).length === 0) {
|
|
172
|
+
return void 0;
|
|
173
|
+
}
|
|
174
|
+
return function(ctx) {
|
|
175
|
+
return function(sf) {
|
|
176
|
+
var visitNode = function(node) {
|
|
177
|
+
if (isDynamicImport(tsBinary, node)) {
|
|
178
|
+
var importPathWithQuotes = node.arguments[0].getText(sf);
|
|
179
|
+
var text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
180
|
+
var result = getNotAliasedPath(sf, matchPath, text);
|
|
181
|
+
if (!result) {
|
|
182
|
+
return node;
|
|
183
|
+
}
|
|
184
|
+
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([
|
|
185
|
+
tsBinary.factory.createStringLiteral(result)
|
|
186
|
+
]));
|
|
144
187
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
188
|
+
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
189
|
+
try {
|
|
190
|
+
var _node_moduleSpecifier;
|
|
191
|
+
var importPathWithQuotes1 = node === null || node === void 0 ? void 0 : (_node_moduleSpecifier = node.moduleSpecifier) === null || _node_moduleSpecifier === void 0 ? void 0 : _node_moduleSpecifier.getText();
|
|
192
|
+
if (!importPathWithQuotes1) {
|
|
193
|
+
return node;
|
|
194
|
+
}
|
|
195
|
+
var text1 = importPathWithQuotes1.substring(1, importPathWithQuotes1.length - 1);
|
|
196
|
+
var result1 = getNotAliasedPath(sf, matchPath, text1);
|
|
197
|
+
if (!result1) {
|
|
198
|
+
return node;
|
|
199
|
+
}
|
|
200
|
+
var moduleSpecifier = tsBinary.factory.createStringLiteral(result1);
|
|
201
|
+
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
202
|
+
var newNode;
|
|
203
|
+
if (tsBinary.isImportDeclaration(node)) {
|
|
204
|
+
newNode = tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
205
|
+
} else {
|
|
206
|
+
newNode = tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
207
|
+
}
|
|
208
|
+
newNode.flags = node.flags;
|
|
209
|
+
return newNode;
|
|
210
|
+
} catch (e) {
|
|
211
|
+
return node;
|
|
212
|
+
}
|
|
154
213
|
}
|
|
155
|
-
return
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return void 0;
|
|
159
|
-
}
|
|
160
|
-
return function(ctx) {
|
|
161
|
-
return function(sf) {
|
|
162
|
-
var visitNode = function(node) {
|
|
163
|
-
if (isDynamicImport(tsBinary, node)) {
|
|
164
|
-
var importPathWithQuotes = node.arguments[0].getText(sf);
|
|
165
|
-
var text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
166
|
-
var result = getNotAliasedPath(sf, matchPath, text);
|
|
167
|
-
if (!result) {
|
|
168
|
-
return node;
|
|
169
|
-
}
|
|
170
|
-
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([
|
|
171
|
-
tsBinary.factory.createStringLiteral(result)
|
|
172
|
-
]));
|
|
173
|
-
}
|
|
174
|
-
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
175
|
-
try {
|
|
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
|
-
if (!importPathWithQuotes1) {
|
|
179
|
-
return node;
|
|
180
|
-
}
|
|
181
|
-
var text1 = importPathWithQuotes1.substring(1, importPathWithQuotes1.length - 1);
|
|
182
|
-
var result1 = getNotAliasedPath(sf, matchPath, text1);
|
|
183
|
-
if (!result1) {
|
|
184
|
-
return node;
|
|
185
|
-
}
|
|
186
|
-
var moduleSpecifier = tsBinary.factory.createStringLiteral(result1);
|
|
187
|
-
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
188
|
-
var newNode;
|
|
189
|
-
if (tsBinary.isImportDeclaration(node)) {
|
|
190
|
-
newNode = tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
191
|
-
} else {
|
|
192
|
-
newNode = tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
193
|
-
}
|
|
194
|
-
newNode.flags = node.flags;
|
|
195
|
-
return newNode;
|
|
196
|
-
} catch (e) {
|
|
197
|
-
return node;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
201
|
-
};
|
|
202
|
-
return tsBinary.visitNode(sf, visitNode);
|
|
203
|
-
};
|
|
214
|
+
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
215
|
+
};
|
|
216
|
+
return tsBinary.visitNode(sf, visitNode);
|
|
204
217
|
};
|
|
218
|
+
};
|
|
205
219
|
}
|
|
206
220
|
function getNotAliasedPath(sf, matcher, text) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
} catch (e) {}
|
|
221
|
+
var result = matcher(text, void 0, void 0, [
|
|
222
|
+
".ts",
|
|
223
|
+
".tsx",
|
|
224
|
+
".js",
|
|
225
|
+
".jsx"
|
|
226
|
+
]);
|
|
227
|
+
if (!result) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (os.platform() === "win32") {
|
|
231
|
+
result = result.replace(/\\/g, "/");
|
|
232
|
+
}
|
|
233
|
+
if (!path.isAbsolute(result)) {
|
|
234
|
+
if (!result.startsWith(".") && !result.startsWith("..")) {
|
|
235
|
+
try {
|
|
236
|
+
var packagePath = require.resolve(result, {
|
|
237
|
+
paths: [
|
|
238
|
+
process.cwd()
|
|
239
|
+
].concat(_to_consumable_array(module.paths))
|
|
240
|
+
});
|
|
241
|
+
if (packagePath) {
|
|
242
|
+
return result;
|
|
231
243
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
244
|
+
} catch (e) {
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
var packagePath1 = require.resolve(text, {
|
|
249
|
+
paths: [
|
|
250
|
+
process.cwd()
|
|
251
|
+
].concat(_to_consumable_array(module.paths))
|
|
252
|
+
});
|
|
253
|
+
if (packagePath1) {
|
|
254
|
+
return text;
|
|
255
|
+
}
|
|
256
|
+
} catch (e) {
|
|
242
257
|
}
|
|
243
|
-
|
|
244
|
-
|
|
258
|
+
}
|
|
259
|
+
var resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
|
|
260
|
+
return resolvedPath[0] === "." ? resolvedPath : "./".concat(resolvedPath);
|
|
245
261
|
}
|
|
246
|
-
export { tsconfigPathsBeforeHookFactory };
|
|
@@ -1,65 +1,67 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _class_call_check(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
5
5
|
}
|
|
6
6
|
function _defineProperties(target, props) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
for (var i = 0; i < props.length; i++) {
|
|
8
|
+
var descriptor = props[i];
|
|
9
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
10
|
+
descriptor.configurable = true;
|
|
11
|
+
if ("value" in descriptor)
|
|
12
|
+
descriptor.writable = true;
|
|
13
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
14
|
+
}
|
|
14
15
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
function _create_class(Constructor, protoProps, staticProps) {
|
|
17
|
+
if (protoProps)
|
|
18
|
+
_defineProperties(Constructor.prototype, protoProps);
|
|
19
|
+
if (staticProps)
|
|
20
|
+
_defineProperties(Constructor, staticProps);
|
|
21
|
+
return Constructor;
|
|
19
22
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
function _define_property(obj, key, value) {
|
|
24
|
+
if (key in obj) {
|
|
25
|
+
Object.defineProperty(obj, key, {
|
|
26
|
+
value,
|
|
27
|
+
enumerable: true,
|
|
28
|
+
configurable: true,
|
|
29
|
+
writable: true
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
obj[key] = value;
|
|
33
|
+
}
|
|
34
|
+
return obj;
|
|
32
35
|
}
|
|
33
|
-
var TypescriptLoader =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
}
|
|
36
|
+
export var TypescriptLoader = /* @__PURE__ */ function() {
|
|
37
|
+
"use strict";
|
|
38
|
+
function TypescriptLoader2(param) {
|
|
39
|
+
var appDirectory = param.appDirectory;
|
|
40
|
+
_class_call_check(this, TypescriptLoader2);
|
|
41
|
+
_define_property(this, "tsBinary", void 0);
|
|
42
|
+
_define_property(this, "appDirectory", void 0);
|
|
43
|
+
this.appDirectory = appDirectory;
|
|
44
|
+
}
|
|
45
|
+
_create_class(TypescriptLoader2, [
|
|
46
|
+
{
|
|
47
|
+
key: "load",
|
|
48
|
+
value: function load() {
|
|
49
|
+
if (this.tsBinary) {
|
|
50
|
+
return this.tsBinary;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
var tsPath = require.resolve("typescript", {
|
|
54
|
+
paths: [
|
|
55
|
+
this.appDirectory || process.cwd()
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
var ts = require(tsPath);
|
|
59
|
+
return ts;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
61
62
|
}
|
|
62
|
-
|
|
63
|
-
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
]);
|
|
66
|
+
return TypescriptLoader2;
|
|
64
67
|
}();
|
|
65
|
-
export { TypescriptLoader };
|
package/dist/esm/index.js
CHANGED
|
@@ -2,26 +2,26 @@ import * as path from "path";
|
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
3
|
import { compileByTs } from "../compilers/typescript";
|
|
4
4
|
import { compileByBabel } from "../compilers/babel";
|
|
5
|
-
const FILE_EXTENSIONS = [
|
|
5
|
+
export const FILE_EXTENSIONS = [
|
|
6
|
+
".js",
|
|
7
|
+
".ts",
|
|
8
|
+
".mjs",
|
|
9
|
+
".ejs"
|
|
10
|
+
];
|
|
6
11
|
const validateAbsolutePath = (filename, message) => {
|
|
7
12
|
if (!path.isAbsolute(filename)) {
|
|
8
13
|
throw new Error(message);
|
|
9
14
|
}
|
|
10
15
|
};
|
|
11
16
|
const validateAbsolutePaths = (filenames, messageFunc) => {
|
|
12
|
-
filenames.forEach(
|
|
13
|
-
(filename) => validateAbsolutePath(filename, messageFunc(filename))
|
|
14
|
-
);
|
|
17
|
+
filenames.forEach((filename) => validateAbsolutePath(filename, messageFunc(filename)));
|
|
15
18
|
};
|
|
16
|
-
const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
17
|
-
var
|
|
19
|
+
export const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
20
|
+
var _modernConfig_server;
|
|
18
21
|
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
19
|
-
validateAbsolutePaths(
|
|
20
|
-
sourceDirs,
|
|
21
|
-
(dir) => `source dir ${dir} is not an absolute path.`
|
|
22
|
-
);
|
|
22
|
+
validateAbsolutePaths(sourceDirs, (dir) => `source dir ${dir} is not an absolute path.`);
|
|
23
23
|
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
24
|
-
const compiler =
|
|
24
|
+
const compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_server = modernConfig.server) === null || _modernConfig_server === void 0 ? void 0 : _modernConfig_server.compiler;
|
|
25
25
|
const isTsProject = tsconfigPath && await fs.pathExists(tsconfigPath);
|
|
26
26
|
if (!isTsProject || compiler === "babel") {
|
|
27
27
|
await compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
@@ -29,7 +29,3 @@ const compile = async (appDirectory, modernConfig, compileOptions) => {
|
|
|
29
29
|
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
export {
|
|
33
|
-
FILE_EXTENSIONS,
|
|
34
|
-
compile
|
|
35
|
-
};
|