@sous-io/sous 0.1.0 → 0.2.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/README.md +121 -35
- package/bin/run.js +10 -1
- package/docs/markdown/README.md +27 -0
- package/docs/markdown/_sidebar.md +18 -0
- package/docs/markdown/commands.md +308 -0
- package/docs/markdown/config-discovery.md +74 -0
- package/docs/markdown/config-inspection.md +69 -0
- package/docs/markdown/config-layers.md +92 -0
- package/docs/markdown/config-variables.md +79 -0
- package/docs/markdown/configuration.md +71 -0
- package/docs/markdown/design-principles.md +59 -0
- package/docs/markdown/repositories-authoring.md +408 -0
- package/docs/markdown/repositories-consuming.md +580 -0
- package/docs/markdown/repositories-file-formats.md +1084 -0
- package/docs/markdown/repositories-variables.md +387 -0
- package/docs/markdown/repositories.md +303 -0
- package/docs/markdown/skill-categories.md +58 -0
- package/package.json +73 -9
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/SKILL.tpl.md +20 -20
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/examples/about-something.md +2 -2
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/examples/do-something.md +1 -1
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/references/advanced-patterns.md +6 -6
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/references/commands.md +5 -5
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/references/frontmatter.md +3 -3
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-liquid-templates/SKILL.tpl.md +40 -25
- package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +70 -0
- package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +75 -0
- package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/create-skill/SKILL.tpl.md +8 -9
- package/recipes/core/sous-skills/sous.recipe.yaml +45 -0
- package/sous.config.schema.json +337 -0
- package/src/base-command.ts +220 -67
- package/src/commands/build.ts +150 -73
- package/src/commands/clear.ts +23 -15
- package/src/commands/compile.ts +74 -16
- package/src/commands/config/get.ts +110 -0
- package/src/commands/config/show.ts +32 -0
- package/src/commands/config/validate.ts +53 -0
- package/src/commands/help.ts +46 -0
- package/src/commands/launch.ts +36 -14
- package/src/commands/lock/rebuild.ts +241 -0
- package/src/commands/lock/show.ts +115 -0
- package/src/commands/namespace/list.ts +117 -0
- package/src/commands/namespace/show.ts +110 -0
- package/src/commands/prune.ts +3 -11
- package/src/commands/recipe/list.ts +95 -0
- package/src/commands/recipe/show.ts +301 -0
- package/src/commands/repo/add.ts +145 -0
- package/src/commands/repo/gc.ts +172 -0
- package/src/commands/repo/init.ts +136 -0
- package/src/commands/repo/link.ts +500 -0
- package/src/commands/repo/list.ts +179 -0
- package/src/commands/repo/release.ts +619 -0
- package/src/commands/repo/remove.ts +193 -0
- package/src/commands/repo/search.ts +189 -0
- package/src/commands/repo/submit.ts +133 -0
- package/src/commands/repo/unlink.ts +147 -0
- package/src/commands/subscription/add.ts +285 -0
- package/src/commands/subscription/list.ts +129 -0
- package/src/commands/subscription/remove.ts +181 -0
- package/src/commands/vars/ask.ts +374 -0
- package/src/commands/vars/index.ts +79 -0
- package/src/commands/vars/list.ts +67 -0
- package/src/commands/vars/show.ts +77 -0
- package/src/config-command.ts +30 -0
- package/src/lib/build-service.ts +206 -54
- package/src/lib/config-discovery.ts +220 -27
- package/src/lib/config-inspect.ts +145 -0
- package/src/lib/config-kernel.mjs +377 -0
- package/src/lib/config-schema.ts +361 -0
- package/src/lib/env-file.ts +328 -0
- package/src/lib/env-local.ts +18 -1
- package/src/lib/errors.ts +32 -0
- package/src/lib/include-resolver.ts +108 -15
- package/src/lib/interactive.ts +165 -0
- package/src/lib/markdown-compiler.ts +118 -37
- package/src/lib/package-info.ts +25 -0
- package/src/lib/pid-service.ts +32 -21
- package/src/lib/refs/find.ts +589 -0
- package/src/lib/refs/index.ts +12 -0
- package/src/lib/refs/pick.ts +147 -0
- package/src/lib/refs/scopes.ts +61 -0
- package/src/lib/repos/catalog-display.ts +116 -0
- package/src/lib/repos/catalog-inputs.ts +160 -0
- package/src/lib/repos/catalog.ts +722 -0
- package/src/lib/repos/core-recipe.ts +105 -0
- package/src/lib/repos/defaults.ts +175 -0
- package/src/lib/repos/formats/common.ts +389 -0
- package/src/lib/repos/formats/index-file.ts +215 -0
- package/src/lib/repos/formats/links-map.ts +96 -0
- package/src/lib/repos/formats/lockfile.ts +167 -0
- package/src/lib/repos/formats/patterns.ts +57 -0
- package/src/lib/repos/formats/recipe-manifest.ts +395 -0
- package/src/lib/repos/formats/repo-manifest.ts +88 -0
- package/src/lib/repos/formats/store-entry.ts +84 -0
- package/src/lib/repos/freshness.ts +208 -0
- package/src/lib/repos/git-clone.ts +312 -0
- package/src/lib/repos/identity.ts +89 -0
- package/src/lib/repos/index.ts +58 -0
- package/src/lib/repos/links.ts +353 -0
- package/src/lib/repos/load-manifest.ts +236 -0
- package/src/lib/repos/lock-service.ts +453 -0
- package/src/lib/repos/locked-namespace-resolver.ts +90 -0
- package/src/lib/repos/locked-recipes.ts +254 -0
- package/src/lib/repos/managed-layer.ts +422 -0
- package/src/lib/repos/namespace-resolver.ts +370 -0
- package/src/lib/repos/providers/base.ts +206 -0
- package/src/lib/repos/providers/git.ts +233 -0
- package/src/lib/repos/providers/github.ts +294 -0
- package/src/lib/repos/providers/gitlab.ts +263 -0
- package/src/lib/repos/providers/http.ts +102 -0
- package/src/lib/repos/providers/index-cache.ts +382 -0
- package/src/lib/repos/providers/index.ts +106 -0
- package/src/lib/repos/providers/local.ts +391 -0
- package/src/lib/repos/providers/provider.ts +401 -0
- package/src/lib/repos/recipe-config-layers.ts +287 -0
- package/src/lib/repos/recipe-targets.ts +223 -0
- package/src/lib/repos/ref-search.ts +46 -0
- package/src/lib/repos/ref.ts +513 -0
- package/src/lib/repos/reference-report.ts +122 -0
- package/src/lib/repos/release/bump.ts +161 -0
- package/src/lib/repos/release/git-state.ts +305 -0
- package/src/lib/repos/release/index-builder.ts +635 -0
- package/src/lib/repos/release/index.ts +16 -0
- package/src/lib/repos/release/plan.ts +512 -0
- package/src/lib/repos/release/submit-service.ts +496 -0
- package/src/lib/repos/release/tags.ts +243 -0
- package/src/lib/repos/release/validate.ts +463 -0
- package/src/lib/repos/resolver.ts +789 -0
- package/src/lib/repos/scaffold/index.ts +238 -0
- package/src/lib/repos/scaffold/templates.ts +413 -0
- package/src/lib/repos/seed.ts +414 -0
- package/src/lib/repos/store/contract.ts +64 -0
- package/src/lib/repos/store/hash.ts +114 -0
- package/src/lib/repos/store/recipe-store.ts +599 -0
- package/src/lib/repos/store/settings.ts +58 -0
- package/src/lib/repos/subscription-service.ts +2678 -0
- package/src/lib/repos/trust.ts +447 -0
- package/src/lib/settings.ts +546 -189
- package/src/lib/sous-home.ts +104 -0
- package/src/lib/state.ts +52 -20
- package/src/lib/vars/ask.ts +1152 -0
- package/src/lib/vars/definition-source.ts +252 -0
- package/src/lib/vars/display.ts +233 -0
- package/src/lib/vars/index.ts +18 -0
- package/src/lib/vars/ladder.ts +282 -0
- package/src/lib/vars/mappings.ts +265 -0
- package/src/lib/vars/names.ts +94 -0
- package/src/lib/vars/preanswers.ts +395 -0
- package/src/lib/vars/question-plan.ts +218 -0
- package/src/lib/vars/report.ts +228 -0
- package/src/lib/vars/safe-regex.ts +235 -0
- package/src/lib/vars/validate.ts +312 -0
- package/src/lib/watch-loop.ts +148 -0
- package/src/templating/init-liquid-engine.ts +58 -16
- package/src/utils/choice-prompt.ts +143 -0
- package/src/utils/command-errors.ts +186 -0
- package/src/utils/command-help.ts +45 -0
- package/src/utils/confirm-prompt.ts +110 -0
- package/src/utils/flags.ts +153 -0
- package/src/utils/formatting.ts +540 -55
- package/src/utils/prompts.ts +35 -1
- package/src/utils/sous-directory.ts +245 -0
- package/src/utils/table.ts +603 -0
- package/src/utils/value-prompt.ts +119 -0
- package/bin/xcv +0 -5
- package/shared-prompts/_partials/resume-task.md +0 -51
- package/shared-prompts/_partials/sub-agent-delegation.md +0 -32
- package/shared-prompts/_partials/update-task-file.md +0 -52
- package/shared-prompts/memories/automated-browser-tasks/INDEX.tpl.md +0 -52
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/SKILL.tpl.md +0 -102
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/examples/auth-failure-handling.mjs +0 -81
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/examples/chained-workflow.mjs +0 -126
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/examples/simple-fetch.mjs +0 -92
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/references/architecture.md +0 -61
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/references/auth-and-sessions.md +0 -65
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/references/ctx-api.md +0 -96
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/references/installation.md +0 -104
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/references/script-conventions.md +0 -243
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/chrome-state.mjs +0 -148
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/debug.mjs +0 -383
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/debug.spec.mjs +0 -267
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/eslint.config.mjs +0 -56
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/harness.mjs +0 -169
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/keyring.mjs +0 -59
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/logger.mjs +0 -25
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/params.mjs +0 -140
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/run.mjs +0 -140
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/settings.tpl.mjs +0 -1
- package/shared-prompts/skills/automated-browser-tasks/about-automated-browser-tasks/scripts/utils.mjs +0 -185
- package/shared-prompts/skills/automated-browser-tasks/create-automated-browser-task/SKILL.tpl.md +0 -52
- package/shared-prompts/skills/automated-browser-tasks/running-automated-browser-tasks/SKILL.tpl.md +0 -59
- package/shared-prompts/skills/automated-browser-tasks/update-automated-browser-task/SKILL.tpl.md +0 -47
- package/shared-prompts/skills/control-flow/approve/SKILL.tpl.md +0 -26
- package/shared-prompts/skills/control-flow/opine/SKILL.tpl.md +0 -58
- package/shared-prompts/skills/control-flow/repeat/SKILL.tpl.md +0 -27
- package/shared-prompts/skills/control-flow/research/SKILL.tpl.md +0 -34
- package/shared-prompts/skills/sous-skills/about-sous/SKILL.tpl.md +0 -51
- package/shared-prompts/skills/task-files/about-task-files/SKILL.tpl.md +0 -122
- package/shared-prompts/skills/task-files/continue-task-in-new-branch/SKILL.tpl.md +0 -80
- package/shared-prompts/skills/task-files/go/SKILL.tpl.md +0 -14
- package/shared-prompts/skills/task-files/resume-task/SKILL.tpl.md +0 -13
- package/shared-prompts/skills/task-files/start-task/SKILL.tpl.md +0 -93
- package/shared-prompts/skills/task-files/update/SKILL.tpl.md +0 -14
- package/shared-prompts/skills/task-files/update-task-file/SKILL.tpl.md +0 -13
- /package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-agent-skills/references/substitutions.md +0 -0
- /package/{shared-prompts/skills/sous-skills → recipes/core/sous-skills/skills}/about-liquid-templates/references/liquid-filters.md +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The user-level sous directory: where machine-wide, project-independent state
|
|
3
|
+
* lives. Today that is the recipe store, globally linked checkouts and the
|
|
4
|
+
* machine-wide links map; the user-level config LAYER is a separate effort and
|
|
5
|
+
* is deliberately NOT read from here.
|
|
6
|
+
*
|
|
7
|
+
* The location is `~/.sous`, overridable with the `SOUS_HOME` environment
|
|
8
|
+
* variable.
|
|
9
|
+
*
|
|
10
|
+
* IMPORTANT: `SOUS_HOME` is file-settable. Unlike `SOUS_CONFIG`, `SOUS_DIR` and
|
|
11
|
+
* `SOUS_CONFD`, which decide which project is active and therefore must come
|
|
12
|
+
* from the real environment only, `SOUS_HOME` may be set in `.sous/.env.local`
|
|
13
|
+
* or `.sous/.env`. Every function here reads `process.env` at CALL time for
|
|
14
|
+
* exactly that reason; never capture the value at import time, because the env
|
|
15
|
+
* files are loaded after this module is first imported (see `loadEnvFiles` in
|
|
16
|
+
* `base-command.ts`).
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import os from "node:os";
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
|
|
22
|
+
/** The directory name used under the user's home directory. */
|
|
23
|
+
export const SOUS_HOME_DIR_NAME = ".sous";
|
|
24
|
+
|
|
25
|
+
/** The environment variable that overrides the user-level sous directory. */
|
|
26
|
+
export const SOUS_HOME_ENV_VAR = "SOUS_HOME";
|
|
27
|
+
|
|
28
|
+
/** Subdirectory of the user-level directory holding the recipe store. */
|
|
29
|
+
export const STORE_DIR_NAME = "cache";
|
|
30
|
+
|
|
31
|
+
/** Subdirectory of the user-level directory holding globally linked checkouts. */
|
|
32
|
+
export const GLOBAL_REPOS_DIR_NAME = "repos";
|
|
33
|
+
|
|
34
|
+
/** File name of the machine-wide links map. */
|
|
35
|
+
export const GLOBAL_LINKS_FILENAME = "sous.links.json";
|
|
36
|
+
|
|
37
|
+
/** A read-only view of an environment, so callers can pass a test fixture. */
|
|
38
|
+
export type EnvLike = Record<string, string | undefined>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Expands a leading `~` in a path, so `SOUS_HOME=~/sous-home` behaves the way a
|
|
42
|
+
* user typing it into an env file expects. A bare `~` and `~/...` expand; a
|
|
43
|
+
* `~user/...` form does not (sous has no way to resolve another account's home
|
|
44
|
+
* directory portably) and is left alone.
|
|
45
|
+
*
|
|
46
|
+
* @param value - The raw path, as written by the user.
|
|
47
|
+
*/
|
|
48
|
+
function expandHome(value: string): string {
|
|
49
|
+
if (value === "~") return os.homedir();
|
|
50
|
+
if (value.startsWith("~/") || value.startsWith("~\\")) {
|
|
51
|
+
return path.join(os.homedir(), value.slice(2));
|
|
52
|
+
}
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Resolves the user-level sous directory: `$SOUS_HOME` when it is set to a
|
|
58
|
+
* non-blank value, otherwise `<home>/.sous`. The result is normalized but is
|
|
59
|
+
* NOT created; each consumer creates the subdirectory it needs.
|
|
60
|
+
*
|
|
61
|
+
* A blank or whitespace-only `SOUS_HOME` is treated as unset rather than as the
|
|
62
|
+
* current directory, matching how `base-command.ts` treats the other `SOUS_*`
|
|
63
|
+
* variables.
|
|
64
|
+
*
|
|
65
|
+
* @param env - The environment to read; defaults to the live `process.env`.
|
|
66
|
+
*/
|
|
67
|
+
export function resolveSousHome(env: EnvLike = process.env): string {
|
|
68
|
+
const raw = env[SOUS_HOME_ENV_VAR];
|
|
69
|
+
if (typeof raw === "string" && raw.trim().length > 0) {
|
|
70
|
+
return path.normalize(path.resolve(expandHome(raw.trim())));
|
|
71
|
+
}
|
|
72
|
+
return path.join(os.homedir(), SOUS_HOME_DIR_NAME);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Resolves the root of the machine-wide recipe store, `$SOUS_HOME/cache`.
|
|
77
|
+
*
|
|
78
|
+
* @param env - The environment to read; defaults to the live `process.env`.
|
|
79
|
+
*/
|
|
80
|
+
export function resolveStoreRoot(env: EnvLike = process.env): string {
|
|
81
|
+
return path.join(resolveSousHome(env), STORE_DIR_NAME);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the directory holding globally linked checkouts,
|
|
86
|
+
* `$SOUS_HOME/repos`. A `sous repo link --global` clones into
|
|
87
|
+
* `<this dir>/<owner>/<repo>`.
|
|
88
|
+
*
|
|
89
|
+
* @param env - The environment to read; defaults to the live `process.env`.
|
|
90
|
+
*/
|
|
91
|
+
export function resolveGlobalReposDir(env: EnvLike = process.env): string {
|
|
92
|
+
return path.join(resolveSousHome(env), GLOBAL_REPOS_DIR_NAME);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Resolves the machine-wide links map, `$SOUS_HOME/sous.links.json`. A
|
|
97
|
+
* project's own `.sous/sous.links.json` is read alongside it and wins on
|
|
98
|
+
* conflict.
|
|
99
|
+
*
|
|
100
|
+
* @param env - The environment to read; defaults to the live `process.env`.
|
|
101
|
+
*/
|
|
102
|
+
export function resolveGlobalLinksPath(env: EnvLike = process.env): string {
|
|
103
|
+
return path.join(resolveSousHome(env), GLOBAL_LINKS_FILENAME);
|
|
104
|
+
}
|
package/src/lib/state.ts
CHANGED
|
@@ -31,39 +31,56 @@ export type StateFile = {
|
|
|
31
31
|
files: StateFileEntry[];
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
// --- Protected paths -----------------------------------------------------------------------------
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* True when a path is one of the protected roots, or sits underneath one.
|
|
38
|
+
*
|
|
39
|
+
* Both sides are normalized and resolved first, so a state file written with a
|
|
40
|
+
* different spelling of the same directory is still recognised.
|
|
41
|
+
*
|
|
42
|
+
* isProtectedPath("/home/me/.sous/cache/r/n/x/1.0.0/a.md", ["/home/me/.sous/cache"]);
|
|
43
|
+
* // -> true
|
|
44
|
+
*
|
|
45
|
+
* @param target - The path something is about to delete.
|
|
46
|
+
* @param protectedRoots - The directories that must never be reached into.
|
|
47
|
+
*/
|
|
48
|
+
export function isProtectedPath(target: string, protectedRoots: string[]): boolean {
|
|
49
|
+
if (protectedRoots.length === 0) return false;
|
|
50
|
+
const candidate = path.resolve(target);
|
|
51
|
+
return protectedRoots.some((root) => {
|
|
52
|
+
const resolved = path.resolve(root);
|
|
53
|
+
return candidate === resolved || candidate.startsWith(resolved + path.sep);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
34
57
|
// --- StateService --------------------------------------------------------------------------------
|
|
35
58
|
|
|
36
59
|
/**
|
|
37
60
|
* Manages reading and writing the project state file.
|
|
38
61
|
* The state file tracks all files and directories Sous has written,
|
|
39
|
-
* enabling
|
|
62
|
+
* enabling sous prune and sous clear to clean up precisely.
|
|
40
63
|
*/
|
|
41
64
|
export class StateService {
|
|
42
65
|
/**
|
|
43
|
-
* Derives the state file path for a
|
|
66
|
+
* Derives the state file path for a config.
|
|
44
67
|
*
|
|
45
68
|
* Precedence:
|
|
46
|
-
* 1. A `stateFilePath` variable in the
|
|
47
|
-
* 2. `<sousDir>/sous.state.json
|
|
48
|
-
*
|
|
49
|
-
* projects (they must not share one state file).
|
|
50
|
-
* 3. `<cwd>/<key>.sous.state.json` as a last resort.
|
|
69
|
+
* 1. A `stateFilePath` variable in the settings scope (explicit override).
|
|
70
|
+
* 2. `<sousDir>/sous.state.json`.
|
|
71
|
+
* 3. `<cwd>/sous.state.json` as a last resort.
|
|
51
72
|
*
|
|
52
|
-
* @param
|
|
53
|
-
* @param projectVars - The resolved PROJECT-scope variables. `sousDir` is
|
|
73
|
+
* @param vars - The resolved settings-scope variables. `sousDir` is
|
|
54
74
|
* auto-injected by buildAutoVars when a config has been discovered.
|
|
55
|
-
* @param projectCount - How many projects the active config defines. Defaults
|
|
56
|
-
* to 1 (the expected case: one `.sous/` per project).
|
|
57
75
|
*/
|
|
58
|
-
getFilePath(
|
|
59
|
-
if (
|
|
60
|
-
return
|
|
76
|
+
getFilePath(vars?: VarScope): string {
|
|
77
|
+
if (vars?.stateFilePath) {
|
|
78
|
+
return vars.stateFilePath;
|
|
61
79
|
}
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
return path.join(projectVars.sousDir, fileName);
|
|
80
|
+
if (vars?.sousDir) {
|
|
81
|
+
return path.join(vars.sousDir, "sous.state.json");
|
|
65
82
|
}
|
|
66
|
-
return path.join(process.cwd(),
|
|
83
|
+
return path.join(process.cwd(), "sous.state.json");
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
/** Loads the state file for a project. Returns null if it does not exist. */
|
|
@@ -77,15 +94,30 @@ export class StateService {
|
|
|
77
94
|
}
|
|
78
95
|
}
|
|
79
96
|
|
|
80
|
-
/**
|
|
81
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Deletes all tracked files and removes any now-empty tracked directories.
|
|
99
|
+
*
|
|
100
|
+
* @param files - The tracked output files to delete.
|
|
101
|
+
* @param dirs - The directories Sous created, removed when they end up empty.
|
|
102
|
+
* @param protectedRoots - Directories nothing here may reach into, whatever the
|
|
103
|
+
* state file says. Pass `protectedRepoPaths(sousDir)` so a stale entry can
|
|
104
|
+
* never make prune or clear delete a linked checkout or the shared recipe
|
|
105
|
+
* store.
|
|
106
|
+
*/
|
|
107
|
+
deleteTrackedFiles(
|
|
108
|
+
files: StateFileEntry[],
|
|
109
|
+
dirs: string[],
|
|
110
|
+
protectedRoots: string[] = []
|
|
111
|
+
): void {
|
|
82
112
|
for (const entry of files) {
|
|
113
|
+
if (isProtectedPath(entry.dest, protectedRoots)) continue;
|
|
83
114
|
if (fs.existsSync(entry.dest)) fs.rmSync(entry.dest);
|
|
84
115
|
}
|
|
85
116
|
const sortedDirs = [...dirs].sort(
|
|
86
117
|
(a, b) => b.split(path.sep).length - a.split(path.sep).length
|
|
87
118
|
);
|
|
88
119
|
for (const dir of sortedDirs) {
|
|
120
|
+
if (isProtectedPath(dir, protectedRoots)) continue;
|
|
89
121
|
if (fs.existsSync(dir) && fs.readdirSync(dir).length === 0) {
|
|
90
122
|
fs.rmdirSync(dir);
|
|
91
123
|
}
|