-
Notifications
You must be signed in to change notification settings - Fork 129
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
@W-13846314@ Enforce lockfile version 2 #1389
Conversation
import path from 'node:path' | ||
import fs from 'node:fs' |
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.
We always grumble about the scripts being stuck using require()
, so this I made this as a .mjs
file so it can use imports.
.readdirSync(packagesDir, {withFileTypes: true}) | ||
.filter((dirent) => dirent.isDirectory()) |
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 is pretty much just to avoid .DS_Store
if it happens to be there.
const lockfile = JSON.parse(fs.readFileSync(filename, 'utf8')) | ||
if (lockfile.lockfileVersion !== LOCKFILE_VERSION_TARGET) { | ||
console.error( | ||
`Expected ${lockfile.name} to have lockfile version ${LOCKFILE_VERSION_TARGET}, but saw version ${lockfile.lockfileVersion}.` |
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.
Are we locking in version 2? As far as I know, lockfile version 3 are compatible with lock file version 2, the only concern is when lock files is generated in version 1, which is from Node 14. When Node 14 is offically out of support, we should not have this issue i believe
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.
Just confirming what @alexvuong said: https://docs.npmjs.com/cli/v9/configuring-npm/package-lock-json#lockfileversion
Why do we want to lock in v2? To ensure compatibility with Node 14 / npm 6?
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.
We want to lock to some version in order to ensure consistency across packages. Version 2 was an arbitrary choice because that's what we're already using.
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.
Testing this change - it works
Expected pwa-kit to have lockfile version 2, but saw version 3.
To regenerate the lockfiles with the correct lockfile version, please run `rm -rf package-lock.json node_modules/` in each impacted directory, and then use npm 7 or 8 to run `npm install` in the monorepo root.
npm ERR! code 1
npm ERR! path /Users/vcua/Git/pwa-kit
npm ERR! command failed
npm ERR! command sh -c -- node ./scripts/bootstrap.js && node ./scripts/check-lockfiles.mjs
Is this a temporary script until Node 14 is deprecated? |
I intended for it to be permanent; if we want it to be temporary we'll have to wait at least until we drop support for npm 8 (and hope that npm 10+ use lockfile v3), as npm 8 uses lockfile v2, but npm 9 uses lockfile v3. |
@adamraya pointed out that in the last release v3 snuck in to a few lockfiles. Since we don't really pay attention to the lockfiles as much as we should, it seems prudent to have a script do that for us.
Description
Types of Changes
Changes
How to Test-Drive This PR
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization