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

getOutputFileNames is returning incorrect path #41780

Closed
benmccann opened this issue Dec 2, 2020 · 1 comment · Fixed by #41811
Closed

getOutputFileNames is returning incorrect path #41780

benmccann opened this issue Dec 2, 2020 · 1 comment · Fixed by #41811
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@benmccann
Copy link
Contributor

benmccann commented Dec 2, 2020

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 git@github.com: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:

@benmccann
Copy link
Contributor Author

benmccann commented Dec 2, 2020

getOutputFileNames calls getOwnOutputFileNames, which calls getOutputJSFileName, which calls getOutputPathWithoutChangingExt, which is where src is being added to the path:

getRelativePathFromDirectory(rootDirOfOptions(configFile), inputFileName, ignoreCase)

None of these four functions have tests in the TypeScript repo. getOutputFileNames is the only one that's exported

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Dec 2, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.2.1 milestone Dec 2, 2020
@sheetalkamat sheetalkamat added Bug A bug in TypeScript Fix Available A PR has been opened for this issue and removed Needs Investigation This issue needs a team member to investigate its status. labels Dec 3, 2020
sheetalkamat added a commit that referenced this issue Dec 3, 2020
sheetalkamat added a commit that referenced this issue Dec 4, 2020
sheetalkamat added a commit that referenced this issue Dec 7, 2020
…am emit file path calculation (#41811)

* Baseline showing #41801 and other issues with output path calculation

* Add a way to note descripencies between clean and incremental build

* Add descripency when no rootDir is specified but project is composite

* if rootDir is specified, irrespective of whether all files belong to rootDir, the paths should be calculated from rootDir

* Fix the output file names api to use the correct common source directory

* Tests for #41780

* Spelling
scalder27 pushed a commit to scalder27/TypeScript that referenced this issue Dec 7, 2020
…am emit file path calculation (microsoft#41811)

* Baseline showing microsoft#41801 and other issues with output path calculation

* Add a way to note descripencies between clean and incremental build

* Add descripency when no rootDir is specified but project is composite

* if rootDir is specified, irrespective of whether all files belong to rootDir, the paths should be calculated from rootDir

* Fix the output file names api to use the correct common source directory

* Tests for microsoft#41780

* Spelling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
3 participants