From 8fb56dec380c7e3251018825410dfad1ea764f6d Mon Sep 17 00:00:00 2001 From: thejackshelton Date: Sat, 4 Jan 2025 17:42:36 -0600 Subject: [PATCH 1/2] updated the server bundle --- libs/qwikdev-astro/q-astro-manifest.json | 1 - libs/qwikdev-astro/server.ts | 40 +------------------ libs/qwikdev-astro/src/index.ts | 51 ++++++++++++------------ 3 files changed, 27 insertions(+), 65 deletions(-) delete mode 100644 libs/qwikdev-astro/q-astro-manifest.json diff --git a/libs/qwikdev-astro/q-astro-manifest.json b/libs/qwikdev-astro/q-astro-manifest.json deleted file mode 100644 index f4b092d..0000000 --- a/libs/qwikdev-astro/q-astro-manifest.json +++ /dev/null @@ -1 +0,0 @@ -{"manifestHash":"ksjrps","symbols":{"s_0DHRa0FqCj4":{"origin":"../../../libs/qwikdev-astro/src/root.tsx","displayName":"root.tsx_root_component","canonicalFilename":"root.tsx_root_component_0DHRa0FqCj4","hash":"0DHRa0FqCj4","ctxKind":"function","ctxName":"component$","captures":false,"loc":[81,136]},"s_qY02pQHKSts":{"origin":"components/qwik/counter.tsx","displayName":"counter.tsx_Counter_component","canonicalFilename":"counter.tsx_Counter_component_qY02pQHKSts","hash":"qY02pQHKSts","ctxKind":"function","ctxName":"component$","captures":false,"loc":[121,322]},"s_WDqUvWziK5k":{"origin":"components/qwik/counter.tsx","displayName":"counter.tsx_Counter_component_Fragment_button_onClick","canonicalFilename":"counter.tsx_Counter_component_Fragment_button_onClick_WDqUvWziK5k","hash":"WDqUvWziK5k","ctxKind":"eventHandler","ctxName":"onClick$","captures":true,"parent":"s_qY02pQHKSts","loc":[235,256]}},"mapping":{"s_0DHRa0FqCj4":"q-CXpka_yH.js","s_qY02pQHKSts":"q-4LT-psvh.js","s_WDqUvWziK5k":"q-Cf-M9i3S.js"},"bundles":{"q-4LT-psvh.js":{"size":88,"imports":["q-Cf-M9i3S.js","q-CXpka_yH.js"],"symbols":["s_qY02pQHKSts"]},"q-Cf-M9i3S.js":{"size":1635,"imports":["q-CXpka_yH.js"],"origins":["src/components/qwik/counter.tsx_Counter_component_Fragment_button_onClick_WDqUvWziK5k.js","src/components/qwik/counter.tsx_Counter_component_qY02pQHKSts.js"],"symbols":["s_WDqUvWziK5k"]},"q-CXpka_yH.js":{"size":61657,"origins":["../../libs/qwikdev-astro/src/root.tsx_root_component_0DHRa0FqCj4.js","../../node_modules/.pnpm/@builder.io+qwik@1.12.0_vite@6.0.6_@types+node@22.10.2_jiti@2.4.2_yaml@2.6.1_/node_modules/@builder.io/qwik/dist/core.prod.mjs","@builder.io/qwik/build"],"symbols":["s_0DHRa0FqCj4"]},"q-FfniopH8.js":{"size":184,"imports":["q-Cf-M9i3S.js","q-CXpka_yH.js"],"dynamicImports":["q-CXpka_yH.js"],"origins":["../../libs/qwikdev-astro/src/root.tsx"]},"q-fzuY5JUw.js":{"size":171,"imports":["q-Cf-M9i3S.js","q-CXpka_yH.js"],"dynamicImports":["q-4LT-psvh.js"],"origins":["src/components/qwik/counter.tsx"]}},"injections":[],"version":"1","options":{"target":"client","buildMode":"production","entryStrategy":{"type":"smart"}},"platform":{"qwik":"1.12.0","vite":"","rollup":"4.29.1","env":"node","os":"darwin","node":"22.12.0"}} \ No newline at end of file diff --git a/libs/qwikdev-astro/server.ts b/libs/qwikdev-astro/server.ts index b147055..82a54eb 100644 --- a/libs/qwikdev-astro/server.ts +++ b/libs/qwikdev-astro/server.ts @@ -1,4 +1,3 @@ -import { isNode, qAstroManifestPath } from "inox:inline-mod:mod_0"; import { type JSXNode, jsx } from "@builder.io/qwik"; import { isDev } from "@builder.io/qwik/build"; import type { QwikManifest } from "@builder.io/qwik/optimizer"; @@ -63,41 +62,6 @@ export async function renderToStaticMarkup( let html = ""; - let integrationManifest = null; - - /** - * fallback to dynamic import if node is false. Node is preferred because most deployment providers still use older versions of node by default, so dynamic json imports will fail. - * - * Until this improves, we'll use node's readFileSync, with dynamic json imports for those not using node. - */ - if (isNode) { - try { - const { readFileSync } = await import("node:fs"); - const manifestContent = readFileSync(qAstroManifestPath, "utf-8"); - integrationManifest = JSON.parse(manifestContent); - } catch (error) { - throw new Error( - `@qwikdev/astro: Failed to read the q-astro-manifest.json file. This file is required for the @qwikdev/astro integration to work. - - It seems like you're using node. If this is not the case, please set the isNode option to false in the integration options in astro.config.mjs. - - Also make sure this is the case with both your local and deployed environment.` - ); - } - } else { - try { - integrationManifest = await import(/* @vite-ignore */ qAstroManifestPath, { - with: { type: "json" } - }); - } catch (error) { - throw new Error( - `@qwikdev/astro: Failed to read the q-astro-manifest.json file. This file is required for the @qwikdev/astro integration to work. - - Because isNode is set to false, the integration will use dynamic json imports to read the q-astro-manifest.json file. Check to make sure this environment supports dynamic json imports.` - ); - } - } - const renderToStreamOpts: RenderToStreamOptions = { containerAttributes: { style: "display: contents" }, containerTagName: "div", @@ -107,8 +71,7 @@ export async function renderToStaticMarkup( symbolMapper: globalThis.symbolMapperFn } : { - manifest: - globalThis.qManifest || integrationManifest?.default || integrationManifest + manifest: globalThis.qManifest }), serverData: props, qwikPrefetchServiceWorker: { @@ -226,6 +189,5 @@ export async function renderToStaticMarkup( export default { renderToStaticMarkup, supportsAstroStaticSlot: true, - testing123: true, check }; diff --git a/libs/qwikdev-astro/src/index.ts b/libs/qwikdev-astro/src/index.ts index b547dc1..84a1faa 100644 --- a/libs/qwikdev-astro/src/index.ts +++ b/libs/qwikdev-astro/src/index.ts @@ -1,12 +1,11 @@ -import { writeFileSync } from "node:fs"; +import fs from "node:fs"; +import { join } from "node:path"; import { qwikVite, symbolMapper } from "@builder.io/qwik/optimizer"; import type { QwikManifest, QwikVitePluginOptions, SymbolMapperFn } from "@builder.io/qwik/optimizer"; -import { inlineModule } from "@inox-tools/inline-mod/vite"; -import inlineMod from "@inox-tools/inline-mod/vite"; import type { AstroConfig, AstroIntegration } from "astro"; import { createResolver, defineIntegration, watchDirectory } from "astro-integration-kit"; import { z } from "astro/zod"; @@ -75,26 +74,12 @@ export default defineIntegration({ let astroConfig: AstroConfig | null = null; const { resolve: resolver } = createResolver(import.meta.url); const filter = createFilter(options?.include, options?.exclude); - const qAstroManifestPath = resolver("../q-astro-manifest.json"); const lifecycleHooks: AstroIntegration["hooks"] = { "astro:config:setup": async (setupProps) => { - const { addRenderer, updateConfig, config, command } = setupProps; + const { addRenderer, updateConfig, config } = setupProps; astroConfig = config; - // passes config values to other runtimes with a virtual module - inlineModule({ - constExports: { - isNode: options?.isNode ?? true, - qAstroManifestPath - } - }); - - /* q-astro-manifest.json doesn't error in dev */ - if (command === "dev") { - writeFileSync(qAstroManifestPath, "{}", "utf-8"); - } - // integration HMR support watchDirectory(setupProps, resolver()); @@ -235,12 +220,7 @@ export default defineIntegration({ } } }, - plugins: [ - inlineMod(), - astroQwikPlugin, - qwikVite(qwikSetupConfig), - overrideEsbuildPlugin - ] + plugins: [astroQwikPlugin, qwikVite(qwikSetupConfig), overrideEsbuildPlugin] } }); }, @@ -269,7 +249,28 @@ export default defineIntegration({ outDir: finalDir, manifestOutput: (manifest) => { globalThis.qManifest = manifest; - writeFileSync(qAstroManifestPath, JSON.stringify(manifest), "utf-8"); + + if (astroConfig?.adapter) { + const serverChunksDir = join(serverDir, "chunks"); + const files = fs.readdirSync(serverChunksDir); + const serverFile = files.find( + (f) => f.startsWith("server_") && f.endsWith(".mjs") + ); + + if (serverFile) { + const serverPath = join(serverChunksDir, serverFile); + const content = fs.readFileSync(serverPath, "utf-8"); + + // Replace the manifest handling in the bundled code + const manifestJson = JSON.stringify(manifest); + const newContent = content.replace( + "globalThis.qManifest", + `globalThis.qManifest || ${manifestJson}` + ); + + fs.writeFileSync(serverPath, newContent); + } + } } }, debug: options?.debug ?? false From 911821aa479b9131661f9f243c27987edde69727 Mon Sep 17 00:00:00 2001 From: thejackshelton Date: Sat, 4 Jan 2025 17:52:18 -0600 Subject: [PATCH 2/2] changeset --- .changeset/thirty-jars-care.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/thirty-jars-care.md diff --git a/.changeset/thirty-jars-care.md b/.changeset/thirty-jars-care.md new file mode 100644 index 0000000..2e8ddac --- /dev/null +++ b/.changeset/thirty-jars-care.md @@ -0,0 +1,5 @@ +--- +"@qwikdev/astro": patch +--- + +fix: q-manifest gets added into the bundled code at build time