Skip to content

Commit 6a39607

Browse files
josezonemad-jose
andauthoredFeb 3, 2021
appTsConfig immutability handling by immer (#10027)
Co-authored-by: mad-jose <joset@yeswearemad.com>
1 parent d229676 commit 6a39607

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed
 

‎packages/react-scripts/scripts/utils/verifyTypeScriptSetup.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,7 @@ function verifyTypeScriptSetup() {
218218
if (appTsConfig.compilerOptions == null) {
219219
appTsConfig.compilerOptions = {};
220220
firstTimeSetup = true;
221-
} else {
222-
// This is bug fix code of https://github.com/facebook/create-react-app/issues/9868
223-
// Bellow code release variable from non-extensible and freeze status.
224-
appTsConfig.compilerOptions = JSON.parse(JSON.stringify(appTsConfig.compilerOptions));
225-
226-
// Original appTsConfig.compilerOptions status
227-
// Object.isExtensible(appTsConfig.compilerOptions) output: false
228-
// Object.isFrozen(appTsConfig.compilerOptions) output: true
229-
}
221+
}
230222

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

237229
if (suggested != null) {
238230
if (parsedCompilerOptions[option] === undefined) {
239-
appTsConfig.compilerOptions[option] = suggested;
231+
appTsConfig = immer(appTsConfig, config => {
232+
config.compilerOptions[option] = suggested;
233+
});
240234
messages.push(
241235
`${coloredOption} to be ${chalk.bold(
242236
'suggested'
243237
)} value: ${chalk.cyan.bold(suggested)} (this can be changed)`
244238
);
245239
}
246240
} else if (parsedCompilerOptions[option] !== valueToCheck) {
247-
appTsConfig.compilerOptions[option] = value;
241+
appTsConfig = immer(appTsConfig, config => {
242+
config.compilerOptions[option] = value;
243+
});
248244
messages.push(
249245
`${coloredOption} ${chalk.bold(
250246
valueToCheck == null ? 'must not' : 'must'
@@ -256,7 +252,9 @@ function verifyTypeScriptSetup() {
256252

257253
// tsconfig will have the merged "include" and "exclude" by this point
258254
if (parsedTsConfig.include == null) {
259-
appTsConfig.include = ['src'];
255+
appTsConfig = immer(appTsConfig, config => {
256+
config.include = ['src'];
257+
});
260258
messages.push(
261259
`${chalk.cyan('include')} should be ${chalk.cyan.bold('src')}`
262260
);

0 commit comments

Comments
 (0)
Please sign in to comment.