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 page.goto(astro.resolveUrl('/'));
|
||||||
await initialLog;
|
await initialLog;
|
||||||
|
|
||||||
|
const el = page.locator('#hoisted-script');
|
||||||
|
expect(await el.innerText()).toContain('Hoisted success');
|
||||||
|
|
||||||
const updatedLog = page.waitForEvent(
|
const updatedLog = page.waitForEvent(
|
||||||
'console',
|
'console',
|
||||||
(message) => message.text() === 'Hello, updated Astro!'
|
(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": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"astro": "./Component.astro"
|
"astro": "./Component.astro"
|
||||||
|
},
|
||||||
|
"./HoistedScript": {
|
||||||
|
"astro": "./HoistedScript.astro"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
---
|
---
|
||||||
import Hero from '../components/Hero.astro';
|
import Hero from '../components/Hero.astro';
|
||||||
import LinkedLib from '@e2e/astro-linked-lib'
|
import LinkedLib from '@e2e/astro-linked-lib'
|
||||||
|
import HoistedScript from '@e2e/astro-linked-lib/HoistedScript'
|
||||||
---
|
---
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
|
@ -13,6 +14,7 @@ import LinkedLib from '@e2e/astro-linked-lib'
|
||||||
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
Lorem ipsum, dolor sit amet consectetur adipisicing elit.
|
||||||
</Hero>
|
</Hero>
|
||||||
<LinkedLib />
|
<LinkedLib />
|
||||||
|
<HoistedScript />
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -158,7 +158,11 @@ export function rootRelativePath(root: URL, idOrUrl: URL | string) {
|
||||||
} else {
|
} else {
|
||||||
id = idOrUrl;
|
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) {
|
export function emoji(char: string, fallback: string) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue