@skitterbyte/skitterspec 23.8.0 → 23.9.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/src/env/trust.js CHANGED
@@ -41,8 +41,11 @@ function writeSettings(file, settings) {
41
41
  * - `added` — the root was merged into an existing file
42
42
  * - `present` — the root was already listed (no write)
43
43
  * - `malformed` — the file exists but isn't parseable JSON (left untouched)
44
+ *
45
+ * `{ dryRun: true }` answers the same question and writes nothing — `changed`
46
+ * then means "would change", which is what `spec-env up --plan` reports.
44
47
  */
45
- function ensureWorktreeDirTrusted(dir, rootAbs) {
48
+ function ensureWorktreeDirTrusted(dir, rootAbs, { dryRun = false } = {}) {
46
49
  const file = settingsPath(dir)
47
50
 
48
51
  let raw
@@ -50,7 +53,7 @@ function ensureWorktreeDirTrusted(dir, rootAbs) {
50
53
  raw = fs.readFileSync(file, 'utf-8')
51
54
  } catch (error) {
52
55
  if (error.code === 'ENOENT') {
53
- writeSettings(file, { permissions: { additionalDirectories: [rootAbs] } })
56
+ if (!dryRun) writeSettings(file, { permissions: { additionalDirectories: [rootAbs] } })
54
57
  return { changed: true, reason: 'created' }
55
58
  }
56
59
  throw error
@@ -70,6 +73,7 @@ function ensureWorktreeDirTrusted(dir, rootAbs) {
70
73
  : []
71
74
 
72
75
  if (dirs.includes(rootAbs)) return { changed: false, reason: 'present' }
76
+ if (dryRun) return { changed: true, reason: 'added' }
73
77
 
74
78
  writeSettings(file, {
75
79
  ...parsed,