Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@types/resolve": "^1.20.2",
"buble": "^0.20.0",
"rollup": "^4.0.0-24",
"typescript": "^4.8.3"
"typescript": "^5.9.3"
},
"types": "./types/index.d.ts"
}
3 changes: 1 addition & 2 deletions packages/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
const mode =
typeof ts.getImpliedNodeFormatForFile === 'function'
? ts.getImpliedNodeFormatForFile(
// @ts-expect-error
containingFile,
undefined, // eslint-disable-line no-undefined
{ ...ts.sys, ...formatHost },
Expand All @@ -236,7 +235,7 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
const resolved = resolveModule(importee, containingFile, undefined, mode);

if (resolved) {
if (/\.d\.[cm]?ts/.test(resolved.extension)) return null;
if (isDeclarationOutputFile(resolved.extension)) return null;
if (!filter(resolved.resolvedFileName)) return null;
return path.normalize(resolved.resolvedFileName);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/options/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function setModuleResolutionKind(parsedConfig: ParsedCommandLine): ParsedCommand
};
}

const configCache = new Map() as typescript.ESMap<string, ExtendedConfigCacheEntry>;
const configCache = new Map() as Map<string, ExtendedConfigCacheEntry>;

/**
* Parse the Typescript config to use with the plugin.
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript/src/outputFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function isTypeScriptMapOutputFile(name: string): boolean {
* Checks if the given OutputFile represents some declaration
*/
export function isDeclarationOutputFile(name: string): boolean {
return /\.d\.[cm]?ts$/.test(name);
return /\.d(\..+)?\.[cm]?ts$/.test(name);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript/src/watchProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ function createWatchHost(
containingFile,
_reusedNames,
redirectedReference,
_optionsOnlyWithNewerTsVersions,
compilerOptions,
containingSourceFile
) {
return moduleNames.map((moduleName, i) => {
const mode = containingSourceFile
? ts.getModeForResolutionAtIndex?.(containingSourceFile, i)
? ts.getModeForResolutionAtIndex?.(containingSourceFile, i, compilerOptions)
: undefined; // eslint-disable-line no-undefined

return resolveModule(moduleName, containingFile, redirectedReference, mode);
Expand Down
3 changes: 3 additions & 0 deletions packages/typescript/test/fixtures/arbitrary-dts/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import module from './module.custom';

export default module.x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
x: 5,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare const CustomModule: {
x: Number;
}
export default CustomModule;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowArbitraryExtensions": true
},
}
19 changes: 16 additions & 3 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ test.serial('warns for invalid module types', async (t) => {
code: 'PLUGIN_WARNING',
plugin: 'typescript',
pluginCode: 'TS6046',
message: `@rollup/plugin-typescript TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'nodenext'.`
message: `@rollup/plugin-typescript TS6046: Argument for '--module' option must be: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', 'es2015', 'es2020', 'es2022', 'esnext', 'node16', 'node18', 'node20', 'nodenext', 'preserve'.`
}
]);
});
Expand Down Expand Up @@ -496,6 +496,18 @@ test.serial('should not resolve .d.ts files', async (t) => {
t.deepEqual(imports, ['an-import']);
});

test.serial('should not resolve arbitrary .d.<ext>.ts files', async (t) => {
const bundle = await rollup({
input: 'fixtures/arbitrary-dts/main.ts',
plugins: [typescript({ tsconfig: 'fixtures/arbitrary-dts/tsconfig.json' })],
onwarn
});
const arbitraryDeclarationModules = bundle.cache.modules.filter((module) =>
module.id.includes('.d.custom.ts')
);
t.is(arbitraryDeclarationModules.length, 0);
});

test.serial('should transpile JSX if enabled', async (t) => {
process.chdir('fixtures/jsx');

Expand Down Expand Up @@ -1538,8 +1550,9 @@ test.serial('correctly resolves types with nodenext moduleResolution', async (t)
const code = await getCode(bundle, outputOptions);

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

test.serial('noForceEmit option defers to tsconfig.json for emitDeclarationOnly', async (t) => {
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

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