typescriptincremental-buildproject-referencerush

Do `rush build` and `tsc -b` play nice together?


I'm exploring Rush/PNPM and Typescript with project references and incremental builds but I'm a little confused about which of the two will be the best at managing incremental builds.

If I use the built-in command to rush build an incremental build, I think Rush rightly recognizes the dependencies from among all the known projects' package.json declarations and runs the build script of each of them in dependency order. If each typescript project's build script is ./node_modules/.bin/tsc -b . then each dependency up the tree will be built in dependency order.

Therein, tsc will also be evaluating the package.json dependencies against its references paths list. Ideally it will(?) recognize that earlier independent builds of its dependencies make them current and don't need rebuilding, and then only build the code for the immediate project as part of its rush build invoked build. If this is even reliable and stable, it seems like an unnecessary number of dependency tree evaluations at best, right?

I experimented with overriding rush's build bulk command to ignoreMissingScript in command-line.json and only define "build": "./node_modules/.bin/tsc -b ." on the top-most application's package.json. (The idea is to use an alternative build-me or whatever in the sub-projects in case I want to really just rebuild one of them and only its dependencies for some reason.) Because of the nature of bulk commands, Rush emits messages about skipped builds and missing scripts which could be misleading to the developer. Also, I'm not convinced that all the projects are being compiled - I'm not seeing the resulting js files, for example - perhaps that's an unrelated problem.

I don't see any easy Rush configuration for deferring to typescript - we aren't allowed to override build command-line to be a global-style shell command. I feel like I really only want Rush for package management and not for script-running (since it's too constrained). But also, I can't easily discourage rush build in favor of some other way of running the main project's typescript incremental build. I'm surprised not to be finding any relevant search results, seeing as how these are both cutting-edge Microsoft projects. Am I missing something fundamental?


Solution

  • From https://github.com/microsoft/rushstack/issues/2368

    Right now the two don't directly interoperate.

    If you run a Rush incremental build command (like the OOB rush build command), Rush will rebuild projects that have files that aren't .gitignored whose hashes have changed since the last time the command was run.

    Heft's incremental TypeScript build only rebuilds individual TS files that haven't changed since the last time heft build was run. If you don't run heft clean --clear-cache before running a project's heft build command, then the build will be incremental if a valid incremental state exists in project's Heft build cache folder (/.heft/build-cache). This will happen regardless of whether you run an incremental Rush build command or not.

    Does that make sense?