File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ const {
2
+ getInternals,
3
+ npmView
4
+ } = require ( './helpers/versioning' )
5
+ const path = require ( 'path' )
6
+ const fs = require ( 'fs' )
7
+
8
+ const latestsPath = path . join (
9
+ __dirname ,
10
+ '..' ,
11
+ 'packages' ,
12
+ 'datadog-instrumentations' ,
13
+ 'src' ,
14
+ 'helpers' ,
15
+ 'latests.json'
16
+ )
17
+ const latestsJson = require ( latestsPath )
18
+ const internalsNames = Array . from ( new Set ( getInternals ( ) . map ( n => n . name ) ) )
19
+ . filter ( x => typeof x === 'string' && x !== 'child_process' && ! x . startsWith ( 'node:' ) )
20
+
21
+ // TODO A lot of this can be optimized by using `npm outdated`.
22
+
23
+ async function fix ( ) {
24
+ const latests = { }
25
+ for ( const name of internalsNames ) {
26
+ const distTags = await npmView ( name + ' dist-tags' )
27
+ const latest = distTags . latest
28
+ latests [ name ] = latest
29
+ }
30
+ latestsJson . latests = latests
31
+ fs . writeFileSync ( latestsPath , JSON . stringify ( latestsJson , null , 2 ) )
32
+ }
33
+
34
+ async function check ( ) {
35
+ for ( const name of internalsNames ) {
36
+ const latest = latestsJson . latests [ name ]
37
+ if ( ! latest ) {
38
+ console . log ( `No latest version found for "${ name } "` )
39
+ process . exitCode = 1
40
+ }
41
+ const distTags = await npmView ( name + ' dist-tags' )
42
+ const npmLatest = distTags . latest
43
+ if ( npmLatest !== latest ) {
44
+ console . log ( `"latests.json: is not up to date for "${ name } ": expected "${ npmLatest } ", got "${ latest } "` )
45
+ process . exitCode = 1
46
+ }
47
+ }
48
+ }
49
+
50
+ if ( process . argv . includes ( 'fix' ) ) fix ( )
51
+ else check ( )
You can’t perform that action at this time.
0 commit comments