Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(partytown): allow overriding copyLibFiles.dest in astro:build:done hook with the lib option #13109

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changeset/plenty-coins-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@astrojs/partytown': patch
---

Adds support for overriding `copyLibFiles.dest` in the `astro:build:done` hook using the `lib` option in `astro.config.*`, if provided. If not specified, it falls back to the default `~partytown`. Also removes the leading "/" from the `lib` value to match the behavior of `fileURLToPath`.

Example:

```typescript
// Options in `astro.config.*`
partytown.config.lib = '/assets/lib/~partytown/';

// `astro:build:done` in `@astrojs/partytown` integration
copyLibFiles.dest =
partytown.config.lib ?
`${PROJECT_ROOT}/assets/lib/~partytown/` // Leading "/" removed to match `fileURLToPath` behavior
: '~partytown'; // Default fallback
```
3 changes: 2 additions & 1 deletion packages/integrations/partytown/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default function createPlugin(options?: PartytownOptions): AstroIntegrati
);
},
'astro:build:done': async ({ dir }) => {
await copyLibFiles(fileURLToPath(new URL('~partytown', dir)), {
let libValue = options?.config?.lib?.replace(/^\/?/, '');
await copyLibFiles(fileURLToPath(new URL(libValue || '~partytown', dir)), {
debugDir: options?.config?.debug ?? false,
});
},
Expand Down