resolve race condition when creating rd.json

This commit is contained in:
Bastian Ike
2021-01-25 15:01:24 +01:00
parent e6830ec131
commit 872df4972c

View File

@@ -10,17 +10,12 @@ process.env.NODE_ENV = 'production';
// ignoring them. In the future, promise rejections that are not handled will // ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code. // terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => { process.on('unhandledRejection', err => {
throw err; throw err;
}); });
// create radar
require('../bin/tasks/radarjson').radarJsonGenerator()
// Ensure environment variables are read. // Ensure environment variables are read.
require('../config/env'); require('../config/env');
const path = require('path'); const path = require('path');
const chalk = require('react-dev-utils/chalk'); const chalk = require('react-dev-utils/chalk');
const fs = require('fs-extra'); const fs = require('fs-extra');
@@ -34,7 +29,7 @@ const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
const printBuildError = require('react-dev-utils/printBuildError'); const printBuildError = require('react-dev-utils/printBuildError');
const measureFileSizesBeforeBuild = const measureFileSizesBeforeBuild =
FileSizeReporter.measureFileSizesBeforeBuild; FileSizeReporter.measureFileSizesBeforeBuild;
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild; const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
const useYarn = fs.existsSync(paths.yarnLockFile); const useYarn = fs.existsSync(paths.yarnLockFile);
@@ -46,7 +41,7 @@ const isInteractive = process.stdout.isTTY;
// Warn and crash if required files are missing // Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) { if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1); process.exit(1);
} }
// Generate configuration // Generate configuration
@@ -54,164 +49,167 @@ const config = configFactory('production');
// We require that you explicitly set browsers and do not fall back to // We require that you explicitly set browsers and do not fall back to
// browserslist defaults. // browserslist defaults.
const { checkBrowsers } = require('react-dev-utils/browsersHelper'); const {checkBrowsers} = require('react-dev-utils/browsersHelper');
checkBrowsers(paths.appPath, isInteractive) require('../bin/tasks/radarjson').radarJsonGenerator()
.then(() => { .then(checkBrowsers(paths.appPath, isInteractive))
// First, read the current file sizes in build directory. .then(() => {
// This lets us display how much they changed later. // First, read the current file sizes in build directory.
return measureFileSizesBeforeBuild(paths.appBuild); // This lets us display how much they changed later.
}) return measureFileSizesBeforeBuild(paths.appBuild);
.then(previousFileSizes => { })
// Remove all content but keep the directory so that .then(previousFileSizes => {
// if you're in it, you don't end up in Trash // Remove all content but keep the directory so that
fs.emptyDirSync(paths.appBuild); // if you're in it, you don't end up in Trash
// Merge with the public folder fs.emptyDirSync(paths.appBuild);
copyPublicFolder(); // Merge with the public folder
// Start the webpack build copyPublicFolder();
return build(previousFileSizes); // Start the webpack build
}) return build(previousFileSizes);
.then( })
({ stats, previousFileSizes, warnings }) => { .then(
if (warnings.length) { ({stats, previousFileSizes, warnings}) => {
console.log(chalk.yellow('Compiled with warnings.\n')); if (warnings.length) {
console.log(warnings.join('\n\n')); console.log(chalk.yellow('Compiled with warnings.\n'));
console.log( console.log(warnings.join('\n\n'));
'\nSearch for the ' + console.log(
chalk.underline(chalk.yellow('keywords')) + '\nSearch for the ' +
' to learn more about each warning.' chalk.underline(chalk.yellow('keywords')) +
); ' to learn more about each warning.'
console.log( );
'To ignore, add ' + console.log(
chalk.cyan('// eslint-disable-next-line') + 'To ignore, add ' +
' to the line before.\n' chalk.cyan('// eslint-disable-next-line') +
); ' to the line before.\n'
} else { );
console.log(chalk.green('Compiled successfully.\n')); } else {
} console.log(chalk.green('Compiled successfully.\n'));
}
console.log('File sizes after gzip:\n'); console.log('File sizes after gzip:\n');
printFileSizesAfterBuild( printFileSizesAfterBuild(
stats, stats,
previousFileSizes, previousFileSizes,
paths.appBuild, paths.appBuild,
WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_BUNDLE_GZIP_SIZE,
WARN_AFTER_CHUNK_GZIP_SIZE WARN_AFTER_CHUNK_GZIP_SIZE
); );
console.log(); console.log();
const appPackage = require(paths.appPackageJson); const appPackage = require(paths.appPackageJson);
const publicUrl = paths.publicUrlOrPath; const publicUrl = paths.publicUrlOrPath;
const publicPath = config.output.publicPath; const publicPath = config.output.publicPath;
const buildFolder = path.relative(process.cwd(), paths.appBuild); const buildFolder = path.relative(process.cwd(), paths.appBuild);
printHostingInstructions( printHostingInstructions(
appPackage, appPackage,
publicUrl, publicUrl,
publicPath, publicPath,
buildFolder, buildFolder,
useYarn useYarn
); );
}, },
err => { err => {
const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true'; const tscCompileOnError = process.env.TSC_COMPILE_ON_ERROR === 'true';
if (tscCompileOnError) { if (tscCompileOnError) {
console.log( console.log(
chalk.yellow( chalk.yellow(
'Compiled with the following type errors (you may want to check these before deploying your app):\n' 'Compiled with the following type errors (you may want to check these before deploying your app):\n'
) )
); );
printBuildError(err); printBuildError(err);
} else { } else {
console.log(chalk.red('Failed to compile.\n')); console.log(chalk.red('Failed to compile.\n'));
printBuildError(err); printBuildError(err);
process.exit(1);
}
}
)
.catch(err => {
if (err && err.message) {
console.log(err.message);
}
process.exit(1); process.exit(1);
} });
}
)
.catch(err => {
if (err && err.message) {
console.log(err.message);
}
process.exit(1);
});
// Create the production build and print the deployment instructions. // Create the production build and print the deployment instructions.
function build(previousFileSizes) { function build(previousFileSizes) {
// We used to support resolving modules according to `NODE_PATH`. // We used to support resolving modules according to `NODE_PATH`.
// This now has been deprecated in favor of jsconfig/tsconfig.json // This now has been deprecated in favor of jsconfig/tsconfig.json
// This lets you use absolute paths in imports inside large monorepos: // This lets you use absolute paths in imports inside large monorepos:
if (process.env.NODE_PATH) { if (process.env.NODE_PATH) {
console.log(
chalk.yellow(
'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.'
)
);
console.log();
}
console.log('Creating an optimized production build...');
const compiler = webpack(config);
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
let messages;
if (err) {
if (!err.message) {
return reject(err);
}
let errMessage = err.message;
// Add additional information for postcss errors
if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
errMessage +=
'\nCompileError: Begins at CSS selector ' +
err['postcssNode'].selector;
}
messages = formatWebpackMessages({
errors: [errMessage],
warnings: [],
});
} else {
messages = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true })
);
}
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1;
}
return reject(new Error(messages.errors.join('\n\n')));
}
if (
process.env.CI &&
(typeof process.env.CI !== 'string' ||
process.env.CI.toLowerCase() !== 'false') &&
messages.warnings.length
) {
console.log( console.log(
chalk.yellow( chalk.yellow(
'\nTreating warnings as errors because process.env.CI = true.\n' + 'Setting NODE_PATH to resolve modules absolutely has been deprecated in favor of setting baseUrl in jsconfig.json (or tsconfig.json if you are using TypeScript) and will be removed in a future major release of create-react-app.'
'Most CI servers set it automatically.\n' )
)
); );
return reject(new Error(messages.warnings.join('\n\n'))); console.log();
} }
return resolve({ console.log('Creating an optimized production build...');
stats,
previousFileSizes, const compiler = webpack(config);
warnings: messages.warnings, return new Promise((resolve, reject) => {
}); compiler.run((err, stats) => {
let messages;
if (err) {
if (!err.message) {
return reject(err);
}
let errMessage = err.message;
// Add additional information for postcss errors
if (Object.prototype.hasOwnProperty.call(err, 'postcssNode')) {
errMessage +=
'\nCompileError: Begins at CSS selector ' +
err['postcssNode'].selector;
}
messages = formatWebpackMessages({
errors: [errMessage],
warnings: [],
});
} else {
messages = formatWebpackMessages(
stats.toJson({all: false, warnings: true, errors: true})
);
}
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1;
}
return reject(new Error(messages.errors.join('\n\n')));
}
if (
process.env.CI &&
(typeof process.env.CI !== 'string' ||
process.env.CI.toLowerCase() !== 'false') &&
messages.warnings.length
) {
console.log(
chalk.yellow(
'\nTreating warnings as errors because process.env.CI = true.\n' +
'Most CI servers set it automatically.\n'
)
);
return reject(new Error(messages.warnings.join('\n\n')));
}
return resolve({
stats,
previousFileSizes,
warnings: messages.warnings,
});
});
}); });
});
} }
function copyPublicFolder() { function copyPublicFolder() {
fs.copySync(paths.appPublic, paths.appBuild, { fs.copySync(paths.appPublic, paths.appBuild, {
dereference: true, dereference: true,
filter: file => file !== paths.appHtml, filter: file => file !== paths.appHtml,
}); });
} }