@hyperframes/share 0.9.35 → 0.9.37
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/dist/projectSnapshot.d.mts +10 -5
- package/dist/sourceIgnore.d.mts +3 -2
- package/package.json +1 -1
- package/src/projectSnapshot.mjs +22 -9
- package/src/sourceIgnore.mjs +3 -2
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/** @param {string} html */
|
|
2
2
|
export function contentKey(html: string): string;
|
|
3
3
|
/** @typedef {Map<string, unknown>} Snapshot */
|
|
4
|
-
/** @
|
|
5
|
-
|
|
4
|
+
/** @typedef {{ lenientIgnore?: boolean }} IgnoreOptions */
|
|
5
|
+
/** @param {string} dir @param {{ byContent?: boolean, followSymlinks?: boolean } & IgnoreOptions} [options]
|
|
6
|
+
* @returns {Promise<Snapshot>} */
|
|
7
|
+
export function snapshotProject(dir: string, { byContent, followSymlinks, lenientIgnore }?: {
|
|
6
8
|
byContent?: boolean;
|
|
7
9
|
followSymlinks?: boolean;
|
|
8
|
-
}): Promise<Snapshot>;
|
|
10
|
+
} & IgnoreOptions): Promise<Snapshot>;
|
|
9
11
|
/** What an export's sidecar records of the project, from a snapshot already taken.
|
|
10
12
|
* @param {Snapshot} snapshot */
|
|
11
13
|
export function snapshotFingerprint(snapshot: Snapshot): string;
|
|
12
14
|
/** Just these project files, keyed as snapshotProject keys them (undefined: not a file the snapshot holds); null when
|
|
13
15
|
* one is a folder, which only a whole snapshot covers. @param {string} dir @param {Iterable<string>} files
|
|
14
|
-
* @returns {Promise<Map<string, unknown> | null>} */
|
|
15
|
-
export function snapshotFiles(dir: string, files: Iterable<string
|
|
16
|
+
* @param {IgnoreOptions} [options] @returns {Promise<Map<string, unknown> | null>} */
|
|
17
|
+
export function snapshotFiles(dir: string, files: Iterable<string>, { lenientIgnore }?: IgnoreOptions): Promise<Map<string, unknown> | null>;
|
|
16
18
|
/** @param {Snapshot} before @param {Snapshot} after */
|
|
17
19
|
export function diffChangedFiles(before: Snapshot, after: Snapshot): string[];
|
|
18
20
|
export const HF_ID_ATTRIBUTE: RegExp;
|
|
@@ -20,3 +22,6 @@ export function projectFingerprint(projectPath: string, options?: {
|
|
|
20
22
|
byContent?: boolean;
|
|
21
23
|
}): Promise<string>;
|
|
22
24
|
export type Snapshot = Map<string, unknown>;
|
|
25
|
+
export type IgnoreOptions = {
|
|
26
|
+
lenientIgnore?: boolean;
|
|
27
|
+
};
|
package/dist/sourceIgnore.d.mts
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
export function readSourceIgnore(root: string): Promise<(path: string) => boolean>;
|
|
4
4
|
/** The exclusions change detection applies. Change detection must keep working whatever the file holds: the CLI
|
|
5
5
|
* reads `.hyperframesignore` as gitignore syntax (`/renders/`, `**`, `!keep`), which this reader refuses. An
|
|
6
|
-
* unreadable file then excludes only scratch files, so a scan sees more files, never fewer.
|
|
7
|
-
*
|
|
6
|
+
* unreadable file then excludes only scratch files, so a scan sees more files, never fewer. Never use it to pick
|
|
7
|
+
* files to send: it drops the file's valid exclusions too. @param {string} root
|
|
8
|
+
* @returns {Promise<(path: string) => boolean>} */
|
|
8
9
|
export function readChangeIgnore(root: string): Promise<(path: string) => boolean>;
|
|
9
10
|
export class SourceIgnoreError extends Error {
|
|
10
11
|
code: string;
|
package/package.json
CHANGED
package/src/projectSnapshot.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
// A project's files as change detection sees them: every file the film can use (isOutsideFilm), keyed by mtime and
|
|
3
3
|
// size, except html, keyed by content without the data-hf-id stamps. A run's change set and the watcher both read it.
|
|
4
|
-
import { readChangeIgnore } from "./sourceIgnore.mjs";
|
|
4
|
+
import { readChangeIgnore, readSourceIgnore } from "./sourceIgnore.mjs";
|
|
5
5
|
import fs from "node:fs/promises";
|
|
6
6
|
import { constants } from "node:fs";
|
|
7
7
|
import path from "node:path";
|
|
@@ -57,11 +57,18 @@ async function entryKind(entry, full, followSymlinks) {
|
|
|
57
57
|
// What a run is judged against: each file's mtime and size, except html, whose key ignores the data-hf-id stamps an
|
|
58
58
|
// open or a save writes. Files the film cannot use are not part of the snapshot.
|
|
59
59
|
/** @typedef {Map<string, unknown>} Snapshot */
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
// A `.hyperframesignore` this package can't read makes the snapshot throw, so a caller that picks files to send never
|
|
61
|
+
// sends one the file meant to exclude. Change detection passes `lenientIgnore`: it then sees more files, never fewer.
|
|
62
|
+
/** @typedef {{ lenientIgnore?: boolean }} IgnoreOptions */
|
|
63
|
+
/** @param {string} dir @param {{ byContent?: boolean, followSymlinks?: boolean } & IgnoreOptions} [options]
|
|
64
|
+
* @returns {Promise<Snapshot>} */
|
|
65
|
+
export async function snapshotProject(
|
|
66
|
+
dir,
|
|
67
|
+
{ byContent = false, followSymlinks = false, lenientIgnore = false } = {},
|
|
68
|
+
) {
|
|
62
69
|
/** @type {Snapshot} */
|
|
63
70
|
const result = new Map();
|
|
64
|
-
const ignored = await
|
|
71
|
+
const ignored = await ignoreFor(dir, lenientIgnore);
|
|
65
72
|
/** @param {string} current @param {Set<string>} ancestors */
|
|
66
73
|
async function walk(current, ancestors) {
|
|
67
74
|
const real = await fs.realpath(current).catch(() => null);
|
|
@@ -98,11 +105,11 @@ export function snapshotFingerprint(snapshot) {
|
|
|
98
105
|
|
|
99
106
|
/** Just these project files, keyed as snapshotProject keys them (undefined: not a file the snapshot holds); null when
|
|
100
107
|
* one is a folder, which only a whole snapshot covers. @param {string} dir @param {Iterable<string>} files
|
|
101
|
-
* @returns {Promise<Map<string, unknown> | null>} */
|
|
102
|
-
export async function snapshotFiles(dir, files) {
|
|
108
|
+
* @param {IgnoreOptions} [options] @returns {Promise<Map<string, unknown> | null>} */
|
|
109
|
+
export async function snapshotFiles(dir, files, { lenientIgnore = false } = {}) {
|
|
103
110
|
/** @type {Map<string, unknown>} */
|
|
104
111
|
const result = new Map();
|
|
105
|
-
const ignored = await
|
|
112
|
+
const ignored = await ignoreFor(dir, lenientIgnore);
|
|
106
113
|
for (const file of files) {
|
|
107
114
|
const full = path.join(dir, file);
|
|
108
115
|
const stat = await fs.lstat(full).catch(() => null);
|
|
@@ -125,9 +132,15 @@ export function diffChangedFiles(before, after) {
|
|
|
125
132
|
return changed;
|
|
126
133
|
}
|
|
127
134
|
|
|
128
|
-
/**
|
|
135
|
+
/** Change detection only: a fingerprint names no files to send, so it reads the ignore file leniently.
|
|
136
|
+
* @param {string} projectPath @param {{ byContent?: boolean }} [options] */
|
|
129
137
|
export const projectFingerprint = async (projectPath, options) =>
|
|
130
|
-
snapshotFingerprint(
|
|
138
|
+
snapshotFingerprint(
|
|
139
|
+
await snapshotProject(projectPath, { ...options, followSymlinks: true, lenientIgnore: true }),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
/** @param {string} dir @param {boolean} lenient */
|
|
143
|
+
const ignoreFor = (dir, lenient) => (lenient ? readChangeIgnore(dir) : readSourceIgnore(dir));
|
|
131
144
|
|
|
132
145
|
/** @param {string} dir @param {string} full @param {(path: string) => boolean} ignored */
|
|
133
146
|
function excludedFromSnapshot(dir, full, ignored) {
|
package/src/sourceIgnore.mjs
CHANGED
|
@@ -65,8 +65,9 @@ export async function readSourceIgnore(root) {
|
|
|
65
65
|
|
|
66
66
|
/** The exclusions change detection applies. Change detection must keep working whatever the file holds: the CLI
|
|
67
67
|
* reads `.hyperframesignore` as gitignore syntax (`/renders/`, `**`, `!keep`), which this reader refuses. An
|
|
68
|
-
* unreadable file then excludes only scratch files, so a scan sees more files, never fewer.
|
|
69
|
-
*
|
|
68
|
+
* unreadable file then excludes only scratch files, so a scan sees more files, never fewer. Never use it to pick
|
|
69
|
+
* files to send: it drops the file's valid exclusions too. @param {string} root
|
|
70
|
+
* @returns {Promise<(path: string) => boolean>} */
|
|
70
71
|
export async function readChangeIgnore(root) {
|
|
71
72
|
return readSourceIgnore(root).catch(() => scratch);
|
|
72
73
|
}
|