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:
@@ -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",
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user