jaredpalmer / tsdx

Zero-config CLI for TypeScript package development
https://tsdx.io
MIT License
11.28k stars 507 forks source link

Support for "composite" TS projects / monorepos? #828

Open transitive-bullshit opened 4 years ago

transitive-bullshit commented 4 years ago

Current Behavior

composite projects don't appear to be recognized properly. Here's an example top-level composite config from notion-kit:

{
  "compilerOptions": {
    "composite": true
  },
  "files": [],
  "include": [],
  "references": [
    { "path": "./packages/notion-types" },
    { "path": "./packages/notion-utils" },
    { "path": "./packages/notion-client" }
  ]
}

If you run tsdx build on either the root directory containing the composite tsconfig.json, it creates empty output for the composite project.

✓ Building modules 0 ms
✓ Creating entry file 5 ms

If you try to run tsdx build on one of the concrete sub-projects, tsdx fails with an opaque error message:

✓ Creating entry file 735 ms
(typescript) Error: failed to transpile '/Users/tfischer/dev/modules/notion-kit/packages/notion-types/src/index.ts'
Error: failed to transpile '/Users/tfischer/dev/modules/notion-kit/packages/notion-types/src/index.ts'
    at error (/Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup/dist/shared/node-entry.js:5400:30)
    at throwPluginError (/Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup/dist/shared/node-entry.js:11878:12)
    at Object.error (/Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup/dist/shared/node-entry.js:12912:24)
    at Object.error (/Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup/dist/shared/node-entry.js:12081:38)
    at /Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:29036:30
    at TsCache.getCompiled (/Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:24870:33)
    at Object.transform (/Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:29022:36)
    at /Users/tfischer/.nvm/versions/node/v14.5.0/lib/node_modules/tsdx/node_modules/rollup/dist/shared/node-entry.js:13117:25

Note that this fairly simple set of composite packages works when compiled directly with tsc.

Versions

node: v14.5.0

"tsdx": "^0.13.3", "tslib": "^2.0.1", "typescript": "^4.0.2",

Desired Behavior

I'd love for tsdx to work in this case just like if I ran tsc on this config. E.g., it would build the sub-projects to their respective output folders, taking into account inter-package dependencies.

Who does this impact? Who is this for?

Monorepo package library authors for medium to large-sized projects. People using lerna and composite TS projects.

Describe alternatives you've considered

Currently, I'm just outputting commonjs packages. I really need to output both esm and commonjs modules for these packages, so I'm considering adding a two-phase build for production, but it's awkward and one of the core reasons tsdx was built in the first place.

Also, it's entirely possible that I'm missing something obvious or messing something up on my end.

Thanks!

agilgur5 commented 4 years ago

TSDX uses rollup-plugin-typescript2 under-the-hood. This sounds like and the error looks to be upstream there

transitive-bullshit commented 4 years ago

Thanks, Anton; seems related: https://github.com/ezolenko/rollup-plugin-typescript2/issues/112