@sous-io/sous 0.2.37 → 1.0.2
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 +14 -256
- package/dist/bin.js +11 -0
- package/dist/sous.js +1094 -0
- package/docs/markdown/README.md +5 -4
- package/docs/markdown/_sidebar.md +21 -1
- package/docs/markdown/commands.md +294 -431
- package/docs/markdown/config-discovery.md +25 -14
- package/docs/markdown/config-inspection.md +53 -31
- package/docs/markdown/config-layers.md +168 -66
- package/docs/markdown/config-variables.md +44 -11
- package/docs/markdown/configuration.md +104 -17
- package/docs/markdown/design-principles.md +4 -1
- package/docs/markdown/repositories-authoring.md +30 -0
- package/docs/markdown/repositories-consuming.md +72 -14
- package/docs/markdown/repositories-file-formats.md +31 -13
- package/docs/markdown/repositories-providers.md +48 -57
- package/docs/markdown/repositories-quickstart.md +3 -2
- package/docs/markdown/repositories-troubleshooting.md +27 -1
- package/docs/markdown/repositories-variables.md +6 -1
- package/docs/markdown/repositories.md +18 -8
- package/package.json +48 -107
- package/recipes/core/sous-skills/skills/about-liquid-templates/SKILL.tpl.md +4 -6
- package/recipes/core/sous-skills/skills/about-liquid-templates/references/liquid-filters.tpl.md +2 -0
- package/recipes/core/sous-skills/skills/about-sous/SKILL.tpl.md +10 -9
- package/recipes/core/sous-skills/skills/about-sous-configuration/SKILL.tpl.md +35 -14
- package/recipes/core/sous-skills/skills/about-sous-recipes/SKILL.tpl.md +51 -20
- package/recipes/core/sous-skills/sous.recipe.yaml +1 -1
- package/sous.config.schema.json +351 -132
- package/bin/run.js +0 -51
- package/src/base-command.ts +0 -457
- package/src/commands/build.ts +0 -181
- package/src/commands/clear.ts +0 -79
- package/src/commands/compile.ts +0 -155
- package/src/commands/config/get.ts +0 -110
- package/src/commands/config/show.ts +0 -32
- package/src/commands/config/validate.ts +0 -53
- package/src/commands/help.ts +0 -46
- package/src/commands/init.ts +0 -289
- package/src/commands/launch.ts +0 -139
- package/src/commands/lock/rebuild.ts +0 -239
- package/src/commands/lock/show.ts +0 -115
- package/src/commands/namespace/list.ts +0 -138
- package/src/commands/namespace/show.ts +0 -130
- package/src/commands/prune.ts +0 -43
- package/src/commands/recipe/list.ts +0 -112
- package/src/commands/recipe/show.ts +0 -439
- package/src/commands/repo/add.ts +0 -145
- package/src/commands/repo/contribute.ts +0 -604
- package/src/commands/repo/gc.ts +0 -173
- package/src/commands/repo/init.ts +0 -136
- package/src/commands/repo/link.ts +0 -899
- package/src/commands/repo/list.ts +0 -236
- package/src/commands/repo/release.ts +0 -685
- package/src/commands/repo/remove.ts +0 -194
- package/src/commands/repo/search.ts +0 -243
- package/src/commands/repo/submit.ts +0 -341
- package/src/commands/repo/unlink.ts +0 -461
- package/src/commands/subscription/add.ts +0 -286
- package/src/commands/subscription/list.ts +0 -208
- package/src/commands/subscription/remove.ts +0 -182
- package/src/commands/subscription/update.ts +0 -216
- package/src/commands/update.ts +0 -178
- package/src/commands/vars/ask.ts +0 -417
- package/src/commands/vars/index.ts +0 -79
- package/src/commands/vars/list.ts +0 -67
- package/src/commands/vars/show.ts +0 -77
- package/src/config-command.ts +0 -30
- package/src/lib/build-preparation.ts +0 -128
- package/src/lib/build-service.ts +0 -580
- package/src/lib/config-discovery.ts +0 -378
- package/src/lib/config-inspect.ts +0 -145
- package/src/lib/config-kernel.mjs +0 -379
- package/src/lib/config-schema.ts +0 -401
- package/src/lib/env-file.ts +0 -328
- package/src/lib/env-local.ts +0 -212
- package/src/lib/errors.ts +0 -32
- package/src/lib/glob-pattern.ts +0 -24
- package/src/lib/include-resolver.ts +0 -523
- package/src/lib/interactive.ts +0 -165
- package/src/lib/markdown-compiler.ts +0 -947
- package/src/lib/package-info.ts +0 -25
- package/src/lib/pid-service.ts +0 -99
- package/src/lib/project-install.d.mts +0 -44
- package/src/lib/project-install.mjs +0 -234
- package/src/lib/project-scaffold/index.ts +0 -332
- package/src/lib/project-scaffold/templates.ts +0 -240
- package/src/lib/repos/catalog-display.ts +0 -215
- package/src/lib/repos/catalog-inputs.ts +0 -288
- package/src/lib/repos/catalog.ts +0 -842
- package/src/lib/repos/contribute.ts +0 -452
- package/src/lib/repos/core-recipe.ts +0 -105
- package/src/lib/repos/declarations.ts +0 -187
- package/src/lib/repos/defaults.ts +0 -175
- package/src/lib/repos/formats/common.ts +0 -440
- package/src/lib/repos/formats/index-file.ts +0 -253
- package/src/lib/repos/formats/links-map.ts +0 -98
- package/src/lib/repos/formats/lockfile.ts +0 -169
- package/src/lib/repos/formats/patterns.ts +0 -57
- package/src/lib/repos/formats/recipe-manifest.ts +0 -205
- package/src/lib/repos/formats/repo-manifest.ts +0 -97
- package/src/lib/repos/formats/store-entry.ts +0 -84
- package/src/lib/repos/formats/variable-definition.ts +0 -268
- package/src/lib/repos/freshness.ts +0 -264
- package/src/lib/repos/git-clone.ts +0 -850
- package/src/lib/repos/identity.ts +0 -89
- package/src/lib/repos/index.ts +0 -57
- package/src/lib/repos/links.ts +0 -356
- package/src/lib/repos/load-manifest.ts +0 -237
- package/src/lib/repos/lock-service.ts +0 -454
- package/src/lib/repos/locked-namespace-resolver.ts +0 -232
- package/src/lib/repos/locked-recipe-lookup.ts +0 -123
- package/src/lib/repos/locked-recipes.ts +0 -254
- package/src/lib/repos/managed-layer.ts +0 -422
- package/src/lib/repos/memories-hash-name.ts +0 -33
- package/src/lib/repos/namespace-resolver.ts +0 -527
- package/src/lib/repos/providers/base.ts +0 -268
- package/src/lib/repos/providers/git.ts +0 -245
- package/src/lib/repos/providers/github.ts +0 -589
- package/src/lib/repos/providers/gitlab.ts +0 -332
- package/src/lib/repos/providers/http.ts +0 -128
- package/src/lib/repos/providers/index-cache.ts +0 -421
- package/src/lib/repos/providers/index.ts +0 -106
- package/src/lib/repos/providers/local.ts +0 -410
- package/src/lib/repos/providers/provider.ts +0 -615
- package/src/lib/repos/recipe-config-layers.ts +0 -316
- package/src/lib/repos/recipe-key-matcher.ts +0 -62
- package/src/lib/repos/recipe-memories.ts +0 -178
- package/src/lib/repos/recipe-targets.ts +0 -236
- package/src/lib/repos/ref-search.ts +0 -46
- package/src/lib/repos/release/bump.ts +0 -161
- package/src/lib/repos/release/changelog.ts +0 -461
- package/src/lib/repos/release/git-state.ts +0 -460
- package/src/lib/repos/release/index-builder.ts +0 -1108
- package/src/lib/repos/release/index.ts +0 -19
- package/src/lib/repos/release/plan.ts +0 -521
- package/src/lib/repos/release/settle.ts +0 -154
- package/src/lib/repos/release/submissions.ts +0 -214
- package/src/lib/repos/release/submit-checkout.ts +0 -290
- package/src/lib/repos/release/submit-questions.ts +0 -153
- package/src/lib/repos/release/submit-service.ts +0 -898
- package/src/lib/repos/release/tags.ts +0 -239
- package/src/lib/repos/release/validate.ts +0 -463
- package/src/lib/repos/resolver.ts +0 -1028
- package/src/lib/repos/scaffold/index.ts +0 -245
- package/src/lib/repos/scaffold/templates.ts +0 -517
- package/src/lib/repos/seed.ts +0 -473
- package/src/lib/repos/store/contract.ts +0 -64
- package/src/lib/repos/store/hash.ts +0 -191
- package/src/lib/repos/store/recipe-store.ts +0 -599
- package/src/lib/repos/store/settings.ts +0 -58
- package/src/lib/repos/subscription-service.ts +0 -3859
- package/src/lib/repos/trust.ts +0 -447
- package/src/lib/repos/update-plan.ts +0 -235
- package/src/lib/self-update/index.ts +0 -14
- package/src/lib/self-update/installs.ts +0 -413
- package/src/lib/self-update/managers.ts +0 -126
- package/src/lib/self-update/plan.ts +0 -315
- package/src/lib/self-update/registry.ts +0 -99
- package/src/lib/self-update/run.ts +0 -506
- package/src/lib/self-update/versions.ts +0 -243
- package/src/lib/settings.ts +0 -1107
- package/src/lib/sous-home.ts +0 -104
- package/src/lib/state.ts +0 -167
- package/src/lib/vars/answers.ts +0 -192
- package/src/lib/vars/ask.ts +0 -1152
- package/src/lib/vars/definition-source.ts +0 -261
- package/src/lib/vars/display.ts +0 -231
- package/src/lib/vars/index.ts +0 -20
- package/src/lib/vars/ladder.ts +0 -282
- package/src/lib/vars/mappings.ts +0 -260
- package/src/lib/vars/names.ts +0 -94
- package/src/lib/vars/preanswers.ts +0 -395
- package/src/lib/vars/question-plan.ts +0 -241
- package/src/lib/vars/report.ts +0 -228
- package/src/lib/vars/safe-regex.ts +0 -235
- package/src/lib/vars/secrets.ts +0 -131
- package/src/lib/vars/validate.ts +0 -312
- package/src/lib/version-report.ts +0 -90
- package/src/lib/watch-loop.ts +0 -148
- package/src/lib/watch-service.ts +0 -116
- package/src/services/ref-resolver/container.ts +0 -107
- package/src/services/ref-resolver/dependency.ts +0 -60
- package/src/services/ref-resolver/format.ts +0 -197
- package/src/services/ref-resolver/glob.ts +0 -115
- package/src/services/ref-resolver/hash-names.ts +0 -155
- package/src/services/ref-resolver/index.ts +0 -55
- package/src/services/ref-resolver/injectable.ts +0 -36
- package/src/services/ref-resolver/location.ts +0 -62
- package/src/services/ref-resolver/lookups/cached-index-lookup.ts +0 -53
- package/src/services/ref-resolver/lookups/catalog-lookup.ts +0 -23
- package/src/services/ref-resolver/lookups/catalog-matcher.ts +0 -261
- package/src/services/ref-resolver/lookups/chained-lookup.ts +0 -27
- package/src/services/ref-resolver/lookups/env-var-lookup.ts +0 -65
- package/src/services/ref-resolver/lookups/fetched-index-lookup.ts +0 -150
- package/src/services/ref-resolver/lookups/recorded-dependency-lookup.ts +0 -62
- package/src/services/ref-resolver/lookups/ref-lookup.ts +0 -54
- package/src/services/ref-resolver/lookups/variable-lookup.ts +0 -123
- package/src/services/ref-resolver/named-refs.ts +0 -144
- package/src/services/ref-resolver/parser/env-var-splitter.ts +0 -27
- package/src/services/ref-resolver/parser/location-splitter.ts +0 -239
- package/src/services/ref-resolver/parser/name-path-splitter.ts +0 -200
- package/src/services/ref-resolver/parser/partial-ref.ts +0 -84
- package/src/services/ref-resolver/parser/query-splitter.ts +0 -61
- package/src/services/ref-resolver/parser/range-splitter.ts +0 -52
- package/src/services/ref-resolver/parser/ref-parser.ts +0 -115
- package/src/services/ref-resolver/parser/repo-qualifier-splitter.ts +0 -51
- package/src/services/ref-resolver/parts.ts +0 -115
- package/src/services/ref-resolver/pruners/command-line-pruner.ts +0 -47
- package/src/services/ref-resolver/pruners/include-pruner.ts +0 -66
- package/src/services/ref-resolver/pruners/manifest-pruner.ts +0 -130
- package/src/services/ref-resolver/pruners/ref-pruner.ts +0 -135
- package/src/services/ref-resolver/pruners/rule-helpers.ts +0 -44
- package/src/services/ref-resolver/pruners/stored-key-pruner.ts +0 -136
- package/src/services/ref-resolver/ref-helpers.ts +0 -62
- package/src/services/ref-resolver/ref-picker-service.ts +0 -204
- package/src/services/ref-resolver/ref-report.ts +0 -84
- package/src/services/ref-resolver/ref-resolve-arguments.ts +0 -47
- package/src/services/ref-resolver/ref-resolve-result.ts +0 -36
- package/src/services/ref-resolver/ref-resolver-service.ts +0 -323
- package/src/services/ref-resolver/source.ts +0 -48
- package/src/services/ref-resolver/tokens.ts +0 -25
- package/src/services/ref-resolver/types.ts +0 -155
- package/src/templating/filters/bullet-list.ts +0 -9
- package/src/templating/filters/index.ts +0 -8
- package/src/templating/init-liquid-engine.ts +0 -139
- package/src/templating/lib/glob-files.ts +0 -74
- package/src/templating/lib/import-export.ts +0 -32
- package/src/templating/lib/secret-scope.ts +0 -41
- package/src/templating/lib/tag-args.ts +0 -19
- package/src/templating/tags/exportScalarVarsJs.ts +0 -46
- package/src/templating/tags/getFiles.ts +0 -89
- package/src/templating/tags/index.ts +0 -14
- package/src/templating/tags/listFiles.ts +0 -54
- package/src/templating/tags/showVars.ts +0 -28
- package/src/utils/choice-prompt.ts +0 -143
- package/src/utils/command-errors.ts +0 -186
- package/src/utils/command-help.ts +0 -45
- package/src/utils/confirm-prompt.ts +0 -110
- package/src/utils/flags.ts +0 -177
- package/src/utils/formatting.ts +0 -849
- package/src/utils/prompts.ts +0 -53
- package/src/utils/sous-directory.ts +0 -245
- package/src/utils/table.ts +0 -603
- package/src/utils/value-prompt.ts +0 -119
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The canonical content hash of a recipe folder.
|
|
3
|
-
*
|
|
4
|
-
* Decision 12 of the Repositories design specifies "SHA-256 over a canonical
|
|
5
|
-
* tar of the recipe folder". This module computes exactly that idea WITHOUT a
|
|
6
|
-
* tar dependency: instead of serializing a real tar archive, it feeds the hash
|
|
7
|
-
* a canonical byte stream built from the same information a tar entry would
|
|
8
|
-
* carry that we actually care about (the path and the file's bytes), in a
|
|
9
|
-
* canonical order. Tar's variable header fields (mode, owner, group, mtime,
|
|
10
|
-
* block padding, format variant) are deliberately excluded, so the same tree
|
|
11
|
-
* hashes the same after a copy, a clone or an archive round-trip on a different
|
|
12
|
-
* machine.
|
|
13
|
-
*
|
|
14
|
-
* The stream, per file, is:
|
|
15
|
-
*
|
|
16
|
-
* <relative path (posix separators)> NUL <byte length> NUL <bytes> NUL
|
|
17
|
-
*
|
|
18
|
-
* Files are visited in bytewise order of their relative paths. `.git` and the
|
|
19
|
-
* store's own `.sous.entry.json` marker are skipped, so an entry's hash is
|
|
20
|
-
* independent of the marker that records it. Empty directories contribute
|
|
21
|
-
* nothing, since they carry no content a recipe can use.
|
|
22
|
-
*
|
|
23
|
-
* SYMLINKS ARE SKIPPED ENTIRELY, and so is anything under one. A hash has to
|
|
24
|
-
* mean the same thing on the publisher's machine and the consumer's, and a link
|
|
25
|
-
* points at bytes the repository does not own: following it made the hash depend
|
|
26
|
-
* on whatever happened to be at the target, so the same published version hashed
|
|
27
|
-
* differently on two machines and failed its own pin on every install. A recipe
|
|
28
|
-
* that needs a file ships the file; `sous repo release` refuses to publish a
|
|
29
|
-
* recipe folder containing a link.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import { createHash, type Hash } from "node:crypto";
|
|
33
|
-
import fsSync from "node:fs";
|
|
34
|
-
import fs from "node:fs/promises";
|
|
35
|
-
import path from "node:path";
|
|
36
|
-
import { STORE_ENTRY_FILENAME } from "../formats/common.js";
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* `git clone` options that check files out exactly as they were committed.
|
|
40
|
-
*
|
|
41
|
-
* A content hash is over raw bytes, and Git for Windows installs with
|
|
42
|
-
* `core.autocrlf=true` by default, which rewrites every text file to CRLF on
|
|
43
|
-
* checkout. A recipe published with LF then hashed differently on such a
|
|
44
|
-
* machine and failed its own pin. `--config` also writes these into the
|
|
45
|
-
* clone's own `.git/config`, so later checkouts in a linked working copy keep
|
|
46
|
-
* the same bytes.
|
|
47
|
-
*/
|
|
48
|
-
export const LF_CHECKOUT_OPTIONS = [
|
|
49
|
-
"--config",
|
|
50
|
-
"core.autocrlf=false",
|
|
51
|
-
"--config",
|
|
52
|
-
"core.eol=lf",
|
|
53
|
-
] as const;
|
|
54
|
-
|
|
55
|
-
/** Directory name never included in a content hash. */
|
|
56
|
-
const GIT_DIR_NAME = ".git";
|
|
57
|
-
|
|
58
|
-
/** The separator byte between the fields of one file's canonical record. */
|
|
59
|
-
const FIELD_SEPARATOR = Buffer.from([0]);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Collects every hashable file under `dir`, as paths relative to `dir` and
|
|
63
|
-
* always with posix separators, so a hash computed on Windows matches one
|
|
64
|
-
* computed on Linux.
|
|
65
|
-
*
|
|
66
|
-
* @param dir - The directory to walk.
|
|
67
|
-
* @param prefix - The relative path of `dir` within the tree being hashed.
|
|
68
|
-
*/
|
|
69
|
-
async function collectFiles(dir: string, prefix = ""): Promise<string[]> {
|
|
70
|
-
const entries = await fs.readdir(dir, { withFileTypes: true });
|
|
71
|
-
const found: string[] = [];
|
|
72
|
-
|
|
73
|
-
for (const entry of entries) {
|
|
74
|
-
if (entry.name === GIT_DIR_NAME) continue;
|
|
75
|
-
if (entry.name === STORE_ENTRY_FILENAME) continue;
|
|
76
|
-
|
|
77
|
-
// `withFileTypes` reports the entry itself, not what it points at, so a
|
|
78
|
-
// symlink is recognised here and skipped whole. Nothing stats through it,
|
|
79
|
-
// which is the point: a hash may only depend on bytes the repository owns.
|
|
80
|
-
if (entry.isSymbolicLink()) continue;
|
|
81
|
-
|
|
82
|
-
const relative = prefix.length > 0 ? `${prefix}/${entry.name}` : entry.name;
|
|
83
|
-
const absolute = path.join(dir, entry.name);
|
|
84
|
-
|
|
85
|
-
if (entry.isDirectory()) found.push(...(await collectFiles(absolute, relative)));
|
|
86
|
-
else if (entry.isFile()) found.push(relative);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return found;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/** Orders two relative paths bytewise, so the ordering never depends on a locale. */
|
|
93
|
-
function bytewiseCompare(a: string, b: string): number {
|
|
94
|
-
return a < b ? -1 : a > b ? 1 : 0;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Computes the canonical content hash of a directory tree, returned as
|
|
99
|
-
* `sha256-` followed by 64 lowercase hexadecimal characters (the shape
|
|
100
|
-
* `contentHashSchema` validates).
|
|
101
|
-
*
|
|
102
|
-
* @param dir - Absolute path to the directory to hash.
|
|
103
|
-
*/
|
|
104
|
-
export async function hashDirectory(dir: string): Promise<string> {
|
|
105
|
-
const root = path.resolve(dir);
|
|
106
|
-
const files = (await collectFiles(root)).sort(bytewiseCompare);
|
|
107
|
-
const hash = createHash("sha256");
|
|
108
|
-
|
|
109
|
-
for (const relative of files) {
|
|
110
|
-
updateWithFile(hash, relative, await fs.readFile(path.join(root, ...relative.split("/"))));
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return `sha256-${hash.digest("hex")}`;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* The same hash as `hashDirectory`, computed synchronously. It exists for the
|
|
118
|
-
* one place that needs a hash inside a synchronous read: folding the packaged
|
|
119
|
-
* core recipe into a cached index as the index is read.
|
|
120
|
-
*
|
|
121
|
-
* hashDirectorySync(dir) === (await hashDirectory(dir))
|
|
122
|
-
* // -> true, for any directory
|
|
123
|
-
*
|
|
124
|
-
* @param dir - Absolute path to the directory to hash.
|
|
125
|
-
*/
|
|
126
|
-
export function hashDirectorySync(dir: string): string {
|
|
127
|
-
const root = path.resolve(dir);
|
|
128
|
-
const files = collectFilesSync(root).sort(bytewiseCompare);
|
|
129
|
-
const hash = createHash("sha256");
|
|
130
|
-
|
|
131
|
-
for (const relative of files) {
|
|
132
|
-
updateWithFile(hash, relative, fsSync.readFileSync(path.join(root, ...relative.split("/"))));
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return `sha256-${hash.digest("hex")}`;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Collects every hashable file under `dir`, synchronously. The rules are exactly
|
|
140
|
-
* those of `collectFiles`; the two differ only in how they wait.
|
|
141
|
-
*
|
|
142
|
-
* @param dir - The directory to walk.
|
|
143
|
-
* @param prefix - The relative path of `dir` within the tree being hashed.
|
|
144
|
-
*/
|
|
145
|
-
function collectFilesSync(dir: string, prefix = ""): string[] {
|
|
146
|
-
const entries = fsSync.readdirSync(dir, { withFileTypes: true });
|
|
147
|
-
const found: string[] = [];
|
|
148
|
-
|
|
149
|
-
for (const entry of entries) {
|
|
150
|
-
if (entry.name === GIT_DIR_NAME) continue;
|
|
151
|
-
if (entry.name === STORE_ENTRY_FILENAME) continue;
|
|
152
|
-
if (entry.isSymbolicLink()) continue;
|
|
153
|
-
|
|
154
|
-
const relative = prefix.length > 0 ? `${prefix}/${entry.name}` : entry.name;
|
|
155
|
-
const absolute = path.join(dir, entry.name);
|
|
156
|
-
|
|
157
|
-
if (entry.isDirectory()) found.push(...collectFilesSync(absolute, relative));
|
|
158
|
-
else if (entry.isFile()) found.push(relative);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return found;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Feeds one file's canonical record into a hash: its path, its byte length and
|
|
166
|
-
* its bytes, each followed by the separator.
|
|
167
|
-
*
|
|
168
|
-
* @param hash - The hash being built.
|
|
169
|
-
* @param relative - The file's path relative to the tree root, posix separators.
|
|
170
|
-
* @param bytes - The file's contents.
|
|
171
|
-
*/
|
|
172
|
-
function updateWithFile(hash: Hash, relative: string, bytes: Buffer): void {
|
|
173
|
-
hash.update(Buffer.from(relative, "utf8"));
|
|
174
|
-
hash.update(FIELD_SEPARATOR);
|
|
175
|
-
hash.update(Buffer.from(String(bytes.byteLength), "utf8"));
|
|
176
|
-
hash.update(FIELD_SEPARATOR);
|
|
177
|
-
hash.update(bytes);
|
|
178
|
-
hash.update(FIELD_SEPARATOR);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Compares two content hashes. Both are canonical lowercase strings, so this is
|
|
183
|
-
* an exact comparison; it exists so callers read as intent rather than as
|
|
184
|
-
* string equality, and so a future multi-algorithm form has one place to land.
|
|
185
|
-
*
|
|
186
|
-
* @param a - The first hash.
|
|
187
|
-
* @param b - The second hash.
|
|
188
|
-
*/
|
|
189
|
-
export function hashesEqual(a: string, b: string): boolean {
|
|
190
|
-
return a === b;
|
|
191
|
-
}
|