Skip to content

Commit

Permalink
Merge branch 'canary' into bugfix/webpack-5-externals
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored May 5, 2021
2 parents 5eb05fa + 83395c9 commit ffa67fa
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@ import { isWebpack5 } from 'next/dist/compiled/webpack/webpack'
import { realpathSync } from 'fs'
import path from 'path'

const originModules = [
require.resolve('../../../next-server/server/require'),
require.resolve('../../../next-server/server/load-components'),
]

function deleteCache(filePath: string) {
try {
delete require.cache[realpathSync(filePath)]
filePath = realpathSync(filePath)
} catch (e) {
if (e.code !== 'ENOENT') throw e
} finally {
delete require.cache[filePath]
}
const module = require.cache[filePath]
if (module) {
// remove the child reference from the originModules
for (const originModule of originModules) {
const parent = require.cache[originModule]
if (parent) {
const idx = parent.children.indexOf(module)
if (idx >= 0) parent.children.splice(idx, 1)
}
}
// remove parent references from external modules
for (const child of module.children) {
child.parent = null
}
}
delete require.cache[filePath]
}

const PLUGIN_NAME = 'NextJsRequireCacheHotReloader'
Expand Down

0 comments on commit ffa67fa

Please sign in to comment.