@hypit/hypit 0.1.9 → 0.1.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hypit/hypit",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "homepage": "https://hypit.ai",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,8 +81,14 @@ export function declaredExternalPackageRoot(root: string, from: string | URL, na
81
81
  while (true) {
82
82
  const manifest = join(cursor, "package.json");
83
83
  if (existsSync(manifest)) {
84
- const value = JSON.parse(readFileSync(manifest, "utf8")) as { dependencies?: Record<string, string> };
85
- const version = value.dependencies?.[name];
84
+ const value = JSON.parse(readFileSync(manifest, "utf8")) as {
85
+ dependencies?: Record<string, string>;
86
+ optionalDependencies?: Record<string, string>;
87
+ };
88
+ // An upstream asset a package ships as optional is still selected by one exact version here.
89
+ // `hypit packages install` places it under the machine npm root named by this selection, so
90
+ // reading only the required map makes the documented repair unusable for every optional asset.
91
+ const version = value.dependencies?.[name] ?? value.optionalDependencies?.[name];
86
92
  return version === undefined ? undefined : externalPackageInstallRoot(root, name, version);
87
93
  }
88
94
  const parent = dirname(cursor);
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Preloaded into the disposable capture process, which never enters `bin/hypit.mjs`.
3
+ *
4
+ * `module.registerHooks` is process-local, so the resolver the launcher installs does not
5
+ * reach a child that Node starts directly. This registers the same resolution environment
6
+ * in the child, so its view of `@hypit/*` and of the machine packages those modules declare
7
+ * is identical to its parent's.
8
+ *
9
+ * Only relative paths can be used here: no hook exists yet, and a Distribution ships its
10
+ * package sources without any `node_modules` link between them.
11
+ */
12
+ import { resolve } from "node:path";
13
+
14
+ // `bin/hypit.mjs` publishes this for every process it starts; the fallback mirrors
15
+ // `packages/video-cli/src/distribution.ts` for callers that import a Distribution directly.
16
+ const distributionRoot = resolve(
17
+ process.env.HYPIT_DISTRIBUTION_ROOT ?? resolve(import.meta.dirname, "../../.."),
18
+ );
19
+
20
+ const { installDistributionPackageResolution, installExternalPackageResolution } =
21
+ await import("../../package-loader-node/src/distribution-resolution.js");
22
+ installDistributionPackageResolution([distributionRoot]);
23
+
24
+ const { hypitHostPackageRoot } = await import("../../runtime-host-node/src/index.js");
25
+ installExternalPackageResolution([hypitHostPackageRoot()]);
@@ -62,7 +62,13 @@ export async function runCaptureProcess(
62
62
  ): Promise<void> {
63
63
  signal.throwIfAborted();
64
64
  await new Promise<void>((resolve, reject) => {
65
- const child = spawn(process.execPath, ["--import", import.meta.resolve("tsx"), fileURLToPath(entry)], {
65
+ // The launcher's resolver hooks are process-local, so this child preloads the same
66
+ // environment before it imports any package the Distribution owns.
67
+ const child = spawn(process.execPath, [
68
+ "--import", import.meta.resolve("tsx"),
69
+ "--import", new URL("./capture-bootstrap.ts", import.meta.url).href,
70
+ fileURLToPath(entry),
71
+ ], {
66
72
  detached: process.platform !== "win32", windowsHide: true,
67
73
  stdio: ["ignore", "pipe", "pipe", "ipc"],
68
74
  });
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from "node:fs";
1
2
  import { requestDeadline } from "@hypit/runtime-kit";
2
3
  import type { AsyncEndpoint, EndpointCredential, EndpointFulfillment, EndpointInvocationContext, EndpointPollContext, EndpointPricingReader, EndpointStartContext, EndpointOutcome, ImmediateEndpointHandler } from "@hypit/endpoint-kit";
3
4
  import { defineEndpointPackage, wakeAfter } from "@hypit/endpoint-kit";
@@ -23,6 +24,29 @@ import { createHypiHubAuth, hypiHubCredentialNeedsRefresh } from "./oauth.js";
23
24
  import type { HypiHubAuth } from "./oauth.js";
24
25
  import { HypiHubHttpError, HypiHubServiceError, hypiHubJobFailure } from "./errors.js";
25
26
 
27
+ function distributionVersion(): string {
28
+ try {
29
+ const manifest = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8")) as {
30
+ readonly name?: unknown; readonly version?: unknown;
31
+ };
32
+ if (manifest.name !== "@hypit/hypit" || typeof manifest.version !== "string" || manifest.version.length === 0) {
33
+ return "unknown";
34
+ }
35
+ return manifest.version;
36
+ } catch {
37
+ return "unknown";
38
+ }
39
+ }
40
+
41
+ const userAgent = `hypit/${distributionVersion()}`;
42
+
43
+ const identifiedFetch = (fetcher: typeof globalThis.fetch): typeof globalThis.fetch =>
44
+ async (input, init) => {
45
+ const headers: Record<string, string> = { "user-agent": userAgent };
46
+ new Headers(init?.headers).forEach((value, name) => { headers[name] = value; });
47
+ return await fetcher(input, { ...init, headers });
48
+ };
49
+
26
50
  export const hypiHubProviderModuleRef = { name: "@hypit/provider-hypihub", version: "1" } as const;
27
51
 
28
52
  export type CreateHypiHubProviderOptions = {
@@ -113,7 +137,7 @@ class HypiHubClient {
113
137
  this.timeout = options.timeout;
114
138
  this.oauthTimeout = options.oauthTimeout;
115
139
  this.downloadAttempts = options.downloadAttempts;
116
- this.fetcher = options.fetcher;
140
+ this.fetcher = identifiedFetch(options.fetcher);
117
141
  this.uploader = new HypiHubUploader({
118
142
  baseUrl: this.baseUrl,
119
143
  requestTimeoutMs: this.timeout,