-
Notifications
You must be signed in to change notification settings - Fork 235
generate lockfiles script: throw if pnpm used is not v8 #1787
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 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e3ec16e
force pnpm v8 and lockfileVersion 6
nazreen 0aced54
check version and throw if not matching
nazreen 11c3068
simplify
nazreen 814bd28
Merge branch 'main' into update-gen-lockfiles-script
nazreen 358ba4f
Merge branch 'main' into update-gen-lockfiles-script
nazreen 8976591
Merge branch 'main' into update-gen-lockfiles-script
shankars99 eda2435
Merge branch 'main' into update-gen-lockfiles-script
nazreen 4328609
Merge branch 'main' into update-gen-lockfiles-script
nazreen 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 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 |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { existsSync } from 'node:fs'; | ||
| import { existsSync, readFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { getExampleDirs } from './common-lockfiles.mjs'; | ||
|
|
@@ -11,6 +11,15 @@ if (dirs.length === 0) { | |
| process.exit(1); | ||
| } | ||
|
|
||
| const pnpmVersion = getPnpmVersionFromPath(); | ||
| console.log(`Using pnpm version: ${pnpmVersion}`); | ||
| const expectedVersion = getExpectedVersionFromPackageJson(); | ||
| // assert pnpm V | ||
| if (pnpmVersion !== expectedVersion) { | ||
| console.error(`Expected pnpm version ${expectedVersion}, got ${pnpmVersion}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| let failures = 0; | ||
| for (const pkgDir of dirs) { | ||
| console.log(`\n[lockfile] ${pkgDir}`); | ||
|
|
@@ -43,3 +52,25 @@ if (failures) { | |
| } | ||
|
|
||
| console.log('\nDone.'); | ||
|
|
||
| function getExpectedVersionFromPackageJson() { | ||
| const packageJson = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf8')); | ||
| const packageManager = packageJson.packageManager; | ||
| if (!packageManager?.startsWith('pnpm@')) { | ||
| throw new Error(`Invalid packageManager: ${packageManager || 'missing'}. Expected format: "[email protected]"`); | ||
| } | ||
| return packageManager.slice(5); // Remove "pnpm@" prefix | ||
| } | ||
|
|
||
| function getPnpmVersionFromPath() { | ||
| const { status, stdout, error } = spawnSync('pnpm', ['--version'], { encoding: 'utf8' }); | ||
| if (status !== 0) { | ||
| const hint = error?.code === 'ENOENT' ? 'pnpm is not on PATH.' : 'failed to run "pnpm --version".'; | ||
| throw new Error(`Could not determine pnpm version: ${hint}`); | ||
| } | ||
| const version = stdout.trim(); | ||
| if (!version) { | ||
| throw new Error('Empty version output from "pnpm --version".'); | ||
| } | ||
| return version; | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes that we will always have fixed versions and no trailing hash (example here https://github.com/LayerZero-Labs/docs/blob/main/package.json#L102).
I think it's a safe assumption given the timeline of the repo though.