@kaynooo/cli-env 0.11.0 → 0.13.0

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-env",
3
3
  "type": "module",
4
- "version": "0.11.0",
4
+ "version": "0.13.0",
5
5
  "description": "ev lists and edits .env files with secrets masked, redact masks secrets in any piped output.",
6
6
  "author": "Kaynooo <contact@kaynooo.fr>",
7
7
  "license": "MIT",
@@ -37,6 +37,6 @@
37
37
  "redact": "$npm_execpath src/redact.ts"
38
38
  },
39
39
  "devDependencies": {
40
- "@kaynooo/cli-kit": "0.21.1"
40
+ "@kaynooo/cli-kit": "0.35.0"
41
41
  }
42
42
  }
package/src/audit.ts CHANGED
@@ -3,7 +3,7 @@ import { readdir, stat } from 'node:fs/promises'
3
3
  import { dirname, join } from 'node:path'
4
4
  import { isSecretName } from '@kaynooo/cli-kit'
5
5
  import { $ } from 'bun'
6
- import { ENV_FILE, isFileEntry, TEMPLATE } from './files'
6
+ import { ENV_FILE, isFileEntry, SKIPPED, TEMPLATE } from './files'
7
7
  import { urlPasswords } from './mask'
8
8
 
9
9
  export interface Exposure {
@@ -18,7 +18,6 @@ export interface Exposure {
18
18
  }
19
19
 
20
20
  const MAX_DEPTH = 5
21
- const SKIPPED = new Set(['node_modules', '.git', 'vendor'])
22
21
  const COMPOSE_FILE = /^(?:docker-)?compose[\w.-]*\.ya?ml$/
23
22
  // An environment entry, `KEY: value` or `- KEY=value`, with its value written out.
24
23
  const ENTRY = /^\s*(?:-\s*)?["']?([A-Z0-9_]+)["']?\s*[:=]\s*["']?([^"'\s#]+)/
@@ -3,7 +3,7 @@ import type { ComposeFix } from '../fix'
3
3
  import { stat } from 'node:fs/promises'
4
4
  import { relative, resolve } from 'node:path'
5
5
  import process from 'node:process'
6
- import { fail, jsonOption, parse, printJson } from '@kaynooo/cli-kit'
6
+ import { fail, jsonOption, parse, printJson, role } from '@kaynooo/cli-kit'
7
7
  import { shellQuote } from '@kaynooo/cli-kit/shell'
8
8
  import { audit as findExposed } from '../audit'
9
9
  import { fixCompose, shutOthersOut } from '../fix'
@@ -46,6 +46,7 @@ function shown(path: string): string {
46
46
  async function fixAll(exposed: Exposure[], json: boolean): Promise<{ fixed: ComposeFix[], left: boolean }> {
47
47
  const fixed: ComposeFix[] = []
48
48
  let left = false
49
+ const tint = role('path', process.stdout)
49
50
 
50
51
  for (const { path, readable, group, tracked, secrets } of exposed) {
51
52
  const fix = secrets === undefined ? undefined : await fixCompose(path, group === true)
@@ -68,7 +69,7 @@ async function fixAll(exposed: Exposure[], json: boolean): Promise<{ fixed: Comp
68
69
  ...tracked ? [`tracked by git: git rm --cached ${shellQuote(shown(path))}, then ignore it`] : [],
69
70
  ]
70
71
 
71
- console.log(`${shown(path)}\n ${lines.join('\n ')}`)
72
+ console.log(`${tint(shown(path))}\n ${lines.join('\n ')}`)
72
73
  }
73
74
 
74
75
  return { fixed, left }
@@ -118,6 +119,7 @@ export async function audit(args: string[]): Promise<number> {
118
119
  }
119
120
 
120
121
  const uid = process.getuid?.()
122
+ const tint = role('path', process.stdout)
121
123
 
122
124
  for (const { path, readable, group, tracked, secrets } of exposed) {
123
125
  // Only the owner or root can change a file's mode.
@@ -128,7 +130,7 @@ export async function audit(args: string[]): Promise<number> {
128
130
  ...tracked ? [`tracked by git: git rm --cached ${shellQuote(shown(path))}, then ignore it`] : [],
129
131
  ]
130
132
 
131
- console.log(`${shown(path)}\n ${problems.join('\n ')}`)
133
+ console.log(`${tint(shown(path))}\n ${problems.join('\n ')}`)
132
134
  }
133
135
 
134
136
  return 1
@@ -1,4 +1,5 @@
1
- import { fail, jsonOption, parse, printJson } from '@kaynooo/cli-kit'
1
+ import process from 'node:process'
2
+ import { fail, jsonOption, parse, printJson, role } from '@kaynooo/cli-kit'
2
3
  import { entries } from '../dotenv'
3
4
  import { readEnv } from '../files'
4
5
 
@@ -43,7 +44,9 @@ export async function diff(args: string[]): Promise<number> {
43
44
  return onlyA.length + onlyB.length === 0 ? 0 : 1
44
45
  }
45
46
 
46
- const lines = [...onlyA.map(key => `only in ${a}: ${key}`), ...onlyB.map(key => `only in ${b}: ${key}`)]
47
+ const path = role('path', process.stdout)
48
+ const value = role('value', process.stdout)
49
+ const lines = [...onlyA.map(key => `only in ${path(a)}: ${value(key)}`), ...onlyB.map(key => `only in ${path(b)}: ${value(key)}`)]
47
50
 
48
51
  if (lines.length === 0)
49
52
  return 0
@@ -71,7 +74,10 @@ export async function missing(args: string[]): Promise<number> {
71
74
  if (absent.length === 0)
72
75
  return 0
73
76
 
74
- console.log(absent.map(key => `${key} (set in ${against}, not in ${file})`).join('\n'))
77
+ const path = role('path', process.stdout)
78
+ const value = role('value', process.stdout)
79
+
80
+ console.log(absent.map(key => `${value(key)} (set in ${path(against)}, not in ${path(file)})`).join('\n'))
75
81
 
76
82
  return 1
77
83
  }
package/src/ev.ts CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env -S bun --no-env-file
1
+ #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
2
 
3
3
  import process from 'node:process'
4
4
  import { runCli } from '@kaynooo/cli-kit'
package/src/files.ts CHANGED
@@ -3,7 +3,7 @@ import type { Dotenv } from './dotenv'
3
3
  import type { KnownSecrets } from './mask'
4
4
  import { chmod, chown, readdir, realpath, rename, rm, stat, writeFile } from 'node:fs/promises'
5
5
  import { basename, dirname, join } from 'node:path'
6
- import { fail, isSecretName } from '@kaynooo/cli-kit'
6
+ import { fail, isSecretName, SKIPPED_FOLDERS } from '@kaynooo/cli-kit'
7
7
  import { entries, parseDotenv, serializeDotenv } from './dotenv'
8
8
  import { knownSecrets, urlPasswords } from './mask'
9
9
 
@@ -13,7 +13,8 @@ export const TEMPLATE = /\.(?:example|sample|template|dist|defaults)$/
13
13
 
14
14
  // Folders searched for secrets below the current one, and the ones never entered.
15
15
  const KNOWN_DEPTH = 3
16
- const SKIPPED = new Set(['node_modules', '.git', 'vendor'])
16
+
17
+ export const SKIPPED = new Set([...SKIPPED_FOLDERS, '.git', '.kay'])
17
18
  const LOCK_WAIT_MS = 5000
18
19
  const LOCK_STALE_MS = 30_000
19
20
  // A reap takes a few milliseconds, so a guard older than this belongs to a reaper that died.
package/src/pins.ts CHANGED
@@ -3,6 +3,7 @@ import { readdir, readFile } from 'node:fs/promises'
3
3
  import { join, relative } from 'node:path'
4
4
  import { fail } from '@kaynooo/cli-kit'
5
5
  import { parseDotenv } from './dotenv'
6
+ import { SKIPPED } from './files'
6
7
 
7
8
  export interface PinFinding {
8
9
  // A test file that renders a page or starts the app, relative to the app folder.
@@ -35,7 +36,6 @@ const KEY = /(?:^|[{,])\s*([A-Z_]\w*)\s*:/gi
35
36
  const TEST_FILE = /\.test\.[cm]?[jt]sx?$/
36
37
  const ENV_TEST = /^\.env\.test(?:\.local)?$/
37
38
  const TEST_ROOTS = ['tests', 'test', '__tests__', 'e2e', 'src']
38
- const SKIPPED = new Set(['node_modules', '.git', '.kay', 'dist', 'vendor'])
39
39
  const SCHEMA_CANDIDATES = ['src/env.ts', 'env.ts', 'src/env/index.ts']
40
40
  const OPENERS = new Set(['(', '[', '{'])
41
41
  const CLOSERS = new Set([')', ']', '}'])
package/src/redact.ts CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env -S bun --no-env-file
1
+ #!/usr/bin/env -S bun --no-env-file --config=/dev/null
2
2
 
3
3
  import process from 'node:process'
4
4
  import { runMain } from '@kaynooo/cli-kit'