Skip to content

Commit 316a4af

Browse files
ivanhoferRich-HarrisbenmccannRich HarrisIvan Hofer
authored
feat: export VERSION from @sveltejs/kit (#9969)
Closes #9937 --------- Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Ben McCann <[email protected]> Co-authored-by: Rich Harris <[email protected]> Co-authored-by: Ivan Hofer <[email protected]>
1 parent ade7283 commit 316a4af

File tree

8 files changed

+42
-1
lines changed

8 files changed

+42
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
feat: export `VERSION` from `@sveltejs/kit`

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
with:
3737
# This expects you to have a script called release which does a build for your packages and calls changeset publish
3838
publish: pnpm release
39+
version: pnpm changeset:version
3940
env:
4041
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4142
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"lint": "pnpm -r lint && eslint --cache --cache-location node_modules/.eslintcache 'packages/**/*.js'",
1515
"format": "pnpm -r format",
1616
"precommit": "pnpm format && pnpm lint",
17+
"changeset:version": "pnpm -r generate:version && git add --all",
1718
"release": "changeset publish",
1819
"start": "cd sites/kit.svelte.dev && npm run dev"
1920
},

packages/kit/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
"test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
6969
"test:unit": "vitest --config kit.vitest.config.js run",
7070
"postinstall": "node postinstall.js",
71-
"prepublishOnly": "node scripts/generate-dts.js"
71+
"prepublishOnly": "node scripts/generate-dts.js",
72+
"generate:version": "node scripts/generate-version.js"
7273
},
7374
"exports": {
7475
"./package.json": "./package.json",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import fs from 'node:fs';
2+
3+
const pkg = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
4+
5+
fs.writeFileSync(
6+
'./src/version.js',
7+
`// generated during release, do not modify\n\n/** @type {string} */\nexport const VERSION = '${pkg.version}';\n`
8+
);

packages/kit/src/exports/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { HttpError, Redirect, ActionFailure } from '../runtime/control.js';
22
import { BROWSER, DEV } from 'esm-env';
33
import { get_route_segments } from '../utils/routing.js';
44

5+
export { VERSION } from '../version.js';
6+
57
/**
68
* @overload
79
* @param {number} status

packages/kit/src/version.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// generated during release, do not modify
2+
3+
/** @type {string} */
4+
export const VERSION = '1.20.4';

packages/kit/src/version.spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { fileURLToPath } from 'node:url';
2+
import { readFileSync } from 'node:fs';
3+
import { assert, describe, it } from 'vitest';
4+
5+
// runs the version generation as a side-effect of importing
6+
import '../scripts/generate-version.js';
7+
8+
describe('@sveltejs/kit VERSION', async () => {
9+
it('should be the exact version from package.json');
10+
const { VERSION } = await import('./version.js');
11+
const pkg = JSON.parse(
12+
readFileSync(fileURLToPath(new URL('../package.json', import.meta.url)), 'utf-8')
13+
);
14+
assert.equal(
15+
VERSION,
16+
pkg.version,
17+
'VERSION export in src/version.js does not equal version in package.json'
18+
);
19+
});

0 commit comments

Comments
 (0)