-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c62f4e
commit 407c554
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,52 @@ | ||
import { Glob } from 'bun' | ||
import fs from 'fs' | ||
|
||
// Find all package.json files (excluding node_modules) | ||
const packageFilesUnfiltered = new Glob('./**/package.json').scanSync() | ||
|
||
const packageFiles = packageFiles.filter((filePath) => !filePath.includes('node_modules')) | ||
|
||
// Create a map of package names to their versions | ||
const packageVersions = {} | ||
packageFiles.forEach((filePath) => { | ||
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8')) | ||
if (pkg.name && pkg.version) { | ||
packageVersions[pkg.name] = pkg.version | ||
} | ||
}) | ||
|
||
// Process each package.json | ||
packageFiles.forEach((filePath) => { | ||
const pkg = JSON.parse(fs.readFileSync(filePath, 'utf8')) | ||
let modified = false | ||
|
||
// Helper function to process dependencies | ||
const processDeps = (deps) => { | ||
if (!deps) return deps | ||
const newDeps = { ...deps } | ||
|
||
Object.entries(deps).forEach(([name, version]) => { | ||
if (version.startsWith('workspace:')) { | ||
const actualVersion = version === 'workspace:*' | ||
? packageVersions[name] | ||
: version.replace('workspace:', '') | ||
|
||
if (actualVersion) { | ||
newDeps[name] = actualVersion | ||
modified = true | ||
} | ||
} | ||
}) | ||
return newDeps | ||
} | ||
|
||
// Process all dependency types | ||
pkg.dependencies = processDeps(pkg.dependencies) | ||
pkg.devDependencies = processDeps(pkg.devDependencies) | ||
pkg.peerDependencies = processDeps(pkg.peerDependencies) | ||
|
||
// Save if modified | ||
if (modified) { | ||
fs.writeFileSync(filePath, `${JSON.stringify(pkg, null, 2)}\n`) | ||
} | ||
}) |