@bleedingdev/modern-js-server-utils 3.5.0-ultramodern.10 → 3.5.0-ultramodern.101

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.
@@ -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
- if (terminated && isSpecifierContext(prev1, prev2, prev3)) specifiers.push({
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
- '.js'
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',
@@ -204,7 +214,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
204
214
  return content.replace(sourceMappingUrlRE, '');
205
215
  };
206
216
  const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
207
- if (0 === Object.keys(paths).length || !await utils_namespaceObject.fs.pathExists(distDir)) return;
217
+ if (!await utils_namespaceObject.fs.pathExists(distDir)) return;
208
218
  const matcher = (0, external_tsconfigPathsPlugin_js_namespaceObject.createTsconfigPathsMatcher)(baseUrl, paths);
209
219
  if (!matcher) return;
210
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
- return ext ? `${sourcePath.slice(0, -ext.length)}.js` : `${sourcePath}.js`;
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
- if (terminated && isSpecifierContext(prev1, prev2, prev3)) specifiers.push({
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
- '.js'
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',
@@ -159,7 +169,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
159
169
  return content.replace(sourceMappingUrlRE, '');
160
170
  };
161
171
  const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
162
- if (0 === Object.keys(paths).length || !await fs.pathExists(distDir)) return;
172
+ if (!await fs.pathExists(distDir)) return;
163
173
  const matcher = createTsconfigPathsMatcher(baseUrl, paths);
164
174
  if (!matcher) return;
165
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
- return ext ? `${sourcePath.slice(0, -ext.length)}.js` : `${sourcePath}.js`;
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
- if (terminated && isSpecifierContext(prev1, prev2, prev3)) specifiers.push({
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)
@@ -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
- '.js'
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',
@@ -164,7 +174,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
164
174
  return content.replace(sourceMappingUrlRE, '');
165
175
  };
166
176
  const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
167
- if (0 === Object.keys(paths).length || !await fs.pathExists(distDir)) return;
177
+ if (!await fs.pathExists(distDir)) return;
168
178
  const matcher = createTsconfigPathsMatcher(baseUrl, paths);
169
179
  if (!matcher) return;
170
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
- return ext ? `${sourcePath.slice(0, -ext.length)}.js` : `${sourcePath}.js`;
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
- export type SpecifierRewrite = (specifier: string) => string | undefined;
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.10",
20
+ "version": "3.5.0-ultramodern.101",
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,15 +38,15 @@
39
38
  }
40
39
  },
41
40
  "dependencies": {
42
- "@swc/helpers": "^0.5.23",
43
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.10"
41
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.101",
42
+ "@swc/helpers": "^0.5.23"
44
43
  },
45
44
  "devDependencies": {
46
- "@rslib/core": "0.23.1",
47
- "@types/node": "^26.0.1",
48
- "@typescript/native-preview": "7.0.0-dev.20260628.1",
45
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.101",
46
+ "@rslib/core": "0.23.2",
49
47
  "@scripts/rstest-config": "2.66.0",
50
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.10"
48
+ "@types/node": "^26.1.1",
49
+ "@typescript/native-preview": "7.0.0-dev.20260707.2"
51
50
  },
52
51
  "peerDependencies": {
53
52
  "@typescript/native-preview": ">=7.0.0-dev.20260628.1"
@@ -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": {