Fix hoisted scripts path for linked package Astro components (#6872)
This commit is contained in:
parent
8cc53090ca
commit
b6154d2d57
6 changed files with 23 additions and 1 deletions
5
.changeset/hungry-houses-arrive.md
Normal file
5
.changeset/hungry-houses-arrive.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix hoisted scripts path for linked package Astro components
|
|
@ -44,6 +44,9 @@ test.describe('Astro component HMR', () => {
|
|||
await page.goto(astro.resolveUrl('/'));
|
||||
await initialLog;
|
||||
|
||||
const el = page.locator('#hoisted-script');
|
||||
expect(await el.innerText()).toContain('Hoisted success');
|
||||
|
||||
const updatedLog = page.waitForEvent(
|
||||
'console',
|
||||
(message) => message.text() === 'Hello, updated Astro!'
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<div id="hoisted-script"></div>
|
||||
|
||||
<script>
|
||||
document.getElementById('hoisted-script').innerHTML = 'Hoisted success';
|
||||
</script>
|
|
@ -5,6 +5,9 @@
|
|||
"exports": {
|
||||
".": {
|
||||
"astro": "./Component.astro"
|
||||
},
|
||||
"./HoistedScript": {
|
||||
"astro": "./HoistedScript.astro"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
---
|
||||
import Hero from '../components/Hero.astro';
|
||||
import LinkedLib from '@e2e/astro-linked-lib'
|
||||
import HoistedScript from '@e2e/astro-linked-lib/HoistedScript'
|
||||
---
|
||||
|
||||
<html>
|
||||
|
@ -13,6 +14,7 @@ import LinkedLib from '@e2e/astro-linked-lib'
|
|||
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
||||
</Hero>
|
||||
<LinkedLib />
|
||||
<HoistedScript />
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -158,7 +158,11 @@ export function rootRelativePath(root: URL, idOrUrl: URL | string) {
|
|||
} else {
|
||||
id = idOrUrl;
|
||||
}
|
||||
return prependForwardSlash(id.slice(normalizePath(fileURLToPath(root)).length));
|
||||
const normalizedRoot = normalizePath(fileURLToPath(root));
|
||||
if (id.startsWith(normalizedRoot)) {
|
||||
id = id.slice(normalizedRoot.length);
|
||||
}
|
||||
return prependForwardSlash(id);
|
||||
}
|
||||
|
||||
export function emoji(char: string, fallback: string) {
|
||||
|
|
Loading…
Reference in a new issue