-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(astro): ignore query params when matching .astro extension (#11240)
* fix: ignore query params when matching .astro extension * Changeset * Add test
- Loading branch information
Showing
7 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Ignores query strings in module identifiers when matching ".astro" file extensions in Vite plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import assert from 'node:assert/strict'; | ||
import { before, describe, it } from 'node:test'; | ||
import * as cheerio from 'cheerio'; | ||
import { loadFixture } from './test-utils.js'; | ||
|
||
describe('Matching .astro modules', () => { | ||
let fixture; | ||
/** @type {string} */ | ||
let output; | ||
|
||
before(async () => { | ||
fixture = await loadFixture({ | ||
root: './fixtures/extension-matching/', | ||
}); | ||
await fixture.build(); | ||
output = await fixture.readFile('./index.html'); | ||
}); | ||
|
||
it('loads virtual modules with .astro in query string', async () => { | ||
const $ = cheerio.load(output); | ||
const title = $('h1').text(); | ||
assert.strictEqual(title, 'true'); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/astro/test/fixtures/extension-matching/astro.config.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { defineConfig } from 'astro/config'; | ||
|
||
const MODULE_ID = 'virtual:test'; | ||
const RESOLVED_MODULE_ID = '\0virtual:test'; | ||
|
||
export default defineConfig({ | ||
integrations: [ | ||
{ | ||
name: 'astro-test-invalid-transform', | ||
hooks: { | ||
'astro:config:setup': ({ updateConfig }) => { | ||
updateConfig({ | ||
vite: { | ||
plugins: [ | ||
// ----------------------------------- | ||
{ | ||
name: 'vite-test-invalid-transform', | ||
resolveId(id) { | ||
if (id === MODULE_ID) { | ||
// Astro tries to transform this import because the query params can end with '.astro' | ||
return `${RESOLVED_MODULE_ID}?importer=index.astro`; | ||
} | ||
}, | ||
load(id) { | ||
if (id.startsWith(RESOLVED_MODULE_ID)) { | ||
return `export default 'true';`; | ||
} | ||
}, | ||
}, | ||
// ----------------------------------- | ||
], | ||
}, | ||
}); | ||
}, | ||
}, | ||
}, | ||
], | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/astro/test/fixtures/extension-matching/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@test/extension-matching", | ||
"type": "module", | ||
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "astro dev", | ||
"start": "astro dev", | ||
"build": "astro build", | ||
"preview": "astro preview", | ||
"astro": "astro" | ||
}, | ||
"dependencies": { | ||
"astro": "workspace:*" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/astro/test/fixtures/extension-matching/src/pages/index.astro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
let success = 'false' | ||
try { | ||
success = (await import('virtual:test')).default | ||
} catch (e) { | ||
console.error('Failed to load virtual module:', e) | ||
} | ||
console.log('Loaded virtual module:', success) | ||
--- | ||
<h1>{String(success)}</h1> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.