Skip to content

Commit 2321126

Browse files
committed
feat: add outdated=dependencies command
1 parent 3737d34 commit 2321126

3 files changed

Lines changed: 53 additions & 154 deletions

File tree

lib/commands/package/outdated-dependencies.js

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ansi from "#core/ansi";
12
import Command from "#lib/command";
23

34
export default class extends Command {
@@ -6,96 +7,44 @@ export default class extends Command {
67
static cli () {
78
return {
89
"options": {
9-
"direct-dependencies": {
10-
"short": "1",
11-
"description": "check only the current package direct dependencies",
12-
"default": false,
13-
"schema": {
14-
"type": "boolean",
15-
},
16-
},
17-
"outdated": {
18-
"negatedShort": "O",
19-
"description": "exclude outdated dependencies",
20-
"default": true,
21-
"schema": {
22-
"type": "boolean",
23-
},
24-
},
25-
"install": {
26-
"short": "i",
27-
"description": "install found updatable dependencies",
28-
"default": false,
29-
"schema": {
30-
"type": "boolean",
31-
},
32-
},
33-
"reinstall": {
34-
"short": "I",
35-
"description": "reinstall all dependencies, even if no updates available",
36-
"default": false,
37-
"schema": {
38-
"type": "boolean",
39-
},
40-
},
41-
"commit": {
42-
"negatedShort": "C",
43-
"description": "do not commit and push changes",
44-
"default": true,
45-
"schema": {
46-
"type": "boolean",
47-
},
48-
},
4910
"sub-packages": {
5011
"negatedShort": "S",
5112
"description": "ignore sub-packages",
5213
"default": true,
5314
"schema": { "type": "boolean" },
5415
},
55-
"quiet": {
56-
"short": "q",
57-
"description": "do not show report",
58-
"default": false,
59-
"schema": {
60-
"type": "boolean",
61-
},
62-
},
63-
"confirm": {
64-
"short": "Y",
65-
"description": "ask before install dependencies",
66-
"default": false,
67-
"schema": {
68-
"type": "boolean",
69-
},
70-
},
7116
},
7217
};
7318
}
7419

7520
// public
7621
async run () {
7722
const pkg = this._findGitPackage();
78-
7923
if ( !pkg ) return result( [ 500, "Unable to find package" ] );
8024

81-
var hasErrors,
25+
var printNewLine,
26+
hasErrors,
8227
cache = {};
8328

8429
for ( const pack of [ pkg, ...( process.cli.options[ "sub-packages" ]
8530
? pkg.subPackages
8631
: [] ) ] ) {
87-
const res = await pack.updateDependencies( {
88-
"all": !process.cli.options[ "direct-dependencies" ],
89-
"outdated": process.cli.options.outdated,
90-
"notInstalled": process.cli.options[ "not-installed" ],
91-
"install": process.cli.options.install,
92-
"reinstall": process.cli.options.reinstall,
93-
"commit": process.cli.options.commit,
94-
"quiet": process.cli.options.quiet,
95-
"confirmInstall": process.cli.options.confirm,
32+
const res = await pack.getOutdatedDependencies( {
9633
cache,
9734
} );
9835

36+
if ( res.ok && !res.data.updates ) continue;
37+
38+
if ( printNewLine ) {
39+
console.log();
40+
}
41+
else {
42+
printNewLine = true;
43+
}
44+
45+
console.log( "Package:", ansi.hl( pkg.workspaceSlug ) );
46+
console.log( res.data.log );
47+
9948
if ( !res.ok ) {
10049
hasErrors = true;
10150
}

lib/commands/workspace.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ export default class extends Command {
3131
"title": "Run packages install script",
3232
"module": () => new URL( "workspace/install.js", import.meta.url ),
3333
},
34+
"outdated-dependencies": {
35+
"short": "O",
36+
"title": "Check packages outdated dependencies",
37+
"module": () => new URL( "workspace/outdated-dependencies.js", import.meta.url ),
38+
},
3439
"update-dependencies": {
3540
"short": "u",
3641
"title": "Update packages dependencies",
Lines changed: 32 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import ansi from "#core/ansi";
12
import ThreadsPoolQueue from "#core/threads/pool/queue";
23
import Command from "#lib/command";
34

@@ -7,68 +8,12 @@ export default class extends Command {
78
static cli () {
89
return {
910
"options": {
10-
"direct-dependencies": {
11-
"short": "1",
12-
"description": "check only the current package direct dependencies",
13-
"default": false,
14-
"schema": {
15-
"type": "boolean",
16-
},
17-
},
18-
"outdated": {
19-
"negatedShort": "O",
20-
"description": "exclude outdated dependencies",
21-
"default": true,
22-
"schema": {
23-
"type": "boolean",
24-
},
25-
},
26-
"install": {
27-
"short": "i",
28-
"description": "install found updatable dependencies",
29-
"default": false,
30-
"schema": {
31-
"type": "boolean",
32-
},
33-
},
34-
"reinstall": {
35-
"short": "I",
36-
"description": "reinstall all dependencies, even if no updates available",
37-
"default": false,
38-
"schema": {
39-
"type": "boolean",
40-
},
41-
},
42-
"commit": {
43-
"negatedShort": "C",
44-
"description": "do not commit and push changes",
45-
"default": true,
46-
"schema": {
47-
"type": "boolean",
48-
},
49-
},
5011
"sub-packages": {
5112
"negatedShort": "S",
5213
"description": "ignore sub-packages",
5314
"default": true,
5415
"schema": { "type": "boolean" },
5516
},
56-
"quiet": {
57-
"short": "q",
58-
"description": "do not show report",
59-
"default": false,
60-
"schema": {
61-
"type": "boolean",
62-
},
63-
},
64-
"confirm": {
65-
"short": "Y",
66-
"description": "ask before install dependencies",
67-
"default": false,
68-
"schema": {
69-
"type": "boolean",
70-
},
71-
},
7217
},
7318
"arguments": {
7419
"pattern": {
@@ -86,67 +31,67 @@ export default class extends Command {
8631
} );
8732
if ( !res.ok ) return res;
8833

89-
var hasErrors,
90-
cache = {};
91-
9234
const packages = res.data,
9335
threads = new ThreadsPoolQueue( {
94-
"maxRunningThreads": 5,
95-
} );
36+
"maxRunningThreads": 10,
37+
} ),
38+
cache = {};
9639

9740
for ( const pkg of packages ) {
41+
42+
// main package
9843
threads.pushThread( async () => {
9944
const res = await pkg.getOutdatedDependencies( {
100-
"all": !process.cli.options[ "direct-dependencies" ],
45+
cache,
10146
} );
10247

103-
return result( res, {
104-
pkg,
105-
"dependencies": res.data,
106-
} );
48+
res.data ??= {};
49+
res.data.package = pkg;
50+
51+
return res;
10752
} );
10853

54+
// sub-packages
10955
if ( process.cli.options[ "sub-packages" ] ) {
11056
for ( const subPkg of pkg.subPackages ) {
11157
threads.pushThread( async () => {
11258
const res = await subPkg.getOutdatedDependencies( {
113-
"all": !process.cli.options[ "direct-dependencies" ],
59+
cache,
11460
} );
11561

116-
return result( res, {
117-
"pkg": subPkg,
118-
"dependencies": res.data,
119-
} );
62+
res.data ??= {};
63+
res.data.package = pkg;
64+
65+
return res;
12066
} );
12167
}
12268
}
12369
}
12470

71+
var hasErrors, printNewLine;
72+
12573
while ( ( res = await threads.getResult() ) ) {
126-
if ( res.ok ) {
127-
const pkg = res.data.pkg;
128-
129-
res = await pkg.updateDependencies( {
130-
"all": !process.cli.options[ "direct-dependencies" ],
131-
"outdated": process.cli.options.outdated,
132-
"notInstalled": process.cli.options[ "not-installed" ],
133-
"install": process.cli.options.install,
134-
"reinstall": process.cli.options.reinstall,
135-
"commit": process.cli.options.commit,
136-
"quiet": process.cli.options.quiet,
137-
"confirmInstall": process.cli.options.confirm,
138-
"outdatedDependencies": res.data.dependencies,
139-
cache,
140-
} );
74+
if ( res.ok && !res.data.updates ) continue;
75+
76+
const pkg = res.data.package;
77+
78+
if ( printNewLine ) {
79+
console.log();
80+
}
81+
else {
82+
printNewLine = true;
14183
}
14284

85+
console.log( "Package:", ansi.hl( pkg.workspaceSlug ) );
86+
console.log( res.data.log );
87+
14388
if ( !res.ok ) {
14489
hasErrors = true;
14590
}
14691
}
14792

14893
if ( hasErrors ) {
149-
return result( [ 500, "Some dependencies wasn't updated" ] );
94+
return result( [ 500, "Some dependencies wasn't checked" ] );
15095
}
15196
}
15297
}

0 commit comments

Comments
 (0)