@okfit/profiles 0.11.0 → 0.13.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 +10 -31
- package/index.d.ts +5 -13
- package/package.json +8 -4
- package/tsdoc-metadata.json +1 -1
package/Derivation.js
CHANGED
|
@@ -2,9 +2,9 @@ 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
8
|
|
|
9
9
|
// src/Derivation.ts
|
|
10
10
|
/**
|
|
@@ -62,11 +62,7 @@ var HumanActorNotAllowedError = class extends Schema.TaggedError()("HumanActorNo
|
|
|
62
62
|
const HUMAN_PREFIX = "human:";
|
|
63
63
|
const FALLBACK_STALE_AFTER = Duration.days(90);
|
|
64
64
|
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. */
|
|
65
|
+
const digestFull = (text) => JsoncFingerprint.hashText(text);
|
|
70
66
|
const digest = (text) => Effect.map(digestFull(text), (hex) => hex.slice(0, 16));
|
|
71
67
|
const bodyDigest = (source) => digest(body(source));
|
|
72
68
|
const contentDigest = (raw, source) => digest(Canonical.contentInput(raw, source));
|
|
@@ -165,30 +161,12 @@ var Derivation = class Derivation {
|
|
|
165
161
|
*/
|
|
166
162
|
static contentDigest = contentDigest;
|
|
167
163
|
/**
|
|
168
|
-
* The worktree root holding `start`: the nearest ancestor directory (inclusive) with a `.git` entry, a
|
|
169
|
-
* directory in a main checkout and a file in a linked worktree or submodule; `undefined` when none has one.
|
|
170
|
-
* Asked of the filesystem rather than of `git rev-parse --show-toplevel` because a pre-commit hook in a
|
|
171
|
-
* linked worktree exports `GIT_DIR` without `GIT_WORK_TREE`, and git then takes each call's cwd as the
|
|
172
|
-
* worktree, naming whatever directory it was asked from as the top level (okfit #315). Not
|
|
173
|
-
* symlink-resolved; callers `realPath` it as they would `Git.repoRoot`.
|
|
174
|
-
*/
|
|
175
|
-
static worktreeRoot = Effect.fn("Derivation.worktreeRoot")(function* (start) {
|
|
176
|
-
const fs = yield* FileSystem.FileSystem;
|
|
177
|
-
const path = yield* Path.Path;
|
|
178
|
-
let dir = path.resolve(start);
|
|
179
|
-
for (;;) {
|
|
180
|
-
if (yield* fs.exists(path.join(dir, ".git")).pipe(Effect.orElseSucceed(() => false))) return dir;
|
|
181
|
-
const parent = path.dirname(dir);
|
|
182
|
-
if (parent === dir) return void 0;
|
|
183
|
-
dir = parent;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
/**
|
|
187
164
|
* Spec 5.4 rule 2 as P-2 (DERIVE option C). Steps:
|
|
188
|
-
* 1. `root =
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
165
|
+
* 1. `root = Git.repoRoot(dirname(file), { ignoreRepositoryEnv: true })`: the option drops the
|
|
166
|
+
* repository-pointing variables (`GIT_DIR` and kin), so a linked worktree's hook environment cannot shrink
|
|
167
|
+
* the root to the file's directory (okfit #315). On `NotARepositoryError` it retries with that
|
|
168
|
+
* environment honoured, so a repository defined only by `GIT_DIR`/`GIT_WORK_TREE` still resolves; a file
|
|
169
|
+
* outside any repository surfaces `NotARepositoryError`. Submodules and worktrees work because both are asked from the file's directory (P-39).
|
|
192
170
|
* 2. `realPath` both (rev-parse is symlink-resolved), then the repo-relative posix path via `Path` (P-39).
|
|
193
171
|
* 3. `worktree = body(readFileString(file))`.
|
|
194
172
|
* 4. `Git.show(realRoot, "HEAD", rel)`: `UnknownRefError` is `uncommitted { unborn }` (P-11), `Option.none`
|
|
@@ -207,7 +185,8 @@ var Derivation = class Derivation {
|
|
|
207
185
|
const history = yield* GitHistory;
|
|
208
186
|
const fs = yield* FileSystem.FileSystem;
|
|
209
187
|
const path = yield* Path.Path;
|
|
210
|
-
const
|
|
188
|
+
const dir = path.dirname(options.file);
|
|
189
|
+
const root = yield* git.repoRoot(dir, { ignoreRepositoryEnv: true }).pipe(Effect.catchTag("NotARepositoryError", () => git.repoRoot(dir)));
|
|
211
190
|
const realRoot = yield* fs.realPath(root);
|
|
212
191
|
const realFile = yield* fs.realPath(options.file);
|
|
213
192
|
const rel = path.relative(realRoot, realFile).split(path.sep).join("/");
|
package/index.d.ts
CHANGED
|
@@ -306,21 +306,13 @@ 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>;
|
|
318
309
|
/**
|
|
319
310
|
* Spec 5.4 rule 2 as P-2 (DERIVE option C). Steps:
|
|
320
|
-
* 1. `root =
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
311
|
+
* 1. `root = Git.repoRoot(dirname(file), { ignoreRepositoryEnv: true })`: the option drops the
|
|
312
|
+
* repository-pointing variables (`GIT_DIR` and kin), so a linked worktree's hook environment cannot shrink
|
|
313
|
+
* the root to the file's directory (okfit #315). On `NotARepositoryError` it retries with that
|
|
314
|
+
* environment honoured, so a repository defined only by `GIT_DIR`/`GIT_WORK_TREE` still resolves; a file
|
|
315
|
+
* outside any repository surfaces `NotARepositoryError`. Submodules and worktrees work because both are asked from the file's directory (P-39).
|
|
324
316
|
* 2. `realPath` both (rev-parse is symlink-resolved), then the repo-relative posix path via `Path` (P-39).
|
|
325
317
|
* 3. `worktree = body(readFileString(file))`.
|
|
326
318
|
* 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.13.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,13 @@
|
|
|
35
35
|
"./package.json": "./package.json"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@effected/git": "^0.
|
|
39
|
-
"@effected/
|
|
40
|
-
"@
|
|
38
|
+
"@effected/git": "^0.27.0",
|
|
39
|
+
"@effected/glob": "^0.16.0",
|
|
40
|
+
"@effected/jsonc": "^0.21.0",
|
|
41
|
+
"@effected/markdown": "^0.24.0",
|
|
42
|
+
"@effected/source": "^0.1.0",
|
|
43
|
+
"@effected/walker": "^0.22.0",
|
|
44
|
+
"@okfit/core": "^0.11.8",
|
|
41
45
|
"effect": "^4.0.0"
|
|
42
46
|
},
|
|
43
47
|
"engines": {
|