{"version":3,"sources":["../../src/server/require-hook.ts"],"sourcesContent":["// Synchronously inject a require hook for webpack and webpack/. It's required to use the internal ncc webpack version.\n// This is needed for userland plugins to attach to the same webpack instance as Next.js'.\n// Individually compiled modules are as defined for the compilation in bundles/webpack/packages/*.\n\n// This module will only be loaded once per process.\nconst path = require('path') as typeof import('path')\nconst mod = require('module') as typeof import('module')\nconst originalRequire = mod.prototype.require\nconst resolveFilename =\n  // @ts-expect-error\n  mod._resolveFilename\n\nlet resolve: typeof require.resolve = process.env.NEXT_MINIMAL\n  ? // @ts-ignore\n    __non_webpack_require__.resolve\n  : require.resolve\n\nexport const hookPropertyMap = new Map()\n\nexport const defaultOverrides: Record<string, string> = {}\n\ntry {\n  Object.assign(defaultOverrides, {\n    'styled-jsx': path.dirname(resolve('styled-jsx/package.json')),\n    'styled-jsx/style': resolve('styled-jsx/style'),\n    'styled-jsx/style.js': resolve('styled-jsx/style'),\n  })\n} catch (_) {}\n\nconst toResolveMap = (map: Record<string, string>): [string, string][] => {\n  const resolveMap: [string, string][] = []\n  for (const [key, value] of Object.entries(map)) {\n    try {\n      resolveMap.push([key, resolve(value)])\n    } catch {}\n  }\n  return resolveMap\n}\n\nexport function addHookAliases(aliases: [string, string][] = []) {\n  for (const [key, value] of aliases) {\n    hookPropertyMap.set(key, value)\n  }\n}\n\naddHookAliases(toResolveMap(defaultOverrides))\n\n// @ts-expect-error\nmod._resolveFilename = function (\n  originalResolveFilename: (\n    request: string,\n    parent: string,\n    isMain: boolean,\n    opts: any\n  ) => string,\n  requestMap: Map<string, string>,\n  request: string,\n  parent: string,\n  isMain: boolean,\n  options: any\n) {\n  const hookResolved = requestMap.get(request)\n  if (hookResolved) request = hookResolved\n\n  return originalResolveFilename.call(mod, request, parent, isMain, options)\n\n  // We use `bind` here to avoid referencing outside variables to create potential memory leaks.\n}.bind(null, resolveFilename, hookPropertyMap)\n\n// @ts-expect-error\n// This is a hack to make sure that if a user requires a Next.js module that wasn't bundled\n// that needs to point to the rendering runtime version, it will point to the correct one.\n// This can happen on `pages` when a user requires a dependency that uses next/image for example.\nmod.prototype.require = function (request: string) {\n  if (request.endsWith('.shared-runtime')) {\n    return originalRequire.call(\n      this,\n      `next/dist/server/route-modules/pages/vendored/contexts/${path.basename(\n        request,\n        '.shared-runtime'\n      )}`\n    )\n  }\n\n  return originalRequire.call(this, request)\n}\n"],"names":["addHookAliases","defaultOverrides","hookPropertyMap","path","require","mod","originalRequire","prototype","resolveFilename","_resolveFilename","resolve","process","env","NEXT_MINIMAL","__non_webpack_require__","Map","Object","assign","dirname","_","toResolveMap","map","resolveMap","key","value","entries","push","aliases","set","originalResolveFilename","requestMap","request","parent","isMain","options","hookResolved","get","call","bind","endsWith","basename"],"mappings":"AAAA,uHAAuH;AACvH,0FAA0F;AAC1F,kGAAkG;AAElG,oDAAoD;;;;;;;;;;;;;;;;;IAmCpCA,cAAc;eAAdA;;IApBHC,gBAAgB;eAAhBA;;IAFAC,eAAe;eAAfA;;;AAZb,MAAMC,OAAOC,QAAQ;AACrB,MAAMC,MAAMD,QAAQ;AACpB,MAAME,kBAAkBD,IAAIE,SAAS,CAACH,OAAO;AAC7C,MAAMI,kBACJ,mBAAmB;AACnBH,IAAII,gBAAgB;AAEtB,IAAIC,UAAkCC,QAAQC,GAAG,CAACC,YAAY,GAE1DC,wBAAwBJ,OAAO,GAC/BN,QAAQM,OAAO;AAEZ,MAAMR,kBAAkB,IAAIa;AAE5B,MAAMd,mBAA2C,CAAC;AAEzD,IAAI;IACFe,OAAOC,MAAM,CAAChB,kBAAkB;QAC9B,cAAcE,KAAKe,OAAO,CAACR,QAAQ;QACnC,oBAAoBA,QAAQ;QAC5B,uBAAuBA,QAAQ;IACjC;AACF,EAAE,OAAOS,GAAG,CAAC;AAEb,MAAMC,eAAe,CAACC;IACpB,MAAMC,aAAiC,EAAE;IACzC,KAAK,MAAM,CAACC,KAAKC,MAAM,IAAIR,OAAOS,OAAO,CAACJ,KAAM;QAC9C,IAAI;YACFC,WAA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