@modern-js/server-utils 2.15.0 → 2.17.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 +23 -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,45 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var tsconfigPathsPlugin_exports = {};
|
|
29
|
-
__export(tsconfigPathsPlugin_exports, {
|
|
30
|
-
tsconfigPathsBeforeHookFactory: () => tsconfigPathsBeforeHookFactory
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "tsconfigPathsBeforeHookFactory", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => tsconfigPathsBeforeHookFactory
|
|
31
8
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
9
|
+
const _os = /* @__PURE__ */ _interop_require_wildcard(require("os"));
|
|
10
|
+
const _path = /* @__PURE__ */ _interop_require_wildcard(require("path"));
|
|
11
|
+
const _typescript = /* @__PURE__ */ _interop_require_wildcard(require("typescript"));
|
|
12
|
+
const _tsconfigpaths = require("@modern-js/utils/tsconfig-paths");
|
|
13
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
14
|
+
if (typeof WeakMap !== "function")
|
|
15
|
+
return null;
|
|
16
|
+
var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
|
|
17
|
+
var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
|
|
18
|
+
return (_getRequireWildcardCache = function(nodeInterop2) {
|
|
19
|
+
return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
|
|
20
|
+
})(nodeInterop);
|
|
21
|
+
}
|
|
22
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
23
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
24
|
+
return obj;
|
|
25
|
+
}
|
|
26
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
27
|
+
return {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
32
|
+
if (cache && cache.has(obj)) {
|
|
33
|
+
return cache.get(obj);
|
|
34
|
+
}
|
|
35
|
+
var newObj = {};
|
|
36
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
37
|
+
for (var key in obj) {
|
|
38
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
39
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
40
|
+
if (desc && (desc.get || desc.set)) {
|
|
41
|
+
Object.defineProperty(newObj, key, desc);
|
|
42
|
+
} else {
|
|
43
|
+
newObj[key] = obj[key];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
newObj.default = obj;
|
|
48
|
+
if (cache) {
|
|
49
|
+
cache.set(obj, newObj);
|
|
50
|
+
}
|
|
51
|
+
return newObj;
|
|
52
|
+
}
|
|
37
53
|
const isRegExpKey = (str) => {
|
|
38
54
|
return str.startsWith("^") || str.endsWith("$");
|
|
39
55
|
};
|
|
40
56
|
const resolveAliasPath = (baseUrl, filePath) => {
|
|
41
57
|
if (filePath.startsWith(".") || filePath.startsWith("..")) {
|
|
42
|
-
return
|
|
58
|
+
return _path.default.resolve(baseUrl, filePath);
|
|
43
59
|
}
|
|
44
60
|
return filePath;
|
|
45
61
|
};
|
|
@@ -48,10 +64,16 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
48
64
|
if (isRegExpKey(key)) {
|
|
49
65
|
const regexp = new RegExp(key);
|
|
50
66
|
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
51
|
-
o.push([
|
|
67
|
+
o.push([
|
|
68
|
+
regexp,
|
|
69
|
+
aliasPath
|
|
70
|
+
]);
|
|
52
71
|
} else {
|
|
53
72
|
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
54
|
-
o.push([
|
|
73
|
+
o.push([
|
|
74
|
+
key,
|
|
75
|
+
aliasPath
|
|
76
|
+
]);
|
|
55
77
|
}
|
|
56
78
|
return o;
|
|
57
79
|
}, []);
|
|
@@ -75,7 +97,7 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
75
97
|
};
|
|
76
98
|
};
|
|
77
99
|
const isDynamicImport = (tsBinary, node) => {
|
|
78
|
-
return tsBinary.isCallExpression(node) && node.expression.kind ===
|
|
100
|
+
return tsBinary.isCallExpression(node) && node.expression.kind === _typescript.SyntaxKind.ImportKeyword;
|
|
79
101
|
};
|
|
80
102
|
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
81
103
|
const tsPaths = {};
|
|
@@ -88,14 +110,11 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
88
110
|
}
|
|
89
111
|
});
|
|
90
112
|
const matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
91
|
-
const matchTsPath = (0,
|
|
113
|
+
const matchTsPath = (0, _tsconfigpaths.createMatchPath)(baseUrl, tsPaths, [
|
|
114
|
+
"main"
|
|
115
|
+
]);
|
|
92
116
|
const matchPath = (requestedModule, readJSONSync, fileExists, extensions) => {
|
|
93
|
-
const result = matchTsPath(
|
|
94
|
-
requestedModule,
|
|
95
|
-
readJSONSync,
|
|
96
|
-
fileExists,
|
|
97
|
-
extensions
|
|
98
|
-
);
|
|
117
|
+
const result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
99
118
|
if (result) {
|
|
100
119
|
return result;
|
|
101
120
|
}
|
|
@@ -107,36 +126,25 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
107
126
|
return (ctx) => {
|
|
108
127
|
return (sf) => {
|
|
109
128
|
const visitNode = (node) => {
|
|
110
|
-
var _a;
|
|
111
129
|
if (isDynamicImport(tsBinary, node)) {
|
|
112
130
|
const importPathWithQuotes = node.arguments[0].getText(sf);
|
|
113
|
-
const text = importPathWithQuotes.slice(
|
|
114
|
-
1,
|
|
115
|
-
importPathWithQuotes.length - 1
|
|
116
|
-
);
|
|
131
|
+
const text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
117
132
|
const result = getNotAliasedPath(sf, matchPath, text);
|
|
118
133
|
if (!result) {
|
|
119
134
|
return node;
|
|
120
135
|
}
|
|
121
|
-
return tsBinary.factory.updateCallExpression(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
node.typeArguments,
|
|
125
|
-
tsBinary.factory.createNodeArray([
|
|
126
|
-
tsBinary.factory.createStringLiteral(result)
|
|
127
|
-
])
|
|
128
|
-
);
|
|
136
|
+
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([
|
|
137
|
+
tsBinary.factory.createStringLiteral(result)
|
|
138
|
+
]));
|
|
129
139
|
}
|
|
130
140
|
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
131
141
|
try {
|
|
132
|
-
|
|
142
|
+
var _node_moduleSpecifier;
|
|
143
|
+
const importPathWithQuotes = node === null || node === void 0 ? void 0 : (_node_moduleSpecifier = node.moduleSpecifier) === null || _node_moduleSpecifier === void 0 ? void 0 : _node_moduleSpecifier.getText();
|
|
133
144
|
if (!importPathWithQuotes) {
|
|
134
145
|
return node;
|
|
135
146
|
}
|
|
136
|
-
const text = importPathWithQuotes.substring(
|
|
137
|
-
1,
|
|
138
|
-
importPathWithQuotes.length - 1
|
|
139
|
-
);
|
|
147
|
+
const text = importPathWithQuotes.substring(1, importPathWithQuotes.length - 1);
|
|
140
148
|
const result = getNotAliasedPath(sf, matchPath, text);
|
|
141
149
|
if (!result) {
|
|
142
150
|
return node;
|
|
@@ -145,22 +153,9 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
145
153
|
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
146
154
|
let newNode;
|
|
147
155
|
if (tsBinary.isImportDeclaration(node)) {
|
|
148
|
-
newNode = tsBinary.factory.updateImportDeclaration(
|
|
149
|
-
node,
|
|
150
|
-
node.modifiers,
|
|
151
|
-
node.importClause,
|
|
152
|
-
moduleSpecifier,
|
|
153
|
-
node.assertClause
|
|
154
|
-
);
|
|
156
|
+
newNode = tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
155
157
|
} else {
|
|
156
|
-
newNode = tsBinary.factory.updateExportDeclaration(
|
|
157
|
-
node,
|
|
158
|
-
node.modifiers,
|
|
159
|
-
node.isTypeOnly,
|
|
160
|
-
node.exportClause,
|
|
161
|
-
moduleSpecifier,
|
|
162
|
-
node.assertClause
|
|
163
|
-
);
|
|
158
|
+
newNode = tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
164
159
|
}
|
|
165
160
|
newNode.flags = node.flags;
|
|
166
161
|
return newNode;
|
|
@@ -184,14 +179,17 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
184
179
|
if (!result) {
|
|
185
180
|
return;
|
|
186
181
|
}
|
|
187
|
-
if (
|
|
182
|
+
if (_os.platform() === "win32") {
|
|
188
183
|
result = result.replace(/\\/g, "/");
|
|
189
184
|
}
|
|
190
|
-
if (!
|
|
185
|
+
if (!_path.default.isAbsolute(result)) {
|
|
191
186
|
if (!result.startsWith(".") && !result.startsWith("..")) {
|
|
192
187
|
try {
|
|
193
188
|
const packagePath = require.resolve(result, {
|
|
194
|
-
paths: [
|
|
189
|
+
paths: [
|
|
190
|
+
process.cwd(),
|
|
191
|
+
...module.paths
|
|
192
|
+
]
|
|
195
193
|
});
|
|
196
194
|
if (packagePath) {
|
|
197
195
|
return result;
|
|
@@ -201,7 +199,10 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
201
199
|
}
|
|
202
200
|
try {
|
|
203
201
|
const packagePath = require.resolve(text, {
|
|
204
|
-
paths: [
|
|
202
|
+
paths: [
|
|
203
|
+
process.cwd(),
|
|
204
|
+
...module.paths
|
|
205
|
+
]
|
|
205
206
|
});
|
|
206
207
|
if (packagePath) {
|
|
207
208
|
return text;
|
|
@@ -209,10 +210,6 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
209
210
|
} catch {
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
|
-
const resolvedPath =
|
|
213
|
+
const resolvedPath = _path.posix.relative((0, _path.dirname)(sf.fileName), result) || "./";
|
|
213
214
|
return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
|
|
214
215
|
}
|
|
215
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
216
|
-
0 && (module.exports = {
|
|
217
|
-
tsconfigPathsBeforeHookFactory
|
|
218
|
-
});
|
|
@@ -1,47 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var typescriptLoader_exports = {};
|
|
19
|
-
__export(typescriptLoader_exports, {
|
|
20
|
-
TypescriptLoader: () => TypescriptLoader
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
21
4
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
Object.defineProperty(exports, "TypescriptLoader", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => TypescriptLoader
|
|
8
|
+
});
|
|
9
|
+
function _define_property(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
26
19
|
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
class TypescriptLoader {
|
|
27
23
|
load() {
|
|
28
24
|
if (this.tsBinary) {
|
|
29
25
|
return this.tsBinary;
|
|
30
26
|
}
|
|
31
27
|
try {
|
|
32
28
|
const tsPath = require.resolve("typescript", {
|
|
33
|
-
paths: [
|
|
29
|
+
paths: [
|
|
30
|
+
this.appDirectory || process.cwd()
|
|
31
|
+
]
|
|
34
32
|
});
|
|
35
33
|
const ts = require(tsPath);
|
|
36
34
|
return ts;
|
|
37
35
|
} catch (error) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
'TypeScript could not be found! Please, install "typescript" package.'
|
|
40
|
-
);
|
|
36
|
+
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
41
37
|
}
|
|
42
38
|
}
|
|
39
|
+
constructor({ appDirectory }) {
|
|
40
|
+
_define_property(this, "tsBinary", void 0);
|
|
41
|
+
_define_property(this, "appDirectory", void 0);
|
|
42
|
+
this.appDirectory = appDirectory;
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
-
0 && (module.exports = {
|
|
46
|
-
TypescriptLoader
|
|
47
|
-
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var src_exports = {};
|
|
20
|
-
__export(src_exports, {
|
|
21
|
-
compile: () => import_common.compile
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
22
4
|
});
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
-
0 && (module.exports = {
|
|
28
|
-
compile
|
|
5
|
+
Object.defineProperty(exports, "compile", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: () => _common.compile
|
|
29
8
|
});
|
|
9
|
+
_export_star(require("./compilers/babel"), exports);
|
|
10
|
+
const _common = require("./common");
|
|
11
|
+
function _export_star(from, to) {
|
|
12
|
+
Object.keys(from).forEach(function(k) {
|
|
13
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
14
|
+
Object.defineProperty(to, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return from[k];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return from;
|
|
23
|
+
}
|