@@ -35,10 +35,6 @@ import {
3535 sveltekit_server
3636} from './module_ids.js' ;
3737import { resolve_peer_dependency } from '../../utils/import.js' ;
38- import {
39- APP_VERSION_PLACEHOLDER_BASE ,
40- APP_VERSION_HASH_PLACEHOLDER_BASE
41- } from '../../constants.js' ;
4238
4339const cwd = process . cwd ( ) ;
4440
@@ -188,16 +184,7 @@ async function kit({ svelte_config }) {
188184 const { kit } = svelte_config ;
189185 const out = `${ kit . outDir } /output` ;
190186
191- const app_version = kit . version . name ;
192- const version_hash = hash ( app_version ) ;
193-
194- // if the app version or hash is longer than the placeholder, we need to pad it to avoid
195- // source map damage
196- const app_version_placeholder = APP_VERSION_PLACEHOLDER_BASE . padEnd ( app_version . length , '_' ) ;
197- const app_version_hash_placeholder = APP_VERSION_HASH_PLACEHOLDER_BASE . padEnd (
198- version_hash . length ,
199- '_'
200- ) ;
187+ const version_hash = hash ( kit . version . name ) ;
201188
202189 /** @type {import('vite').ResolvedConfig } */
203190 let vite_config ;
@@ -397,7 +384,7 @@ async function kit({ svelte_config }) {
397384 const browser = ! options ?. ssr ;
398385
399386 const global = is_build
400- ? `globalThis.__sveltekit_${ browser ? app_version_hash_placeholder : version_hash } `
387+ ? `globalThis.__sveltekit_${ version_hash } `
401388 : 'globalThis.__sveltekit_dev' ;
402389
403390 if ( options ?. ssr === false && process . env . TEST !== 'true' ) {
@@ -483,8 +470,10 @@ async function kit({ svelte_config }) {
483470 }
484471
485472 case sveltekit_environment : {
473+ const { version } = svelte_config . kit ;
474+
486475 return dedent `
487- export const version = ${ is_build && browser ? app_version_placeholder : s ( kit . version . name ) } ;
476+ export const version = ${ s ( version . name ) } ;
488477 export let building = false;
489478 export let prerendering = false;
490479
@@ -934,50 +923,7 @@ async function kit({ svelte_config }) {
934923 }
935924 } ;
936925
937- /** @type {import('vite').Plugin } */
938- const plugin_replace_version_and_hash = {
939- name : 'vite-plugin-svelte-replace-version-and-hash' ,
940- enforce : 'post' ,
941-
942- generateBundle ( _ , bundle , __ ) {
943- if ( vite_config . build . ssr ) return ;
944-
945- for ( const file in bundle ) {
946- if ( bundle [ file ] . type !== 'chunk' ) continue ;
947- const chunk = /** @type {import('rollup').OutputChunk } */ ( bundle [ file ] ) ;
948- let code = chunk . code ;
949- if (
950- ! ( code . includes ( app_version_placeholder ) || code . includes ( app_version_hash_placeholder ) )
951- )
952- continue ;
953-
954- // replace the version and version after the chunk hash has already been calculated
955- // to avoid affecting the chunk hash
956- const substitutions = [
957- [ app_version_hash_placeholder , version_hash ] ,
958- [ app_version_placeholder , JSON . stringify ( kit . version . name ) ]
959- ] ;
960-
961- for ( const [ placeholder , replacement ] of substitutions ) {
962- code = code . replaceAll (
963- placeholder ,
964- // pad the replacement to mitigate source map changes
965- replacement . padEnd ( placeholder . length , ' ' )
966- ) ;
967- }
968-
969- chunk . code = code ;
970- }
971- }
972- } ;
973-
974- return [
975- plugin_setup ,
976- plugin_virtual_modules ,
977- plugin_guard ,
978- plugin_compile ,
979- plugin_replace_version_and_hash
980- ] ;
926+ return [ plugin_setup , plugin_virtual_modules , plugin_guard , plugin_compile ] ;
981927}
982928
983929/**
0 commit comments