mirror of
https://github.com/Swatinem/rust-cache
synced 2025-06-19 06:43:41 +00:00
rewrite it all
This commit is contained in:
parent
5df06440c6
commit
6ed4c28a7c
8 changed files with 527 additions and 466 deletions
42
src/workspace.ts
Normal file
42
src/workspace.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import path from "path";
|
||||
|
||||
import { getCmdOutput } from "./utils";
|
||||
|
||||
export class Workspace {
|
||||
constructor(public root: string, public target: string) {}
|
||||
|
||||
public async getPackages(): Promise<Packages> {
|
||||
let packages: Packages = [];
|
||||
try {
|
||||
const meta: Meta = JSON.parse(
|
||||
await getCmdOutput("cargo", ["metadata", "--all-features", "--format-version", "1"]),
|
||||
);
|
||||
for (const pkg of meta.packages) {
|
||||
if (!pkg.manifest_path.startsWith(this.root)) {
|
||||
continue;
|
||||
}
|
||||
const targets = pkg.targets.filter((t) => t.kind[0] === "lib").map((t) => t.name);
|
||||
packages.push({ name: pkg.name, version: pkg.version, targets, path: path.dirname(pkg.manifest_path) });
|
||||
}
|
||||
} catch {}
|
||||
return packages;
|
||||
}
|
||||
}
|
||||
|
||||
export interface PackageDefinition {
|
||||
name: string;
|
||||
version: string;
|
||||
path: string;
|
||||
targets: Array<string>;
|
||||
}
|
||||
|
||||
export type Packages = Array<PackageDefinition>;
|
||||
|
||||
interface Meta {
|
||||
packages: Array<{
|
||||
name: string;
|
||||
version: string;
|
||||
manifest_path: string;
|
||||
targets: Array<{ kind: Array<string>; name: string }>;
|
||||
}>;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue