@brutalsystems/dray 0.1.9 → 0.1.10

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@brutalsystems/dray",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Convention-driven multi-repo deploy orchestrator (forge for shipping)",
5
5
  "bin": {
6
6
  "dray": "bin/dray.js"
@@ -1,7 +1,20 @@
1
+ const fs = require('node:fs'); const path = require('node:path');
1
2
  const { loadRepoConfig } = require('../../config/repo'); const { addRepo } = require('../../config/registry');
3
+
4
+ // The registry is consulted from arbitrary working directories, so a stored path
5
+ // MUST be absolute. `dray add .` used to store "." verbatim, which then resolved
6
+ // against whatever cwd dray ran in later -- two repos added that way both pointed
7
+ // at "the current directory", and `dray ship <a>` from repo b deployed b under a's
8
+ // name. realpath so symlinked checkouts land on one canonical path.
9
+ function resolveRepoPath(repoPath) {
10
+ const p = path.resolve(repoPath || process.cwd());
11
+ try { return fs.realpathSync(p); } catch { return p; }
12
+ }
13
+
2
14
  module.exports = function registerAdd(program) {
3
15
  program.command('add [repoPath]').description('Register a repo').action((repoPath) => {
4
- const p = repoPath || process.cwd(); const config = loadRepoConfig(p);
16
+ const p = resolveRepoPath(repoPath); const config = loadRepoConfig(p);
5
17
  addRepo(undefined, { name: config.name, path: p, config }); console.log(`registered ${config.name} → ${p}`);
6
18
  });
7
19
  };
20
+ module.exports.resolveRepoPath = resolveRepoPath;
@@ -10,16 +10,22 @@ function removeRepo(file, name) { const r = loadRegistry(file); delete r[name];
10
10
  // without a manual `dray reload`. Falls back to the snapshot when the repo
11
11
  // isn't checked out here (stat throws) or its config is momentarily invalid
12
12
  // (loadRepoConfig throws) — a broken repo must not break `list`/`--all`.
13
- function refreshEntry(entry) {
13
+ function refreshEntry(entry, name) {
14
14
  try {
15
15
  const mtime = Math.floor(fs.statSync(path.join(entry.path, '.dray', 'config.json')).mtimeMs);
16
16
  if (mtime <= (Date.parse(entry.addedAt) || 0)) return entry;
17
- return { ...entry, config: loadRepoConfig(entry.path), addedAt: new Date(mtime).toISOString() };
17
+ const config = loadRepoConfig(entry.path);
18
+ // Only adopt a config that still belongs to this entry. A path pointing at a
19
+ // different project (a relative path left by an old `dray add .`, or a moved
20
+ // checkout) would otherwise have its config silently written into this key and
21
+ // PERSISTED -- turning `dray ship <name>` into a deploy of someone else's repo.
22
+ if (name !== undefined && config.name !== name) return entry;
23
+ return { ...entry, config, addedAt: new Date(mtime).toISOString() };
18
24
  } catch { return entry; }
19
25
  }
20
26
  function allRepos(file = REGISTRY) {
21
27
  const reg = loadRegistry(file); let changed = false;
22
- for (const [n, e] of Object.entries(reg)) { const f = refreshEntry(e); if (f !== e) { reg[n] = f; changed = true; } }
28
+ for (const [n, e] of Object.entries(reg)) { const f = refreshEntry(e, n); if (f !== e) { reg[n] = f; changed = true; } }
23
29
  if (changed) saveRegistry(file, reg);
24
30
  return reg;
25
31
  }