@bleedingdev/modern-js-server-utils 3.5.0-ultramodern.97 → 3.5.0-ultramodern.99

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
  }
@@ -80,6 +82,7 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
80
82
  config.compilerOptions.emitDeclarationOnly = false;
81
83
  config.compilerOptions.incremental = false;
82
84
  config.compilerOptions.noEmit = false;
85
+ if (void 0 === config.compilerOptions.jsx || 'preserve' === config.compilerOptions.jsx) config.compilerOptions.jsx = 'react-jsx';
83
86
  delete config.compilerOptions.tsBuildInfoFile;
84
87
  if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
85
88
  config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
@@ -211,7 +214,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
211
214
  return content.replace(sourceMappingUrlRE, '');
212
215
  };
213
216
  const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
214
- if (0 === Object.keys(paths).length || !await utils_namespaceObject.fs.pathExists(distDir)) return;
217
+ if (!await utils_namespaceObject.fs.pathExists(distDir)) return;
215
218
  const matcher = (0, external_tsconfigPathsPlugin_js_namespaceObject.createTsconfigPathsMatcher)(baseUrl, paths);
216
219
  if (!matcher) return;
217
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
  }
@@ -35,6 +37,7 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
35
37
  config.compilerOptions.emitDeclarationOnly = false;
36
38
  config.compilerOptions.incremental = false;
37
39
  config.compilerOptions.noEmit = false;
40
+ if (void 0 === config.compilerOptions.jsx || 'preserve' === config.compilerOptions.jsx) config.compilerOptions.jsx = 'react-jsx';
38
41
  delete config.compilerOptions.tsBuildInfoFile;
39
42
  if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
40
43
  config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
@@ -166,7 +169,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
166
169
  return content.replace(sourceMappingUrlRE, '');
167
170
  };
168
171
  const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
169
- if (0 === Object.keys(paths).length || !await fs.pathExists(distDir)) return;
172
+ if (!await fs.pathExists(distDir)) return;
170
173
  const matcher = createTsconfigPathsMatcher(baseUrl, paths);
171
174
  if (!matcher) return;
172
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
  }
@@ -40,6 +42,7 @@ const createResolvedTsgoConfig = async (appDirectory, tsconfigPath, distDir, sou
40
42
  config.compilerOptions.emitDeclarationOnly = false;
41
43
  config.compilerOptions.incremental = false;
42
44
  config.compilerOptions.noEmit = false;
45
+ if (void 0 === config.compilerOptions.jsx || 'preserve' === config.compilerOptions.jsx) config.compilerOptions.jsx = 'react-jsx';
43
46
  delete config.compilerOptions.tsBuildInfoFile;
44
47
  if (true === config.compilerOptions.allowImportingTsExtensions) config.compilerOptions.rewriteRelativeImportExtensions = true;
45
48
  config.files = filterSourceFiles(tsconfigDir, sourceDirs, config.files);
@@ -171,7 +174,7 @@ const dropStaleSourceMap = async (outputFile, content)=>{
171
174
  return content.replace(sourceMappingUrlRE, '');
172
175
  };
173
176
  const rewriteOutputSpecifiers = async (appDirectory, distDir, baseUrl, paths, moduleType)=>{
174
- if (0 === Object.keys(paths).length || !await fs.pathExists(distDir)) return;
177
+ if (!await fs.pathExists(distDir)) return;
175
178
  const matcher = createTsconfigPathsMatcher(baseUrl, paths);
176
179
  if (!matcher) return;
177
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;
@@ -8,6 +8,7 @@ type TsgoConfig = {
8
8
  declarationMap?: boolean;
9
9
  emitDeclarationOnly?: boolean;
10
10
  incremental?: boolean;
11
+ jsx?: string;
11
12
  module?: string;
12
13
  moduleResolution?: string;
13
14
  noEmit?: boolean;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.97",
20
+ "version": "3.5.0-ultramodern.99",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -38,11 +38,11 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.97",
41
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.99",
42
42
  "@swc/helpers": "^0.5.23"
43
43
  },
44
44
  "devDependencies": {
45
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.97",
45
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.99",
46
46
  "@rslib/core": "0.23.2",
47
47
  "@scripts/rstest-config": "2.66.0",
48
48
  "@types/node": "^26.1.1",