Skip to content

Commit

Permalink
appTsConfig immutability handling by immer (#10027)
Browse files Browse the repository at this point in the history
Co-authored-by: mad-jose <joset@yeswearemad.com>
  • Loading branch information
josezone and mad-jose committed Feb 3, 2021
1 parent d229676 commit 6a39607
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
Expand Up @@ -218,15 +218,7 @@ function verifyTypeScriptSetup() {
if (appTsConfig.compilerOptions == null) {
appTsConfig.compilerOptions = {};
firstTimeSetup = true;
} else {
// This is bug fix code of https://github.com/facebook/create-react-app/issues/9868
// Bellow code release variable from non-extensible and freeze status.
appTsConfig.compilerOptions = JSON.parse(JSON.stringify(appTsConfig.compilerOptions));

// Original appTsConfig.compilerOptions status
// Object.isExtensible(appTsConfig.compilerOptions) output: false
// Object.isFrozen(appTsConfig.compilerOptions) output: true
}
}

for (const option of Object.keys(compilerOptions)) {
const { parsedValue, value, suggested, reason } = compilerOptions[option];
Expand All @@ -236,15 +228,19 @@ function verifyTypeScriptSetup() {

if (suggested != null) {
if (parsedCompilerOptions[option] === undefined) {
appTsConfig.compilerOptions[option] = suggested;
appTsConfig = immer(appTsConfig, config => {
config.compilerOptions[option] = suggested;
});
messages.push(
`${coloredOption} to be ${chalk.bold(
'suggested'
)} value: ${chalk.cyan.bold(suggested)} (this can be changed)`
);
}
} else if (parsedCompilerOptions[option] !== valueToCheck) {
appTsConfig.compilerOptions[option] = value;
appTsConfig = immer(appTsConfig, config => {
config.compilerOptions[option] = value;
});
messages.push(
`${coloredOption} ${chalk.bold(
valueToCheck == null ? 'must not' : 'must'
Expand All @@ -256,7 +252,9 @@ function verifyTypeScriptSetup() {

// tsconfig will have the merged "include" and "exclude" by this point
if (parsedTsConfig.include == null) {
appTsConfig.include = ['src'];
appTsConfig = immer(appTsConfig, config => {
config.include = ['src'];
});
messages.push(
`${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`
);
Expand Down

0 comments on commit 6a39607

Please sign in to comment.