Skip to content
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

Ensure older lockfile/invalid formats are handled #36577

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/next/lib/patch-incorrect-lockfile.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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