Skip to content

Commit

Permalink
chore: Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored and actions-user committed Apr 7, 2022
1 parent 7b69c63 commit 9847d11
Show file tree
Hide file tree
Showing 33 changed files with 263 additions and 256 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
55 changes: 30 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -32,7 +37,7 @@ var extensions = {
},
'.babel.jsx': {
module: '@babel/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.jsx',
rootMode: 'upward-optional',
Expand All @@ -43,7 +48,7 @@ var extensions = {
'.babel.ts': [
{
module: '@babel/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.ts',
rootMode: 'upward-optional',
Expand All @@ -54,7 +59,7 @@ var extensions = {
],
'.babel.tsx': {
module: '@babel/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.tsx',
rootMode: 'upward-optional',
Expand All @@ -66,55 +71,55 @@ 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);
},
});
},
},
'.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);
},
});
},
},
'.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);
},
});
},
},
'.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);
},
});
},
},
'.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);
Expand All @@ -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',
Expand All @@ -139,7 +144,7 @@ var extensions = {
'.node': null,
'.toml': {
module: 'toml-require',
register: function(hook) {
register: function (hook) {
hook.install();
},
},
Expand All @@ -148,7 +153,7 @@ var extensions = {
'sucrase/register/ts',
{
module: '@babel/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.ts',
rootMode: 'upward-optional',
Expand All @@ -158,19 +163,19 @@ 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);
},
});
},
},
{
module: '@swc/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.ts',
only: [endsInTs],
Expand All @@ -184,7 +189,7 @@ var extensions = {
'sucrase/register',
{
module: '@babel/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.tsx',
rootMode: 'upward-optional',
Expand All @@ -194,19 +199,19 @@ 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);
},
});
},
},
{
module: '@swc/register',
register: function(hook) {
register: function (hook) {
hook({
extensions: '.tsx',
only: [endsInTsx],
Expand Down Expand Up @@ -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;
}, {}),
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/babel.js/0/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["@babel/preset-react"],
"presets": ["@babel/preset-react"]
}
2 changes: 1 addition & 1 deletion test/fixtures/babel.js/0/test.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 1 addition & 1 deletion test/fixtures/babel.jsx/0/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["@babel/preset-react"],
"presets": ["@babel/preset-react"]
}
2 changes: 1 addition & 1 deletion test/fixtures/babel.jsx/0/test.babel.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const React = {
createElement: function (Component) {
return Component();
}
},
};

// Test harmony arrow functions
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/babel.ts/0/test.babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
20 changes: 10 additions & 10 deletions test/fixtures/babel.tsx/0/data.babel.tsx
Original file line number Diff line number Diff line change
@@ -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;
20 changes: 10 additions & 10 deletions test/fixtures/babel.tsx/0/test.babel.tsx
Original file line number Diff line number Diff line change
@@ -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 <Component {...data} />
export default <Component {...data} />;
4 changes: 1 addition & 3 deletions test/fixtures/coffee.md/0/test.coffee.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
Test Fixture
============
# Test Fixture

module.exports =
data:
trueKey: true
falseKey: false
subKey:
subProp: 1
4 changes: 2 additions & 2 deletions test/fixtures/esbuild.js/0/test.esbuild.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Foo {
#x = 1
#y = 2
#x = 1;
#y = 2;
}

export default {
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/esbuild.jsx/0/test.esbuild.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const React = {
createElement(Component) {
return Component()
}
}
return Component();
},
};

class Foo {
#x = 1
#y = 2
#x = 1;
#y = 2;
}

function Bar() {
Expand All @@ -15,7 +15,7 @@ function Bar() {
return foo;
}

const a = <Bar />
const a = <Bar />;

export default {
data: {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/esbuild.ts/0/test.esbuild.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Foo {
#x: number = 1
#y: number = 2
#x: number = 1;
#y: number = 2;
}

export default {
Expand Down
Loading

0 comments on commit 9847d11

Please sign in to comment.