(spec, branch = 'main', opts)
| 118 | } |
| 119 | |
| 120 | const main = async (spec, branch = 'main', opts) => withTempDir(CWD, async (tmpDir) => { |
| 121 | const { GITHUB_TOKEN } = process.env |
| 122 | const { dryRun, registryOnly, localTest } = opts |
| 123 | |
| 124 | if (!spec) { |
| 125 | throw new Error('`spec` is required as the first argument') |
| 126 | } |
| 127 | |
| 128 | if (!branch) { |
| 129 | throw new Error('`branch` is required as the second argument') |
| 130 | } |
| 131 | |
| 132 | if (!GITHUB_TOKEN) { |
| 133 | throw new Error(`process.env.GITHUB_TOKEN is required`) |
| 134 | } |
| 135 | |
| 136 | await fsp.access(NODE_DIR, fsp.constants.F_OK).catch(() => { |
| 137 | throw new Error(`node repo must be checked out to \`${NODE_DIR}\` to continue`) |
| 138 | }) |
| 139 | |
| 140 | await gh.json('repo', 'view', NODE_FORK, 'url').catch(() => { |
| 141 | throw new Error(`node repo must be forked to ${NODE_FORK}`) |
| 142 | }) |
| 143 | |
| 144 | await git.dirty().catch((er) => { |
| 145 | if (localTest) { |
| 146 | return log.info('Skipping git dirty check due to `--local-test` flag') |
| 147 | } |
| 148 | throw er |
| 149 | }) |
| 150 | |
| 151 | const mani = await pacote.manifest(`npm@${spec}`, { preferOnline: true }) |
| 152 | const packument = await pacote.packument('npm', { preferOnline: true }) |
| 153 | const npmVersions = Object.keys(packument.versions).sort(semver.rcompare) |
| 154 | |
| 155 | const npmVersion = semver.parse(mani.version) |
| 156 | const npmHost = hgi.fromUrl(NODE_FORK) |
| 157 | const npmTag = `v${npmVersion}` |
| 158 | // use the target branch as part of the name so we can create multiple PRs for |
| 159 | // the same npm version targeting different Node branches at the same time |
| 160 | const npmBranch = `npm-${npmTag}-${branch}` |
| 161 | const npmRemoteUrl = tokenRemoteUrl({ host: npmHost, token: GITHUB_TOKEN }) |
| 162 | const npmMessage = (v = npmVersion) => `deps: upgrade npm to ${v}` |
| 163 | |
| 164 | const tarball = await createNodeTarball({ |
| 165 | mani, |
| 166 | tag: npmTag, |
| 167 | dir: tmpDir, |
| 168 | registryOnly, |
| 169 | localTest, |
| 170 | }) |
| 171 | log.info('tarball path', tarball) |
| 172 | |
| 173 | const nodeRemote = 'origin' |
| 174 | const nodeBranch = /^\d+$/.test(branch) ? `v${branch}.x-staging` : branch |
| 175 | const nodeHost = hgi.fromUrl(await gitNode('remote', 'get-url', nodeRemote, { out: true })) |
| 176 | const nodePrArgs = ['pr', '-R', nodeHost.path()] |
| 177 |
no test coverage detected