Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typescript): Allow for using compilerOptions.moduleResolution #1453

Merged
merged 2 commits into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/typescript/src/options/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function containsEnumOptions(
*/
function setModuleResolutionKind(parsedConfig: ParsedCommandLine): ParsedCommandLine {
const moduleKind = parsedConfig.options.module;
// Fallback if `parsedConfig.options.moduleResolution` is not set
const moduleResolution =
moduleKind === ModuleKind.Node16
? ModuleResolutionKind.Node16
Expand All @@ -115,8 +116,8 @@ function setModuleResolutionKind(parsedConfig: ParsedCommandLine): ParsedCommand
return {
...parsedConfig,
options: {
...parsedConfig.options,
moduleResolution
moduleResolution,
...parsedConfig.options
}
};
}
Expand Down
4 changes: 4 additions & 0 deletions packages/typescript/test/fixtures/nodenext-module/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import foo from 'foo';

const bar: string = foo;
console.log(bar);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"module": "nodenext"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"compilerOptions": {
"module": "nodenext"
"moduleResolution": "nodenext"
shellscape marked this conversation as resolved.
Show resolved Hide resolved
}
}
22 changes: 21 additions & 1 deletion packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,26 @@ test.serial('works when code is in src directory', async (t) => {
});

test.serial('correctly resolves types in a nodenext module', async (t) => {
const warnings = [];
const bundle = await rollup({
input: 'fixtures/nodenext-module/index.ts',
plugins: [
typescript({
tsconfig: 'fixtures/nodenext-module/tsconfig.json'
})
],
onwarn({ toString, ...warning }) {
warnings.push(warning);
}
});
const code = await getCode(bundle, outputOptions);

t.true(code.includes('const bar = foo'), code);
t.is(warnings.length, 1);
t.is(warnings[0].code, 'UNRESOLVED_IMPORT');
});

test.serial('correctly resolves types with nodenext moduleResolution', async (t) => {
const warnings = [];
const bundle = await rollup({
input: 'fixtures/nodenext-resolution/index.ts',
Expand All @@ -1306,7 +1326,7 @@ test.serial('correctly resolves types in a nodenext module', async (t) => {
});
const code = await getCode(bundle, outputOptions);

t.true(code.includes('const bar = foo'), code);
t.true(code.includes('var bar = foo'), code);
t.is(warnings.length, 1);
t.is(warnings[0].code, 'UNRESOLVED_IMPORT');
});
Expand Down