22
33import { existsSync } from "node:fs" ;
44import Path from "node:path" ;
5+ import { parseArgs } from "node:util" ;
6+
57import { promiseErrorToSettled } from "./utils.js" ;
68import {
79 readWorkspaceDirs ,
810 readWorkspaceSettings ,
911 resolveWorkspaceDeps ,
1012} from "./pnpmWorkspace.js" ;
1113import { compare } from "./git.js" ;
14+ import { debug } from "./debug.js" ;
1215
1316const 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
1838const 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+
2345if ( ! 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+
3761const workspaceDepsRelativePaths = [ cwd , ...workspaceDepsPaths ] . map (
3862 ( path ) => Path . relative ( cwd , path ) || "." ,
3963) ;
4064
65+ log ( { workspaceDepsRelativePaths } ) ;
66+
4167const result = await Promise . all ( [
4268 ...workspaceDepsRelativePaths . map ( async ( path ) => {
4369 return {
@@ -73,6 +99,10 @@ const result = await Promise.all([
7399] ) ;
74100
75101const 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