Skip to content

Commit

Permalink
fix(integration api): improve module resolution (#10060)
Browse files Browse the repository at this point in the history
* fix(integration api): improve module resolution

* add changeset
  • Loading branch information
lilnasy authored Feb 9, 2024
1 parent 989ea63 commit 1810309
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-shirts-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fixes an issue where custom client directives added by integrations broke builds with a custom root.
7 changes: 4 additions & 3 deletions packages/astro/src/core/client-directive/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { build } from 'esbuild';
import { fileURLToPath } from 'node:url';

/**
* Build a client directive entrypoint into code that can directly run in a `<script>` tag.
*/
export async function buildClientDirectiveEntrypoint(name: string, entrypoint: string) {
export async function buildClientDirectiveEntrypoint(name: string, entrypoint: string, root: URL) {
const stringifiedName = JSON.stringify(name);
const stringifiedEntrypoint = JSON.stringify(entrypoint);

Expand All @@ -17,9 +18,9 @@ import directive from ${stringifiedEntrypoint};
(self.Astro || (self.Astro = {}))[${stringifiedName}] = directive;
window.dispatchEvent(new Event('astro:' + ${stringifiedName}));`,
resolveDir: process.cwd(),
resolveDir: fileURLToPath(root),
},
absWorkingDir: process.cwd(),
absWorkingDir: fileURLToPath(root),
format: 'iife',
minify: true,
bundle: true,
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/integrations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export async function runHookConfigSetup({
`The "${integration.name}" integration is trying to add the "${name}" client directive, but it already exists.`
);
}
addedClientDirectives.set(name, buildClientDirectiveEntrypoint(name, entrypoint));
// TODO: this should be performed after astro:config:done
addedClientDirectives.set(name, buildClientDirectiveEntrypoint(name, entrypoint, settings.config.root));
},
addMiddleware: ({ order, entrypoint }) => {
if (typeof updatedSettings.middlewares[order] === 'undefined') {
Expand Down

0 comments on commit 1810309

Please sign in to comment.