babel-loader
Advanced tools
Comparing version 8.2.5 to 8.3.0
"use strict"; | ||
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); }); }; } | ||
/** | ||
@@ -17,23 +15,15 @@ * Filesystem Cache | ||
const fs = require("fs"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
const zlib = require("zlib"); | ||
const crypto = require("crypto"); | ||
const findCacheDir = require("find-cache-dir"); | ||
const { | ||
promisify | ||
} = require("util"); | ||
const transform = require("./transform"); // Lazily instantiated when needed | ||
const transform = require("./transform"); | ||
// Lazily instantiated when needed | ||
let defaultCacheDirectory = null; | ||
let hashType = "md4"; // use md5 hashing if md4 is not available | ||
let hashType = "sha256"; | ||
// use md5 hashing if sha256 is not available | ||
try { | ||
@@ -44,3 +34,2 @@ crypto.createHash(hashType); | ||
} | ||
const readFile = promisify(fs.readFile); | ||
@@ -50,4 +39,4 @@ const writeFile = promisify(fs.writeFile); | ||
const gzip = promisify(zlib.gzip); | ||
const makeDir = require("make-dir"); | ||
const makeDir = require("make-dir"); | ||
/** | ||
@@ -60,4 +49,2 @@ * Read the contents from the compressed file. | ||
*/ | ||
const read = /*#__PURE__*/function () { | ||
@@ -69,3 +56,2 @@ var _ref = _asyncToGenerator(function* (filename, compress) { | ||
}); | ||
return function read(_x, _x2) { | ||
@@ -75,2 +61,3 @@ return _ref.apply(this, arguments); | ||
}(); | ||
/** | ||
@@ -84,4 +71,2 @@ * Write contents into a compressed file. | ||
*/ | ||
const write = /*#__PURE__*/function () { | ||
@@ -93,3 +78,2 @@ var _ref2 = _asyncToGenerator(function* (filename, compress, result) { | ||
}); | ||
return function write(_x3, _x4, _x5) { | ||
@@ -99,2 +83,3 @@ return _ref2.apply(this, arguments); | ||
}(); | ||
/** | ||
@@ -108,4 +93,2 @@ * Build the filename for the cached file | ||
*/ | ||
const filename = function (source, identifier, options) { | ||
@@ -121,2 +104,3 @@ const hash = crypto.createHash(hashType); | ||
}; | ||
/** | ||
@@ -128,4 +112,2 @@ * Handle the cache | ||
*/ | ||
const handleCache = /*#__PURE__*/function () { | ||
@@ -141,3 +123,2 @@ var _ref3 = _asyncToGenerator(function* (directory, params) { | ||
const file = path.join(directory, filename(source, cacheIdentifier, options)); | ||
try { | ||
@@ -148,5 +129,5 @@ // No errors mean that the file was previously cached | ||
} catch (err) {} | ||
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir(); | ||
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir(); // Make sure the directory exists. | ||
// Make sure the directory exists. | ||
try { | ||
@@ -158,24 +139,24 @@ yield makeDir(directory); | ||
} | ||
throw err; | ||
} | ||
throw err; | ||
} // Otherwise just transform the file | ||
// Otherwise just transform the file | ||
// return it to the user asap and write it in cache | ||
const result = yield transform(source, options); | ||
try { | ||
yield write(file, cacheCompression, result); | ||
} catch (err) { | ||
if (fallback) { | ||
// Fallback to tmpdir if node_modules folder not writable | ||
return handleCache(os.tmpdir(), params); | ||
// Do not cache if there are external dependencies, | ||
// since they might change and we cannot control it. | ||
if (!result.externalDependencies.length) { | ||
try { | ||
yield write(file, cacheCompression, result); | ||
} catch (err) { | ||
if (fallback) { | ||
// Fallback to tmpdir if node_modules folder not writable | ||
return handleCache(os.tmpdir(), params); | ||
} | ||
throw err; | ||
} | ||
throw err; | ||
} | ||
return result; | ||
}); | ||
return function handleCache(_x6, _x7) { | ||
@@ -185,2 +166,3 @@ return _ref3.apply(this, arguments); | ||
}(); | ||
/** | ||
@@ -211,7 +193,5 @@ * Retrieve file from cache, or create a new one for future reads | ||
module.exports = /*#__PURE__*/function () { | ||
var _ref4 = _asyncToGenerator(function* (params) { | ||
let directory; | ||
if (typeof params.cacheDirectory === "string") { | ||
@@ -225,9 +205,6 @@ directory = params.cacheDirectory; | ||
} | ||
directory = defaultCacheDirectory; | ||
} | ||
return yield handleCache(directory, params); | ||
}); | ||
return function (_x8) { | ||
@@ -234,0 +211,0 @@ return _ref4.apply(this, arguments); |
"use strict"; | ||
const STRIP_FILENAME_RE = /^[^:]+: /; | ||
const format = err => { | ||
@@ -15,6 +14,4 @@ if (err instanceof SyntaxError) { | ||
} | ||
return err; | ||
}; | ||
class LoaderError extends Error { | ||
@@ -34,5 +31,3 @@ constructor(err) { | ||
} | ||
} | ||
module.exports = LoaderError; |
"use strict"; | ||
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; | ||
try { | ||
@@ -15,32 +12,22 @@ babel = require("@babel/core"); | ||
} | ||
throw err; | ||
} | ||
throw err; | ||
} // Since we've got the reverse bridge package at @babel/core@6.x, give | ||
// Since we've got the reverse bridge package at @babel/core@6.x, give | ||
// people useful feedback if they try to use it alongside babel-loader. | ||
if (/^6\./.test(babel.version)) { | ||
throw new Error("\n babel-loader@8 will not work with the '@babel/core@6' bridge package. " + "If you want to use Babel 6.x, install 'babel-loader@7'."); | ||
} | ||
const { | ||
version | ||
} = require("../package.json"); | ||
const cache = require("./cache"); | ||
const transform = require("./transform"); | ||
const injectCaller = require("./injectCaller"); | ||
const schema = require("./schema"); | ||
const { | ||
isAbsolute | ||
} = require("path"); | ||
const loaderUtils = require("loader-utils"); | ||
const validateOptions = require("schema-utils"); | ||
function subscribe(subscriber, metadata, context) { | ||
@@ -51,6 +38,4 @@ if (context[subscriber]) { | ||
} | ||
module.exports = makeLoader(); | ||
module.exports.custom = makeLoader; | ||
function makeLoader(callback) { | ||
@@ -64,7 +49,5 @@ const overrides = callback ? callback(babel) : undefined; | ||
} | ||
function loader(_x, _x2, _x3) { | ||
return _loader.apply(this, arguments); | ||
} | ||
function _loader() { | ||
@@ -77,3 +60,2 @@ _loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) { | ||
}); | ||
if (loaderOptions.customize != null) { | ||
@@ -83,24 +65,16 @@ if (typeof loaderOptions.customize !== "string") { | ||
} | ||
if (!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) { | ||
@@ -113,16 +87,15 @@ const result = yield overrides.customOptions.call(this, loaderOptions, { | ||
loaderOptions = result.loader; | ||
} // Deprecation handling | ||
} | ||
// Deprecation handling | ||
if ("forceEnv" in loaderOptions) { | ||
console.warn("The option `forceEnv` has been removed in favor of `envName` in Babel 7."); | ||
} | ||
if (typeof loaderOptions.babelrc === "string") { | ||
console.warn("The option `babelrc` should not be set to a string anymore in the babel-loader config. " + "Please update your configuration and set `babelrc` to true or false.\n" + "If you want to specify a specific babel config file to inherit config from " + "please use the `extends` option.\nFor more information about this options see " + "https://babeljs.io/docs/core-packages/#options"); | ||
} // Standardize on 'sourceMaps' as the key passed through to Webpack, so that | ||
} | ||
// Standardize on 'sourceMaps' as the key passed through to Webpack, so that | ||
// users may safely use either one alongside our default use of | ||
// 'this.sourceMap' below without getting error about conflicting aliases. | ||
if (Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps")) { | ||
@@ -134,3 +107,2 @@ loaderOptions = Object.assign({}, loaderOptions, { | ||
} | ||
const programmaticOptions = Object.assign({}, loaderOptions, { | ||
@@ -146,4 +118,4 @@ filename, | ||
sourceFileName: filename | ||
}); // Remove loader related options | ||
}); | ||
// Remove loader related options | ||
delete programmaticOptions.customize; | ||
@@ -154,8 +126,7 @@ delete programmaticOptions.cacheDirectory; | ||
delete programmaticOptions.metadataSubscribers; | ||
if (!babel.loadPartialConfig) { | ||
throw new Error(`babel-loader ^8.0.0-beta.3 requires @babel/core@7.0.0-beta.41, but ` + `you appear to be using "${babel.version}". Either update your ` + `@babel/core version, or pin you babel-loader version to 8.0.0-beta.2`); | ||
} // babel.loadPartialConfigAsync is available in v7.8.0+ | ||
} | ||
// babel.loadPartialConfigAsync is available in v7.8.0+ | ||
const { | ||
@@ -165,6 +136,4 @@ loadPartialConfigAsync = babel.loadPartialConfig | ||
const config = yield loadPartialConfigAsync(injectCaller(programmaticOptions, this.target)); | ||
if (config) { | ||
let options = config.options; | ||
if (overrides && overrides.config) { | ||
@@ -177,3 +146,2 @@ options = yield overrides.config.call(this, config, { | ||
} | ||
if (options.sourceMaps === "inline") { | ||
@@ -188,3 +156,2 @@ // Babel has this weird behavior where if you set "inline", we | ||
} | ||
const { | ||
@@ -201,3 +168,2 @@ cacheDirectory = null, | ||
let result; | ||
if (cacheDirectory) { | ||
@@ -214,6 +180,6 @@ result = yield cache({ | ||
result = yield transform(source, options); | ||
} // Availabe since Babel 7.12 | ||
} | ||
// Availabe since Babel 7.12 | ||
// https://github.com/babel/babel/pull/11907 | ||
if (config.files) { | ||
@@ -225,5 +191,4 @@ config.files.forEach(configFile => this.addDependency(configFile)); | ||
this.addDependency(config.babelrc); | ||
} // babel.config.js | ||
} | ||
// babel.config.js | ||
if (config.config) { | ||
@@ -233,3 +198,2 @@ this.addDependency(config.config); | ||
} | ||
if (result) { | ||
@@ -245,8 +209,9 @@ if (overrides && overrides.result) { | ||
} | ||
const { | ||
code, | ||
map, | ||
metadata | ||
metadata, | ||
externalDependencies | ||
} = result; | ||
externalDependencies == null ? void 0 : externalDependencies.forEach(dep => this.addDependency(dep)); | ||
metadataSubscribers.forEach(subscriber => { | ||
@@ -257,5 +222,5 @@ subscribe(subscriber, metadata, this); | ||
} | ||
} // If the file was ignored, pass through the original content. | ||
} | ||
// If the file was ignored, pass through the original content. | ||
return [source, inputSourceMap]; | ||
@@ -262,0 +227,0 @@ }); |
"use strict"; | ||
const babel = require("@babel/core"); | ||
module.exports = function injectCaller(opts, target) { | ||
@@ -22,9 +21,8 @@ if (!supportsCallerOption()) return opts; | ||
}); | ||
}; // TODO: We can remove this eventually, I'm just adding it so that people have | ||
}; | ||
// 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() { | ||
@@ -45,4 +43,3 @@ if (supportsCallerOptionFlag === undefined) { | ||
} | ||
return supportsCallerOptionFlag; | ||
} |
"use strict"; | ||
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"); | ||
const { | ||
promisify | ||
} = require("util"); | ||
const LoaderError = require("./Error"); | ||
const transform = promisify(babel.transform); | ||
module.exports = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator(function* (source, options) { | ||
let result; | ||
try { | ||
@@ -26,4 +19,5 @@ result = yield transform(source, options); | ||
} | ||
if (!result) return null; | ||
if (!result) return null; // We don't return the full result here because some entries are not | ||
// We don't return the full result here because some entries are not | ||
// really serializable. For a full list of properties see here: | ||
@@ -33,3 +27,2 @@ // https://github.com/babel/babel/blob/main/packages/babel-core/src/transformation/index.js | ||
// https://github.com/babel/babel-loader/pull/629 | ||
const { | ||
@@ -40,9 +33,8 @@ ast, | ||
metadata, | ||
sourceType | ||
sourceType, | ||
externalDependencies | ||
} = result; | ||
if (map && (!map.sourcesContent || !map.sourcesContent.length)) { | ||
map.sourcesContent = [source]; | ||
} | ||
return { | ||
@@ -53,6 +45,7 @@ ast, | ||
metadata, | ||
sourceType | ||
sourceType, | ||
// Convert it from a Set to an Array to make it JSON-serializable. | ||
externalDependencies: Array.from(externalDependencies || []) | ||
}; | ||
}); | ||
return function (_x, _x2) { | ||
@@ -62,3 +55,2 @@ return _ref.apply(this, arguments); | ||
}(); | ||
module.exports.version = babel.version; |
{ | ||
"name": "babel-loader", | ||
"version": "8.2.5", | ||
"version": "8.3.0", | ||
"description": "babel module loader for webpack", | ||
@@ -24,5 +24,5 @@ "files": [ | ||
"@ava/babel": "^1.0.1", | ||
"@babel/cli": "^7.12.1", | ||
"@babel/core": "^7.12.3", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/cli": "^7.19.3", | ||
"@babel/core": "^7.19.6", | ||
"@babel/preset-env": "^7.19.4", | ||
"ava": "^3.13.0", | ||
@@ -124,3 +124,6 @@ "babel-eslint": "^10.0.1", | ||
] | ||
}, | ||
"resolutions": { | ||
"nyc/node-preload": "0.2.0" | ||
} | ||
} |
42151
536