@bleedingdev/modern-js-server-utils 3.4.0-ultramodern.2 → 3.4.0-ultramodern.20
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/index.js +4 -1
- package/dist/cjs/compilers/typescript/tsconfigPathsPlugin.js +12 -7
- package/dist/esm/compilers/typescript/index.mjs +4 -1
- package/dist/esm/compilers/typescript/tsconfigPathsPlugin.mjs +13 -8
- package/dist/esm-node/compilers/typescript/index.mjs +4 -1
- package/dist/esm-node/compilers/typescript/tsconfigPathsPlugin.mjs +13 -8
- package/dist/types/compilers/typescript/index.d.ts +2 -0
- package/package.json +3 -3
|
@@ -75,6 +75,7 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
|
|
|
75
75
|
config.compilerOptions.rootDir = appDirectory;
|
|
76
76
|
config.compilerOptions.outDir = distDir;
|
|
77
77
|
config.compilerOptions.noEmit = false;
|
|
78
|
+
if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
|
|
78
79
|
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
79
80
|
delete config.include;
|
|
80
81
|
delete config.compilerOptions.baseUrl;
|
|
@@ -107,9 +108,11 @@ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
|
|
|
107
108
|
const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(external_path_default().sep).join(external_path_default().posix.sep));
|
|
108
109
|
return files.filter((fileName)=>{
|
|
109
110
|
const absoluteFileName = external_path_default().resolve(tsconfigDir, fileName).split(external_path_default().sep).join(external_path_default().posix.sep);
|
|
111
|
+
if (isAppRouterGeneratedDeclaration(absoluteFileName)) return false;
|
|
110
112
|
return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
|
|
111
113
|
});
|
|
112
114
|
};
|
|
115
|
+
const isAppRouterGeneratedDeclaration = (absoluteFileName)=>/\/src\/modern-tanstack\/.*\.gen\.d\.ts$/u.test(absoluteFileName);
|
|
113
116
|
const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
114
117
|
const child = (0, external_child_process_namespaceObject.spawn)(process.execPath, [
|
|
115
118
|
tsgoBinPath,
|
|
@@ -238,6 +241,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
238
241
|
}
|
|
239
242
|
if (result.stderr) utils_namespaceObject.logger.error(result.stderr);
|
|
240
243
|
if (result.stdout) utils_namespaceObject.logger.info(result.stdout);
|
|
244
|
+
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
241
245
|
if (0 !== result.code) {
|
|
242
246
|
const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
|
|
243
247
|
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
|
|
@@ -248,7 +252,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
248
252
|
].filter(Boolean).join('\n'));
|
|
249
253
|
} else process.exit(1);
|
|
250
254
|
}
|
|
251
|
-
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
252
255
|
for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
|
|
253
256
|
utils_namespaceObject.logger.info("TS-Go compile succeed");
|
|
254
257
|
};
|
|
@@ -42,9 +42,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
42
42
|
});
|
|
43
43
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
44
|
const tsconfig_paths_namespaceObject = require("@modern-js/utils/tsconfig-paths");
|
|
45
|
-
const external_os_namespaceObject = require("os");
|
|
46
45
|
const external_path_namespaceObject = require("path");
|
|
47
46
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
47
|
+
const windowsAbsolutePathRE = /^[A-Za-z]:[\\/]/u;
|
|
48
|
+
const isAbsolutePath = (input)=>external_path_default().isAbsolute(input) || external_path_default().win32.isAbsolute(input);
|
|
49
|
+
const pathApiFor = (...inputs)=>inputs.some((input)=>windowsAbsolutePathRE.test(input)) ? external_path_default().win32 : external_path_default();
|
|
50
|
+
const toImportSpecifier = (sourceFile, resolvedPath)=>{
|
|
51
|
+
const pathApi = pathApiFor(sourceFile, resolvedPath);
|
|
52
|
+
const relativePath = pathApi.relative(pathApi.dirname(sourceFile), resolvedPath).split(pathApi.sep).join(external_path_default().posix.sep);
|
|
53
|
+
return '.' === relativePath[0] ? relativePath : `./${relativePath}`;
|
|
54
|
+
};
|
|
48
55
|
const toEsmOutputPath = (resolvedPath)=>{
|
|
49
56
|
const sourcePath = (0, utils_namespaceObject.findSourceEntry)(resolvedPath) || resolvedPath;
|
|
50
57
|
const ext = external_path_default().extname(sourcePath);
|
|
@@ -52,8 +59,8 @@ const toEsmOutputPath = (resolvedPath)=>{
|
|
|
52
59
|
};
|
|
53
60
|
const resolveRelativeEsmSpecifier = (sourceFile, text)=>{
|
|
54
61
|
if (!text.startsWith('./') && !text.startsWith('../')) return;
|
|
55
|
-
const
|
|
56
|
-
return
|
|
62
|
+
const pathApi = pathApiFor(sourceFile);
|
|
63
|
+
return pathApi.resolve(pathApi.dirname(sourceFile), text);
|
|
57
64
|
};
|
|
58
65
|
const isRegExpKey = (str)=>str.startsWith('^') || str.endsWith('$');
|
|
59
66
|
const resolveAliasPath = (baseUrl, filePath)=>{
|
|
@@ -116,8 +123,7 @@ function getNotAliasedPath(sourceFile, matcher, text, moduleType) {
|
|
|
116
123
|
let result = (0, utils_namespaceObject.findMatchedSourcePath)(matcher, text);
|
|
117
124
|
if (!result && 'module' === moduleType) result = resolveRelativeEsmSpecifier(sourceFile, text);
|
|
118
125
|
if (!result) return;
|
|
119
|
-
if (
|
|
120
|
-
if (!external_path_default().isAbsolute(result)) {
|
|
126
|
+
if (!isAbsolutePath(result)) {
|
|
121
127
|
if (!result.startsWith('.') && !result.startsWith('..')) try {
|
|
122
128
|
const packagePath = require.resolve(result, {
|
|
123
129
|
paths: [
|
|
@@ -138,8 +144,7 @@ function getNotAliasedPath(sourceFile, matcher, text, moduleType) {
|
|
|
138
144
|
} catch {}
|
|
139
145
|
}
|
|
140
146
|
if ('module' === moduleType) result = toEsmOutputPath(result);
|
|
141
|
-
|
|
142
|
-
return '.' === resolvedPath[0] ? resolvedPath : `./${resolvedPath}`;
|
|
147
|
+
return toImportSpecifier(sourceFile, result) || './';
|
|
143
148
|
}
|
|
144
149
|
exports.createTsconfigPathsMatcher = __webpack_exports__.createTsconfigPathsMatcher;
|
|
145
150
|
exports.getNotAliasedPath = __webpack_exports__.getNotAliasedPath;
|
|
@@ -30,6 +30,7 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
|
|
|
30
30
|
config.compilerOptions.rootDir = appDirectory;
|
|
31
31
|
config.compilerOptions.outDir = distDir;
|
|
32
32
|
config.compilerOptions.noEmit = false;
|
|
33
|
+
if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
|
|
33
34
|
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
34
35
|
delete config.include;
|
|
35
36
|
delete config.compilerOptions.baseUrl;
|
|
@@ -62,9 +63,11 @@ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
|
|
|
62
63
|
const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(path.sep).join(path.posix.sep));
|
|
63
64
|
return files.filter((fileName)=>{
|
|
64
65
|
const absoluteFileName = path.resolve(tsconfigDir, fileName).split(path.sep).join(path.posix.sep);
|
|
66
|
+
if (isAppRouterGeneratedDeclaration(absoluteFileName)) return false;
|
|
65
67
|
return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
|
|
66
68
|
});
|
|
67
69
|
};
|
|
70
|
+
const isAppRouterGeneratedDeclaration = (absoluteFileName)=>/\/src\/modern-tanstack\/.*\.gen\.d\.ts$/u.test(absoluteFileName);
|
|
68
71
|
const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
69
72
|
const child = spawn(process.execPath, [
|
|
70
73
|
tsgoBinPath,
|
|
@@ -193,6 +196,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
193
196
|
}
|
|
194
197
|
if (result.stderr) logger.error(result.stderr);
|
|
195
198
|
if (result.stdout) logger.info(result.stdout);
|
|
199
|
+
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
196
200
|
if (0 !== result.code) {
|
|
197
201
|
const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
|
|
198
202
|
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
|
|
@@ -203,7 +207,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
203
207
|
].filter(Boolean).join('\n'));
|
|
204
208
|
} else process.exit(1);
|
|
205
209
|
}
|
|
206
|
-
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
207
210
|
for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
|
|
208
211
|
logger.info("TS-Go compile succeed");
|
|
209
212
|
};
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { findMatchedSourcePath, findSourceEntry } from "@modern-js/utils";
|
|
2
2
|
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
3
|
-
import path
|
|
4
|
-
|
|
3
|
+
import path from "path";
|
|
4
|
+
const windowsAbsolutePathRE = /^[A-Za-z]:[\\/]/u;
|
|
5
|
+
const isAbsolutePath = (input)=>path.isAbsolute(input) || path.win32.isAbsolute(input);
|
|
6
|
+
const pathApiFor = (...inputs)=>inputs.some((input)=>windowsAbsolutePathRE.test(input)) ? path.win32 : path;
|
|
7
|
+
const toImportSpecifier = (sourceFile, resolvedPath)=>{
|
|
8
|
+
const pathApi = pathApiFor(sourceFile, resolvedPath);
|
|
9
|
+
const relativePath = pathApi.relative(pathApi.dirname(sourceFile), resolvedPath).split(pathApi.sep).join(path.posix.sep);
|
|
10
|
+
return '.' === relativePath[0] ? relativePath : `./${relativePath}`;
|
|
11
|
+
};
|
|
5
12
|
const toEsmOutputPath = (resolvedPath)=>{
|
|
6
13
|
const sourcePath = findSourceEntry(resolvedPath) || resolvedPath;
|
|
7
14
|
const ext = path.extname(sourcePath);
|
|
@@ -9,8 +16,8 @@ const toEsmOutputPath = (resolvedPath)=>{
|
|
|
9
16
|
};
|
|
10
17
|
const resolveRelativeEsmSpecifier = (sourceFile, text)=>{
|
|
11
18
|
if (!text.startsWith('./') && !text.startsWith('../')) return;
|
|
12
|
-
const
|
|
13
|
-
return
|
|
19
|
+
const pathApi = pathApiFor(sourceFile);
|
|
20
|
+
return pathApi.resolve(pathApi.dirname(sourceFile), text);
|
|
14
21
|
};
|
|
15
22
|
const isRegExpKey = (str)=>str.startsWith('^') || str.endsWith('$');
|
|
16
23
|
const resolveAliasPath = (baseUrl, filePath)=>{
|
|
@@ -73,8 +80,7 @@ function getNotAliasedPath(sourceFile, matcher, text, moduleType) {
|
|
|
73
80
|
let result = findMatchedSourcePath(matcher, text);
|
|
74
81
|
if (!result && 'module' === moduleType) result = resolveRelativeEsmSpecifier(sourceFile, text);
|
|
75
82
|
if (!result) return;
|
|
76
|
-
if (
|
|
77
|
-
if (!path.isAbsolute(result)) {
|
|
83
|
+
if (!isAbsolutePath(result)) {
|
|
78
84
|
if (!result.startsWith('.') && !result.startsWith('..')) try {
|
|
79
85
|
const packagePath = require.resolve(result, {
|
|
80
86
|
paths: [
|
|
@@ -95,7 +101,6 @@ function getNotAliasedPath(sourceFile, matcher, text, moduleType) {
|
|
|
95
101
|
} catch {}
|
|
96
102
|
}
|
|
97
103
|
if ('module' === moduleType) result = toEsmOutputPath(result);
|
|
98
|
-
|
|
99
|
-
return '.' === resolvedPath[0] ? resolvedPath : `./${resolvedPath}`;
|
|
104
|
+
return toImportSpecifier(sourceFile, result) || './';
|
|
100
105
|
}
|
|
101
106
|
export { createTsconfigPathsMatcher, getNotAliasedPath };
|
|
@@ -35,6 +35,7 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
|
|
|
35
35
|
config.compilerOptions.rootDir = appDirectory;
|
|
36
36
|
config.compilerOptions.outDir = distDir;
|
|
37
37
|
config.compilerOptions.noEmit = false;
|
|
38
|
+
if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
|
|
38
39
|
config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
|
|
39
40
|
delete config.include;
|
|
40
41
|
delete config.compilerOptions.baseUrl;
|
|
@@ -67,9 +68,11 @@ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
|
|
|
67
68
|
const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(path.sep).join(path.posix.sep));
|
|
68
69
|
return files.filter((fileName)=>{
|
|
69
70
|
const absoluteFileName = path.resolve(tsconfigDir, fileName).split(path.sep).join(path.posix.sep);
|
|
71
|
+
if (isAppRouterGeneratedDeclaration(absoluteFileName)) return false;
|
|
70
72
|
return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
|
|
71
73
|
});
|
|
72
74
|
};
|
|
75
|
+
const isAppRouterGeneratedDeclaration = (absoluteFileName)=>/\/src\/modern-tanstack\/.*\.gen\.d\.ts$/u.test(absoluteFileName);
|
|
73
76
|
const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
|
|
74
77
|
const child = spawn(process.execPath, [
|
|
75
78
|
tsgoBinPath,
|
|
@@ -198,6 +201,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
198
201
|
}
|
|
199
202
|
if (result.stderr) logger.error(result.stderr);
|
|
200
203
|
if (result.stdout) logger.info(result.stdout);
|
|
204
|
+
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
201
205
|
if (0 !== result.code) {
|
|
202
206
|
const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
|
|
203
207
|
if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
|
|
@@ -208,7 +212,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
|
|
|
208
212
|
].filter(Boolean).join('\n'));
|
|
209
213
|
} else process.exit(1);
|
|
210
214
|
}
|
|
211
|
-
await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
|
|
212
215
|
for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
|
|
213
216
|
logger.info("TS-Go compile succeed");
|
|
214
217
|
};
|
|
@@ -2,8 +2,15 @@ import __rslib_shim_module__ from "node:module";
|
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
3
|
import { findMatchedSourcePath, findSourceEntry } from "@modern-js/utils";
|
|
4
4
|
import { createMatchPath } from "@modern-js/utils/tsconfig-paths";
|
|
5
|
-
import path
|
|
6
|
-
|
|
5
|
+
import path from "path";
|
|
6
|
+
const windowsAbsolutePathRE = /^[A-Za-z]:[\\/]/u;
|
|
7
|
+
const isAbsolutePath = (input)=>path.isAbsolute(input) || path.win32.isAbsolute(input);
|
|
8
|
+
const pathApiFor = (...inputs)=>inputs.some((input)=>windowsAbsolutePathRE.test(input)) ? path.win32 : path;
|
|
9
|
+
const toImportSpecifier = (sourceFile, resolvedPath)=>{
|
|
10
|
+
const pathApi = pathApiFor(sourceFile, resolvedPath);
|
|
11
|
+
const relativePath = pathApi.relative(pathApi.dirname(sourceFile), resolvedPath).split(pathApi.sep).join(path.posix.sep);
|
|
12
|
+
return '.' === relativePath[0] ? relativePath : `./${relativePath}`;
|
|
13
|
+
};
|
|
7
14
|
const toEsmOutputPath = (resolvedPath)=>{
|
|
8
15
|
const sourcePath = findSourceEntry(resolvedPath) || resolvedPath;
|
|
9
16
|
const ext = path.extname(sourcePath);
|
|
@@ -11,8 +18,8 @@ const toEsmOutputPath = (resolvedPath)=>{
|
|
|
11
18
|
};
|
|
12
19
|
const resolveRelativeEsmSpecifier = (sourceFile, text)=>{
|
|
13
20
|
if (!text.startsWith('./') && !text.startsWith('../')) return;
|
|
14
|
-
const
|
|
15
|
-
return
|
|
21
|
+
const pathApi = pathApiFor(sourceFile);
|
|
22
|
+
return pathApi.resolve(pathApi.dirname(sourceFile), text);
|
|
16
23
|
};
|
|
17
24
|
const isRegExpKey = (str)=>str.startsWith('^') || str.endsWith('$');
|
|
18
25
|
const resolveAliasPath = (baseUrl, filePath)=>{
|
|
@@ -75,8 +82,7 @@ function getNotAliasedPath(sourceFile, matcher, text, moduleType) {
|
|
|
75
82
|
let result = findMatchedSourcePath(matcher, text);
|
|
76
83
|
if (!result && 'module' === moduleType) result = resolveRelativeEsmSpecifier(sourceFile, text);
|
|
77
84
|
if (!result) return;
|
|
78
|
-
if (
|
|
79
|
-
if (!path.isAbsolute(result)) {
|
|
85
|
+
if (!isAbsolutePath(result)) {
|
|
80
86
|
if (!result.startsWith('.') && !result.startsWith('..')) try {
|
|
81
87
|
const packagePath = require.resolve(result, {
|
|
82
88
|
paths: [
|
|
@@ -97,7 +103,6 @@ function getNotAliasedPath(sourceFile, matcher, text, moduleType) {
|
|
|
97
103
|
} catch {}
|
|
98
104
|
}
|
|
99
105
|
if ('module' === moduleType) result = toEsmOutputPath(result);
|
|
100
|
-
|
|
101
|
-
return '.' === resolvedPath[0] ? resolvedPath : `./${resolvedPath}`;
|
|
106
|
+
return toImportSpecifier(sourceFile, result) || './';
|
|
102
107
|
}
|
|
103
108
|
export { createTsconfigPathsMatcher, getNotAliasedPath };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CompileFunc } from '../../common';
|
|
2
2
|
type TsgoConfig = {
|
|
3
3
|
compilerOptions?: {
|
|
4
|
+
allowImportingTsExtensions?: boolean;
|
|
4
5
|
baseUrl?: unknown;
|
|
5
6
|
module?: string;
|
|
6
7
|
moduleResolution?: string;
|
|
@@ -8,6 +9,7 @@ type TsgoConfig = {
|
|
|
8
9
|
noEmitOnError?: boolean;
|
|
9
10
|
outDir?: string;
|
|
10
11
|
rootDir?: string;
|
|
12
|
+
rewriteRelativeImportExtensions?: boolean;
|
|
11
13
|
verbatimModuleSyntax?: boolean;
|
|
12
14
|
};
|
|
13
15
|
files?: string[];
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.4.0-ultramodern.
|
|
20
|
+
"version": "3.4.0-ultramodern.20",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@swc/helpers": "^0.5.23",
|
|
43
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.
|
|
43
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.20"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@rslib/core": "0.23.0",
|
|
47
47
|
"@types/node": "^26.0.1",
|
|
48
48
|
"@typescript/native-preview": "7.0.0-dev.20260624.1",
|
|
49
|
-
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.
|
|
49
|
+
"@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.20",
|
|
50
50
|
"@scripts/rstest-config": "2.66.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|