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

Add support for project references #139

Closed
thdk opened this issue Feb 19, 2019 · 13 comments
Closed

Add support for project references #139

thdk opened this issue Feb 19, 2019 · 13 comments
Labels
kind: feature New feature or request

Comments

@thdk
Copy link

thdk commented Feb 19, 2019

What happens and why it is wrong

Since typescript 3.0, typescript has added support for project references.
tsc -b now build all projects listed in references section of the main tsconfig before the main project is built. See typescript documentation for project references.

When using rollup-plugin-typescript2, the references projects are not being build at all. It only builds the current project.

Environment

Versions

  • typescript: 3.2.2
  • rollup: 1.1.2
  • rollup-plugin-typescript2: 0.19.2

rollup.config.js

Not relevant

tsconfig.json

Main project:

{
  "compilerOptions": {
    "target": "es6",
    "module": "es2015", 
    "lib": [
      "es2015",
      "dom"
    ],
},
  "references": [
    {
      "path": "./common"
    }
  ]
}

Common project

{
  "compilerOptions": {
    /* Basic Options */
    "target": "es5",
    "module": "es2015",
    "declaration": true,
    "declarationMap": false,
    "outDir": "dist",
    "rootDir": ".",
    "composite": true,
    "strict": true, 
     "moduleResolution": "node", 
    "esModuleInterop": true
  },
  "references": []  // * Any project that is referenced must itself have a `references` array (which may be empty).
}

package.json

Not relevant

plugin output with verbosity 3

Not relevant

@ezolenko
Copy link
Owner

Also related to #112

@ezolenko ezolenko added the kind: feature New feature or request label Feb 19, 2019
@rosskevin
Copy link

I just made a big effort to get to rollup/bundle based output on our internal projects (instead of exploded output) and ran into this. Is there any guidance on where the gap is to get project references supported? I'd like to help but unsure if it will take me a lot of time to ramp up on this plugin or rollup internals.

@ezolenko
Copy link
Owner

@rosskevin I haven't looked at what would be involved, with any luck changes should be fairly limited (unless complicated by decisions like if projects should be all rolled into one bundle or split up, etc).

If you can make a small example repo that is using project references that will help a lot.

@thdk
Copy link
Author

thdk commented Feb 23, 2019

I had made a very small repo to try out project references with typescript and now I've added a new branch with rollup configured to bundle the typescript files using rollup-plugin-typescript2.

https://github.com/thdk/TS3-projects-references-example/tree/es-rollup-typescript

Would that be of any help?

@rosskevin
Copy link

rosskevin commented Feb 25, 2019

@thdk you aren't using composite according to the reference docs, not sure how that impacts things.

@ezolenko Here is a repo setup based on Ryan Cavanaugh's original sample with project references according to the reference docs:

https://github.com/rosskevin/learn-a/tree/build-rollup

It is also setup in a common lerna monorepo structure using yarn workspaces. Currently bundle seems to and only warns on rpt2: config error TS18002 The 'files' list in config file '/Users/kross/projects/learn-a/tsconfig.json' is empty.

I'll try this now in my more complex internal repo and see if there are more complications.

@rosskevin
Copy link

rosskevin commented Feb 25, 2019

So it appears that with the same setup from the learn-a sample above run in a more complex internal project, that rpt2 stops using the inherited tsconfig settings.

For example, rpt2 yields:

semantic error TS1192 Module '"/Users/kross/projects/js/node_modules/@types/lodash/merge"' has no default export.

which is solved with and part of my base tsconfig: esModuleInterop/allowSyntheticDefaultImports.

Is tsconfig extension (I have two levels of extension) unsupported?

EDIT: I switched to a single level of extension and get the same error

@thdk
Copy link
Author

thdk commented Feb 25, 2019

@rosskevin composite need to be set only for the referenced projects

"Referenced projects must have the new composite setting enabled."

https://www.typescriptlang.org/docs/handbook/project-references.html

Note that my repo only contains a very simple example using only typescript files with no other dependencies in the referenced projects. I'll try to add some more complexity to allow to test more features of rollup-plugin-typescript2 with project references.

@ezolenko
Copy link
Owner

@thdk I made both examples in TS3-projects-references-example work, for project-b you'll need to build common-with-dist before running rollup though.

@ezolenko
Copy link
Owner

@rosskevin tsconfig extension should work, but there might be bugs propagating the options. Try increasing plugin verbosity to 4 and check if the option shows up in parsed tsconfig (look for rpt2: parsed tsconfig: { line).

@thdk
Copy link
Author

thdk commented Mar 2, 2019

@ezolenko I know it works when I build project common-with-dist before running rollup, but coudn't the common project be detected and be build when required?

@ezolenko
Copy link
Owner

ezolenko commented Mar 4, 2019

@thdk Maybe it could, but it feels like an overreach to launch independent tsc compilations from rollup. Workaround for now is to add referenced project build step as a dependency or a pre-build in whatever build system starts rollup itself. Or to use direct imports like in project-a.

@ezolenko
Copy link
Owner

ezolenko commented Mar 11, 2019

Partial support is in 0.20.0 now.

@dtassone
Copy link

dtassone commented Jun 17, 2020

Partial support is in 0.20.0 now.

What does it mean partial? I'm trying to use this feature in a monorepo and I don't get my referenced package rebuilt when I add the option in the plugin conf or in my tsconfig...

    typescript({ build: true }),
...
  "compilerOptions": {
    "declaration": true,
    "declarationDir": "./dist",
    "module": "es6",
    "noImplicitAny": true,
    "strict": true,
    "outDir": "./dist",
    "target": "es6",
    "sourceMap": true,
    "build": true
  },

Composite flag is on in my referenced package and running tsc --build works as expected

Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: feature New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants