Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Fix `spree --version` reporting stale hardcoded version (#14253)

Damian Legawiecb22f398f6b82
diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md
index 5ecbbf7747..af414db6f8 100644
--- a/packages/cli/CHANGELOG.md
+++ b/packages/cli/CHANGELOG.md
@@ -1,5 +1,11 @@
# @spree/cli
+## 2.3.6
+
+### Patch Changes
+
+- Fix `spree --version` reporting a stale hardcoded `2.0.0` instead of the installed CLI version. The version is now read from the package's `package.json` at runtime, so `spree -V` and `npx spree -V` always match the release you have installed.
+
## 2.3.5
### Patch Changes
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 0108e0e71b..8071b0c620 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@spree/cli",
- "version": "2.3.5",
+ "version": "2.3.6",
"description": "CLI for managing Spree Commerce projects",
"type": "module",
"bin": {
diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts
index 21c91638b2..c5564310b6 100644
--- a/packages/cli/src/index.ts
+++ b/packages/cli/src/index.ts
@@ -27,11 +27,12 @@ import { registerTaskCommand } from './commands/task.js'
import { registerUpdateCommand } from './commands/update.js'
import { registerUpgradeCommand } from './commands/upgrade.js'
import { registerUserCommand } from './commands/user.js'
+import { VERSION } from './version.js'
const program = new Command()
.name('spree')
.description('CLI for managing Spree Commerce projects')
- .version('2.0.0')
+ .version(VERSION)
// Required by passThroughOptions on subcommands (exec/rails/bundle/rake/task)
// so flags like `ls -la` or `bin/rails routes -g foo` reach the inner command
// instead of being parsed as options of the spree subcommand.
diff --git a/packages/cli/src/version.ts b/packages/cli/src/version.ts
new file mode 100644
index 0000000000..4f840e3f6f
--- /dev/null
+++ b/packages/cli/src/version.ts
@@ -0,0 +1,10 @@
+import { createRequire } from 'node:module'
+
+// Resolve the CLI version from the package's own package.json at runtime rather
+// than hardcoding it, so `spree --version` always reports the installed release.
+// `../package.json` resolves the same whether this runs as the bundled
+// `dist/index.js` or as `src/` source (tests), and npm always ships
+// package.json in the published tarball.
+const requirePackage = createRequire(import.meta.url)
+
+export const VERSION: string = (requirePackage('../package.json') as { version: string }).version