Skip to content
This repository was archived by the owner on May 10, 2021. It is now read-only.

add check if pages-manifest exists before reading #147

Merged
merged 1 commit into from
Jan 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/helpers/getPagesManifest.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const { join } = require("path");
const { readJSONSync } = require("fs-extra");
const { existsSync, readJSONSync } = require("fs-extra");
const { NEXT_DIST_DIR } = require("../config");

const getPagesManifest = () => {
const contents = readJSONSync(
join(NEXT_DIST_DIR, "serverless", "pages-manifest.json")
);
const manifestPath = join(NEXT_DIST_DIR, "serverless", "pages-manifest.json");
if (!existsSync(manifestPath)) return {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure: would next-on-netlify still behave correctly even if this function returns an empty object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes! each place that uses getPagesManifest iterates over it using Object.entries

so it'd be calling Object.entries({}) which returns an empty array meaning no pages will get included (as appropriate, if there's somehow no pages-manifest) for the relevant page types

const contents = readJSONSync(manifestPath);
// Next.js mistakenly puts backslashes in certain paths on Windows, replace
Object.entries(contents).forEach(([key, value]) => {
contents[key] = value.replace(/\\/g, "/");
Expand Down