From 427083ba19debf6a1b947390a44f9da42c01aeba Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Thu, 18 May 2023 12:05:19 +0200 Subject: [PATCH 01/12] export `VERSION` from `@sveltejs/kit` --- packages/kit/scripts/update_version.js | 7 +++++++ packages/kit/src/exports/index.js | 2 ++ packages/kit/src/exports/public.d.ts | 2 ++ packages/kit/src/version.js | 2 ++ 4 files changed, 13 insertions(+) create mode 100644 packages/kit/scripts/update_version.js create mode 100644 packages/kit/src/version.js diff --git a/packages/kit/scripts/update_version.js b/packages/kit/scripts/update_version.js new file mode 100644 index 000000000000..9ac145d11b5a --- /dev/null +++ b/packages/kit/scripts/update_version.js @@ -0,0 +1,7 @@ +import { readFile, writeFile } from 'node:fs/promises' + +const pkg = JSON.parse(await readFile("./package.json", { encoding: "utf-8" })); + +await writeFile('./src/version.js', `// This file get's auto-updated on each release. Please don't edit it manually. +export const VERSION = '${pkg.version}'; +`) diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index b1d50790c444..35cfd2001f92 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -9,6 +9,8 @@ import { get_route_segments } from '../utils/routing.js'; * @return {HttpError} */ +export { VERSION } from '../version.js'; + /** * @overload * @param {number} status diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 35c9235b0c94..484024aa44e5 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -24,6 +24,8 @@ import type { PluginOptions } from '@sveltejs/vite-plugin-svelte'; export { PrerenderOption } from '../types/private.js'; export { ActionFailure }; +export const VERSION: `${number}.${number}.${number}` + /** * [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing. */ diff --git a/packages/kit/src/version.js b/packages/kit/src/version.js new file mode 100644 index 000000000000..efeb382d9b8c --- /dev/null +++ b/packages/kit/src/version.js @@ -0,0 +1,2 @@ +// This file get's auto-updated on each release. Please don't edit it manually. +export const VERSION = '1.18.0'; From 0a5ea8f275469639f0c53b64fd2e2cd27ec92de8 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Thu, 18 May 2023 12:05:49 +0200 Subject: [PATCH 02/12] add changeset --- .changeset/unlucky-eagles-destroy.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/unlucky-eagles-destroy.md diff --git a/.changeset/unlucky-eagles-destroy.md b/.changeset/unlucky-eagles-destroy.md new file mode 100644 index 000000000000..3270346b97f7 --- /dev/null +++ b/.changeset/unlucky-eagles-destroy.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +export `VERSION` from `@sveltejs/kit` From a4155c865d6408e4a2f2e9f51458e42b73a2ec01 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Thu, 18 May 2023 12:13:09 +0200 Subject: [PATCH 03/12] auto update version in CI --- .github/workflows/release.yml | 1 + packages/kit/scripts/update_version.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c6e40316e959..0142e55b09e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,6 +36,7 @@ jobs: with: # This expects you to have a script called release which does a build for your packages and calls changeset publish publish: pnpm release + version: changeset version && node ./packages/kit/scripts/update_version.js env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/packages/kit/scripts/update_version.js b/packages/kit/scripts/update_version.js index 9ac145d11b5a..d07f6232ad3b 100644 --- a/packages/kit/scripts/update_version.js +++ b/packages/kit/scripts/update_version.js @@ -1,7 +1,15 @@ -import { readFile, writeFile } from 'node:fs/promises' +import { readFile, writeFile } from 'node:fs/promises'; +import { resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; -const pkg = JSON.parse(await readFile("./package.json", { encoding: "utf-8" })); +const __dirname = fileURLToPath(new URL('.', import.meta.url)); +const pathToPackageJson = resolve(__dirname, '..', 'package.json') +const pathToVersionModule = resolve(__dirname, '..', 'src', 'version.js') -await writeFile('./src/version.js', `// This file get's auto-updated on each release. Please don't edit it manually. +const pkg = JSON.parse(await readFile(pathToPackageJson, { encoding: 'utf-8' })); + +await writeFile( + pathToVersionModule, + `// This file get's auto-updated on each release. Please don't edit it manually. export const VERSION = '${pkg.version}'; `) From 2e1057bdc8caa4976d115f2f3c9b3f75c35a18d3 Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Thu, 18 May 2023 12:23:46 +0200 Subject: [PATCH 04/12] format files --- packages/kit/scripts/update_version.js | 7 ++++--- packages/kit/src/exports/public.d.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/kit/scripts/update_version.js b/packages/kit/scripts/update_version.js index d07f6232ad3b..35b5ecdff255 100644 --- a/packages/kit/scripts/update_version.js +++ b/packages/kit/scripts/update_version.js @@ -3,8 +3,8 @@ import { resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const pathToPackageJson = resolve(__dirname, '..', 'package.json') -const pathToVersionModule = resolve(__dirname, '..', 'src', 'version.js') +const pathToPackageJson = resolve(__dirname, '..', 'package.json'); +const pathToVersionModule = resolve(__dirname, '..', 'src', 'version.js'); const pkg = JSON.parse(await readFile(pathToPackageJson, { encoding: 'utf-8' })); @@ -12,4 +12,5 @@ await writeFile( pathToVersionModule, `// This file get's auto-updated on each release. Please don't edit it manually. export const VERSION = '${pkg.version}'; -`) +` +); diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 484024aa44e5..17f4f7d443fc 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -24,7 +24,7 @@ import type { PluginOptions } from '@sveltejs/vite-plugin-svelte'; export { PrerenderOption } from '../types/private.js'; export { ActionFailure }; -export const VERSION: `${number}.${number}.${number}` +export const VERSION: `${number}.${number}.${number}`; /** * [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing. From cc10009be4f41c390f1627d658d18d94f74b2c62 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 May 2023 10:18:28 -0400 Subject: [PATCH 05/12] Update packages/kit/src/version.js Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- packages/kit/src/version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/src/version.js b/packages/kit/src/version.js index efeb382d9b8c..aecc799560f8 100644 --- a/packages/kit/src/version.js +++ b/packages/kit/src/version.js @@ -1,2 +1,2 @@ -// This file get's auto-updated on each release. Please don't edit it manually. +// This file is auto-updated on each release. Please don't edit it manually. export const VERSION = '1.18.0'; From 6650624f8e8876f5e21a31cf8241cc8f92f1639b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 May 2023 10:19:39 -0400 Subject: [PATCH 06/12] Update .changeset/unlucky-eagles-destroy.md Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- .changeset/unlucky-eagles-destroy.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/unlucky-eagles-destroy.md b/.changeset/unlucky-eagles-destroy.md index 3270346b97f7..74c96a7fe2d9 100644 --- a/.changeset/unlucky-eagles-destroy.md +++ b/.changeset/unlucky-eagles-destroy.md @@ -2,4 +2,4 @@ '@sveltejs/kit': patch --- -export `VERSION` from `@sveltejs/kit` +feat: export `VERSION` from `@sveltejs/kit` From c9007834df708d0e968b7c8fe7465a63516e8185 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 May 2023 10:24:01 -0400 Subject: [PATCH 07/12] simplify script --- packages/kit/scripts/update_version.js | 13 +++++-------- packages/kit/src/version.js | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/kit/scripts/update_version.js b/packages/kit/scripts/update_version.js index 35b5ecdff255..083018e2fd2f 100644 --- a/packages/kit/scripts/update_version.js +++ b/packages/kit/scripts/update_version.js @@ -1,15 +1,12 @@ -import { readFile, writeFile } from 'node:fs/promises'; -import { resolve } from 'node:path'; +import fs from 'node:fs'; import { fileURLToPath } from 'node:url'; -const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const pathToPackageJson = resolve(__dirname, '..', 'package.json'); -const pathToVersionModule = resolve(__dirname, '..', 'src', 'version.js'); +process.chdir(fileURLToPath(new URL('..', import.meta.url))); -const pkg = JSON.parse(await readFile(pathToPackageJson, { encoding: 'utf-8' })); +const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); -await writeFile( - pathToVersionModule, +fs.writeFileSync( + 'src/version.js', `// This file get's auto-updated on each release. Please don't edit it manually. export const VERSION = '${pkg.version}'; ` diff --git a/packages/kit/src/version.js b/packages/kit/src/version.js index aecc799560f8..efeb382d9b8c 100644 --- a/packages/kit/src/version.js +++ b/packages/kit/src/version.js @@ -1,2 +1,2 @@ -// This file is auto-updated on each release. Please don't edit it manually. +// This file get's auto-updated on each release. Please don't edit it manually. export const VERSION = '1.18.0'; From d6df640ee1794fd647a3ffa5d3f2d5cdcb92fcaa Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 May 2023 10:24:22 -0400 Subject: [PATCH 08/12] oops --- packages/kit/scripts/update_version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/scripts/update_version.js b/packages/kit/scripts/update_version.js index 083018e2fd2f..28696f6d192a 100644 --- a/packages/kit/scripts/update_version.js +++ b/packages/kit/scripts/update_version.js @@ -7,7 +7,7 @@ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); fs.writeFileSync( 'src/version.js', - `// This file get's auto-updated on each release. Please don't edit it manually. + `// This file is auto-updated on each release. Please don't edit it manually. export const VERSION = '${pkg.version}'; ` ); From f0e3dc3b37a1c932ad9d5a25d9f153d788d14599 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 May 2023 10:25:04 -0400 Subject: [PATCH 09/12] oops --- packages/kit/src/version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/src/version.js b/packages/kit/src/version.js index efeb382d9b8c..aecc799560f8 100644 --- a/packages/kit/src/version.js +++ b/packages/kit/src/version.js @@ -1,2 +1,2 @@ -// This file get's auto-updated on each release. Please don't edit it manually. +// This file is auto-updated on each release. Please don't edit it manually. export const VERSION = '1.18.0'; From 57f13de44c22c133b13bf937c4937d47a2c1c4de Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Tue, 20 Jun 2023 12:16:16 +0200 Subject: [PATCH 10/12] adapt to svelte setup --- .github/workflows/release.yml | 2 +- package.json | 1 + packages/kit/package.json | 3 ++- packages/kit/scripts/generate-version.js | 8 ++++++++ packages/kit/scripts/update_version.js | 13 ------------- packages/kit/src/exports/public.d.ts | 2 +- packages/kit/src/version.js | 6 ++++-- packages/kit/src/version.spec.js | 19 +++++++++++++++++++ 8 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 packages/kit/scripts/generate-version.js delete mode 100644 packages/kit/scripts/update_version.js create mode 100644 packages/kit/src/version.spec.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0142e55b09e8..4f8c925e23e3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,7 +36,7 @@ jobs: with: # This expects you to have a script called release which does a build for your packages and calls changeset publish publish: pnpm release - version: changeset version && node ./packages/kit/scripts/update_version.js + version: pnpm changeset:version env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/package.json b/package.json index e3c25ea371cb..b229ef5b6411 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "lint": "pnpm -r lint && eslint --cache --cache-location node_modules/.eslintcache 'packages/**/*.js'", "format": "pnpm -r format", "precommit": "pnpm format && pnpm lint", + "changeset:version": "pnpm -r generate:version && git add --all", "release": "changeset publish", "start": "cd sites/kit.svelte.dev && npm run dev" }, diff --git a/packages/kit/package.json b/packages/kit/package.json index 0dd25bbe40c7..5300b94cbc12 100644 --- a/packages/kit/package.json +++ b/packages/kit/package.json @@ -68,7 +68,8 @@ "test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build", "test:unit": "vitest --config kit.vitest.config.js run", "postinstall": "node postinstall.js", - "prepublishOnly": "node scripts/generate-dts.js" + "prepublishOnly": "node scripts/generate-dts.js", + "generate:version": "node scripts/generate-version.js" }, "exports": { "./package.json": "./package.json", diff --git a/packages/kit/scripts/generate-version.js b/packages/kit/scripts/generate-version.js new file mode 100644 index 000000000000..ecf715c9a15c --- /dev/null +++ b/packages/kit/scripts/generate-version.js @@ -0,0 +1,8 @@ +import fs from 'node:fs'; + +const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); + +fs.writeFileSync( + './src/version.js', + `// generated during release, do not modify\n\n/** @type {string} */\nexport const VERSION = '${pkg.version}';\n` +); diff --git a/packages/kit/scripts/update_version.js b/packages/kit/scripts/update_version.js deleted file mode 100644 index 28696f6d192a..000000000000 --- a/packages/kit/scripts/update_version.js +++ /dev/null @@ -1,13 +0,0 @@ -import fs from 'node:fs'; -import { fileURLToPath } from 'node:url'; - -process.chdir(fileURLToPath(new URL('..', import.meta.url))); - -const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8')); - -fs.writeFileSync( - 'src/version.js', - `// This file is auto-updated on each release. Please don't edit it manually. -export const VERSION = '${pkg.version}'; -` -); diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index 17f4f7d443fc..a498c4041000 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -24,7 +24,7 @@ import type { PluginOptions } from '@sveltejs/vite-plugin-svelte'; export { PrerenderOption } from '../types/private.js'; export { ActionFailure }; -export const VERSION: `${number}.${number}.${number}`; +export const VERSION: string; /** * [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing. diff --git a/packages/kit/src/version.js b/packages/kit/src/version.js index aecc799560f8..2b0e210e9821 100644 --- a/packages/kit/src/version.js +++ b/packages/kit/src/version.js @@ -1,2 +1,4 @@ -// This file is auto-updated on each release. Please don't edit it manually. -export const VERSION = '1.18.0'; +// generated during release, do not modify + +/** @type {string} */ +export const VERSION = '1.20.4'; diff --git a/packages/kit/src/version.spec.js b/packages/kit/src/version.spec.js new file mode 100644 index 000000000000..16cec44926ab --- /dev/null +++ b/packages/kit/src/version.spec.js @@ -0,0 +1,19 @@ +import { fileURLToPath } from 'node:url'; +import { readFileSync } from 'node:fs'; +import { assert, describe, it } from 'vitest'; +import { VERSION } from './version.js'; + +// runs the version generation as a side-effect of importing +import '../scripts/generate-version.js'; + +describe('@sveltejs/kit VERSION', () => { + it('should be the exact version from package.json'); + const pkg = JSON.parse( + readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8') + ); + assert.equal( + VERSION, + pkg.version, + 'VERSION export in src/version.js does not equal version in package.json' + ); +}); From cc0f567751230c4085fd1cf3fe70330e6191bbae Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Tue, 20 Jun 2023 12:20:20 +0200 Subject: [PATCH 11/12] import version after updating it --- packages/kit/src/version.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/version.spec.js b/packages/kit/src/version.spec.js index 16cec44926ab..fa44692da9ff 100644 --- a/packages/kit/src/version.spec.js +++ b/packages/kit/src/version.spec.js @@ -1,13 +1,13 @@ import { fileURLToPath } from 'node:url'; import { readFileSync } from 'node:fs'; import { assert, describe, it } from 'vitest'; -import { VERSION } from './version.js'; // runs the version generation as a side-effect of importing import '../scripts/generate-version.js'; -describe('@sveltejs/kit VERSION', () => { +describe('@sveltejs/kit VERSION', async () => { it('should be the exact version from package.json'); + const { VERSION } = await import('./version.js'); const pkg = JSON.parse( readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8') ); From 91fcda9575eb343834f9e4a3e41742fcf802323b Mon Sep 17 00:00:00 2001 From: Ivan Hofer Date: Tue, 20 Jun 2023 12:27:11 +0200 Subject: [PATCH 12/12] fix export --- packages/kit/src/exports/index.js | 4 ++-- packages/kit/src/exports/public.d.ts | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index 35cfd2001f92..63bc183feb33 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -2,6 +2,8 @@ import { HttpError, Redirect, ActionFailure } from '../runtime/control.js'; import { BROWSER, DEV } from 'esm-env'; import { get_route_segments } from '../utils/routing.js'; +export { VERSION } from '../version.js'; + /** * @overload * @param {number} status @@ -9,8 +11,6 @@ import { get_route_segments } from '../utils/routing.js'; * @return {HttpError} */ -export { VERSION } from '../version.js'; - /** * @overload * @param {number} status diff --git a/packages/kit/src/exports/public.d.ts b/packages/kit/src/exports/public.d.ts index a498c4041000..35c9235b0c94 100644 --- a/packages/kit/src/exports/public.d.ts +++ b/packages/kit/src/exports/public.d.ts @@ -24,8 +24,6 @@ import type { PluginOptions } from '@sveltejs/vite-plugin-svelte'; export { PrerenderOption } from '../types/private.js'; export { ActionFailure }; -export const VERSION: string; - /** * [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing. */