Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export VERSION from @sveltejs/kit #9969

Merged
merged 12 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -9,6 +9,8 @@ import { get_route_segments } from '../utils/routing.js';
* @return {HttpError}
*/

export { VERSION } from '../version.js';

/**
* @overload
* @param {number} status
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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.
*/
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';
import { VERSION } from './version.js';

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure where to put this..
There is no build step involved in this repo.
I guess this is needed when running the tests and for publishing pnpm changeset:version should be called. Are there also other places where it is needed to update the version info?


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'
);
});