@@ -91,45 +91,40 @@ async function updateHistoricalData(
91
91
}
92
92
93
93
async function processPackage ( packageName : string ) : Promise < void > {
94
- try {
95
- // Fetch current stats
96
- const stats = await fetchPackageStats ( packageName ) ;
97
-
98
- // Check if package has any download statistics
99
- if ( ! stats . downloads || Object . keys ( stats . downloads ) . length === 0 ) {
100
- throw new Error (
101
- `Package ${ packageName } has no download statistics - it may not exist or have no downloads` ,
102
- ) ;
103
- }
94
+ // Fetch current stats
95
+ const stats = await fetchPackageStats ( packageName ) ;
96
+
97
+ // Check if package has any download statistics
98
+ if ( ! stats . downloads || Object . keys ( stats . downloads ) . length === 0 ) {
99
+ throw new Error (
100
+ `Package ${ packageName } has no download statistics - it may not exist or have no downloads` ,
101
+ ) ;
102
+ }
104
103
105
- // Use all versions without aggregation
106
- const allVersionDownloads = stats . downloads ;
104
+ // Use all versions without aggregation
105
+ const allVersionDownloads = stats . downloads ;
107
106
108
- // Determine file path
109
- const dataDir = join ( process . cwd ( ) , 'data' , 'npm-versions' ) ;
110
- const filePath = join ( dataDir , `${ packageName } .json` ) ;
107
+ // Determine file path
108
+ const dataDir = join ( process . cwd ( ) , 'data' , 'npm-versions' ) ;
109
+ const filePath = join ( dataDir , `${ packageName } .json` ) ;
111
110
112
- // Ensure directory exists
113
- await mkdir ( dirname ( filePath ) , { recursive : true } ) ;
111
+ // Ensure directory exists
112
+ await mkdir ( dirname ( filePath ) , { recursive : true } ) ;
114
113
115
- // Read existing data
116
- const existingData = await readExistingData ( filePath ) ;
114
+ // Read existing data
115
+ const existingData = await readExistingData ( filePath ) ;
117
116
118
- // Update historical data
119
- const updatedData = await updateHistoricalData ( packageName , allVersionDownloads , existingData ) ;
117
+ // Update historical data
118
+ const updatedData = await updateHistoricalData ( packageName , allVersionDownloads , existingData ) ;
120
119
121
- // Write back to file
122
- await writeFile ( filePath , JSON . stringify ( updatedData , null , 2 ) ) ;
120
+ // Write back to file
121
+ await writeFile ( filePath , JSON . stringify ( updatedData , null , 2 ) ) ;
123
122
124
- console . log ( `✅ Updated stats for ${ packageName } ` ) ;
125
- console . log ( ` Versions: ${ Object . keys ( allVersionDownloads ) . join ( ', ' ) } ` ) ;
126
- console . log (
127
- ` Total downloads: ${ Object . values ( allVersionDownloads ) . reduce ( ( a , b ) => a + b , 0 ) } ` ,
128
- ) ;
129
- } catch ( error ) {
130
- console . error ( `❌ Failed to process ${ packageName } :` , error ) ;
131
- throw error ;
132
- }
123
+ console . log ( `✅ Updated stats for ${ packageName } ` ) ;
124
+ console . log ( ` Versions: ${ Object . keys ( allVersionDownloads ) . join ( ', ' ) } ` ) ;
125
+ console . log (
126
+ ` Total downloads: ${ Object . values ( allVersionDownloads ) . reduce ( ( a , b ) => a + b , 0 ) } ` ,
127
+ ) ;
133
128
}
134
129
135
130
async function main ( ) {
0 commit comments