@@ -35,10 +35,6 @@ import {
35
35
sveltekit_server
36
36
} from './module_ids.js' ;
37
37
import { resolve_peer_dependency } from '../../utils/import.js' ;
38
- import {
39
- APP_VERSION_PLACEHOLDER_BASE ,
40
- APP_VERSION_HASH_PLACEHOLDER_BASE
41
- } from '../../constants.js' ;
42
38
43
39
const cwd = process . cwd ( ) ;
44
40
@@ -188,16 +184,7 @@ async function kit({ svelte_config }) {
188
184
const { kit } = svelte_config ;
189
185
const out = `${ kit . outDir } /output` ;
190
186
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 ) ;
201
188
202
189
/** @type {import('vite').ResolvedConfig } */
203
190
let vite_config ;
@@ -397,7 +384,7 @@ async function kit({ svelte_config }) {
397
384
const browser = ! options ?. ssr ;
398
385
399
386
const global = is_build
400
- ? `globalThis.__sveltekit_${ browser ? app_version_hash_placeholder : version_hash } `
387
+ ? `globalThis.__sveltekit_${ version_hash } `
401
388
: 'globalThis.__sveltekit_dev' ;
402
389
403
390
if ( options ?. ssr === false && process . env . TEST !== 'true' ) {
@@ -483,8 +470,10 @@ async function kit({ svelte_config }) {
483
470
}
484
471
485
472
case sveltekit_environment : {
473
+ const { version } = svelte_config . kit ;
474
+
486
475
return dedent `
487
- export const version = ${ is_build && browser ? app_version_placeholder : s ( kit . version . name ) } ;
476
+ export const version = ${ s ( version . name ) } ;
488
477
export let building = false;
489
478
export let prerendering = false;
490
479
@@ -934,50 +923,7 @@ async function kit({ svelte_config }) {
934
923
}
935
924
} ;
936
925
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 ] ;
981
927
}
982
928
983
929
/**
0 commit comments