@bleedingdev/modern-js-server-utils 3.2.0-ultramodern.98 → 3.4.0-ultramodern.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 +9 -5
- package/dist/cjs/compilers/typescript/importRewriter.js +242 -0
- package/dist/cjs/compilers/typescript/index.js +106 -39
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +9 -5
- package/dist/cjs/index.js +9 -5
- package/dist/esm/compilers/typescript/importRewriter.mjs +204 -0
- package/dist/esm/compilers/typescript/index.mjs +87 -33
- package/dist/esm-node/compilers/typescript/importRewriter.mjs +205 -0
- package/dist/esm-node/compilers/typescript/index.mjs +90 -33
- package/dist/types/compilers/typescript/importRewriter.d.ts +12 -0
- package/dist/types/compilers/typescript/index.d.ts +19 -0
- package/dist/types/compilers/typescript/tsconfigPathsPlugin.d.ts +1 -1
- package/package.json +15 -7
package/dist/cjs/common/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
const IDENTIFIER_CHAR = /[A-Za-z0-9_$]/;
|
|
31
|
+
const WHITESPACE = /\s/;
|
|
32
|
+
const KEYWORDS_BEFORE_REGEX = new Set([
|
|
33
|
+
'return',
|
|
34
|
+
'typeof',
|
|
35
|
+
'instanceof',
|
|
36
|
+
'in',
|
|
37
|
+
'of',
|
|
38
|
+
'new',
|
|
39
|
+
'delete',
|
|
40
|
+
'void',
|
|
41
|
+
'throw',
|
|
42
|
+
'case',
|
|
43
|
+
'do',
|
|
44
|
+
'else',
|
|
45
|
+
'yield',
|
|
46
|
+
'await'
|
|
47
|
+
]);
|
|
48
|
+
const PUNCTUATORS_BEFORE_REGEX = new Set('{}(,;[=:?!&|+-*%^~<>/');
|
|
49
|
+
const isRegexAllowed = (lastToken)=>{
|
|
50
|
+
if (!lastToken) return true;
|
|
51
|
+
if (KEYWORDS_BEFORE_REGEX.has(lastToken)) return true;
|
|
52
|
+
return 1 === lastToken.length && PUNCTUATORS_BEFORE_REGEX.has(lastToken);
|
|
53
|
+
};
|
|
54
|
+
const isSpecifierContext = (prev1, prev2, prev3)=>{
|
|
55
|
+
if (('from' === prev1 || 'import' === prev1) && '.' !== prev2) return true;
|
|
56
|
+
return '(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
57
|
+
};
|
|
58
|
+
const skipRegexLiteral = (content, start)=>{
|
|
59
|
+
let i = start + 1;
|
|
60
|
+
let inClass = false;
|
|
61
|
+
while(i < content.length){
|
|
62
|
+
const ch = content[i];
|
|
63
|
+
if ('\\' === ch) {
|
|
64
|
+
i += 2;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if ('\n' === ch) break;
|
|
68
|
+
if ('[' === ch) inClass = true;
|
|
69
|
+
else if (']' === ch) inClass = false;
|
|
70
|
+
else if ('/' === ch && !inClass) {
|
|
71
|
+
i++;
|
|
72
|
+
while(i < content.length && IDENTIFIER_CHAR.test(content[i]))i++;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
i++;
|
|
76
|
+
}
|
|
77
|
+
return i;
|
|
78
|
+
};
|
|
79
|
+
const scanSpecifiers = (content)=>{
|
|
80
|
+
const specifiers = [];
|
|
81
|
+
const length = content.length;
|
|
82
|
+
const templateExpressionDepths = [];
|
|
83
|
+
let prev1 = '';
|
|
84
|
+
let prev2 = '';
|
|
85
|
+
let prev3 = '';
|
|
86
|
+
const pushToken = (token)=>{
|
|
87
|
+
prev3 = prev2;
|
|
88
|
+
prev2 = prev1;
|
|
89
|
+
prev1 = token;
|
|
90
|
+
};
|
|
91
|
+
let mode = 'code';
|
|
92
|
+
let i = 0;
|
|
93
|
+
while(i < length){
|
|
94
|
+
const ch = content[i];
|
|
95
|
+
if ('template' === mode) {
|
|
96
|
+
if ('\\' === ch) {
|
|
97
|
+
i += 2;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
if ('`' === ch) {
|
|
101
|
+
mode = 'code';
|
|
102
|
+
pushToken('`');
|
|
103
|
+
i++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if ('$' === ch && '{' === content[i + 1]) {
|
|
107
|
+
templateExpressionDepths.push(0);
|
|
108
|
+
mode = 'code';
|
|
109
|
+
pushToken('{');
|
|
110
|
+
i += 2;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
i++;
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (WHITESPACE.test(ch)) {
|
|
117
|
+
i++;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if ('/' === ch) {
|
|
121
|
+
const next = content[i + 1];
|
|
122
|
+
if ('/' === next) {
|
|
123
|
+
const newline = content.indexOf('\n', i + 2);
|
|
124
|
+
i = -1 === newline ? length : newline + 1;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if ('*' === next) {
|
|
128
|
+
const end = content.indexOf('*/', i + 2);
|
|
129
|
+
i = -1 === end ? length : end + 2;
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (isRegexAllowed(prev1)) {
|
|
133
|
+
i = skipRegexLiteral(content, i);
|
|
134
|
+
pushToken('/regex/');
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
pushToken('/');
|
|
138
|
+
i++;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if ('`' === ch) {
|
|
142
|
+
mode = 'template';
|
|
143
|
+
i++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if ('{' === ch) {
|
|
147
|
+
if (templateExpressionDepths.length > 0) templateExpressionDepths[templateExpressionDepths.length - 1]++;
|
|
148
|
+
pushToken('{');
|
|
149
|
+
i++;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if ('}' === ch) {
|
|
153
|
+
if (templateExpressionDepths.length > 0) {
|
|
154
|
+
const top = templateExpressionDepths.length - 1;
|
|
155
|
+
if (0 === templateExpressionDepths[top]) {
|
|
156
|
+
templateExpressionDepths.pop();
|
|
157
|
+
mode = 'template';
|
|
158
|
+
i++;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
templateExpressionDepths[top]--;
|
|
162
|
+
}
|
|
163
|
+
pushToken('}');
|
|
164
|
+
i++;
|
|
165
|
+
continue;
|
|
166
|
+
}
|
|
167
|
+
if ('"' === ch || "'" === ch) {
|
|
168
|
+
const start = i;
|
|
169
|
+
let j = i + 1;
|
|
170
|
+
let terminated = false;
|
|
171
|
+
while(j < length){
|
|
172
|
+
const sch = content[j];
|
|
173
|
+
if ('\\' === sch) {
|
|
174
|
+
j += 2;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (sch === ch) {
|
|
178
|
+
terminated = true;
|
|
179
|
+
j++;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
if ('\n' === sch) break;
|
|
183
|
+
j++;
|
|
184
|
+
}
|
|
185
|
+
if (terminated && isSpecifierContext(prev1, prev2, prev3)) specifiers.push({
|
|
186
|
+
start: start + 1,
|
|
187
|
+
end: j - 1,
|
|
188
|
+
value: content.slice(start + 1, j - 1)
|
|
189
|
+
});
|
|
190
|
+
pushToken('"string"');
|
|
191
|
+
i = j;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (IDENTIFIER_CHAR.test(ch)) {
|
|
195
|
+
let j = i + 1;
|
|
196
|
+
while(j < length && IDENTIFIER_CHAR.test(content[j]))j++;
|
|
197
|
+
pushToken(content.slice(i, j));
|
|
198
|
+
i = j;
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
pushToken(ch);
|
|
202
|
+
i++;
|
|
203
|
+
}
|
|
204
|
+
return specifiers;
|
|
205
|
+
};
|
|
206
|
+
const rewriteImportSpecifiers = (content, rewrite)=>{
|
|
207
|
+
const specifiers = scanSpecifiers(content);
|
|
208
|
+
if (0 === specifiers.length) return {
|
|
209
|
+
content,
|
|
210
|
+
changed: false
|
|
211
|
+
};
|
|
212
|
+
let result = '';
|
|
213
|
+
let cursor = 0;
|
|
214
|
+
let changed = false;
|
|
215
|
+
for (const specifier of specifiers){
|
|
216
|
+
if (specifier.value.includes('\\')) continue;
|
|
217
|
+
const next = rewrite(specifier.value);
|
|
218
|
+
if (void 0 !== next && next !== specifier.value) {
|
|
219
|
+
changed = true;
|
|
220
|
+
result += content.slice(cursor, specifier.start) + next;
|
|
221
|
+
cursor = specifier.end;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (!changed) return {
|
|
225
|
+
content,
|
|
226
|
+
changed: false
|
|
227
|
+
};
|
|
228
|
+
return {
|
|
229
|
+
content: result + content.slice(cursor),
|
|
230
|
+
changed: true
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
234
|
+
rewriteImportSpecifiers: rewriteImportSpecifiers
|
|
235
|
+
});
|
|
236
|
+
exports.rewriteImportSpecifiers = __webpack_exports__.rewriteImportSpecifiers;
|
|
237
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
238
|
+
"rewriteImportSpecifiers"
|
|
239
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
240
|
+
Object.defineProperty(exports, '__esModule', {
|
|
241
|
+
value: true
|
|
242
|
+
});
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -33,14 +37,17 @@ var __webpack_require__ = {};
|
|
|
33
37
|
var __webpack_exports__ = {};
|
|
34
38
|
__webpack_require__.r(__webpack_exports__);
|
|
35
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
-
compileByTs: ()=>compileByTs
|
|
40
|
+
compileByTs: ()=>compileByTs,
|
|
41
|
+
createResolvedTsgoConfig: ()=>createResolvedTsgoConfig,
|
|
42
|
+
getTsgoBinPath: ()=>getTsgoBinPath,
|
|
43
|
+
rewriteOutputSpecifiers: ()=>rewriteOutputSpecifiers
|
|
37
44
|
});
|
|
38
45
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
39
46
|
const external_child_process_namespaceObject = require("child_process");
|
|
40
47
|
const external_path_namespaceObject = require("path");
|
|
41
48
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
49
|
+
const external_importRewriter_js_namespaceObject = require("./importRewriter.js");
|
|
42
50
|
const external_tsconfigPathsPlugin_js_namespaceObject = require("./tsconfigPathsPlugin.js");
|
|
43
|
-
const importSpecifierRE = /((?:from\s*|import\s*\(\s*|require\s*\(\s*)['"])([^'"]+)(['"])/g;
|
|
44
51
|
const copyFiles = async (from, to, appDirectory)=>{
|
|
45
52
|
if (await utils_namespaceObject.fs.pathExists(from)) {
|
|
46
53
|
const relativePath = external_path_default().relative(appDirectory, from);
|
|
@@ -53,42 +60,55 @@ const copyFiles = async (from, to, appDirectory)=>{
|
|
|
53
60
|
});
|
|
54
61
|
}
|
|
55
62
|
};
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
let resolvedConfigCount = 0;
|
|
64
|
+
const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sourceDirs, moduleType, tsgoBinPath)=>{
|
|
65
|
+
const tsconfigDir = external_path_default().dirname(tsconfigPath);
|
|
66
|
+
const output = await runTsgo(tsgoBinPath, [
|
|
58
67
|
'--showConfig',
|
|
59
68
|
'-p',
|
|
60
69
|
tsconfigPath
|
|
61
70
|
], {
|
|
62
|
-
cwd:
|
|
71
|
+
cwd: tsconfigDir
|
|
63
72
|
});
|
|
64
73
|
const config = JSON.parse(output.stdout);
|
|
65
74
|
config.compilerOptions ??= {};
|
|
66
75
|
config.compilerOptions.rootDir = appDirectory;
|
|
67
76
|
config.compilerOptions.outDir = distDir;
|
|
68
|
-
config.files = filterSourceFiles(
|
|
77
|
+
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
69
78
|
delete config.include;
|
|
70
79
|
delete config.compilerOptions.baseUrl;
|
|
71
80
|
if ([
|
|
72
81
|
'node',
|
|
73
82
|
'node10'
|
|
74
83
|
].includes(String(config.compilerOptions.moduleResolution).toLowerCase())) delete config.compilerOptions.moduleResolution;
|
|
75
|
-
|
|
84
|
+
if ('module' !== moduleType && [
|
|
85
|
+
'preserve',
|
|
86
|
+
'esnext',
|
|
87
|
+
'es2015',
|
|
88
|
+
'es2020',
|
|
89
|
+
'es2022',
|
|
90
|
+
'es6'
|
|
91
|
+
].includes(String(config.compilerOptions.module).toLowerCase())) {
|
|
92
|
+
config.compilerOptions.module = 'commonjs';
|
|
93
|
+
delete config.compilerOptions.moduleResolution;
|
|
94
|
+
}
|
|
95
|
+
const resolvedConfigPath = external_path_default().join(tsconfigDir, `.tsgo.${process.pid}.${resolvedConfigCount++}.resolved.json`);
|
|
76
96
|
await utils_namespaceObject.fs.writeFile(resolvedConfigPath, JSON.stringify(config, null, 2));
|
|
77
97
|
return {
|
|
78
98
|
config,
|
|
79
99
|
resolvedConfigPath
|
|
80
100
|
};
|
|
81
101
|
};
|
|
82
|
-
const filterSourceFiles = (
|
|
102
|
+
const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
|
|
83
103
|
const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(external_path_default().sep).join(external_path_default().posix.sep));
|
|
84
104
|
return files.filter((fileName)=>{
|
|
85
|
-
const absoluteFileName = external_path_default().resolve(
|
|
105
|
+
const absoluteFileName = external_path_default().resolve(tsconfigDir, fileName).split(external_path_default().sep).join(external_path_default().posix.sep);
|
|
86
106
|
return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
|
|
87
107
|
});
|
|
88
108
|
};
|
|
89
|
-
const runTsgo = (args, options)=>new Promise((resolve, reject)=>{
|
|
109
|
+
const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
90
110
|
const child = (0, external_child_process_namespaceObject.spawn)(process.execPath, [
|
|
91
|
-
|
|
111
|
+
tsgoBinPath,
|
|
92
112
|
...args
|
|
93
113
|
], {
|
|
94
114
|
cwd: options.cwd,
|
|
@@ -117,14 +137,51 @@ const runTsgo = (args, options)=>new Promise((resolve, reject)=>{
|
|
|
117
137
|
resolve(result);
|
|
118
138
|
});
|
|
119
139
|
});
|
|
120
|
-
const getTsgoBinPath = (
|
|
140
|
+
const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
141
|
+
appDirectory,
|
|
142
|
+
__dirname
|
|
143
|
+
])=>{
|
|
144
|
+
try {
|
|
145
|
+
const pkgPath = require.resolve("@typescript/native-preview/package.json", {
|
|
146
|
+
paths: resolvePaths
|
|
147
|
+
});
|
|
148
|
+
return external_path_default().join(external_path_default().dirname(pkgPath), 'bin/tsgo.js');
|
|
149
|
+
} catch {
|
|
150
|
+
throw new Error('tsgo could not be found! Please install "@typescript/native-preview" in your project to compile BFF/server code.');
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const OUTPUT_SOURCE_EXTENSIONS = {
|
|
154
|
+
'.js': [
|
|
155
|
+
'.ts',
|
|
156
|
+
'.tsx',
|
|
157
|
+
'.js',
|
|
158
|
+
'.jsx'
|
|
159
|
+
],
|
|
160
|
+
'.mjs': [
|
|
161
|
+
'.mts',
|
|
162
|
+
'.mjs'
|
|
163
|
+
],
|
|
164
|
+
'.cjs': [
|
|
165
|
+
'.cts',
|
|
166
|
+
'.cjs'
|
|
167
|
+
]
|
|
168
|
+
};
|
|
121
169
|
const getSourceFileForOutput = (appDirectory, distDir, outputFile)=>{
|
|
122
170
|
const relativeOutput = external_path_default().relative(distDir, outputFile);
|
|
123
171
|
const parsed = external_path_default().parse(relativeOutput);
|
|
124
172
|
const sourceBase = external_path_default().join(appDirectory, parsed.dir, parsed.name);
|
|
125
|
-
|
|
173
|
+
const extensions = OUTPUT_SOURCE_EXTENSIONS[parsed.ext] ?? OUTPUT_SOURCE_EXTENSIONS['.js'];
|
|
174
|
+
for (const extension of extensions){
|
|
175
|
+
const candidate = `${sourceBase}${extension}`;
|
|
176
|
+
if (utils_namespaceObject.fs.existsSync(candidate)) return candidate;
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const sourceMappingUrlRE = /^\/\/[#@] sourceMappingURL=.*$/gm;
|
|
180
|
+
const dropStaleSourceMap = async (outputFile, content)=>{
|
|
181
|
+
const mapFile = `${outputFile}.map`;
|
|
182
|
+
if (await utils_namespaceObject.fs.pathExists(mapFile)) await utils_namespaceObject.fs.remove(mapFile);
|
|
183
|
+
return content.replace(sourceMappingUrlRE, '');
|
|
126
184
|
};
|
|
127
|
-
const findExistingSource = (filePath)=>utils_namespaceObject.fs.existsSync(filePath) ? filePath : void 0;
|
|
128
185
|
const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
|
|
129
186
|
if (0 === Object.keys(paths).length || !await utils_namespaceObject.fs.pathExists(distDir)) return;
|
|
130
187
|
const matcher = (0, external_tsconfigPathsPlugin_js_namespaceObject.createTsconfigPathsMatcher)(baseUrl, paths);
|
|
@@ -134,14 +191,8 @@ const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, mo
|
|
|
134
191
|
const sourceFile = getSourceFileForOutput(appDirectory, distDir, file);
|
|
135
192
|
if (!sourceFile) return;
|
|
136
193
|
const content = await utils_namespaceObject.fs.readFile(file, 'utf8');
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const nextSpecifier = (0, external_tsconfigPathsPlugin_js_namespaceObject.getNotAliasedPath)(sourceFile, matcher, specifier, moduleType);
|
|
140
|
-
if (!nextSpecifier || nextSpecifier === specifier) return match;
|
|
141
|
-
changed = true;
|
|
142
|
-
return `${prefix}${nextSpecifier}${suffix}`;
|
|
143
|
-
});
|
|
144
|
-
if (changed) await utils_namespaceObject.fs.writeFile(file, rewritten);
|
|
194
|
+
const { content: rewritten, changed } = (0, external_importRewriter_js_namespaceObject.rewriteImportSpecifiers)(content, (specifier)=>(0, external_tsconfigPathsPlugin_js_namespaceObject.getNotAliasedPath)(sourceFile, matcher, specifier, moduleType));
|
|
195
|
+
if (changed) await utils_namespaceObject.fs.writeFile(file, await dropStaleSourceMap(file, rewritten));
|
|
145
196
|
}));
|
|
146
197
|
};
|
|
147
198
|
const collectOutputFiles = async (dir)=>{
|
|
@@ -167,29 +218,45 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
167
218
|
tsconfigPath
|
|
168
219
|
});
|
|
169
220
|
const { paths = {}, absoluteBaseUrl = './' } = aliasOption;
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
221
|
+
const tsgoBinPath = getTsgoBinPath(appDirectory);
|
|
222
|
+
const { config: tsgoConfig, resolvedConfigPath } = await createResolvedTsgoConfig(appDirectory, tsconfigPath, distDir, sourceDirs, compileOptions.moduleType, tsgoBinPath);
|
|
223
|
+
let result;
|
|
224
|
+
try {
|
|
225
|
+
result = await runTsgo(tsgoBinPath, [
|
|
226
|
+
'-p',
|
|
227
|
+
resolvedConfigPath
|
|
228
|
+
], {
|
|
229
|
+
cwd: appDirectory,
|
|
230
|
+
reject: false
|
|
231
|
+
});
|
|
232
|
+
} finally{
|
|
233
|
+
await utils_namespaceObject.fs.remove(resolvedConfigPath);
|
|
234
|
+
}
|
|
179
235
|
if (result.stderr) utils_namespaceObject.logger.error(result.stderr);
|
|
180
236
|
if (result.stdout) utils_namespaceObject.logger.info(result.stdout);
|
|
181
237
|
if (0 !== result.code) {
|
|
182
238
|
const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
|
|
183
|
-
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit)
|
|
184
|
-
|
|
239
|
+
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
|
|
240
|
+
utils_namespaceObject.logger.error('TS-Go compilation failed');
|
|
241
|
+
throw new Error([
|
|
242
|
+
`TS-Go compilation failed with exit code ${result.code}.`,
|
|
243
|
+
result.stderr.trim() || result.stdout.trim()
|
|
244
|
+
].filter(Boolean).join('\n'));
|
|
245
|
+
} else process.exit(1);
|
|
185
246
|
}
|
|
186
247
|
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
187
248
|
for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
|
|
188
249
|
utils_namespaceObject.logger.info("TS-Go compile succeed");
|
|
189
250
|
};
|
|
190
251
|
exports.compileByTs = __webpack_exports__.compileByTs;
|
|
252
|
+
exports.createResolvedTsgoConfig = __webpack_exports__.createResolvedTsgoConfig;
|
|
253
|
+
exports.getTsgoBinPath = __webpack_exports__.getTsgoBinPath;
|
|
254
|
+
exports.rewriteOutputSpecifiers = __webpack_exports__.rewriteOutputSpecifiers;
|
|
191
255
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
192
|
-
"compileByTs"
|
|
256
|
+
"compileByTs",
|
|
257
|
+
"createResolvedTsgoConfig",
|
|
258
|
+
"getTsgoBinPath",
|
|
259
|
+
"rewriteOutputSpecifiers"
|
|
193
260
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
194
261
|
Object.defineProperty(exports, '__esModule', {
|
|
195
262
|
value: true
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|