@bleedingdev/modern-js-server-utils 3.2.0-ultramodern.99 → 3.4.0-ultramodern.1
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 +109 -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 +90 -33
- package/dist/esm-node/compilers/typescript/importRewriter.mjs +205 -0
- package/dist/esm-node/compilers/typescript/index.mjs +93 -33
- package/dist/types/compilers/typescript/importRewriter.d.ts +12 -0
- package/dist/types/compilers/typescript/index.d.ts +20 -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,58 @@ 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
|
+
if ([
|
|
86
|
+
'preserve',
|
|
87
|
+
'esnext',
|
|
88
|
+
'es2015',
|
|
89
|
+
'es2020',
|
|
90
|
+
'es2022',
|
|
91
|
+
'es6'
|
|
92
|
+
].includes(String(config.compilerOptions.module).toLowerCase())) {
|
|
93
|
+
config.compilerOptions.module = 'commonjs';
|
|
94
|
+
delete config.compilerOptions.moduleResolution;
|
|
95
|
+
}
|
|
96
|
+
config.compilerOptions.verbatimModuleSyntax = false;
|
|
97
|
+
}
|
|
98
|
+
const resolvedConfigPath = external_path_default().join(tsconfigDir, `.tsgo.${process.pid}.${resolvedConfigCount++}.resolved.json`);
|
|
76
99
|
await utils_namespaceObject.fs.writeFile(resolvedConfigPath, JSON.stringify(config, null, 2));
|
|
77
100
|
return {
|
|
78
101
|
config,
|
|
79
102
|
resolvedConfigPath
|
|
80
103
|
};
|
|
81
104
|
};
|
|
82
|
-
const filterSourceFiles = (
|
|
105
|
+
const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
|
|
83
106
|
const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(external_path_default().sep).join(external_path_default().posix.sep));
|
|
84
107
|
return files.filter((fileName)=>{
|
|
85
|
-
const absoluteFileName = external_path_default().resolve(
|
|
108
|
+
const absoluteFileName = external_path_default().resolve(tsconfigDir, fileName).split(external_path_default().sep).join(external_path_default().posix.sep);
|
|
86
109
|
return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
|
|
87
110
|
});
|
|
88
111
|
};
|
|
89
|
-
const runTsgo = (args, options)=>new Promise((resolve, reject)=>{
|
|
112
|
+
const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
90
113
|
const child = (0, external_child_process_namespaceObject.spawn)(process.execPath, [
|
|
91
|
-
|
|
114
|
+
tsgoBinPath,
|
|
92
115
|
...args
|
|
93
116
|
], {
|
|
94
117
|
cwd: options.cwd,
|
|
@@ -117,14 +140,51 @@ const runTsgo = (args, options)=>new Promise((resolve, reject)=>{
|
|
|
117
140
|
resolve(result);
|
|
118
141
|
});
|
|
119
142
|
});
|
|
120
|
-
const getTsgoBinPath = (
|
|
143
|
+
const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
144
|
+
appDirectory,
|
|
145
|
+
__dirname
|
|
146
|
+
])=>{
|
|
147
|
+
try {
|
|
148
|
+
const pkgPath = require.resolve("@typescript/native-preview/package.json", {
|
|
149
|
+
paths: resolvePaths
|
|
150
|
+
});
|
|
151
|
+
return external_path_default().join(external_path_default().dirname(pkgPath), 'bin/tsgo.js');
|
|
152
|
+
} catch {
|
|
153
|
+
throw new Error('tsgo could not be found! Please install "@typescript/native-preview" in your project to compile BFF/server code.');
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const OUTPUT_SOURCE_EXTENSIONS = {
|
|
157
|
+
'.js': [
|
|
158
|
+
'.ts',
|
|
159
|
+
'.tsx',
|
|
160
|
+
'.js',
|
|
161
|
+
'.jsx'
|
|
162
|
+
],
|
|
163
|
+
'.mjs': [
|
|
164
|
+
'.mts',
|
|
165
|
+
'.mjs'
|
|
166
|
+
],
|
|
167
|
+
'.cjs': [
|
|
168
|
+
'.cts',
|
|
169
|
+
'.cjs'
|
|
170
|
+
]
|
|
171
|
+
};
|
|
121
172
|
const getSourceFileForOutput = (appDirectory, distDir, outputFile)=>{
|
|
122
173
|
const relativeOutput = external_path_default().relative(distDir, outputFile);
|
|
123
174
|
const parsed = external_path_default().parse(relativeOutput);
|
|
124
175
|
const sourceBase = external_path_default().join(appDirectory, parsed.dir, parsed.name);
|
|
125
|
-
|
|
176
|
+
const extensions = OUTPUT_SOURCE_EXTENSIONS[parsed.ext] ?? OUTPUT_SOURCE_EXTENSIONS['.js'];
|
|
177
|
+
for (const extension of extensions){
|
|
178
|
+
const candidate = `${sourceBase}${extension}`;
|
|
179
|
+
if (utils_namespaceObject.fs.existsSync(candidate)) return candidate;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const sourceMappingUrlRE = /^\/\/[#@] sourceMappingURL=.*$/gm;
|
|
183
|
+
const dropStaleSourceMap = async (outputFile, content)=>{
|
|
184
|
+
const mapFile = `${outputFile}.map`;
|
|
185
|
+
if (await utils_namespaceObject.fs.pathExists(mapFile)) await utils_namespaceObject.fs.remove(mapFile);
|
|
186
|
+
return content.replace(sourceMappingUrlRE, '');
|
|
126
187
|
};
|
|
127
|
-
const findExistingSource = (filePath)=>utils_namespaceObject.fs.existsSync(filePath) ? filePath : void 0;
|
|
128
188
|
const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
|
|
129
189
|
if (0 === Object.keys(paths).length || !await utils_namespaceObject.fs.pathExists(distDir)) return;
|
|
130
190
|
const matcher = (0, external_tsconfigPathsPlugin_js_namespaceObject.createTsconfigPathsMatcher)(baseUrl, paths);
|
|
@@ -134,14 +194,8 @@ const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, mo
|
|
|
134
194
|
const sourceFile = getSourceFileForOutput(appDirectory, distDir, file);
|
|
135
195
|
if (!sourceFile) return;
|
|
136
196
|
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);
|
|
197
|
+
const { content: rewritten, changed } = (0, external_importRewriter_js_namespaceObject.rewriteImportSpecifiers)(content, (specifier)=>(0, external_tsconfigPathsPlugin_js_namespaceObject.getNotAliasedPath)(sourceFile, matcher, specifier, moduleType));
|
|
198
|
+
if (changed) await utils_namespaceObject.fs.writeFile(file, await dropStaleSourceMap(file, rewritten));
|
|
145
199
|
}));
|
|
146
200
|
};
|
|
147
201
|
const collectOutputFiles = async (dir)=>{
|
|
@@ -167,29 +221,45 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
167
221
|
tsconfigPath
|
|
168
222
|
});
|
|
169
223
|
const { paths = {}, absoluteBaseUrl = './' } = aliasOption;
|
|
170
|
-
const
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
224
|
+
const tsgoBinPath = getTsgoBinPath(appDirectory);
|
|
225
|
+
const { config: tsgoConfig, resolvedConfigPath } = await createResolvedTsgoConfig(appDirectory, tsconfigPath, distDir, sourceDirs, compileOptions.moduleType, tsgoBinPath);
|
|
226
|
+
let result;
|
|
227
|
+
try {
|
|
228
|
+
result = await runTsgo(tsgoBinPath, [
|
|
229
|
+
'-p',
|
|
230
|
+
resolvedConfigPath
|
|
231
|
+
], {
|
|
232
|
+
cwd: appDirectory,
|
|
233
|
+
reject: false
|
|
234
|
+
});
|
|
235
|
+
} finally{
|
|
236
|
+
await utils_namespaceObject.fs.remove(resolvedConfigPath);
|
|
237
|
+
}
|
|
179
238
|
if (result.stderr) utils_namespaceObject.logger.error(result.stderr);
|
|
180
239
|
if (result.stdout) utils_namespaceObject.logger.info(result.stdout);
|
|
181
240
|
if (0 !== result.code) {
|
|
182
241
|
const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
|
|
183
|
-
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit)
|
|
184
|
-
|
|
242
|
+
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
|
|
243
|
+
utils_namespaceObject.logger.error('TS-Go compilation failed');
|
|
244
|
+
throw new Error([
|
|
245
|
+
`TS-Go compilation failed with exit code ${result.code}.`,
|
|
246
|
+
result.stderr.trim() || result.stdout.trim()
|
|
247
|
+
].filter(Boolean).join('\n'));
|
|
248
|
+
} else process.exit(1);
|
|
185
249
|
}
|
|
186
250
|
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
187
251
|
for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
|
|
188
252
|
utils_namespaceObject.logger.info("TS-Go compile succeed");
|
|
189
253
|
};
|
|
190
254
|
exports.compileByTs = __webpack_exports__.compileByTs;
|
|
255
|
+
exports.createResolvedTsgoConfig = __webpack_exports__.createResolvedTsgoConfig;
|
|
256
|
+
exports.getTsgoBinPath = __webpack_exports__.getTsgoBinPath;
|
|
257
|
+
exports.rewriteOutputSpecifiers = __webpack_exports__.rewriteOutputSpecifiers;
|
|
191
258
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
192
|
-
"compileByTs"
|
|
259
|
+
"compileByTs",
|
|
260
|
+
"createResolvedTsgoConfig",
|
|
261
|
+
"getTsgoBinPath",
|
|
262
|
+
"rewriteOutputSpecifiers"
|
|
193
263
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
194
264
|
Object.defineProperty(exports, '__esModule', {
|
|
195
265
|
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
|
(()=>{
|