From df0c6335c68c9b23fd2b63a36986d365687a5272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SIGUI=20Kess=C3=A9=20Emmanuel?= Date: Tue, 14 Nov 2023 05:15:44 +0100 Subject: [PATCH] :sparkles: Fix #13: Add include and exclude options to filter entrypoints. --- apps/astro-demo/astro.config.mjs | 7 ++++++- libs/qwikdev-astro/src/index.ts | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/astro-demo/astro.config.mjs b/apps/astro-demo/astro.config.mjs index 4b8b8c7..f90abe2 100644 --- a/apps/astro-demo/astro.config.mjs +++ b/apps/astro-demo/astro.config.mjs @@ -8,5 +8,10 @@ export default defineConfig({ adapter: node({ mode: "standalone", }), - integrations: [qwik()], + integrations: [qwik({ + exclude: [ + "**/react/*", + "**/react-*", + ] + })], }); diff --git a/libs/qwikdev-astro/src/index.ts b/libs/qwikdev-astro/src/index.ts index 15288df..95c5788 100644 --- a/libs/qwikdev-astro/src/index.ts +++ b/libs/qwikdev-astro/src/index.ts @@ -1,4 +1,4 @@ -import { build } from "vite"; +import { build, createFilter, type FilterPattern } from "vite"; import { join, relative } from "node:path"; import { createInterface } from "node:readline"; import { qwikVite } from "@builder.io/qwik/optimizer"; @@ -8,7 +8,10 @@ import { getQwikLoaderScript } from "@builder.io/qwik/server"; import type { AstroConfig, AstroIntegration } from "astro"; -export default function createIntegration(): AstroIntegration { +export type Options = Partial<{ include: FilterPattern, exclude: FilterPattern }>; + +export default function createIntegration(options: Options = {}): AstroIntegration { + let filter = createFilter(options.include, options.exclude); let distDir: string = ""; let entryDir: string = ""; let astroConfig: AstroConfig | null = null; @@ -32,7 +35,7 @@ export default function createIntegration(): AstroIntegration { astroConfig.root.pathname, astroConfig.srcDir.pathname ); - entrypoints = getQwikEntrypoints(entryDir); + entrypoints = getQwikEntrypoints(entryDir, filter); if ((await entrypoints).length !== 0) { addRenderer({ name: "@qwikdev/astro", @@ -138,11 +141,16 @@ async function crawlDirectory(dir: string): Promise { * We need to find the Qwik entrypoints so that the client build will run successfully. * */ -async function getQwikEntrypoints(dir: string): Promise { +async function getQwikEntrypoints(dir: string, filter: (id: unknown) => boolean ): Promise { const files = await crawlDirectory(dir); const qwikFiles = []; for (const file of files) { + // Skip files not matching patterns + if (! filter(file)) { + continue; + } + const fileStream = createReadStream(file); // holds readline interface @@ -174,5 +182,7 @@ async function getQwikEntrypoints(dir: string): Promise { } } + console.log("Qwik entrypoints: ", qwikFiles); + return qwikFiles; }