Comparing version 2.2.0 to 3.0.0
592
index.js
var path = require('path'); | ||
var endsInBabelJs = /\.babel\.[jt]s(x)$/; | ||
// We only register on the final extension (like `.js`) due to https://github.com/joyent/node/blob/v0.12.0/lib/module.js#L353 | ||
// However, we use these matchers to apply the transform only if the full extension matches | ||
function endsInJsx(filename) { | ||
return filename.endsWith('.jsx'); | ||
} | ||
function endsInTs(filename) { | ||
return filename.endsWith('.ts'); | ||
} | ||
function endsInTsx(filename) { | ||
return filename.endsWith('.tsx'); | ||
} | ||
function endsInBabelJs(filename) { | ||
return filename.endsWith('.babel.js'); | ||
} | ||
function endsInBabelJsx(filename) { | ||
return filename.endsWith('.babel.jsx'); | ||
} | ||
function endsInBabelTs(filename) { | ||
return filename.endsWith('.babel.ts'); | ||
} | ||
function endsInBabelTsx(filename) { | ||
return filename.endsWith('.babel.tsx'); | ||
} | ||
function endsInEsbuildJs(filename) { | ||
return filename.endsWith('.esbuild.js'); | ||
} | ||
function endsInEsbuildJsx(filename) { | ||
return filename.endsWith('.esbuild.jsx'); | ||
} | ||
function endsInEsbuildTs(filename) { | ||
return filename.endsWith('.esbuild.ts'); | ||
} | ||
function endsInEsbuildTsx(filename) { | ||
return filename.endsWith('.esbuild.tsx'); | ||
} | ||
function endsInSucraseJs(filename) { | ||
return filename.endsWith('.sucrase.js'); | ||
} | ||
function endsInSucraseJsx(filename) { | ||
return filename.endsWith('.sucrase.jsx'); | ||
} | ||
function endsInSucraseTs(filename) { | ||
return filename.endsWith('.sucrase.ts'); | ||
} | ||
function endsInSucraseTsx(filename) { | ||
return filename.endsWith('.sucrase.tsx'); | ||
} | ||
function endsInSwcJs(filename) { | ||
return filename.endsWith('.swc.js'); | ||
} | ||
function endsInSwcJsx(filename) { | ||
return filename.endsWith('.swc.jsx'); | ||
} | ||
function endsInSwcTs(filename) { | ||
return filename.endsWith('.swc.ts'); | ||
} | ||
function endsInSwcTsx(filename) { | ||
return filename.endsWith('.swc.tsx'); | ||
} | ||
var cjsStub = path.join(__dirname, 'cjs-stub'); | ||
var mjsStub = path.join(__dirname, 'mjs-stub'); | ||
function ignoreNonBabelAndNodeModules(file) { | ||
return !endsInBabelJs.test(file) && | ||
path.relative(process.cwd(), file).split(path.sep).indexOf('node_modules') >= 0; | ||
function isNodeModules(file) { | ||
return path.relative(process.cwd(), file).includes('node_modules'); | ||
} | ||
var extensions = { | ||
'.babel.js': [ | ||
'.babel.js': { | ||
module: '@babel/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
overrides: [{ only: [endsInBabelJs], presets: ['@babel/preset-env'] }], | ||
}; | ||
hook(Object.assign({}, config, { extensions: '.js' })); | ||
}, | ||
}, | ||
'.babel.jsx': { | ||
module: '@babel/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
overrides: [ | ||
{ | ||
only: [endsInBabelJsx], | ||
presets: ['@babel/preset-env', '@babel/preset-react'], | ||
}, | ||
], | ||
}; | ||
hook(Object.assign({}, config, { extensions: '.jsx' })); | ||
}, | ||
}, | ||
'.babel.ts': [ | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
overrides: [ | ||
{ | ||
only: [endsInBabelTs], | ||
presets: ['@babel/preset-env', '@babel/preset-typescript'], | ||
}, | ||
], | ||
}; | ||
hook(Object.assign({}, config, { extensions: '.ts' })); | ||
}, | ||
}, | ||
{ | ||
module: 'babel-register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
], | ||
'.babel.tsx': { | ||
module: '@babel/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
overrides: [ | ||
{ | ||
only: [endsInBabelTsx], | ||
presets: [ | ||
'@babel/preset-env', | ||
'@babel/preset-react', | ||
[ | ||
'@babel/preset-typescript', | ||
{ | ||
isTSX: true, | ||
allExtensions: true, | ||
}, | ||
], | ||
], | ||
}, | ||
], | ||
}; | ||
hook(Object.assign({}, config, { extensions: '.tsx' })); | ||
}, | ||
{ | ||
module: 'babel-core/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
'.cjs': cjsStub, | ||
'.coffee': 'coffeescript/register', | ||
'.coffee.md': 'coffeescript/register', | ||
'.esbuild.js': { | ||
module: 'esbuild-register/dist/node', | ||
register: function (mod, config) { | ||
config = config || { | ||
target: 'node' + process.version.slice(1), | ||
hookMatcher: endsInEsbuildJs, | ||
}; | ||
mod.register(Object.assign({}, config, { extensions: ['.js'] })); | ||
}, | ||
{ | ||
module: 'babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
'.esbuild.jsx': { | ||
module: 'esbuild-register/dist/node', | ||
register: function (mod, config) { | ||
config = config || { | ||
target: 'node' + process.version.slice(1), | ||
hookMatcher: endsInEsbuildJsx, | ||
}; | ||
mod.register(Object.assign({}, config, { extensions: ['.jsx'] })); | ||
}, | ||
], | ||
'.babel.ts': [ | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.ts', | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
}, | ||
}, | ||
'.esbuild.ts': { | ||
module: 'esbuild-register/dist/node', | ||
register: function (mod, config) { | ||
config = config || { | ||
target: 'node' + process.version.slice(1), | ||
hookMatcher: endsInEsbuildTs, | ||
}; | ||
mod.register(Object.assign({}, config, { extensions: ['.ts'] })); | ||
}, | ||
], | ||
'.buble.js': 'buble/register', | ||
'.cirru': 'cirru-script/lib/register', | ||
'.cjsx': 'node-cjsx/register', | ||
'.co': 'coco', | ||
'.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], | ||
'.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], | ||
'.csv': 'require-csv', | ||
'.eg': 'earlgrey/register', | ||
}, | ||
'.esbuild.tsx': { | ||
module: 'esbuild-register/dist/node', | ||
register: function (mod, config) { | ||
config = config || { | ||
target: 'node' + process.version.slice(1), | ||
hookMatcher: endsInEsbuildTsx, | ||
}; | ||
mod.register(Object.assign({}, config, { extensions: ['.tsx'] })); | ||
}, | ||
}, | ||
'.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 (.babel.js -> .js) | ||
// which only captures the final extension (.esm.js -> .js) | ||
var esmLoader = hook(module); | ||
@@ -81,62 +198,168 @@ require.extensions['.js'] = esmLoader('module')._extensions['.js']; | ||
}, | ||
'.iced': ['iced-coffee-script/register', 'iced-coffee-script'], | ||
'.iced.md': 'iced-coffee-script/register', | ||
'.ini': 'require-ini', | ||
'.js': null, | ||
'.json': null, | ||
'.json5': ['json5/lib/register', 'json5/lib/require'], | ||
'.json5': 'json5/lib/register', | ||
'.jsx': [ | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
overrides: [ | ||
{ | ||
only: [endsInJsx], | ||
presets: ['@babel/preset-env', '@babel/preset-react'], | ||
}, | ||
], | ||
}; | ||
hook(Object.assign({}, config, { extensions: '.jsx' })); | ||
}, | ||
}, | ||
{ | ||
module: 'babel-register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
'sucrase/register/jsx', | ||
], | ||
'.litcoffee': 'coffeescript/register', | ||
// The mdx loader hooks both `.md` and `.mdx` when it is imported | ||
// but we only install the hook if `.mdx` is the first file | ||
'.mdx': '@mdx-js/register', | ||
'.mjs': mjsStub, | ||
'.node': null, | ||
'.sucrase.js': { | ||
module: 'sucrase/dist/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
matcher: endsInSucraseJs, | ||
}; | ||
hook.registerJS(config); | ||
}, | ||
{ | ||
module: 'babel-core/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
'.sucrase.jsx': { | ||
module: 'sucrase/dist/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
matcher: endsInSucraseJsx, | ||
}; | ||
hook.registerJSX(config); | ||
}, | ||
{ | ||
module: 'babel/register', | ||
register: function(hook) { | ||
hook({ | ||
}, | ||
'.sucrase.ts': { | ||
module: 'sucrase/dist/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
matcher: endsInSucraseTs, | ||
}; | ||
hook.registerTS(config); | ||
}, | ||
}, | ||
'.sucrase.tsx': { | ||
module: 'sucrase/dist/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
matcher: endsInSucraseTsx, | ||
}; | ||
hook.registerTSX(config); | ||
}, | ||
}, | ||
'.swc.js': { | ||
module: '@swc/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
only: [endsInSwcJs], | ||
ignore: [isNodeModules], | ||
jsc: { | ||
parser: { | ||
syntax: 'ecmascript', | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.js', | ||
}) | ||
); | ||
}, | ||
}, | ||
'.swc.jsx': { | ||
module: '@swc/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
only: [endsInSwcJsx], | ||
ignore: [isNodeModules], | ||
jsc: { | ||
parser: { | ||
syntax: 'ecmascript', | ||
jsx: true, | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.jsx', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}) | ||
); | ||
}, | ||
{ | ||
module: 'node-jsx', | ||
register: function(hook) { | ||
hook.install({ extension: '.jsx', harmony: true }); | ||
}, | ||
}, | ||
'.swc.ts': { | ||
module: '@swc/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
only: [endsInSwcTs], | ||
ignore: [isNodeModules], | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.ts', | ||
}) | ||
); | ||
}, | ||
], | ||
'.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], | ||
'.liticed': 'iced-coffee-script/register', | ||
'.ls': ['livescript', 'LiveScript'], | ||
'.mjs': mjsStub, | ||
'.node': null, | ||
}, | ||
'.swc.tsx': { | ||
module: '@swc/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
only: [endsInSwcTsx], | ||
ignore: [isNodeModules], | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
tsx: true, | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.tsx', | ||
}) | ||
); | ||
}, | ||
}, | ||
'.toml': { | ||
module: 'toml-require', | ||
register: function(hook) { | ||
hook.install(); | ||
register: function (hook, config) { | ||
hook.install(config); | ||
}, | ||
@@ -146,36 +369,137 @@ }, | ||
'ts-node/register', | ||
'typescript-node/register', | ||
'typescript-register', | ||
'typescript-require', | ||
'sucrase/register/ts', | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.ts', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
overrides: [ | ||
{ | ||
only: [endsInTs], | ||
presets: ['@babel/preset-env', '@babel/preset-typescript'], | ||
}, | ||
], | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.ts', | ||
}) | ||
); | ||
}, | ||
}, | ||
{ | ||
module: 'esbuild-register/dist/node', | ||
register: function (mod, config) { | ||
config = config || { | ||
target: 'node' + process.version.slice(1), | ||
hookMatcher: endsInTs, | ||
}; | ||
mod.register( | ||
Object.assign({}, config, { | ||
extensions: ['.ts'], | ||
}) | ||
); | ||
}, | ||
}, | ||
{ | ||
module: '@swc/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
only: [endsInTs], | ||
ignore: [isNodeModules], | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.ts', | ||
}) | ||
); | ||
}, | ||
}, | ||
], | ||
'.tsx': [ | ||
'ts-node/register', | ||
'typescript-node/register', | ||
'sucrase/register', | ||
'sucrase/register/tsx', | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.tsx', | ||
register: function (hook, config) { | ||
config = config || { | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
overrides: [ | ||
{ | ||
only: [endsInTsx], | ||
presets: [ | ||
'@babel/preset-env', | ||
'@babel/preset-react', | ||
[ | ||
'@babel/preset-typescript', | ||
{ | ||
isTSX: true, | ||
allExtensions: true, | ||
}, | ||
], | ||
], | ||
}, | ||
], | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.tsx', | ||
}) | ||
); | ||
}, | ||
}, | ||
{ | ||
module: 'esbuild-register/dist/node', | ||
register: function (mod, config) { | ||
config = config || { | ||
target: 'node' + process.version.slice(1), | ||
hookMatcher: endsInTsx, | ||
}; | ||
mod.register( | ||
Object.assign({}, config, { | ||
extensions: ['.tsx'], | ||
}) | ||
); | ||
}, | ||
}, | ||
{ | ||
module: '@swc/register', | ||
register: function (hook, config) { | ||
config = config || { | ||
only: [endsInTsx], | ||
ignore: [isNodeModules], | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
tsx: true, | ||
}, | ||
}, | ||
module: { | ||
type: 'commonjs', | ||
}, | ||
}; | ||
hook( | ||
Object.assign({}, config, { | ||
extensions: '.tsx', | ||
}) | ||
); | ||
}, | ||
}, | ||
], | ||
'.wisp': 'wisp/engine/node', | ||
'.xml': 'require-xml', | ||
'.yaml': 'require-yaml', | ||
'.yml': 'require-yaml', | ||
'.yaml': 'yaml-hook/register', | ||
'.yml': 'yaml-hook/register', | ||
}; | ||
@@ -186,21 +510,27 @@ | ||
'.babel.js', | ||
'.babel.jsx', | ||
'.babel.ts', | ||
'.buble.js', | ||
'.cirru', | ||
'.cjsx', | ||
'.co', | ||
'.babel.tsx', | ||
'.esbuild.js', | ||
'.esbuild.jsx', | ||
'.esbuild.ts', | ||
'.esbuild.tsx', | ||
'.cjs', | ||
'.coffee', | ||
'.coffee.md', | ||
'.eg', | ||
'.esm.js', | ||
'.iced', | ||
'.iced.md', | ||
'.jsx', | ||
'.litcoffee', | ||
'.liticed', | ||
'.ls', | ||
'.mdx', | ||
'.mjs', | ||
'.sucrase.js', | ||
'.sucrase.jsx', | ||
'.sucrase.ts', | ||
'.sucrase.tsx', | ||
'.swc.js', | ||
'.swc.jsx', | ||
'.swc.ts', | ||
'.swc.tsx', | ||
'.ts', | ||
'.tsx', | ||
'.wisp', | ||
]; | ||
@@ -210,3 +540,3 @@ | ||
extensions: extensions, | ||
jsVariants: jsVariantExtensions.reduce(function(result, ext) { | ||
jsVariants: jsVariantExtensions.reduce(function (result, ext) { | ||
result[ext] = extensions[ext]; | ||
@@ -213,0 +543,0 @@ return result; |
{ | ||
"name": "interpret", | ||
"version": "2.2.0", | ||
"version": "3.0.0", | ||
"description": "A dictionary of file extensions and associated module loaders.", | ||
"author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)", | ||
"author": "Gulp Team <team@gulpjs.com> (https://gulpjs.com/)", | ||
"contributors": [ | ||
@@ -13,3 +13,3 @@ "Blaine Bublitz <blaine.bublitz@gmail.com>", | ||
"engines": { | ||
"node": ">= 0.10" | ||
"node": ">=10.13.0" | ||
}, | ||
@@ -23,38 +23,39 @@ "main": "index.js", | ||
"scripts": { | ||
"readme": "remark README.md --use ./scripts/plugin.mjs --output", | ||
"lint": "eslint .", | ||
"pretest": "rm -rf tmp/ && npm run lint", | ||
"test": "mocha --async-only", | ||
"cover": "nyc --reporter=lcov --reporter=text-summary npm test", | ||
"coveralls": "nyc --reporter=text-lcov npm test | coveralls" | ||
"pretest": "npm run lint", | ||
"test": "nyc mocha --async-only" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"coveralls": "github:phated/node-coveralls#2.x", | ||
"eslint": "^2.13.0", | ||
"eslint-config-gulp": "^3.0.1", | ||
"expect": "^1.20.2", | ||
"mocha": "^3.5.3", | ||
"nyc": "^10.3.2", | ||
"parse-node-version": "^1.0.0", | ||
"rechoir": "^0.7.0", | ||
"shelljs": "0.7.5", | ||
"trash-cli": "^3.0.0" | ||
"eslint": "^7.0.0", | ||
"eslint-config-gulp": "^5.0.0", | ||
"eslint-plugin-node": "^11.1.0", | ||
"expect": "^27.0.0", | ||
"js-yaml": "^4.1.0", | ||
"mocha": "^8.0.0", | ||
"nyc": "^15.0.0", | ||
"parse-node-version": "^2.0.0", | ||
"rechoir": "^0.8.0", | ||
"remark-cli": "^10.0.1", | ||
"remark-code-import": "^1.1.0", | ||
"shelljs": "0.8.5" | ||
}, | ||
"nyc": { | ||
"extension": [ | ||
".js" | ||
], | ||
"reporter": [ | ||
"lcov", | ||
"text-summary" | ||
] | ||
}, | ||
"prettier": { | ||
"singleQuote": true | ||
}, | ||
"keywords": [ | ||
"cirru-script", | ||
"cjsx", | ||
"co", | ||
"coco", | ||
"coffee", | ||
"coffee-script", | ||
"coffee.md", | ||
"coffeescript", | ||
"csv", | ||
"earlgrey", | ||
"es", | ||
"es6", | ||
"iced", | ||
"iced.md", | ||
"iced-coffee-script", | ||
"ini", | ||
"js", | ||
@@ -66,9 +67,5 @@ "json", | ||
"litcoffee", | ||
"liticed", | ||
"ls", | ||
"livescript", | ||
"toml", | ||
"ts", | ||
"typescript", | ||
"wisp", | ||
"xml", | ||
@@ -75,0 +72,0 @@ "yaml", |
367
README.md
@@ -9,3 +9,3 @@ <p align="center"> | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] | ||
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] | ||
@@ -15,152 +15,33 @@ A dictionary of file extensions and associated module loaders. | ||
## What is it | ||
This is used by [Liftoff](http://github.com/tkellen/node-liftoff) to automatically require dependencies for configuration files, and by [rechoir](http://github.com/tkellen/node-rechoir) for registering module loaders. | ||
## interpret for enterprise | ||
This is used by [Liftoff] to automatically require dependencies for configuration files, and by [rechoir] for registering module loaders. | ||
Available as part of the Tidelift Subscription | ||
## How to use it | ||
The maintainers of interpret and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-interpret?utm_source=npm-interpret&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) | ||
Consumers should use the exported `extensions` or `jsVariants` object to determine which module should be loaded for a given extension. If a matching extension is found, consumers should do the following: | ||
1. If the value is null, do nothing. | ||
2. If the value is a string, try to require it. | ||
3. If the value is an object, try to require the `module` property. If successful, the `register` property (a function) should be called with the module passed as the first argument. **Advanced:** An optional second argument can be provided to replace the default configuration for a hook. | ||
4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw. | ||
## API | ||
### extensions | ||
Map file types to modules which provide a [require.extensions] loader. | ||
This module provides two top-level properties: `extensions` and `jsVariants`. | ||
**Note:** This module does not depend on any of the loaders it recommends; instead, end-users are expected to install the hooks they want to use for the file types they want to use. See supported extensions and their hooks in the sections below. | ||
### `extensions` | ||
A mapping of file extensions to modules which provide a [require.extensions] loader. | ||
File extension keys are all in the format of `'.foo'` or `'.foo.bar'` and module loader values are either `null` if the loader should fallthrough to node's loader, | ||
or a string representing the module to be required, an object of `{ module: 'foobar', register: function }`, or an array containing those strings and/or objects. | ||
A sample of an entry containing multiple hooks would look like: | ||
```js | ||
{ | ||
'.babel.js': [ | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'babel-register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'babel-core/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.js', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
], | ||
'.babel.ts': [ | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.ts', | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
}, | ||
}, | ||
], | ||
'.buble.js': 'buble/register', | ||
'.cirru': 'cirru-script/lib/register', | ||
'.cjsx': 'node-cjsx/register', | ||
'.co': 'coco', | ||
'.coffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], | ||
'.coffee.md': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], | ||
'.csv': 'require-csv', | ||
'.eg': 'earlgrey/register', | ||
'.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) | ||
var esmLoader = hook(module); | ||
require.extensions['.js'] = esmLoader('module')._extensions['.js']; | ||
}, | ||
}, | ||
'.iced': ['iced-coffee-script/register', 'iced-coffee-script'], | ||
'.iced.md': 'iced-coffee-script/register', | ||
'.ini': 'require-ini', | ||
'.js': null, | ||
'.json': null, | ||
'.json5': ['json5/lib/register', 'json5/lib/require'], | ||
'.jsx': [ | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'babel-register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'babel-core/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.jsx', | ||
ignore: ignoreNonBabelAndNodeModules, | ||
}); | ||
}, | ||
}, | ||
{ | ||
module: 'node-jsx', | ||
register: function(hook) { | ||
hook.install({ extension: '.jsx', harmony: true }); | ||
}, | ||
}, | ||
], | ||
'.litcoffee': ['coffeescript/register', 'coffee-script/register', 'coffeescript', 'coffee-script'], | ||
'.liticed': 'iced-coffee-script/register', | ||
'.ls': ['livescript', 'LiveScript'], | ||
'.mjs': '/absolute/path/to/interpret/mjs-stub.js', | ||
'.node': null, | ||
'.toml': { | ||
module: 'toml-require', | ||
register: function(hook) { | ||
hook.install(); | ||
}, | ||
}, | ||
'.ts': [ | ||
'ts-node/register', | ||
'typescript-node/register', | ||
'typescript-register', | ||
'typescript-require', | ||
'sucrase/register/ts', | ||
@@ -178,55 +59,187 @@ { | ||
], | ||
'.tsx': [ | ||
'ts-node/register', | ||
'typescript-node/register', | ||
'sucrase/register', | ||
{ | ||
module: '@babel/register', | ||
register: function(hook) { | ||
hook({ | ||
extensions: '.tsx', | ||
rootMode: 'upward-optional', | ||
ignore: [ignoreNonBabelAndNodeModules], | ||
}); | ||
}, | ||
}, | ||
], | ||
'.wisp': 'wisp/engine/node', | ||
'.xml': 'require-xml', | ||
'.yaml': 'require-yaml', | ||
'.yml': 'require-yaml', | ||
} | ||
``` | ||
### jsVariants | ||
Same as above, but only include the extensions which are javascript variants. | ||
**Supported extensions and their hooks** | ||
## How to use it | ||
```yaml file=scripts/extensions.yaml | ||
.babel.js: | ||
- '@babel/register' | ||
.babel.jsx: | ||
- '@babel/register' | ||
.babel.ts: | ||
- '@babel/register' | ||
.babel.tsx: | ||
- '@babel/register' | ||
.cjs: | ||
- interpret/cjs-stub | ||
.coffee: | ||
- coffeescript/register | ||
.coffee.md: | ||
- coffeescript/register | ||
.esbuild.js: | ||
- esbuild-register/dist/node | ||
.esbuild.jsx: | ||
- esbuild-register/dist/node | ||
.esbuild.ts: | ||
- esbuild-register/dist/node | ||
.esbuild.tsx: | ||
- esbuild-register/dist/node | ||
.esm.js: | ||
- esm | ||
.js: | ||
- built-in node.js loader | ||
.json: | ||
- built-in node.js loader | ||
.json5: | ||
- json5/lib/register | ||
.jsx: | ||
- '@babel/register' | ||
- sucrase/register/jsx | ||
.litcoffee: | ||
- coffeescript/register | ||
.mdx: | ||
- '@mdx-js/register' | ||
.mjs: | ||
- interpret/mjs-stub | ||
.node: | ||
- built-in node.js loader | ||
.sucrase.js: | ||
- sucrase/dist/register | ||
.sucrase.jsx: | ||
- sucrase/dist/register | ||
.sucrase.ts: | ||
- sucrase/dist/register | ||
.sucrase.tsx: | ||
- sucrase/dist/register | ||
.swc.js: | ||
- '@swc/register' | ||
.swc.jsx: | ||
- '@swc/register' | ||
.swc.ts: | ||
- '@swc/register' | ||
.swc.tsx: | ||
- '@swc/register' | ||
.toml: | ||
- toml-require | ||
.ts: | ||
- ts-node/register | ||
- sucrase/register/ts | ||
- '@babel/register' | ||
- esbuild-register/dist/node | ||
- '@swc/register' | ||
.tsx: | ||
- ts-node/register | ||
- sucrase/register/tsx | ||
- '@babel/register' | ||
- esbuild-register/dist/node | ||
- '@swc/register' | ||
.yaml: | ||
- yaml-hook/register | ||
.yml: | ||
- yaml-hook/register | ||
``` | ||
Consumers should use the exported `extensions` or `jsVariants` object to determine which module should be loaded for a given extension. If a matching extension is found, consumers should do the following: | ||
### `jsVariants` | ||
1. If the value is null, do nothing. | ||
The `jsVariants` is the same mapping as above, but only include the extensions which are variants of JavaScript. | ||
2. If the value is a string, try to require it. | ||
**Supported extensions and their hooks** | ||
3. If the value is an object, try to require the `module` property. If successful, the `register` property (a function) should be called with the module passed as the first argument. | ||
```yaml file=scripts/jsVariants.yaml | ||
.babel.js: | ||
- '@babel/register' | ||
.babel.jsx: | ||
- '@babel/register' | ||
.babel.ts: | ||
- '@babel/register' | ||
.babel.tsx: | ||
- '@babel/register' | ||
.cjs: | ||
- interpret/cjs-stub | ||
.coffee: | ||
- coffeescript/register | ||
.coffee.md: | ||
- coffeescript/register | ||
.esbuild.js: | ||
- esbuild-register/dist/node | ||
.esbuild.jsx: | ||
- esbuild-register/dist/node | ||
.esbuild.ts: | ||
- esbuild-register/dist/node | ||
.esbuild.tsx: | ||
- esbuild-register/dist/node | ||
.esm.js: | ||
- esm | ||
.js: | ||
- built-in node.js loader | ||
.jsx: | ||
- '@babel/register' | ||
- sucrase/register/jsx | ||
.litcoffee: | ||
- coffeescript/register | ||
.mdx: | ||
- '@mdx-js/register' | ||
.mjs: | ||
- interpret/mjs-stub | ||
.sucrase.js: | ||
- sucrase/dist/register | ||
.sucrase.jsx: | ||
- sucrase/dist/register | ||
.sucrase.ts: | ||
- sucrase/dist/register | ||
.sucrase.tsx: | ||
- sucrase/dist/register | ||
.swc.js: | ||
- '@swc/register' | ||
.swc.jsx: | ||
- '@swc/register' | ||
.swc.ts: | ||
- '@swc/register' | ||
.swc.tsx: | ||
- '@swc/register' | ||
.ts: | ||
- ts-node/register | ||
- sucrase/register/ts | ||
- '@babel/register' | ||
- esbuild-register/dist/node | ||
- '@swc/register' | ||
.tsx: | ||
- ts-node/register | ||
- sucrase/register/tsx | ||
- '@babel/register' | ||
- esbuild-register/dist/node | ||
- '@swc/register' | ||
``` | ||
4. If the value is an array, iterate over it, attempting step #2 or #3 until one of the attempts does not throw. | ||
## License | ||
[require.extensions]: http://nodejs.org/api/globals.html#globals_require_extensions | ||
MIT | ||
[downloads-image]: http://img.shields.io/npm/dm/interpret.svg | ||
<!-- prettier-ignore-start --> | ||
[downloads-image]: https://img.shields.io/npm/dm/interpret.svg?style=flat-square | ||
[npm-url]: https://www.npmjs.com/package/interpret | ||
[npm-image]: http://img.shields.io/npm/v/interpret.svg | ||
[travis-url]: https://travis-ci.org/gulpjs/interpret | ||
[travis-image]: http://img.shields.io/travis/gulpjs/interpret.svg?label=travis-ci | ||
[npm-image]: https://img.shields.io/npm/v/interpret.svg?style=flat-square | ||
[appveyor-url]: https://ci.appveyor.com/project/gulpjs/interpret | ||
[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/interpret.svg?label=appveyor | ||
[ci-url]: https://github.com/gulpjs/interpret/actions?query=workflow:dev | ||
[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/interpret/dev?style=flat-square | ||
[coveralls-url]: https://coveralls.io/r/gulpjs/interpret | ||
[coveralls-image]: http://img.shields.io/coveralls/gulpjs/interpret/master.svg | ||
[gitter-url]: https://gitter.im/gulpjs/gulp | ||
[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg | ||
[coveralls-image]: https://img.shields.io/coveralls/gulpjs/interpret/master.svg?style=flat-square | ||
<!-- prettier-ignore-end --> | ||
<!-- prettier-ignore-start --> | ||
[Liftoff]: http://github.com/gulpjs/liftoff | ||
[rechoir]: http://github.com/gulpjs/rechoir | ||
[require.extensions]: https://nodejs.org/api/modules.html#requireextensions | ||
<!-- prettier-ignore-end --> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21345
513
243
12
5
1