diff --git a/apps/demo/package.json b/apps/demo/package.json index 6f50f1d..294eab0 100644 --- a/apps/demo/package.json +++ b/apps/demo/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "@astrojs/react": "^3.6.0", - "@builder.io/qwik": "^1.7.2", + "@builder.io/qwik": "https://pkg.pr.new/@builder.io/qwik@eb845d0", "@qwikdev/astro": "workspace:*", "@qwikest/icons": "^0.0.13", "@types/react": "^18.2.64", diff --git a/apps/demo/src/root.tsx b/apps/demo/src/root.tsx new file mode 100644 index 0000000..9eb1161 --- /dev/null +++ b/apps/demo/src/root.tsx @@ -0,0 +1,9 @@ +import { Slot, component$ } from "@builder.io/qwik"; + +export default component$(() => { + return ( + <> + + + ); +}); diff --git a/libs/qwikdev-astro/package.json b/libs/qwikdev-astro/package.json index 52b62a1..e10ba2f 100644 --- a/libs/qwikdev-astro/package.json +++ b/libs/qwikdev-astro/package.json @@ -57,7 +57,7 @@ "vite-tsconfig-paths": "^4.2.1" }, "devDependencies": { - "@builder.io/qwik": "^1.7.2", + "@builder.io/qwik": "https://pkg.pr.new/@builder.io/qwik@eb845d0", "@types/fs-extra": "^11.0.4", "@types/node": "^20.10.0", "astro": "^4.12.2", @@ -65,7 +65,7 @@ "vite": "^5.3" }, "peerDependencies": { - "@builder.io/qwik": "^1.7.2", + "@builder.io/qwik": "https://pkg.pr.new/@builder.io/qwik@eb845d0", "typescript": "^5.4.2" } } diff --git a/libs/qwikdev-astro/src/entrypoints.ts b/libs/qwikdev-astro/src/entrypoints.ts deleted file mode 100644 index 4247dd8..0000000 --- a/libs/qwikdev-astro/src/entrypoints.ts +++ /dev/null @@ -1,93 +0,0 @@ -import fs from "node:fs"; -import path from "node:path"; -import ts from "typescript"; -import { crawlDirectory } from "./utils"; - -export const qwikModules = [ - "@builder.io/qwik", - "@builder.io/qwik-react", - "@qwikdev/core", - "@qwikdev/qwik-react" -]; - -export async function getQwikEntrypoints( - dir: string, - filter: (id: unknown) => boolean -): Promise { - const files = await crawlDirectory(dir); - const qwikFiles = []; - - // Find project entrypoints - for (const file of files) { - if (!filter(file)) { - continue; - } - const fileContent = fs.readFileSync(file, "utf-8"); - const sourceFile = ts.createSourceFile( - file, - fileContent, - ts.ScriptTarget.ESNext, - true - ); - - let qwikImportFound = false; - - ts.forEachChild(sourceFile, function nodeVisitor(node) { - if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) { - if (qwikModules.includes(node.moduleSpecifier.text)) { - qwikImportFound = true; - } - } - - if (!qwikImportFound) { - ts.forEachChild(node, nodeVisitor); - } - }); - - if (qwikImportFound) { - qwikFiles.push(file); - } - } - - return qwikFiles; - - // Find library entrypoints here - // const nodeModulesPath = path.resolve(dir, "..", "node_modules"); - // const libraryEntrypoints = findQwikLibraryEntrypoints(nodeModulesPath); - - // return [...qwikFiles, ...libraryEntrypoints]; -} - -// function findQwikLibraryEntrypoints(nodeModulesPath: string): string[] { -// const entrypoints: string[] = []; - -// function searchDirectory(dirPath: string) { -// const items = fs.readdirSync(dirPath); - -// for (const item of items) { -// const fullPath = path.join(dirPath, item); -// const stat = fs.statSync(fullPath); - -// if (stat.isDirectory()) { -// // Skip nested node_modules to avoid redundant searches -// if (item === "node_modules") { -// continue; -// } -// searchDirectory(fullPath); -// } else if (stat.isFile() && item.includes(".qwik.")) { -// entrypoints.push(fullPath); -// } -// } -// } - -// // Start the search from each immediate subdirectory of node_modules -// const packages = fs.readdirSync(nodeModulesPath); -// for (const pkg of packages) { -// const pkgPath = path.join(nodeModulesPath, pkg); -// if (fs.statSync(pkgPath).isDirectory()) { -// searchDirectory(pkgPath); -// } -// } - -// return entrypoints; -// } diff --git a/libs/qwikdev-astro/src/index.ts b/libs/qwikdev-astro/src/index.ts index 7b3dd42..4ca90a2 100644 --- a/libs/qwikdev-astro/src/index.ts +++ b/libs/qwikdev-astro/src/index.ts @@ -1,4 +1,3 @@ -import fs from "node:fs"; import { rmSync } from "node:fs"; import os from "node:os"; import { normalize, relative } from "node:path"; @@ -15,7 +14,6 @@ import { build, createFilter } from "vite"; import type { InlineConfig, PluginOption } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; -import { getQwikEntrypoints, qwikModules } from "./entrypoints"; import { moveArtifacts, newHash } from "./utils"; declare global { @@ -35,7 +33,6 @@ const FilterPatternSchema = z.union([ * This project uses Astro Integration Kit. * @see https://astro-integration-kit.netlify.app/ */ - export default defineIntegration({ name: "@qwikdev/astro", optionsSchema: z @@ -63,7 +60,6 @@ export default defineIntegration({ const tempDir = `tmp-${newHash()}`; let astroConfig: AstroConfig | null = null; - let entrypoints: Promise; const { resolve: resolver } = createResolver(import.meta.url); const filter = createFilter(options?.include, options?.exclude); @@ -88,89 +84,76 @@ export default defineIntegration({ // Retrieve Qwik files from the project source directory srcDir = relative(astroConfig.root.pathname, astroConfig.srcDir.pathname); - entrypoints = getQwikEntrypoints(srcDir, filter); + addRenderer({ + name: "@qwikdev/astro", + serverEntrypoint: "@qwikdev/astro/server" + }); - if ((await entrypoints).length !== 0) { - addRenderer({ - name: "@qwikdev/astro", - serverEntrypoint: "@qwikdev/astro/server" - }); + // Update the global dist directory + outDir = astroConfig.outDir.pathname; - // Update the global dist directory - outDir = astroConfig.outDir.pathname; + // checks all windows platforms and removes drive ex: C:\\ + if (os.platform() === "win32") { + outDir = outDir.substring(3); + } - // checks all windows platforms and removes drive ex: C:\\ - if (os.platform() === "win32") { - outDir = outDir.substring(3); + /** We need to get the symbolMapper straight from qwikVite here. You can think of it as the "manifest" for dev mode. */ + const symbolMapperPlugin: PluginOption = { + name: "grabSymbolMapper", + configResolved() { + globalThis.symbolMapperFn = symbolMapper; } + }; - /** We need to get the symbolMapper straight from qwikVite here. You can think of it as the "manifest" for dev mode. */ - const symbolMapperPlugin: PluginOption = { - name: "grabSymbolMapper", - configResolved() { - globalThis.symbolMapperFn = symbolMapper; - } - }; - - /** check if the file should be processed based on the 'transform' hook and user-defined filters (include & exclude) */ - const fileFilter = (id: string, hook: string) => { - try { - const content = fs.readFileSync(id, "utf-8"); - if (qwikModules.some((module) => content.includes(module))) { - return true; - } - } catch (error) { - // file can't be read, silently continue - } - - if (hook === "transform" && !filter(id)) { - return false; - } - - return true; - }; + /** check if the file should be processed based on the 'transform' hook and user-defined filters (include & exclude) */ + const fileFilter = (id: string, hook: string) => { + if (hook === "transform" && !filter(id)) { + return false; + } - const qwikViteConfig: QwikVitePluginOptions = { - fileFilter, - devSsrServer: false, - srcDir, - client: { - input: await entrypoints - }, - ssr: { - input: "@qwikdev/astro/server" - }, - debug: options?.debug ?? false - }; - - const overrideEsbuildPlugin: PluginOption = { - // override qwikVite's attempt to set `esbuild` to false during dev - name: "overrideEsbuild", - enforce: "post", - config(config) { - config.esbuild = {}; - return config; - } - }; - - updateConfig({ - vite: { - build: { - rollupOptions: { - output: { - inlineDynamicImports: false - } + return true; + }; + + const qwikViteConfig: QwikVitePluginOptions = { + fileFilter, + devSsrServer: false, + srcDir, + client: { + input: "src/root.tsx" + }, + ssr: { + input: "@qwikdev/astro/server" + }, + debug: options?.debug ?? false + }; + + const overrideEsbuildPlugin: PluginOption = { + // override qwikVite's attempt to set `esbuild` to false during dev + name: "overrideEsbuild", + enforce: "post", + config(config) { + config.esbuild = {}; + return config; + } + }; + + updateConfig({ + vite: { + build: { + rollupOptions: { + output: { + inlineDynamicImports: false } - }, - plugins: [ - symbolMapperPlugin, - qwikVite(qwikViteConfig), - tsconfigPaths(), - overrideEsbuildPlugin - ] - } - }); - } + } + }, + plugins: [ + symbolMapperPlugin, + qwikVite(qwikViteConfig), + tsconfigPaths(), + overrideEsbuildPlugin + ] + } + }); }, "astro:config:done": async ({ config }) => { @@ -180,55 +163,52 @@ export default defineIntegration({ "astro:build:start": async ({ logger }) => { logger.info("astro:build:start"); - if ((await entrypoints).length > 0) { - // make sure vite does not parse .astro files in the qwik integration - const astroNoopPlugin: PluginOption = { - enforce: "pre", - name: "astro-noop", + // make sure vite does not parse .astro files in the qwik integration + const astroNoopPlugin: PluginOption = { + enforce: "pre", + name: "astro-noop", - load(id: string) { - if (id.endsWith(".astro")) { - return "export default function() {}"; - } - return null; + load(id: string) { + if (id.endsWith(".astro")) { + return "export default function() {}"; } - }; + return null; + } + }; - // client build that we pass back to the server build - await build({ - ...astroConfig?.vite, - plugins: [...(astroConfig?.vite.plugins || []), astroNoopPlugin] - } as InlineConfig); + // client build that we pass back to the server build + await build({ + ...astroConfig?.vite, + plugins: [...(astroConfig?.vite.plugins || []), astroNoopPlugin] + } as InlineConfig); - await moveArtifacts(outDir, tempDir); - } else { - logger.info("No entrypoints found. Skipping build."); - } + await moveArtifacts(outDir, tempDir); }, - "astro:build:done": async ({ logger }) => { - if ((await entrypoints).length > 0 && astroConfig) { - let outputPath: string; - if (astroConfig.output === "server" || astroConfig.output === "hybrid") { - outputPath = astroConfig.build.client.pathname; - } else { - outputPath = astroConfig.outDir.pathname; - } + "astro:build:done": async () => { + let outputPath: string; - // checks all windows platforms and removes drive ex: C:\\ - if (os.platform() === "win32") { - outputPath = outputPath.substring(3); - } - - const normalizedPath = normalize(outputPath); - process.env.Q_BASE = normalizedPath; + if (!astroConfig) { + throw new Error("Qwik Astro: there is no astro config present."); + } - await moveArtifacts(tempDir, normalizedPath); - // remove the temp dir folder - rmSync(tempDir, { recursive: true }); + if (astroConfig.output === "server" || astroConfig.output === "hybrid") { + outputPath = astroConfig.build.client.pathname; } else { - logger.info("Build finished. No artifacts moved."); + outputPath = astroConfig.outDir.pathname; } + + // checks all windows platforms and removes drive ex: C:\\ + if (os.platform() === "win32") { + outputPath = outputPath.substring(3); + } + + const normalizedPath = normalize(outputPath); + process.env.Q_BASE = normalizedPath; + + await moveArtifacts(tempDir, normalizedPath); + // remove the temp dir folder + rmSync(tempDir, { recursive: true }); } }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8a85c65..8f1b260 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,14 +33,14 @@ importers: specifier: ^3.6.0 version: 3.6.0(@types/react-dom@18.2.25)(@types/react@18.2.79)(react-dom@18.2.0(react@18.2.0))(react@18.2.0)(vite@5.3.5(@types/node@20.12.7)) '@builder.io/qwik': - specifier: ^1.7.2 - version: 1.7.3(@types/node@20.12.7) + specifier: https://pkg.pr.new/@builder.io/qwik@eb845d0 + version: https://pkg.pr.new/@builder.io/qwik@eb845d0(@types/node@20.12.7) '@qwikdev/astro': specifier: workspace:* version: link:../../libs/qwikdev-astro '@qwikest/icons': specifier: ^0.0.13 - version: 0.0.13(@builder.io/qwik@1.7.3(@types/node@20.12.7)) + version: 0.0.13(@builder.io/qwik@https://pkg.pr.new/@builder.io/qwik@eb845d0(@types/node@20.12.7)) '@types/react': specifier: ^18.2.64 version: 18.2.79 @@ -233,8 +233,8 @@ importers: version: 4.3.2(typescript@5.4.5)(vite@5.3.3(@types/node@20.12.7)) devDependencies: '@builder.io/qwik': - specifier: ^1.7.2 - version: 1.7.3(@types/node@20.12.7) + specifier: https://pkg.pr.new/@builder.io/qwik@eb845d0 + version: https://pkg.pr.new/@builder.io/qwik@eb845d0(@types/node@20.12.7) '@types/fs-extra': specifier: ^11.0.4 version: 11.0.4 @@ -570,6 +570,12 @@ packages: engines: {node: '>=16.8.0 <18.0.0 || >=18.11'} hasBin: true + '@builder.io/qwik@https://pkg.pr.new/@builder.io/qwik@eb845d0': + resolution: {tarball: https://pkg.pr.new/@builder.io/qwik@eb845d0} + version: 1.9.0 + engines: {node: '>=16.8.0 <18.0.0 || >=18.11'} + hasBin: true + '@changesets/apply-release-plan@7.0.0': resolution: {integrity: sha512-vfi69JR416qC9hWmFGSxj7N6wA5J222XNBmezSVATPWDVPIF7gkd4d8CpbEbXmRWbVrkoli3oerGS6dcL/BGsQ==} @@ -1386,6 +1392,7 @@ packages: '@qwikest/icons@0.0.13': resolution: {integrity: sha512-e0wY8vmx0nDSUiuCATlk+ojTvdBV4txIGHHWjZW5SRkv4XB8H9+3WSDcLPz0ItUdRyzcrohE9k2jtQI/98aRPA==} + version: 0.0.13 engines: {node: '>=15.0.0'} peerDependencies: '@builder.io/qwik': '>=1.0.0' @@ -6201,6 +6208,19 @@ snapshots: - sugarss - terser + '@builder.io/qwik@https://pkg.pr.new/@builder.io/qwik@eb845d0(@types/node@20.12.7)': + dependencies: + csstype: 3.1.3 + vite: 5.3.5(@types/node@20.12.7) + transitivePeerDependencies: + - '@types/node' + - less + - lightningcss + - sass + - stylus + - sugarss + - terser + '@changesets/apply-release-plan@7.0.0': dependencies: '@babel/runtime': 7.24.4 @@ -6930,9 +6950,9 @@ snapshots: '@pnpm/network.ca-file': 1.0.2 config-chain: 1.1.13 - '@qwikest/icons@0.0.13(@builder.io/qwik@1.7.3(@types/node@20.12.7))': + '@qwikest/icons@0.0.13(@builder.io/qwik@https://pkg.pr.new/@builder.io/qwik@eb845d0(@types/node@20.12.7))': dependencies: - '@builder.io/qwik': 1.7.3(@types/node@20.12.7) + '@builder.io/qwik': https://pkg.pr.new/@builder.io/qwik@eb845d0(@types/node@20.12.7) '@rollup/rollup-android-arm-eabi@4.16.1': optional: true