@ff-labs/pi-fff 0.10.6 → 0.10.7-nightly.097c6ff

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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/sdk.ts +37 -2
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ff-labs/pi-fff",
3
3
  "public": true,
4
- "version": "0.10.6",
4
+ "version": "0.10.7-nightly.097c6ff",
5
5
  "description": "pi extension: FFF-powered fuzzy file and content search",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -41,8 +41,8 @@
41
41
  "typecheck": "tsc --noEmit"
42
42
  },
43
43
  "dependencies": {
44
- "@ff-labs/fff-bun": "0.10.6",
45
- "@ff-labs/fff-node": "0.10.6"
44
+ "@ff-labs/fff-bun": "0.10.7-nightly.097c6ff",
45
+ "@ff-labs/fff-node": "0.10.7-nightly.097c6ff"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "@earendil-works/pi-coding-agent": "*",
package/src/sdk.ts CHANGED
@@ -9,6 +9,22 @@ export type FileFinderStatic = {
9
9
 
10
10
  let sdkPromise: Promise<{ FileFinder: FileFinderStatic }> | null = null;
11
11
 
12
+ const SDK_ORDER: Record<"bun" | "node", readonly [string, string]> = {
13
+ // fff-bun is TS-source only and cannot be imported by Bun-compiled hosts
14
+ // (e.g. omp) whose module resolver rejects .ts under node_modules, so the
15
+ // JS-compiled fff-node is kept as a fallback for every runtime.
16
+ bun: ["@ff-labs/fff-bun", "@ff-labs/fff-node"],
17
+ node: ["@ff-labs/fff-node", "@ff-labs/fff-bun"],
18
+ };
19
+
20
+ // Literal dynamic imports so hosts that statically scan extension graphs
21
+ // (omp's legacy-pi-compat loader) discover and hook both SDK packages;
22
+ // a variable `import(pkg)` would bypass that scan and fail at runtime.
23
+ const SDK_IMPORTS = {
24
+ "@ff-labs/fff-bun": () => import("@ff-labs/fff-bun"),
25
+ "@ff-labs/fff-node": () => import("@ff-labs/fff-node"),
26
+ } as const;
27
+
12
28
  function detectRuntime(): "bun" | "node" {
13
29
  if (typeof (globalThis as { Bun?: unknown }).Bun !== "undefined") return "bun";
14
30
  if (
@@ -19,6 +35,26 @@ function detectRuntime(): "bun" | "node" {
19
35
  return "node";
20
36
  }
21
37
 
38
+ /** Preferred SDK order for the detected runtime. */
39
+ export function sdkCandidates(): readonly [string, string] {
40
+ return SDK_ORDER[detectRuntime()];
41
+ }
42
+
43
+ export async function loadFirst(
44
+ candidates: readonly [string, string],
45
+ loaders: Record<string, () => Promise<unknown>> = SDK_IMPORTS,
46
+ ): Promise<{ FileFinder: FileFinderStatic }> {
47
+ let lastError: unknown;
48
+ for (const pkg of candidates) {
49
+ try {
50
+ return (await loaders[pkg]()) as { FileFinder: FileFinderStatic };
51
+ } catch (error) {
52
+ lastError = error;
53
+ }
54
+ }
55
+ throw lastError;
56
+ }
57
+
22
58
  export function loadSdk(): Promise<{ FileFinder: FileFinderStatic }> {
23
59
  if (sdkPromise) return sdkPromise;
24
60
 
@@ -34,8 +70,7 @@ export function loadSdk(): Promise<{ FileFinder: FileFinderStatic }> {
34
70
  }
35
71
 
36
72
  // default to node as it seems like default option
37
- const pkg = detectRuntime() === "bun" ? "@ff-labs/fff-bun" : "@ff-labs/fff-node";
38
- const p = import(pkg) as Promise<{ FileFinder: FileFinderStatic }>;
73
+ const p = loadFirst(sdkCandidates());
39
74
  sdkPromise = p;
40
75
  (globalThis as Record<string, unknown>).__fffSdkPromiseGlobal = p;
41
76
  return p;