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

Honor declaration config #61

Closed
amcdnl opened this issue Jul 19, 2016 · 20 comments
Closed

Honor declaration config #61

amcdnl opened this issue Jul 19, 2016 · 20 comments

Comments

@amcdnl
Copy link

amcdnl commented Jul 19, 2016

It would be nice if the declaration: true flag would be honored in the output.

@GiedriusGrabauskas
Copy link

👍

eventualbuddha referenced this issue in decaffeinate/coffee-lex Dec 11, 2016
This commit changes the distributable file format in the following ways:
- unbundles both the commonjs and ES module files from one file each to one for each original file for each format
- includes `.d.ts` files for each original source file
- adds `types` field to `package.json` per https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
- removes rollup as the dist builder and uses a wrapper, `script/build`, that uses `tsc` directly
- removes `coffee-lex.js.flow`

I don't like that I had to write a custom build script for this. It makes me feel like I'm doing something incorrectly to support both commonjs and ES modules. I removed rollup because it didn't seem to play well with TypeScript from a publishing perspective. Specifically, I couldn't find any way to automatically build a `d.ts` file for the project bundle generated by rollup that didn't have serious shortcomings (https://github.com/rollup/rollup-plugin-typescript/issues/54). I considered keeping the bundled `.js` and `.mjs` files and using multiple `.d.ts` files, but there didn't seem to be much benefit over simply leaving all of them split up. Other rollup-based projects can still efficiently bundle coffee-lex with the modules split out as separate files.
eventualbuddha referenced this issue in decaffeinate/coffee-lex Dec 11, 2016
This commit changes the distributable file format in the following ways:
- unbundles both the commonjs and ES module files from one file each to one for each original file for each format
- includes `.d.ts` files for each original source file
- adds `types` field to `package.json` per https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
- removes rollup as the dist builder and uses a wrapper, `script/build`, that uses `tsc` directly
- removes `coffee-lex.js.flow`

I don't like that I had to write a custom build script for this. It makes me feel like I'm doing something incorrectly to support both commonjs and ES modules. I removed rollup because it didn't seem to play well with TypeScript from a publishing perspective. Specifically, I couldn't find any way to automatically build a `d.ts` file for the project bundle generated by rollup that didn't have serious shortcomings (https://github.com/rollup/rollup-plugin-typescript/issues/54). I considered keeping the bundled `.js` and `.mjs` files and using multiple `.d.ts` files, but there didn't seem to be much benefit over simply leaving all of them split up. Other rollup-based projects can still efficiently bundle coffee-lex with the modules split out as separate files.
eventualbuddha referenced this issue in decaffeinate/coffee-lex Dec 13, 2016
This commit changes the distributable file format in the following ways:
- unbundles both the commonjs and ES module files from one file each to one for each original file for each format
- includes `.d.ts` files for each original source file
- adds `types` field to `package.json` per https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
- removes rollup as the dist builder and uses a wrapper, `script/build`, that uses `tsc` directly
- removes `coffee-lex.js.flow`

I don't like that I had to write a custom build script for this. It makes me feel like I'm doing something incorrectly to support both commonjs and ES modules. I removed rollup because it didn't seem to play well with TypeScript from a publishing perspective. Specifically, I couldn't find any way to automatically build a `d.ts` file for the project bundle generated by rollup that didn't have serious shortcomings (https://github.com/rollup/rollup-plugin-typescript/issues/54). I considered keeping the bundled `.js` and `.mjs` files and using multiple `.d.ts` files, but there didn't seem to be much benefit over simply leaving all of them split up. Other rollup-based projects can still efficiently bundle coffee-lex with the modules split out as separate files.
eventualbuddha referenced this issue in decaffeinate/coffee-lex Dec 13, 2016
This commit changes the distributable file format in the following ways:
- unbundles both the commonjs and ES module files from one file each to one for each original file for each format
- includes `.d.ts` files for each original source file
- adds `types` field to `package.json` per https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html
- removes rollup as the dist builder and uses a wrapper, `script/build`, that uses `tsc` directly
- removes `coffee-lex.js.flow`

I don't like that I had to write a custom build script for this. It makes me feel like I'm doing something incorrectly to support both commonjs and ES modules. I removed rollup because it didn't seem to play well with TypeScript from a publishing perspective. Specifically, I couldn't find any way to automatically build a `d.ts` file for the project bundle generated by rollup that didn't have serious shortcomings (https://github.com/rollup/rollup-plugin-typescript/issues/54). I considered keeping the bundled `.js` and `.mjs` files and using multiple `.d.ts` files, but there didn't seem to be much benefit over simply leaving all of them split up. Other rollup-based projects can still efficiently bundle coffee-lex with the modules split out as separate files.
@thgreasi
Copy link

👍 I currently have to use typescript on its own to generate es6 files and .d.ts files and then use rollup for bundling and generating a UMD dist.

@thgreasi
Copy link

rollup-plugin-typescript2 says that it supports it. I will give it a try but I would prefer to use the official rollup plugin for typescript.

@ncphillips
Copy link

I've had to switch to rollup-plugin-typescript2 as well. Honestly, I don't see how this plugin is useful in for creating public packages without this feature.

@janbiasi
Copy link

janbiasi commented Feb 8, 2018

Still no update on this? I have to sadly agree to @ncphillips ...

@markcellus
Copy link

Yup, I've moved to rollup-plugin-typescript2 as well. Any idea on a timeline of when this will be implemented?

@onbjerg
Copy link

onbjerg commented Sep 3, 2019

Guys, still nothing?

@couellet
Copy link

Had to switch to rollup-plugin-typescript2 too, and it's 10 times slower. Hope this is going to be fixed soon!

@bodograumann
Copy link

I use tsc --emitDeclarationOnly in addition to rollup. It‘s not that bad, but it‘s also not perfect.

@shellscape
Copy link
Collaborator

There are quite a few people commenting on support for this, but we don't have any open PRs to address this. We're totally open to adding this, but we need you fine folks to help us. We're getting ready to move this plugin to a new home at https://github.com/rollup/plugins, and we have to do some spring cleaning of the issues to make that happen. We're going to close this one if no one from userland steps up to make the request happen. After that point, we'd encourage anyone still facing the issue to pitch in on the new repo and get this improvement in for the plugin.

@shellscape shellscape transferred this issue from rollup/rollup-plugin-typescript Nov 29, 2019
@shellscape shellscape changed the title Declarations not included Honor declaration config Nov 29, 2019
@shellscape
Copy link
Collaborator

Hey folks. We're in progress on migrating the plugin, and have transferred this issue. We're going to lock it for a short time until the migration is complete, and then we'll unlock and continue the discussion. 🍺

@timonson
Copy link

timonson commented Feb 8, 2020

Is anybody working on this?

@NotWoods
Copy link
Member

NotWoods commented Feb 8, 2020

Yes, it's being worked on. Contributor support is also welcome!

@NotWoods
Copy link
Member

NotWoods commented Mar 6, 2020

Added in version 4.0.0 of the typescript plugin

@NotWoods NotWoods closed this as completed Mar 6, 2020
@danimoh
Copy link
Contributor

danimoh commented Mar 9, 2020

For others also potentially struggling with this: For types to be emitted, you currently have to declare a rootDir in tsconfig.json. This is related to #243. Even though the compilation does not fail when using declarationDir instead of outDir this does also apply when using declarationDir.

Also have a look at the PR that implemented this feature for instructions on how to generate declaration files: #217

@zeakd
Copy link

zeakd commented Mar 10, 2020

Thanks @danimoh it's very helpful. additionally..

  • output.dir is required for declaration: true option.
  • declarationDir folder should be inside output.dir.
  • do not use declaration and declarationDir in tsconfig.json. declarationDir can't override using @rollup/plugin-typescript

Here's my rollup config to make redux style outputs.

import typescript from '@rollup/plugin-typescript'

export default [
  // CommonJS
  {
    input: 'src/index.ts',
    output: {
      dir: './',
      entryFileNames: 'lib/my-pkg.js',
      format: 'cjs',
    },
    plugins: [
      typescript({
        declaration: true,
        declarationDir: 'types/',
        rootDir: 'src/'
      }),
    ]
  },

  // ES
  {
    input: 'src/index.ts',
    output: { file: 'es/my-pkg.js', format: 'es' },
    plugins: [
      typescript(),
    ]
  },
]

danimoh added a commit to nimiq/ledger-api that referenced this issue May 17, 2020
Note that currently a rootDir needs to be specified in tsconfig.json,
see rollup/plugins#61 (comment)
@imjeen
Copy link

imjeen commented Sep 7, 2020

Yes, it's being worked.

And get many .d.ts files if the source is not one file.

There was any way to generate only one declaration file?

@sekoyo
Copy link

sekoyo commented May 21, 2021

Since I always get stuck on this when trying to use this package instead of rollup-plugin-typescript2 (which works perfectly out the box but doesn't play as nicely with the babel plugin if I recall - might be wrong) here's how to get declarations working with this one.

  1. Even though it says you don't need to, you need to tell it the tsconfig path:
typescript({
  tsconfig: './tsconfig.json',
}),
babel({ babelHelpers: 'bundled', extensions }), // Note: DON'T need babel typescript preset (or this babel plugin unless you need to)
  1. This will start to emit declarations but in the wrong directory, for example dist/dist/<types here> (it duplicates the folder). To fix this keep "outDir": "./dist", in tsconfig.json but remove it from the output of rollup, e.g.:
{
  file: './index.js', // don't do './dist/index.js' like you normally would
  format: 'esm',
  globals,
}

@shellscape
Copy link
Collaborator

Since I always get stuck on this when trying to use this package instead of typescript2 (which works perfectly out the box)

@dominictobias I really wish you would leave the snark and slight out of replies. It doesn't serve any purpose, makes you look like a jerk, and is insulting to the folks who gave their free time to improve this plugin over time. Sure, it works different for people in different scenarios - as all things do - but that doesn't mean you need to disrespect who freely made something for you to use. Be a better person.

@betabandido
Copy link

@zeakd @danimoh Following your instructions I finally managed the plugin to output declarations 🎉 Thanks!!

I have a question, though. It seems dir and file cannot be both present at the same time in an output definition. Therefore, I don't seem to have any way to control the name of the file being generated (the name I add in the main field in package.json).

Is there any solution or workaround for this?

tommy-lettieri added a commit to tommy-lettieri/resume-template that referenced this issue Jul 8, 2021
Finally got type definitions to work following this commenting:
rollup/plugins#61 (comment)
danimoh added a commit to nimiq/ledger-api that referenced this issue Oct 27, 2024
Also update @typescript-eslint/eslint-plugin, @typescript-eslint/parser and eslint-config-airbnb-typescript
for compatibility with the updated typescript version, and fix newly reported type and lint issues.

Additionally, with the merge of rollup/plugins#818, the rootDir hack for making
typescript build in combination with emitting declaration files could now be removed. For the previous hack
see rollup/plugins#61 (comment) and
rollup/plugins#287.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests