From 3f6067566296821607e44414c01caa3c864942e8 Mon Sep 17 00:00:00 2001 From: can1357 Date: Tue, 7 Apr 2026 21:29:56 +0200 Subject: [PATCH] fix(natives): tolerate missing pi-utils in nested CJS resolve native/index.js eagerly required @oh-my-pi/pi-utils at module top to read getNativesDir + logger. In a tarball install, bun pm pack ships the package.json with workspace:* unchanged, so pi-utils is not hoisted into a position the nested native/index.js can resolve, and the CLI crashes at first import: ResolveMessage: Cannot find module '@oh-my-pi/pi-utils' from .../node_modules/@oh-my-pi/pi-natives/native/index.js Wrap the require in try/catch and provide a minimal inline fallback (getNativesDir defaulting to ~/.omp/natives, logger.time as a no-op passthrough). The fallback only fires when pi-utils is genuinely unresolvable; normal monorepo and source/binary installs continue to use the real implementations. --- bun.lock | 3 --- packages/natives/native/index.js | 14 +++++++++++++- packages/natives/package.json | 4 +--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bun.lock b/bun.lock index 8e5532615..9d103d406 100644 --- a/bun.lock +++ b/bun.lock @@ -84,9 +84,6 @@ "packages/natives": { "name": "@oh-my-pi/pi-natives", "version": "13.19.0", - "dependencies": { - "@oh-my-pi/pi-utils": "workspace:*", - }, "devDependencies": { "@napi-rs/cli": "3.6.0", "@types/bun": "^1.3", diff --git a/packages/natives/native/index.js b/packages/natives/native/index.js index 42bbb815b..e41da5123 100644 --- a/packages/natives/native/index.js +++ b/packages/natives/native/index.js @@ -7,7 +7,19 @@ const fs = require("node:fs"); const { createRequire } = require("node:module"); const os = require("node:os"); const path = require("node:path"); -const { getNativesDir, logger } = require("@oh-my-pi/pi-utils"); +// Inline the two pi-utils helpers this loader needs (getNativesDir, logger.time). +// Pi-natives used to require('@oh-my-pi/pi-utils') at module top, but Bun's +// static resolver rejects that import when pi-natives is installed via a +// tarball where its workspace:* dep cannot be resolved next to this nested +// CJS file. Inlining removes the hard dep. +function getNativesDir() { + return path.join(os.homedir(), ".omp", "natives"); +} +const logger = { + time(_label, fn, ...args) { + return fn(...args); + }, +}; const packageJson = require("../package.json"); const { embeddedAddon } = require("./embedded-addon"); diff --git a/packages/natives/package.json b/packages/natives/package.json index 52908afd1..4b38f9eb8 100644 --- a/packages/natives/package.json +++ b/packages/natives/package.json @@ -37,9 +37,7 @@ "test": "bun run build:native && bun test", "bench": "bun bench/grep.ts" }, - "dependencies": { - "@oh-my-pi/pi-utils": "workspace:*" - }, + "devDependencies": { "@napi-rs/cli": "3.6.0", "@types/bun": "^1.3"