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
This commit is contained in:
Rishi Raj Jain 2023-01-23 20:13:06 +05:30 committed by GitHub
parent 46ecd5de34
commit 77ae7a597a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/partytown': patch
---
fix trailing slash with base path

View file

@ -17,6 +17,10 @@ type PartytownOptions =
} }
| undefined; | undefined;
function appendForwardSlash(str: string) {
return str.endsWith('/') ? str : str + '/';
}
export default function createPlugin(options: PartytownOptions): AstroIntegration { export default function createPlugin(options: PartytownOptions): AstroIntegration {
let config: AstroConfig; let config: AstroConfig;
let partytownSnippetHtml: string; let partytownSnippetHtml: string;
@ -26,7 +30,7 @@ export default function createPlugin(options: PartytownOptions): AstroIntegratio
name: '@astrojs/partytown', name: '@astrojs/partytown',
hooks: { hooks: {
'astro:config:setup': ({ config: _config, command, injectScript }) => { 'astro:config:setup': ({ config: _config, command, injectScript }) => {
const lib = `${_config.base}~partytown/`; const lib = `${appendForwardSlash(_config.base)}~partytown/`;
const forward = options?.config?.forward || []; const forward = options?.config?.forward || [];
const debug = options?.config?.debug || command === 'dev'; const debug = options?.config?.debug || command === 'dev';
partytownSnippetHtml = partytownSnippet({ lib, debug, forward }); partytownSnippetHtml = partytownSnippet({ lib, debug, forward });