From f5c1122921c929f3c80ed3a49fc1c53a5c5ee4ba Mon Sep 17 00:00:00 2001 From: Rishi Raj Jain Date: Mon, 23 Jan 2023 20:13:06 +0530 Subject: [PATCH] fix: trailingSlash with base breaking partytown file path (#5936) * fix: trailingSlash with base breaking partytown file path * Update index.ts * Update index.ts * Update index.ts * fix lint * Update index.ts --- .changeset/beige-waves-wave.md | 5 +++++ packages/integrations/partytown/src/index.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/beige-waves-wave.md diff --git a/.changeset/beige-waves-wave.md b/.changeset/beige-waves-wave.md new file mode 100644 index 000000000000..690c371607b7 --- /dev/null +++ b/.changeset/beige-waves-wave.md @@ -0,0 +1,5 @@ +--- +'@astrojs/partytown': patch +--- + +fix trailing slash with base path diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index eed0ab7c537e..adeab75dda91 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -17,6 +17,10 @@ type PartytownOptions = } | undefined; +function appendForwardSlash(str: string) { + return str.endsWith('/') ? str : str + '/'; +} + export default function createPlugin(options: PartytownOptions): AstroIntegration { let config: AstroConfig; let partytownSnippetHtml: string; @@ -26,7 +30,7 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio name: '@astrojs/partytown', hooks: { 'astro:config:setup': ({ config: _config, command, injectScript }) => { - const lib = `${_config.base}~partytown/`; + const lib = `${appendForwardSlash(_config.base)}~partytown/`; const forward = options?.config?.forward || []; const debug = options?.config?.debug || command === 'dev'; partytownSnippetHtml = partytownSnippet({ lib, debug, forward });