fix: imports for images with uppercase extensions not working (#8437)
This commit is contained in:
parent
6df4f3bd9d
commit
b3cf1b3276
5 changed files with 31 additions and 3 deletions
5
.changeset/nice-sheep-bathe.md
Normal file
5
.changeset/nice-sheep-bathe.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix imports of images with uppercased file extensions not working
|
|
@ -8,12 +8,14 @@ import {
|
|||
prependForwardSlash,
|
||||
removeQueryString,
|
||||
} from '../core/path.js';
|
||||
import { VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from './consts.js';
|
||||
import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from './consts.js';
|
||||
import { emitESMImage } from './utils/emitAsset.js';
|
||||
import { hashTransform, propsToFilename } from './utils/transformToPath.js';
|
||||
|
||||
const resolvedVirtualModuleId = '\0' + VIRTUAL_MODULE_ID;
|
||||
|
||||
const assetRegex = new RegExp(`\.(${VALID_INPUT_FORMATS.join('|')})$`, 'i');
|
||||
|
||||
export default function assets({
|
||||
settings,
|
||||
mode,
|
||||
|
@ -121,7 +123,7 @@ export default function assets({
|
|||
if (id !== removeQueryString(id)) {
|
||||
return;
|
||||
}
|
||||
if (/\.(jpeg|jpg|png|tiff|webp|gif|svg)$/.test(id)) {
|
||||
if (assetRegex.test(id)) {
|
||||
const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile);
|
||||
return `export default ${JSON.stringify(meta)}`;
|
||||
}
|
||||
|
|
|
@ -3,10 +3,10 @@ import * as cheerio from 'cheerio';
|
|||
import { basename } from 'node:path';
|
||||
import { Writable } from 'node:stream';
|
||||
import { removeDir } from '../dist/core/fs/index.js';
|
||||
import { Logger } from '../dist/core/logger/core.js';
|
||||
import testAdapter from './test-adapter.js';
|
||||
import { testImageService } from './test-image-service.js';
|
||||
import { loadFixture } from './test-utils.js';
|
||||
import { Logger } from '../dist/core/logger/core.js';
|
||||
|
||||
describe('astro:image', () => {
|
||||
/** @type {import('./test-utils').Fixture} */
|
||||
|
@ -159,6 +159,21 @@ describe('astro:image', () => {
|
|||
res = await fixture.fetch(src);
|
||||
expect(res.status).to.equal(200);
|
||||
});
|
||||
|
||||
it('supports uppercased imports', async () => {
|
||||
let res = await fixture.fetch('/uppercase');
|
||||
let html = await res.text();
|
||||
$ = cheerio.load(html);
|
||||
|
||||
let $img = $('img');
|
||||
expect($img).to.have.a.lengthOf(1);
|
||||
|
||||
let src = $img.attr('src');
|
||||
let loading = $img.attr('loading');
|
||||
res = await fixture.fetch(src);
|
||||
expect(res.status).to.equal(200);
|
||||
expect(loading).to.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('vite-isms', () => {
|
||||
|
|
BIN
packages/astro/test/fixtures/core-image/src/assets/walrus.JPG
vendored
Normal file
BIN
packages/astro/test/fixtures/core-image/src/assets/walrus.JPG
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
6
packages/astro/test/fixtures/core-image/src/pages/uppercase.astro
vendored
Normal file
6
packages/astro/test/fixtures/core-image/src/pages/uppercase.astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
import { Image } from "astro:assets";
|
||||
import walrus from "../assets/walrus.JPG";
|
||||
---
|
||||
|
||||
<Image src={walrus} alt="My favorite animal, the walrus"></Image>
|
Loading…
Reference in a new issue