@bleedingdev/modern-js-server-utils 3.4.0-ultramodern.1 → 3.4.0-ultramodern.10

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.
@@ -74,6 +74,8 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
74
74
  config.compilerOptions ??= {};
75
75
  config.compilerOptions.rootDir = appDirectory;
76
76
  config.compilerOptions.outDir = distDir;
77
+ config.compilerOptions.noEmit = false;
78
+ if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
77
79
  config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
78
80
  delete config.include;
79
81
  delete config.compilerOptions.baseUrl;
@@ -106,9 +108,11 @@ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
106
108
  const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(external_path_default().sep).join(external_path_default().posix.sep));
107
109
  return files.filter((fileName)=>{
108
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;
109
112
  return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
110
113
  });
111
114
  };
115
+ const isAppRouterGeneratedDeclaration = (absoluteFileName)=>/\/src\/modern-tanstack\/.*\.gen\.d\.ts$/u.test(absoluteFileName);
112
116
  const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
113
117
  const child = (0, external_child_process_namespaceObject.spawn)(process.execPath, [
114
118
  tsgoBinPath,
@@ -237,6 +241,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
237
241
  }
238
242
  if (result.stderr) utils_namespaceObject.logger.error(result.stderr);
239
243
  if (result.stdout) utils_namespaceObject.logger.info(result.stdout);
244
+ await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
240
245
  if (0 !== result.code) {
241
246
  const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
242
247
  if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
@@ -247,7 +252,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
247
252
  ].filter(Boolean).join('\n'));
248
253
  } else process.exit(1);
249
254
  }
250
- await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
251
255
  for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
252
256
  utils_namespaceObject.logger.info("TS-Go compile succeed");
253
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 importerDir = (0, external_path_namespaceObject.dirname)(sourceFile);
56
- return external_path_default().resolve(importerDir, text);
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 ('win32' === external_os_namespaceObject.platform()) result = result.replace(/\\/g, '/');
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
- const resolvedPath = external_path_namespaceObject.posix.relative((0, external_path_namespaceObject.dirname)(sourceFile), result) || './';
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;
@@ -29,6 +29,8 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
29
29
  config.compilerOptions ??= {};
30
30
  config.compilerOptions.rootDir = appDirectory;
31
31
  config.compilerOptions.outDir = distDir;
32
+ config.compilerOptions.noEmit = false;
33
+ if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
32
34
  config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
33
35
  delete config.include;
34
36
  delete config.compilerOptions.baseUrl;
@@ -61,9 +63,11 @@ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
61
63
  const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(path.sep).join(path.posix.sep));
62
64
  return files.filter((fileName)=>{
63
65
  const absoluteFileName = path.resolve(tsconfigDir, fileName).split(path.sep).join(path.posix.sep);
66
+ if (isAppRouterGeneratedDeclaration(absoluteFileName)) return false;
64
67
  return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
65
68
  });
66
69
  };
70
+ const isAppRouterGeneratedDeclaration = (absoluteFileName)=>/\/src\/modern-tanstack\/.*\.gen\.d\.ts$/u.test(absoluteFileName);
67
71
  const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
68
72
  const child = spawn(process.execPath, [
69
73
  tsgoBinPath,
@@ -192,6 +196,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
192
196
  }
193
197
  if (result.stderr) logger.error(result.stderr);
194
198
  if (result.stdout) logger.info(result.stdout);
199
+ await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
195
200
  if (0 !== result.code) {
196
201
  const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
197
202
  if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
@@ -202,7 +207,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
202
207
  ].filter(Boolean).join('\n'));
203
208
  } else process.exit(1);
204
209
  }
205
- await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
206
210
  for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
207
211
  logger.info("TS-Go compile succeed");
208
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, { dirname, posix } from "path";
4
- import * as __rspack_external_os from "os";
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 importerDir = dirname(sourceFile);
13
- return path.resolve(importerDir, text);
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 ('win32' === __rspack_external_os.platform()) result = result.replace(/\\/g, '/');
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
- const resolvedPath = posix.relative(dirname(sourceFile), result) || './';
99
- return '.' === resolvedPath[0] ? resolvedPath : `./${resolvedPath}`;
104
+ return toImportSpecifier(sourceFile, result) || './';
100
105
  }
101
106
  export { createTsconfigPathsMatcher, getNotAliasedPath };
@@ -34,6 +34,8 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
34
34
  config.compilerOptions ??= {};
35
35
  config.compilerOptions.rootDir = appDirectory;
36
36
  config.compilerOptions.outDir = distDir;
37
+ config.compilerOptions.noEmit = false;
38
+ if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
37
39
  config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
38
40
  delete config.include;
39
41
  delete config.compilerOptions.baseUrl;
@@ -66,9 +68,11 @@ const filterSourceFiles = (tsconfigDir, sourceDirs, files = [])=>{
66
68
  const sourcePosixPaths = sourceDirs.map((sourceDir)=>sourceDir.split(path.sep).join(path.posix.sep));
67
69
  return files.filter((fileName)=>{
68
70
  const absoluteFileName = path.resolve(tsconfigDir, fileName).split(path.sep).join(path.posix.sep);
71
+ if (isAppRouterGeneratedDeclaration(absoluteFileName)) return false;
69
72
  return fileName.endsWith('.d.ts') || sourcePosixPaths.some((sourceDir)=>absoluteFileName.includes(sourceDir));
70
73
  });
71
74
  };
75
+ const isAppRouterGeneratedDeclaration = (absoluteFileName)=>/\/src\/modern-tanstack\/.*\.gen\.d\.ts$/u.test(absoluteFileName);
72
76
  const runTsgo = (tsgoBinPath, args, options)=>new Promise((resolve, reject)=>{
73
77
  const child = spawn(process.execPath, [
74
78
  tsgoBinPath,
@@ -197,6 +201,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
197
201
  }
198
202
  if (result.stderr) logger.error(result.stderr);
199
203
  if (result.stdout) logger.info(result.stdout);
204
+ await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
200
205
  if (0 !== result.code) {
201
206
  const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
202
207
  if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
@@ -207,7 +212,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
207
212
  ].filter(Boolean).join('\n'));
208
213
  } else process.exit(1);
209
214
  }
210
- await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
211
215
  for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
212
216
  logger.info("TS-Go compile succeed");
213
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, { dirname, posix } from "path";
6
- import * as __rspack_external_os from "os";
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 importerDir = dirname(sourceFile);
15
- return path.resolve(importerDir, text);
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 ('win32' === __rspack_external_os.platform()) result = result.replace(/\\/g, '/');
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
- const resolvedPath = posix.relative(dirname(sourceFile), result) || './';
101
- return '.' === resolvedPath[0] ? resolvedPath : `./${resolvedPath}`;
106
+ return toImportSpecifier(sourceFile, result) || './';
102
107
  }
103
108
  export { createTsconfigPathsMatcher, getNotAliasedPath };
@@ -1,12 +1,15 @@
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
+ noEmit?: boolean;
7
9
  noEmitOnError?: boolean;
8
10
  outDir?: string;
9
11
  rootDir?: string;
12
+ rewriteRelativeImportExtensions?: boolean;
10
13
  verbatimModuleSyntax?: boolean;
11
14
  };
12
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.1",
20
+ "version": "3.4.0-ultramodern.10",
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.1"
43
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.10"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rslib/core": "0.23.0",
47
- "@types/node": "^26.0.0",
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.1",
49
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.10",
50
50
  "@scripts/rstest-config": "2.66.0"
51
51
  },
52
52
  "peerDependencies": {