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

Allow Yarn PnP to access internal pages #23374

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 17 additions & 2 deletions packages/next/server/hot-reloader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import fs from 'fs'
import { getOverlayMiddleware } from '@next/react-dev-overlay/lib/middleware'
import { NextHandleFunction } from 'connect'
import { IncomingMessage, ServerResponse } from 'http'
Expand All @@ -23,7 +24,6 @@ import {
normalizePathSep,
} from '../next-server/server/normalize-page-path'
import getRouteFromEntrypoint from '../next-server/server/get-route-from-entrypoint'
import { isWriteable } from '../build/is-writeable'
import { ClientPagesLoaderOptions } from '../build/webpack/loaders/next-client-pages-loader'
import { stringify } from 'querystring'
import { Rewrite } from '../lib/load-custom-routes'
Expand Down Expand Up @@ -298,6 +298,15 @@ export default class HotReloader {
])
}

private async isReadable(path: string): Promise<boolean> {
try {
await fs.promises.access(path, (fs.constants || fs).R_OK)
return true
} catch (err) {
return false
}
}

public async start(): Promise<void> {
await this.clean()

Expand All @@ -321,7 +330,13 @@ export default class HotReloader {
clientBundlePath,
absolutePagePath,
} = entries[page]
const pageExists = await isWriteable(absolutePagePath)

// Check for read access to the page rather than using the common
// "isWritable" utility used elsewhere.
// When operating in a Yarn Plug'n'Play environment, internal pages
// will be contained within readonly zip files.
const pageExists = await this.isReadable(absolutePagePath)

if (!pageExists) {
// page was removed
delete entries[page]
Expand Down