Skip to content

Commit

Permalink
nail workspace versions
Browse files Browse the repository at this point in the history
  • Loading branch information
robertherber committed Jan 21, 2025
1 parent 6c62f4e commit 407c554
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"postinstall": "cp manual-patches/sofa-api/package.json node_modules/sofa-api/",
"prepush": "bunx turbo run lint test typecheck --continue",
"generate-cms-json-schema": "typescript-json-schema ./packages/cms/tsconfig.json CmsConfigFile --include ./packages/cms/types.ts --out ./packages/cms/entities-json-schema.json --required --strictNullChecks --rejectDateType",
"fix-workspace-dependencies": "find . -type f -name 'package.json' -not -path './package.json' -not -path '*/node_modules/*' -exec perl -pi -e 's/\"workspace:.*\"/\"*\"/g' {} \\;",
"changeset-release": "bun run fix-workspace-dependencies && bunx changeset publish",
"nail-workspace-dependency-versions": "node scripts/nail-workspace-dependency-versions.js",
"changeset-release": "bun run nail-workspace-dependency-versions && bunx changeset publish",
"create-changeset": "bunx changeset",
"reinstall": "rm -rf node_modules/ && find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + && bun install --force",
"reinstall-with-nuked-lockfile": "rm -rf node_modules/ && rm bun.lockb && find . -name 'node_modules' -type d -prune -exec rm -rf '{}' + && bun install",
Expand Down
52 changes: 52 additions & 0 deletions scripts/nail-workspace-dependency-versions.ts
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`)
}
})

0 comments on commit 407c554

Please sign in to comment.