Skip to content

Commit

Permalink
Allow Yarn PnP to access internal pages
Browse files Browse the repository at this point in the history
  • Loading branch information
strothj committed Mar 25, 2021
1 parent 9f5b61d commit e40af37
Showing 1 changed file with 17 additions and 2 deletions.
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

0 comments on commit e40af37

Please sign in to comment.