MCPcopy
hub / github.com/vercel/next.js / updatePackageJson

Function updatePackageJson

rspack/change-npm-name.js:18–48  ·  view source on GitHub ↗
(filePath, packageName)

Source from the content-addressed store, hash-verified

16console.log(`GitHub Repository: ${process.env.GITHUB_REPOSITORY || 'not set'}`)
17
18function updatePackageJson(filePath, packageName) {
19 try {
20 if (!fs.existsSync(filePath)) {
21 console.warn(`Package.json not found: ${filePath}`)
22 return
23 }
24
25 const packageJson = JSON.parse(fs.readFileSync(filePath, 'utf8'))
26 packageJson.name = packageName
27
28 // Update repository URL to match current GitHub repo for provenance validation
29 if (packageJson.repository && packageJson.repository.url) {
30 const githubRepo = process.env.GITHUB_REPOSITORY
31 if (githubRepo) {
32 packageJson.repository.url = `git+https://github.com/${githubRepo}.git`
33 console.log(
34 `📝 Updated repository URL to: ${packageJson.repository.url}`
35 )
36 } else {
37 console.log(
38 `⚠️ GITHUB_REPOSITORY not found, keeping original repository URL: ${packageJson.repository.url}`
39 )
40 }
41 }
42
43 fs.writeFileSync(filePath, JSON.stringify(packageJson, null, 2) + '\n')
44 console.log(`✅ Updated ${filePath} with name: ${packageName}`)
45 } catch (error) {
46 console.error(`❌ Error updating ${filePath}:`, error.message)
47 }
48}
49
50function updateBindingIndex(filePath, packageName) {
51 try {

Callers 1

mainFunction · 0.85

Calls 6

readFileSyncMethod · 0.80
errorMethod · 0.65
warnMethod · 0.45
parseMethod · 0.45
logMethod · 0.45
stringifyMethod · 0.45

Tested by

no test coverage detected