UNPKG

@shopify/cli

Version:

A CLI tool to build for the Shopify platform

171 lines (167 loc) 5.39 kB
import { H2O_BINDING_NAME, SUBREQUEST_PROFILER_ENDPOINT, TUNNEL_DOMAIN, createLogRequestEvent, getDebugBannerLine, getUtilityBannerlines, handleDebugNetworkRequest, handleMiniOxygenImportFail, importLocal, logRequestLine, setConstructors } from "./chunk-M3TVLW4G.js"; import "./chunk-CP3BRHWK.js"; import "./chunk-YF7CDH6L.js"; import "./chunk-3TBLURBG.js"; import "./chunk-AGY4NR7U.js"; import "./chunk-SHWOPMLQ.js"; import "./chunk-QJQK26XP.js"; import "./chunk-FRQN52H3.js"; import "./chunk-JLITATNF.js"; import "./chunk-Q76H7OUL.js"; import "./chunk-25IMI7TH.js"; import "./chunk-Z2AIGIVT.js"; import "./chunk-KDFL67TE.js"; import { AbortError, createFileReadStream, outputNewline, readFile, renderSuccess, source_default } from "./chunk-4NC2NVYY.js"; import "./chunk-75LV6AQS.js"; import { dirname, resolvePath } from "./chunk-EG6MBBEN.js"; import "./chunk-3FBDJEGD.js"; import "./chunk-UMUTXITN.js"; import "./chunk-HMDWNGIV.js"; import "./chunk-G5R6YD27.js"; import "./chunk-G2ZZKGSV.js"; import "./chunk-UV5N2VL7.js"; import "./chunk-XE5EOEBL.js"; import "./chunk-B5EXYCV3.js"; import { init_cjs_shims } from "./chunk-PKR7KJ6P.js"; // ../../node_modules/.pnpm/@shopify+cli-hydrogen@11.1.2_@graphql-codegen+cli@5.0.4_@parcel+watcher@2.5.1_@types+no_e67bd8d5620b222f0d88ec0729535c5f/node_modules/@shopify/cli-hydrogen/dist/lib/mini-oxygen/workerd.js init_cjs_shims(); import { createRequire } from "node:module"; async function startWorkerdServer({ root, appPort, inspectorPort: publicInspectorPort, assetsPort, debug = !1, watch = !1, buildPathWorkerFile, buildPathClient, env }) { let { createMiniOxygen, Response } = await importLocal( "@shopify/mini-oxygen", root ).catch(handleMiniOxygenImportFail); setConstructors({ Response }); async function handleCustomerAccountSchema() { let filePath = createRequire(import.meta.url).resolve( "@shopify/hydrogen/customer-account.schema.json" ); return new Response(createFileReadStream(filePath), { headers: { "Content-Type": "application/json" } }); } let mainWorkerName = "hydrogen", absoluteBundlePath = resolvePath(root, buildPathWorkerFile), readWorkerFile = () => readFile(absoluteBundlePath).catch((error) => { throw new AbortError( `Could not read worker file. ` + error.stack, "Did you build the project?" ); }), miniOxygen = createMiniOxygen({ debug, port: appPort, host: "localhost", liveReload: watch, requestHook: logRequestLine, inspectorPort: publicInspectorPort, inspectWorkerName: mainWorkerName, assets: { port: assetsPort, directory: buildPathClient }, workers: [ { name: "hydrogen:middleware", modules: !0, script: `export default { fetch: (request, env) => { const url = new URL(request.url); if (url.hostname.endsWith('${TUNNEL_DOMAIN.ORIGINAL}')) { url.hostname = url.hostname.replace( '${TUNNEL_DOMAIN.ORIGINAL}', '${TUNNEL_DOMAIN.REBRANDED}', ); } return url.pathname === '${SUBREQUEST_PROFILER_ENDPOINT}' ? env.profiler.fetch(url, request) : url.pathname === '/graphiql/customer-account.schema.json' ? env.assets.fetch(url, request) : env.next.fetch(url, request) } }`, serviceBindings: { profiler: handleDebugNetworkRequest, assets: handleCustomerAccountSchema, next: mainWorkerName } }, { name: mainWorkerName, modulesRoot: dirname(absoluteBundlePath), modules: [ { type: "ESModule", path: absoluteBundlePath, contents: await readWorkerFile() } ], bindings: { ...env }, serviceBindings: { [H2O_BINDING_NAME]: createLogRequestEvent({ transformLocation: () => absoluteBundlePath }) } } ] }), { workerUrl, inspectorUrl } = await miniOxygen.ready; return { port: Number(workerUrl.port), listeningAt: workerUrl.origin, reload(nextOptions) { return miniOxygen.reload(async ({ workers }) => { let mainWorker = workers.find(({ name }) => name === mainWorkerName); return Array.isArray(mainWorker.modules) && mainWorker.modules[0] && (mainWorker.modules[0].contents = await readWorkerFile()), nextOptions && (mainWorker.bindings = { ...nextOptions?.env ?? env }), { workers }; }); }, showBanner(options) { outputNewline(); let customSections = []; options?.host && customSections.push({ body: getUtilityBannerlines(options.host) }), inspectorUrl && customSections.push({ body: { warn: getDebugBannerLine(Number(inspectorUrl.port)) } }), renderSuccess({ headline: `${options?.headlinePrefix ?? ""}MiniOxygen (Worker Runtime) ${options?.mode ?? "development"} server running.`, body: [ `View ${options?.appName ? source_default.cyan(options?.appName) : "Hydrogen"} app:`, { link: { url: options?.host || workerUrl.origin } } ], customSections }), console.log(""); }, async close() { await miniOxygen.dispose(); } }; } export { startWorkerdServer }; //# sourceMappingURL=workerd-GLBI5GFX.js.map