MCPcopy Create free account
hub / github.com/npm/cli / main

Function main

scripts/create-node-pr.js:120–283  ·  view source on GitHub ↗
(spec, branch = 'main', opts)

Source from the content-addressed store, hash-verified

118}
119
120const 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

Callers 1

create-node-pr.jsFile · 0.70

Calls 14

tokenRemoteUrlFunction · 0.85
createNodeTarballFunction · 0.85
npmMessageFunction · 0.85
getPrBodyFunction · 0.85
manifestMethod · 0.80
packumentMethod · 0.80
parseMethod · 0.80
filterMethod · 0.80
cleanMethod · 0.80
replaceMethod · 0.80
pushMethod · 0.80
flatMethod · 0.80

Tested by

no test coverage detected