@@ -5,9 +5,6 @@ const path = require("path");
5
5
6
6
const DEBUG = false ;
7
7
8
- const missingPackageWarnings = [ ] ;
9
- const manualChecks = [ ] ;
10
-
11
8
/**
12
9
* Returns an array with arrays of types and names of frameworks
13
10
* @example getFramewokrs()
@@ -23,16 +20,52 @@ function getFrameworks() {
23
20
return [ ...keyedFrameworks , ...nonKeyedFrameworks ] ;
24
21
}
25
22
23
+ const frameworks = getFrameworks ( ) ;
24
+
25
+ /**
26
+ * Looks for duplicate frameworks
27
+ * @param {{type: string, name: string}[] } frameworks
28
+ * @returns {string[] }
29
+ */
30
+ function findDuplicateFrameworks ( frameworks ) {
31
+ const names = frameworks . map ( ( framework ) => framework . name ) ; // Creates an array with framework names only
32
+ const duplicateNames = names . filter (
33
+ ( name , index ) => names . indexOf ( name ) !== index
34
+ ) ; // Filters out repetitive framework names
35
+
36
+ return duplicateNames ;
37
+ }
38
+
39
+ const duplicateFrameworks = findDuplicateFrameworks ( frameworks ) ;
40
+ const frameworksCache = new Map ( ) ;
41
+
26
42
/**
27
43
* @param {string } packageName
28
44
*/
29
45
function maybeObsolete ( packageName ) {
30
46
try {
31
47
const npmCmd = `npm view ${ packageName } time` ;
32
- const output = execSync ( npmCmd , {
33
- stdio : [ "ignore" , "pipe" , "ignore" ] ,
34
- } ) . toString ( ) ;
35
- const timeData = JSON5 . parse ( output ) ;
48
+ let timeData ;
49
+
50
+ if ( duplicateFrameworks . includes ( packageName ) ) {
51
+ if ( frameworksCache . has ( packageName ) ) {
52
+ const output = frameworksCache . get ( packageName ) ;
53
+ timeData = JSON5 . parse ( output ) ;
54
+ return ;
55
+ }
56
+
57
+ const output = execSync ( npmCmd , {
58
+ stdio : [ "ignore" , "pipe" , "ignore" ] ,
59
+ } ) . toString ( ) ;
60
+ timeData = JSON5 . parse ( output ) ;
61
+
62
+ frameworksCache . set ( packageName , JSON5 . stringify ( timeData ) ) ;
63
+ } else {
64
+ const output = execSync ( npmCmd , {
65
+ stdio : [ "ignore" , "pipe" , "ignore" ] ,
66
+ } ) . toString ( ) ;
67
+ timeData = JSON5 . parse ( output ) ;
68
+ }
36
69
37
70
const now = new Date ( ) ;
38
71
const obsoleteDate = new Date (
@@ -45,18 +78,23 @@ function maybeObsolete(packageName) {
45
78
const isObsolete = modifiedDate < obsoleteDate ;
46
79
const formattedDate = modifiedDate . toISOString ( ) . substring ( 0 , 10 ) ;
47
80
48
- return [ isObsolete , packageName , formattedDate ] ;
81
+ return { isObsolete, packageName, lastUpdate : formattedDate } ;
49
82
} catch ( error ) {
50
83
console . error (
51
84
`Failed to execute npm view for ${ packageName } . Error Code ${ error . status } and message: ${ error . message } `
52
85
) ;
53
- return [ false , packageName , null ] ;
86
+ return { isObsolete : false , packageName, lastUpdate : null } ;
54
87
}
55
88
}
56
89
57
- function checkFrameworks ( ) {
58
- const frameworks = getFrameworks ( ) ;
90
+ const missingPackageWarnings = [ ] ;
91
+ const manualChecks = [ ] ;
59
92
93
+ /**
94
+ * Checks frameworks in frameworks/keyed and frameworks/non-keyed for obsolescence,
95
+ * the presence of package.json and the presence of the frameworkVersionFromPackage property
96
+ */
97
+ function checkFrameworks ( ) {
60
98
for ( const { type, name } of frameworks ) {
61
99
const frameworkPath = path . join ( "frameworks" , type , name ) ;
62
100
const packageJSONPath = path . join ( frameworkPath , "package.json" ) ;
@@ -88,20 +126,25 @@ function checkFrameworks() {
88
126
console . log ( `Results for ${ type } /${ name } ${ isPackageObsolete } ` ) ;
89
127
}
90
128
91
- const anyPackageObsolete = isPackageObsolete . some ( ( r ) => r [ 0 ] ) ;
129
+ const anyPackageObsolete = isPackageObsolete . some (
130
+ ( packageFramework ) => packageFramework . isObsolete
131
+ ) ;
132
+
92
133
if ( anyPackageObsolete ) {
93
134
const formattedPackages = isPackageObsolete
94
- . map ( ( result ) => result . slice ( 1 ) . join ( ":" ) )
135
+ . map ( ( result ) => ` ${ result . packageName } : ${ result . lastUpdate } ` )
95
136
. join ( ", " ) ;
96
137
97
138
console . log (
98
- `Last npm update for ${ type } /${ name } ${ mainPackages } is older than a year: ${ formattedPackages } `
139
+ `Last npm update for ${ type } /${ name } - ${ mainPackages } is older than a year: ${ formattedPackages } `
140
+ ) ;
141
+ continue ;
142
+ }
143
+
144
+ if ( DEBUG ) {
145
+ console . log (
146
+ `Last npm update for ${ type } /${ name } ${ mainPackages } is newer than a year`
99
147
) ;
100
- } else {
101
- if ( DEBUG )
102
- console . log (
103
- `Last npm update for ${ type } /${ name } ${ mainPackages } is newer than a year`
104
- ) ;
105
148
}
106
149
}
107
150
0 commit comments