@hyperframes/core 0.9.45 → 0.9.47

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,11 +1,13 @@
1
1
  import * as fs from "node:fs";
2
2
  type SiblingFileSystem = Pick<typeof fs, "writeFileSync" | "chmodSync" | "unlinkSync">;
3
3
  type DirectFileSystem = SiblingFileSystem & Pick<typeof fs, "openSync" | "closeSync">;
4
+ export declare function cannotHardLink(error: unknown): boolean;
4
5
  /** A fresh temp sibling for a write that publishes `filePath`. 13 bytes, so a 242-byte name still fits. */
5
6
  export declare function atomicTempPath(filePath: string): string;
6
7
  export declare function isAtomicTempPath(path: string): boolean;
7
8
  /** Replace a file only after the complete sibling temp file is written. No mode: the default one. */
8
9
  export declare function replaceFileAtomically(filePath: string, content: string | Uint8Array, mode?: number, operations?: SiblingFileSystem & Pick<typeof fs, "renameSync">): void;
10
+ export declare function refuseReadOnly(filePath: string): void;
9
11
  /** Create a file that must not exist yet (EEXIST otherwise); readers never see it empty or partial. */
10
12
  export declare function createFileAtomically(filePath: string, content: string | Uint8Array, operations?: DirectFileSystem & Pick<typeof fs, "linkSync">): void;
11
13
  /** The file a write to `filePath` lands on: folder links and file links followed as the system does. */
@@ -5,10 +5,21 @@ import { realpath } from "./safePath.js";
5
5
  import { renameWithRetry } from "./renameWithRetry.js";
6
6
  // Codes a volume without hard links (FAT, exFAT, some network shares, Android app data) answers link() with.
7
7
  // EISDIR: libuv maps Windows ERROR_INVALID_FUNCTION (FAT/exFAT refusing a link) to it; nodejs/node#65817.
8
- const NO_HARD_LINKS = new Set(["EPERM", "ENOTSUP", "EOPNOTSUPP", "EXDEV", "EISDIR", "EACCES"]);
8
+ const NO_HARD_LINKS = new Set([
9
+ "EPERM",
10
+ "ENOTSUP",
11
+ "EOPNOTSUPP",
12
+ "ENOSYS",
13
+ "EXDEV",
14
+ "EISDIR",
15
+ "EACCES",
16
+ ]);
9
17
  const MAX_LINK_HOPS = 40;
10
18
  const TEMP_NAME_TRIES = 3;
11
19
  const TEMP_SUFFIX = /\.hf[0-9a-f]{6}\.tmp$/;
20
+ export function cannotHardLink(error) {
21
+ return NO_HARD_LINKS.has(errorCode(error));
22
+ }
12
23
  /** A fresh temp sibling for a write that publishes `filePath`. 13 bytes, so a 242-byte name still fits. */
13
24
  export function atomicTempPath(filePath) {
14
25
  return `${filePath}.hf${randomBytes(3).toString("hex")}.tmp`;
@@ -33,9 +44,19 @@ function traceWrite(filePath, content) {
33
44
  /** Replace a file only after the complete sibling temp file is written. No mode: the default one. */
34
45
  export function replaceFileAtomically(filePath, content, mode, operations = fs) {
35
46
  traceWrite(filePath, content);
47
+ refuseReadOnly(filePath);
36
48
  // Node fs.rename uses libuv uv_fs_rename; win32 calls MoveFileExW with MOVEFILE_REPLACE_EXISTING.
37
49
  publishSibling(filePath, content, mode, operations, (tempPath) => renameWithRetry(tempPath, filePath, { rename: operations.renameSync }));
38
50
  }
51
+ export function refuseReadOnly(filePath) {
52
+ try {
53
+ fs.accessSync(filePath, fs.constants.W_OK);
54
+ }
55
+ catch (error) {
56
+ if (errorCode(error) !== "ENOENT")
57
+ throw error;
58
+ }
59
+ }
39
60
  /** Create a file that must not exist yet (EEXIST otherwise); readers never see it empty or partial. */
40
61
  export function createFileAtomically(filePath, content, operations = fs) {
41
62
  publishSibling(filePath, content, undefined, operations, (tempPath) => {
@@ -43,7 +64,7 @@ export function createFileAtomically(filePath, content, operations = fs) {
43
64
  operations.linkSync(tempPath, filePath);
44
65
  }
45
66
  catch (error) {
46
- if (!NO_HARD_LINKS.has(errorCode(error)))
67
+ if (!cannotHardLink(error))
47
68
  throw error;
48
69
  createDirectly(filePath, content, operations);
49
70
  }
package/dist/index.d.ts CHANGED
@@ -45,7 +45,7 @@ export { buildHyperframesRuntimeScript, type HyperframesRuntimeBuildOptions, } f
45
45
  export { MEDIA_VISUAL_STYLE_PROPERTIES, copyMediaVisualStyles, exportClipWindow, quantizeSeekTime, quantizeTimeToFrame, type MediaVisualStyleProperty, } from "./inline-scripts/parityContract.js";
46
46
  export { redactKnownPaths, redactTelemetryString, redactUrlQueryStrings, } from "./telemetryRedaction.js";
47
47
  export { folderGone, isProjectRootMissing, isSafePath, mkdirWithinProject, ProjectRootMissingError, realpath, realProjectRoot, resolveWithinProject, } from "./safePath.js";
48
- export { isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
48
+ export { isCompositionFolder, isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
49
49
  export type { HyperframePickerApi, HyperframePickerBoundingBox, HyperframePickerElementInfo, } from "./inline-scripts/pickerApi.js";
50
50
  export type { FrameAdapter, FrameAdapterContext } from "./adapters/types.js";
51
51
  export type { GSAPTimelineLike, CreateGSAPFrameAdapterOptions } from "./adapters/gsap.js";
package/dist/index.js CHANGED
@@ -41,7 +41,7 @@ export { buildHyperframesRuntimeScript, } from "./inline-scripts/hyperframesRunt
41
41
  export { MEDIA_VISUAL_STYLE_PROPERTIES, copyMediaVisualStyles, exportClipWindow, quantizeSeekTime, quantizeTimeToFrame, } from "./inline-scripts/parityContract.js";
42
42
  export { redactKnownPaths, redactTelemetryString, redactUrlQueryStrings, } from "./telemetryRedaction.js";
43
43
  export { folderGone, isProjectRootMissing, isSafePath, mkdirWithinProject, ProjectRootMissingError, realpath, realProjectRoot, resolveWithinProject, } from "./safePath.js";
44
- export { isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
44
+ export { isCompositionFolder, isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
45
45
  export { createGSAPFrameAdapter } from "./adapters/gsap.js";
46
46
  // Text measurement
47
47
  export { fitTextFontSize } from "./text/index.js";
@@ -1,3 +1,4 @@
1
1
  /** Files that `hyperframes init` or another HyperFrames tool writes at a project's root, next to its `index.html`. */
2
2
  export declare const PROJECT_MARKER_FILES: readonly ["hyperframes.json", "meta.json", "project.json"];
3
3
  export declare function isHyperframesProject(fileNames: Iterable<string>): boolean;
4
+ export declare function isCompositionFolder(fileNames: Iterable<string>): boolean;
@@ -4,3 +4,6 @@ export function isHyperframesProject(fileNames) {
4
4
  const names = new Set(fileNames);
5
5
  return names.has("index.html") && PROJECT_MARKER_FILES.some((name) => names.has(name));
6
6
  }
7
+ export function isCompositionFolder(fileNames) {
8
+ return new Set(fileNames).has("index.html");
9
+ }
@@ -1,5 +1,5 @@
1
- import { isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
2
- export { isHyperframesProject, PROJECT_MARKER_FILES };
1
+ import { isCompositionFolder, isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
2
+ export { isCompositionFolder, isHyperframesProject, PROJECT_MARKER_FILES };
3
3
  export interface FoundProject {
4
4
  path: string;
5
5
  name: string;
package/dist/projects.js CHANGED
@@ -2,8 +2,8 @@ import { execFile } from "node:child_process";
2
2
  import { readFile, readdir, realpath, stat } from "node:fs/promises";
3
3
  import { homedir } from "node:os";
4
4
  import { basename, dirname, isAbsolute, join, relative, sep } from "node:path";
5
- import { isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
6
- export { isHyperframesProject, PROJECT_MARKER_FILES };
5
+ import { isCompositionFolder, isHyperframesProject, PROJECT_MARKER_FILES } from "./projectRule.js";
6
+ export { isCompositionFolder, isHyperframesProject, PROJECT_MARKER_FILES };
7
7
  const WALK_CONCURRENCY = 64;
8
8
  async function readEntries(dir) {
9
9
  try {
@@ -4,6 +4,7 @@ interface Options {
4
4
  copyFallback?: boolean;
5
5
  }
6
6
  export declare function isWindowsHold(error: unknown, platform?: NodeJS.Platform): boolean;
7
+ export declare function catchHeldRename(work: () => Promise<void>): Promise<unknown>;
7
8
  /** `renameSync` that rides out Windows' transient file locks; other platforms and errors throw at once. */
8
9
  export declare function renameWithRetry(from: string, to: string, options?: Options & {
9
10
  rename?: (from: string, to: string) => void;
@@ -1,3 +1,4 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
1
2
  import { copyFileSync, renameSync } from "node:fs";
2
3
  import { copyFile, rename } from "node:fs/promises";
3
4
  import { removeScratch } from "./removeScratch.js";
@@ -10,6 +11,35 @@ export function isWindowsHold(error, platform = process.platform) {
10
11
  return false;
11
12
  return RETRYABLE.has(error?.code ?? "");
12
13
  }
14
+ const holdScope = new AsyncLocalStorage();
15
+ class HeldRename {
16
+ error;
17
+ constructor(error) {
18
+ this.error = error;
19
+ }
20
+ }
21
+ export async function catchHeldRename(work) {
22
+ const scope = { open: true, held: null };
23
+ try {
24
+ await holdScope.run(scope, work);
25
+ }
26
+ catch (thrown) {
27
+ if (!(thrown instanceof HeldRename))
28
+ throw thrown;
29
+ }
30
+ finally {
31
+ scope.open = false;
32
+ }
33
+ return scope.held;
34
+ }
35
+ function handOverHold(error) {
36
+ const scope = holdScope.getStore();
37
+ if (!scope?.open)
38
+ return;
39
+ scope.open = false;
40
+ scope.held = error;
41
+ throw new HeldRename(error);
42
+ }
13
43
  /** What a refused rename does next: wait and try again, fall back to a copy, or give up with the error. */
14
44
  function nextStep(error, attempt, options, platform) {
15
45
  if (!isWindowsHold(error, platform))
@@ -35,6 +65,7 @@ export function renameWithRetry(from, to, options = {}) {
35
65
  const step = nextStep(error, attempt, options, platform);
36
66
  if (step === "throw")
37
67
  throw error;
68
+ handOverHold(error);
38
69
  if (step === "wait") {
39
70
  sleepSync(BACKOFF_MS[attempt]);
40
71
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.45",
3
+ "version": "0.9.47",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -449,9 +449,9 @@
449
449
  "linkedom": "^0.18.12",
450
450
  "postcss": "^8.5.8",
451
451
  "wawoff2": "^2.0.1",
452
- "@hyperframes/lint": "0.9.45",
453
- "@hyperframes/parsers": "0.9.45",
454
- "@hyperframes/studio-server": "0.9.45"
452
+ "@hyperframes/lint": "0.9.47",
453
+ "@hyperframes/studio-server": "0.9.47",
454
+ "@hyperframes/parsers": "0.9.47"
455
455
  },
456
456
  "devDependencies": {
457
457
  "@fontsource/archivo-black": "^5.2.8",