@hyperframes/core 0.9.77 → 0.9.79

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.
@@ -1,9 +1,9 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
- import { copyFileSync, renameSync } from "node:fs";
2
+ import { copyFileSync, readdirSync, renameSync } from "node:fs";
3
3
  import { copyFile, rename } from "node:fs/promises";
4
4
  import { removeScratch } from "./removeScratch.js";
5
- // Windows reports EPERM/EACCES/EBUSY while antivirus or a just-exited process still holds the
6
- // file; the hold clears within milliseconds. Total wait before giving up: about 1.3 s.
5
+ // Windows reports EPERM/EACCES/EBUSY while antivirus or a just-exited process holds the file (clears in ms; ~1.3 s of
6
+ // waits in all). EPERM onto a folder with files in it never clears; an empty one may be a removed folder still held.
7
7
  const RETRYABLE = new Set(["EPERM", "EACCES", "EBUSY"]);
8
8
  const BACKOFF_MS = [10, 20, 40, 80, 160, 320, 640];
9
9
  export function isWindowsHold(error, platform = process.platform) {
@@ -41,13 +41,21 @@ function handOverHold(error) {
41
41
  throw new HeldRename(error);
42
42
  }
43
43
  /** What a refused rename does next: wait and try again, fall back to a copy, or give up with the error. */
44
- function nextStep(error, attempt, options, platform) {
45
- if (!isWindowsHold(error, platform))
44
+ function nextStep(error, attempt, options, platform, to) {
45
+ if (!isWindowsHold(error, platform) || isFilledFolder(to))
46
46
  return "throw";
47
47
  if (attempt < BACKOFF_MS.length)
48
48
  return "wait";
49
49
  return options.copyFallback ? "copy" : "throw";
50
50
  }
51
+ function isFilledFolder(path) {
52
+ try {
53
+ return readdirSync(path).length > 0;
54
+ }
55
+ catch {
56
+ return false;
57
+ }
58
+ }
51
59
  function sleepSync(ms) {
52
60
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
53
61
  }
@@ -62,7 +70,7 @@ export function renameWithRetry(from, to, options = {}) {
62
70
  return;
63
71
  }
64
72
  catch (error) {
65
- const step = nextStep(error, attempt, options, platform);
73
+ const step = nextStep(error, attempt, options, platform, to);
66
74
  if (step === "throw")
67
75
  throw error;
68
76
  handOverHold(error);
@@ -92,7 +100,7 @@ export async function renameWithRetryAsync(from, to, options = {}) {
92
100
  return;
93
101
  }
94
102
  catch (error) {
95
- const step = nextStep(error, attempt, options, platform);
103
+ const step = nextStep(error, attempt, options, platform, to);
96
104
  if (step === "throw")
97
105
  throw error;
98
106
  if (step === "wait") {
@@ -27,7 +27,13 @@ export function buildElementLabel(el) {
27
27
  const text = renderedTextOf(el, LABEL_SOURCE_CHARS).trim().replace(/\s+/g, " ");
28
28
  const trimLabel = (value, maxChars) => {
29
29
  const chars = Array.from(value);
30
- return chars.length > maxChars ? `${chars.slice(0, maxChars - 1).join("")}…` : value;
30
+ if (chars.length <= maxChars)
31
+ return value;
32
+ const kept = chars.slice(0, maxChars - 1).join("");
33
+ const cutInsideWord = chars[maxChars - 1] !== " ";
34
+ const lastWordEnd = cutInsideWord ? kept.lastIndexOf(" ") : -1;
35
+ const keepsMostOfIt = lastWordEnd >= kept.length / 2;
36
+ return `${(keepsMostOfIt ? kept.slice(0, lastWordEnd) : kept).trimEnd()}…`;
31
37
  };
32
38
  const heading = /^h[1-6]$/.test(tag);
33
39
  if (heading || tag === "p" || tag === "span" || tag === "div")
@@ -1,4 +1,5 @@
1
1
  export declare const MEDIA_ELEMENT_LEAD_SECONDS = 0.00001;
2
2
  export declare function mediaElementTime(sourceSeconds: number): number;
3
3
  export declare function startsSoundOnlyInsideATap(): boolean;
4
+ export declare function isChromium(): boolean;
4
5
  export declare function isWebKit(): boolean;
@@ -6,6 +6,9 @@ export function startsSoundOnlyInsideATap() {
6
6
  const { userAgent, maxTouchPoints } = navigator;
7
7
  return /iP(hone|ad|od)/.test(userAgent) || (/Macintosh/.test(userAgent) && maxTouchPoints > 1);
8
8
  }
9
+ export function isChromium() {
10
+ return /Chrom(e|ium)\/\d/.test(navigator.userAgent);
11
+ }
9
12
  export function isWebKit() {
10
13
  const { userAgent } = navigator;
11
14
  return /AppleWebKit/.test(userAgent) && !/Chrom(e|ium)\/|Edg\/|Android/.test(userAgent);
@@ -1,5 +1,7 @@
1
1
  export { isCredentialOrToolStatePath, isPrivateFileUnder, isStudioPrivatePath, isVcsOrSecretPath, projectPathSegments, } from "@hyperframes/parsers/private-path";
2
2
  export declare function realpath(path: string): string;
3
+ /** `realpath` off the event loop: the same answer, the EISDIR fallback included. */
4
+ export declare function realpathOff(path: string): Promise<string>;
3
5
  /**
4
6
  * Reject paths that escape the `base` directory — including via symlinks.
5
7
  *
package/dist/safePath.js CHANGED
@@ -1,18 +1,32 @@
1
1
  import { resolve, sep, join, dirname, basename, relative, isAbsolute, parse } from "node:path";
2
- import { lstatSync, mkdirSync, realpathSync, statSync } from "node:fs";
2
+ import { lstatSync, mkdirSync, realpath as realpathWalk, realpathSync, statSync } from "node:fs";
3
+ import { realpath as realpathNative } from "node:fs/promises";
4
+ import { promisify } from "node:util";
3
5
  import { projectPathSegments } from "@hyperframes/parsers/private-path";
4
6
  export { isCredentialOrToolStatePath, isPrivateFileUnder, isStudioPrivatePath, isVcsOrSecretPath, projectPathSegments, } from "@hyperframes/parsers/private-path";
7
+ // Some Windows volumes (RAM disks) refuse the native realpath with EISDIR; the JS walk still resolves there.
8
+ const nativeRefused = (error) => error.code === "EISDIR";
5
9
  export function realpath(path) {
6
10
  try {
7
11
  return realpathSync.native(path);
8
12
  }
9
13
  catch (error) {
10
- // Some Windows volumes (RAM disks) refuse the native call with EISDIR.
11
- if (error.code === "EISDIR")
14
+ if (nativeRefused(error))
12
15
  return realpathSync(path);
13
16
  throw error;
14
17
  }
15
18
  }
19
+ /** `realpath` off the event loop: the same answer, the EISDIR fallback included. */
20
+ export async function realpathOff(path) {
21
+ try {
22
+ return await realpathNative(path);
23
+ }
24
+ catch (error) {
25
+ if (nativeRefused(error))
26
+ return promisify(realpathWalk)(path);
27
+ throw error;
28
+ }
29
+ }
16
30
  // realpath also fails for dangling/cyclic symlinks. Existing entries must not
17
31
  // become missing segments: writes could follow them outside the project.
18
32
  function isMissingPath(path) {
@@ -1,9 +1,15 @@
1
1
  const isControlCode = (code) => (code < 0x20 && code !== 0x09) || (code >= 0x7f && code <= 0x9f);
2
+ const reordersOrBreaksTextOnScreen = (code) => (code >= 0x2028 && code <= 0x202e) || (code >= 0x2066 && code <= 0x2069);
2
3
  export function terminalText(text) {
3
4
  let shown = "";
4
5
  for (const ch of text) {
5
6
  const code = ch.charCodeAt(0);
6
- shown += isControlCode(code) ? `\\x${code.toString(16).padStart(2, "0")}` : ch;
7
+ if (isControlCode(code))
8
+ shown += `\\x${code.toString(16).padStart(2, "0")}`;
9
+ else if (reordersOrBreaksTextOnScreen(code))
10
+ shown += `\\u${code.toString(16)}`;
11
+ else
12
+ shown += ch;
7
13
  }
8
14
  return shown;
9
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.77",
3
+ "version": "0.9.79",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -493,9 +493,9 @@
493
493
  "linkedom": "^0.18.12",
494
494
  "postcss": "^8.5.8",
495
495
  "wawoff2": "^2.0.1",
496
- "@hyperframes/lint": "0.9.77",
497
- "@hyperframes/studio-server": "0.9.77",
498
- "@hyperframes/parsers": "0.9.77"
496
+ "@hyperframes/lint": "0.9.79",
497
+ "@hyperframes/studio-server": "0.9.79",
498
+ "@hyperframes/parsers": "0.9.79"
499
499
  },
500
500
  "devDependencies": {
501
501
  "@fontsource/archivo-black": "^5.2.8",