hatch-surf/node_modules/next/dist/esm/server/dev/require-cache.js
Riley Zhang df378d33ef
Some checks failed
CI / go (push) Waiting to run
CI / docker (push) Waiting to run
CI / lint-go (push) Waiting to run
CI / lint-docs (push) Waiting to run
CI / check-paperclip (push) Waiting to run
Deploy static site / Deploy to GitHub Pages (push) Has been cancelled
Deploy static site / Deploy via Docker to hatch.surf (push) Has been cancelled
Merge GitHub main into Gitea repo (allow unrelated histories)
Resolved conflicts by taking GitHub versions for:
- .dockerignore, .gitignore, Dockerfile, README.md, docker-compose.yml

Kept deploy.sh updated to:
- Pull from GitHub (primary source)
- Push to Gitea (push-mirror)
- Build from site/ directory (GitHub structure)

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-06-25 05:20:46 +02:00

64 lines
2.2 KiB
JavaScript

import isError from '../../lib/is-error';
import { realpathSync } from '../../lib/realpath';
import { clearManifestCache } from '../load-manifest.external';
/**
* Batch delete modules from require.cache with a single scan.
*
* When deleting N modules, this performs ONE scan of require.cache
* instead of N scans, reducing complexity from O(N * C) to O(C + N)
* where C = size of require.cache.
*/ function deleteFromRequireCache(filePaths) {
// Phase 1: Resolve all paths and collect modules to delete
const resolvedPaths = [];
const modsToDelete = new Set();
for (let filePath of filePaths){
try {
filePath = realpathSync(filePath);
} catch (e) {
if (isError(e) && e.code !== 'ENOENT') throw e;
}
const mod = require.cache[filePath];
if (mod) {
resolvedPaths.push(filePath);
modsToDelete.add(mod);
}
}
if (modsToDelete.size === 0) return;
// Phase 2: Single scan of require.cache to remove child references
const modules = Object.values(require.cache);
for(let m = 0; m < modules.length; m++){
var _modules_m;
const children = (_modules_m = modules[m]) == null ? void 0 : _modules_m.children;
if (children && children.length) {
let len = children.length;
for(let i = 0; i < len; i++){
if (modsToDelete.has(children[i])) {
children[i] = children[--len];
i-- // re-check swapped element
;
}
}
children.length = len;
}
}
// Phase 3: Clear parent references from children and delete cache entries
for (const mod of modsToDelete){
const children = mod.children;
for(let i = 0; i < children.length; i++){
if (children[i].parent === mod) {
children[i].parent = null;
}
}
}
for (const filePath of resolvedPaths){
delete require.cache[filePath];
}
}
export function deleteCache(filePaths) {
for (const filePath of filePaths){
clearManifestCache(filePath);
}
deleteFromRequireCache(filePaths);
}
//# sourceMappingURL=require-cache.js.map