Skip to content

Commit 6e801fb

Browse files
committed
Parse args and add verbose mode
1 parent e65a3b1 commit 6e801fb

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/debug.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const debug =
2+
(verbose: boolean) =>
3+
(...args: unknown[]) => {
4+
if (verbose) {
5+
console.log(...args);
6+
}
7+
};

src/index.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,46 @@
22

33
import { existsSync } from "node:fs";
44
import Path from "node:path";
5+
import { parseArgs } from "node:util";
6+
57
import { promiseErrorToSettled } from "./utils.js";
68
import {
79
readWorkspaceDirs,
810
readWorkspaceSettings,
911
resolveWorkspaceDeps,
1012
} from "./pnpmWorkspace.js";
1113
import { compare } from "./git.js";
14+
import { debug } from "./debug.js";
1215

1316
const cwd = process.cwd();
1417

15-
const [_node, _bin, gitFromPointer = "HEAD^", gitToPointer = "HEAD"] =
16-
process.argv;
18+
const [_node, _bin, ...args] = process.argv;
19+
20+
const configuration = parseArgs({
21+
args,
22+
allowPositionals: true,
23+
options: {
24+
verbose: {
25+
type: "boolean",
26+
default: false,
27+
},
28+
},
29+
});
30+
31+
const log = debug(configuration.values.verbose || false);
32+
33+
const [gitFromPointer = "HEAD^", gitToPointer = "HEAD"] =
34+
configuration.positionals;
35+
36+
log({ gitFromPointer, gitToPointer });
1737

1838
const rootDir = cwd
1939
.split(Path.sep)
2040
.map((_, idx) => Path.join(cwd, "../".repeat(idx)))
2141
.find((path) => existsSync(Path.join(path, "pnpm-workspace.yaml")));
2242

43+
log({ rootDir });
44+
2345
if (!rootDir) {
2446
throw new Error(`Couldn't determine rootDir!`);
2547
}
@@ -34,10 +56,14 @@ const workspaceDepsPaths = workspaceDeps
3456
.map((name) => workspaceSettings.workspaces[name]?.packagePath)
3557
.filter((path): path is string => typeof path === "string");
3658

59+
log({ workspaceDepsPaths });
60+
3761
const workspaceDepsRelativePaths = [cwd, ...workspaceDepsPaths].map(
3862
(path) => Path.relative(cwd, path) || ".",
3963
);
4064

65+
log({ workspaceDepsRelativePaths });
66+
4167
const result = await Promise.all([
4268
...workspaceDepsRelativePaths.map(async (path) => {
4369
return {
@@ -73,6 +99,10 @@ const result = await Promise.all([
7399
]);
74100

75101
const dirtyTrees = result
102+
.map((r) => {
103+
log(r);
104+
return r;
105+
})
76106
.filter((r) => r.result.status === "rejected")
77107
.map((d) => "/" + Path.relative(rootDir, Path.resolve(cwd, d.path)))
78108
.sort();

0 commit comments

Comments
 (0)