@getbastionai/gatepost 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/setup.js +20 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getbastionai/gatepost",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Wraps npm, npx, yarn, pnpm, and pnpx to block malicious packages in real-time",
5
5
  "scripts": {
6
6
  "postinstall": "node ./src/index.js setup"
package/src/setup.js CHANGED
@@ -35,14 +35,18 @@ function setup() {
35
35
 
36
36
  let updated = 0
37
37
  for (const config of configs) {
38
- const contents = fs.readFileSync(config, 'utf8')
39
- if (contents.includes(MARKER_START)) {
40
- console.log(` Already configured: ${config}`)
41
- continue
38
+ try {
39
+ const contents = fs.readFileSync(config, 'utf8')
40
+ if (contents.includes(MARKER_START)) {
41
+ console.log(` Already configured: ${config}`)
42
+ continue
43
+ }
44
+ fs.appendFileSync(config, block)
45
+ console.log(` Updated: ${config}`)
46
+ updated++
47
+ } catch (e) {
48
+ // skip files we can't read or write
42
49
  }
43
- fs.appendFileSync(config, block)
44
- console.log(` Updated: ${config}`)
45
- updated++
46
50
  }
47
51
 
48
52
  if (updated > 0) {
@@ -58,11 +62,15 @@ function remove() {
58
62
 
59
63
  let removed = 0
60
64
  for (const config of configs) {
61
- const contents = fs.readFileSync(config, 'utf8')
62
- if (!contents.includes(MARKER_START)) continue
63
- fs.writeFileSync(config, contents.replace(re, '\n'))
64
- console.log(` Removed aliases from: ${config}`)
65
- removed++
65
+ try {
66
+ const contents = fs.readFileSync(config, 'utf8')
67
+ if (!contents.includes(MARKER_START)) continue
68
+ fs.writeFileSync(config, contents.replace(re, '\n'))
69
+ console.log(` Removed aliases from: ${config}`)
70
+ removed++
71
+ } catch (e) {
72
+ // skip files we can't read or write
73
+ }
66
74
  }
67
75
 
68
76
  if (removed === 0) {