Skip to content

Commit

Permalink
appTsConfig immutability handling by immer (facebook#10027)
Browse files Browse the repository at this point in the history
Co-authored-by: mad-jose <[email protected]>
  • Loading branch information
2 people authored and wombleton committed Jun 1, 2021
1 parent e1e5a07 commit 0b2c8be
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js
Original file line number Diff line number Diff line change
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 0b2c8be

Please sign in to comment.