Skip to content

Commit

Permalink
feat: export VERSION from @sveltejs/kit (#9969)
Browse files Browse the repository at this point in the history
Closes #9937

---------

Co-authored-by: Rich Harris <hello@rich-harris.dev>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Rich Harris <git@rich-harris.dev>
Co-authored-by: Ivan Hofer <ivan.hofer@outlok.com>
  • Loading branch information
5 people committed Jun 28, 2023
1 parent ade7283 commit 316a4af
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/unlucky-eagles-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

feat: export `VERSION` from `@sveltejs/kit`
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: pnpm changeset:version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions packages/kit/scripts/generate-version.js
Original file line number Diff line number Diff line change
@@ -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`
);
2 changes: 2 additions & 0 deletions packages/kit/src/exports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/kit/src/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// generated during release, do not modify

/** @type {string} */
export const VERSION = '1.20.4';
19 changes: 19 additions & 0 deletions packages/kit/src/version.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { fileURLToPath } from 'node:url';
import { readFileSync } from 'node:fs';
import { assert, describe, it } from 'vitest';

// runs the version generation as a side-effect of importing
import '../scripts/generate-version.js';

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')
);
assert.equal(
VERSION,
pkg.version,
'VERSION export in src/version.js does not equal version in package.json'
);
});

0 comments on commit 316a4af

Please sign in to comment.