@hyperframes/share 0.9.28-alpha.1 → 0.9.28-alpha.3
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/index.d.mts +1 -0
- package/dist/sourceIgnore.d.mts +3 -0
- package/package.json +1 -1
- package/src/index.mjs +2 -0
- package/src/sourceIgnore.mjs +39 -16
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ export { firstReviewAudience } from "./reviewAudience.mjs";
|
|
|
2
2
|
export { versionSentence } from "./reviewVersionSentences.mjs";
|
|
3
3
|
export { shareOpenCalls } from "./reviewOpenCalls.mjs";
|
|
4
4
|
export { bindShareHost } from "./host.mjs";
|
|
5
|
+
export { SourceIgnoreError } from "./sourceIgnore.mjs";
|
|
5
6
|
export type ShareHost = import("./hosts.js").ShareHost;
|
|
6
7
|
export type ReviewClient = import("./reviewClient.mjs").ReviewClient;
|
|
7
8
|
export type ReviewShare = import("./types/share.js").ReviewShare;
|
package/dist/sourceIgnore.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
/** Explicit, project-relative exclusions. This only removes files; it cannot override safety exclusions.
|
|
2
2
|
* @param {string} root @returns {Promise<(path: string) => boolean>} */
|
|
3
3
|
export function readSourceIgnore(root: string): Promise<(path: string) => boolean>;
|
|
4
|
+
export class SourceIgnoreError extends Error {
|
|
5
|
+
code: string;
|
|
6
|
+
}
|
package/package.json
CHANGED
package/src/index.mjs
CHANGED
package/src/sourceIgnore.mjs
CHANGED
|
@@ -3,12 +3,19 @@ import { constants } from "node:fs";
|
|
|
3
3
|
import { lstat, open } from "node:fs/promises";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
6
|
+
export class SourceIgnoreError extends Error {
|
|
7
|
+
code = "invalid_source_ignore";
|
|
8
|
+
}
|
|
9
|
+
const scratch = (/** @type {string} */ path) => /(?:^|\/)[^/]+\.(?:log|swp)$/.test(path);
|
|
10
|
+
|
|
6
11
|
/** Explicit, project-relative exclusions. This only removes files; it cannot override safety exclusions.
|
|
7
12
|
* @param {string} root @returns {Promise<(path: string) => boolean>} */
|
|
8
13
|
export async function readSourceIgnore(root) {
|
|
9
14
|
const file = join(root, ".hyperframesignore");
|
|
10
15
|
const invalid = () =>
|
|
11
|
-
new
|
|
16
|
+
new SourceIgnoreError(
|
|
17
|
+
".hyperframesignore must be a regular file inside the project, smaller than 64 KiB.",
|
|
18
|
+
);
|
|
12
19
|
const handle = await open(
|
|
13
20
|
file,
|
|
14
21
|
constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0),
|
|
@@ -22,7 +29,7 @@ export async function readSourceIgnore(root) {
|
|
|
22
29
|
if (named) throw invalid();
|
|
23
30
|
return null;
|
|
24
31
|
});
|
|
25
|
-
if (!handle) return
|
|
32
|
+
if (!handle) return scratch;
|
|
26
33
|
let text;
|
|
27
34
|
try {
|
|
28
35
|
// Validate the opened descriptor before reading. lstat additionally rejects links on
|
|
@@ -52,18 +59,34 @@ export async function readSourceIgnore(root) {
|
|
|
52
59
|
.split(/\r?\n/)
|
|
53
60
|
.map((line) => line.trim())
|
|
54
61
|
.filter((line) => line && !line.startsWith("#"));
|
|
55
|
-
const entries = paths.map(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
62
|
+
const entries = paths.map(ignorePattern);
|
|
63
|
+
return (path) => scratch(path) || entries.some((entry) => entry.test(path));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {string} entry */
|
|
67
|
+
function ignorePattern(entry) {
|
|
68
|
+
const path = entry.replace(/\/$/, "");
|
|
69
|
+
const invalid = () =>
|
|
70
|
+
new SourceIgnoreError(
|
|
71
|
+
".hyperframesignore accepts project-relative paths or patterns with one * wildcard. Negation, traversal, and excluding index.html are not supported.",
|
|
72
|
+
);
|
|
73
|
+
if (!validPatternPath(path)) throw invalid();
|
|
74
|
+
const escaped = path
|
|
75
|
+
.split("*")
|
|
76
|
+
.map((part) => part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
|
77
|
+
.join("[^/]*");
|
|
78
|
+
const prefix = path.includes("*") && !path.includes("/") ? "(?:^|/)" : "^";
|
|
79
|
+
const pattern = new RegExp(`${prefix}${escaped}(?:/|$)`);
|
|
80
|
+
if (pattern.test("index.html")) throw invalid();
|
|
81
|
+
return pattern;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** @param {string} path */
|
|
85
|
+
function validPatternPath(path) {
|
|
86
|
+
return (
|
|
87
|
+
!/[\\?![\]:]/.test(path) &&
|
|
88
|
+
!path.includes("\0") &&
|
|
89
|
+
!path.split("/").some((part) => !part || part === "." || part === "..") &&
|
|
90
|
+
path.split("*").length <= 2
|
|
91
|
+
);
|
|
69
92
|
}
|