forked from rrweb-io/rrweb
-
Notifications
You must be signed in to change notification settings - Fork 12
chore: Replace lerna with lightweight versioning script #272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,88 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| function readJson(filePath) { | ||
| return JSON.parse(fs.readFileSync(filePath, 'utf-8')); | ||
| } | ||
|
|
||
| /** | ||
| * Bumps the version of all workspace packages and their internal dependencies. | ||
| * Replicates the behavior of: | ||
| * lerna version --force-publish --exact --no-git-tag-version --no-push --yes <newVersion> | ||
| * | ||
| * - Updates `version` in every workspace package.json to newVersion | ||
| * - Updates all internal workspace dependency references to the new exact version | ||
| * - No git tags, commits, or pushes are made | ||
| */ | ||
| function bumpVersions(rootDir, newVersion) { | ||
| const rootPkgPath = path.join(rootDir, 'package.json'); | ||
| const rootPkg = readJson(rootPkgPath); | ||
| const workspaceGlobs = rootPkg.workspaces; | ||
|
|
||
| if (!workspaceGlobs || !Array.isArray(workspaceGlobs)) { | ||
| throw new Error('Could not find workspaces array in root package.json'); | ||
| } | ||
|
|
||
| // Resolve workspace globs to actual directories | ||
| const workspaceDirs = []; | ||
| for (const glob of workspaceGlobs) { | ||
| // Handle simple globs like "packages/*" and "packages/plugins/*" | ||
| const baseDir = glob.replace(/\/\*$/, ''); | ||
| const fullBase = path.join(rootDir, baseDir); | ||
| if (!fs.existsSync(fullBase)) continue; | ||
| const entries = fs.readdirSync(fullBase, { withFileTypes: true }); | ||
| for (const entry of entries) { | ||
| if (entry.isDirectory()) { | ||
| const pkgJsonPath = path.join(fullBase, entry.name, 'package.json'); | ||
| if (fs.existsSync(pkgJsonPath)) { | ||
| workspaceDirs.push(path.join(baseDir, entry.name)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Read all workspace package.json files upfront to fail early | ||
| const workspacePackages = []; | ||
| const workspaceNames = new Set(); | ||
| for (const dir of workspaceDirs) { | ||
| const pkgPath = path.join(rootDir, dir, 'package.json'); | ||
| const pkg = readJson(pkgPath); | ||
| workspaceNames.add(pkg.name); | ||
| workspacePackages.push({ pkgPath, pkg }); | ||
| } | ||
|
|
||
| // Apply version bumps | ||
| for (const { pkgPath, pkg } of workspacePackages) { | ||
| pkg.version = newVersion; | ||
|
|
||
| for (const depType of ['dependencies', 'devDependencies', 'peerDependencies']) { | ||
| if (!pkg[depType]) continue; | ||
|
|
||
| for (const [dep, ver] of Object.entries(pkg[depType])) { | ||
| if (workspaceNames.has(dep) && !ver.startsWith('workspace:')) { | ||
| pkg[depType][dep] = newVersion; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n'); | ||
| } | ||
|
|
||
| return workspacePackages.length; | ||
| } | ||
|
|
||
| // CLI entry point | ||
| if (require.main === module) { | ||
| const newVersion = process.argv[2]; | ||
|
|
||
| if (!newVersion) { | ||
| console.error('Usage: node scripts/bump-version.js <new-version>'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const rootDir = path.join(__dirname, '..'); | ||
| const updatedCount = bumpVersions(rootDir, newVersion); | ||
| console.log(`Updated ${updatedCount} packages to version ${newVersion}`); | ||
| } | ||
|
|
||
| module.exports = { bumpVersions }; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.