Skip to content

Commit

Permalink
chore (cli): extract cli to separate package (#1317)
Browse files Browse the repository at this point in the history
This PR extracts the CLI out of the `electric-sql` package and into its
own `@electric-sql/cli` package.

TODO:
- We may want to add `.js` extension to every import to avoid having to
run the `fix-imports.js` script.
  • Loading branch information
kevin-dp committed Jun 25, 2024
1 parent 5e16611 commit cb19c58
Show file tree
Hide file tree
Showing 73 changed files with 1,428 additions and 2,009 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"fixed": [["@electric-sql/cli", "electric-sql"]],
"linked": [],
"access": "public",
"baseBranch": "main",
Expand Down
6 changes: 6 additions & 0 deletions .changeset/wise-moose-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"electric-sql": patch
"@electric-sql/cli": patch
---

Extract CLI to a separate package.
87 changes: 87 additions & 0 deletions .github/workflows/cli_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CLI / Tests

on:
workflow_call:
push:
branches:
- main
pull_request:
paths:
- 'pnpm-lock.yaml'
- 'components/cli/**'
- '!components/cli/**.md'

defaults:
run:
working-directory: components/cli

concurrency:
group: cli-${{ github.ref }}
cancel-in-progress: true

jobs:
verify_formatting:
name: Check formatting & linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm
- run: make deps
- run: pnpm run check-styleguide
check_types:
name: Check types
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
cache: pnpm
- run: make deps
- run: pnpm run typecheck
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [16, 18, 20]
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install
run: make deps
- name: Build
run: make build
- name: Run tests
run: make tests
maybe_publish:
runs-on: ubuntu-latest
needs: [test, check_types, verify_formatting]
if: ${{ github.ref_name == 'main' }}
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- run: make deps
- run: pnpm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}"
- run: make publish-canary
34 changes: 2 additions & 32 deletions clients/typescript/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,32 +1,2 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
root: true,
rules: {
'@typescript-eslint/no-unused-vars': [
'warn', // or "error"
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-inferrable-types': 'off', // always allow explicit typings
'@typescript-eslint/no-explicit-any': ['warn', { ignoreRestArgs: true }],
'@typescript-eslint/ban-ts-comment': [
'error',
{ 'ts-ignore': 'allow-with-description' },
],
'no-constant-condition': ['error', { checkLoops: false }],
eqeqeq: ['error'],
},
ignorePatterns: [
'**/*/mock.ts',
'**/*/prismaClient.d.ts',
'**/*/_generated/**',
'**/node_modules/**',
'**/dist/**',
],
}
const config = require('../../common/.eslintrc.cjs')
module.exports = config
2 changes: 2 additions & 0 deletions clients/typescript/.prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const config = require('../../common/.prettierrc.cjs')
module.exports = config
10 changes: 0 additions & 10 deletions clients/typescript/.release-it.json

This file was deleted.

21 changes: 2 additions & 19 deletions clients/typescript/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-env node */
const [major, minor, _patch] = process.versions.node.split('.').map(Number)
import config from '../../common/ava.config.mjs'

// Developers can provide a `TEST_ONLY_DIALECT` value of `postgres`, `pglite`, or `sqlite`
// to run the unit tests only for that dialect.
Expand All @@ -14,17 +14,6 @@ if (testOnlyDialect && disableDialect) {
)
}

let loaderArg
if (
major > 20 ||
(major === 20 && minor >= 6) ||
(major === 18 && minor >= 19)
) {
loaderArg = '--import=tsx'
} else {
loaderArg = '--loader=tsx'
}

const files = ['test/**/*.test.ts', 'test/**/*.test.tsx']
const ignorePostgres = ['!test/**/postgres/**']
const ignorePglite = ['!test/**/pglite/**']
Expand Down Expand Up @@ -55,12 +44,6 @@ switch (disableDialect) {
}

export default {
timeout: '10m',
...config,
files,
extensions: {
ts: 'module',
tsx: 'module',
},
nodeArguments: ['--no-warnings', loaderArg],
workerThreads: false,
}
31 changes: 4 additions & 27 deletions clients/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@
"files": [
"dist"
],
"bin": {
"electric-sql": "dist/cli/main.js"
},
"exports": {
"./browser": "./dist/drivers/wa-sqlite/index.js",
"./capacitor": "./dist/drivers/capacitor-sqlite/index.js",
Expand Down Expand Up @@ -160,12 +157,11 @@
},
"scripts": {
"post-version-bump": "node -p \"'export const LIB_VERSION = \\'' + require('./package.json').version + '\\''\" > src/version/index.ts",
"dev": "shx rm -rf dist && npm run build:copy-docker && mkdir dist && concurrently \"tsup --watch\" \"tsc -p tsconfig.build.json --watch\" \"nodemon --watch ./dist --delay 250ms ./scripts/fix-imports.js\"",
"build": "shx rm -rf dist && npm run build:copy-docker && concurrently \"tsup\" \"tsc -p tsconfig.build.json\" && node scripts/fix-imports.js",
"build:copy-docker": "shx mkdir -p ./dist/cli/docker-commands/docker && shx cp -r ./src/cli/docker-commands/docker ./dist/cli/docker-commands",
"dev": "shx rm -rf dist && mkdir dist && concurrently \"tsup --watch\" \"tsc -p tsconfig.build.json --watch\" \"nodemon --watch ./dist --delay 250ms ./scripts/fix-imports.js\"",
"build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\" && node scripts/fix-imports.js",
"test": "ava",
"test-CI": "DISABLE_DIALECT=postgres npm run test",
"generate-test-client": "npx tsx ./test/client/generateTestClient.ts",
"generate-test-client": "npx tsx ../../components/cli/src/client/generateTestClient.ts",
"typecheck": "tsc -p tsconfig.json",
"posttest": "npm run typecheck",
"prepublishOnly": "pnpm run build",
Expand All @@ -177,19 +173,10 @@
"**/*": "prettier --write --ignore-unknown"
},
"dependencies": {
"@electric-sql/prisma-generator": "workspace:*",
"@prisma/client": "4.8.1",
"async-mutex": "^0.4.0",
"base-64": "^1.0.0",
"better-sqlite3": "^11.0.0",
"commander": "^11.1.0",
"cross-fetch": "^3.1.5",
"decompress": "^4.2.1",
"dotenv-flow": "^4.1.0",
"events": "^3.3.0",
"exponential-backoff": "^3.1.0",
"frame-stream": "^3.0.1",
"get-port": "^7.0.0",
"jose": "^4.14.4",
"lodash.flow": "^3.5.0",
"lodash.groupby": "^4.6.0",
Expand All @@ -205,24 +192,20 @@
"object.hasown": "^1.1.2",
"ohash": "^1.1.2",
"prisma": "4.8.1",
"prompts": "^2.4.2",
"protobufjs": "^7.1.1",
"squel": "^5.13.0",
"tcp-port-used": "^1.0.2",
"text-encoder-lite": "^2.0.0",
"ts-dedent": "^2.2.0",
"ws": "^8.8.1",
"zod": "3.21.1"
},
"devDependencies": {
"@electric-sql/pglite": "^0.1.5",
"@electric-sql/prisma-generator": "workspace:*",
"@op-engineering/op-sqlite": ">= 2.0.16",
"@tauri-apps/plugin-sql": "2.0.0-alpha.5",
"@testing-library/react": "^13.4.0",
"@types/base-64": "^1.0.0",
"@types/better-sqlite3": "7.6.10",
"@types/decompress": "^4.2.4",
"@types/lodash.flow": "^3.5.7",
"@types/lodash.groupby": "^4.6.7",
"@types/lodash.isequal": "^4.5.6",
Expand All @@ -234,10 +217,7 @@
"@types/lodash.uniqwith": "^4.5.9",
"@types/node": "^18.8.4",
"@types/pg": "^8.11.0",
"@types/prompts": "^2.4.9",
"@types/react": "^18.0.18",
"@types/tcp-port-used": "^1.0.2",
"@types/uuid": "^9.0.1",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.34.0",
"@typescript-eslint/parser": "^5.34.0",
Expand All @@ -249,7 +229,6 @@
"expo-sqlite": "^13.1.0",
"glob": "^10.3.10",
"global-jsdom": "24.0.0",
"husky": "^8.0.3",
"jsdom": "24.0.0",
"lint-staged": "^13.1.0",
"memorystorage": "^0.12.0",
Expand All @@ -258,7 +237,6 @@
"prettier": "2.8.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"release-it": "^15.5.0",
"shx": "^0.3.4",
"ts-proto": "^1.125.0",
"tsup": "^8.0.1",
Expand All @@ -267,8 +245,7 @@
"typescript": "^5.3.3",
"vue": "^3.4.19",
"vue-tsc": "^1.8.27",
"wa-sqlite": "rhashimoto/wa-sqlite#semver:^0.9.8",
"web-worker": "^1.2.0"
"wa-sqlite": "rhashimoto/wa-sqlite#semver:^0.9.8"
},
"peerDependencies": {
"@capacitor-community/sqlite": ">= 5.6.2",
Expand Down
1 change: 1 addition & 0 deletions clients/typescript/src/migrators/query-builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import pgBuilder from './pgBuilder'
import { QueryBuilder as QueryBuilder } from './builder'

export { sqliteBuilder, pgBuilder, QueryBuilder }
export type { Dialect } from './builder'
Loading

0 comments on commit cb19c58

Please sign in to comment.