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

Support running transforms on all referenced projects with the --build option #28

Closed
purplemana opened this issue Nov 2, 2018 · 7 comments

Comments

@purplemana
Copy link

I have a monorepo where I have configured each package to be built by ttsc -b. I need tsconfig alias paths to be transformed to relative paths using https://www.npmjs.com/package/@zerollup/ts-transform-paths module. Currently building a dependent project with ttsc doesn't run the transforms on the dependency packages. The only way is to manually build all packages in the order of dependencies. Considering tsc already builds them in the order, adding this support will be a huge step in solving the dreaded mono-repo holy grail problems.

Please let me know if there are any known workarounds.

@cevek
Copy link
Owner

cevek commented Nov 2, 2018

I've just tested project references, and it works.
testTtsc.zip (npm i && npm start)

Can you provide some example project where it doesn't work?

@cevek
Copy link
Owner

cevek commented Nov 2, 2018

Maybe you put all transformers into main project which gather other projects via references?
Transformers should be in every project's tsconfig.json

@purplemana
Copy link
Author

purplemana commented Nov 3, 2018

Please access it from the branch ttypescript in the git repo https://github.com/purplemana/alchemist. Few points:

  1. This is a lerna, yarn & TS mono-repo.
  2. The important package dependencies are in this order - drivers < models < services.
  3. Every package has a top level src folder. The baseUrl points to .. Paths is set to resolve @src/* to src/*, so inside the package code, you can reference any local file from the top, e.g. @src/types instead of relative ../../types.
  4. All packages build to their own build folder.
  5. Every package has its own build script. This is different from your example zip where there's only one at the top. The idea is that you can build any package instead of building the whole mono-repo, and it will only build that package and its dependencies.

Repro steps:

  1. Checkout branch ttypescript & yarn install.
  2. cd packacges/drivers and build with yarn build.
  3. Notice that src/fixtures/db/index.ts contains import { DB } from "@src/db"; which is remapped correctly to const db_1 = require("../../db"); in the output file located at build/src/fixtures/db/index.js.
  4. Now clean the build assets using yarn clean.
  5. cd packages/models and build with yarn build. This will trigger re-building of drivers.
  6. Check the file packages/drivers/build/src/fixtures/db/index.js. This time it is not remapped by the transform and still contains const db_1 = require("@src/db");.

So when models is being built, the transform doesn't run on the output of drivers.

@cevek
Copy link
Owner

cevek commented Nov 3, 2018

Your project doesn't build correctly: after yarn install it prints

yarn install v0.16.1
info No lockfile found.
success Nothing to install.
✨  Done in 0.08s.

and after yarn build a lot of ts errors:

../resources/src/errors/auth/index.test.ts:2:24 - error TS2307: Cannot find module 'chai'.

2 import { expect } from "chai";
                         ~~~~~~

../resources/src/errors/auth/index.test.ts:6:1 - error TS2582: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha`.

6 describe("errors/auth tests", () => {

@purplemana
Copy link
Author

purplemana commented Nov 3, 2018

Your yarn version seems to not support workspaces. Could you try with the latest version 1.12.1 please? Also as a precaution, check if the older yarn created an empty lockfile and delete it.

@cevek
Copy link
Owner

cevek commented Nov 3, 2018

I found your problem: plugins section must be in the compilerOptions, but you set it in the root of tsconfig.json

@purplemana
Copy link
Author

Thanks for the super quick help @cevek! It's working as expected. Wow, this has been the end of a long list of trial and errors to get this mono-repo setup working without heart burns.

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

2 participants