hazo_env 0.15.2 → 0.16.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.
Files changed (47) hide show
  1. package/CHANGE_LOG.md +84 -0
  2. package/README.md +316 -0
  3. package/dist/cli.js +102 -14
  4. package/dist/deploy/build.d.ts.map +1 -1
  5. package/dist/deploy/build.js +19 -0
  6. package/dist/deploy/clean.d.ts +2 -1
  7. package/dist/deploy/clean.d.ts.map +1 -1
  8. package/dist/deploy/clean.js +36 -6
  9. package/dist/deploy/generate-readme-cli.d.ts +3 -0
  10. package/dist/deploy/generate-readme-cli.d.ts.map +1 -0
  11. package/dist/deploy/generate-readme-cli.js +40 -0
  12. package/dist/deploy/help.d.ts +55 -0
  13. package/dist/deploy/help.d.ts.map +1 -0
  14. package/dist/deploy/help.js +526 -0
  15. package/dist/deploy/index.d.ts +3 -0
  16. package/dist/deploy/index.d.ts.map +1 -1
  17. package/dist/deploy/index.js +3 -0
  18. package/dist/deploy/init.d.ts +8 -0
  19. package/dist/deploy/init.d.ts.map +1 -1
  20. package/dist/deploy/init.js +12 -1
  21. package/dist/deploy/rollback.d.ts +10 -1
  22. package/dist/deploy/rollback.d.ts.map +1 -1
  23. package/dist/deploy/rollback.js +25 -1
  24. package/dist/deploy/share.d.ts +28 -0
  25. package/dist/deploy/share.d.ts.map +1 -0
  26. package/dist/deploy/share.js +53 -0
  27. package/dist/deploy/shared-dirs.d.ts +128 -0
  28. package/dist/deploy/shared-dirs.d.ts.map +1 -0
  29. package/dist/deploy/shared-dirs.js +486 -0
  30. package/dist/deploy/status.d.ts +8 -0
  31. package/dist/deploy/status.d.ts.map +1 -1
  32. package/dist/deploy/status.js +6 -0
  33. package/dist/deploy/switch.d.ts.map +1 -1
  34. package/dist/deploy/switch.js +25 -0
  35. package/dist/deploy/types.d.ts +18 -0
  36. package/dist/deploy/types.d.ts.map +1 -1
  37. package/dist/envsync/engine.d.ts.map +1 -1
  38. package/dist/envsync/engine.js +21 -7
  39. package/dist/envsync/paths.d.ts +22 -0
  40. package/dist/envsync/paths.d.ts.map +1 -1
  41. package/dist/envsync/paths.js +55 -0
  42. package/dist/resolve/deploy.d.ts.map +1 -1
  43. package/dist/resolve/deploy.js +165 -0
  44. package/dist/resolve/envsync.d.ts +16 -0
  45. package/dist/resolve/envsync.d.ts.map +1 -1
  46. package/dist/resolve/envsync.js +19 -0
  47. package/package.json +3 -2
@@ -50,8 +50,9 @@ export declare const SWAP_INCREASE_SUGGESTIONS: string[];
50
50
  * Safe-targets-only cleanup, for reuse by `deploy build`'s auto-clean step
51
51
  * (Task 5). Stable 2-arg signature — do not add parameters here; use
52
52
  * `runClean` for anything CLI-specific (--aggressive, swap suggestions).
53
+ * `config.shared_dirs` (ticket 03) is read here — see `overlapsSharedDir`.
53
54
  */
54
- export declare function autoClean(_config: DeployConfig, runner: CommandRunner): AutoCleanResult;
55
+ export declare function autoClean(config: DeployConfig, runner: CommandRunner): AutoCleanResult;
55
56
  /**
56
57
  * Full `deploy clean` behavior: runs the same safe-target cleanup as
57
58
  * `autoClean`, then adds the memory-triggered swap suggestion (independent
@@ -1 +1 @@
1
- {"version":3,"file":"clean.d.ts","sourceRoot":"","sources":["../../src/deploy/clean.ts"],"names":[],"mappings":"AAiCA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE9D,0EAA0E;AAC1E,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,oFAAoF;IACpF,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,cAAc,EAAE,MAAM,CAAC;IACvB,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAC;IACjB,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,mBAAmB,EAAE,M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AED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,iBAAiB,EAAE,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,UAAU,EAAE,OAAO,CAAC;IACpB,2IAA2I;IAC3I,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,8EAA8E;AAC9E,MAAM,WAAW,cAAe,SAAQ,eAAe;IACrD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,4DAA4D;IAC5D,SAAS,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,iFAAiF;AACjF,eAAO,MAAM,0BAA0B,UAItC,CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,yBAAyB,UAKrC,CAAC;AA+GF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,GAAG,eAAe,CAEtF;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,eAAe,GAAG,cAAc,CAiB3G"}
@@ -48,6 +48,31 @@ const DIR_TARGETS = [
48
48
  { name: '.next.staging', relativePath: '.next.staging' },
49
49
  { name: 'node_modules/.cache', relativePath: path.join('node_modules', '.cache') },
50
50
  ];
51
+ /**
52
+ * Ticket 03 (deploy-shared-dirs spec), user story 30: `deploy clean` must
53
+ * never delete through a shared-dir link. The three `DIR_TARGETS` above are
54
+ * fixed, well-known build-artifact paths that would never normally overlap
55
+ * an operator-declared `shared_dirs` entry (an uploads folder) — this is a
56
+ * defensive guard against misconfiguration, not the normal case. True when
57
+ * `relativePath` (one of DIR_TARGETS) is equal to, an ancestor of, or a
58
+ * descendant of ANY configured shared dir — in every one of those shapes,
59
+ * removing `relativePath` would touch (or BE) a shared-dir path. A pure
60
+ * config-level comparison (no fs calls): matches this module's existing
61
+ * discipline of only ever touching the filesystem through CommandRunner.
62
+ */
63
+ function overlapsSharedDir(relativePath, sharedDirs) {
64
+ const target = path.normalize(relativePath);
65
+ return sharedDirs.some((dir) => {
66
+ const normalizedDir = path.normalize(dir);
67
+ if (normalizedDir === target)
68
+ return true;
69
+ const targetUnderDir = path.relative(normalizedDir, target);
70
+ if (!targetUnderDir.startsWith('..') && !path.isAbsolute(targetUnderDir))
71
+ return true;
72
+ const dirUnderTarget = path.relative(target, normalizedDir);
73
+ return !dirUnderTarget.startsWith('..') && !path.isAbsolute(dirUnderTarget);
74
+ });
75
+ }
51
76
  /** Parse `du -sk <path>` output's leading KB column. Lenient to platform/locale variance. */
52
77
  function parseDuKb(duOutput) {
53
78
  const token = duOutput.trim().split(/\s+/)[0];
@@ -61,8 +86,12 @@ function measureDirKb(runner, absPath) {
61
86
  return undefined;
62
87
  return parseDuKb(result.stdout);
63
88
  }
64
- function cleanDirTarget(runner, cwd, name, relativePath, warnings) {
89
+ function cleanDirTarget(runner, cwd, name, relativePath, sharedDirs, warnings) {
65
90
  const absPath = path.join(cwd, relativePath);
91
+ if (overlapsSharedDir(relativePath, sharedDirs)) {
92
+ warnings.push(`skipping "${name}" (${absPath}) — it overlaps a configured shared dir; "deploy clean" never deletes through a shared-dir link.`);
93
+ return { target: name, path: absPath, bytesReclaimed: 0, skipped: true };
94
+ }
66
95
  const beforeKb = measureDirKb(runner, absPath);
67
96
  if (beforeKb === undefined) {
68
97
  // Doesn't exist (or unreadable) — nothing to clean, not an error.
@@ -95,9 +124,9 @@ function cleanNpmCacheTarget(runner, warnings) {
95
124
  const bytesReclaimed = Math.max(0, (beforeKb - afterKb) * 1024);
96
125
  return { target: 'npm-cache', path: cachePath ?? '(unknown)', bytesReclaimed, skipped: false };
97
126
  }
98
- function cleanAllTargets(runner, cwd) {
127
+ function cleanAllTargets(runner, cwd, sharedDirs) {
99
128
  const warnings = [];
100
- const targets = DIR_TARGETS.map((t) => cleanDirTarget(runner, cwd, t.name, t.relativePath, warnings));
129
+ const targets = DIR_TARGETS.map((t) => cleanDirTarget(runner, cwd, t.name, t.relativePath, sharedDirs, warnings));
101
130
  targets.push(cleanNpmCacheTarget(runner, warnings));
102
131
  const totalBytesReclaimed = targets.reduce((sum, t) => sum + t.bytesReclaimed, 0);
103
132
  return { targets, totalBytesReclaimed, warnings };
@@ -106,9 +135,10 @@ function cleanAllTargets(runner, cwd) {
106
135
  * Safe-targets-only cleanup, for reuse by `deploy build`'s auto-clean step
107
136
  * (Task 5). Stable 2-arg signature — do not add parameters here; use
108
137
  * `runClean` for anything CLI-specific (--aggressive, swap suggestions).
138
+ * `config.shared_dirs` (ticket 03) is read here — see `overlapsSharedDir`.
109
139
  */
110
- export function autoClean(_config, runner) {
111
- return cleanAllTargets(runner, process.cwd());
140
+ export function autoClean(config, runner) {
141
+ return cleanAllTargets(runner, process.cwd(), config.shared_dirs);
112
142
  }
113
143
  /**
114
144
  * Full `deploy clean` behavior: runs the same safe-target cleanup as
@@ -119,7 +149,7 @@ export function autoClean(_config, runner) {
119
149
  */
120
150
  export function runClean(config, runner, opts) {
121
151
  const cwd = opts.cwd ?? process.cwd();
122
- const auto = cleanAllTargets(runner, cwd);
152
+ const auto = cleanAllTargets(runner, cwd, config.shared_dirs);
123
153
  const warnings = [...auto.warnings];
124
154
  const memoryFreeMb = queryMemoryFreeMb(runner, warnings);
125
155
  const memoryLow = memoryFreeMb !== undefined && memoryFreeMb < config.min_memory_mb;
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=generate-readme-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-readme-cli.d.ts","sourceRoot":"","sources":["../../src/deploy/generate-readme-cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env node
2
+ // hazo_env/src/deploy/generate-readme-cli.ts — regenerate README.md's
3
+ // generated "Deploy" section from src/deploy/help.ts.
4
+ //
5
+ // Run via `npm run docs:deploy` (builds first, then runs this compiled file —
6
+ // see package.json). Idempotent: re-running with no help.ts changes leaves
7
+ // README.md byte-identical. Fails loudly if the markers are missing or out
8
+ // of order, rather than silently appending or corrupting the file.
9
+ import fs from 'node:fs';
10
+ import path from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { renderDeployReadmeSection, DEPLOY_README_MARKER_START, DEPLOY_README_MARKER_END } from './help.js';
13
+ function findReadmePath() {
14
+ // dist/deploy/generate-readme-cli.js -> package root is two levels up.
15
+ const here = path.dirname(fileURLToPath(import.meta.url));
16
+ return path.resolve(here, '..', '..', 'README.md');
17
+ }
18
+ function main() {
19
+ const readmePath = findReadmePath();
20
+ const original = fs.readFileSync(readmePath, 'utf-8');
21
+ const startIdx = original.indexOf(DEPLOY_README_MARKER_START);
22
+ const endIdx = original.indexOf(DEPLOY_README_MARKER_END);
23
+ if (startIdx === -1 || endIdx === -1 || endIdx < startIdx) {
24
+ console.error(`Error: could not find both deploy-section markers in ${readmePath}.\n` +
25
+ `Expected:\n ${DEPLOY_README_MARKER_START}\n ...\n ${DEPLOY_README_MARKER_END}`);
26
+ process.exit(1);
27
+ return;
28
+ }
29
+ const before = original.slice(0, startIdx);
30
+ const after = original.slice(endIdx + DEPLOY_README_MARKER_END.length);
31
+ const generated = `${DEPLOY_README_MARKER_START}\n\n${renderDeployReadmeSection()}\n\n${DEPLOY_README_MARKER_END}`;
32
+ const updated = `${before}${generated}${after}`;
33
+ if (updated === original) {
34
+ console.log(`README.md's deploy section is already up to date (${readmePath}).`);
35
+ return;
36
+ }
37
+ fs.writeFileSync(readmePath, updated, 'utf-8');
38
+ console.log(`Regenerated README.md's deploy section (${readmePath}).`);
39
+ }
40
+ main();
@@ -0,0 +1,55 @@
1
+ /** The 8 real `deploy` actions (excludes the documentation-only `config` pseudo-subcommand). */
2
+ export declare const DEPLOY_SUBCOMMAND_NAMES: readonly ["init", "build", "verify", "switch", "rollback", "status", "clean", "share"];
3
+ export type DeploySubcommandName = (typeof DEPLOY_SUBCOMMAND_NAMES)[number];
4
+ export interface DeployFlagHelp {
5
+ flag: string;
6
+ description: string;
7
+ }
8
+ export interface DeploySubcommandHelp {
9
+ name: DeploySubcommandName;
10
+ /** One-liner shown in `deploy --help`'s subcommand list and the README's summary table. */
11
+ summary: string;
12
+ flags: DeployFlagHelp[];
13
+ /** Prose paragraphs (rendered one per blank-line-separated block) for `deploy <cmd> --help` / README. */
14
+ description: string[];
15
+ /** What this command reads, as "<location>: <what>" lines (location = live slot / standby slot / shared root / state file / external). */
16
+ reads: string[];
17
+ /** What this command writes/mutates, same "<location>: <what>" shape. */
18
+ writes: string[];
19
+ /** `[deploy]` INI keys this command consults. */
20
+ configKeys: string[];
21
+ /** Every way this command can fail, as one line each — typed error + code where one exists, otherwise the literal thrown message. */
22
+ failureModes: string[];
23
+ /** Runnable example invocations, most useful first. */
24
+ examples: string[];
25
+ }
26
+ export declare const DEPLOY_SUBCOMMAND_HELP: Record<DeploySubcommandName, DeploySubcommandHelp>;
27
+ export interface DeployConfigKeyHelp {
28
+ key: string;
29
+ type: string;
30
+ default: string;
31
+ meaning: string;
32
+ example: string;
33
+ }
34
+ /**
35
+ * Every `[deploy]` INI key `resolveDeployConfig` parses, in the order
36
+ * declared on `DeployConfig` (src/deploy/types.ts). `post_switch_cmd` is
37
+ * documented once here even though the parser also accepts numbered
38
+ * `post_switch_cmd_2`, `_3`, ... suffixes — see its `meaning` text.
39
+ * `__tests__/deploy-help.test.ts` cross-checks this list's `key`s (mapped
40
+ * back from the field names `resolveDeployConfig` actually returns) against
41
+ * a fully-populated resolved config, so a new `DeployConfig` field with no
42
+ * matching entry here fails CI.
43
+ */
44
+ export declare const DEPLOY_CONFIG_HELP: DeployConfigKeyHelp[];
45
+ /** Body of `hazo-env deploy --help` — one line per subcommand plus its flags, exactly as before but generated. */
46
+ export declare function renderDeploySummaryList(): string;
47
+ /** Body of `hazo-env deploy <cmd> --help`. */
48
+ export declare function renderDeploySubcommandHelpText(name: DeploySubcommandName): string;
49
+ /** Body of `hazo-env deploy config --help` (and `hazo-env deploy config`). */
50
+ export declare function renderDeployConfigHelpText(): string;
51
+ export declare const DEPLOY_README_MARKER_START = "<!-- BEGIN GENERATED: deploy section (see src/deploy/help.ts) -->";
52
+ export declare const DEPLOY_README_MARKER_END = "<!-- END GENERATED: deploy section -->";
53
+ /** The whole generated Markdown block, placed between DEPLOY_README_MARKER_START/_END in README.md. */
54
+ export declare function renderDeployReadmeSection(): string;
55
+ //# sourceMappingURL=help.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.d.ts","sourceRoot":"","sources":["../../src/deploy/help.ts"],"names":[],"mappings":"AA0BA,gGAAgG;AAChG,eAAO,MAAM,uBAAuB,wFAS1B,CAAC;AAEX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,2FAA2F;IAC3F,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,yGAAyG;IACzG,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,0IAA0I;IAC1I,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,yEAAyE;IACzE,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,iDAAiD;IACjD,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,qIAAqI;IACrI,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,uDAAuD;IACvD,Q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