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

@@ -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];
}