File tree 2 files changed +45
-35
lines changed
2 files changed +45
-35
lines changed Original file line number Diff line number Diff line change 95
95
uses : actions/checkout@v4
96
96
97
97
- name : Check for pinned dependencies
98
- run : |
99
- node -e '
100
- const fs = require("fs");
101
- const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
102
- const errors = [];
103
-
104
- function isPinned(version) {
105
- if (version.startsWith("workspace:")) {
106
- return true;
107
- }
108
- if (version.startsWith("npm:")) {
109
- return true;
110
- }
111
- return /^\d+\.\d+\.\d+$|^[a-z]+:[a-z]+@\d+$/.test(version);
112
- }
113
-
114
- for (const [dep, version] of Object.entries(pkg.dependencies || {})) {
115
- if (!isPinned(version)) {
116
- errors.push(`Dependency "${dep}" is not pinned: "${version}"`);
117
- }
118
- }
119
-
120
- for (const [dep, version] of Object.entries(pkg.devDependencies || {})) {
121
- if (!isPinned(version)) {
122
- errors.push(`Dev dependency "${dep}" is not pinned: "${version}"`);
123
- }
124
- }
125
-
126
- if (errors.length > 0) {
127
- console.error(`\n${errors.join("\n")}\n`);
128
- process.exit(1);
129
- } else {
130
- console.log("All dependencies are pinned.");
131
- }
132
- '
98
+ run : npx tsx ./scripts/check-dependency-versions.ts
Original file line number Diff line number Diff line change
1
+ import fs from 'node:fs/promises' ;
2
+
3
+ ( async ( ) => {
4
+ const pkg : {
5
+ dependencies : Record < string , string > ;
6
+ devDependencies : Record < string , string > ;
7
+ } = JSON . parse ( await fs . readFile ( 'package.json' , 'utf8' ) ) ;
8
+ const errors = [ ] ;
9
+
10
+ function isPinned ( version : string ) {
11
+ if ( version . startsWith ( 'workspace:' ) ) {
12
+ return true ;
13
+ }
14
+ if ( version . startsWith ( 'npm:' ) ) {
15
+ return true ;
16
+ }
17
+ if ( / ^ \d + \. \d + \. \d + ( - \S + ) ? $ / . test ( version ) ) {
18
+ return true ;
19
+ }
20
+ if ( / ^ [ a - z ] + : [ a - z ] + @ \d + $ / . test ( version ) ) {
21
+ return true ;
22
+ }
23
+ return false ;
24
+ }
25
+
26
+ for ( const [ dep , version ] of Object . entries ( pkg . dependencies || { } ) ) {
27
+ if ( ! isPinned ( version ) ) {
28
+ errors . push ( `Dependency "${ dep } " is not pinned: "${ version } "` ) ;
29
+ }
30
+ }
31
+
32
+ for ( const [ dep , version ] of Object . entries ( pkg . devDependencies || { } ) ) {
33
+ if ( ! isPinned ( version ) ) {
34
+ errors . push ( `Dev dependency "${ dep } " is not pinned: "${ version } "` ) ;
35
+ }
36
+ }
37
+
38
+ if ( errors . length > 0 ) {
39
+ console . error ( `\n${ errors . join ( '\n' ) } \n` ) ;
40
+ process . exit ( 1 ) ;
41
+ } else {
42
+ console . log ( 'All dependencies are pinned.' ) ;
43
+ }
44
+ } ) ( ) ;
You can’t perform that action at this time.
0 commit comments