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

tsconfig include not overridden #39

Closed
kalitine opened this issue Oct 23, 2017 · 6 comments
Closed

tsconfig include not overridden #39

kalitine opened this issue Oct 23, 2017 · 6 comments
Assignees
Labels
kind: bug Something isn't working properly solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue

Comments

@kalitine
Copy link

kalitine commented Oct 23, 2017

#It's either a bug or maybe a wanted functionality. Here are my tsconfig file and plugin options which work well:
tsconfig.dist.esm.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "dist/esm"
  },
  "include": ["src/**/*.ts"]
}

rollup.config.js:

typescript({
  tsconfig: 'tsconfig.dist.esm.json',
  useTsconfigDeclarationDir: true
})

I wanted to rid of tsconfig.dist.esm.json and thus modified rollup.config.js file:

typescript({
  tsconfig: 'tsconfig.dist.esm.json',
  tsconfigOverride: {
    compilerOptions: {
      declaration: true,
      declarationDir: 'dist/esm'
    },
    include: ['src/**/*.ts']
  },
  useTsconfigDeclarationDir: true
})

But it does not work. The plugin does not pay attention to txconfigOverride.compilerOptions.declarationDir option. Would be nice if it could.

@ezolenko ezolenko self-assigned this Oct 23, 2017
@ezolenko
Copy link
Owner

ezolenko commented Oct 23, 2017

Seems to work for me, I added declarationDir to tsconfigOverride.compilerOptions, and depending on useTsconfigDeclarationDir it puts them in default location (with the bundle) or in the place declarationDir points to.

You have 2 dots in tsconfig.dist.esm..json, is that intentional or a copy-paste error?

What's in the file itself? Plugin will fail if the file doesn't exist at all, so it needs to have at least {} in there. (but you should be able to point all builds at a single file and use overrides to tweak them).

Check if you have correct plugin version, tsconfigOverride was added in 0.7.0.

@ezolenko

This comment was marked as off-topic.

@kalitine
Copy link
Author

kalitine commented Oct 24, 2017

Thanks, I've edited the issue, as 2 dots were just copy-paste error.
Sorry, you are right it works with the rollup.config.js I've mentioned above.

But I've also mistaken with this example, as I wanted to rid of tsconfig.dist.esm.json, thus I do not want this file to exist, which means to have rollup.config.js like this:

typescript({
  tsconfigOverride: {
    compilerOptions: {
      declaration: true,
      declarationDir: 'dist/esm'
    },
    include: ['src/**/*.ts']
  },
  useTsconfigDeclarationDir: true
})

But you said that it must exist even just {}, so it's ok that it does not work without.

As I steel want to rid of tsconfig.dist.esm.json I tried another solution. This config extends tsconfig.json, so I tried this configuration:

typescript({
  tsconfig: 'tsconfig.json',
  tsconfigOverride: {
    compilerOptions: {
      declaration: true,
      declarationDir: 'dist/esm'
    },
    include: ['src/**/*.ts']
  },
  useTsconfigDeclarationDir: true
})

And strangely this did not work for me. I looked to the difference between tsconfig.dist.esm.json and tsconfig.json. And here is what I found. With the following tsconfig.json it does not work:

{
  "compilerOptions": {
    "target": "ES5",
    "module": "ES2015",
    "lib": [ "ES2015", "ES2016", "ES2017", "DOM" ],
    "moduleResolution": "node",
    "downlevelIteration": true,
    "types": ["node", "text-encoding"]
  },
  "include": [
    "src/**/*",
    "test/**/*"
  ],
  "exclude": ["**/proto/index.d.ts"]
}

But if I remove "test/**/*" line, it works. Which means that override for include option does not work.

@kalitine kalitine changed the title declarationDir not overrided include not overrided Oct 24, 2017
@ezolenko
Copy link
Owner

Ah, yes, that works as coded. Objects and arrays are merged, not replaced. This is a different behavior from tsconfig extends option (and I probably shouldn't have called it override :)). Arguably either way is useful in different cases.

You can achieve what you want by creating tsconfig.base.json file without test/**/* in includes (but with all the other common options) and using that for rollup directly. Then create tsconfig.json that extends your base and specifies full include list and use that outside of rollup. (see Configuration inheritance in tsconfig-json)

Doesn't reduce number of files, but removes duplication.

@kalitine
Copy link
Author

Ok, I see. Yes override confused me. No problem I will preserve my tsconfig.dist.esm.json which extends tsconfig.json and is not a big deal.

@agilgur5 agilgur5 changed the title include not overrided tsconfigs include not overridden May 21, 2022
@agilgur5 agilgur5 changed the title tsconfigs include not overridden tsconfig include not overridden May 21, 2022
@agilgur5 agilgur5 added kind: bug Something isn't working properly solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue labels May 21, 2022
@agilgur5
Copy link
Collaborator

agilgur5 commented May 21, 2022

See #86 for the root cause fix

(this issue came before it, but marking as duplicate as that is currently the central issue for this topic)

Repository owner locked as resolved and limited conversation to collaborators May 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: bug Something isn't working properly solution: duplicate This issue or pull request already exists solution: workaround available There is a workaround available for this issue
Projects
None yet
Development

No branches or pull requests

3 participants