@kaynooo/cli-env 0.12.0 → 0.13.1

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.
@@ -7,25 +7,27 @@ const DEFAULT_FILE = '.env'
7
7
  const TRAILING_NEWLINE = /\r?\n$/
8
8
  const KEY_NAME = /^[A-Z_][\w.-]*$/i
9
9
 
10
- const setUsage = `ev set KEY [file]
10
+ const QUIET = { quiet: { type: 'boolean', short: 'q', description: 'print nothing on success' } } as const
11
+
12
+ const setUsage = `ev set KEY [file] [--quiet]
11
13
 
12
14
  Sets KEY in the file (.env by default, created when missing), replacing its line in place or appending one. The value is read from stdin, or from -F <file>, so it never appears in a command line; --empty sets it to an empty value.
13
15
 
14
16
  Exits 0 when it wrote the key, 1 when it could not, 2 on a usage error.`
15
17
 
16
- const unsetUsage = `ev unset KEY [file]
18
+ const unsetUsage = `ev unset KEY [file] [--quiet]
17
19
 
18
20
  Removes every line setting KEY from the file (.env by default), leaving comments and other lines as they are.
19
21
 
20
22
  Exits 0 when it removed the key, 1 when the file does not set it, 2 on a usage error.`
21
23
 
22
- const mvUsage = `ev mv KEY --from <file> --to <file>
24
+ const mvUsage = `ev mv KEY --from <file> --to <file> [--quiet]
23
25
 
24
26
  Moves KEY's line from one file to another, as written. Refuses to replace a key the target already sets unless --force.
25
27
 
26
28
  Exits 0 when it moved the key, 1 when the source lacks it or the target already sets it, 2 on a usage error.`
27
29
 
28
- const cpUsage = `ev cp KEY --from <file> --to <file> [--as NEWKEY]
30
+ const cpUsage = `ev cp KEY --from <file> --to <file> [--as NEWKEY] [--quiet]
29
31
 
30
32
  Copies KEY's value from one file to another without printing it, replacing the key's line in the target in place or appending one, and prints the masked result as ev set does. --as stores the copy under another key.
31
33
 
@@ -54,6 +56,7 @@ export async function set(args: string[]): Promise<number> {
54
56
  const parsed = parse(args, setUsage, {
55
57
  file: { type: 'string', short: 'F', description: 'read the value from this file instead of stdin' },
56
58
  empty: { type: 'boolean', description: 'set an empty value, reading nothing' },
59
+ ...QUIET,
57
60
  })
58
61
 
59
62
  const [key, target = DEFAULT_FILE] = parsed.positionals
@@ -77,13 +80,14 @@ export async function set(args: string[]): Promise<number> {
77
80
  return current
78
81
  })
79
82
 
80
- console.log(`${target}: ${key}=${maskValue(key, value, await loadKnown(process.cwd(), [file])).replaceAll('\n', '\\n')}`)
83
+ if (parsed.values.quiet !== true)
84
+ console.log(`${target}: ${key}=${maskValue(key, value, await loadKnown(process.cwd(), [file])).replaceAll('\n', '\\n')}`)
81
85
 
82
86
  return 0
83
87
  }
84
88
 
85
89
  export async function unset(args: string[]): Promise<number> {
86
- const parsed = parse(args, unsetUsage, {})
90
+ const parsed = parse(args, unsetUsage, QUIET)
87
91
 
88
92
  const [key, target = DEFAULT_FILE] = parsed.positionals
89
93
 
@@ -99,7 +103,8 @@ export async function unset(args: string[]): Promise<number> {
99
103
  await writeEnv(target, file)
100
104
  })
101
105
 
102
- console.log(`${target}: removed ${key}`)
106
+ if (parsed.values.quiet !== true)
107
+ console.log(`${target}: removed ${key}`)
103
108
 
104
109
  return 0
105
110
  }
@@ -139,6 +144,7 @@ export async function mv(args: string[]): Promise<number> {
139
144
  from: { type: 'string', description: 'the file to take KEY from' },
140
145
  to: { type: 'string', description: 'the file to put KEY in, created when missing' },
141
146
  force: { type: 'boolean', description: 'replace KEY when the target already sets it' },
147
+ ...QUIET,
142
148
  })
143
149
 
144
150
  const [key] = parsed.positionals
@@ -154,7 +160,8 @@ export async function mv(args: string[]): Promise<number> {
154
160
  await writeEnv(from, source)
155
161
  })
156
162
 
157
- console.log(`${key}: ${from} -> ${to}`)
163
+ if (parsed.values.quiet !== true)
164
+ console.log(`${key}: ${from} -> ${to}`)
158
165
 
159
166
  return 0
160
167
  }
@@ -164,6 +171,7 @@ export async function cp(args: string[]): Promise<number> {
164
171
  from: { type: 'string', description: 'the file to take KEY from' },
165
172
  to: { type: 'string', description: 'the file to put the copy in, created when missing' },
166
173
  as: { type: 'string', description: 'store the copy under this key instead' },
174
+ ...QUIET,
167
175
  })
168
176
 
169
177
  const [key] = parsed.positionals
@@ -173,9 +181,9 @@ export async function cp(args: string[]): Promise<number> {
173
181
  fail(`needs KEY, --from and --to\n\n${cpUsage}`)
174
182
 
175
183
  const { source, target, value, name } = await withLocks([from, to], async () => transfer(key, from, to, as, true))
176
- const known = await loadKnown(process.cwd(), [source, target])
177
184
 
178
- console.log(`${to}: ${name}=${maskValue(name, value, known).replaceAll('\n', '\\n')}`)
185
+ if (parsed.values.quiet !== true)
186
+ console.log(`${to}: ${name}=${maskValue(name, value, await loadKnown(process.cwd(), [source, target])).replaceAll('\n', '\\n')}`)
179
187
 
180
188
  return 0
181
189
  }
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, ignoredFolders, isSecretName } 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 = ignoredFolders(['.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'