Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 7590fea

Browse files
committed
feat!: support estimating the set of inputs to tsc
BREAKING CHANGE: require to choose `exact` or `estimate` calculation This commit adds support for estimating the set of input files to `tsc`. Whereas the exact method of enumerating input files uses `tsc` as the source of truth, this method crudely enumerates files matching the package's tsconfig `include` globs. There are known (and documented) limitations of this approach, but it is between 1 and 3 orders of magnitude faster than `tsc`, depending on the nature of your monorepo.
1 parent 2650d39 commit 7590fea

20 files changed

Lines changed: 445 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ exclude = [
2121

2222
[dependencies]
2323
anyhow = "1.0.66"
24+
globwalk = "0.8.1"
2425
log = "0.4.17"
26+
pathdiff = "0.2.1"
2527
rayon = "1.6.0"
28+
serde = { version = "1.0.137", features = ["derive"] }
29+
serde_json = "1.0.81"
2630
thiserror = "1.0.37"
2731
typescript_tools = "5.0.0"
2832

examples/local.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ extern crate tsconfig_includes;
66

77
fn main() -> Result<()> {
88
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
9-
let included_files = tsconfig_includes::tsconfig_includes(&PathBuf::from(
10-
"/path-to-your-monorepo/packages/package-a/tsconfig.json",
11-
))?;
9+
let included_files = tsconfig_includes::tsconfig_includes(
10+
&PathBuf::from("/path-to-your-monorepo/packages/package-a/tsconfig.json"),
11+
tsconfig_includes::Calculation::Exact,
12+
)?;
1213
println!("{:#?}", included_files);
1314
Ok(())
1415
}

flake.lock

Lines changed: 70 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,59 @@
77
inputs.nixpkgs.follows = "nixpkgs";
88
inputs.flake-utils.follows = "flake-utils";
99
};
10+
fenix = {
11+
url = "github:nix-community/fenix";
12+
inputs.nixpkgs.follows = "nixpkgs";
13+
};
1014
pre-commit-hooks = {
1115
url = "github:cachix/pre-commit-hooks.nix";
1216
inputs.flake-utils.follows = "flake-utils";
1317
inputs.nixpkgs.follows = "nixpkgs";
1418
};
19+
typescript-tools = {
20+
url = "github:typescript-tools/rust-implementation";
21+
inputs.nixpkgs.follows = "nixpkgs";
22+
inputs.flake-utils.follows = "flake-utils";
23+
inputs.crane.follows = "crane";
24+
inputs.pre-commit-hooks.follows = "pre-commit-hooks";
25+
};
1526
};
1627

1728
outputs = {
1829
self,
1930
nixpkgs,
2031
crane,
32+
fenix,
2133
flake-utils,
2234
pre-commit-hooks,
35+
typescript-tools,
2336
...
2437
}:
2538
flake-utils.lib.eachDefaultSystem (system: let
2639
pkgs = import nixpkgs {
2740
inherit system;
2841
};
2942

30-
craneLib = crane.lib.${system};
43+
fenix-channel = fenix.packages.${system}.latest;
44+
fenix-toolchain = fenix-channel.withComponents [
45+
"rustc"
46+
"cargo"
47+
"clippy"
48+
"rust-analysis"
49+
"rust-src"
50+
"rustfmt"
51+
];
52+
53+
craneLib = crane.lib.${system}.overrideToolchain fenix-toolchain;
3154

3255
# Common derivation arguments used for all builds
3356
commonArgs = {
3457
src = craneLib.cleanCargoSource ./.;
58+
59+
buildInputs = [
60+
fenix-channel.rustc
61+
fenix-channel.clippy
62+
];
3563
};
3664

3765
# Build *just* the cargo dependencies, so we can reuse
@@ -86,9 +114,13 @@
86114
};
87115
devShells = {
88116
default = nixpkgs.legacyPackages.${system}.mkShell {
117+
buildInputs = commonArgs.buildInputs;
89118
nativeBuildInputs = [
90-
pkgs.cargo
119+
fenix-toolchain
120+
fenix.packages.${system}.rust-analyzer
91121
pkgs.nodejs
122+
pkgs.nodePackages.typescript
123+
typescript-tools.packages.${pkgs.system}.default
92124
];
93125

94126
inherit (self.checks.${system}.pre-commit-check) shellHook;

src/error.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
use std::path::PathBuf;
2+
13
#[derive(Debug, thiserror::Error)]
24
pub enum Error {
35
#[error(transparent)]
46
ReadLernaManifestError(#[from] anyhow::Error),
57

8+
#[error("Error parsing {filename:?}")]
9+
TypescriptConfigParseError {
10+
#[source]
11+
source: serde_json::Error,
12+
filename: PathBuf,
13+
},
14+
15+
#[error("Error enumerating files by tsconfig glob")]
16+
GlobWalkError {
17+
#[from]
18+
source: globwalk::WalkError,
19+
},
20+
21+
#[error("Error calculating relating path from monorepo root for {filename:?}")]
22+
RelativePathError { filename: PathBuf },
23+
624
#[error("Project is not in a lerna monorepo: {filename:?}")]
725
TypescriptProjectNotInMonorepo { filename: String },
826

0 commit comments

Comments
 (0)