From 1d5e936aa3f6a16f5bf8e8a4148724c2c7aa1650 Mon Sep 17 00:00:00 2001 From: arnottferels <64685389+arnottferels@users.noreply.github.com> Date: Fri, 31 Jan 2025 17:58:31 +0700 Subject: [PATCH] Support overriding copyLibFiles.dest in stro:build:done hook with lib option, defaulting to ~partytown. Remove leading '/' to match ileURLToPath. --- .changeset/plenty-coins-destroy.md | 18 ++++++++++++++++++ packages/integrations/partytown/src/index.ts | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 .changeset/plenty-coins-destroy.md diff --git a/.changeset/plenty-coins-destroy.md b/.changeset/plenty-coins-destroy.md new file mode 100644 index 000000000000..cff4f57098d0 --- /dev/null +++ b/.changeset/plenty-coins-destroy.md @@ -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 +``` \ No newline at end of file diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index f2ffbfea42c9..126cef5643ff 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -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, }); },