Thanks to visit codestin.com
Credit goes to github.com

Skip to content

getOutputFileNames is returning incorrect path #41780

Closed
@benmccann

Description

@benmccann

Importance

The Rollup TypeScript plugin cannot handle files that are located in a sub-directory: rollup/plugins#287

This is the #1 most reported bug in the Rollup ecosystem (i.e. including both the core package and all plugins) with over 100 thumbs up on the issue

Overview

tsc uses getSourceFilePathInNewDir to find out where the output is placed. However, this method is not exposed. Thus, the Rollup plugin must use getOutputFileNames, which often returns incorrectly.

TypeScript Version: 4.1.2

Search Terms: getOutputFileNames

Code

I wrote a unit test that fails.

I know the TypeScript team gets an insane amount of bug reports. I hope you might bear with me a little bit on this one given how widely used Rollup is and how many people this is impacting as noted above.

The call to getOutputFileNames is made in src/outputFile.ts. I added some console.log statements that show the options it's being called with. It seems pretty clear to me that this is a bug because none of the option values reference the src directory specifically. The outDir is correctly showing the dist/ directory.

I pushed this to my fork of the Rollup plugins. (You can install pnpm with npm install -g pnpm if you do not have it)

git clone [email protected]:benmccann/plugins.git
cd plugins
git checkout src-dir-test-enabled
pnpm install
cd packages/typescript
pnpm ts-bug

pnpm ts-bug is an npm script that runs a single unit test I added, which fails because of this bug. Running it will print to the console the arguments passed to getOutputFileNames and result from it

Expected behavior:

getOutputFileNames should return dist/index.js

Actual behavior:

getOutputFileNames returns dist/src/index.js

Playground Link:

Related Issues:

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions