Skip to content

Commit 323ac67

Browse files
committed
Fix run query param parsing
1 parent dfce98a commit 323ac67

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

src/lib/vite.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ function main({
3030
} = {}) {
3131
return imagetools({
3232
defaultDirectives: (url) =>
33-
url.searchParams.get('as') === 'run' ? runDefaultDirectives : defaultDirectives,
33+
url.searchParams.get('as')?.split(':')[0] === 'run'
34+
? runDefaultDirectives
35+
: defaultDirectives,
3436
extendOutputFormats: (builtins) => ({ ...extendOutputFormats(builtins), run }),
3537
exclude,
3638
...rest

src/routes/+page.svelte

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import i5 from './assets/1920/5.jpg?h=720&as=run'
99
import pllx from './assets/pllx.jpg?h=1024&as=run'
1010
import Img, { FxReveal, FxParallax } from '$lib/index.js'
1111
import { version } from '$app/environment'
12-
import testSingle from './assets/640/01.jpg?w=80&h=80&as=run:0'
12+
import testSingle from './assets/640/01.jpg?w=80&h=80&format=jpg&as=run:0'
1313
import testFallback from './assets/640/01.jpg?h=80'
1414
1515
const modules = import.meta.glob('./assets/640/*.jpg', {
@@ -108,11 +108,13 @@ export default defineConfig({
108108
</blockquote>
109109
</div>
110110

111-
<Img
112-
class="w-full h-[32rem] max-w-[1920px] mx-auto object-cover mb-16 test-1px"
113-
src={i2}
114-
alt="cat"
115-
/>
111+
<div class="test-run-param">
112+
<Img
113+
class="w-full h-[32rem] max-w-[1920px] mx-auto object-cover mb-16 test-1px"
114+
src={i2}
115+
alt="cat"
116+
/>
117+
</div>
116118

117119
<div class="prose mx-auto px-4 mb-8">
118120
<blockquote>Which looks like this.</blockquote>

tests/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ test('falls back to standard imagetools without run directive', async ({ page })
2929
expect(await page.locator('.test-fallback').innerText()).toContain('@imagetools')
3030
})
3131

32+
test('run with param uses runDefaultDirectives', async ({ page }) => {
33+
await page.goto('/')
34+
expect(await page.locator('.test-run-param source').count()).toBe(3)
35+
})
36+
3237
/*
3338
test('', async ({ page }) => {
3439
await page.goto('/')

0 commit comments

Comments
 (0)