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 98
98
uses : actions/checkout@v4
99
99
100
100
- name : Check for pinned dependencies
101
- run : |
102
- node -e '
103
- const fs = require("fs");
104
- const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
105
- const errors = [];
106
-
107
- function isPinned(version) {
108
- if (version.startsWith("workspace:")) {
109
- return true;
110
- }
111
- if (version.startsWith("npm:")) {
112
- return true;
113
- }
114
- return /^\d+\.\d+\.\d+$|^[a-z]+:[a-z]+@\d+$/.test(version);
115
- }
116
-
117
- for (const [dep, version] of Object.entries(pkg.dependencies || {})) {
118
- if (!isPinned(version)) {
119
- errors.push(`Dependency "${dep}" is not pinned: "${version}"`);
120
- }
121
- }
122
-
123
- for (const [dep, version] of Object.entries(pkg.devDependencies || {})) {
124
- if (!isPinned(version)) {
125
- errors.push(`Dev dependency "${dep}" is not pinned: "${version}"`);
126
- }
127
- }
128
-
129
- if (errors.length > 0) {
130
- console.error(`\n${errors.join("\n")}\n`);
131
- process.exit(1);
132
- } else {
133
- console.log("All dependencies are pinned.");
134
- }
135
- '
101
+ 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