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)!: incorrect declarations directory #1313

Merged

Conversation

georg94
Copy link
Contributor

@georg94 georg94 commented Oct 12, 2022

Rollup Plugin Name: plugin-typescript

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

If yes, then include "BREAKING CHANGES:" in the first commit message body, followed by a description of what is breaking.

List any relevant issue numbers:

Description

The commit 5f78173 changed the behaviour of the typescript plugin. This introduced the issue #1230: The declarationDir was now ignored for single file setups. I made some analysis and found the problem:

  • In the construction of the plugin the typescript configuration is parsed
  • while parsing all paths are made absolute, prepended with process.cwd() (packages/typescript/src/options/tsconfig.ts#L147)
  • in order to output declaration files the baseDir is determied from the parsed config
  • the id (filename generated by typescript) of the declaration file is also an absolute path, generated with the config
  • as the "prefixes" match the result file misses the declarationDir

Example:

let tsConfig = {
  // [...]
  "declaration": true,
  "declarationDir": "types"
  // [...]
};
// After initial config processing
tsConfig = {
  // [...]
  "declaration": true,
  "declarationDir": "/home/user/app/types"
  // [...]
};
// declaration file generation
const id = '/home/user/app/types/index.d.ts';
const baseDir = parsedOptions.options.declarationDir; // -> '/home/user/app/types'
path.relative(baseDir, id) // gives `index.d.ts` instead of `types/index.d.ts`

There is another description of this error in #1230 (comment)

@shellscape shellscape changed the title Fix wrong declarations directory in typescript plugin fix(typescript): incorrect declarations directory Oct 24, 2022
@georg94 georg94 force-pushed the fix/1230-typescript-declarations-directory branch from f64222d to c74c11d Compare October 25, 2022 11:31
@shellscape
Copy link
Collaborator

Because this fix is modifying the output of the plugin, it's a breaking change and will be released as a new major.

@shellscape shellscape changed the title fix(typescript): incorrect declarations directory fix(typescript)!: incorrect declarations directory Nov 27, 2022
@shellscape shellscape merged commit a5c90d1 into rollup:master Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants