Skip to content

Commit 1071d8d

Browse files
authored
fix(register): tsx file (#800)
1 parent 714d3f2 commit 1071d8d

File tree

6 files changed

+28
-3
lines changed

6 files changed

+28
-3
lines changed

packages/integrate-module/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"devDependencies": {
1111
"@swc/core": "^1.6.6",
1212
"@swc-node/register": "workspace:*",
13+
"@types/react": "^18.3.3",
14+
"@types/react-dom": "^18.3.0",
15+
"react": "^18.3.1",
16+
"react-dom": "^18.3.1",
1317
"typescript": "^5.5.3"
1418
}
1519
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function Component() {
2+
return <div>Component</div>
3+
}

packages/integrate-module/src/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import test from 'node:test'
44

55
import { bar as subBar } from '@subdirectory/bar.mjs'
66
import { supportedExtensions } from 'file-type'
7+
import { renderToString } from 'react-dom/server'
78

89
import { CompiledClass } from './compiled.js'
910
import { foo } from './foo.mjs'
1011
import { bar } from './subdirectory/bar.mjs'
1112
import { baz } from './subdirectory/index.mjs'
13+
import { Component } from './component.js'
1214
import './js-module.mjs'
1315

1416
await test('file-type should work', () => {
@@ -35,3 +37,7 @@ await test('compiled js file with .d.ts', () => {
3537
const instance = new CompiledClass()
3638
assert.equal(instance.name, 'CompiledClass')
3739
})
40+
41+
await test('jsx should work', () => {
42+
assert.equal(renderToString(Component()), '<div>Component</div>')
43+
})

packages/integrate-module/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"target": "ESNext",
55
"module": "ESNext",
66
"composite": true,
7+
"jsx": "react-jsx",
78
"outDir": "dist",
89
"baseUrl": "./",
910
"paths": {

packages/register/esm.mts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const resolver = new ResolverFactory({
3333
},
3434
conditionNames: ['node', 'import'],
3535
extensionAlias: {
36-
'.js': ['.ts', '.js'],
36+
'.js': ['.ts', '.tsx', '.js'],
3737
'.mjs': ['.mts', '.mjs'],
3838
'.cjs': ['.cts', '.cjs'],
3939
},
@@ -192,8 +192,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
192192
)
193193

194194
if (error) {
195-
console.error(error)
196-
throw error
195+
throw new Error(`${error}: ${specifier} cannot be resolved in ${context.parentURL}`)
197196
}
198197

199198
// local project file

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)