@okfit/profiles 0.10.6 → 0.12.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/Derivation.js +24 -10
- package/index.d.ts +13 -2
- package/package.json +7 -4
- package/tsdoc-metadata.json +1 -1
package/Derivation.js
CHANGED
|
@@ -2,9 +2,10 @@ import { body } from "./internal/body.js";
|
|
|
2
2
|
import { Canonical } from "./Canonical.js";
|
|
3
3
|
import { GitHistory } from "./GitHistory.js";
|
|
4
4
|
import { Actor, OkfitConfig } from "@okfit/core";
|
|
5
|
-
import {
|
|
5
|
+
import { DateTime, Duration, Effect, FileSystem, Option, Path, Schema } from "effect";
|
|
6
6
|
import { Git } from "@effected/git";
|
|
7
|
-
import
|
|
7
|
+
import { JsoncFingerprint } from "@effected/jsonc";
|
|
8
|
+
import { Walker } from "@effected/walker";
|
|
8
9
|
|
|
9
10
|
// src/Derivation.ts
|
|
10
11
|
/**
|
|
@@ -62,11 +63,7 @@ var HumanActorNotAllowedError = class extends Schema.TaggedError()("HumanActorNo
|
|
|
62
63
|
const HUMAN_PREFIX = "human:";
|
|
63
64
|
const FALLBACK_STALE_AFTER = Duration.days(90);
|
|
64
65
|
const decodeActor = Schema.decodeSync(Actor);
|
|
65
|
-
const digestFull = (text) =>
|
|
66
|
-
const bytes = yield* (yield* Crypto.Crypto).digest("SHA-256", new TextEncoder().encode(text));
|
|
67
|
-
return Hex.encode(bytes);
|
|
68
|
-
});
|
|
69
|
-
/** 16-hex okfit digest (spec section 3): the first 64 bits of SHA-256. */
|
|
66
|
+
const digestFull = (text) => JsoncFingerprint.hashText(text);
|
|
70
67
|
const digest = (text) => Effect.map(digestFull(text), (hex) => hex.slice(0, 16));
|
|
71
68
|
const bodyDigest = (source) => digest(body(source));
|
|
72
69
|
const contentDigest = (raw, source) => digest(Canonical.contentInput(raw, source));
|
|
@@ -165,9 +162,26 @@ var Derivation = class Derivation {
|
|
|
165
162
|
*/
|
|
166
163
|
static contentDigest = contentDigest;
|
|
167
164
|
/**
|
|
165
|
+
* The worktree root holding `start`: the nearest ancestor directory (inclusive) with a `.git` entry, a
|
|
166
|
+
* directory in a main checkout and a file in a linked worktree or submodule; `undefined` when none has one.
|
|
167
|
+
* Asked of the filesystem rather than of `git rev-parse --show-toplevel` because a pre-commit hook in a
|
|
168
|
+
* linked worktree exports `GIT_DIR` without `GIT_WORK_TREE`, and git then takes each call's cwd as the
|
|
169
|
+
* worktree, naming whatever directory it was asked from as the top level (okfit #315). Not
|
|
170
|
+
* symlink-resolved; callers `realPath` it as they would `Git.repoRoot`.
|
|
171
|
+
*/
|
|
172
|
+
static worktreeRoot = Effect.fn("Derivation.worktreeRoot")(function* (start) {
|
|
173
|
+
const fs = yield* FileSystem.FileSystem;
|
|
174
|
+
const path = yield* Path.Path;
|
|
175
|
+
const dirs = yield* Walker.ascend(path.resolve(start));
|
|
176
|
+
const root = yield* Walker.findRoot(dirs, (dir) => fs.exists(path.join(dir, ".git")));
|
|
177
|
+
return Option.getOrUndefined(root);
|
|
178
|
+
});
|
|
179
|
+
/**
|
|
168
180
|
* Spec 5.4 rule 2 as P-2 (DERIVE option C). Steps:
|
|
169
|
-
* 1. `root = Git.repoRoot(dirname(file))`:
|
|
170
|
-
*
|
|
181
|
+
* 1. `root = worktreeRoot(dirname(file)) ?? Git.repoRoot(dirname(file))`: the filesystem walk first, so a
|
|
182
|
+
* linked worktree's hook environment (`GIT_DIR` exported) cannot shrink the root to the file's directory
|
|
183
|
+
* (okfit #315); git answers when no ancestor holds `.git`, and a file outside any repository surfaces
|
|
184
|
+
* `NotARepositoryError`. Submodules and worktrees work because both are asked from the file's directory (P-39).
|
|
171
185
|
* 2. `realPath` both (rev-parse is symlink-resolved), then the repo-relative posix path via `Path` (P-39).
|
|
172
186
|
* 3. `worktree = body(readFileString(file))`.
|
|
173
187
|
* 4. `Git.show(realRoot, "HEAD", rel)`: `UnknownRefError` is `uncommitted { unborn }` (P-11), `Option.none`
|
|
@@ -186,7 +200,7 @@ var Derivation = class Derivation {
|
|
|
186
200
|
const history = yield* GitHistory;
|
|
187
201
|
const fs = yield* FileSystem.FileSystem;
|
|
188
202
|
const path = yield* Path.Path;
|
|
189
|
-
const root = yield* git.repoRoot(path.dirname(options.file));
|
|
203
|
+
const root = (yield* Derivation.worktreeRoot(path.dirname(options.file))) ?? (yield* git.repoRoot(path.dirname(options.file)));
|
|
190
204
|
const realRoot = yield* fs.realPath(root);
|
|
191
205
|
const realFile = yield* fs.realPath(options.file);
|
|
192
206
|
const rel = path.relative(realRoot, realFile).split(path.sep).join("/");
|
package/index.d.ts
CHANGED
|
@@ -306,10 +306,21 @@ export declare class Derivation {
|
|
|
306
306
|
* plus the normalised body, insensitive to style, key order and CRLF.
|
|
307
307
|
*/
|
|
308
308
|
static readonly contentDigest: (raw: Readonly<Record<string, unknown>>, source: string) => Effect.Effect<Digest, PlatformError.PlatformError, Crypto.Crypto>;
|
|
309
|
+
/**
|
|
310
|
+
* The worktree root holding `start`: the nearest ancestor directory (inclusive) with a `.git` entry, a
|
|
311
|
+
* directory in a main checkout and a file in a linked worktree or submodule; `undefined` when none has one.
|
|
312
|
+
* Asked of the filesystem rather than of `git rev-parse --show-toplevel` because a pre-commit hook in a
|
|
313
|
+
* linked worktree exports `GIT_DIR` without `GIT_WORK_TREE`, and git then takes each call's cwd as the
|
|
314
|
+
* worktree, naming whatever directory it was asked from as the top level (okfit #315). Not
|
|
315
|
+
* symlink-resolved; callers `realPath` it as they would `Git.repoRoot`.
|
|
316
|
+
*/
|
|
317
|
+
static readonly worktreeRoot: (start: string) => Effect.Effect<string | undefined, never, FileSystem.FileSystem | Path.Path>;
|
|
309
318
|
/**
|
|
310
319
|
* Spec 5.4 rule 2 as P-2 (DERIVE option C). Steps:
|
|
311
|
-
* 1. `root = Git.repoRoot(dirname(file))`:
|
|
312
|
-
*
|
|
320
|
+
* 1. `root = worktreeRoot(dirname(file)) ?? Git.repoRoot(dirname(file))`: the filesystem walk first, so a
|
|
321
|
+
* linked worktree's hook environment (`GIT_DIR` exported) cannot shrink the root to the file's directory
|
|
322
|
+
* (okfit #315); git answers when no ancestor holds `.git`, and a file outside any repository surfaces
|
|
323
|
+
* `NotARepositoryError`. Submodules and worktrees work because both are asked from the file's directory (P-39).
|
|
313
324
|
* 2. `realPath` both (rev-parse is symlink-resolved), then the repo-relative posix path via `Path` (P-39).
|
|
314
325
|
* 3. `worktree = body(readFileString(file))`.
|
|
315
326
|
* 4. `Git.show(realRoot, "HEAD", rel)`: `UnknownRefError` is `uncommitted { unborn }` (P-11), `Option.none`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@okfit/profiles",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Named OKF configuration profiles for okfit, starting with the software-project profile.",
|
|
6
6
|
"keywords": [
|
|
@@ -35,9 +35,12 @@
|
|
|
35
35
|
"./package.json": "./package.json"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@effected/git": "^0.
|
|
39
|
-
"@effected/
|
|
40
|
-
"@
|
|
38
|
+
"@effected/git": "^0.26.0",
|
|
39
|
+
"@effected/glob": "^0.15.0",
|
|
40
|
+
"@effected/jsonc": "^0.20.0",
|
|
41
|
+
"@effected/markdown": "^0.23.0",
|
|
42
|
+
"@effected/walker": "^0.21.0",
|
|
43
|
+
"@okfit/core": "^0.11.7",
|
|
41
44
|
"effect": "^4.0.0"
|
|
42
45
|
},
|
|
43
46
|
"engines": {
|