Files
cloud-code/claude-code-source/node_modules/.pnpm/npm-run-path@6.0.0/node_modules/npm-run-path/index.js
janlaywss 6187147b74 reconstruct and build @anthropic-ai/claude-code source from source map
- Extract 4756 source files from cli.js.map (57MB)
- Set up Bun build system with bun:bundle feature flag shim
- Configure 90+ compile-time feature flags matching production defaults
- Inject MACRO constants (VERSION, BUILD_TIME, etc.)
- Create stubs for private packages (color-diff-napi, modifiers-napi, etc.)
- Install all public dependencies via pnpm
- Patch commander v14 to allow multi-char short flags (-d2e)
- Build output: dist/cli.js (22MB), verified working
2026-03-31 19:19:50 +08:00

56 lines
1.4 KiB
JavaScript

import process from 'node:process';
import path from 'node:path';
import pathKey from 'path-key';
import {toPath, traversePathUp} from 'unicorn-magic';
export const npmRunPath = ({
cwd = process.cwd(),
path: pathOption = process.env[pathKey()],
preferLocal = true,
execPath = process.execPath,
addExecPath = true,
} = {}) => {
const cwdPath = path.resolve(toPath(cwd));
const result = [];
const pathParts = pathOption.split(path.delimiter);
if (preferLocal) {
applyPreferLocal(result, pathParts, cwdPath);
}
if (addExecPath) {
applyExecPath(result, pathParts, execPath, cwdPath);
}
return pathOption === '' || pathOption === path.delimiter
? `${result.join(path.delimiter)}${pathOption}`
: [...result, pathOption].join(path.delimiter);
};
const applyPreferLocal = (result, pathParts, cwdPath) => {
for (const directory of traversePathUp(cwdPath)) {
const pathPart = path.join(directory, 'node_modules/.bin');
if (!pathParts.includes(pathPart)) {
result.push(pathPart);
}
}
};
// Ensure the running `node` binary is used
const applyExecPath = (result, pathParts, execPath, cwdPath) => {
const pathPart = path.resolve(cwdPath, toPath(execPath), '..');
if (!pathParts.includes(pathPart)) {
result.push(pathPart);
}
};
export const npmRunPathEnv = ({env = process.env, ...options} = {}) => {
env = {...env};
const pathName = pathKey({env});
options.path = env[pathName];
env[pathName] = npmRunPath(options);
return env;
};