Skip to content

Commit

Permalink
Ensure older lockfile/invalid formats are handled (#36577)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Apr 29, 2022
1 parent 486040e commit e30d723
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/next/lib/patch-incorrect-lockfile.ts
Expand Up @@ -19,15 +19,15 @@ export async function patchIncorrectLockfile(dir: string) {
const content = await promises.readFile(lockfilePath, 'utf8')
const lockfileParsed = JSON.parse(content)

const packageKeys = Object.keys(lockfileParsed.dependencies)
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 (!nextPkg) {
return
}
const nextVersion = nextPkg.version
const packageKeys = Object.keys(lockfileParsed.dependencies || {})

const expectedSwcPkgs = Object.keys(nextPkg?.optionalDependencies).filter(
(pkg) => pkg.startsWith('@next/swc-')
Expand Down
Expand Up @@ -40,12 +40,18 @@ describe('dependencies can use env vars in middlewares', () => {
})
}
`,
// make sure invalid package-lock doesn't error
'package-lock.json': '{}',
},
dependencies: {},
})
})
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 () => {
const testDir = next.testDir
const manifestPath = path.join(
Expand Down

0 comments on commit e30d723

Please sign in to comment.