@hyperframes/share 0.9.28-alpha.2 → 0.9.28-alpha.4

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 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;
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/share",
3
- "version": "0.9.28-alpha.2",
3
+ "version": "0.9.28-alpha.4",
4
4
  "description": "Shared review identity, version upload and sharing state for HyperFrames hosts",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
package/src/index.mjs CHANGED
@@ -86,3 +86,5 @@ export {
86
86
  shareSourceFingerprint,
87
87
  createProjectShareSourceStore,
88
88
  } from "./shareSources.mjs";
89
+
90
+ export { SourceIgnoreError } from "./sourceIgnore.mjs";
@@ -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 Error(".hyperframesignore must be a regular file inside the project, smaller than 64 KiB.");
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 () => false;
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((entry) => {
56
- const path = entry.replace(/\/$/, "");
57
- if (
58
- path === "index.html" ||
59
- /[\\*?![\]:]/.test(path) ||
60
- path.includes("\0") ||
61
- path.split("/").some((part) => !part || part === "." || part === "..")
62
- )
63
- throw new Error(
64
- ".hyperframesignore accepts literal project-relative file or folder paths, one per line. Wildcards and excluding index.html are not supported.",
65
- );
66
- return path;
67
- });
68
- return (path) => entries.some((entry) => path === entry || path.startsWith(`${entry}/`));
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
  }