File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed
packages/enhanced-img/src Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @sveltejs/enhanced-img " : patch
3+ ---
4+
5+ fix: throw an error if image cannot be resolved
Original file line number Diff line number Diff line change @@ -25,12 +25,15 @@ function image_plugin(imagetools_plugin) {
2525 /**
2626 * @type {{
2727 * plugin_context: import('vite').Rollup.PluginContext
28+ * vite_config: import('vite').ResolvedConfig
2829 * imagetools_plugin: import('vite').Plugin
2930 * }}
3031 */
3132 const opts = {
3233 // @ts -expect-error populated when build starts so we cheat on type
3334 plugin_context : undefined ,
35+ // @ts -expect-error populated when build starts so we cheat on type
36+ vite_config : undefined ,
3437 imagetools_plugin
3538 } ;
3639 const preprocessor = image ( opts ) ;
@@ -40,6 +43,9 @@ function image_plugin(imagetools_plugin) {
4043 api : {
4144 sveltePreprocess : preprocessor
4245 } ,
46+ configResolved ( config ) {
47+ opts . vite_config = config ;
48+ } ,
4349 buildStart ( ) {
4450 opts . plugin_context = this ;
4551 }
Original file line number Diff line number Diff line change 1+ import { existsSync } from 'node:fs' ;
2+ import * as path from 'node:path' ;
3+
14import MagicString from 'magic-string' ;
25import { asyncWalk } from 'estree-walker' ;
36import { parse } from 'svelte-parse-markup' ;
@@ -10,6 +13,7 @@ const OPTIMIZABLE = /^[^?]+\.(avif|heif|gif|jpeg|jpg|png|tiff|webp)(\?.*)?$/;
1013/**
1114 * @param {{
1215 * plugin_context: import('vite').Rollup.PluginContext
16+ * vite_config: import('vite').ResolvedConfig
1317 * imagetools_plugin: import('vite').Plugin
1418 * }} opts
1519 * @returns {import('svelte/types/compiler/preprocess').PreprocessorGroup }
@@ -72,7 +76,15 @@ export function image(opts) {
7276 // need any logic blocks
7377 image = await resolve ( opts , url , filename ) ;
7478 if ( ! image ) {
75- return ;
79+ const file_path = url . substring ( 0 , url . indexOf ( '?' ) ) ;
80+ if ( existsSync ( path . resolve ( opts . vite_config . publicDir , file_path ) ) ) {
81+ throw new Error (
82+ `Could not locate ${ file_path } . Please move it to be located relative to the page in the routes directory or reference it beginning with /static/. See https://vitejs.dev/guide/assets for more details on referencing assets.`
83+ ) ;
84+ }
85+ throw new Error (
86+ `Could not locate ${ file_path } . See https://vitejs.dev/guide/assets for more details on referencing assets.`
87+ ) ;
7688 }
7789 images . set ( url , image ) ;
7890 }
You can’t perform that action at this time.
0 commit comments