mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
refactor extend babel options
This commit is contained in:
@@ -304,22 +304,33 @@ BCp.processOneFileForTarget = function (inputFile, source) {
|
||||
},
|
||||
};
|
||||
|
||||
this.inferTypeScriptConfig(features, inputFile, cacheOptions.cacheDeps);
|
||||
// Helper function to setup Babel options
|
||||
const setupBabelOptions = () => {
|
||||
this.inferTypeScriptConfig(features, inputFile, cacheOptions.cacheDeps);
|
||||
|
||||
var babelOptions = Babel.getDefaultOptions(features);
|
||||
babelOptions.caller = { name: "meteor", arch };
|
||||
var babelOptions = Babel.getDefaultOptions(features);
|
||||
babelOptions.caller = { name: "meteor", arch };
|
||||
|
||||
this.inferExtraBabelOptions(inputFile, babelOptions, cacheOptions.cacheDeps);
|
||||
babelOptions.sourceMaps = true;
|
||||
const filename = packageName
|
||||
? `packages/${packageName}/${inputFilePath}`
|
||||
: inputFilePath;
|
||||
babelOptions.filename = babelOptions.sourceFileName = filename;
|
||||
|
||||
babelOptions.sourceMaps = true;
|
||||
this.inferExtraBabelOptions(inputFile, babelOptions, cacheOptions.cacheDeps);
|
||||
|
||||
if (this.modifyBabelConfig) {
|
||||
this.modifyBabelConfig(babelOptions, inputFile);
|
||||
}
|
||||
|
||||
return babelOptions;
|
||||
};
|
||||
|
||||
// Define babelOptions at the outer scope so it's available for source map
|
||||
var babelOptions;
|
||||
const filename = packageName
|
||||
? `packages/${packageName}/${inputFilePath}`
|
||||
: inputFilePath;
|
||||
babelOptions.filename = babelOptions.sourceFileName = filename;
|
||||
|
||||
if (this.modifyBabelConfig) {
|
||||
this.modifyBabelConfig(babelOptions, inputFile);
|
||||
}
|
||||
|
||||
try {
|
||||
var result = (() => {
|
||||
@@ -384,6 +395,8 @@ BCp.processOneFileForTarget = function (inputFile, source) {
|
||||
arch,
|
||||
});
|
||||
}
|
||||
// Set babelOptions.filename for source map
|
||||
babelOptions = { filename };
|
||||
return compilation;
|
||||
}
|
||||
|
||||
@@ -396,7 +409,12 @@ BCp.processOneFileForTarget = function (inputFile, source) {
|
||||
// Save result in cache
|
||||
this.writeToSwcCache({ cacheKey, compilation });
|
||||
usedSwc = true;
|
||||
// Set babelOptions.filename for source map
|
||||
babelOptions = { filename };
|
||||
} else {
|
||||
// Set up Babel options only when compiling with Babel
|
||||
babelOptions = setupBabelOptions();
|
||||
|
||||
compilation = compileWithBabel(source, babelOptions, cacheOptions);
|
||||
usedSwc = false;
|
||||
}
|
||||
@@ -414,6 +432,10 @@ BCp.processOneFileForTarget = function (inputFile, source) {
|
||||
} catch (e) {
|
||||
this._swcIncompatible[cacheKey] = true;
|
||||
// If SWC fails, fall back to Babel
|
||||
|
||||
// Set up Babel options for fallback
|
||||
babelOptions = setupBabelOptions();
|
||||
|
||||
compilation = compileWithBabel(source, babelOptions, cacheOptions);
|
||||
if (config?.verbose) {
|
||||
logTranspilation({
|
||||
|
||||
Reference in New Issue
Block a user