feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

View File

@@ -105,18 +105,24 @@ const handleCache = /*#__PURE__*/function () {
options = {},
cacheIdentifier,
cacheDirectory,
cacheCompression
cacheCompression,
logger
} = params;
const file = path.join(directory, filename(source, cacheIdentifier, options));
try {
// No errors mean that the file was previously cached
// we just need to return it
logger.debug(`reading cache file '${file}'`);
return yield read(file, cacheCompression);
} catch (err) {}
} catch (err) {
// conitnue if cache can't be read
logger.debug(`discarded cache as it can not be read`);
}
const fallback = typeof cacheDirectory !== "string" && directory !== os.tmpdir();
// Make sure the directory exists.
try {
logger.debug(`creating cache folder '${directory}'`);
yield makeDir(directory);
} catch (err) {
if (fallback) {
@@ -127,12 +133,14 @@ const handleCache = /*#__PURE__*/function () {
// Otherwise just transform the file
// return it to the user asap and write it in cache
logger.debug(`applying Babel transform`);
const result = yield transform(source, options);
// Do not cache if there are external dependencies,
// since they might change and we cannot control it.
if (!result.externalDependencies.length) {
try {
logger.debug(`writing result to cache file '${file}'`);
yield write(file, cacheCompression, result);
} catch (err) {
if (fallback) {

View File

@@ -50,6 +50,9 @@ function loader(_x, _x2, _x3) {
function _loader() {
_loader = _asyncToGenerator(function* (source, inputSourceMap, overrides) {
const filename = this.resourcePath;
const logger = typeof this.getLogger === "function" ? this.getLogger("babel-loader") : {
debug: () => {}
};
let loaderOptions = loaderUtils.getOptions(this);
validateOptions(schema, loaderOptions, {
name: "Babel loader"
@@ -64,15 +67,18 @@ function _loader() {
if (overrides) {
throw new Error("babel-loader's 'customize' option is not available when already " + "using a customized babel-loader wrapper.");
}
logger.debug(`loading customize override: '${loaderOptions.customize}'`);
let override = require(loaderOptions.customize);
if (override.__esModule) override = override.default;
if (typeof override !== "function") {
throw new Error("Custom overrides must be functions.");
}
logger.debug("applying customize override to @babel/core");
overrides = override(babel);
}
let customOptions;
if (overrides && overrides.customOptions) {
logger.debug("applying overrides customOptions() to loader options");
const result = yield overrides.customOptions.call(this, loaderOptions, {
source,
map: inputSourceMap
@@ -88,7 +94,7 @@ function _loader() {
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");
}
logger.debug("normalizing loader options");
// 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.
@@ -123,10 +129,12 @@ function _loader() {
const {
loadPartialConfigAsync = babel.loadPartialConfig
} = babel;
logger.debug("resolving Babel configs");
const config = yield loadPartialConfigAsync(injectCaller(programmaticOptions, this.target));
if (config) {
let options = config.options;
if (overrides && overrides.config) {
logger.debug("applying overrides config() to Babel config");
options = yield overrides.config.call(this, config, {
source,
map: inputSourceMap,
@@ -154,34 +162,43 @@ function _loader() {
} = loaderOptions;
let result;
if (cacheDirectory) {
logger.debug("cache is enabled");
result = yield cache({
source,
options,
transform,
cacheDirectory,
cacheIdentifier,
cacheCompression
cacheCompression,
logger
});
} else {
logger.debug("cache is disabled, applying Babel transform");
result = yield transform(source, options);
}
// Availabe since Babel 7.12
// https://github.com/babel/babel/pull/11907
if (config.files) {
config.files.forEach(configFile => this.addDependency(configFile));
config.files.forEach(configFile => {
this.addDependency(configFile);
logger.debug(`added '${configFile}' to webpack dependencies`);
});
} else {
// .babelrc.json
if (typeof config.babelrc === "string") {
this.addDependency(config.babelrc);
logger.debug(`added '${config.babelrc}' to webpack dependencies`);
}
// babel.config.js
if (config.config) {
this.addDependency(config.config);
logger.debug(`added '${config.config}' to webpack dependencies`);
}
}
if (result) {
if (overrides && overrides.result) {
logger.debug("applying overrides result() to Babel transform results");
result = yield overrides.result.call(this, result, {
source,
map: inputSourceMap,
@@ -196,9 +213,13 @@ function _loader() {
metadata,
externalDependencies
} = result;
externalDependencies == null ? void 0 : externalDependencies.forEach(dep => this.addDependency(dep));
externalDependencies == null ? void 0 : externalDependencies.forEach(dep => {
this.addDependency(dep);
logger.debug(`added '${dep}' to webpack dependencies`);
});
metadataSubscribers.forEach(subscriber => {
subscribe(subscriber, metadata, this);
logger.debug(`invoked metadata subscriber '${String(subscriber)}'`);
});
return [code, map];
}

View File

@@ -1,6 +1,6 @@
{
"name": "babel-loader",
"version": "8.3.0",
"version": "8.4.1",
"description": "babel module loader for webpack",
"files": [
"lib"
@@ -11,7 +11,7 @@
},
"dependencies": {
"find-cache-dir": "^3.3.1",
"loader-utils": "^2.0.0",
"loader-utils": "^2.0.4",
"make-dir": "^3.1.0",
"schema-utils": "^2.6.5"
},
@@ -44,7 +44,7 @@
"react-intl-webpack-plugin": "^0.3.0",
"rimraf": "^3.0.0",
"semver": "7.3.2",
"webpack": "^5.34.0"
"webpack": "^5.61.0"
},
"scripts": {
"clean": "rimraf lib/",
@@ -123,5 +123,6 @@
},
"resolutions": {
"nyc/node-preload": "0.2.0"
}
},
"packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
}