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.

Changed pnpm install to build the spree CLI and link its command (#15063)

Damian Legawiecf114556b7bfa
diff --git a/.changeset/cli-stable-bin.md b/.changeset/cli-stable-bin.md
new file mode 100644
index 0000000000..c86ce2c875
--- /dev/null
+++ b/.changeset/cli-stable-bin.md
@@ -0,0 +1,5 @@
+---
+"@spree/cli": patch
+---
+
+The `spree` command now starts from `bin/spree.js`, which loads the built `dist/index.js`. Running `spree` works the same as before.
diff --git a/package.json b/package.json
index b9969a77c4..e08969736f 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,7 @@
"private": true,
"scripts": {
"preinstall": "npx only-allow pnpm",
+ "postinstall": "test -n \"$CI\" || turbo build --filter=@spree/cli... --output-logs=errors-only || echo \"Warning: building @spree/cli failed; the spree command will not work until it builds.\"",
"dev": "turbo dev",
"build": "turbo build",
"test": "turbo test",
diff --git a/packages/cli/bin/spree.js b/packages/cli/bin/spree.js
new file mode 100755
index 0000000000..cf505dc113
--- /dev/null
+++ b/packages/cli/bin/spree.js
@@ -0,0 +1,4 @@
+#!/usr/bin/env node
+// A stable bin target that exists before the first build, so `pnpm install`
+// on a fresh clone can link `spree` before its postinstall builds dist/.
+import '../dist/index.js'
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 607be3f303..2494d06b99 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -4,9 +4,10 @@
"description": "CLI for managing Spree Commerce projects",
"type": "module",
"bin": {
- "spree": "./dist/index.js"
+ "spree": "./bin/spree.js"
},
"files": [
+ "bin",
"dist",
"README.md",
"LICENSE"
diff --git a/scripts/server-setup.sh b/scripts/server-setup.sh
index e236f5f218..ee7202660b 100755
--- a/scripts/server-setup.sh
+++ b/scripts/server-setup.sh
@@ -56,15 +56,12 @@ step "Building @spree/cli (so the spree CLI works in server/)"
# doesn't exist yet.
pnpm turbo build --filter=@spree/cli
-# On a clean clone `pnpm install` runs before the CLI is ever built, and pnpm
-# only links a workspace bin whose target file exists — so the `spree` shim
-# is silently skipped, and a later `pnpm install` (even --force) does not
-# recreate it. Link it ourselves now that the build exists; dist/index.js
-# carries a node shebang and is executable, so a plain symlink works.
+# Clones installed before bin/spree.js existed never got the `spree` shim, and
+# pnpm does not recreate it while it considers node_modules up to date.
if [ ! -e "$ROOT/node_modules/.bin/spree" ]; then
step "Linking the missing spree bin shim"
mkdir -p "$ROOT/node_modules/.bin"
- ln -sf ../../packages/cli/dist/index.js "$ROOT/node_modules/.bin/spree"
+ ln -sf ../../packages/cli/bin/spree.js "$ROOT/node_modules/.bin/spree"
fi
step "Starting the edge stack"