@shopify/cli
Version:
A CLI tool to build for the Shopify platform
167 lines (164 loc) • 5.09 kB
JavaScript
import {
findPort
} from "./chunk-BV6PURBM.js";
import {
DEFAULT_INSPECTOR_PORT,
H2O_BINDING_NAME,
SUBREQUEST_PROFILER_ENDPOINT,
createLogRequestEvent,
getUtilityBannerlines,
handleDebugNetworkRequest,
handleMiniOxygenImportFail,
importLocal,
logRequestLine,
setConstructors
} from "./chunk-H73PDGHM.js";
import "./chunk-LQ2ZKVR6.js";
import "./chunk-CP3BRHWK.js";
import "./chunk-FEYZLXHI.js";
import "./chunk-PT5BDLIN.js";
import "./chunk-EBRJEUGC.js";
import "./chunk-SHWOPMLQ.js";
import "./chunk-HO5XX2LU.js";
import "./chunk-HGD26EDV.js";
import "./chunk-DNGCAQBF.js";
import "./chunk-HE3BDMSQ.js";
import "./chunk-25IMI7TH.js";
import "./chunk-UGX6DGR4.js";
import "./chunk-5DXEBIVF.js";
import "./chunk-HMDWNGIV.js";
import {
AbortError,
outputNewline,
readFile,
renderSuccess,
source_default
} from "./chunk-OAZABGFS.js";
import "./chunk-B5EXYCV3.js";
import "./chunk-75LV6AQS.js";
import "./chunk-57Q6OQG4.js";
import "./chunk-QAKYKTFV.js";
import "./chunk-G5R6YD27.js";
import "./chunk-3I3GQNEW.js";
import "./chunk-G2ZZKGSV.js";
import "./chunk-MP5RLDFN.js";
import "./chunk-XE5EOEBL.js";
import "./chunk-5DBS6QOU.js";
import "./chunk-B3YWYURY.js";
import "./chunk-CDBXAE2F.js";
import {
init_cjs_shims
} from "./chunk-PKR7KJ6P.js";
// ../../node_modules/.pnpm/@shopify+cli-hydrogen@10.0.0_@graphql-codegen+cli@5.0.4_react-dom@17.0.2_react@17.0.2/node_modules/@shopify/cli-hydrogen/dist/lib/mini-oxygen/node.js
init_cjs_shims();
import { AsyncLocalStorage } from "node:async_hooks";
async function startNodeServer({
appPort,
watch = !1,
buildPathWorkerFile,
buildPathClient,
env,
debug = !1,
inspectorPort,
root
}) {
let { startServer, Request, Response } = await importLocal(
"@shopify/mini-oxygen/node",
root
).catch(handleMiniOxygenImportFail);
setConstructors({ Response });
let logRequestEvent = createLogRequestEvent(), asyncLocalStorage = new AsyncLocalStorage(), serviceBindings = {
[H2O_BINDING_NAME]: {
fetch: async (request) => logRequestEvent(
new Request(request.url, {
method: "POST",
body: JSON.stringify({
...asyncLocalStorage.getStore(),
...await request.json()
})
})
)
}
};
debug && (inspectorPort || (inspectorPort = await findPort(DEFAULT_INSPECTOR_PORT)), (await import("node:inspector")).open(inspectorPort));
let readWorkerFile = () => readFile(buildPathWorkerFile).catch((error) => {
throw new AbortError(
`Could not read worker file.
` + error.stack,
"Did you build the project?"
);
}), miniOxygen = await startServer({
script: await readWorkerFile(),
workerFile: buildPathWorkerFile,
assetsDir: buildPathClient,
publicPath: "",
port: appPort,
watch,
autoReload: watch,
modules: !0,
env: {
...env,
...process.env,
...serviceBindings
},
log: () => {
},
async onRequest(request, defaultDispatcher) {
if (new URL(request.url).pathname === SUBREQUEST_PROFILER_ENDPOINT)
return handleDebugNetworkRequest(request);
let requestId = request.headers.get("request-id"), startTimeMs = Date.now(), response = await asyncLocalStorage.run(
{ requestId, purpose: request.headers.get("purpose") },
() => defaultDispatcher(request)
), endTimeMs = Date.now();
return logRequestLine({
request: {
url: request.url,
method: request.method,
headers: Object.fromEntries(request.headers.entries())
},
response: {
status: response.status,
statusText: response.statusText,
headers: Object.fromEntries(response.headers.entries())
},
meta: {
startTimeMs,
endTimeMs,
durationMs: startTimeMs > 0 ? endTimeMs - startTimeMs : 0
}
}), response;
}
}), listeningAt = `http://localhost:${miniOxygen.port}`;
return {
listeningAt,
port: miniOxygen.port,
async reload(options) {
let nextOptions = {};
options?.env && (nextOptions.env = {
...options.env,
...process.env
}), nextOptions.script = await readWorkerFile(), await miniOxygen.reload(nextOptions);
},
showBanner(options) {
outputNewline();
let customSections = [];
options?.host && customSections.push({ body: getUtilityBannerlines(options.host) }), debug && inspectorPort && customSections.push({
body: { warn: `Debugger listening on ws://localhost:${inspectorPort}` }
}), renderSuccess({
headline: `${options?.headlinePrefix ?? ""}MiniOxygen (Node Sandbox) ${options?.mode ?? "development"} server running.`,
body: [
`View ${options?.appName ? source_default.cyan(options?.appName) : "Hydrogen"} app:`,
{ link: { url: options?.host || listeningAt } }
],
customSections
}), console.log("");
},
async close() {
await miniOxygen.close();
}
};
}
export {
startNodeServer
};
//# sourceMappingURL=node-RJ5OAO2M.js.map