Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(register): tsx file #800

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.