@modern-js/server-utils 2.69.5 → 3.0.0-alpha.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/dist/cjs/common/index.js +58 -62
- package/dist/cjs/compilers/babel/index.js +145 -101
- package/dist/cjs/compilers/babel/preset/alias.js +123 -105
- package/dist/cjs/compilers/babel/preset/index.js +102 -68
- package/dist/cjs/compilers/babel/preset/types.js +17 -15
- package/dist/cjs/compilers/typescript/index.js +112 -119
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +157 -191
- package/dist/cjs/compilers/typescript/typescriptLoader.js +47 -41
- package/dist/cjs/index.js +68 -28
- package/dist/esm/common/index.mjs +29 -0
- package/dist/esm/compilers/babel/index.mjs +57 -0
- package/dist/esm/compilers/babel/preset/alias.mjs +84 -0
- package/dist/esm/compilers/babel/preset/index.mjs +29 -0
- package/dist/esm/compilers/typescript/index.mjs +76 -0
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.mjs +126 -0
- package/dist/esm/compilers/typescript/typescriptLoader.mjs +20 -0
- package/dist/{esm-node/index.js → esm/index.mjs} +2 -4
- package/dist/esm-node/common/index.mjs +29 -0
- package/dist/esm-node/compilers/babel/index.mjs +57 -0
- package/dist/esm-node/compilers/babel/preset/alias.mjs +84 -0
- package/dist/esm-node/compilers/babel/preset/index.mjs +29 -0
- package/dist/esm-node/compilers/typescript/index.mjs +76 -0
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.mjs +126 -0
- package/dist/esm-node/compilers/typescript/typescriptLoader.mjs +20 -0
- package/dist/esm-node/index.mjs +3 -0
- package/package.json +32 -24
- package/rslib.config.mts +4 -0
- package/dist/esm/common/index.js +0 -97
- package/dist/esm/compilers/babel/index.js +0 -119
- package/dist/esm/compilers/babel/preset/alias.js +0 -70
- package/dist/esm/compilers/babel/preset/index.js +0 -36
- package/dist/esm/compilers/typescript/index.js +0 -202
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.js +0 -188
- package/dist/esm/compilers/typescript/typescriptLoader.js +0 -30
- package/dist/esm/index.js +0 -5
- package/dist/esm-node/common/index.js +0 -35
- package/dist/esm-node/compilers/babel/index.js +0 -66
- package/dist/esm-node/compilers/babel/preset/alias.js +0 -76
- package/dist/esm-node/compilers/babel/preset/index.js +0 -36
- package/dist/esm-node/compilers/typescript/index.js +0 -93
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.js +0 -170
- package/dist/esm-node/compilers/typescript/typescriptLoader.js +0 -24
- /package/dist/esm/compilers/babel/preset/{types.js → types.mjs} +0 -0
- /package/dist/esm-node/compilers/babel/preset/{types.js → types.mjs} +0 -0
|
@@ -1,204 +1,170 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module1)=>{
|
|
5
|
+
var getter = module1 && module1.__esModule ? ()=>module1['default'] : ()=>module1;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
tsconfigPathsBeforeHookFactory: ()=>tsconfigPathsBeforeHookFactory
|
|
32
37
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const isRegExpKey = (str)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (filePath.startsWith(".") || filePath.startsWith("..")) {
|
|
43
|
-
return import_path.default.resolve(baseUrl, filePath);
|
|
44
|
-
}
|
|
45
|
-
return filePath;
|
|
46
|
-
};
|
|
47
|
-
const createAliasMatcher = (baseUrl, alias) => {
|
|
48
|
-
const aliasPairs = Object.keys(alias).reduce((o, key) => {
|
|
49
|
-
if (isRegExpKey(key)) {
|
|
50
|
-
const regexp = new RegExp(key);
|
|
51
|
-
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
52
|
-
o.push([
|
|
53
|
-
regexp,
|
|
54
|
-
aliasPath
|
|
55
|
-
]);
|
|
56
|
-
} else {
|
|
57
|
-
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
58
|
-
o.push([
|
|
59
|
-
key,
|
|
60
|
-
aliasPath
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
return o;
|
|
64
|
-
}, []);
|
|
65
|
-
const cacheMap = /* @__PURE__ */ new Map();
|
|
66
|
-
return (requestedModule) => {
|
|
67
|
-
if (cacheMap.has(requestedModule)) {
|
|
68
|
-
return cacheMap.get(requestedModule);
|
|
69
|
-
}
|
|
70
|
-
for (const [key, value] of aliasPairs) {
|
|
71
|
-
if (key instanceof RegExp) {
|
|
72
|
-
if (key.test(requestedModule)) {
|
|
73
|
-
cacheMap.set(requestedModule, value);
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (requestedModule === key) {
|
|
78
|
-
cacheMap.set(requestedModule, value);
|
|
79
|
-
return value;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
38
|
+
const external_os_namespaceObject = require("os");
|
|
39
|
+
const external_path_namespaceObject = require("path");
|
|
40
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
41
|
+
const tsconfig_paths_namespaceObject = require("@modern-js/utils/tsconfig-paths");
|
|
42
|
+
const external_typescript_namespaceObject = require("typescript");
|
|
43
|
+
const isRegExpKey = (str)=>str.startsWith('^') || str.endsWith('$');
|
|
44
|
+
const resolveAliasPath = (baseUrl, filePath)=>{
|
|
45
|
+
if (filePath.startsWith('.') || filePath.startsWith('..')) return external_path_default().resolve(baseUrl, filePath);
|
|
46
|
+
return filePath;
|
|
83
47
|
};
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
"main"
|
|
100
|
-
]);
|
|
101
|
-
const matchPath = (requestedModule, readJSONSync, fileExists, extensions) => {
|
|
102
|
-
const result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
103
|
-
if (result) {
|
|
104
|
-
return result;
|
|
105
|
-
}
|
|
106
|
-
return matchAliasPath(requestedModule);
|
|
107
|
-
};
|
|
108
|
-
if (Object.keys(paths).length === 0) {
|
|
109
|
-
return void 0;
|
|
110
|
-
}
|
|
111
|
-
return (ctx) => {
|
|
112
|
-
return (sf) => {
|
|
113
|
-
const visitNode = (node) => {
|
|
114
|
-
if (isDynamicImport(tsBinary, node)) {
|
|
115
|
-
const importPathWithQuotes = node.arguments[0].getText(sf);
|
|
116
|
-
const text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
117
|
-
const result = getNotAliasedPath(sf, matchPath, text);
|
|
118
|
-
if (!result) {
|
|
119
|
-
return node;
|
|
120
|
-
}
|
|
121
|
-
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([
|
|
122
|
-
tsBinary.factory.createStringLiteral(result)
|
|
123
|
-
]));
|
|
48
|
+
const createAliasMatcher = (baseUrl, alias)=>{
|
|
49
|
+
const aliasPairs = Object.keys(alias).reduce((o, key)=>{
|
|
50
|
+
if (isRegExpKey(key)) {
|
|
51
|
+
const regexp = new RegExp(key);
|
|
52
|
+
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
53
|
+
o.push([
|
|
54
|
+
regexp,
|
|
55
|
+
aliasPath
|
|
56
|
+
]);
|
|
57
|
+
} else {
|
|
58
|
+
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
59
|
+
o.push([
|
|
60
|
+
key,
|
|
61
|
+
aliasPath
|
|
62
|
+
]);
|
|
124
63
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
64
|
+
return o;
|
|
65
|
+
}, []);
|
|
66
|
+
const cacheMap = new Map();
|
|
67
|
+
return (requestedModule)=>{
|
|
68
|
+
if (cacheMap.has(requestedModule)) return cacheMap.get(requestedModule);
|
|
69
|
+
for (const [key, value] of aliasPairs){
|
|
70
|
+
if (key instanceof RegExp) {
|
|
71
|
+
if (key.test(requestedModule)) {
|
|
72
|
+
cacheMap.set(requestedModule, value);
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
136
75
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (tsBinary.isImportDeclaration(node)) {
|
|
141
|
-
newNode = tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
142
|
-
} else {
|
|
143
|
-
newNode = tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
76
|
+
if (requestedModule === key) {
|
|
77
|
+
cacheMap.set(requestedModule, value);
|
|
78
|
+
return value;
|
|
144
79
|
}
|
|
145
|
-
newNode.flags = node.flags;
|
|
146
|
-
return newNode;
|
|
147
|
-
} catch {
|
|
148
|
-
return node;
|
|
149
|
-
}
|
|
150
80
|
}
|
|
151
|
-
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
152
|
-
};
|
|
153
|
-
return tsBinary.visitNode(sf, visitNode);
|
|
154
81
|
};
|
|
155
|
-
|
|
82
|
+
};
|
|
83
|
+
const isDynamicImport = (tsBinary, node)=>tsBinary.isCallExpression(node) && node.expression.kind === external_typescript_namespaceObject.SyntaxKind.ImportKeyword;
|
|
84
|
+
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
85
|
+
const tsPaths = {};
|
|
86
|
+
const alias = {};
|
|
87
|
+
Object.keys(paths).forEach((key)=>{
|
|
88
|
+
if (Array.isArray(paths[key])) tsPaths[key] = paths[key];
|
|
89
|
+
else alias[key] = paths[key];
|
|
90
|
+
});
|
|
91
|
+
const matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
92
|
+
const matchTsPath = (0, tsconfig_paths_namespaceObject.createMatchPath)(baseUrl, tsPaths, [
|
|
93
|
+
'main'
|
|
94
|
+
]);
|
|
95
|
+
const matchPath = (requestedModule, readJSONSync, fileExists, extensions)=>{
|
|
96
|
+
const result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
97
|
+
if (result) return result;
|
|
98
|
+
return matchAliasPath(requestedModule);
|
|
99
|
+
};
|
|
100
|
+
if (0 === Object.keys(paths).length) return;
|
|
101
|
+
return (ctx)=>(sf)=>{
|
|
102
|
+
const visitNode = (node)=>{
|
|
103
|
+
if (isDynamicImport(tsBinary, node)) {
|
|
104
|
+
const importPathWithQuotes = node.arguments[0].getText(sf);
|
|
105
|
+
const text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
106
|
+
const result = getNotAliasedPath(sf, matchPath, text);
|
|
107
|
+
if (!result) return node;
|
|
108
|
+
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([
|
|
109
|
+
tsBinary.factory.createStringLiteral(result)
|
|
110
|
+
]));
|
|
111
|
+
}
|
|
112
|
+
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) try {
|
|
113
|
+
const importPathWithQuotes = node?.moduleSpecifier?.getText();
|
|
114
|
+
if (!importPathWithQuotes) return node;
|
|
115
|
+
const text = importPathWithQuotes.substring(1, importPathWithQuotes.length - 1);
|
|
116
|
+
const result = getNotAliasedPath(sf, matchPath, text);
|
|
117
|
+
if (!result) return node;
|
|
118
|
+
const moduleSpecifier = tsBinary.factory.createStringLiteral(result);
|
|
119
|
+
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
120
|
+
let newNode;
|
|
121
|
+
newNode = tsBinary.isImportDeclaration(node) ? tsBinary.factory.updateImportDeclaration(node, node.modifiers, node.importClause, moduleSpecifier, node.assertClause) : tsBinary.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
122
|
+
newNode.flags = node.flags;
|
|
123
|
+
return newNode;
|
|
124
|
+
} catch {
|
|
125
|
+
return node;
|
|
126
|
+
}
|
|
127
|
+
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
128
|
+
};
|
|
129
|
+
return tsBinary.visitNode(sf, visitNode);
|
|
130
|
+
};
|
|
156
131
|
}
|
|
157
132
|
function getNotAliasedPath(sf, matcher, text) {
|
|
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
|
-
try {
|
|
186
|
-
const packagePath = require.resolve(text, {
|
|
187
|
-
paths: [
|
|
188
|
-
process.cwd(),
|
|
189
|
-
...module.paths
|
|
190
|
-
]
|
|
191
|
-
});
|
|
192
|
-
if (packagePath) {
|
|
193
|
-
return text;
|
|
194
|
-
}
|
|
195
|
-
} catch {
|
|
133
|
+
let result = matcher(text, void 0, void 0, [
|
|
134
|
+
'.ts',
|
|
135
|
+
'.tsx',
|
|
136
|
+
'.js',
|
|
137
|
+
'.jsx'
|
|
138
|
+
]);
|
|
139
|
+
if (!result) return;
|
|
140
|
+
if ('win32' === external_os_namespaceObject.platform()) result = result.replace(/\\/g, '/');
|
|
141
|
+
if (!external_path_default().isAbsolute(result)) {
|
|
142
|
+
if (!result.startsWith('.') && !result.startsWith('..')) try {
|
|
143
|
+
const packagePath = require.resolve(result, {
|
|
144
|
+
paths: [
|
|
145
|
+
process.cwd(),
|
|
146
|
+
...module.paths
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
if (packagePath) return result;
|
|
150
|
+
} catch {}
|
|
151
|
+
try {
|
|
152
|
+
const packagePath = require.resolve(text, {
|
|
153
|
+
paths: [
|
|
154
|
+
process.cwd(),
|
|
155
|
+
...module.paths
|
|
156
|
+
]
|
|
157
|
+
});
|
|
158
|
+
if (packagePath) return text;
|
|
159
|
+
} catch {}
|
|
196
160
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return resolvedPath[0] === "." ? resolvedPath : `./${resolvedPath}`;
|
|
161
|
+
const resolvedPath = external_path_namespaceObject.posix.relative((0, external_path_namespaceObject.dirname)(sf.fileName), result) || './';
|
|
162
|
+
return '.' === resolvedPath[0] ? resolvedPath : `./${resolvedPath}`;
|
|
200
163
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
164
|
+
exports.tsconfigPathsBeforeHookFactory = __webpack_exports__.tsconfigPathsBeforeHookFactory;
|
|
165
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
166
|
+
"tsconfigPathsBeforeHookFactory"
|
|
167
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
168
|
+
Object.defineProperty(exports, '__esModule', {
|
|
169
|
+
value: true
|
|
204
170
|
});
|
|
@@ -1,48 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
TypescriptLoader: ()=>TypescriptLoader
|
|
22
28
|
});
|
|
23
|
-
module.exports = __toCommonJS(typescriptLoader_exports);
|
|
24
29
|
class TypescriptLoader {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
load() {
|
|
31
|
+
if (this.tsBinary) return this.tsBinary;
|
|
32
|
+
try {
|
|
33
|
+
const tsPath = require.resolve("typescript", {
|
|
34
|
+
paths: [
|
|
35
|
+
this.appDirectory || process.cwd()
|
|
36
|
+
]
|
|
37
|
+
});
|
|
38
|
+
const ts = require(tsPath);
|
|
39
|
+
return ts;
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
42
|
+
}
|
|
28
43
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
paths: [
|
|
32
|
-
this.appDirectory || process.cwd()
|
|
33
|
-
]
|
|
34
|
-
});
|
|
35
|
-
const ts = require(tsPath);
|
|
36
|
-
return ts;
|
|
37
|
-
} catch (error) {
|
|
38
|
-
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
44
|
+
constructor({ appDirectory }){
|
|
45
|
+
this.appDirectory = appDirectory;
|
|
39
46
|
}
|
|
40
|
-
}
|
|
41
|
-
constructor({ appDirectory }) {
|
|
42
|
-
this.appDirectory = appDirectory;
|
|
43
|
-
}
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
exports.TypescriptLoader = __webpack_exports__.TypescriptLoader;
|
|
49
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
50
|
+
"TypescriptLoader"
|
|
51
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
52
|
+
Object.defineProperty(exports, '__esModule', {
|
|
53
|
+
value: true
|
|
48
54
|
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,31 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./common" (module) {
|
|
4
|
+
module.exports = require("./common/index.js");
|
|
5
|
+
},
|
|
6
|
+
"./compilers/babel" (module) {
|
|
7
|
+
module.exports = require("./compilers/babel/index.js");
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
10
|
+
var __webpack_module_cache__ = {};
|
|
11
|
+
function __webpack_require__(moduleId) {
|
|
12
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
13
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
14
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
15
|
+
exports: {}
|
|
16
|
+
};
|
|
17
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
18
|
+
return module.exports;
|
|
19
|
+
}
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.n = (module)=>{
|
|
22
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
23
|
+
__webpack_require__.d(getter, {
|
|
24
|
+
a: getter
|
|
25
|
+
});
|
|
26
|
+
return getter;
|
|
27
|
+
};
|
|
28
|
+
})();
|
|
29
|
+
(()=>{
|
|
30
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
31
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: definition[key]
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
39
|
+
})();
|
|
40
|
+
(()=>{
|
|
41
|
+
__webpack_require__.r = (exports1)=>{
|
|
42
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
43
|
+
value: 'Module'
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
46
|
+
value: true
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
})();
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
(()=>{
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
54
|
+
compile: ()=>_common__rspack_import_1.compile
|
|
55
|
+
});
|
|
56
|
+
var _compilers_babel__rspack_import_0 = __webpack_require__("./compilers/babel");
|
|
57
|
+
var __rspack_reexport = {};
|
|
58
|
+
for(const __rspack_import_key in _compilers_babel__rspack_import_0)if ([
|
|
59
|
+
"compile",
|
|
60
|
+
"default"
|
|
61
|
+
].indexOf(__rspack_import_key) < 0) __rspack_reexport[__rspack_import_key] = ()=>_compilers_babel__rspack_import_0[__rspack_import_key];
|
|
62
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
63
|
+
var _common__rspack_import_1 = __webpack_require__("./common");
|
|
64
|
+
})();
|
|
65
|
+
exports.compile = __webpack_exports__.compile;
|
|
66
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
67
|
+
"compile"
|
|
68
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
69
|
+
Object.defineProperty(exports, '__esModule', {
|
|
70
|
+
value: true
|
|
31
71
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { isAbsolute } from "path";
|
|
2
|
+
import { fs } from "@modern-js/utils";
|
|
3
|
+
const FILE_EXTENSIONS = [
|
|
4
|
+
'.js',
|
|
5
|
+
'.ts',
|
|
6
|
+
'.mjs',
|
|
7
|
+
'.ejs'
|
|
8
|
+
];
|
|
9
|
+
const validateAbsolutePath = (filename, message)=>{
|
|
10
|
+
if (!isAbsolute(filename)) throw new Error(message);
|
|
11
|
+
};
|
|
12
|
+
const validateAbsolutePaths = (filenames, messageFunc)=>{
|
|
13
|
+
filenames.forEach((filename)=>validateAbsolutePath(filename, messageFunc(filename)));
|
|
14
|
+
};
|
|
15
|
+
const compile = async (appDirectory, modernConfig, compileOptions)=>{
|
|
16
|
+
const { sourceDirs, distDir, tsconfigPath } = compileOptions;
|
|
17
|
+
validateAbsolutePaths(sourceDirs, (dir)=>`source dir ${dir} is not an absolute path.`);
|
|
18
|
+
validateAbsolutePath(distDir, `dist dir ${distDir} is not an absolute path.`);
|
|
19
|
+
const compiler = modernConfig?.server?.compiler;
|
|
20
|
+
const isTsProject = tsconfigPath && await fs.pathExists(tsconfigPath);
|
|
21
|
+
if (isTsProject && 'babel' !== compiler) {
|
|
22
|
+
const { compileByTs } = await import("../compilers/typescript");
|
|
23
|
+
await compileByTs(appDirectory, modernConfig, compileOptions);
|
|
24
|
+
} else {
|
|
25
|
+
const { compileByBabel } = await import("../compilers/babel");
|
|
26
|
+
await compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export { FILE_EXTENSIONS, compile };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { basename as external_path_basename, extname, join } from "path";
|
|
2
|
+
import { compiler } from "@modern-js/babel-compiler";
|
|
3
|
+
import { fs, getAliasConfig, json5 } from "@modern-js/utils";
|
|
4
|
+
import { FILE_EXTENSIONS } from "../../common";
|
|
5
|
+
import { applyUserBabelConfig, getBabelConfig } from "./preset";
|
|
6
|
+
export * from "@babel/core";
|
|
7
|
+
const readTsConfig = (tsconfigPath, noExistReturn = null)=>{
|
|
8
|
+
if (!fs.existsSync(tsconfigPath)) return noExistReturn;
|
|
9
|
+
const content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
10
|
+
return json5.parse(content);
|
|
11
|
+
};
|
|
12
|
+
const existTsConfigFile = (tsconfigAbsolutePath)=>{
|
|
13
|
+
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
14
|
+
return Boolean(tsconfig);
|
|
15
|
+
};
|
|
16
|
+
const resolveBabelConfig = (appDirectory, config, option, isEsm)=>{
|
|
17
|
+
const { alias, babelConfig } = config;
|
|
18
|
+
const aliasConfig = getAliasConfig(alias, {
|
|
19
|
+
appDirectory,
|
|
20
|
+
...option
|
|
21
|
+
});
|
|
22
|
+
const defaultBabelConfig = getBabelConfig({
|
|
23
|
+
appDirectory,
|
|
24
|
+
alias: aliasConfig,
|
|
25
|
+
isEsm
|
|
26
|
+
});
|
|
27
|
+
return applyUserBabelConfig(defaultBabelConfig, babelConfig);
|
|
28
|
+
};
|
|
29
|
+
const compileByBabel = async (appDirectory, config, compileOptions)=>{
|
|
30
|
+
const { sourceDirs, distDir, tsconfigPath, moduleType } = compileOptions;
|
|
31
|
+
const isEsm = 'module' === moduleType;
|
|
32
|
+
const results = await Promise.all(sourceDirs.map(async (sourceDir)=>{
|
|
33
|
+
const babelConfig = resolveBabelConfig(appDirectory, config, {
|
|
34
|
+
tsconfigPath: tsconfigPath ? tsconfigPath : ''
|
|
35
|
+
}, isEsm);
|
|
36
|
+
if (await fs.pathExists(sourceDir)) {
|
|
37
|
+
const basename = external_path_basename(sourceDir);
|
|
38
|
+
const targetDir = join(distDir, basename);
|
|
39
|
+
await fs.copy(sourceDir, targetDir, {
|
|
40
|
+
filter: (src)=>![
|
|
41
|
+
'.ts',
|
|
42
|
+
'.js'
|
|
43
|
+
].includes(extname(src)) && src !== tsconfigPath
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return compiler({
|
|
47
|
+
rootDir: appDirectory,
|
|
48
|
+
distDir,
|
|
49
|
+
sourceDir,
|
|
50
|
+
extensions: FILE_EXTENSIONS
|
|
51
|
+
}, babelConfig);
|
|
52
|
+
}));
|
|
53
|
+
results.forEach((result)=>{
|
|
54
|
+
if (1 === result.code) throw new Error(result.message);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
export { compileByBabel, existTsConfigFile, readTsConfig, resolveBabelConfig };
|