Skip to content

Commit

Permalink
support libs
Browse files Browse the repository at this point in the history
  • Loading branch information
thejackshelton committed Nov 30, 2024
1 parent c370247 commit cbc9aaf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion apps/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"@builder.io/qwik": "^1.10",
"@qwikdev/astro": "workspace:*",
"astro": "^4.16.14"
"astro": "^4.16.14",
"demo-lib": "workspace:*"
}
}
12 changes: 6 additions & 6 deletions apps/demo/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
import { ViewTransitions } from "astro:transitions";
import { Counter } from "@components/qwik/counter";
import { Counter } from "demo-lib";
import { Counter as NativeCounter } from "@components/qwik/counter";
---

<html lang="en">
Expand All @@ -10,11 +10,11 @@ import { Counter } from "@components/qwik/counter";
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Astro</title>
<ViewTransitions />
</head>
<body>
<div style={{ height: '1000px' }}>
<Counter initial={5}>Yo</Counter>
<div style={{ height: "1000px" }}>
<Counter />
<NativeCounter initial={2} />
</div>
</body>
</html>
</html>
25 changes: 21 additions & 4 deletions libs/qwikdev-astro/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const FilterPatternSchema = z.union([
]);

const qwikEntrypoints = new Set<string>();
const potentialEntrypoints = new Set<string>();
let resolveEntrypoints: () => void;
const entrypointsReady = new Promise<void>((resolve) => {
resolveEntrypoints = resolve;
Expand Down Expand Up @@ -131,12 +132,28 @@ export default defineIntegration({
throw new Error(`Could not resolve ${id} from ${importer}`);
}

console.log("RESOLVED ID:", resolved.id);

// Only add non-astro files to entrypoints
if (resolved.id.includes(".tsx")) {
// qwik libraries
if (resolved.id.includes(".qwik.")) {
qwikEntrypoints.add(resolved.id);
}

if (/\.(tsx|jsx|ts|js)$/.test(resolved.id)) {
potentialEntrypoints.add(resolved.id);
}

return null;
},
async transform(code, id) {
if (!potentialEntrypoints.has(id)) {
return null;
}

const qwikPackages = ['@builder.io/qwik', "@builder.io/qwik-react", "qwik.dev/core", "@qwik.dev/react"]

if (qwikPackages.some(pkg => code.includes(pkg))) {
qwikEntrypoints.add(id);
}

return null;
}
};
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cbc9aaf

Please sign in to comment.