diff --git a/index.js b/index.js index aea15b0..aca5fcc 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,10 @@ var path = require('path'); var endsInTs = /\.ts$/; var endsInTsx = /\.tsx$/; var endsInBabelJs = /\.babel\.[jt]s(x)$/; +var endsInEsbuildJs = /\.esbuild\.js$/; +var endsInEsbuildJsx = /\.esbuild\.jsx$/; +var endsInEsbuildTs = /\.esbuild\.ts$/; +var endsInEsbuildTsx = /\.esbuild\.tsx$/; var mjsStub = path.join(__dirname, 'mjs-stub'); @@ -71,11 +75,59 @@ var extensions = { '.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], '.csv': 'require-csv', '.eg': 'earlgrey/register', + '.esbuild.js': { + module: 'esbuild-register/dist/node', + register: function(mod) { + mod.register({ + extensions: ['.js'], + target: 'node' + process.version.slice(1), + hookMatcher: function(file) { + return endsInEsbuildJs.test(file); + }, + }); + }, + }, + '.esbuild.jsx': { + module: 'esbuild-register/dist/node', + register: function(mod) { + mod.register({ + extensions: ['.jsx'], + target: 'node' + process.version.slice(1), + hookMatcher: function(file) { + return endsInEsbuildJsx.test(file); + }, + }); + }, + }, + '.esbuild.ts': { + module: 'esbuild-register/dist/node', + register: function(mod) { + mod.register({ + extensions: ['.ts'], + target: 'node' + process.version.slice(1), + hookMatcher: function(file) { + return endsInEsbuildTs.test(file); + }, + }); + }, + }, + '.esbuild.tsx': { + module: 'esbuild-register/dist/node', + register: function(mod) { + mod.register({ + extensions: ['.tsx'], + target: 'node' + process.version.slice(1), + hookMatcher: function(file) { + return endsInEsbuildTsx.test(file); + }, + }); + }, + }, '.esm.js': { module: 'esm', register: function(hook) { // register on .js extension due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353 - // which only captures the final extension (.babel.js -> .js) + // which only captures the final extension (.esm.js -> .js) var esmLoader = hook(module); require.extensions['.js'] = esmLoader('module')._extensions['.js']; }, diff --git a/test/fixtures/esbuild.js/0/package.json b/test/fixtures/esbuild.js/0/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/esbuild.js/0/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/esbuild.js/0/test.esbuild.js b/test/fixtures/esbuild.js/0/test.esbuild.js new file mode 100644 index 0000000..7e19ed6 --- /dev/null +++ b/test/fixtures/esbuild.js/0/test.esbuild.js @@ -0,0 +1,14 @@ +class Foo { + #x = 1 + #y = 2 +} + +export default { + data: { + trueKey: true, + falseKey: false, + subKey: { + subProp: 1, + }, + }, +}; diff --git a/test/fixtures/esbuild.jsx/0/package.json b/test/fixtures/esbuild.jsx/0/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/esbuild.jsx/0/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/esbuild.jsx/0/test.esbuild.jsx b/test/fixtures/esbuild.jsx/0/test.esbuild.jsx new file mode 100644 index 0000000..8d81afb --- /dev/null +++ b/test/fixtures/esbuild.jsx/0/test.esbuild.jsx @@ -0,0 +1,28 @@ +const React = { + createElement(Component) { + return Component() + } +} + +class Foo { + #x = 1 + #y = 2 +} + +function Bar() { + const foo = new Foo(); + + return foo; +} + +const a = + +export default { + data: { + trueKey: true, + falseKey: false, + subKey: { + subProp: 1, + }, + }, +}; diff --git a/test/fixtures/esbuild.ts/0/package.json b/test/fixtures/esbuild.ts/0/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/esbuild.ts/0/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/esbuild.ts/0/test.esbuild.ts b/test/fixtures/esbuild.ts/0/test.esbuild.ts new file mode 100644 index 0000000..3a027f2 --- /dev/null +++ b/test/fixtures/esbuild.ts/0/test.esbuild.ts @@ -0,0 +1,14 @@ +class Foo { + #x: number = 1 + #y: number = 2 +} + +export default { + data: { + trueKey: true as boolean, + falseKey: false as boolean, + subKey: { + subProp: 1, + }, + }, +} as const; diff --git a/test/fixtures/esbuild.tsx/0/package.json b/test/fixtures/esbuild.tsx/0/package.json new file mode 100644 index 0000000..b32c446 --- /dev/null +++ b/test/fixtures/esbuild.tsx/0/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "esbuild": "^0.14.29", + "esbuild-register": "^3.3.2" + } +} diff --git a/test/fixtures/esbuild.tsx/0/test.esbuild.tsx b/test/fixtures/esbuild.tsx/0/test.esbuild.tsx new file mode 100644 index 0000000..4215dfc --- /dev/null +++ b/test/fixtures/esbuild.tsx/0/test.esbuild.tsx @@ -0,0 +1,28 @@ +const React = { + createElement(Component) { + return Component() + } +} + +class Foo { + #x: number = 1 + #y: number = 2 +} + +function Bar() { + const foo = new Foo(); + + return foo; +} + +const a = + +export default { + data: { + trueKey: true as boolean, + falseKey: false as boolean, + subKey: { + subProp: 1, + }, + }, +} as const; diff --git a/test/index.js b/test/index.js index a878b6f..b0ccad2 100644 --- a/test/index.js +++ b/test/index.js @@ -156,6 +156,10 @@ describe('interpret.extensions', function() { case '.ts': case '.tsx': case '.esm.js': + case '.esbuild.js': + case '.esbuild.jsx': + case '.esbuild.ts': + case '.esbuild.tsx': expected = { default: { data: {