@bleedingdev/modern-js-server-utils 3.5.0-ultramodern.1 → 3.5.0-ultramodern.100
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/compilers/typescript/importRewriter.js +26 -1
- package/dist/cjs/compilers/typescript/index.js +27 -3
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +10 -2
- package/dist/esm/compilers/typescript/importRewriter.mjs +26 -1
- package/dist/esm/compilers/typescript/index.mjs +27 -3
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.mjs +10 -2
- package/dist/esm-node/compilers/typescript/importRewriter.mjs +26 -1
- package/dist/esm-node/compilers/typescript/index.mjs +29 -5
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.mjs +10 -2
- package/dist/types/compilers/typescript/importRewriter.d.ts +2 -1
- package/dist/types/compilers/typescript/index.d.ts +10 -0
- package/package.json +9 -11
|
@@ -55,6 +55,28 @@ const isSpecifierContext = (prev1, prev2, prev3)=>{
|
|
|
55
55
|
if (('from' === prev1 || 'import' === prev1) && '.' !== prev2) return true;
|
|
56
56
|
return '(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
57
57
|
};
|
|
58
|
+
const isCallSpecifierContext = (prev1, prev2, prev3)=>'(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
59
|
+
const nextNonTriviaChar = (content, start)=>{
|
|
60
|
+
let i = start;
|
|
61
|
+
while(i < content.length){
|
|
62
|
+
if (WHITESPACE.test(content[i])) {
|
|
63
|
+
i++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if ('/' === content[i] && '/' === content[i + 1]) {
|
|
67
|
+
const newline = content.indexOf('\n', i + 2);
|
|
68
|
+
i = -1 === newline ? content.length : newline + 1;
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if ('/' === content[i] && '*' === content[i + 1]) {
|
|
72
|
+
const end = content.indexOf('*/', i + 2);
|
|
73
|
+
i = -1 === end ? content.length : end + 2;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
return content[i];
|
|
77
|
+
}
|
|
78
|
+
return '';
|
|
79
|
+
};
|
|
58
80
|
const skipRegexLiteral = (content, start)=>{
|
|
59
81
|
let i = start + 1;
|
|
60
82
|
let inClass = false;
|
|
@@ -182,7 +204,10 @@ const scanSpecifiers = (content)=>{
|
|
|
182
204
|
if ('\n' === sch) break;
|
|
183
205
|
j++;
|
|
184
206
|
}
|
|
185
|
-
|
|
207
|
+
const callSpecifier = isCallSpecifierContext(prev1, prev2, prev3);
|
|
208
|
+
const nextChar = callSpecifier ? nextNonTriviaChar(content, j) : '';
|
|
209
|
+
const isCompleteCallSpecifier = !callSpecifier || ')' === nextChar || ',' === nextChar;
|
|
210
|
+
if (terminated && isSpecifierContext(prev1, prev2, prev3) && isCompleteCallSpecifier) specifiers.push({
|
|
186
211
|
start: start + 1,
|
|
187
212
|
end: j - 1,
|
|
188
213
|
value: content.slice(start + 1, j - 1)
|
|
@@ -55,7 +55,9 @@ const copyFiles = async (from, to, appDirectory)=>{
|
|
|
55
55
|
await utils_namespaceObject.fs.copy(from, targetDir, {
|
|
56
56
|
filter: (src)=>![
|
|
57
57
|
'.ts',
|
|
58
|
-
'.
|
|
58
|
+
'.tsx',
|
|
59
|
+
'.js',
|
|
60
|
+
'.jsx'
|
|
59
61
|
].includes(external_path_default().extname(src)) && !src.endsWith('tsconfig.json')
|
|
60
62
|
});
|
|
61
63
|
}
|
|
@@ -74,10 +76,18 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
|
|
|
74
76
|
config.compilerOptions ??= {};
|
|
75
77
|
config.compilerOptions.rootDir = appDirectory;
|
|
76
78
|
config.compilerOptions.outDir = distDir;
|
|
79
|
+
config.compilerOptions.composite = false;
|
|
80
|
+
config.compilerOptions.declaration = false;
|
|
81
|
+
config.compilerOptions.declarationMap = false;
|
|
82
|
+
config.compilerOptions.emitDeclarationOnly = false;
|
|
83
|
+
config.compilerOptions.incremental = false;
|
|
77
84
|
config.compilerOptions.noEmit = false;
|
|
85
|
+
if (void 0 === config.compilerOptions.jsx || 'preserve' === config.compilerOptions.jsx) config.compilerOptions.jsx = 'react-jsx';
|
|
86
|
+
delete config.compilerOptions.tsBuildInfoFile;
|
|
78
87
|
if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
|
|
79
88
|
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
80
89
|
delete config.include;
|
|
90
|
+
delete config.references;
|
|
81
91
|
delete config.compilerOptions.baseUrl;
|
|
82
92
|
if ([
|
|
83
93
|
'node',
|
|
@@ -144,6 +154,20 @@ const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
|
144
154
|
resolve(result);
|
|
145
155
|
});
|
|
146
156
|
});
|
|
157
|
+
const getTsgoBinEntry = (pkg)=>{
|
|
158
|
+
if ('string' == typeof pkg.bin) return pkg.bin;
|
|
159
|
+
return pkg.bin?.tsgo;
|
|
160
|
+
};
|
|
161
|
+
const resolveTsgoBinPath = (pkgPath)=>{
|
|
162
|
+
const pkgDir = external_path_default().dirname(pkgPath);
|
|
163
|
+
const pkg = require(pkgPath);
|
|
164
|
+
const declaredBinEntry = getTsgoBinEntry(pkg);
|
|
165
|
+
const candidates = [
|
|
166
|
+
declaredBinEntry ? external_path_default().resolve(pkgDir, declaredBinEntry) : void 0,
|
|
167
|
+
external_path_default().join(pkgDir, 'bin/tsgo.js')
|
|
168
|
+
].filter((candidate)=>Boolean(candidate));
|
|
169
|
+
return candidates.find((candidate)=>utils_namespaceObject.fs.existsSync(candidate)) ?? candidates[0];
|
|
170
|
+
};
|
|
147
171
|
const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
148
172
|
appDirectory,
|
|
149
173
|
__dirname
|
|
@@ -152,7 +176,7 @@ const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
|
152
176
|
const pkgPath = require.resolve("@typescript/native-preview/package.json", {
|
|
153
177
|
paths: resolvePaths
|
|
154
178
|
});
|
|
155
|
-
return
|
|
179
|
+
return resolveTsgoBinPath(pkgPath);
|
|
156
180
|
} catch {
|
|
157
181
|
throw new Error('tsgo could not be found! Please install "@typescript/native-preview" in your project to compile BFF/server code.');
|
|
158
182
|
}
|
|
@@ -190,7 +214,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
|
|
|
190
214
|
return content.replace(sourceMappingUrlRE, '');
|
|
191
215
|
};
|
|
192
216
|
const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
|
|
193
|
-
if (
|
|
217
|
+
if (!await utils_namespaceObject.fs.pathExists(distDir)) return;
|
|
194
218
|
const matcher = (0, external_tsconfigPathsPlugin_js_namespaceObject.createTsconfigPathsMatcher)(baseUrl, paths);
|
|
195
219
|
if (!matcher) return;
|
|
196
220
|
const files = await collectOutputFiles(distDir);
|
|
@@ -52,10 +52,18 @@ const toImportSpecifier = (sourceFile, resolvedPath)=>{
|
|
|
52
52
|
const relativePath = pathApi.relative(pathApi.dirname(sourceFile), resolvedPath).split(pathApi.sep).join(external_path_default().posix.sep);
|
|
53
53
|
return '.' === relativePath[0] ? relativePath : `./${relativePath}`;
|
|
54
54
|
};
|
|
55
|
+
const COMPILED_TO_JS_EXTENSIONS = new Set([
|
|
56
|
+
'.ts',
|
|
57
|
+
'.tsx',
|
|
58
|
+
'.js',
|
|
59
|
+
'.jsx'
|
|
60
|
+
]);
|
|
55
61
|
const toEsmOutputPath = (resolvedPath)=>{
|
|
56
|
-
const sourcePath = (0, utils_namespaceObject.findSourceEntry)(resolvedPath) || resolvedPath;
|
|
62
|
+
const sourcePath = ((0, utils_namespaceObject.findSourceEntry)(resolvedPath) || resolvedPath).replace(/\\/g, '/');
|
|
57
63
|
const ext = external_path_default().extname(sourcePath);
|
|
58
|
-
|
|
64
|
+
if (!ext) return `${sourcePath}.js`;
|
|
65
|
+
if (!COMPILED_TO_JS_EXTENSIONS.has(ext)) return sourcePath;
|
|
66
|
+
return `${sourcePath.slice(0, -ext.length)}.js`;
|
|
59
67
|
};
|
|
60
68
|
const resolveRelativeEsmSpecifier = (sourceFile, text)=>{
|
|
61
69
|
if (!text.startsWith('./') && !text.startsWith('../')) return;
|
|
@@ -26,6 +26,28 @@ const isSpecifierContext = (prev1, prev2, prev3)=>{
|
|
|
26
26
|
if (('from' === prev1 || 'import' === prev1) && '.' !== prev2) return true;
|
|
27
27
|
return '(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
28
28
|
};
|
|
29
|
+
const isCallSpecifierContext = (prev1, prev2, prev3)=>'(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
30
|
+
const nextNonTriviaChar = (content, start)=>{
|
|
31
|
+
let i = start;
|
|
32
|
+
while(i < content.length){
|
|
33
|
+
if (WHITESPACE.test(content[i])) {
|
|
34
|
+
i++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if ('/' === content[i] && '/' === content[i + 1]) {
|
|
38
|
+
const newline = content.indexOf('\n', i + 2);
|
|
39
|
+
i = -1 === newline ? content.length : newline + 1;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if ('/' === content[i] && '*' === content[i + 1]) {
|
|
43
|
+
const end = content.indexOf('*/', i + 2);
|
|
44
|
+
i = -1 === end ? content.length : end + 2;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
return content[i];
|
|
48
|
+
}
|
|
49
|
+
return '';
|
|
50
|
+
};
|
|
29
51
|
const skipRegexLiteral = (content, start)=>{
|
|
30
52
|
let i = start + 1;
|
|
31
53
|
let inClass = false;
|
|
@@ -153,7 +175,10 @@ const scanSpecifiers = (content)=>{
|
|
|
153
175
|
if ('\n' === sch) break;
|
|
154
176
|
j++;
|
|
155
177
|
}
|
|
156
|
-
|
|
178
|
+
const callSpecifier = isCallSpecifierContext(prev1, prev2, prev3);
|
|
179
|
+
const nextChar = callSpecifier ? nextNonTriviaChar(content, j) : '';
|
|
180
|
+
const isCompleteCallSpecifier = !callSpecifier || ')' === nextChar || ',' === nextChar;
|
|
181
|
+
if (terminated && isSpecifierContext(prev1, prev2, prev3) && isCompleteCallSpecifier) specifiers.push({
|
|
157
182
|
start: start + 1,
|
|
158
183
|
end: j - 1,
|
|
159
184
|
value: content.slice(start + 1, j - 1)
|
|
@@ -10,7 +10,9 @@ const copyFiles = async (from, to, appDirectory)=>{
|
|
|
10
10
|
await fs.copy(from, targetDir, {
|
|
11
11
|
filter: (src)=>![
|
|
12
12
|
'.ts',
|
|
13
|
-
'.
|
|
13
|
+
'.tsx',
|
|
14
|
+
'.js',
|
|
15
|
+
'.jsx'
|
|
14
16
|
].includes(path.extname(src)) && !src.endsWith('tsconfig.json')
|
|
15
17
|
});
|
|
16
18
|
}
|
|
@@ -29,10 +31,18 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
|
|
|
29
31
|
config.compilerOptions ??= {};
|
|
30
32
|
config.compilerOptions.rootDir = appDirectory;
|
|
31
33
|
config.compilerOptions.outDir = distDir;
|
|
34
|
+
config.compilerOptions.composite = false;
|
|
35
|
+
config.compilerOptions.declaration = false;
|
|
36
|
+
config.compilerOptions.declarationMap = false;
|
|
37
|
+
config.compilerOptions.emitDeclarationOnly = false;
|
|
38
|
+
config.compilerOptions.incremental = false;
|
|
32
39
|
config.compilerOptions.noEmit = false;
|
|
40
|
+
if (void 0 === config.compilerOptions.jsx || 'preserve' === config.compilerOptions.jsx) config.compilerOptions.jsx = 'react-jsx';
|
|
41
|
+
delete config.compilerOptions.tsBuildInfoFile;
|
|
33
42
|
if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
|
|
34
43
|
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
35
44
|
delete config.include;
|
|
45
|
+
delete config.references;
|
|
36
46
|
delete config.compilerOptions.baseUrl;
|
|
37
47
|
if ([
|
|
38
48
|
'node',
|
|
@@ -99,6 +109,20 @@ const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
|
99
109
|
resolve(result);
|
|
100
110
|
});
|
|
101
111
|
});
|
|
112
|
+
const getTsgoBinEntry = (pkg)=>{
|
|
113
|
+
if ('string' == typeof pkg.bin) return pkg.bin;
|
|
114
|
+
return pkg.bin?.tsgo;
|
|
115
|
+
};
|
|
116
|
+
const resolveTsgoBinPath = (pkgPath)=>{
|
|
117
|
+
const pkgDir = path.dirname(pkgPath);
|
|
118
|
+
const pkg = require(pkgPath);
|
|
119
|
+
const declaredBinEntry = getTsgoBinEntry(pkg);
|
|
120
|
+
const candidates = [
|
|
121
|
+
declaredBinEntry ? path.resolve(pkgDir, declaredBinEntry) : void 0,
|
|
122
|
+
path.join(pkgDir, 'bin/tsgo.js')
|
|
123
|
+
].filter((candidate)=>Boolean(candidate));
|
|
124
|
+
return candidates.find((candidate)=>fs.existsSync(candidate)) ?? candidates[0];
|
|
125
|
+
};
|
|
102
126
|
const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
103
127
|
appDirectory,
|
|
104
128
|
__dirname
|
|
@@ -107,7 +131,7 @@ const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
|
107
131
|
const pkgPath = require.resolve("@typescript/native-preview/package.json", {
|
|
108
132
|
paths: resolvePaths
|
|
109
133
|
});
|
|
110
|
-
return
|
|
134
|
+
return resolveTsgoBinPath(pkgPath);
|
|
111
135
|
} catch {
|
|
112
136
|
throw new Error('tsgo could not be found! Please install "@typescript/native-preview" in your project to compile BFF/server code.');
|
|
113
137
|
}
|
|
@@ -145,7 +169,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
|
|
|
145
169
|
return content.replace(sourceMappingUrlRE, '');
|
|
146
170
|
};
|
|
147
171
|
const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
|
|
148
|
-
if (
|
|
172
|
+
if (!await fs.pathExists(distDir)) return;
|
|
149
173
|
const matcher = createTsconfigPathsMatcher(baseUrl, paths);
|
|
150
174
|
if (!matcher) return;
|
|
151
175
|
const files = await collectOutputFiles(distDir);
|
|
@@ -9,10 +9,18 @@ const toImportSpecifier = (sourceFile, resolvedPath)=>{
|
|
|
9
9
|
const relativePath = pathApi.relative(pathApi.dirname(sourceFile), resolvedPath).split(pathApi.sep).join(path.posix.sep);
|
|
10
10
|
return '.' === relativePath[0] ? relativePath : `./${relativePath}`;
|
|
11
11
|
};
|
|
12
|
+
const COMPILED_TO_JS_EXTENSIONS = new Set([
|
|
13
|
+
'.ts',
|
|
14
|
+
'.tsx',
|
|
15
|
+
'.js',
|
|
16
|
+
'.jsx'
|
|
17
|
+
]);
|
|
12
18
|
const toEsmOutputPath = (resolvedPath)=>{
|
|
13
|
-
const sourcePath = findSourceEntry(resolvedPath) || resolvedPath;
|
|
19
|
+
const sourcePath = (findSourceEntry(resolvedPath) || resolvedPath).replace(/\\/g, '/');
|
|
14
20
|
const ext = path.extname(sourcePath);
|
|
15
|
-
|
|
21
|
+
if (!ext) return `${sourcePath}.js`;
|
|
22
|
+
if (!COMPILED_TO_JS_EXTENSIONS.has(ext)) return sourcePath;
|
|
23
|
+
return `${sourcePath.slice(0, -ext.length)}.js`;
|
|
16
24
|
};
|
|
17
25
|
const resolveRelativeEsmSpecifier = (sourceFile, text)=>{
|
|
18
26
|
if (!text.startsWith('./') && !text.startsWith('../')) return;
|
|
@@ -27,6 +27,28 @@ const isSpecifierContext = (prev1, prev2, prev3)=>{
|
|
|
27
27
|
if (('from' === prev1 || 'import' === prev1) && '.' !== prev2) return true;
|
|
28
28
|
return '(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
29
29
|
};
|
|
30
|
+
const isCallSpecifierContext = (prev1, prev2, prev3)=>'(' === prev1 && ('import' === prev2 || 'require' === prev2) && '.' !== prev3;
|
|
31
|
+
const nextNonTriviaChar = (content, start)=>{
|
|
32
|
+
let i = start;
|
|
33
|
+
while(i < content.length){
|
|
34
|
+
if (WHITESPACE.test(content[i])) {
|
|
35
|
+
i++;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if ('/' === content[i] && '/' === content[i + 1]) {
|
|
39
|
+
const newline = content.indexOf('\n', i + 2);
|
|
40
|
+
i = -1 === newline ? content.length : newline + 1;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if ('/' === content[i] && '*' === content[i + 1]) {
|
|
44
|
+
const end = content.indexOf('*/', i + 2);
|
|
45
|
+
i = -1 === end ? content.length : end + 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
return content[i];
|
|
49
|
+
}
|
|
50
|
+
return '';
|
|
51
|
+
};
|
|
30
52
|
const skipRegexLiteral = (content, start)=>{
|
|
31
53
|
let i = start + 1;
|
|
32
54
|
let inClass = false;
|
|
@@ -154,7 +176,10 @@ const scanSpecifiers = (content)=>{
|
|
|
154
176
|
if ('\n' === sch) break;
|
|
155
177
|
j++;
|
|
156
178
|
}
|
|
157
|
-
|
|
179
|
+
const callSpecifier = isCallSpecifierContext(prev1, prev2, prev3);
|
|
180
|
+
const nextChar = callSpecifier ? nextNonTriviaChar(content, j) : '';
|
|
181
|
+
const isCompleteCallSpecifier = !callSpecifier || ')' === nextChar || ',' === nextChar;
|
|
182
|
+
if (terminated && isSpecifierContext(prev1, prev2, prev3) && isCompleteCallSpecifier) specifiers.push({
|
|
158
183
|
start: start + 1,
|
|
159
184
|
end: j - 1,
|
|
160
185
|
value: content.slice(start + 1, j - 1)
|
|
@@ -7,7 +7,7 @@ import { rewriteImportSpecifiers } from "./importRewriter.mjs";
|
|
|
7
7
|
import { createTsconfigPathsMatcher, getNotAliasedPath } from "./tsconfigPathsPlugin.mjs";
|
|
8
8
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
9
9
|
import { dirname as __rspack_dirname } from "node:path";
|
|
10
|
-
var
|
|
10
|
+
var __rspack_import_meta_dirname__ = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
11
11
|
const copyFiles = async (from, to, appDirectory)=>{
|
|
12
12
|
if (await fs.pathExists(from)) {
|
|
13
13
|
const relativePath = path.relative(appDirectory, from);
|
|
@@ -15,7 +15,9 @@ const copyFiles = async (from, to, appDirectory)=>{
|
|
|
15
15
|
await fs.copy(from, targetDir, {
|
|
16
16
|
filter: (src)=>![
|
|
17
17
|
'.ts',
|
|
18
|
-
'.
|
|
18
|
+
'.tsx',
|
|
19
|
+
'.js',
|
|
20
|
+
'.jsx'
|
|
19
21
|
].includes(path.extname(src)) && !src.endsWith('tsconfig.json')
|
|
20
22
|
});
|
|
21
23
|
}
|
|
@@ -34,10 +36,18 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
|
|
|
34
36
|
config.compilerOptions ??= {};
|
|
35
37
|
config.compilerOptions.rootDir = appDirectory;
|
|
36
38
|
config.compilerOptions.outDir = distDir;
|
|
39
|
+
config.compilerOptions.composite = false;
|
|
40
|
+
config.compilerOptions.declaration = false;
|
|
41
|
+
config.compilerOptions.declarationMap = false;
|
|
42
|
+
config.compilerOptions.emitDeclarationOnly = false;
|
|
43
|
+
config.compilerOptions.incremental = false;
|
|
37
44
|
config.compilerOptions.noEmit = false;
|
|
45
|
+
if (void 0 === config.compilerOptions.jsx || 'preserve' === config.compilerOptions.jsx) config.compilerOptions.jsx = 'react-jsx';
|
|
46
|
+
delete config.compilerOptions.tsBuildInfoFile;
|
|
38
47
|
if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
|
|
39
48
|
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
40
49
|
delete config.include;
|
|
50
|
+
delete config.references;
|
|
41
51
|
delete config.compilerOptions.baseUrl;
|
|
42
52
|
if ([
|
|
43
53
|
'node',
|
|
@@ -104,15 +114,29 @@ const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
|
104
114
|
resolve(result);
|
|
105
115
|
});
|
|
106
116
|
});
|
|
117
|
+
const getTsgoBinEntry = (pkg)=>{
|
|
118
|
+
if ('string' == typeof pkg.bin) return pkg.bin;
|
|
119
|
+
return pkg.bin?.tsgo;
|
|
120
|
+
};
|
|
121
|
+
const resolveTsgoBinPath = (pkgPath)=>{
|
|
122
|
+
const pkgDir = path.dirname(pkgPath);
|
|
123
|
+
const pkg = require(pkgPath);
|
|
124
|
+
const declaredBinEntry = getTsgoBinEntry(pkg);
|
|
125
|
+
const candidates = [
|
|
126
|
+
declaredBinEntry ? path.resolve(pkgDir, declaredBinEntry) : void 0,
|
|
127
|
+
path.join(pkgDir, 'bin/tsgo.js')
|
|
128
|
+
].filter((candidate)=>Boolean(candidate));
|
|
129
|
+
return candidates.find((candidate)=>fs.existsSync(candidate)) ?? candidates[0];
|
|
130
|
+
};
|
|
107
131
|
const getTsgoBinPath = (appDirectory, resolvePaths = [
|
|
108
132
|
appDirectory,
|
|
109
|
-
|
|
133
|
+
__rspack_import_meta_dirname__
|
|
110
134
|
])=>{
|
|
111
135
|
try {
|
|
112
136
|
const pkgPath = require.resolve("@typescript/native-preview/package.json", {
|
|
113
137
|
paths: resolvePaths
|
|
114
138
|
});
|
|
115
|
-
return
|
|
139
|
+
return resolveTsgoBinPath(pkgPath);
|
|
116
140
|
} catch {
|
|
117
141
|
throw new Error('tsgo could not be found! Please install "@typescript/native-preview" in your project to compile BFF/server code.');
|
|
118
142
|
}
|
|
@@ -150,7 +174,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
|
|
|
150
174
|
return content.replace(sourceMappingUrlRE, '');
|
|
151
175
|
};
|
|
152
176
|
const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
|
|
153
|
-
if (
|
|
177
|
+
if (!await fs.pathExists(distDir)) return;
|
|
154
178
|
const matcher = createTsconfigPathsMatcher(baseUrl, paths);
|
|
155
179
|
if (!matcher) return;
|
|
156
180
|
const files = await collectOutputFiles(distDir);
|
|
@@ -11,10 +11,18 @@ const toImportSpecifier = (sourceFile, resolvedPath)=>{
|
|
|
11
11
|
const relativePath = pathApi.relative(pathApi.dirname(sourceFile), resolvedPath).split(pathApi.sep).join(path.posix.sep);
|
|
12
12
|
return '.' === relativePath[0] ? relativePath : `./${relativePath}`;
|
|
13
13
|
};
|
|
14
|
+
const COMPILED_TO_JS_EXTENSIONS = new Set([
|
|
15
|
+
'.ts',
|
|
16
|
+
'.tsx',
|
|
17
|
+
'.js',
|
|
18
|
+
'.jsx'
|
|
19
|
+
]);
|
|
14
20
|
const toEsmOutputPath = (resolvedPath)=>{
|
|
15
|
-
const sourcePath = findSourceEntry(resolvedPath) || resolvedPath;
|
|
21
|
+
const sourcePath = (findSourceEntry(resolvedPath) || resolvedPath).replace(/\\/g, '/');
|
|
16
22
|
const ext = path.extname(sourcePath);
|
|
17
|
-
|
|
23
|
+
if (!ext) return `${sourcePath}.js`;
|
|
24
|
+
if (!COMPILED_TO_JS_EXTENSIONS.has(ext)) return sourcePath;
|
|
25
|
+
return `${sourcePath.slice(0, -ext.length)}.js`;
|
|
18
26
|
};
|
|
19
27
|
const resolveRelativeEsmSpecifier = (sourceFile, text)=>{
|
|
20
28
|
if (!text.startsWith('./') && !text.startsWith('../')) return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type SpecifierRewrite = (specifier: string) => string | undefined;
|
|
2
2
|
/**
|
|
3
3
|
* Rewrite the import/export/require specifiers of emitted JavaScript.
|
|
4
4
|
*
|
|
@@ -10,3 +10,4 @@ export declare const rewriteImportSpecifiers: (content: string, rewrite: Specifi
|
|
|
10
10
|
content: string;
|
|
11
11
|
changed: boolean;
|
|
12
12
|
};
|
|
13
|
+
export {};
|
|
@@ -3,6 +3,12 @@ type TsgoConfig = {
|
|
|
3
3
|
compilerOptions?: {
|
|
4
4
|
allowImportingTsExtensions?: boolean;
|
|
5
5
|
baseUrl?: unknown;
|
|
6
|
+
composite?: boolean;
|
|
7
|
+
declaration?: boolean;
|
|
8
|
+
declarationMap?: boolean;
|
|
9
|
+
emitDeclarationOnly?: boolean;
|
|
10
|
+
incremental?: boolean;
|
|
11
|
+
jsx?: string;
|
|
6
12
|
module?: string;
|
|
7
13
|
moduleResolution?: string;
|
|
8
14
|
noEmit?: boolean;
|
|
@@ -10,10 +16,14 @@ type TsgoConfig = {
|
|
|
10
16
|
outDir?: string;
|
|
11
17
|
rootDir?: string;
|
|
12
18
|
rewriteRelativeImportExtensions?: boolean;
|
|
19
|
+
tsBuildInfoFile?: string;
|
|
13
20
|
verbatimModuleSyntax?: boolean;
|
|
14
21
|
};
|
|
15
22
|
files?: string[];
|
|
16
23
|
include?: string[];
|
|
24
|
+
references?: Array<{
|
|
25
|
+
path: string;
|
|
26
|
+
}>;
|
|
17
27
|
};
|
|
18
28
|
export declare const createResolvedTsgoConfig: (appDirectory: string, tsconfigPath: string, distDir: string, sourceDirs: string[], moduleType: 'module' | 'commonjs' | undefined, tsgoBinPath: string) => Promise<{
|
|
19
29
|
config: TsgoConfig;
|
package/package.json
CHANGED
|
@@ -17,13 +17,12 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.5.0-ultramodern.
|
|
20
|
+
"version": "3.5.0-ultramodern.100",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
25
|
"types": "./dist/types/index.d.ts",
|
|
26
|
-
"modern:source": "./src/index.ts",
|
|
27
26
|
"node": {
|
|
28
27
|
"import": "./dist/esm-node/index.mjs",
|
|
29
28
|
"require": "./dist/cjs/index.js"
|
|
@@ -39,18 +38,18 @@
|
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
40
|
"dependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@
|
|
41
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.100",
|
|
42
|
+
"@swc/helpers": "^0.5.23"
|
|
44
43
|
},
|
|
45
44
|
"devDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
45
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.100",
|
|
46
|
+
"@rslib/core": "0.23.2",
|
|
47
|
+
"@scripts/rstest-config": "2.66.0",
|
|
48
|
+
"@types/node": "^26.1.1",
|
|
49
|
+
"@typescript/native-preview": "7.0.0-dev.20260707.2"
|
|
51
50
|
},
|
|
52
51
|
"peerDependencies": {
|
|
53
|
-
"@typescript/native-preview": ">=7.0.0-dev.
|
|
52
|
+
"@typescript/native-preview": ">=7.0.0-dev.20260628.1"
|
|
54
53
|
},
|
|
55
54
|
"peerDependenciesMeta": {
|
|
56
55
|
"@typescript/native-preview": {
|
|
@@ -59,7 +58,6 @@
|
|
|
59
58
|
},
|
|
60
59
|
"sideEffects": false,
|
|
61
60
|
"publishConfig": {
|
|
62
|
-
"registry": "https://registry.npmjs.org/",
|
|
63
61
|
"access": "public"
|
|
64
62
|
},
|
|
65
63
|
"scripts": {
|