Skip to content

Commit

Permalink
fix(register): tsx file (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn authored Jul 4, 2024
1 parent 714d3f2 commit 1071d8d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/integrate-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"devDependencies": {
"@swc/core": "^1.6.6",
"@swc-node/register": "workspace:*",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"typescript": "^5.5.3"
}
}
3 changes: 3 additions & 0 deletions packages/integrate-module/src/component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Component() {
return <div>Component</div>
}
6 changes: 6 additions & 0 deletions packages/integrate-module/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import test from 'node:test'

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

import { CompiledClass } from './compiled.js'
import { foo } from './foo.mjs'
import { bar } from './subdirectory/bar.mjs'
import { baz } from './subdirectory/index.mjs'
import { Component } from './component.js'
import './js-module.mjs'

await test('file-type should work', () => {
Expand All @@ -35,3 +37,7 @@ await test('compiled js file with .d.ts', () => {
const instance = new CompiledClass()
assert.equal(instance.name, 'CompiledClass')
})

await test('jsx should work', () => {
assert.equal(renderToString(Component()), '<div>Component</div>')
})
1 change: 1 addition & 0 deletions packages/integrate-module/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"target": "ESNext",
"module": "ESNext",
"composite": true,
"jsx": "react-jsx",
"outDir": "dist",
"baseUrl": "./",
"paths": {
Expand Down
5 changes: 2 additions & 3 deletions packages/register/esm.mts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const resolver = new ResolverFactory({
},
conditionNames: ['node', 'import'],
extensionAlias: {
'.js': ['.ts', '.js'],
'.js': ['.ts', '.tsx', '.js'],
'.mjs': ['.mts', '.mjs'],
'.cjs': ['.cts', '.cjs'],
},
Expand Down Expand Up @@ -192,8 +192,7 @@ export const resolve: ResolveHook = async (specifier, context, nextResolve) => {
)

if (error) {
console.error(error)
throw error
throw new Error(`${error}: ${specifier} cannot be resolved in ${context.parentURL}`)
}

// local project file
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1071d8d

Please sign in to comment.