hatch-surf/node_modules/enhanced-resolve/lib/createInnerContext.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

57 lines
1.8 KiB
JavaScript

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
/** @typedef {import("./Resolver").ResolveContext} ResolveContext */
/**
* Build the `ResolveContext` passed into the next hook in the chain.
*
* The caller — `Resolver.doResolve` — runs on every resolve step, so we
* want to allocate as little as possible here. Previously the caller
* constructed a temporary `{ log, yield, fileDependencies, ... }` literal
* and handed it to this helper, which then copied those same fields into
* a second fresh object. That's two allocations per step for what is
* effectively a struct copy with one mutated field (`stack`) and one
* optionally-wrapped field (`log`). Taking the parent context and the
* two things we actually want to change (stack, message) as separate
* arguments lets us allocate exactly one inner context.
* @param {ResolveContext} parent parent resolve context to inherit dependency sets / yield from
* @param {ResolveContext["stack"]} stack new stack tip for the nested call
* @param {null | string} message log message prefix for this step
* @returns {ResolveContext} inner context
*/
module.exports = function createInnerContext(parent, stack, message) {
const parentLog = parent.log;
let innerLog;
if (parentLog) {
if (message) {
let messageReported = false;
/**
* @param {string} msg message
*/
innerLog = (msg) => {
if (!messageReported) {
parentLog(message);
messageReported = true;
}
parentLog(` ${msg}`);
};
} else {
innerLog = parentLog;
}
}
return {
log: innerLog,
yield: parent.yield,
fileDependencies: parent.fileDependencies,
contextDependencies: parent.contextDependencies,
missingDependencies: parent.missingDependencies,
stack,
};
};