From 963f5fadb0b01a0640c52b68f4d76480fdbf70eb Mon Sep 17 00:00:00 2001 From: Piotr Monwid-Olechnowicz Date: Fri, 1 Apr 2022 23:51:57 +0200 Subject: [PATCH] feat: Add esbuild-register for typescript extensions (#77) --- index.js | 18 ++++++++++++++++++ test/fixtures/ts/6/package.json | 6 ++++++ test/fixtures/ts/6/test.ts | 13 +++++++++++++ test/fixtures/tsx/4/data.tsx | 7 +++++++ test/fixtures/tsx/4/package.json | 6 ++++++ test/fixtures/tsx/4/test.tsx | 11 +++++++++++ 6 files changed, 61 insertions(+) create mode 100644 test/fixtures/ts/6/package.json create mode 100644 test/fixtures/ts/6/test.ts create mode 100644 test/fixtures/tsx/4/data.tsx create mode 100644 test/fixtures/tsx/4/package.json create mode 100644 test/fixtures/tsx/4/test.tsx diff --git a/index.js b/index.js index 2a2b829..310f9e8 100644 --- a/index.js +++ b/index.js @@ -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) { @@ -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) { diff --git a/test/fixtures/ts/6/package.json b/test/fixtures/ts/6/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/ts/6/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/ts/6/test.ts b/test/fixtures/ts/6/test.ts new file mode 100644 index 0000000..2e3ed5d --- /dev/null +++ b/test/fixtures/ts/6/test.ts @@ -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), + }, + }, +}; diff --git a/test/fixtures/tsx/4/data.tsx b/test/fixtures/tsx/4/data.tsx new file mode 100644 index 0000000..0fd771f --- /dev/null +++ b/test/fixtures/tsx/4/data.tsx @@ -0,0 +1,7 @@ +export const data = { + trueKey: true, + falseKey: false, + subKey: { + subProp: 1, + }, +}; diff --git a/test/fixtures/tsx/4/package.json b/test/fixtures/tsx/4/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/tsx/4/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/tsx/4/test.tsx b/test/fixtures/tsx/4/test.tsx new file mode 100644 index 0000000..a5581e3 --- /dev/null +++ b/test/fixtures/tsx/4/test.tsx @@ -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 ;