@bleedingdev/modern-js-server-utils 3.4.0-ultramodern.2 → 3.4.0-ultramodern.4

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.
@@ -238,6 +238,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
238
238
  }
239
239
  if (result.stderr) utils_namespaceObject.logger.error(result.stderr);
240
240
  if (result.stdout) utils_namespaceObject.logger.info(result.stdout);
241
+ await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
241
242
  if (0 !== result.code) {
242
243
  const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
243
244
  if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
@@ -248,7 +249,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
248
249
  ].filter(Boolean).join('\n'));
249
250
  } else process.exit(1);
250
251
  }
251
- await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
252
252
  for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
253
253
  utils_namespaceObject.logger.info("TS-Go compile succeed");
254
254
  };
@@ -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;
@@ -193,6 +193,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
193
193
  }
194
194
  if (result.stderr) logger.error(result.stderr);
195
195
  if (result.stdout) logger.info(result.stdout);
196
+ await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
196
197
  if (0 !== result.code) {
197
198
  const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
198
199
  if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
@@ -203,7 +204,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
203
204
  ].filter(Boolean).join('\n'));
204
205
  } else process.exit(1);
205
206
  }
206
- await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
207
207
  for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
208
208
  logger.info("TS-Go compile succeed");
209
209
  };
@@ -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 };
@@ -198,6 +198,7 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
198
198
  }
199
199
  if (result.stderr) logger.error(result.stderr);
200
200
  if (result.stdout) logger.info(result.stdout);
201
+ await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
201
202
  if (0 !== result.code) {
202
203
  const noEmitOnError = tsgoConfig.compilerOptions?.noEmitOnError;
203
204
  if (void 0 === noEmitOnError || true === noEmitOnError) if (compileOptions.throwErrorInsteadOfExit) {
@@ -208,7 +209,6 @@ const compileByTs = async (appDirectory, config, compileOptions)=>{
208
209
  ].filter(Boolean).join('\n'));
209
210
  } else process.exit(1);
210
211
  }
211
- await rewriteOutputSpecifiers(appDirectory, distDir, absoluteBaseUrl, paths, compileOptions.moduleType);
212
212
  for (const source of sourceDirs)await copyFiles(source, distDir, appDirectory);
213
213
  logger.info("TS-Go compile succeed");
214
214
  };
@@ -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 };
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.4.0-ultramodern.2",
20
+ "version": "3.4.0-ultramodern.4",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -40,14 +40,14 @@
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.2"
43
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.4"
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.2",
50
- "@scripts/rstest-config": "2.66.0"
49
+ "@scripts/rstest-config": "2.66.0",
50
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.4"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@typescript/native-preview": ">=7.0.0-dev.20260624.1"