babel-loader
Advanced tools
Comparing version 8.0.2 to 8.0.3
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
/** | ||
@@ -6,0 +8,0 @@ * Filesystem Cache |
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
let babel; | ||
@@ -29,2 +31,6 @@ | ||
const injectCaller = require("./injectCaller"); | ||
const path = require("path"); | ||
const loaderUtils = require("loader-utils"); | ||
@@ -58,6 +64,34 @@ | ||
let loaderOptions = loaderUtils.getOptions(this) || {}; | ||
if (loaderOptions.customize != null) { | ||
if (typeof loaderOptions.customize !== "string") { | ||
throw new Error("Customized loaders must be implemented as standalone modules."); | ||
} | ||
if (!path.isAbsolute(loaderOptions.customize)) { | ||
throw new Error("Customized loaders must be passed as absolute paths, since " + "babel-loader has no way to know what they would be relative to."); | ||
} | ||
if (overrides) { | ||
throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper."); | ||
} | ||
let override = require(loaderOptions.customize); | ||
if (override.__esModule) override = override.default; | ||
if (typeof override === "function") { | ||
throw new Error("Custom overrides must be functions."); | ||
} | ||
overrides = override(babel); | ||
} | ||
let customOptions; | ||
if (overrides && overrides.customOptions) { | ||
const result = yield overrides.customOptions.call(this, loaderOptions); | ||
const result = yield overrides.customOptions.call(this, loaderOptions, { | ||
source, | ||
map: inputSourceMap | ||
}); | ||
customOptions = result.custom; | ||
@@ -98,2 +132,3 @@ loaderOptions = result.loader; | ||
delete programmaticOptions.customize; | ||
delete programmaticOptions.cacheDirectory; | ||
@@ -108,3 +143,3 @@ delete programmaticOptions.cacheIdentifier; | ||
const config = babel.loadPartialConfig(programmaticOptions); | ||
const config = babel.loadPartialConfig(injectCaller(programmaticOptions)); | ||
@@ -117,2 +152,3 @@ if (config) { | ||
source, | ||
map: inputSourceMap, | ||
customOptions | ||
@@ -167,2 +203,3 @@ }); | ||
source, | ||
map: inputSourceMap, | ||
customOptions, | ||
@@ -169,0 +206,0 @@ config, |
"use strict"; | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _next(value) { step("next", value); } function _throw(err) { step("throw", err); } _next(); }); }; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
const babel = require("@babel/core"); | ||
@@ -20,3 +22,3 @@ | ||
try { | ||
result = yield transform(source, injectCaller(options)); | ||
result = yield transform(source, options); | ||
} catch (err) { | ||
@@ -58,38 +60,2 @@ throw err.message && err.codeFrame ? new LoaderError(err) : err; | ||
module.exports.version = babel.version; | ||
function injectCaller(opts) { | ||
if (!supportsCallerOption()) return opts; | ||
return Object.assign({}, opts, { | ||
caller: Object.assign({ | ||
name: "babel-loader", | ||
// Webpack >= 2 supports ESM and dynamic import. | ||
supportsStaticESM: true, | ||
supportsDynamicImport: true | ||
}, opts.caller) | ||
}); | ||
} // TODO: We can remove this eventually, I'm just adding it so that people have | ||
// a little time to migrate to the newer RCs of @babel/core without getting | ||
// hard-to-diagnose errors about unknown 'caller' options. | ||
let supportsCallerOptionFlag = undefined; | ||
function supportsCallerOption() { | ||
if (supportsCallerOptionFlag === undefined) { | ||
try { | ||
// Rather than try to match the Babel version, we just see if it throws | ||
// when passed a 'caller' flag, and use that to decide if it is supported. | ||
babel.loadPartialConfig({ | ||
caller: undefined, | ||
babelrc: false, | ||
configFile: false | ||
}); | ||
supportsCallerOptionFlag = true; | ||
} catch (err) { | ||
supportsCallerOptionFlag = false; | ||
} | ||
} | ||
return supportsCallerOptionFlag; | ||
} | ||
module.exports.version = babel.version; |
{ | ||
"name": "babel-loader", | ||
"version": "8.0.2", | ||
"version": "8.0.3", | ||
"description": "babel module loader for webpack", | ||
@@ -23,5 +23,5 @@ "files": [ | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.41", | ||
"@babel/core": "^7.0.0-beta.41", | ||
"@babel/preset-env": "^7.0.0-beta.41", | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"ava": "0.25.0", | ||
@@ -33,3 +33,3 @@ "babel-eslint": "^8.0.0", | ||
"eslint": "^4.1.0", | ||
"eslint-config-babel": "^7.0.0", | ||
"eslint-config-babel": "^8.0.0", | ||
"eslint-plugin-flowtype": "^2.25.0", | ||
@@ -36,0 +36,0 @@ "eslint-plugin-prettier": "^2.1.2", |
@@ -6,3 +6,3 @@ > This README is for babel-loader v8 + Babel v7 | ||
[![Build Status](https://travis-ci.org/babel/babel-loader.svg?branch=master)](https://travis-ci.org/babel/babel-loader) | ||
[![Build Status](https://ci.appveyor.com/api/projects/status/vgtpr2i5bykgyuqo/branch/master?svg=true)](https://ci.appveyor.com/project/danez/babel-loader/branch/master) | ||
[![Build Status](https://ci.appveyor.com/api/projects/status/77y5mk6amwqt0q88/branch/master?svg=true)](https://ci.appveyor.com/project/babel/babel-loader/branch/master) | ||
[![codecov](https://codecov.io/gh/babel/babel-loader/branch/master/graph/badge.svg)](https://codecov.io/gh/babel/babel-loader) | ||
@@ -49,3 +49,3 @@ | ||
{ | ||
test: /\.js$/, | ||
test: /\.m?js$/, | ||
exclude: /(node_modules|bower_components)/, | ||
@@ -65,3 +65,3 @@ use: { | ||
See the `babel` [options](https://babeljs.io/docs/usage/api/#options). | ||
See the `babel` [options](https://babeljs.io/docs/en/options). | ||
@@ -74,3 +74,3 @@ You can pass options to the loader by using the [`options`](https://webpack.js.org/configuration/module/#rule-options-rule-query) property: | ||
{ | ||
test: /\.js$/, | ||
test: /\.m?js$/, | ||
exclude: /(node_modules|bower_components)/, | ||
@@ -97,2 +97,4 @@ use: { | ||
* `customize`: Default `null`. The path of a module that exports a `custom` callback [like the one that you'd pass to `.custom()`](#customized-loader). Since you already have to make a new file to use this, it is recommended that you instead use `.custom` to create a wrapper loader. Only use this is you _must_ continue using `babel-loader` directly, but still want to customize. | ||
**Note**: The `sourceMap` option is ignored. Instead, source maps are automatically enabled when webpack is configured to use them (via the [`devtool`](https://webpack.js.org/configuration/devtool/#devtool) config option). | ||
@@ -104,3 +106,3 @@ | ||
Make sure you are transforming as few files as possible. Because you are probably matching `/\.js$/`, you might be transforming the `node_modules` folder or other unwanted source. | ||
Make sure you are transforming as few files as possible. Because you are probably matching `/\.m?js$/`, you might be transforming the `node_modules` folder or other unwanted source. | ||
@@ -128,3 +130,3 @@ To exclude `node_modules`, see the `exclude` option in the `loaders` config as documented above. | ||
{ | ||
test: /\.js$/, | ||
test: /\.m?js$/, | ||
exclude: /(node_modules|bower_components)/, | ||
@@ -193,3 +195,3 @@ use: { | ||
{ | ||
test: /\.js$/, | ||
test: /\.m?js$/, | ||
loader: 'babel', | ||
@@ -205,3 +207,3 @@ } | ||
{ | ||
test: /\.js$/, | ||
test: /\.m?js$/, | ||
loader: 'babel-loader', | ||
@@ -220,5 +222,10 @@ } | ||
In cases where you want to customize without actually having a file to call `.custom`, you | ||
may also pass the `customize` option with a string pointing at a file that exports | ||
your `custom` callback function. | ||
### Example | ||
```js | ||
// Export from "./my-custom-loader.js" or whatever you want. | ||
module.exports = require("babel-loader").custom(babel => { | ||
@@ -243,3 +250,3 @@ function myPlugin() { | ||
// Passed Babel's 'PartialConfig' object. | ||
// Passed Babel's 'PartialConfig' object. | ||
config(cfg) { | ||
@@ -272,2 +279,16 @@ if (cfg.hasFilesystemConfig()) { | ||
```js | ||
// And in your Webpack config | ||
module.exports = { | ||
// .. | ||
module: { | ||
rules: [{ | ||
// ... | ||
loader: path.join(__dirname, 'my-custom-loader.js'), | ||
// ... | ||
}] | ||
} | ||
}; | ||
``` | ||
### `customOptions(options: Object): { custom: Object, loader: Object }` | ||
@@ -274,0 +295,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
37391
9
465
300
2