From 24e945c6accd7ac3df810c62323ff331b42e2fdb Mon Sep 17 00:00:00 2001 From: Logan McAnsh Date: Sat, 20 Aug 2022 17:48:52 -0400 Subject: [PATCH 1/3] chore: allow setting tsconfig moduleResolution to `node`, `node16`, and `nodenext` Signed-off-by: Logan McAnsh --- integration/tsconfig-test.ts | 1 + .../utils/tsconfig/write-config-defaults.ts | 27 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/integration/tsconfig-test.ts b/integration/tsconfig-test.ts index 61da678887e..cb380ae7fa9 100644 --- a/integration/tsconfig-test.ts +++ b/integration/tsconfig-test.ts @@ -74,6 +74,7 @@ test("shouldn't change suggested config if set", async () => { compilerOptions: { ...DEFAULT_CONFIG.compilerOptions, strict: false, + moduleResolution: "NodeNext", }, }; diff --git a/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts b/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts index 320e37e4c7b..f8bc26a3829 100644 --- a/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts +++ b/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts @@ -23,7 +23,6 @@ let requiredCompilerOptions: TsConfigJson.CompilerOptions = { esModuleInterop: true, isolatedModules: true, jsx: "react-jsx", - moduleResolution: "node", noEmit: true, resolveJsonModule: true, }; @@ -92,6 +91,7 @@ export function writeConfigDefaults(configPath: string) { ); } } + for (let key of objectKeys(requiredCompilerOptions)) { if (fullConfig.compilerOptions[key] !== requiredCompilerOptions[key]) { config.compilerOptions[key] = requiredCompilerOptions[key] as any; @@ -102,6 +102,31 @@ export function writeConfigDefaults(configPath: string) { ); } } + + if (typeof fullConfig.compilerOptions.moduleResolution === "undefined") { + fullConfig.compilerOptions.moduleResolution = "node"; + config.compilerOptions.moduleResolution = "node"; + suggestedChanges.push( + colors.blue("compilerOptions.moduleResolution") + + " was set to " + + colors.bold(`'node'`) + ); + } + + if ( + !["node", "node16", "nodenext"].includes( + fullConfig.compilerOptions.moduleResolution.toLowerCase() + ) + ) { + config.compilerOptions.moduleResolution = "node"; + + suggestedChanges.push( + colors.blue("compilerOptions.moduleResolution") + + " was set to " + + colors.bold(`'node'`) + ); + } + if (suggestedChanges.length > 0 || requiredChanges.length > 0) { fse.writeFileSync( configPath, From a24dda245e5f734470ccb34d869f6542ff1597f1 Mon Sep 17 00:00:00 2001 From: Logan McAnsh Date: Thu, 25 Aug 2022 14:06:34 -0400 Subject: [PATCH 2/3] Create five-apricots-happen.md --- .changeset/five-apricots-happen.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/five-apricots-happen.md diff --git a/.changeset/five-apricots-happen.md b/.changeset/five-apricots-happen.md new file mode 100644 index 00000000000..3dfc7115534 --- /dev/null +++ b/.changeset/five-apricots-happen.md @@ -0,0 +1,6 @@ +--- +"remix": patch +"@remix-run/dev": patch +--- + +allow setting tsconfig moduleResolution to `node`, `node16`, and `nodenext` From 68ef70b93bd8bf60ebb84556e252bc293cafaa3b Mon Sep 17 00:00:00 2001 From: Logan McAnsh Date: Wed, 21 Sep 2022 09:11:01 -0500 Subject: [PATCH 3/3] Update write-config-defaults.ts --- .../compiler/utils/tsconfig/write-config-defaults.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts b/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts index bdd6e63ec6b..e77c171bac0 100644 --- a/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts +++ b/packages/remix-dev/compiler/utils/tsconfig/write-config-defaults.ts @@ -118,7 +118,7 @@ export function writeConfigDefaults(configPath: string) { if (typeof fullConfig.compilerOptions.moduleResolution === "undefined") { fullConfig.compilerOptions.moduleResolution = "node"; config.compilerOptions.moduleResolution = "node"; - suggestedChanges.push( + requiredChanges.push( colors.blue("compilerOptions.moduleResolution") + " was set to " + colors.bold(`'node'`) @@ -132,7 +132,7 @@ export function writeConfigDefaults(configPath: string) { ) { config.compilerOptions.moduleResolution = "node"; - suggestedChanges.push( + requiredChanges.push( colors.blue("compilerOptions.moduleResolution") + " was set to " + colors.bold(`'node'`)