Repository navigation
fix(installer): support npm 12 remote dependency policy #1992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1d25a60
fix(installer): support npm 12 remote dependency policy
sethkarten 998e0c5
fix(installer): allow verified npm 12 postinstall
sethkarten af4798b
refactor(installer): simplify npm 12 coverage
sethkarten 3498b0e
refactor(installer): consolidate installer checks
sethkarten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Fixed the stable installer failing under npm 12 when resolving verified release dependencies. ([Discussion #1988](https://github.com/PrimeIntellect-ai/prime-agent/discussions/1988)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { spawnSync } from "node:child_process"; | ||
| import { chmodSync, mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { delimiter, join } from "node:path"; | ||
|
|
||
| const installerSource = readFileSync("install.sh", "utf-8"); | ||
| const mainCall = '\nmain "$@"'; | ||
| const mainCallIndex = installerSource.lastIndexOf(mainCall); | ||
|
|
||
| if (mainCallIndex === -1) { | ||
| console.error('Installer install check failed: could not find final main "$@" call.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const tempDir = mkdtempSync(join(tmpdir(), "prime-agent-installer-install-")); | ||
| const binDir = join(tempDir, "bin"); | ||
| const harnessPath = join(tempDir, "harness.sh"); | ||
| const npmPath = join(binDir, "npm"); | ||
| const tarballPath = join(tempDir, "verified release package.tgz"); | ||
|
|
||
| const harnessSource = `${installerSource.slice(0, mainCallIndex)} | ||
|
|
||
| prime_agent_screen_enabled=0 | ||
| prime_agent_bootstrap_kernel_on_install="$1" | ||
| install_prime_agent_package "$2" | ||
| `; | ||
|
|
||
| const npmSource = `#!/bin/sh | ||
| set -eu | ||
|
|
||
| if [ "\${1:-}" = "--version" ]; then | ||
| printf '%s\\n' "$FAKE_NPM_VERSION" | ||
| exit 0 | ||
| fi | ||
|
|
||
| if [ "\${1:-}" != install ]; then | ||
| printf 'unexpected npm command: %s\\n' "\${1:-}" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| remote_policy= | ||
| for arg in "$@"; do | ||
| case "$arg" in | ||
| --allow-remote=*) remote_policy=\${arg#*=} ;; | ||
| esac | ||
| done | ||
|
|
||
| npm_major=\${FAKE_NPM_VERSION%%.*} | ||
| if [ "$npm_major" -ge 12 ]; then | ||
| if [ "$remote_policy" != all ]; then | ||
| printf 'npm error code EALLOWREMOTE\\n' >&2 | ||
| exit 1 | ||
| fi | ||
| elif [ -n "$remote_policy" ]; then | ||
| printf 'npm error Unknown option: allow-remote\\n' >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "\${PRIME_AGENT_BOOTSTRAP_TOOLS_ON_INSTALL:-}" != 1 ]; then | ||
| printf 'missing tool bootstrap environment\\n' >&2 | ||
| exit 2 | ||
| fi | ||
| if [ "$EXPECT_KERNEL_BOOTSTRAP" = 1 ]; then | ||
| if [ "\${PRIME_AGENT_BOOTSTRAP_KERNEL_ON_INSTALL:-}" != 1 ] || [ "\${PRIME_AGENT_INSTALL_UV:-}" != 1 ]; then | ||
| printf 'missing kernel bootstrap environment\\n' >&2 | ||
| exit 2 | ||
| fi | ||
| elif [ -n "\${PRIME_AGENT_BOOTSTRAP_KERNEL_ON_INSTALL:-}" ] || [ -n "\${PRIME_AGENT_INSTALL_UV:-}" ]; then | ||
| printf 'unexpected kernel bootstrap environment\\n' >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| printf '%s\\n' "$remote_policy" > "$FAKE_NPM_RESULT" | ||
| `; | ||
|
|
||
| try { | ||
| mkdirSync(binDir); | ||
| writeFileSync(harnessPath, harnessSource, "utf-8"); | ||
| writeFileSync(npmPath, npmSource, "utf-8"); | ||
| writeFileSync(tarballPath, "verified fixture", "utf-8"); | ||
| chmodSync(npmPath, 0o755); | ||
|
|
||
| for (const npmVersion of ["10.9.8", "11.12.1", "12.0.2"]) { | ||
| for (const bootstrapKernel of [false, true]) { | ||
| const resultPath = join(tempDir, `npm-${npmVersion}-${bootstrapKernel ? "kernel" : "tools"}.txt`); | ||
| const result = spawnSync("sh", [harnessPath, bootstrapKernel ? "1" : "0", tarballPath], { | ||
| encoding: "utf-8", | ||
| env: { | ||
| ...process.env, | ||
| EXPECT_KERNEL_BOOTSTRAP: bootstrapKernel ? "1" : "0", | ||
| FAKE_NPM_RESULT: resultPath, | ||
| FAKE_NPM_VERSION: npmVersion, | ||
| PATH: `${binDir}${delimiter}${process.env.PATH ?? ""}`, | ||
| }, | ||
| }); | ||
| if (result.status !== 0) { | ||
| console.error( | ||
| `Installer install check failed for npm ${npmVersion} (${bootstrapKernel ? "kernel" : "tools"}):\n${result.stderr}${result.stdout}`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const remotePolicy = readFileSync(resultPath, "utf-8").trim(); | ||
| const expectedPolicy = npmVersion.startsWith("12.") ? "all" : ""; | ||
| if (remotePolicy !== expectedPolicy) { | ||
| console.error( | ||
| `Installer install check failed for npm ${npmVersion}: expected remote policy ${JSON.stringify(expectedPolicy)}, got ${JSON.stringify(remotePolicy)}.`, | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| } | ||
| } | ||
| } finally { | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
|
|
||
| console.log("Installer install check passed."); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.