kifaru 1.0.145 → 1.0.147

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.
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs")
4
+ const os = require("os")
5
+ const path = require("path")
6
+
7
+ const approvedPackages = ["kifaru", "agent-browser", "snyk", "esbuild", "workerd", "sharp", "keytar", "node-pty"]
8
+
9
+ function parseAllowScripts(value) {
10
+ return value
11
+ .split(/[,\r\n]+/)
12
+ .map((item) => item.trim())
13
+ .filter((item) => item && item !== "null" && item !== "undefined")
14
+ }
15
+
16
+ function mergeAllowScripts(current, additions = approvedPackages) {
17
+ return [...new Set([...parseAllowScripts(current), ...additions])]
18
+ }
19
+
20
+ function resolveUserConfig() {
21
+ const configured = process.env.NPM_CONFIG_USERCONFIG || process.env.npm_config_userconfig
22
+ return configured ? path.resolve(configured) : path.join(os.homedir(), ".npmrc")
23
+ }
24
+
25
+ // npm 12 introduced allow-scripts. npm 10/11 reject the key through
26
+ // `npm config`, so update the forward-compatible user config directly.
27
+ function updateAllowScripts(content, additions = approvedPackages) {
28
+ const newline = content.includes("\r\n") ? "\r\n" : "\n"
29
+ const hadTrailingNewline = content.endsWith("\n")
30
+ const lines = content ? content.split(/\r?\n/) : []
31
+ if (hadTrailingNewline) lines.pop()
32
+
33
+ const values = []
34
+ for (const line of lines) {
35
+ const match = line.match(/^\s*allow-scripts\s*=\s*(.*)$/i)
36
+ if (match) values.push(match[1])
37
+ }
38
+
39
+ const allowed = mergeAllowScripts(values.join(","), additions)
40
+ const setting = `allow-scripts=${allowed.join(",")}`
41
+ let replaced = false
42
+ const next = lines.flatMap((line) => {
43
+ if (!/^\s*allow-scripts\s*=/i.test(line)) return [line]
44
+ if (replaced) return []
45
+ replaced = true
46
+ return [setting]
47
+ })
48
+ if (!replaced) next.push(setting)
49
+
50
+ return next.join(newline) + newline
51
+ }
52
+
53
+ function main() {
54
+ const userConfig = resolveUserConfig()
55
+ const current = fs.existsSync(userConfig) ? fs.readFileSync(userConfig, "utf8") : ""
56
+ const updated = updateAllowScripts(current)
57
+
58
+ fs.mkdirSync(path.dirname(userConfig), { recursive: true })
59
+ fs.writeFileSync(userConfig, updated)
60
+
61
+ console.log(`Allowed npm install scripts for: ${approvedPackages.join(", ")}`)
62
+ console.log(`Updated: ${userConfig}`)
63
+ }
64
+
65
+ if (require.main === module) {
66
+ try {
67
+ main()
68
+ } catch (error) {
69
+ console.error(`Failed to update npm install-script policy: ${error.message}`)
70
+ process.exit(1)
71
+ }
72
+ }
73
+
74
+ module.exports = {
75
+ approvedPackages,
76
+ mergeAllowScripts,
77
+ parseAllowScripts,
78
+ resolveUserConfig,
79
+ updateAllowScripts,
80
+ }
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "kifaru",
3
3
  "bin": {
4
- "kifaru": "./bin/kifaru"
4
+ "kifaru": "./bin/kifaru",
5
+ "kifaru-allow-scripts": "./bin/kifaru-allow-scripts.cjs"
5
6
  },
6
7
  "scripts": {
7
8
  "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
9
  },
9
- "version": "1.0.145",
10
+ "version": "1.0.147",
10
11
  "dependencies": {
11
12
  "@openauthjs/openauth": "0.0.0-20250322224806"
12
13
  },
13
14
  "optionalDependencies": {
14
- "kifaru-linux-arm64": "1.0.145",
15
- "kifaru-linux-x64-baseline": "1.0.145",
16
- "kifaru-linux-arm64-musl": "1.0.145",
17
- "kifaru-linux-x64-baseline-musl": "1.0.145",
18
- "kifaru-darwin-arm64": "1.0.145",
19
- "kifaru-darwin-x64": "1.0.145",
20
- "kifaru-windows-x64": "1.0.145"
15
+ "kifaru-linux-arm64": "1.0.147",
16
+ "kifaru-linux-x64-baseline": "1.0.147",
17
+ "kifaru-linux-arm64-musl": "1.0.147",
18
+ "kifaru-linux-x64-baseline-musl": "1.0.147",
19
+ "kifaru-darwin-arm64": "1.0.147",
20
+ "kifaru-darwin-x64": "1.0.147",
21
+ "kifaru-windows-x64": "1.0.147"
21
22
  }
22
23
  }