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:
parent
0f26dc94d3
commit
ac1419cdca
|
@ -24,6 +24,8 @@ if (!logOutputFromChildProcesses) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const resolvedChildForkScriptPath = require.resolve('./child-fork-script');
|
||||||
|
|
||||||
function assembleErrorAfterChildExitsWithErrors(exitCode, childErrors) {
|
function assembleErrorAfterChildExitsWithErrors(exitCode, childErrors) {
|
||||||
assert(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
|
// 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
|
// after we receive the results. We use `fork` instead of `exec`/`spawn` so
|
||||||
// that we can pass a module instead of running a command.
|
// 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,
|
signal,
|
||||||
// Default to silencing logs from the child process. We already have
|
// Default to silencing logs from the child process. We already have
|
||||||
// proper instrumentation of any errors that might occur.
|
// proper instrumentation of any errors that might occur.
|
||||||
|
|
|
@ -10,6 +10,10 @@ const assert = require('assert');
|
||||||
const RethrownError = require('../lib/rethrown-error');
|
const RethrownError = require('../lib/rethrown-error');
|
||||||
const runInChildProcess = require('../child-process-runner/run-in-child-process');
|
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
|
// The render should be fast. If it's taking more than 5 seconds, something has
|
||||||
// gone really wrong.
|
// gone really wrong.
|
||||||
const RENDER_TIMEOUT = 5000;
|
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
|
// we receive the SSR results. We don't want Hydrogen to keep running after we
|
||||||
// get our initial rendered HTML.
|
// get our initial rendered HTML.
|
||||||
const hydrogenHtmlOutput = await runInChildProcess(
|
const hydrogenHtmlOutput = await runInChildProcess(
|
||||||
require.resolve('./render-hydrogen-to-string-unsafe'),
|
resolvedRenderHydrogenToStringUnsafeScriptPath,
|
||||||
renderOptions,
|
renderOptions,
|
||||||
{
|
{
|
||||||
timeout: RENDER_TIMEOUT,
|
timeout: RENDER_TIMEOUT,
|
||||||
|
|
Loading…
Reference in New Issue