@adea-ai/app-framework 0.39.2 → 0.39.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.
Files changed (199) hide show
  1. package/README.md +158 -52
  2. package/dist/app/application.d.ts +0 -1
  3. package/dist/app/application.js +8 -6
  4. package/dist/app/create-application.js +3 -11
  5. package/dist/app/service-registry.d.ts +0 -1
  6. package/dist/app/service-registry.js +3 -3
  7. package/dist/app/value-guards.d.ts +2 -0
  8. package/dist/app/value-guards.js +6 -1
  9. package/dist/appearance/appearance-host.d.ts +1 -1
  10. package/dist/appearance/appearance-host.js +11 -2
  11. package/dist/appearance/appearance-preferences.d.ts +0 -1
  12. package/dist/appearance/custom-theme-import.d.ts +8 -2
  13. package/dist/appearance/custom-theme-import.js +58 -23
  14. package/dist/appearance/custom-theme-library.d.ts +3 -3
  15. package/dist/appearance/custom-theme-library.js +3 -3
  16. package/dist/appearance/theme-file-importer.d.ts +1 -1
  17. package/dist/appearance/theme-file-importer.js +2 -1
  18. package/dist/appearance/theme-library-mutation.d.ts +7 -0
  19. package/dist/appearance/theme-library-mutation.js +10 -2
  20. package/dist/appearance/theme-library-store.d.ts +17 -13
  21. package/dist/appearance/theme-library-store.js +35 -22
  22. package/dist/appearance/theme-record-adapter.js +1 -2
  23. package/dist/appearance/theme-registry.js +0 -1
  24. package/dist/cli/cli-runner.d.ts +3 -2
  25. package/dist/cli/cli-runner.js +5 -10
  26. package/dist/cli/release-assets-plan-cli.js +2 -2
  27. package/dist/cli/release-cut-cli.js +2 -3
  28. package/dist/cli/release-descriptor-staging-cli.js +2 -2
  29. package/dist/cli/release-finalize-cli.js +3 -3
  30. package/dist/cli/release-promote-cli.js +2 -2
  31. package/dist/cli/release-publish-cli.js +2 -2
  32. package/dist/cli/release-sign-cli.js +2 -1
  33. package/dist/cli/release-step-cli.js +2 -2
  34. package/dist/desktop/channel-proof.js +27 -11
  35. package/dist/desktop/client-assets.d.ts +6 -1
  36. package/dist/desktop/client-assets.js +16 -3
  37. package/dist/desktop/client-dev-proxy.d.ts +0 -2
  38. package/dist/desktop/client-dev-proxy.js +2 -2
  39. package/dist/desktop/desktop-client.js +2 -1
  40. package/dist/desktop/desktop-gateway.js +24 -82
  41. package/dist/desktop/desktop-host-websocket.d.ts +5 -1
  42. package/dist/desktop/desktop-host-websocket.js +9 -7
  43. package/dist/desktop/desktop-host.d.ts +5 -0
  44. package/dist/desktop/desktop-host.js +3 -0
  45. package/dist/desktop/desktop-stream.js +5 -10
  46. package/dist/desktop/typed-array-intrinsics.d.ts +6 -0
  47. package/dist/desktop/typed-array-intrinsics.js +13 -1
  48. package/dist/developer-app/developer-app.d.ts +1 -1
  49. package/dist/developer-app/developer-app.js +26 -13
  50. package/dist/framework-source.json +1 -1
  51. package/dist/installer/command-artifact.d.ts +1 -0
  52. package/dist/installer/command-artifact.js +47 -27
  53. package/dist/installer/installed-payload.js +3 -1
  54. package/dist/installer/installer-ci-bootstrap.js +5 -6
  55. package/dist/installer/installer-ci-preflight.js +3 -3
  56. package/dist/installer/installer-identity.d.ts +0 -22
  57. package/dist/installer/installer-identity.js +3 -53
  58. package/dist/installer/installer-image-mount.d.ts +0 -1
  59. package/dist/installer/installer-image-mount.js +1 -1
  60. package/dist/installer/installer-observation.d.ts +5 -5
  61. package/dist/installer/installer-observation.js +32 -47
  62. package/dist/installer/installer-process-cleanup.js +2 -2
  63. package/dist/installer/installer-renderer-evidence.js +7 -28
  64. package/dist/installer/installer-upgrade-command.js +8 -20
  65. package/dist/installer/installer-worker-guard.js +3 -3
  66. package/dist/native/cef-helper.js +4 -4
  67. package/dist/native/desktop-build.d.ts +0 -3
  68. package/dist/native/desktop-build.js +2 -2
  69. package/dist/native/electrobun-source-patch.d.ts +4 -0
  70. package/dist/native/electrobun-source-patch.js +5 -1
  71. package/dist/native/native-utilities.js +4 -3
  72. package/dist/native/pinned-download.d.ts +16 -0
  73. package/dist/native/pinned-download.js +42 -0
  74. package/dist/native/posix-launcher-build.js +15 -35
  75. package/dist/native/posix-tree-removal.js +21 -33
  76. package/dist/native/sidecar-services.d.ts +0 -2
  77. package/dist/native/sidecar-services.js +1 -1
  78. package/dist/native/sidecar.d.ts +3 -0
  79. package/dist/native/sidecar.js +15 -2
  80. package/dist/native/window-surface-store.js +3 -3
  81. package/dist/native/windows-extractor-build.d.ts +6 -16
  82. package/dist/native/windows-extractor-build.js +11 -14
  83. package/dist/release/feed-release-cut.d.ts +2 -6
  84. package/dist/release/feed-release-cut.js +5 -93
  85. package/dist/release/feed-state.js +1 -5
  86. package/dist/release/github-release-cut.js +5 -66
  87. package/dist/release/github-release-provenance.d.ts +2 -0
  88. package/dist/release/github-release-provenance.js +4 -7
  89. package/dist/release/github-release-publisher.js +2 -2
  90. package/dist/release/github-release-qualification.js +3 -3
  91. package/dist/release/local-release.d.ts +3 -3
  92. package/dist/release/local-release.js +12 -23
  93. package/dist/release/qualification-run.js +1 -1
  94. package/dist/release/release-assets-plan.js +1 -1
  95. package/dist/release/release-config.d.ts +7 -15
  96. package/dist/release/release-config.js +25 -29
  97. package/dist/release/release-cut-command.d.ts +1 -1
  98. package/dist/release/release-cut-command.js +1 -1
  99. package/dist/release/release-cut.d.ts +5 -32
  100. package/dist/release/release-cut.js +9 -55
  101. package/dist/release/release-descriptor-staging.js +3 -8
  102. package/dist/release/release-promotion.js +2 -1
  103. package/dist/release/release-publish-command.js +5 -15
  104. package/dist/release/release-qualification.js +1 -1
  105. package/dist/shared/bounded-body.d.ts +33 -0
  106. package/dist/shared/bounded-body.js +102 -0
  107. package/dist/shared/file-system.d.ts +12 -0
  108. package/dist/shared/file-system.js +40 -0
  109. package/dist/shell/app-shell.js +29 -14
  110. package/dist/shell/app-utilities.d.ts +2 -1
  111. package/dist/shell/app-utilities.js +2 -1
  112. package/dist/shell/application-menu.d.ts +1 -1
  113. package/dist/shell/application-menu.js +7 -3
  114. package/dist/shell/poll.d.ts +27 -0
  115. package/dist/shell/poll.js +88 -0
  116. package/dist/update-helper.bundle.js +268 -144
  117. package/dist/updates/channel-update-manager.js +0 -1
  118. package/dist/updates/desktop-updater.d.ts +9 -0
  119. package/dist/updates/desktop-updater.js +103 -50
  120. package/dist/updates/feed/release-feed.d.ts +7 -4
  121. package/dist/updates/feed/release-feed.js +3 -7
  122. package/dist/updates/feed/release-location.js +6 -26
  123. package/dist/updates/feed/release-version.d.ts +7 -2
  124. package/dist/updates/feed/release-version.js +9 -2
  125. package/dist/updates/feed/signed-release.d.ts +1 -1
  126. package/dist/updates/feed/signed-release.js +2 -2
  127. package/dist/updates/feed/update-discovery.js +2 -6
  128. package/dist/updates/helper/launch-gate-recovery.js +28 -78
  129. package/dist/updates/helper/resume-staging.d.ts +14 -3
  130. package/dist/updates/helper/resume-staging.js +23 -37
  131. package/dist/updates/helper/update-helper.d.ts +6 -2
  132. package/dist/updates/helper/update-helper.js +38 -33
  133. package/dist/updates/helper/update-resume.js +9 -6
  134. package/dist/updates/install/update-extraction.js +28 -8
  135. package/dist/updates/install/update-handoff-plan.d.ts +0 -1
  136. package/dist/updates/install/update-handoff-plan.js +3 -4
  137. package/dist/updates/install/update-swap-stage.js +1 -6
  138. package/dist/updates/install/update-swap.d.ts +5 -2
  139. package/dist/updates/install/update-swap.js +193 -72
  140. package/dist/updates/launch/helper-exit-wait.d.ts +6 -0
  141. package/dist/updates/launch/helper-exit-wait.js +18 -0
  142. package/dist/updates/launch/packaged-update-startup.js +8 -6
  143. package/dist/updates/launch/update-launch-gate.js +7 -14
  144. package/dist/updates/locks/stable-file.js +4 -1
  145. package/dist/updates/locks/update-helper-presence.d.ts +12 -0
  146. package/dist/updates/locks/update-helper-presence.js +27 -0
  147. package/dist/updates/retention/retention-cleanup.js +10 -9
  148. package/dist/updates/retention/retention-maintenance.d.ts +40 -0
  149. package/dist/updates/retention/retention-maintenance.js +95 -0
  150. package/dist/updates/retention/retention-prune-progress.js +4 -5
  151. package/dist/updates/retention/retirement-inventory.d.ts +13 -0
  152. package/dist/updates/retention/retirement-inventory.js +39 -31
  153. package/dist/updates/retention/retirement-records.d.ts +1 -4
  154. package/dist/updates/retention/retirement-records.js +18 -32
  155. package/dist/updates/retention/update-retention-marker.d.ts +4 -0
  156. package/dist/updates/retention/update-retention-marker.js +9 -14
  157. package/dist/updates/retention/update-retirement.d.ts +12 -0
  158. package/dist/updates/retention/update-retirement.js +59 -31
  159. package/dist/updates/update-adapter.d.ts +1 -23
  160. package/dist/updates/update-adapter.js +31 -24
  161. package/dist/updates/update-channel-store.d.ts +2 -1
  162. package/dist/updates/update-channel-store.js +6 -4
  163. package/dist/updates/update-manager.js +2 -2
  164. package/dist/updates/update-services.d.ts +1 -1
  165. package/dist/updates/update-services.js +9 -4
  166. package/dist/updates/update-state-store.d.ts +0 -2
  167. package/dist/updates/update-state-store.js +5 -12
  168. package/dist/updates/update-state.d.ts +6 -10
  169. package/dist/updates/update-state.js +1 -1
  170. package/dist/views/app-help.d.ts +1 -1
  171. package/dist/views/app-help.js +1 -3
  172. package/dist/views/appearance-surface.js +15 -8
  173. package/dist/views/update-surface.d.ts +1 -3
  174. package/dist/views/update-surface.js +2 -2
  175. package/package.json +18 -16
  176. package/src/app/application.tsx +13 -6
  177. package/src/appearance/appearance-host.tsx +17 -7
  178. package/src/appearance/appearance-preferences.ts +0 -1
  179. package/src/appearance/custom-theme-import.ts +99 -26
  180. package/src/appearance/custom-theme-library.ts +3 -2
  181. package/src/appearance/theme-file-importer.ts +3 -2
  182. package/src/appearance/theme-library-mutation.ts +20 -8
  183. package/src/appearance/theme-library-schema.ts +7 -0
  184. package/src/appearance/theme-library-store.ts +41 -26
  185. package/src/desktop/client-assets.ts +27 -12
  186. package/src/shell/app-shell.tsx +33 -13
  187. package/src/shell/app-utilities.tsx +7 -1
  188. package/src/shell/poll.ts +125 -0
  189. package/src/updates/feed/release-version.ts +11 -3
  190. package/src/updates/update-adapter.ts +27 -44
  191. package/src/updates/update-state.ts +7 -13
  192. package/src/views/app-help.tsx +1 -1
  193. package/src/views/appearance-surface.tsx +39 -11
  194. package/src/views/update-surface.tsx +0 -4
  195. package/templates/application/.github/workflows/release-assets.yml +2 -2
  196. package/templates/application/README.md +3 -3
  197. package/dist/native/cef-helper-download.d.ts +0 -1
  198. package/dist/native/cef-helper-download.js +0 -35
  199. package/src/desktop/client-response-lifecycle.ts +0 -305
@@ -1,4 +1,4 @@
1
- import { isGitSha, isRecord } from "../app/value-guards.js";
1
+ import { isRecord } from "../app/value-guards.js";
2
2
  import { parseOfflinePolicy } from "./release-qualification.js";
3
3
  import { assertSidecarNames } from "../native/app-bundle.js";
4
4
  import { containsAsciiControl } from "../desktop/string-policy.js";
@@ -49,9 +49,9 @@ function hostedReleaseWorkflows(workflows) {
49
49
  /** The file name GitHub's workflow APIs and `gh workflow run` address a workflow by. */
50
50
  var workflowFile = (path) => path.slice(18);
51
51
  var workflowPath = (value) => typeof value === "string" && value.length <= 200 && value.startsWith(workflowDirectory) && /^[A-Za-z0-9][A-Za-z0-9._-]*\.ya?ml$/.test(workflowFile(value));
52
- /** Validate shared daily, dev and stable asset requirements. */
52
+ /** Validate shared daily and stable asset requirements. */
53
53
  function parseReleaseConfig(config) {
54
- if (!isRecord(config) || !isRecord(config.platforms) || !strings(config.releaseAssets) || !strings(config.dailyDiscoveryAssets) || !strings(config.stableDiscoveryAssets) || config.devDiscoveryAssets !== void 0 && !strings(config.devDiscoveryAssets) || !Number.isSafeInteger(config.soakHours) || Number(config.soakHours) < 0 || Number(config.soakHours) > 8760) throw new Error("Invalid release configuration");
54
+ if (!isRecord(config) || !isRecord(config.platforms) || !strings(config.releaseAssets) || !strings(config.dailyDiscoveryAssets) || !strings(config.stableDiscoveryAssets) || !Number.isSafeInteger(config.soakHours) || Number(config.soakHours) < 0 || Number(config.soakHours) > 8760) throw new Error("Invalid release configuration");
55
55
  const workflows = config.releaseWorkflows;
56
56
  let releaseWorkflows;
57
57
  if (workflows !== void 0) {
@@ -98,16 +98,13 @@ function parseReleaseConfig(config) {
98
98
  const releaseAssets = [...config.releaseAssets];
99
99
  const daily = [...config.dailyDiscoveryAssets];
100
100
  const stable = [...config.stableDiscoveryAssets];
101
- const dev = config.devDiscoveryAssets === void 0 ? [] : [...config.devDiscoveryAssets];
102
- if (daily.some((name) => !releaseAssets.includes(name) || stable.includes(name) || dev.includes(name)) || stable.some((name) => !releaseAssets.includes(name) || dev.includes(name)) || dev.some((name) => !releaseAssets.includes(name))) throw new Error("Daily, stable and dev discovery assets must be distinct release assets");
101
+ if (daily.some((name) => !releaseAssets.includes(name) || stable.includes(name)) || stable.some((name) => !releaseAssets.includes(name))) throw new Error("Daily and stable discovery assets must be distinct release assets");
103
102
  const requirements = (tag) => {
104
- if (!/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(tag) || tag.length > 65) throw new Error("Invalid release tag");
105
- const isDev = tag.includes("-dev.");
106
- const selectedAssets = releaseAssets.filter((name) => isDev ? !daily.includes(name) && !stable.includes(name) : !dev.includes(name));
103
+ if (!/^v\d+\.\d+\.\d+$/.test(tag) || tag.length > 65) throw new Error("Invalid release tag");
107
104
  const substitute = (value) => value.replaceAll("{tag}", tag);
108
105
  const result = {
109
106
  platforms: Object.fromEntries(Object.entries(platformSnapshot).map(([platform, assets]) => [platform, assets.map(substitute)])),
110
- releaseAssets: selectedAssets.map(substitute),
107
+ releaseAssets: releaseAssets.map(substitute),
111
108
  ...offlinePolicy ? { offlinePolicy: { ...offlinePolicy } } : {},
112
109
  ...commandArtifacts.length ? { commandArtifacts: Object.fromEntries(commandArtifacts.map((artifact) => [artifact.kind, Object.fromEntries(Object.entries(artifact.platforms).map(([platform, name]) => [platform, substitute(name)]))])) } : {}
113
110
  };
@@ -125,27 +122,9 @@ function parseReleaseConfig(config) {
125
122
  releaseWorkflows,
126
123
  feed,
127
124
  commandArtifacts,
128
- historyRewrite: parseHistoryRewrite(config.historyRewrite),
129
125
  requirements
130
126
  };
131
127
  }
132
- var sha = (value) => typeof value === "string" && isGitSha(value);
133
- /** Parse the optional `historyRewrite` list: at most 256 entries of exactly `from`, `to` and
134
- * `tree`, each a full lowercase SHA-1, with `from` distinct from `to` and never listed twice. */
135
- function parseHistoryRewrite(value) {
136
- if (value === void 0) return [];
137
- if (!Array.isArray(value) || value.length > 256) throw new Error("Invalid history rewrite");
138
- const entries = value.map((entry) => {
139
- if (!isRecord(entry) || Object.keys(entry).length !== 3 || !sha(entry.from) || !sha(entry.to) || !sha(entry.tree) || entry.from === entry.to) throw new Error("Invalid history rewrite");
140
- return {
141
- from: entry.from,
142
- to: entry.to,
143
- tree: entry.tree
144
- };
145
- });
146
- if (new Set(entries.map((entry) => entry.from)).size !== entries.length) throw new Error("Invalid history rewrite");
147
- return entries;
148
- }
149
128
  /** Every payload and release asset a release's requirements name, desktop payloads first. */
150
129
  function releaseAssetNames(requirements) {
151
130
  return [
@@ -163,6 +142,23 @@ function platformPayloads(requirements, platform) {
163
142
  })];
164
143
  }
165
144
  /**
145
+ * The configured release verification keys by id. A packaged app refuses a release-config.json
146
+ * with more than eight keys (packaged-release-config), so publishing refuses one as well.
147
+ */
148
+ function releaseVerificationKeys(config) {
149
+ if (!isRecord(config) || typeof config.appId !== "string" || config.appId.length > 255 || !appIdPattern.test(config.appId) || !isRecord(config.releaseSigningKeys) || !isRecord(config.descriptors)) throw new Error("Invalid release signing configuration");
150
+ const entries = Object.entries(config.releaseSigningKeys);
151
+ if (!entries.length || entries.length > 8) throw new Error("Missing release verification keys");
152
+ const keys = /* @__PURE__ */ new Map();
153
+ for (const [id, encoded] of entries) {
154
+ if (!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(id) || typeof encoded !== "string") throw new Error("Invalid release verification key");
155
+ const raw = Buffer.from(encoded, "base64");
156
+ if (raw.length !== 32 || raw.toString("base64") !== encoded) throw new Error("Invalid release verification key");
157
+ keys.set(id, encoded);
158
+ }
159
+ return keys;
160
+ }
161
+ /**
166
162
  * Resolve the channel descriptors a tag publishes: one per channel, payload kind (the desktop
167
163
  * archive and each command artifact) and platform, each naming exactly that payload.
168
164
  */
@@ -178,7 +174,7 @@ function discoveryPolicies(config, tag) {
178
174
  appId: artifact.appId,
179
175
  payloads: (platform) => requirements.commandArtifacts[artifact.kind][platform]
180
176
  }))];
181
- const channels = tag.includes("-dev.") ? ["dev"] : ["daily", "stable"];
177
+ const channels = ["daily", "stable"];
182
178
  const result = [];
183
179
  for (const channel of channels) {
184
180
  const configured = config[`${channel}DiscoveryAssets`];
@@ -206,4 +202,4 @@ function discoveryPolicies(config, tag) {
206
202
  }
207
203
  return result;
208
204
  }
209
- export { discoveryPolicies, hostedReleaseWorkflows, parseHistoryRewrite, parseReleaseConfig, platformPayloads, platformTargets, releaseAssetNames, workflowFile };
205
+ export { discoveryPolicies, hostedReleaseWorkflows, parseReleaseConfig, platformPayloads, platformTargets, releaseAssetNames, releaseVerificationKeys, workflowFile };
@@ -1,7 +1,7 @@
1
1
  /** Execute release cuts only from the recorded main-branch GitHub workflow. */
2
2
  export declare function runReleaseCutCommand(options: {
3
3
  env: Record<string, string | undefined>;
4
- kind: 'dev' | 'daily';
4
+ kind: 'daily';
5
5
  appName: string;
6
6
  config: unknown;
7
7
  run?: (args: string[], input?: string) => Promise<string>;
@@ -11,7 +11,7 @@ var execute = promisify(execFile);
11
11
  /** Execute release cuts only from the recorded main-branch GitHub workflow. */
12
12
  async function runReleaseCutCommand(options) {
13
13
  const { env, kind } = options;
14
- if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || (kind === "daily" ? !["schedule", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") : kind === "dev" ? !["push", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "") : true)) throw new Error("Release cut requires a trusted main workflow");
14
+ if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || kind !== "daily" || !["schedule", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "")) throw new Error("Release cut requires a trusted main workflow");
15
15
  const parsed = parseReleaseConfig(options.config);
16
16
  const { requirements, versionSource, releasePleaseManifestPath } = parsed;
17
17
  const releaseWorkflows = hostedReleaseWorkflows(parsed.releaseWorkflows);
@@ -3,7 +3,7 @@
3
3
  export type CutRelease = {
4
4
  tag: string;
5
5
  sourceSha: string;
6
- kind: 'dev' | 'daily';
6
+ kind: 'daily';
7
7
  draft: boolean;
8
8
  prerelease: boolean;
9
9
  stageableDraft?: boolean;
@@ -12,44 +12,17 @@ export type ReleaseCutProvider = {
12
12
  /** Return a release only after independently resolving its tag target and channel marker. */
13
13
  find(tag: string): Promise<CutRelease | null>;
14
14
  isMainAncestor(sha: string): Promise<boolean>;
15
- /** Whether `newer` strictly descends from `older`. */
16
- isAncestor(older: string, newer: string): Promise<boolean>;
17
- /** Create a dev prerelease for the tag at the source commit. */
18
- create(identity: Pick<CutRelease, 'tag' | 'sourceSha'>): Promise<void>;
19
15
  qualification(release: CutRelease): Promise<'qualified' | 'not-qualified' | 'unknown'>;
20
16
  pendingBuild(release: CutRelease): Promise<'pending' | 'idle' | 'unknown'>;
21
- /** Inspect all existing dev releases of a dev version line; errors must fail closed. */
22
- highestDevCounter(version: string): Promise<number>;
23
- /** The highest dev counter among the Git tags of a dev version line, with or without a
24
- * release (0 when none). A tag left by an earlier release system or a deleted release keeps
25
- * its counter taken, so a new cut numbers above it instead of colliding. */
26
- highestDevTag(version: string): Promise<number>;
27
- /** Check the actual Git tag even when no release exists. */
28
- tagExists(tag: string): Promise<boolean>;
29
17
  dispatch(tag: string): Promise<void>;
30
18
  };
31
19
  /**
32
- * The version dev builds after `released` are numbered for: the next minor version.
33
- * Release Please writes a version to the manifest only when it releases it, so the
34
- * source manifest always names a released version (or the one its own commit
35
- * releases). The next release is a patch or minor above it, or a new major, so dev
36
- * builds of the next minor sort above the release they follow, and stay strictly
37
- * increasing across a patch release, which leaves the next minor unchanged.
38
- */
39
- export declare function nextDevVersion(released: string): string;
40
- /**
41
- * Cut or repair a daily/dev release without moving an existing tag. A daily is the
42
- * Release Please release `v<version>` of the source manifest's version. A dev build is
43
- * `v<next>-dev.N` for the next unreleased version (see `nextDevVersion`), where N counts
44
- * that version's dev releases from 1, so it starts again at 1 when a release moves the
45
- * next version: `v0.112.0-dev.15` is followed, after the `v0.112.0` release, by
46
- * `v0.113.0-dev.1`. A new cut also numbers above every existing dev tag of the version,
47
- * so tags with no trusted release (from an earlier release system) are skipped, never
48
- * reused or moved: with `v0.73.0-dev.1` and `dev.2` tagged but unreleased, the cut is
49
- * `v0.73.0-dev.3`.
20
+ * Repair or dispatch the daily release of the source manifest's version without moving a
21
+ * tag. Release Please creates every daily `v<version>`; this only checks its identity,
22
+ * reports it qualified or pending, or dispatches its build.
50
23
  */
51
24
  export declare function cutRelease(options: {
52
- kind: 'dev' | 'daily';
25
+ kind: 'daily';
53
26
  sourceSha: string;
54
27
  /** The version in the source manifest at the exact source commit: the latest release. */
55
28
  releasedVersion: string;
@@ -1,60 +1,18 @@
1
1
  import { isGitSha } from "../app/value-guards.js";
2
2
  // src/release/release-cut.ts
3
3
  /**
4
- * The version dev builds after `released` are numbered for: the next minor version.
5
- * Release Please writes a version to the manifest only when it releases it, so the
6
- * source manifest always names a released version (or the one its own commit
7
- * releases). The next release is a patch or minor above it, or a new major, so dev
8
- * builds of the next minor sort above the release they follow, and stay strictly
9
- * increasing across a patch release, which leaves the next minor unchanged.
10
- */
11
- function nextDevVersion(released) {
12
- const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.exec(released);
13
- if (!match) throw new Error("Invalid release identity");
14
- return `${match[1]}.${BigInt(match[2]) + 1n}.0`;
15
- }
16
- /**
17
- * Cut or repair a daily/dev release without moving an existing tag. A daily is the
18
- * Release Please release `v<version>` of the source manifest's version. A dev build is
19
- * `v<next>-dev.N` for the next unreleased version (see `nextDevVersion`), where N counts
20
- * that version's dev releases from 1, so it starts again at 1 when a release moves the
21
- * next version: `v0.112.0-dev.15` is followed, after the `v0.112.0` release, by
22
- * `v0.113.0-dev.1`. A new cut also numbers above every existing dev tag of the version,
23
- * so tags with no trusted release (from an earlier release system) are skipped, never
24
- * reused or moved: with `v0.73.0-dev.1` and `dev.2` tagged but unreleased, the cut is
25
- * `v0.73.0-dev.3`.
4
+ * Repair or dispatch the daily release of the source manifest's version without moving a
5
+ * tag. Release Please creates every daily `v<version>`; this only checks its identity,
6
+ * reports it qualified or pending, or dispatches its build.
26
7
  */
27
8
  async function cutRelease(options) {
28
9
  const { kind, sourceSha, releasedVersion, provider } = options;
29
- if (!["daily", "dev"].includes(kind) || !isGitSha(sourceSha) || typeof releasedVersion !== "string" || releasedVersion.length > 48 || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(releasedVersion)) throw new Error("Invalid release identity");
30
- const version = kind === "dev" ? nextDevVersion(releasedVersion) : releasedVersion;
10
+ if (kind !== "daily" || !isGitSha(sourceSha) || typeof releasedVersion !== "string" || releasedVersion.length > 48 || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/.test(releasedVersion)) throw new Error("Invalid release identity");
31
11
  if (!await provider.isMainAncestor(sourceSha)) throw new Error("Requested source is not on main");
32
- let count = 0;
33
- if (kind === "dev") {
34
- const highest = await provider.highestDevCounter(version);
35
- if (!Number.isSafeInteger(highest) || highest < 0) throw new Error("Dev release history is invalid");
36
- const newest = highest > 0 ? await provider.find(`v${version}-dev.${highest}`) : null;
37
- if (highest > 0 && !newest) throw new Error("Dev release history changed");
38
- if (newest && newest.sourceSha !== sourceSha && !await provider.isAncestor(newest.sourceSha, sourceSha)) throw new Error("Dev release source is not newer than the last dev release");
39
- count = newest?.sourceSha === sourceSha ? highest : highest + 1;
40
- if (count > highest) {
41
- const tagged = await provider.highestDevTag(version);
42
- if (!Number.isSafeInteger(tagged) || tagged < 0) throw new Error("Dev tag history is invalid");
43
- count = Math.max(count, tagged + 1);
44
- }
45
- }
46
- const tag = `v${version}${kind === "dev" ? `-dev.${count}` : ""}`;
47
- let release = await provider.find(tag);
48
- if (!release) {
49
- if (kind === "daily") throw new Error("Release Please has not released this version");
50
- if (await provider.tagExists(tag)) throw new Error("Existing tag has no trusted release");
51
- await provider.create({
52
- tag,
53
- sourceSha
54
- });
55
- release = await provider.find(tag);
56
- }
57
- if (!release || release.tag !== tag || release.kind !== kind || release.draft && !(kind === "daily" && release.stageableDraft === true) || !isGitSha(release.sourceSha) || kind === "dev" && release.sourceSha !== sourceSha || !await provider.isMainAncestor(release.sourceSha)) throw new Error("Existing release identity mismatch");
12
+ const tag = `v${releasedVersion}`;
13
+ const release = await provider.find(tag);
14
+ if (!release) throw new Error("Release Please has not released this version");
15
+ if (release.tag !== tag || release.kind !== kind || release.draft && release.stageableDraft !== true || !isGitSha(release.sourceSha) || !await provider.isMainAncestor(release.sourceSha)) throw new Error("Existing release identity mismatch");
58
16
  const qualification = await provider.qualification(release);
59
17
  if (qualification === "qualified") return {
60
18
  tag,
@@ -71,10 +29,6 @@ async function cutRelease(options) {
71
29
  if (pending !== "idle") throw new Error("Release build state is unknown");
72
30
  const current = await provider.find(tag);
73
31
  if (!current || current.sourceSha !== release.sourceSha || current.kind !== kind || current.draft !== release.draft || (current.draft ? current.stageableDraft !== true : !current.prerelease) || !await provider.isMainAncestor(current.sourceSha)) throw new Error("Release changed before build dispatch");
74
- if (kind === "dev") {
75
- const latest = await provider.highestDevCounter(version);
76
- if (!Number.isSafeInteger(latest) || latest !== count) throw new Error("Dev release history changed before dispatch");
77
- }
78
32
  await provider.dispatch(tag);
79
33
  return {
80
34
  tag,
@@ -82,4 +36,4 @@ async function cutRelease(options) {
82
36
  status: "dispatched"
83
37
  };
84
38
  }
85
- export { cutRelease, nextDevVersion };
39
+ export { cutRelease };
@@ -6,7 +6,8 @@ import { discoveryPolicies, parseReleaseConfig, platformPayloads, platformTarget
6
6
  import { validateCommandReceipts, validateInstallerReceipt } from "./release-qualification.js";
7
7
  import { feedUrl } from "../updates/feed/release-feed.js";
8
8
  import { signReleaseDescriptor, verifyReleaseDescriptor } from "../updates/feed/signed-release.js";
9
- import { lstat, readFile, writeFile } from "node:fs/promises";
9
+ import { readJsonFile } from "../shared/file-system.js";
10
+ import { lstat, writeFile } from "node:fs/promises";
10
11
  import { join, resolve } from "node:path";
11
12
  import { createPublicKey } from "node:crypto";
12
13
  // src/release/release-descriptor-staging.ts
@@ -83,13 +84,7 @@ function configuredSigningKey(config, keyId, privateKey) {
83
84
  if (typeof encoded !== "string" || encoded !== publicKey) throw new Error("Signing key does not match configured trust");
84
85
  return encoded;
85
86
  }
86
- async function receipt(path) {
87
- const info = await lstat(path);
88
- if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > 262144) throw new Error("Invalid receipt");
89
- const bytes = await readFile(path);
90
- if (bytes.length !== info.size) throw new Error("Receipt changed");
91
- return JSON.parse(bytes.toString("utf8"));
92
- }
87
+ var receipt = (path) => readJsonFile(path, 262144, "receipt");
93
88
  /** Sign descriptors only for payloads verified by every installer and command artifact receipt. */
94
89
  async function stageReleaseDescriptors(options) {
95
90
  const { env, config, tag, keyId, privateKey } = options;
@@ -1,4 +1,5 @@
1
1
  import { versionLessThan } from "../updates/feed/release-version.js";
2
+ import { hasCutterMarker } from "./github-release-provenance.js";
2
3
  // src/release/release-promotion.ts
3
4
  function order(a, b) {
4
5
  return Date.parse(a.publishedAt) - Date.parse(b.publishedAt) || a.id - b.id;
@@ -39,7 +40,7 @@ async function promoteDailyRelease(options) {
39
40
  tags.add(release.tag);
40
41
  }
41
42
  const compareVersion = (a, b) => versionLessThan(a.tag, b.tag) ? -1 : versionLessThan(b.tag, a.tag) ? 1 : order(a, b);
42
- const dailies = releases.filter((release) => !release.draft && Date.parse(release.publishedAt) <= now && eligibleTag(release.tag) && !release.body.split(/\r?\n/).some((line) => line.startsWith("adea-channel:") || line.startsWith("Source: "))).sort(order);
43
+ const dailies = releases.filter((release) => !release.draft && Date.parse(release.publishedAt) <= now && eligibleTag(release.tag) && !hasCutterMarker(release.body)).sort(order);
43
44
  const stableReleases = dailies.filter((release) => !release.prerelease && stableTime(release) !== void 0);
44
45
  stableReleases.sort(compareVersion);
45
46
  const stable = stableReleases.at(-1);
@@ -1,8 +1,8 @@
1
- import { isGitSha, isRecord } from "../app/value-guards.js";
1
+ import { isGitSha } from "../app/value-guards.js";
2
2
  import { githubCli, verifyWorkflowAttempt } from "./github-cli.js";
3
3
  import { createGitHubReleasePublisher } from "./github-release-publisher.js";
4
4
  import { publishQualifiedRelease } from "./release-publication.js";
5
- import { discoveryPolicies, hostedReleaseWorkflows, parseReleaseConfig } from "./release-config.js";
5
+ import { discoveryPolicies, hostedReleaseWorkflows, parseReleaseConfig, releaseVerificationKeys } from "./release-config.js";
6
6
  import { commandReceiptName } from "../installer/command-qualification-command.js";
7
7
  import { feedUrl } from "../updates/feed/release-feed.js";
8
8
  import { assertRepositorySlug } from "../updates/feed/signed-release.js";
@@ -30,21 +30,11 @@ async function boundedJson(path) {
30
30
  /** Publish only the current trusted release-assets attempt and its staged receipts. */
31
31
  async function runReleasePublishCommand(options) {
32
32
  const { env, config } = options;
33
- if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !isGitSha(env.SOURCE_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || !/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(env.RELEASE_TAG ?? "")) throw new Error("Publication requires a trusted release-assets workflow");
33
+ if (env.GITHUB_ACTIONS !== "true" || env.GITHUB_REF !== "refs/heads/main" || env.GITHUB_EVENT_NAME !== "workflow_dispatch" || !env.GITHUB_REPOSITORY || !isGitSha(env.GITHUB_SHA) || !isGitSha(env.SOURCE_SHA) || !/^[1-9]\d{0,19}$/.test(env.GITHUB_RUN_ID ?? "") || !/^[1-9]\d{0,8}$/.test(env.GITHUB_RUN_ATTEMPT ?? "") || !/^v\d+\.\d+\.\d+$/.test(env.RELEASE_TAG ?? "")) throw new Error("Publication requires a trusted release-assets workflow");
34
34
  assertRepositorySlug(env.GITHUB_REPOSITORY);
35
35
  const { requirements, releasePleaseManifestPath, releaseWorkflows, feed } = parseReleaseConfig(config);
36
- if (!isRecord(config) || typeof config.appId !== "string" || !/^[a-z][a-z0-9-]*(?:\.[a-z][a-z0-9-]*)+$/.test(config.appId) || config.appId.length > 255 || !isRecord(config.releaseSigningKeys) || !isRecord(config.descriptors)) throw new Error("Invalid release signing configuration");
37
- const keyEntries = Object.entries(config.releaseSigningKeys);
38
- if (!keyEntries.length || keyEntries.length > 16) throw new Error("Missing release verification keys");
39
- const keys = /* @__PURE__ */ new Map();
40
- for (const [id, encoded] of keyEntries) {
41
- if (!/^[a-z0-9][a-z0-9._-]{0,63}$/.test(id) || typeof encoded !== "string") throw new Error("Invalid release verification key");
42
- const raw = Buffer.from(encoded, "base64");
43
- if (raw.length !== 32 || raw.toString("base64") !== encoded) throw new Error("Invalid release verification key");
44
- keys.set(id, encoded);
45
- }
36
+ const keys = releaseVerificationKeys(config);
46
37
  const tag = env.RELEASE_TAG, repository = env.GITHUB_REPOSITORY, releaseRequirements = requirements(tag);
47
- const isDev = tag.includes("-dev.");
48
38
  const discoveryTrust = {};
49
39
  for (const policy of discoveryPolicies(config, tag)) discoveryTrust[policy.name] = {
50
40
  trust: {
@@ -94,7 +84,7 @@ async function runReleasePublishCommand(options) {
94
84
  ...commandReceipts ? { commandReceipts } : {},
95
85
  discoveryTrust,
96
86
  remote,
97
- allowDraft: !isDev
87
+ allowDraft: true
98
88
  });
99
89
  }
100
90
  export { runReleasePublishCommand };
@@ -76,7 +76,7 @@ function validateInstallerReceipt(identity, entry, platform, names, assets, offl
76
76
  return true;
77
77
  }
78
78
  function assertIdentity(identity, platform) {
79
- assert(/^v\d+\.\d+\.\d+(?:-dev\.\d+)?$/.test(identity.tag) && isGitSha(identity.sourceSha) && isGitSha(identity.workflowSha) && /^[1-9]\d{0,19}$/.test(identity.runId) && Number.isSafeInteger(identity.runAttempt) && identity.runAttempt > 0 && /^[a-z0-9-]+$/.test(platform), "Invalid receipt context");
79
+ assert(/^v\d+\.\d+\.\d+$/.test(identity.tag) && isGitSha(identity.sourceSha) && isGitSha(identity.workflowSha) && /^[1-9]\d{0,19}$/.test(identity.runId) && Number.isSafeInteger(identity.runAttempt) && identity.runAttempt > 0 && /^[a-z0-9-]+$/.test(platform), "Invalid receipt context");
80
80
  }
81
81
  /** Validate one command artifact receipt against the exact attempt and payload bytes. */
82
82
  function validateCommandReceipt(identity, entry, kind, platform, name, assets) {
@@ -0,0 +1,33 @@
1
+ /** Why a bounded read refused a body. */
2
+ export type BoundedBodyFailure = 'too-large' | 'aborted' | 'invalid' | 'missing';
3
+ /** A body that a bounded read refused; `reason` maps to a status (413, 408 or 400). */
4
+ export declare class BoundedBodyError extends Error {
5
+ readonly reason: BoundedBodyFailure;
6
+ constructor(reason: BoundedBodyFailure, message?: string, options?: ErrorOptions);
7
+ }
8
+ /** A request or response, or anything else with a byte stream and headers. */
9
+ export type BoundedBodySource = Readonly<{
10
+ body: ReadableStream<Uint8Array> | null;
11
+ headers: Headers;
12
+ }>;
13
+ export type BoundedBodyOptions = Readonly<{
14
+ /** Cancels the read and refuses the body with `aborted`. A request's own signal is used by default. */
15
+ signal?: AbortSignal;
16
+ /** Read a missing body as empty instead of refusing it with `missing`. */
17
+ allowEmpty?: boolean;
18
+ }>;
19
+ /**
20
+ * Reads a body into bytes, bounding the bytes actually streamed.
21
+ *
22
+ * Content-Length is only a claim: it may be absent or wrong, so it never admits a body on its
23
+ * own. A malformed claim, or one above `limit`, is refused before any byte is read. Otherwise
24
+ * the first chunk that crosses `limit` cancels the stream, so an oversized body is never held
25
+ * whole. An abort settles the read at once, even while a chunk is pending.
26
+ */
27
+ export declare function readBoundedBytes(source: BoundedBodySource, limit: number, options?: BoundedBodyOptions): Promise<Uint8Array>;
28
+ /** Reads a body of at most `limit` bytes as strict UTF-8. */
29
+ export declare function readBoundedText(source: BoundedBodySource, limit: number, options?: BoundedBodyOptions): Promise<string>;
30
+ /** Reads a body of at most `limit` bytes as strict UTF-8 JSON. */
31
+ export declare function readBoundedJson(source: BoundedBodySource, limit: number, options?: BoundedBodyOptions): Promise<unknown>;
32
+ /** The HTTP status a refused body maps to. */
33
+ export declare function boundedBodyStatus(error: BoundedBodyError): 400 | 408 | 413;
@@ -0,0 +1,102 @@
1
+ import { discardStream } from "./discard-stream.js";
2
+ // src/shared/bounded-body.ts
3
+ /** A body that a bounded read refused; `reason` maps to a status (413, 408 or 400). */
4
+ var BoundedBodyError = class extends Error {
5
+ reason;
6
+ constructor(reason, message = `Body ${reason}`, options) {
7
+ super(message, options);
8
+ this.name = "BoundedBodyError";
9
+ this.reason = reason;
10
+ }
11
+ };
12
+ var signalOf = (source, options) => options?.signal ?? (source instanceof Request ? source.signal : void 0);
13
+ /**
14
+ * Reads a body into bytes, bounding the bytes actually streamed.
15
+ *
16
+ * Content-Length is only a claim: it may be absent or wrong, so it never admits a body on its
17
+ * own. A malformed claim, or one above `limit`, is refused before any byte is read. Otherwise
18
+ * the first chunk that crosses `limit` cancels the stream, so an oversized body is never held
19
+ * whole. An abort settles the read at once, even while a chunk is pending.
20
+ */
21
+ async function readBoundedBytes(source, limit, options) {
22
+ if (!Number.isSafeInteger(limit) || limit < 0) throw new RangeError("Invalid body limit");
23
+ const claimed = source.headers.get("content-length");
24
+ if (claimed !== null && (!/^\d+$/.test(claimed) || Number(claimed) > limit)) {
25
+ discardStream(source.body);
26
+ throw new BoundedBodyError("too-large");
27
+ }
28
+ const signal = signalOf(source, options);
29
+ if (signal?.aborted) {
30
+ discardStream(source.body);
31
+ throw new BoundedBodyError("aborted");
32
+ }
33
+ if (!source.body) {
34
+ if (options?.allowEmpty) return /* @__PURE__ */ new Uint8Array(0);
35
+ throw new BoundedBodyError("missing");
36
+ }
37
+ const reader = source.body.getReader();
38
+ let abort;
39
+ const aborted = signal ? new Promise((_, reject) => {
40
+ abort = () => {
41
+ discardStream(reader);
42
+ reject(new BoundedBodyError("aborted"));
43
+ };
44
+ signal.addEventListener("abort", abort, { once: true });
45
+ }) : void 0;
46
+ aborted?.catch(() => {});
47
+ const chunks = [];
48
+ let total = 0;
49
+ try {
50
+ for (;;) {
51
+ const next = await (aborted ? Promise.race([reader.read(), aborted]) : reader.read());
52
+ if (signal?.aborted) throw new BoundedBodyError("aborted");
53
+ if (next.done) break;
54
+ total += next.value.byteLength;
55
+ if (total > limit) {
56
+ discardStream(reader);
57
+ throw new BoundedBodyError("too-large");
58
+ }
59
+ chunks.push(next.value);
60
+ }
61
+ } catch (error) {
62
+ if (error instanceof BoundedBodyError) throw error;
63
+ throw new BoundedBodyError("invalid", "Body stream failed", { cause: error });
64
+ } finally {
65
+ if (abort) signal?.removeEventListener("abort", abort);
66
+ try {
67
+ reader.releaseLock();
68
+ } catch {}
69
+ }
70
+ if (chunks.length === 1) return chunks[0];
71
+ const bytes = new Uint8Array(total);
72
+ let offset = 0;
73
+ for (const chunk of chunks) {
74
+ bytes.set(chunk, offset);
75
+ offset += chunk.byteLength;
76
+ }
77
+ return bytes;
78
+ }
79
+ var strictUtf8 = new TextDecoder("utf-8", { fatal: true });
80
+ /** Reads a body of at most `limit` bytes as strict UTF-8. */
81
+ async function readBoundedText(source, limit, options) {
82
+ const bytes = await readBoundedBytes(source, limit, options);
83
+ try {
84
+ return strictUtf8.decode(bytes);
85
+ } catch {
86
+ throw new BoundedBodyError("invalid", "Body is not UTF-8");
87
+ }
88
+ }
89
+ /** Reads a body of at most `limit` bytes as strict UTF-8 JSON. */
90
+ async function readBoundedJson(source, limit, options) {
91
+ const text = await readBoundedText(source, limit, options);
92
+ try {
93
+ return JSON.parse(text);
94
+ } catch {
95
+ throw new BoundedBodyError("invalid", "Body is not JSON");
96
+ }
97
+ }
98
+ /** The HTTP status a refused body maps to. */
99
+ function boundedBodyStatus(error) {
100
+ return error.reason === "too-large" ? 413 : error.reason === "aborted" ? 408 : 400;
101
+ }
102
+ export { BoundedBodyError, boundedBodyStatus, readBoundedBytes, readBoundedJson, readBoundedText };
@@ -0,0 +1,12 @@
1
+ /** Whether a path exists, without following a final symbolic link. Only ENOENT means
2
+ * absent; permission and path errors surface. */
3
+ export declare function pathExists(path: string): Promise<boolean>;
4
+ /** Sync a directory's entries to disk, after a rename, link or unlink inside it. */
5
+ export declare function syncDirectory(path: string): Promise<void>;
6
+ /**
7
+ * Read a regular file (not a link) of 1 to `maxBytes` bytes whole. `name` words the
8
+ * errors: `Invalid <name>`, and `<Name> changed` when the size moved during the read.
9
+ */
10
+ export declare function readBoundedFile(path: string, maxBytes: number, name: string): Promise<NonSharedBuffer>;
11
+ /** Parse a JSON file through `readBoundedFile`. */
12
+ export declare function readJsonFile(path: string, maxBytes: number, name?: string): Promise<unknown>;
@@ -0,0 +1,40 @@
1
+ import { errorCode } from "../app/value-guards.js";
2
+ import { lstat, open, readFile } from "node:fs/promises";
3
+ import { constants as constants$1 } from "node:fs";
4
+ // src/shared/file-system.ts
5
+ /** Whether a path exists, without following a final symbolic link. Only ENOENT means
6
+ * absent; permission and path errors surface. */
7
+ async function pathExists(path) {
8
+ try {
9
+ await lstat(path);
10
+ return true;
11
+ } catch (error) {
12
+ if (errorCode(error) === "ENOENT") return false;
13
+ throw error;
14
+ }
15
+ }
16
+ /** Sync a directory's entries to disk, after a rename, link or unlink inside it. */
17
+ async function syncDirectory(path) {
18
+ const directory = await open(path, constants$1.O_RDONLY);
19
+ try {
20
+ await directory.sync();
21
+ } finally {
22
+ await directory.close();
23
+ }
24
+ }
25
+ /**
26
+ * Read a regular file (not a link) of 1 to `maxBytes` bytes whole. `name` words the
27
+ * errors: `Invalid <name>`, and `<Name> changed` when the size moved during the read.
28
+ */
29
+ async function readBoundedFile(path, maxBytes, name) {
30
+ const info = await lstat(path);
31
+ if (!info.isFile() || info.size < 1 || info.size > maxBytes) throw new Error(`Invalid ${name}`);
32
+ const bytes = await readFile(path);
33
+ if (bytes.length !== info.size) throw new Error(`${name[0].toUpperCase()}${name.slice(1)} changed`);
34
+ return bytes;
35
+ }
36
+ /** Parse a JSON file through `readBoundedFile`. */
37
+ async function readJsonFile(path, maxBytes, name = "configuration file") {
38
+ return JSON.parse((await readBoundedFile(path, maxBytes, name)).toString("utf8"));
39
+ }
40
+ export { pathExists, readBoundedFile, readJsonFile, syncDirectory };