mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-19 21:52:21 +03:00
fix(build): resolve npm-cli.js on POSIX layouts in the shim-free prepublish resolver (#9553)
* fix(build): resolve npm-cli.js on POSIX layouts in the shim-free prepublish resolver The #8858 resolver only tried <dir(node)>/node_modules/npm/bin — the Windows layout. On POSIX (GitHub hosted runners, nvm, system installs) npm lives at <prefix>/lib/node_modules/npm while node is <prefix>/bin/ node, so resolveBundledNpmEntry returned null and npm run build:cli died installing @omniroute/opencode-plugin deps on every fresh checkout ('npm-cli.js not found next to the running Node binary') — redding Fast Production Build and dast-smoke for the whole PR queue. Extract the resolver to scripts/build/resolveNpmEntry.ts with injectable seams and try, in order: npm_execpath (exported by npm run itself), the Windows beside-the-binary layout, the POSIX <prefix>/lib layout. TDD: tests/unit/build/resolve-npm-entry.test.ts — the POSIX-layout and npm_execpath cases plus a live regression guard fail against the old single-candidate logic (2/5) and pass with the fix (5/5). * docs(env): register the 7 env vars orphaned by the 08-05 merge batch The Docs Gates env/docs contract went red on the release tip: #9260 added OMNIROUTE_INTERNAL_SERVICE_TOKEN(_FILE) and #9324 added OPENROUTER_PROVIDER_STATS_ENABLED/_TTL_MS without .env.example entries, and the #9286 Redis sidecar vars (REDIS_BIND_HOST, REDIS_PORT, OMNIROUTE_REDIS_BIND_HOST) never reached ENVIRONMENT.md. Inherited base-red on every open PR. Defaults and descriptions taken from the consuming source files. --------- Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bca61af8ae
commit
e12d2d546b
@@ -27,6 +27,7 @@ import { join, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { assembleStandalone } from "./assembleStandalone.mjs";
|
||||
import { resolveBundledNpmEntry } from "./resolveNpmEntry.ts";
|
||||
import {
|
||||
APP_STAGING_ALLOWED_EXACT_PATHS,
|
||||
APP_STAGING_ALLOWED_PATH_PREFIXES,
|
||||
@@ -64,11 +65,6 @@ function resolveLocalBinEntry(packageName: string, binName: string): string | nu
|
||||
}
|
||||
}
|
||||
|
||||
function resolveBundledNpmEntry(name: "npm-cli.js" | "npx-cli.js"): string | null {
|
||||
const candidate = join(dirname(process.execPath), "node_modules", "npm", "bin", name);
|
||||
return existsSync(candidate) ? candidate : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a build tool without ever touching a `.cmd` shim. `packageName` is where the
|
||||
* tool lives in the local dependency tree; when it is not installed there the call
|
||||
|
||||
40
scripts/build/resolveNpmEntry.ts
Normal file
40
scripts/build/resolveNpmEntry.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { existsSync } from "fs";
|
||||
import { dirname, join } from "path";
|
||||
|
||||
/** Injectable seams for {@link resolveBundledNpmEntry} (all default to the real ones). */
|
||||
export interface ResolveNpmEntryDeps {
|
||||
execPath?: string;
|
||||
/** `process.env.npm_execpath` — set by npm itself when running under `npm run`. */
|
||||
npmExecPath?: string;
|
||||
exists?: (p: string) => boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locate `npm-cli.js` / `npx-cli.js` so build steps can run npm/npx through
|
||||
* `process.execPath` directly and never touch a `.cmd` shim (#8858), covering
|
||||
* BOTH install layouts:
|
||||
* - Windows: `<dir(node.exe)>\node_modules\npm\bin\<name>` (npm beside the binary)
|
||||
* - POSIX: `<dir(node)>/../lib/node_modules/npm/bin/<name>` (node under `<prefix>/bin`,
|
||||
* the shape of GitHub hosted runners, nvm and system installs)
|
||||
* When the script itself runs under `npm run`, npm exports `npm_execpath` pointing at
|
||||
* its own npm-cli.js — the most reliable source, tried first (npx-cli.js is its sibling).
|
||||
*/
|
||||
export function resolveBundledNpmEntry(
|
||||
name: "npm-cli.js" | "npx-cli.js",
|
||||
deps: ResolveNpmEntryDeps = {}
|
||||
): string | null {
|
||||
const execPath = deps.execPath ?? process.execPath;
|
||||
const exists = deps.exists ?? existsSync;
|
||||
const npmExecPath = deps.npmExecPath ?? process.env.npm_execpath;
|
||||
|
||||
const binDir = dirname(execPath);
|
||||
const candidates: string[] = [];
|
||||
if (npmExecPath) candidates.push(join(dirname(npmExecPath), name));
|
||||
candidates.push(join(binDir, "node_modules", "npm", "bin", name));
|
||||
candidates.push(join(binDir, "..", "lib", "node_modules", "npm", "bin", name));
|
||||
|
||||
for (const candidate of candidates) {
|
||||
if (exists(candidate)) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user