Repository: sveltejs/kit (js)

Issue:
Make "version" available from $app/environment
### Describe the problem

Caching is great, it makes things fast. But using a cached page after an app deploy means all the script references are wrong and "bad things". So some form of "app version" needs to be part of any cache key.

There is a generated version string, used for the update checks. That could be read from `build/client/_app/version.json`except ... it won't be there during the build if pre-rendering.

So you have to check if running in `dev` or `prerendering` mode before reading the file.

### Describe the proposed solution

I would like to be able to access the version string from `$app/environment`

### Alternatives considered

Maybe it's already exposed from '$service-worker'?

But I don't know if that only works if using a service-worker, and it feels odd importing it from there when it isn't _really_ anything todo with a service-worker.

### Importance

nice to have

### Additional Information

_No response_

Pull request description:
expose `version` from `$app/environment`
closes #7436

### Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
- [x] It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
- [x] This message body should clearly illustrate what problems it solves.
- [x] Ideally, include a test that fails without this PR but passes with it.

### Tests
- [x] Run the tests with `pnpm test` and lint the project with `pnpm lint` and `pnpm check`

### Changesets
- [x] If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running `pnpm changeset` and following the prompts. All changesets should be `patch` until SvelteKit 1.0


Patch:
diff --git a/.changeset/clever-students-report.md b/.changeset/clever-students-report.md
new file mode 100644
index 000000000..49cd156bf
--- /dev/null
+++ b/.changeset/clever-students-report.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Add `Access-Control-Allow-Origin: *` to static assets in dev
diff --git a/.changeset/friendly-plums-notice.md b/.changeset/friendly-plums-notice.md
new file mode 100644
index 000000000..d1f5cd192
--- /dev/null
+++ b/.changeset/friendly-plums-notice.md
@@ -0,0 +1,5 @@
+---
+'@sveltejs/kit': patch
+---
+
+Expose version from `$app/environment`
diff --git a/.changeset/pre.json b/.changeset/pre.json
index 1b0c3dc07..f47dd0e27 100644
--- a/.changeset/pre.json
+++ b/.changeset/pre.json
@@ -180,6 +180,7 @@
     "clever-pillows-sing",
     "clever-readers-turn",
     "clever-shrimps-whisper",
+    "clever-students-report",
     "clever-tools-enjoy",
     "cold-boats-wave",
     "cold-buttons-sell",
@@ -432,6 +433,7 @@
     "gentle-dogs-heal",
     "gentle-maps-pull",
     "gentle-news-shout",
+    "gentle-rocks-run",
     "gentle-rules-camp",
     "gentle-shoes-run",
     "gentle-years-leave",
@@ -545,6 +547,7 @@
     "hot-books-march",
     "hot-clouds-work",
     "hot-dogs-fry",
+    "hot-keys-lick",
     "hot-keys-walk",
     "hot-kings-confess",
     "hot-lions-cough",
diff --git a/packages/kit/CHANGELOG.md b/packages/kit/CHANGELOG.md
index 47411692c..1142c62e9 100644
--- a/packages/kit/CHANGELOG.md
+++ b/packages/kit/CHANGELOG.md
@@ -1,5 +1,13 @@
 # @sveltejs/kit
 
+## 1.0.0-next.551
+
+### Patch Changes
+
+- Add `Access-Control-Allow-Origin: *` to static assets in dev ([#7688](https://github.com/sveltejs/kit/pull/7688))
+
+- Ignore presence of `keepfocus` and `noscroll` in `goto` options if correctly-cased options are also present ([#7678](https://github.com/sveltejs/kit/pull/7678))
+
 ## 1.0.0-next.550
 
 ### Patch Changes
diff --git a/packages/kit/package.json b/packages/kit/package.json
index 70a2a4329..38bd048cf 100644
--- a/packages/kit/package.json
+++ b/packages/kit/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@sveltejs/kit",
-	"version": "1.0.0-next.550",
+	"version": "1.0.0-next.551",
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/sveltejs/kit",
diff --git a/packages/kit/src/exports/vite/build/build_server.js b/packages/kit/src/exports/vite/build/build_server.js
index 0af93efd8..36c655f88 100644
--- a/packages/kit/src/exports/vite/build/build_server.js
+++ b/packages/kit/src/exports/vite/build/build_server.js
@@ -27,7 +27,7 @@ const server_template = ({ config, hooks, has_service_worker, runtime, template,
 import root from '__GENERATED__/root.svelte';
 import { respond } from '${runtime}/server/index.js';
 import { set_paths, assets, base } from '${runtime}/paths.js';
-import { set_prerendering } from '${runtime}/env.js';
+import { set_prerendering, set_version } from '${runtime}/env.js';
 import { set_private_env } from '${runtime}/env-private.js';
 import { set_public_env } from '${runtime}/env-public.js';
 
@@ -44,6 +44,7 @@ const error_template = ({ status, message }) => ${s(error_page)
 let read = null;
 
 set_paths(${s(config.kit.paths)});
+set_version(${s(config.kit.version.name)});
 
 let default_protocol = 'https';
 
@@ -86,7 +87,8 @@ export class Server {
 			app_template,
 			app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
 			error_template,
-			trailing_slash: ${s(config.kit.trailingSlash)}
+			trailing_slash: ${s(config.kit.trailingSlash)},
+			version: ${s(config.kit.version.name)}
 		};
 	}
 
diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js
index 6944f30dd..ae5591062 100644
--- a/packages/kit/src/exports/vite/dev/index.js
+++ b/packages/kit/src/exports/vite/dev/index.js
@@ -236,7 +236,10 @@ export async function dev(vite, vite_config, svelte_config) {
 		dev: true,
 		etag: true,
 		maxAge: 0,
-		extensions: []
+		extensions: [],
+		setHeaders: (res) => {
+			res.setHeader('access-control-allow-origin', '*');
+		}
 	});
 
 	vite.middlewares.use(async (req, res, next) => {
@@ -268,6 +271,11 @@ export async function dev(vite, vite_config, svelte_config) {
 		}
 	});
 
+	// set `import { version } from '$app/environment'`
+	(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
+		svelte_config.kit.version.name
+	);
+
 	return () => {
 		const serve_static_middleware = vite.middlewares.stack.find(
 			(middleware) =>
@@ -472,7 +480,8 @@ export async function dev(vite, vite_config, svelte_config) {
 						service_worker:
 							svelte_config.kit.serviceWorker.register &&
 							!!resolve_entry(svelte_config.kit.files.serviceWorker),
-						trailing_slash: svelte_config.kit.trailingSlash
+						trailing_slash: svelte_config.kit.trailingSlash,
+						version: svelte_config.kit.version.name
 					},
 					{
 						getClientAddress: () => {
diff --git a/packages/kit/src/runtime/app/environment.js b/packages/kit/src/runtime/app/environment.js
index f7b96f8c1..56853b8cd 100644
--- a/packages/kit/src/runtime/app/environment.js
+++ b/packages/kit/src/runtime/app/environment.js
@@ -8,4 +8,4 @@ export const browser = !import.meta.env.SSR;
  */
 export const dev = __SVELTEKIT_DEV__;
 
-export { prerendering } from '../env.js';
+export { prerendering, version } from '../env.js';
diff --git a/packages/kit/src/runtime/client/start.js b/packages/kit/src/runtime/client/start.js
index 03b49829c..00b0fd9a9 100644
--- a/packages/kit/src/runtime/client/start.js
+++ b/packages/kit/src/runtime/client/start.js
@@ -2,6 +2,7 @@ import { create_client } from './client.js';
 import { init } from './singletons.js';
 import { set_paths } from '../paths.js';
 import { set_public_env } from '../env-public.js';
+import { set_version } from '../env.js';
 
 /**
  * @param {{
@@ -13,11 +14,13 @@ import { set_public_env } from '../env-public.js';
  *   },
  *   target: Element;
  *   trailing_slash: import('types').TrailingSlash;
+ *   version: string;
  * }} opts
  */
-export async function start({ env, hydrate, paths, target, trailing_slash }) {
+export async function start({ env, hydrate, paths, target, trailing_slash, version }) {
 	set_public_env(env);
 	set_paths(paths);
+	set_version(version);
 
 	if (__SVELTEKIT_DEV__ && target === document.body) {
 		console.warn(
diff --git a/packages/kit/src/runtime/env.js b/packages/kit/src/runtime/env.js
index cf8181252..73c9bb927 100644
--- a/packages/kit/src/runtime/env.js
+++ b/packages/kit/src/runtime/env.js
@@ -1,6 +1,12 @@
 export let prerendering = false;
+export let version = '';
 
 /** @param {boolean} value */
 export function set_prerendering(value) {
 	prerendering = value;
 }
+
+/** @param {string} value */
+export function set_version(value) {
+	version = value;
+}
diff --git a/packages/kit/src/runtime/server/page/render.js b/packages/kit/src/runtime/server/page/render.js
index cd0e6a329..bcde19fde 100644
--- a/packages/kit/src/runtime/server/page/render.js
+++ b/packages/kit/src/runtime/server/page/render.js
@@ -281,7 +281,8 @@ export async function render_response({
 				}` : 'null'},
 				paths: ${s(options.paths)},
 				target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
-				trailing_slash: ${s(options.trailing_slash)}
+				trailing_slash: ${s(options.trailing_slash)},
+				version: ${s(options.version)}
 			});
 		`;
 
diff --git a/packages/kit/types/ambient.d.ts b/packages/kit/types/ambient.d.ts
index d10b0e329..3e11f5d17 100644
--- a/packages/kit/types/ambient.d.ts
+++ b/packages/kit/types/ambient.d.ts
@@ -85,6 +85,11 @@ declare module '$app/environment' {
 	 * `true` when prerendering, `false` otherwise.
 	 */
 	export const prerendering: boolean;
+
+	/**
+	 * The value of `config.kit.version.name`
+	 */
+	export const version: string;
 }
 
 /**
diff --git a/packages/kit/types/internal.d.ts b/packages/kit/types/internal.d.ts
index 1edb814bd..aa8dea77b 100644
--- a/packages/kit/types/internal.d.ts
+++ b/packages/kit/types/internal.d.ts
@@ -313,6 +313,7 @@ export interface SSROptions {
 	app_template_contains_nonce: boolean;
 	error_template({ message, status }: { message: string; status: number }): string;
 	trailing_slash: TrailingSlash;
+	version: string;
 }
 
 export interface SSRErrorPage {
diff --git a/packages/package/CHANGELOG.md b/packages/package/CHANGELOG.md
index 2d6c7cb57..568e1b5e7 100644
--- a/packages/package/CHANGELOG.md
+++ b/packages/package/CHANGELOG.md
@@ -1,5 +1,11 @@
 # @sveltejs/package
 
+## 1.0.0-next.6
+
+### Patch Changes
+
+- [feat] warn if svelte not found in dependencies or peerDependencies ([#7685](https://github.com/sveltejs/kit/pull/7685))
+
 ## 1.0.0-next.5
 
 ### Patch Changes
diff --git a/packages/package/package.json b/packages/package/package.json
index 5d7907e35..e5e3005d9 100644
--- a/packages/package/package.json
+++ b/packages/package/package.json
@@ -1,6 +1,6 @@
 {
 	"name": "@sveltejs/package",
-	"version": "1.0.0-next.5",
+	"version": "1.0.0-next.6",
 	"repository": {
 		"type": "git",
 		"url": "https://github.com/sveltejs/kit",


Test patch:
diff --git a/packages/kit/test/apps/basics/src/routes/app-environment/+page.svelte b/packages/kit/test/apps/basics/src/routes/app-environment/+page.svelte
new file mode 100644
index 000000000..317b7a8ce
--- /dev/null
+++ b/packages/kit/test/apps/basics/src/routes/app-environment/+page.svelte
@@ -0,0 +1,5 @@
+<script>
+	import { version } from '$app/environment';
+</script>
+
+<h1>{version}</h1>
diff --git a/packages/kit/test/apps/basics/svelte.config.js b/packages/kit/test/apps/basics/svelte.config.js
index 67d403fb0..fa9ea301b 100644
--- a/packages/kit/test/apps/basics/svelte.config.js
+++ b/packages/kit/test/apps/basics/svelte.config.js
@@ -3,6 +3,10 @@ const config = {
 	kit: {
 		prerender: {
 			handleHttpError: 'warn'
+		},
+
+		version: {
+			name: 'TEST_VERSION'
 		}
 	}
 };
diff --git a/packages/kit/test/apps/basics/test/server.test.js b/packages/kit/test/apps/basics/test/server.test.js
index 2f56b508a..97f6bceff 100644
--- a/packages/kit/test/apps/basics/test/server.test.js
+++ b/packages/kit/test/apps/basics/test/server.test.js
@@ -372,6 +372,8 @@ test.describe('Static files', () => {
 		response = await request.get('/subdirectory/static.json');
 		expect(await response.json()).toBe('subdirectory file');
 
+		expect(response.headers()['access-control-allow-origin']).toBe('*');
+
 		response = await request.get('/favicon.ico');
 		expect(response.status()).toBe(200);
 	});
diff --git a/packages/kit/test/apps/basics/test/test.js b/packages/kit/test/apps/basics/test/test.js
index 46a003d51..2ee921709 100644
--- a/packages/kit/test/apps/basics/test/test.js
+++ b/packages/kit/test/apps/basics/test/test.js
@@ -1051,6 +1051,13 @@ test.describe('Page options', () => {
 	});
 });
 
+test.describe('$app/environment', () => {
+	test('includes version', async ({ page }) => {
+		await page.goto('/app-environment');
+		expect(await page.textContent('h1')).toBe('TEST_VERSION');
+	});
+});
+
 test.describe('$app/paths', () => {
 	test('includes paths', async ({ page }) => {
 		await page.goto('/paths');