diff --git a/README.md b/README.md
index 56f53ad..7bb799e 100644
--- a/README.md
+++ b/README.md
@@ -11,11 +11,13 @@
A dictionary of file extensions and associated module loaders.
## What is it
+
This is used by [Liftoff] to automatically require dependencies for configuration files, and by [rechoir] for registering module loaders.
## API
### extensions
+
Map file types to modules which provide a [require.extensions] loader.
```js
@@ -109,6 +111,7 @@ Map file types to modules which provide a [require.extensions] loader.
```
### jsVariants
+
Same as above, but only include the extensions which are javascript variants.
## How to use it
diff --git a/index.js b/index.js
index 1cabc4a..3492e61 100644
--- a/index.js
+++ b/index.js
@@ -16,13 +16,18 @@ var mjsStub = path.join(__dirname, 'mjs-stub');
// Not part of the above check because it seems broken
function isNodeModules(file) {
- return path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0;
+ return (
+ path
+ .relative(process.cwd(), file)
+ .split(path.sep)
+ .indexOf('node_modules') >= 0
+ );
}
var extensions = {
'.babel.js': {
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.js',
rootMode: 'upward-optional',
@@ -32,7 +37,7 @@ var extensions = {
},
'.babel.jsx': {
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.jsx',
rootMode: 'upward-optional',
@@ -43,7 +48,7 @@ var extensions = {
'.babel.ts': [
{
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.ts',
rootMode: 'upward-optional',
@@ -54,7 +59,7 @@ var extensions = {
],
'.babel.tsx': {
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.tsx',
rootMode: 'upward-optional',
@@ -66,11 +71,11 @@ var extensions = {
'.coffee.md': 'coffeescript/register',
'.esbuild.js': {
module: 'esbuild-register/dist/node',
- register: function(mod) {
+ register: function (mod) {
mod.register({
extensions: ['.js'],
target: 'node' + process.version.slice(1),
- hookMatcher: function(file) {
+ hookMatcher: function (file) {
return endsInEsbuildJs.test(file);
},
});
@@ -78,11 +83,11 @@ var extensions = {
},
'.esbuild.jsx': {
module: 'esbuild-register/dist/node',
- register: function(mod) {
+ register: function (mod) {
mod.register({
extensions: ['.jsx'],
target: 'node' + process.version.slice(1),
- hookMatcher: function(file) {
+ hookMatcher: function (file) {
return endsInEsbuildJsx.test(file);
},
});
@@ -90,11 +95,11 @@ var extensions = {
},
'.esbuild.ts': {
module: 'esbuild-register/dist/node',
- register: function(mod) {
+ register: function (mod) {
mod.register({
extensions: ['.ts'],
target: 'node' + process.version.slice(1),
- hookMatcher: function(file) {
+ hookMatcher: function (file) {
return endsInEsbuildTs.test(file);
},
});
@@ -102,11 +107,11 @@ var extensions = {
},
'.esbuild.tsx': {
module: 'esbuild-register/dist/node',
- register: function(mod) {
+ register: function (mod) {
mod.register({
extensions: ['.tsx'],
target: 'node' + process.version.slice(1),
- hookMatcher: function(file) {
+ hookMatcher: function (file) {
return endsInEsbuildTsx.test(file);
},
});
@@ -114,7 +119,7 @@ var extensions = {
},
'.esm.js': {
module: 'esm',
- register: function(hook) {
+ 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 (.esm.js -> .js)
var esmLoader = hook(module);
@@ -126,7 +131,7 @@ var extensions = {
'.json5': 'json5/lib/register',
'.jsx': {
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.jsx',
rootMode: 'upward-optional',
@@ -139,7 +144,7 @@ var extensions = {
'.node': null,
'.toml': {
module: 'toml-require',
- register: function(hook) {
+ register: function (hook) {
hook.install();
},
},
@@ -148,7 +153,7 @@ var extensions = {
'sucrase/register/ts',
{
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.ts',
rootMode: 'upward-optional',
@@ -158,11 +163,11 @@ var extensions = {
},
{
module: 'esbuild-register/dist/node',
- register: function(mod) {
+ register: function (mod) {
mod.register({
extensions: ['.ts'],
target: 'node' + process.version.slice(1),
- hookMatcher: function(file) {
+ hookMatcher: function (file) {
return endsInTs.test(file);
},
});
@@ -170,7 +175,7 @@ var extensions = {
},
{
module: '@swc/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.ts',
only: [endsInTs],
@@ -184,7 +189,7 @@ var extensions = {
'sucrase/register',
{
module: '@babel/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.tsx',
rootMode: 'upward-optional',
@@ -194,11 +199,11 @@ var extensions = {
},
{
module: 'esbuild-register/dist/node',
- register: function(mod) {
+ register: function (mod) {
mod.register({
extensions: ['.tsx'],
target: 'node' + process.version.slice(1),
- hookMatcher: function(file) {
+ hookMatcher: function (file) {
return endsInTsx.test(file);
},
});
@@ -206,7 +211,7 @@ var extensions = {
},
{
module: '@swc/register',
- register: function(hook) {
+ register: function (hook) {
hook({
extensions: '.tsx',
only: [endsInTsx],
@@ -241,7 +246,7 @@ var jsVariantExtensions = [
module.exports = {
extensions: extensions,
- jsVariants: jsVariantExtensions.reduce(function(result, ext) {
+ jsVariants: jsVariantExtensions.reduce(function (result, ext) {
result[ext] = extensions[ext];
return result;
}, {}),
diff --git a/test/fixtures/babel.js/0/.babelrc b/test/fixtures/babel.js/0/.babelrc
index 90bbf88..7dd5e9d 100644
--- a/test/fixtures/babel.js/0/.babelrc
+++ b/test/fixtures/babel.js/0/.babelrc
@@ -1,3 +1,3 @@
{
- "presets": ["@babel/preset-react"],
+ "presets": ["@babel/preset-react"]
}
diff --git a/test/fixtures/babel.js/0/test.babel.js b/test/fixtures/babel.js/0/test.babel.js
index e929c98..d399372 100644
--- a/test/fixtures/babel.js/0/test.babel.js
+++ b/test/fixtures/babel.js/0/test.babel.js
@@ -4,7 +4,7 @@ var fn = () => {
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
- return { data: { trueKey, falseKey, subKey}};
+ return { data: { trueKey, falseKey, subKey } };
};
module.exports = fn();
diff --git a/test/fixtures/babel.jsx/0/.babelrc b/test/fixtures/babel.jsx/0/.babelrc
index 90bbf88..7dd5e9d 100644
--- a/test/fixtures/babel.jsx/0/.babelrc
+++ b/test/fixtures/babel.jsx/0/.babelrc
@@ -1,3 +1,3 @@
{
- "presets": ["@babel/preset-react"],
+ "presets": ["@babel/preset-react"]
}
diff --git a/test/fixtures/babel.jsx/0/test.babel.jsx b/test/fixtures/babel.jsx/0/test.babel.jsx
index e9bb137..1e2bee9 100644
--- a/test/fixtures/babel.jsx/0/test.babel.jsx
+++ b/test/fixtures/babel.jsx/0/test.babel.jsx
@@ -1,7 +1,7 @@
const React = {
createElement: function (Component) {
return Component();
- }
+ },
};
// Test harmony arrow functions
diff --git a/test/fixtures/babel.ts/0/test.babel.ts b/test/fixtures/babel.ts/0/test.babel.ts
index e929c98..d399372 100644
--- a/test/fixtures/babel.ts/0/test.babel.ts
+++ b/test/fixtures/babel.ts/0/test.babel.ts
@@ -4,7 +4,7 @@ var fn = () => {
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
- return { data: { trueKey, falseKey, subKey}};
+ return { data: { trueKey, falseKey, subKey } };
};
module.exports = fn();
diff --git a/test/fixtures/babel.tsx/0/data.babel.tsx b/test/fixtures/babel.tsx/0/data.babel.tsx
index e41be4f..3fa0969 100644
--- a/test/fixtures/babel.tsx/0/data.babel.tsx
+++ b/test/fixtures/babel.tsx/0/data.babel.tsx
@@ -1,19 +1,19 @@
var test: {
data: {
- trueKey: boolean,
- falseKey: boolean,
+ trueKey: boolean;
+ falseKey: boolean;
subKey: {
- subProp: number
- }
- }
+ subProp: number;
+ };
+ };
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
-}
+ subProp: 1,
+ },
+ },
+};
-export default test
+export default test;
diff --git a/test/fixtures/babel.tsx/0/test.babel.tsx b/test/fixtures/babel.tsx/0/test.babel.tsx
index 7324803..207ed4d 100644
--- a/test/fixtures/babel.tsx/0/test.babel.tsx
+++ b/test/fixtures/babel.tsx/0/test.babel.tsx
@@ -1,20 +1,20 @@
-import data from "./data.babel"
+import data from './data.babel';
const React = {
createElement(Component: () => any) {
- return Component()
- }
-}
+ return Component();
+ },
+};
// Test harmony arrow functions.
const Component = () => {
- var trueKey: boolean = true
- var falseKey: boolean = false
- var subKey = { subProp: 1 }
+ var trueKey: boolean = true;
+ var falseKey: boolean = false;
+ var subKey = { subProp: 1 };
// Test harmony object short notation.
- return { data: { trueKey, falseKey, subKey } }
-}
+ return { data: { trueKey, falseKey, subKey } };
+};
// Test TSX syntax.
-export default
+export default ;
diff --git a/test/fixtures/coffee.md/0/test.coffee.md b/test/fixtures/coffee.md/0/test.coffee.md
index 42ada56..f4b5928 100644
--- a/test/fixtures/coffee.md/0/test.coffee.md
+++ b/test/fixtures/coffee.md/0/test.coffee.md
@@ -1,5 +1,4 @@
-Test Fixture
-============
+# Test Fixture
module.exports =
data:
@@ -7,4 +6,3 @@ Test Fixture
falseKey: false
subKey:
subProp: 1
-
diff --git a/test/fixtures/esbuild.js/0/test.esbuild.js b/test/fixtures/esbuild.js/0/test.esbuild.js
index 7e19ed6..5dfbff3 100644
--- a/test/fixtures/esbuild.js/0/test.esbuild.js
+++ b/test/fixtures/esbuild.js/0/test.esbuild.js
@@ -1,6 +1,6 @@
class Foo {
- #x = 1
- #y = 2
+ #x = 1;
+ #y = 2;
}
export default {
diff --git a/test/fixtures/esbuild.jsx/0/test.esbuild.jsx b/test/fixtures/esbuild.jsx/0/test.esbuild.jsx
index 8d81afb..448a430 100644
--- a/test/fixtures/esbuild.jsx/0/test.esbuild.jsx
+++ b/test/fixtures/esbuild.jsx/0/test.esbuild.jsx
@@ -1,12 +1,12 @@
const React = {
createElement(Component) {
- return Component()
- }
-}
+ return Component();
+ },
+};
class Foo {
- #x = 1
- #y = 2
+ #x = 1;
+ #y = 2;
}
function Bar() {
@@ -15,7 +15,7 @@ function Bar() {
return foo;
}
-const a =
+const a = ;
export default {
data: {
diff --git a/test/fixtures/esbuild.ts/0/test.esbuild.ts b/test/fixtures/esbuild.ts/0/test.esbuild.ts
index 3a027f2..9a0862f 100644
--- a/test/fixtures/esbuild.ts/0/test.esbuild.ts
+++ b/test/fixtures/esbuild.ts/0/test.esbuild.ts
@@ -1,6 +1,6 @@
class Foo {
- #x: number = 1
- #y: number = 2
+ #x: number = 1;
+ #y: number = 2;
}
export default {
diff --git a/test/fixtures/esbuild.tsx/0/test.esbuild.tsx b/test/fixtures/esbuild.tsx/0/test.esbuild.tsx
index 4215dfc..b76f379 100644
--- a/test/fixtures/esbuild.tsx/0/test.esbuild.tsx
+++ b/test/fixtures/esbuild.tsx/0/test.esbuild.tsx
@@ -1,12 +1,12 @@
const React = {
createElement(Component) {
- return Component()
- }
-}
+ return Component();
+ },
+};
class Foo {
- #x: number = 1
- #y: number = 2
+ #x: number = 1;
+ #y: number = 2;
}
function Bar() {
@@ -15,7 +15,7 @@ function Bar() {
return foo;
}
-const a =
+const a = ;
export default {
data: {
diff --git a/test/fixtures/esm.js/0/test.esm.js b/test/fixtures/esm.js/0/test.esm.js
index 6266742..4d6da4b 100644
--- a/test/fixtures/esm.js/0/test.esm.js
+++ b/test/fixtures/esm.js/0/test.esm.js
@@ -3,9 +3,9 @@ var test = {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
export default test;
diff --git a/test/fixtures/js/0/test.js b/test/fixtures/js/0/test.js
index 09ad00b..77bd74f 100644
--- a/test/fixtures/js/0/test.js
+++ b/test/fixtures/js/0/test.js
@@ -3,7 +3,7 @@ module.exports = {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
diff --git a/test/fixtures/json5/0/test.json5 b/test/fixtures/json5/0/test.json5
index 3b39a49..005efe8 100644
--- a/test/fixtures/json5/0/test.json5
+++ b/test/fixtures/json5/0/test.json5
@@ -1,10 +1,10 @@
{
- "data": {
- "trueKey": true,
- "falseKey": false,
- "subKey": {
- "subProp": 1
- }
- }
+ data: {
+ trueKey: true,
+ falseKey: false,
+ subKey: {
+ subProp: 1,
+ },
+ },
/* omg, a comment in json?? */
}
diff --git a/test/fixtures/jsx/0/test.jsx b/test/fixtures/jsx/0/test.jsx
index acfb81c..1e2bee9 100644
--- a/test/fixtures/jsx/0/test.jsx
+++ b/test/fixtures/jsx/0/test.jsx
@@ -1,7 +1,7 @@
const React = {
- createElement: function(Component){
+ createElement: function (Component) {
return Component();
- }
+ },
};
// Test harmony arrow functions
@@ -10,7 +10,7 @@ const Component = () => {
var falseKey = false;
var subKey = { subProp: 1 };
// Test harmony object short notation
- return { data: { trueKey, falseKey, subKey}};
+ return { data: { trueKey, falseKey, subKey } };
};
// Test JSX syntax
diff --git a/test/fixtures/mjs/0/test.mjs b/test/fixtures/mjs/0/test.mjs
index 4389305..eb9a129 100644
--- a/test/fixtures/mjs/0/test.mjs
+++ b/test/fixtures/mjs/0/test.mjs
@@ -3,7 +3,7 @@ export default {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
diff --git a/test/fixtures/mjs/1/test.mjs b/test/fixtures/mjs/1/test.mjs
index 09ad00b..77bd74f 100644
--- a/test/fixtures/mjs/1/test.mjs
+++ b/test/fixtures/mjs/1/test.mjs
@@ -3,7 +3,7 @@ module.exports = {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
diff --git a/test/fixtures/ts/0/test.ts b/test/fixtures/ts/0/test.ts
index c4c77e6..3fa0969 100644
--- a/test/fixtures/ts/0/test.ts
+++ b/test/fixtures/ts/0/test.ts
@@ -1,19 +1,19 @@
var test: {
data: {
- trueKey: boolean,
- falseKey: boolean,
+ trueKey: boolean;
+ falseKey: boolean;
subKey: {
- subProp: number
- }
- }
+ subProp: number;
+ };
+ };
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
export default test;
diff --git a/test/fixtures/ts/1/test.ts b/test/fixtures/ts/1/test.ts
index 46c3ac2..c755421 100644
--- a/test/fixtures/ts/1/test.ts
+++ b/test/fixtures/ts/1/test.ts
@@ -1,25 +1,25 @@
var test: {
data: {
- trueKey: boolean,
- falseKey: boolean,
+ trueKey: boolean;
+ falseKey: boolean;
subKey: {
- subProp: number
- }
- }
+ subProp: number;
+ };
+ };
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
var main: {
- default: typeof test
+ default: typeof test;
} = {
- default: test
+ default: test,
};
export = main;
diff --git a/test/fixtures/ts/2/component.ts b/test/fixtures/ts/2/component.ts
index 1ab6f87..d26bcf1 100644
--- a/test/fixtures/ts/2/component.ts
+++ b/test/fixtures/ts/2/component.ts
@@ -1,18 +1,18 @@
const React = {
createElement(Component: () => any) {
- return Component()
- }
-}
+ return Component();
+ },
+};
// Test harmony arrow functions.
const Component = () => {
- var trueKey: boolean = true
- var falseKey: boolean = false
- var subKey = { subProp: 1 }
+ var trueKey: boolean = true;
+ var falseKey: boolean = false;
+ var subKey = { subProp: 1 };
// Test harmony object short notation.
- return { data: { trueKey, falseKey, subKey } }
-}
+ return { data: { trueKey, falseKey, subKey } };
+};
// Test TSX syntax.
-export default
+export default ;
diff --git a/test/fixtures/ts/2/test.ts b/test/fixtures/ts/2/test.ts
index 5c3065b..28103e5 100644
--- a/test/fixtures/ts/2/test.ts
+++ b/test/fixtures/ts/2/test.ts
@@ -1,5 +1,5 @@
-import Component from "./component"
+import Component from './component';
-var test: typeof Component = { ...Component }
+var test: typeof Component = { ...Component };
-export default test
+export default test;
diff --git a/test/fixtures/ts/4/test.ts b/test/fixtures/ts/4/test.ts
index 9a955db..5044977 100644
--- a/test/fixtures/ts/4/test.ts
+++ b/test/fixtures/ts/4/test.ts
@@ -3,13 +3,13 @@ var test = {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
+ subProp: 1,
+ },
+ },
};
var main = {
- default: test
+ default: test,
};
export = main;
diff --git a/test/fixtures/tsx/0/test.tsx b/test/fixtures/tsx/0/test.tsx
index c52e28d..d26bcf1 100644
--- a/test/fixtures/tsx/0/test.tsx
+++ b/test/fixtures/tsx/0/test.tsx
@@ -1,18 +1,18 @@
const React = {
createElement(Component: () => any) {
- return Component()
- }
-}
+ return Component();
+ },
+};
// Test harmony arrow functions.
const Component = () => {
- var trueKey: boolean = true
- var falseKey: boolean = false
- var subKey = { subProp: 1 }
+ var trueKey: boolean = true;
+ var falseKey: boolean = false;
+ var subKey = { subProp: 1 };
// Test harmony object short notation.
- return { data: { trueKey, falseKey, subKey } }
+ return { data: { trueKey, falseKey, subKey } };
};
// Test TSX syntax.
-export default
+export default ;
diff --git a/test/fixtures/tsx/1/test.tsx b/test/fixtures/tsx/1/test.tsx
index c52e28d..d26bcf1 100644
--- a/test/fixtures/tsx/1/test.tsx
+++ b/test/fixtures/tsx/1/test.tsx
@@ -1,18 +1,18 @@
const React = {
createElement(Component: () => any) {
- return Component()
- }
-}
+ return Component();
+ },
+};
// Test harmony arrow functions.
const Component = () => {
- var trueKey: boolean = true
- var falseKey: boolean = false
- var subKey = { subProp: 1 }
+ var trueKey: boolean = true;
+ var falseKey: boolean = false;
+ var subKey = { subProp: 1 };
// Test harmony object short notation.
- return { data: { trueKey, falseKey, subKey } }
+ return { data: { trueKey, falseKey, subKey } };
};
// Test TSX syntax.
-export default
+export default ;
diff --git a/test/fixtures/tsx/2/data.tsx b/test/fixtures/tsx/2/data.tsx
index e41be4f..3fa0969 100644
--- a/test/fixtures/tsx/2/data.tsx
+++ b/test/fixtures/tsx/2/data.tsx
@@ -1,19 +1,19 @@
var test: {
data: {
- trueKey: boolean,
- falseKey: boolean,
+ trueKey: boolean;
+ falseKey: boolean;
subKey: {
- subProp: number
- }
- }
+ subProp: number;
+ };
+ };
} = {
data: {
trueKey: true,
falseKey: false,
subKey: {
- subProp: 1
- }
- }
-}
+ subProp: 1,
+ },
+ },
+};
-export default test
+export default test;
diff --git a/test/fixtures/tsx/2/test.tsx b/test/fixtures/tsx/2/test.tsx
index fb1c6d4..d1b2de4 100644
--- a/test/fixtures/tsx/2/test.tsx
+++ b/test/fixtures/tsx/2/test.tsx
@@ -1,20 +1,20 @@
-import data from "./data"
+import data from './data';
const React = {
createElement(Component: () => any) {
- return Component()
- }
-}
+ return Component();
+ },
+};
// Test harmony arrow functions.
const Component = () => {
- var trueKey: boolean = true
- var falseKey: boolean = false
- var subKey = { subProp: 1 }
+ var trueKey: boolean = true;
+ var falseKey: boolean = false;
+ var subKey = { subProp: 1 };
// Test harmony object short notation.
- return { data: { trueKey, falseKey, subKey } }
-}
+ return { data: { trueKey, falseKey, subKey } };
+};
// Test TSX syntax.
-export default
+export default ;
diff --git a/test/fixtures/tsx/3/data.tsx b/test/fixtures/tsx/3/data.tsx
index e2af2a8..c75e132 100644
--- a/test/fixtures/tsx/3/data.tsx
+++ b/test/fixtures/tsx/3/data.tsx
@@ -1,9 +1,9 @@
export const data: {
- trueKey: boolean,
- falseKey: boolean,
+ trueKey: boolean;
+ falseKey: boolean;
subKey: {
- subProp: number
- }
+ subProp: number;
+ };
} = {
trueKey: true,
falseKey: false,
diff --git a/test/fixtures/tsx/3/test.tsx b/test/fixtures/tsx/3/test.tsx
index a5581e3..895dd00 100644
--- a/test/fixtures/tsx/3/test.tsx
+++ b/test/fixtures/tsx/3/test.tsx
@@ -1,6 +1,6 @@
/** @jsx jsx */
-import { data } from "./data";
+import { data } from './data';
const Component = (props: object) => ({ data: props });
diff --git a/test/fixtures/tsx/4/test.tsx b/test/fixtures/tsx/4/test.tsx
index c52e28d..d26bcf1 100644
--- a/test/fixtures/tsx/4/test.tsx
+++ b/test/fixtures/tsx/4/test.tsx
@@ -1,18 +1,18 @@
const React = {
createElement(Component: () => any) {
- return Component()
- }
-}
+ return Component();
+ },
+};
// Test harmony arrow functions.
const Component = () => {
- var trueKey: boolean = true
- var falseKey: boolean = false
- var subKey = { subProp: 1 }
+ var trueKey: boolean = true;
+ var falseKey: boolean = false;
+ var subKey = { subProp: 1 };
// Test harmony object short notation.
- return { data: { trueKey, falseKey, subKey } }
+ return { data: { trueKey, falseKey, subKey } };
};
// Test TSX syntax.
-export default
+export default ;
diff --git a/test/index.js b/test/index.js
index f56f402..2b26eab 100644
--- a/test/index.js
+++ b/test/index.js
@@ -12,7 +12,7 @@ var extensions = require('../').extensions;
// Save the original Module._extensions
var originalExtensions = Object.keys(Module._extensions);
-var original = originalExtensions.reduce(function(result, key) {
+var original = originalExtensions.reduce(function (result, key) {
result[key] = require.extensions[key];
return result;
}, {});
@@ -52,13 +52,12 @@ var minVersions = {};
var maxVersions = {};
-describe('interpret.extensions', function() {
-
+describe('interpret.extensions', function () {
beforeEach(cleanup);
var exts = Object.keys(extensions);
- var attempts = exts.reduce(function(attempts, ext) {
+ var attempts = exts.reduce(function (attempts, ext) {
var modules = extensions[ext];
if (!Array.isArray(modules)) {
modules = [modules];
@@ -75,7 +74,7 @@ describe('interpret.extensions', function() {
return attempts;
}
- modules.forEach(function(mod, idx) {
+ modules.forEach(function (mod, idx) {
if (mod && typeof mod !== 'string') {
mod = mod.module;
}
@@ -99,7 +98,7 @@ describe('interpret.extensions', function() {
return attempts;
}, []);
- attempts.forEach(function(attempt) {
+ attempts.forEach(function (attempt) {
var extension = attempt.extension;
var module = attempt.module;
var name = attempt.name;
@@ -107,58 +106,84 @@ describe('interpret.extensions', function() {
var fixtureDir = path.dirname(fixture);
var idx = attempt.index;
- it('can require ' + extension + ' using ' + name + ' (' + idx + ')', function(done) {
- var minVersion = minVersions[module];
-
- if (minVersion) {
- if (nodeVersion.major === 0 && nodeVersion.minor < minVersion.minor) {
- this.skip();
- } else if (nodeVersion.major < minVersion.major) {
- this.skip();
+ it(
+ 'can require ' + extension + ' using ' + name + ' (' + idx + ')',
+ function (done) {
+ var minVersion = minVersions[module];
+
+ if (minVersion) {
+ if (nodeVersion.major === 0 && nodeVersion.minor < minVersion.minor) {
+ this.skip();
+ } else if (nodeVersion.major < minVersion.major) {
+ this.skip();
+ }
}
- }
- var maxVersion = maxVersions[module];
+ var maxVersion = maxVersions[module];
- if (maxVersion) {
- if (nodeVersion.major > maxVersion.major) {
- this.skip();
+ if (maxVersion) {
+ if (nodeVersion.major > maxVersion.major) {
+ this.skip();
+ }
}
- }
- // Skip any swc test on linux due to https://github.com/swc-project/swc/issues/4107
- if (name === '@swc/register' && process.platform === 'linux') {
- this.skip();
- }
+ // Skip any swc test on linux due to https://github.com/swc-project/swc/issues/4107
+ if (name === '@swc/register' && process.platform === 'linux') {
+ this.skip();
+ }
- this.timeout(0);
+ this.timeout(0);
- var expected;
+ var expected;
- process.chdir(path.join(__dirname, fixtureDir));
+ process.chdir(path.join(__dirname, fixtureDir));
- shell.exec('rm -r node_modules', { silent: true });
- shell.exec('rm package-lock.json', { silent: true });
- shell.exec('npm install', { silent: true });
+ shell.exec('rm -r node_modules', { silent: true });
+ shell.exec('rm package-lock.json', { silent: true });
+ shell.exec('npm install', { silent: true });
- try {
- rechoir.prepare(extensions, fixture);
- } catch (err) {
- console.error(err.failures);
- throw err;
- }
+ try {
+ rechoir.prepare(extensions, fixture);
+ } catch (err) {
+ console.error(err.failures);
+ throw err;
+ }
- switch (extension) {
- case '.ts':
- case '.tsx':
- case '.esm.js':
- case '.babel.tsx':
- case '.esbuild.js':
- case '.esbuild.jsx':
- case '.esbuild.ts':
- case '.esbuild.tsx':
- expected = {
- default: {
+ switch (extension) {
+ case '.ts':
+ case '.tsx':
+ case '.esm.js':
+ case '.babel.tsx':
+ case '.esbuild.js':
+ case '.esbuild.jsx':
+ case '.esbuild.ts':
+ case '.esbuild.tsx':
+ expected = {
+ default: {
+ data: {
+ trueKey: true,
+ falseKey: false,
+ subKey: {
+ subProp: 1,
+ },
+ },
+ },
+ };
+ expect(require(fixture)).toEqual(expected);
+ break;
+
+ case '.toml':
+ expected = Object.create(null);
+ expected.data = Object.create(null);
+ expected.data.trueKey = true;
+ expected.data.falseKey = false;
+ expected.data.subKey = Object.create(null);
+ expected.data.subKey.subProp = 1;
+ expect(require(fixture)).toEqual(expected);
+ break;
+
+ default:
+ expected = {
data: {
trueKey: true,
falseKey: false,
@@ -166,38 +191,15 @@ describe('interpret.extensions', function() {
subProp: 1,
},
},
- },
- };
- expect(require(fixture)).toEqual(expected);
- break;
-
- case '.toml':
- expected = Object.create(null);
- expected.data = Object.create(null);
- expected.data.trueKey = true;
- expected.data.falseKey = false;
- expected.data.subKey = Object.create(null);
- expected.data.subKey.subProp = 1;
- expect(require(fixture)).toEqual(expected);
- break;
-
- default:
- expected = {
- data: {
- trueKey: true,
- falseKey: false,
- subKey: {
- subProp: 1,
- },
- },
- };
- expect(require(fixture)).toEqual(expected);
+ };
+ expect(require(fixture)).toEqual(expected);
+ }
+ done();
}
- done();
- });
+ );
});
- it('does not error with the .mjs extension', function(done) {
+ it('does not error with the .mjs extension', function (done) {
var ext = '.mjs';
var fixture = './fixtures/' + ext.slice(1) + '/0/test' + ext;
@@ -208,7 +210,7 @@ describe('interpret.extensions', function() {
done();
});
- it('the module can be loaded with import(), ignoring the loader', function() {
+ it('the module can be loaded with import(), ignoring the loader', function () {
if (nodeVersion.major < 12) {
this.skip();
}
@@ -231,13 +233,12 @@ describe('interpret.extensions', function() {
// This avoid SyntaxError when parsing on old node versions
var imprt = new Function('a', 'return import(a)');
- return imprt(fixture)
- .then(function(result) {
- expect(result.default).toEqual(expected);
- });
+ return imprt(fixture).then(function (result) {
+ expect(result.default).toEqual(expected);
+ });
});
- it('stubs .mjs extension with null on old node that do not care about it', function(done) {
+ it('stubs .mjs extension with null on old node that do not care about it', function (done) {
if (nodeVersion.major > 10) {
this.skip();
}