Skip to content

Commit

Permalink
chore(remix-dev): allow setting tsconfig's moduleResolution to `n…
Browse files Browse the repository at this point in the history
…ode`, `node16` or `nodenext` (#4034)
  • Loading branch information
mcansh authored Sep 21, 2022
1 parent 82d4ea3 commit cd26306
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/five-apricots-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"remix": patch
"@remix-run/dev": patch
---

allow setting tsconfig moduleResolution to `node`, `node16`, and `nodenext`
1 change: 1 addition & 0 deletions integration/tsconfig-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ test("shouldn't change suggested config if set", async () => {
compilerOptions: {
...DEFAULT_CONFIG.compilerOptions,
strict: false,
moduleResolution: "NodeNext",
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ let requiredCompilerOptions: TsConfigJson.CompilerOptions = {
esModuleInterop: true,
isolatedModules: true,
jsx: "react-jsx",
moduleResolution: "node",
noEmit: true,
resolveJsonModule: true,
};
Expand Down Expand Up @@ -104,6 +103,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;
Expand All @@ -114,6 +114,31 @@ export function writeConfigDefaults(configPath: string) {
);
}
}

if (typeof fullConfig.compilerOptions.moduleResolution === "undefined") {
fullConfig.compilerOptions.moduleResolution = "node";
config.compilerOptions.moduleResolution = "node";
requiredChanges.push(
colors.blue("compilerOptions.moduleResolution") +
" was set to " +
colors.bold(`'node'`)
);
}

if (
!["node", "node16", "nodenext"].includes(
fullConfig.compilerOptions.moduleResolution.toLowerCase()
)
) {
config.compilerOptions.moduleResolution = "node";

requiredChanges.push(
colors.blue("compilerOptions.moduleResolution") +
" was set to " +
colors.bold(`'node'`)
);
}

if (suggestedChanges.length > 0 || requiredChanges.length > 0) {
fse.writeFileSync(
configPath,
Expand Down

0 comments on commit cd26306

Please sign in to comment.