2022-07-02 01:57:45 +02:00
|
|
|
const mod = require('module')
|
|
|
|
|
2022-10-23 01:33:51 +02:00
|
|
|
const reactDir = 'react'
|
|
|
|
const reactDomDir = 'react-dom'
|
2022-07-02 01:57:45 +02:00
|
|
|
|
|
|
|
const hookPropertyMap = new Map([
|
|
|
|
['react', reactDir],
|
|
|
|
['react/package.json', `${reactDir}/package.json`],
|
|
|
|
['react/jsx-runtime', `${reactDir}/jsx-runtime`],
|
|
|
|
['react/jsx-dev-runtime', `${reactDir}/jsx-dev-runtime`],
|
|
|
|
['react-dom', `${reactDomDir}`],
|
|
|
|
['react-dom/package.json', `${reactDomDir}/package.json`],
|
|
|
|
['react-dom/client', `${reactDomDir}/client`],
|
|
|
|
['react-dom/server', `${reactDomDir}/server`],
|
|
|
|
['react-dom/server.browser', `${reactDomDir}/server.browser`],
|
2023-04-27 12:51:52 +02:00
|
|
|
['react-dom/server.edge', `${reactDomDir}/server.edge`],
|
2022-07-02 01:57:45 +02:00
|
|
|
])
|
|
|
|
|
|
|
|
const resolveFilename = mod._resolveFilename
|
|
|
|
mod._resolveFilename = function (request, parent, isMain, options) {
|
|
|
|
const hookResolved = hookPropertyMap.get(request)
|
|
|
|
if (hookResolved) request = hookResolved
|
|
|
|
return resolveFilename.call(mod, request, parent, isMain, options)
|
|
|
|
}
|