Only `require.resolve(...)` the path once (#180)

Perhaps an early optimization or not even needed but doesn't seem wise to keep pulling this over and over (best case it's cached).
This commit is contained in:
Eric Eastwood 2023-04-25 00:50:43 -05:00 committed by GitHub
parent 0f26dc94d3
commit ac1419cdca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -24,6 +24,8 @@ if (!logOutputFromChildProcesses) {
);
}
const resolvedChildForkScriptPath = require.resolve('./child-fork-script');
function assembleErrorAfterChildExitsWithErrors(exitCode, childErrors) {
assert(childErrors);
@ -72,7 +74,7 @@ async function runInChildProcess(modulePath, runArguments, { timeout }) {
// We use a child_process because we want to be able to exit the process
// after we receive the results. We use `fork` instead of `exec`/`spawn` so
// that we can pass a module instead of running a command.
const child = fork(require.resolve('./child-fork-script'), [modulePath], {
const child = fork(resolvedChildForkScriptPath, [modulePath], {
signal,
// Default to silencing logs from the child process. We already have
// proper instrumentation of any errors that might occur.

View File

@ -10,6 +10,10 @@ const assert = require('assert');
const RethrownError = require('../lib/rethrown-error');
const runInChildProcess = require('../child-process-runner/run-in-child-process');
const resolvedRenderHydrogenToStringUnsafeScriptPath = require.resolve(
'./render-hydrogen-to-string-unsafe'
);
// The render should be fast. If it's taking more than 5 seconds, something has
// gone really wrong.
const RENDER_TIMEOUT = 5000;
@ -40,7 +44,7 @@ async function renderHydrogenToString(renderOptions) {
// we receive the SSR results. We don't want Hydrogen to keep running after we
// get our initial rendered HTML.
const hydrogenHtmlOutput = await runInChildProcess(
require.resolve('./render-hydrogen-to-string-unsafe'),
resolvedRenderHydrogenToStringUnsafeScriptPath,
renderOptions,
{
timeout: RENDER_TIMEOUT,