@modern-js/server-utils 2.5.1-alpha.0 → 2.6.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 +11 -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 +4 -0
- package/dist/esm/compilers/typescript/index.js +6 -6
- package/dist/esm-node/compilers/typescript/index.js +4 -4
- 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
|
@@ -1,246 +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 _arrayWithoutHoles(arr) {
|
|
10
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
11
|
-
}
|
|
12
|
-
function _instanceof(left, right) {
|
|
13
|
-
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
14
|
-
return !!right[Symbol.hasInstance](left);
|
|
15
|
-
} else {
|
|
16
|
-
return left instanceof right;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
function _iterableToArray(iter) {
|
|
20
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
21
|
-
}
|
|
22
|
-
function _iterableToArrayLimit(arr, i) {
|
|
23
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
24
|
-
if (_i == null) return;
|
|
25
|
-
var _arr = [];
|
|
26
|
-
var _n = true;
|
|
27
|
-
var _d = false;
|
|
28
|
-
var _s, _e;
|
|
29
|
-
try {
|
|
30
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
31
|
-
_arr.push(_s.value);
|
|
32
|
-
if (i && _arr.length === i) break;
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
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
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return _arr;
|
|
45
|
-
}
|
|
46
|
-
function _nonIterableRest() {
|
|
47
|
-
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
|
-
}
|
|
49
|
-
function _nonIterableSpread() {
|
|
50
|
-
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
|
-
}
|
|
52
|
-
function _slicedToArray(arr, i) {
|
|
53
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
54
|
-
}
|
|
55
|
-
function _toConsumableArray(arr) {
|
|
56
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
57
|
-
}
|
|
58
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
59
|
-
if (!o) return;
|
|
60
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
61
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
62
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
63
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
64
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
65
|
-
}
|
|
66
|
-
import * as os from "os";
|
|
67
|
-
import path, { dirname, posix } from "path";
|
|
68
|
-
import * as ts from "typescript";
|
|
69
|
-
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
70
|
-
var isRegExpKey = function(str) {
|
|
71
|
-
return str.startsWith("^") || str.endsWith("$");
|
|
72
|
-
};
|
|
73
|
-
var resolveAliasPath = function(baseUrl, filePath) {
|
|
74
|
-
if (filePath.startsWith(".") || filePath.startsWith("..")) {
|
|
75
|
-
return path.resolve(baseUrl, filePath);
|
|
76
|
-
}
|
|
77
|
-
return filePath;
|
|
78
|
-
};
|
|
79
|
-
var createAliasMatcher = function(baseUrl, alias) {
|
|
80
|
-
var aliasPairs = Object.keys(alias).reduce(function(o, key) {
|
|
81
|
-
if (isRegExpKey(key)) {
|
|
82
|
-
var regexp = new RegExp(key);
|
|
83
|
-
var aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
84
|
-
o.push([
|
|
85
|
-
regexp,
|
|
86
|
-
aliasPath
|
|
87
|
-
]);
|
|
88
|
-
} else {
|
|
89
|
-
var aliasPath1 = resolveAliasPath(baseUrl, alias[key]);
|
|
90
|
-
o.push([
|
|
91
|
-
key,
|
|
92
|
-
aliasPath1
|
|
93
|
-
]);
|
|
94
|
-
}
|
|
95
|
-
return o;
|
|
96
|
-
}, []);
|
|
97
|
-
var cacheMap = /* @__PURE__ */ new Map();
|
|
98
|
-
return function(requestedModule) {
|
|
99
|
-
if (cacheMap.has(requestedModule)) {
|
|
100
|
-
return cacheMap.get(requestedModule);
|
|
101
|
-
}
|
|
102
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
103
|
-
try {
|
|
104
|
-
for(var _iterator = aliasPairs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
105
|
-
var _step_value = _slicedToArray(_step.value, 2), key = _step_value[0], value = _step_value[1];
|
|
106
|
-
if (_instanceof(key, RegExp)) {
|
|
107
|
-
if (key.test(requestedModule)) {
|
|
108
|
-
cacheMap.set(requestedModule, value);
|
|
109
|
-
return value;
|
|
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
|
-
};
|
|
132
|
-
};
|
|
133
|
-
var isDynamicImport = function(tsBinary, node) {
|
|
134
|
-
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
135
|
-
};
|
|
136
|
-
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
137
|
-
var tsPaths = {};
|
|
138
|
-
var alias = {};
|
|
139
|
-
Object.keys(paths).forEach(function(key) {
|
|
140
|
-
if (Array.isArray(paths[key])) {
|
|
141
|
-
tsPaths[key] = paths[key];
|
|
142
|
-
} else {
|
|
143
|
-
alias[key] = paths[key];
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
var matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
147
|
-
var matchTsPath = createMatchPath(baseUrl, tsPaths, [
|
|
148
|
-
"main"
|
|
149
|
-
]);
|
|
150
|
-
var matchPath = function(requestedModule, readJSONSync, fileExists, extensions) {
|
|
151
|
-
var result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
152
|
-
if (result) {
|
|
153
|
-
return result;
|
|
154
|
-
}
|
|
155
|
-
return matchAliasPath(requestedModule);
|
|
156
|
-
};
|
|
157
|
-
if (Object.keys(paths).length === 0) {
|
|
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.decorators, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
191
|
-
} else {
|
|
192
|
-
newNode = tsBinary.factory.updateExportDeclaration(node, node.decorators, 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
|
-
};
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
function getNotAliasedPath(sf, matcher, text) {
|
|
207
|
-
var result = matcher(text, void 0, void 0, [
|
|
208
|
-
".ts",
|
|
209
|
-
".tsx",
|
|
210
|
-
".js",
|
|
211
|
-
".jsx"
|
|
212
|
-
]);
|
|
213
|
-
if (!result) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (os.platform() === "win32") {
|
|
217
|
-
result = result.replace(/\\/g, "/");
|
|
218
|
-
}
|
|
219
|
-
if (!path.isAbsolute(result)) {
|
|
220
|
-
if (!result.startsWith(".") && !result.startsWith("..")) {
|
|
221
|
-
try {
|
|
222
|
-
var packagePath = require.resolve(result, {
|
|
223
|
-
paths: [
|
|
224
|
-
process.cwd()
|
|
225
|
-
].concat(_toConsumableArray(module.paths))
|
|
226
|
-
});
|
|
227
|
-
if (packagePath) {
|
|
228
|
-
return result;
|
|
229
|
-
}
|
|
230
|
-
} catch (e) {}
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
var packagePath1 = require.resolve(text, {
|
|
234
|
-
paths: [
|
|
235
|
-
process.cwd()
|
|
236
|
-
].concat(_toConsumableArray(module.paths))
|
|
237
|
-
});
|
|
238
|
-
if (packagePath1) {
|
|
239
|
-
return text;
|
|
240
|
-
}
|
|
241
|
-
} catch (e1) {}
|
|
242
|
-
}
|
|
243
|
-
var resolvedPath = posix.relative(dirname(sf.fileName), result) || "./";
|
|
244
|
-
return resolvedPath[0] === "." ? resolvedPath : "./".concat(resolvedPath);
|
|
245
|
-
}
|
|
246
|
-
export { tsconfigPathsBeforeHookFactory };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
function _classCallCheck(instance, Constructor) {
|
|
2
|
-
if (!(instance instanceof Constructor)) {
|
|
3
|
-
throw new TypeError("Cannot call a class as a function");
|
|
4
|
-
}
|
|
5
|
-
}
|
|
6
|
-
function _defineProperties(target, props) {
|
|
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) descriptor.writable = true;
|
|
12
|
-
Object.defineProperty(target, descriptor.key, descriptor);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _createClass(Constructor, protoProps, staticProps) {
|
|
16
|
-
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
17
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
18
|
-
return Constructor;
|
|
19
|
-
}
|
|
20
|
-
function _defineProperty(obj, key, value) {
|
|
21
|
-
if (key in obj) {
|
|
22
|
-
Object.defineProperty(obj, key, {
|
|
23
|
-
value: value,
|
|
24
|
-
enumerable: true,
|
|
25
|
-
configurable: true,
|
|
26
|
-
writable: true
|
|
27
|
-
});
|
|
28
|
-
} else {
|
|
29
|
-
obj[key] = value;
|
|
30
|
-
}
|
|
31
|
-
return obj;
|
|
32
|
-
}
|
|
33
|
-
var TypescriptLoader = /*#__PURE__*/ function() {
|
|
34
|
-
"use strict";
|
|
35
|
-
function TypescriptLoader(param) {
|
|
36
|
-
var appDirectory = param.appDirectory;
|
|
37
|
-
_classCallCheck(this, TypescriptLoader);
|
|
38
|
-
_defineProperty(this, "tsBinary", void 0);
|
|
39
|
-
_defineProperty(this, "appDirectory", void 0);
|
|
40
|
-
this.appDirectory = appDirectory;
|
|
41
|
-
}
|
|
42
|
-
_createClass(TypescriptLoader, [
|
|
43
|
-
{
|
|
44
|
-
key: "load",
|
|
45
|
-
value: function load() {
|
|
46
|
-
if (this.tsBinary) {
|
|
47
|
-
return this.tsBinary;
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
var tsPath = require.resolve("typescript", {
|
|
51
|
-
paths: [
|
|
52
|
-
this.appDirectory || process.cwd()
|
|
53
|
-
]
|
|
54
|
-
});
|
|
55
|
-
var ts = require(tsPath);
|
|
56
|
-
return ts;
|
|
57
|
-
} catch (error) {
|
|
58
|
-
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
]);
|
|
63
|
-
return TypescriptLoader;
|
|
64
|
-
}();
|
|
65
|
-
export { TypescriptLoader };
|