@xynogen/pix-commands 0.1.1 → 0.1.2
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 +1 -1
- package/src/extension.ts +5 -2
- package/src/once.ts +16 -0
package/package.json
CHANGED
package/src/extension.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import registerClear from "./clear.ts";
|
|
3
3
|
import registerDiff from "./diff.ts";
|
|
4
|
+
import { once } from "./once.ts";
|
|
4
5
|
|
|
5
6
|
export default function (pi: ExtensionAPI): void {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
once("pix-commands", () => {
|
|
8
|
+
registerDiff(pi);
|
|
9
|
+
registerClear(pi);
|
|
10
|
+
});
|
|
8
11
|
}
|
package/src/once.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency guard for extension activation.
|
|
3
|
+
*
|
|
4
|
+
* pix-core (the meta-package) invokes this package's factory in addition to a
|
|
5
|
+
* possible direct install. Pi's loader uses jiti with `moduleCache: false`, so
|
|
6
|
+
* each load pass re-evaluates modules — a plain module-level flag would not be
|
|
7
|
+
* shared. The dedupe key therefore lives on `globalThis`, which persists for
|
|
8
|
+
* the lifetime of the process across all load passes.
|
|
9
|
+
*/
|
|
10
|
+
export function once(key: string, fn: () => void): void {
|
|
11
|
+
const g = globalThis as { __pixLoaded?: Set<string> };
|
|
12
|
+
const loaded = (g.__pixLoaded ??= new Set<string>());
|
|
13
|
+
if (loaded.has(key)) return;
|
|
14
|
+
loaded.add(key);
|
|
15
|
+
fn();
|
|
16
|
+
}
|