Unverified Commit e30d7237 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Ensure older lockfile/invalid formats are handled (#36577)

parent 486040ef
...@@ -19,15 +19,15 @@ export async function patchIncorrectLockfile(dir: string) { ...@@ -19,15 +19,15 @@ export async function patchIncorrectLockfile(dir: string) {
const content = await promises.readFile(lockfilePath, 'utf8') const content = await promises.readFile(lockfilePath, 'utf8')
const lockfileParsed = JSON.parse(content) const lockfileParsed = JSON.parse(content)
const packageKeys = Object.keys(lockfileParsed.dependencies)
const foundSwcPkgs = new Set() const foundSwcPkgs = new Set()
const nextPkg = lockfileParsed.packages['node_modules/next'] const nextPkg = lockfileParsed.packages?.['node_modules/next']
// if we don't find next in the package-lock we can't continue // if we don't find next in the package-lock we can't continue
if (!nextPkg) { if (!nextPkg) {
return return
} }
const nextVersion = nextPkg.version const nextVersion = nextPkg.version
const packageKeys = Object.keys(lockfileParsed.dependencies || {})
const expectedSwcPkgs = Object.keys(nextPkg?.optionalDependencies).filter( const expectedSwcPkgs = Object.keys(nextPkg?.optionalDependencies).filter(
(pkg) => pkg.startsWith('@next/swc-') (pkg) => pkg.startsWith('@next/swc-')
......
...@@ -40,12 +40,18 @@ describe('dependencies can use env vars in middlewares', () => { ...@@ -40,12 +40,18 @@ describe('dependencies can use env vars in middlewares', () => {
}) })
} }
`, `,
// make sure invalid package-lock doesn't error
'package-lock.json': '{}',
}, },
dependencies: {}, dependencies: {},
}) })
}) })
afterAll(() => next.destroy()) afterAll(() => next.destroy())
it('does not error from patching lockfile', () => {
expect(next.cliOutput).not.toContain('patch-incorrect-lockfile')
})
it('parses the env vars correctly', async () => { it('parses the env vars correctly', async () => {
const testDir = next.testDir const testDir = next.testDir
const manifestPath = path.join( const manifestPath = path.join(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment