Skip to content

Commit

Permalink
feat: Add esbuild-register for typescript extensions (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasparus authored Apr 1, 2022
1 parent 57cd597 commit 963f5fa
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ var extensions = {
'typescript-register',
'typescript-require',
'sucrase/register/ts',
{
module: 'esbuild-register/dist/node',
register: function(mod) {
mod.register({
extensions: ['.ts'],
target: 'node' + process.version.slice(1),
});
},
},
{
module: '@babel/register',
register: function(hook) {
Expand All @@ -161,6 +170,15 @@ var extensions = {
'ts-node/register',
'typescript-node/register',
'sucrase/register',
{
module: 'esbuild-register/dist/node',
register: function(mod) {
mod.register({
extensions: ['.tsx'],
target: 'node' + process.version.slice(1),
});
},
},
{
module: '@babel/register',
register: function(hook) {
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/ts/6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"esbuild": "^0.14.29",
"esbuild-register": "^3.3.2"
}
}
13 changes: 13 additions & 0 deletions test/fixtures/ts/6/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function add(x: number, y: number): number {
return x + y;
}

export default {
data: {
trueKey: true,
falseKey: false,
subKey: {
subProp: add(0.5, 0.5),
},
},
};
7 changes: 7 additions & 0 deletions test/fixtures/tsx/4/data.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const data = {
trueKey: true,
falseKey: false,
subKey: {
subProp: 1,
},
};
6 changes: 6 additions & 0 deletions test/fixtures/tsx/4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"esbuild": "^0.14.29",
"esbuild-register": "^3.3.2"
}
}
11 changes: 11 additions & 0 deletions test/fixtures/tsx/4/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @jsx jsx */

import { data } from "./data";

const Component = (props: object) => ({ data: props });

function jsx(element: typeof Component, props: object) {
return element(props);
}

export default <Component {...data} />;

0 comments on commit 963f5fa

Please sign in to comment.