Skip to content

Commit

Permalink
fix(starter): Avoid using npx in scripts (#1200)
Browse files Browse the repository at this point in the history
Removes `npx` from the example scripts as npx [will fetch a remote
package](https://docs.npmjs.com/cli/v8/commands/npx) by default if a
local one is not found.

There was an issue raised by someone who was running `npx pg-migrations
blah blah` without the appropriate @databases/pg-migrations package
installed which led to `npx` downloading the wrong `pg-migrations`
package leading to confusing red herring errors.

This way it ensures that scripts require the dependencies to be
installed to run, and that they run with the specified versions.
  • Loading branch information
msfstef committed Apr 25, 2024
1 parent dd5bd65 commit 784f737
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 315 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-rocks-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-electric-app": patch
---

Remove usage of `npx` in template scripts to ensure correct package is used.
2 changes: 1 addition & 1 deletion examples/checkout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"backend:down": "cd ./backend && docker compose -f docker-compose.yml -f ./dev/docker-compose.dev.yml down -v --remove-orphans",
"client:generate": "electric-sql generate --service http://localhost:5133 --proxy postgresql://prisma:proxy_password@localhost:65432/postgres",
"client:watch": "npm run client:generate --watch",
"db:migrate": "electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:migrate": "electric-sql with-config \"pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:load-data": "node ./db/load-data.js",
"dev": "vite",
"build": "tsc && vite build",
Expand Down
18 changes: 9 additions & 9 deletions examples/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"license": "Apache-2.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"backend:start": "npx electric-sql start --with-postgres",
"backend:stop": "npx electric-sql stop",
"backend:up": "npx electric-sql start --with-postgres --detach",
"backend:down": "npx electric-sql stop --remove",
"client:generate": "npx electric-sql generate",
"client:watch": "npx electric-sql generate --watch",
"db:migrate": "npx electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "npx electric-sql psql",
"electric:start": "npx electric-sql start",
"backend:start": "electric-sql start --with-postgres",
"backend:stop": "electric-sql stop",
"backend:up": "electric-sql start --with-postgres --detach",
"backend:down": "electric-sql stop --remove",
"client:generate": "electric-sql generate",
"client:watch": "electric-sql generate --watch",
"db:migrate": "electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "electric-sql psql",
"electric:start": "electric-sql start",
"start": "expo start",
"start:android": "expo start --android",
"start:ios": "expo start --ios"
Expand Down
20 changes: 10 additions & 10 deletions examples/ionic-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"version": "0.9.4",
"type": "module",
"scripts": {
"backend:start": "npx electric-sql start --with-postgres",
"backend:stop": "npx electric-sql stop",
"backend:up": "npx electric-sql start --with-postgres --detach",
"backend:down": "npx electric-sql stop --remove",
"client:generate": "npx electric-sql generate",
"client:watch": "npx electric-sql generate --watch",
"db:migrate": "npx electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "npx electric-sql psql",
"electric:start": "npx electric-sql start",
"backend:start": "electric-sql start --with-postgres",
"backend:stop": "electric-sql stop",
"backend:up": "electric-sql start --with-postgres --detach",
"backend:down": "electric-sql stop --remove",
"client:generate": "electric-sql generate",
"client:watch": "electric-sql generate --watch",
"db:migrate": "electric-sql with-config \"pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "electric-sql psql",
"electric:start": "electric-sql start",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
Expand All @@ -21,7 +21,7 @@
"lint": "eslint",
"typecheck": "tsc --noEmit --skipLibCheck",
"format": "prettier --write --loglevel warn .",
"make-icons": "npx @capacitor/assets generate"
"make-icons": "@capacitor/assets generate"
},
"dependencies": {
"@capacitor-community/sqlite": "^5.6.2",
Expand Down
18 changes: 9 additions & 9 deletions examples/linearlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
"license": "Apache-2.0",
"type": "module",
"scripts": {
"backend:start": "npx electric-sql start --with-postgres",
"backend:stop": "npx electric-sql stop",
"backend:up": "npx electric-sql start --with-postgres --detach",
"backend:down": "npx electric-sql stop --remove",
"client:generate": "npx electric-sql generate",
"client:watch": "npx electric-sql generate --watch",
"db:migrate": "npx electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "npx electric-sql psql",
"backend:start": "electric-sql start --with-postgres",
"backend:stop": "electric-sql stop",
"backend:up": "electric-sql start --with-postgres --detach",
"backend:down": "electric-sql stop --remove",
"client:generate": "electric-sql generate",
"client:watch": "electric-sql generate --watch",
"db:migrate": "electric-sql with-config \"pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "electric-sql psql",
"db:load-data": "node ./db/load_data.js",
"db:process-data": "node ./db/process_data.js",
"db:truncate": "node ./db/truncate.js",
"db:reload-data": "npm run db:truncate && npm run db:load-data",
"electric:start": "npx electric-sql start",
"electric:start": "electric-sql start",
"reset": "npm run backend:down && npm run backend:up && sleep 5 && npm run db:migrate && npm run client:generate && npm run db:load-data",
"dev": "vite",
"start": "npm run dev",
Expand Down
18 changes: 9 additions & 9 deletions examples/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"author": "ElectricSQL",
"license": "Apache-2.0",
"scripts": {
"backend:start": "npx electric-sql start --with-postgres",
"backend:stop": "npx electric-sql stop",
"backend:up": "npx electric-sql start --with-postgres --detach",
"backend:down": "npx electric-sql stop --remove",
"client:generate": "npx electric-sql generate",
"client:watch": "npx electric-sql generate --watch",
"db:migrate": "npx electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "npx electric-sql psql",
"electric:start": "npx electric-sql start",
"backend:start": "electric-sql start --with-postgres",
"backend:stop": "electric-sql stop",
"backend:up": "electric-sql start --with-postgres --detach",
"backend:down": "electric-sql stop --remove",
"client:generate": "electric-sql generate",
"client:watch": "electric-sql generate --watch",
"db:migrate": "electric-sql with-config \"pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "electric-sql psql",
"electric:start": "electric-sql start",
"pods:install": "cd ios && bundle install && bundle exec pod install && cd ..",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"start": "react-native start",
Expand Down
8 changes: 4 additions & 4 deletions examples/recipes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"backend:stop": "npm run backend:compose stop",
"backend:up": "npm run backend:compose up -- --detach",
"backend:down": "npm run backend:compose down -- --volumes",
"client:generate": "npx electric-sql generate",
"client:watch": "npx electric-sql generate --watch",
"db:migrate": "npx electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "npx electric-sql psql",
"client:generate": "electric-sql generate",
"client:watch": "electric-sql generate --watch",
"db:migrate": "electric-sql with-config \"pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "electric-sql psql",
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
Expand Down
18 changes: 9 additions & 9 deletions examples/tauri-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"author": "ElectricSQL",
"type": "module",
"scripts": {
"backend:start": "npx electric-sql start --with-postgres",
"backend:stop": "npx electric-sql stop",
"backend:up": "npx electric-sql start --with-postgres --detach",
"backend:down": "npx electric-sql stop --remove",
"client:generate": "npx electric-sql generate",
"client:watch": "npx electric-sql generate --watch",
"db:migrate": "npx electric-sql with-config \"npx pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "npx electric-sql psql",
"electric:start": "npx electric-sql start",
"backend:start": "electric-sql start --with-postgres",
"backend:stop": "electric-sql stop",
"backend:up": "electric-sql start --with-postgres --detach",
"backend:down": "electric-sql stop --remove",
"client:generate": "electric-sql generate",
"client:watch": "electric-sql generate --watch",
"db:migrate": "electric-sql with-config \"pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"db:psql": "electric-sql psql",
"electric:start": "electric-sql start",
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
Expand Down
Loading

0 comments on commit 784f737

Please sign in to comment.