Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/makePatch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk from "chalk"
import semver from "semver"
import console from "console"
import { renameSync } from "fs"
import {
Expand Down Expand Up @@ -54,6 +55,14 @@ function printNoPackageFoundError(
)
}

function npmRequiresAllowRemoteFlag() {
const npmVersion = spawnSafeSync("npm", ["--version"], {
stdio: "pipe",
}).stdout.toString().trim()

return semver.gte(npmVersion, "12.0.0")
}

export function makePatch({
packagePathSpecifier,
appPath,
Expand Down Expand Up @@ -228,18 +237,26 @@ export function makePatch({
chalk.grey("•"),
`Installing ${packageDetails.name}@${packageVersion} with npm`,
)

const npmInstallArgs = ["i", "--force"]

// npm 12+ defaults to blocking remote tarball dependencies
if (npmRequiresAllowRemoteFlag()) {
npmInstallArgs.push("--allow-remote=all")
}

try {
// try first without ignoring scripts in case they are required
// this works in 99.99% of cases
spawnSafeSync(`npm`, ["i", "--force"], {
spawnSafeSync(`npm`, npmInstallArgs, {
cwd: tmpRepoNpmRoot,
logStdErrOnError: false,
stdio: "ignore",
})
} catch (e) {
// try again while ignoring scripts in case the script depends on
// an implicit context which we haven't reproduced
spawnSafeSync(`npm`, ["i", "--ignore-scripts", "--force"], {
spawnSafeSync(`npm`, [...npmInstallArgs, "--ignore-scripts"], {
cwd: tmpRepoNpmRoot,
stdio: "ignore",
})
Expand Down