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.
This commit is contained in:
can1357
2026-04-07 21:29:56 +02:00
parent efd5343388
commit 3f60675662
3 changed files with 14 additions and 7 deletions
-3
View File
@@ -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",
+13 -1
View File
@@ -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");
+1 -3
View File
@@ -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"