mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Fix: Relative imports inside of hosited script on windows (#3423)
* Failing test * Add some debugging * Normalize filename to remove @fs prefix * Adds a changeset * Break it again * Fix it * Update assertion
This commit is contained in:
parent
af179c0d89
commit
463a1c2147
5 changed files with 17 additions and 4 deletions
5
.changeset/friendly-ways-collect.md
Normal file
5
.changeset/friendly-ways-collect.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix relative inline scripts on Windows
|
|
@ -62,8 +62,9 @@ export default function astro({ config, logging }: AstroPluginOptions): vite.Plu
|
|||
// If resolving from an astro subresource such as a hoisted script,
|
||||
// we need to resolve relative paths ourselves.
|
||||
if (from) {
|
||||
const { query: fromQuery, filename } = parseAstroRequest(from);
|
||||
if (fromQuery.astro && isRelativePath(id) && fromQuery.type === 'script') {
|
||||
const parsedFrom = parseAstroRequest(from);
|
||||
if (parsedFrom.query.astro && isRelativePath(id) && parsedFrom.query.type === 'script') {
|
||||
const filename = normalizeFilename(parsedFrom.filename);
|
||||
const resolvedURL = new URL(id, `file://${filename}`);
|
||||
const resolved = resolvedURL.pathname;
|
||||
if (isBrowserPath(resolved)) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cheerio from 'cheerio';
|
||||
import path from 'path';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
|
||||
describe('Scripts (hoisted and not)', () => {
|
||||
|
@ -50,6 +49,9 @@ describe('Scripts (hoisted and not)', () => {
|
|||
|
||||
// test 3: the JS exists
|
||||
expect(inlineEntryJS).to.be.ok;
|
||||
|
||||
// test 4: Inline imported JS is included
|
||||
expect(inlineEntryJS).to.contain("I AM IMPORTED INLINE", "The inline imported JS is included in the bundle");
|
||||
});
|
||||
|
||||
it('External page builds the hoisted scripts to a single bundle', async () => {
|
||||
|
|
|
@ -12,5 +12,9 @@ import Inline from '../components/Inline.astro';
|
|||
<Inline />
|
||||
<Inline />
|
||||
<Inline />
|
||||
<script>
|
||||
// This must be relative for the test
|
||||
import '../scripts/hoist_external_imported_inline.js';
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
1
packages/astro/test/fixtures/astro-scripts/src/scripts/hoist_external_imported_inline.js
vendored
Normal file
1
packages/astro/test/fixtures/astro-scripts/src/scripts/hoist_external_imported_inline.js
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("I AM IMPORTED INLINE");
|
Loading…
Reference in a new issue