@dbdiff/cli 3.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # @dbdiff/cli
2
+
3
+ > Compare MySQL, Postgres or SQLite databases and automatically create schema & data change migrations — no PHP required.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ # Global install
9
+ npm install -g @dbdiff/cli
10
+
11
+ # One-off via npx
12
+ npx @dbdiff/cli --help
13
+
14
+ # Project dev dependency
15
+ npm install --save-dev @dbdiff/cli
16
+
17
+ # Install from GitHub Packages (mirror registry)
18
+ npm install -g @dbdiff/cli --registry=https://npm.pkg.github.com
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ # Schema diff between two MySQL databases
25
+ dbdiff server1.db1:server2.db2
26
+
27
+ # Full diff (schema + data) with Supabase Postgres
28
+ dbdiff --supabase --server1=user:pass@host:5432 db1:db2
29
+
30
+ # Generate migration files
31
+ dbdiff --type=both --output=migrations/ server1.db1:server2.db2
32
+ ```
33
+
34
+ ## How it works
35
+
36
+ `@dbdiff/cli` distributes a **platform-native self-contained binary** — a
37
+ static PHP interpreter with all required extensions baked in, combined with
38
+ the DBDiff PHAR. There is no PHP installation, no Composer, and no runtime
39
+ dependencies required on the end-user machine.
40
+
41
+ npm automatically downloads only the binary for your platform (~10–15 MB):
42
+
43
+ | Platform | Package |
44
+ |---|---|
45
+ | Linux x64 (glibc) | `@dbdiff/cli-linux-x64` |
46
+ | Linux arm64 (glibc) | `@dbdiff/cli-linux-arm64` |
47
+ | Linux x64 (musl/Alpine) | `@dbdiff/cli-linux-x64-musl` |
48
+ | Linux arm64 (musl/Alpine) | `@dbdiff/cli-linux-arm64-musl` |
49
+ | macOS Intel | `@dbdiff/cli-darwin-x64` |
50
+ | macOS Apple Silicon | `@dbdiff/cli-darwin-arm64` |
51
+ | Windows x64 | `@dbdiff/cli-win32-x64` |
52
+ | Windows arm64 | `@dbdiff/cli-win32-arm64` |
53
+
54
+ ## Links
55
+
56
+ - [Full documentation](https://github.com/DBDiff/DBDiff)
57
+ - [Issue tracker](https://github.com/DBDiff/DBDiff/issues)
58
+ - [Changelog](https://github.com/DBDiff/DBDiff/releases)
59
+
60
+ ## License
61
+
62
+ MIT
package/bin/dbdiff.js ADDED
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ // This is the only JavaScript in the entire @dbdiff/cli distribution.
5
+ // It detects the current platform, resolves the matching pre-built binary
6
+ // from the appropriate optional-dependency package, and executes it.
7
+ //
8
+ // Pattern mirrors @biomejs/biome and @tailwindcss/oxide — no PHP required.
9
+
10
+ const { execFileSync } = require('child_process');
11
+ const path = require('path');
12
+
13
+ const PLATFORM_PACKAGES = {
14
+ 'linux-x64': '@dbdiff/cli-linux-x64',
15
+ 'linux-arm64': '@dbdiff/cli-linux-arm64',
16
+ 'linux-x64-musl': '@dbdiff/cli-linux-x64-musl',
17
+ 'linux-arm64-musl': '@dbdiff/cli-linux-arm64-musl',
18
+ 'darwin-x64': '@dbdiff/cli-darwin-x64',
19
+ 'darwin-arm64': '@dbdiff/cli-darwin-arm64',
20
+ 'win32-x64': '@dbdiff/cli-win32-x64',
21
+ 'win32-arm64': '@dbdiff/cli-win32-arm64',
22
+ };
23
+
24
+ /**
25
+ * Returns true when the current Linux system is musl-based (e.g. Alpine).
26
+ * Checks /proc/version and ldd output — both are available on Alpine.
27
+ */
28
+ function isMusl() {
29
+ // Fast path: check /proc/version which contains "musl" on Alpine kernels
30
+ try {
31
+ const fs = require('fs');
32
+ const procVersion = fs.readFileSync('/proc/version', 'utf8');
33
+ if (procVersion.toLowerCase().includes('musl')) return true;
34
+ } catch {
35
+ // /proc/version may be absent in some minimal environments
36
+ }
37
+
38
+ // Fallback: ask ldd
39
+ try {
40
+ const { execSync } = require('child_process');
41
+ const ldd = execSync('ldd --version 2>&1', { encoding: 'utf8', timeout: 2000 });
42
+ return ldd.toLowerCase().includes('musl');
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+
48
+ function getPlatformKey() {
49
+ const platform = process.platform; // 'linux', 'darwin', 'win32'
50
+ const arch = process.arch; // 'x64', 'arm64'
51
+ let key = `${platform}-${arch}`;
52
+
53
+ // On Linux, distinguish musl (Alpine) from glibc (Ubuntu/Debian/RHEL)
54
+ if (platform === 'linux' && isMusl()) {
55
+ key = `linux-${arch}-musl`;
56
+ }
57
+
58
+ return key;
59
+ }
60
+
61
+ function getBinaryPath(pkg) {
62
+ const binaryName = process.platform === 'win32' ? 'dbdiff.exe' : 'dbdiff';
63
+ try {
64
+ const pkgDir = path.dirname(require.resolve(`${pkg}/package.json`));
65
+ const binPath = path.join(pkgDir, binaryName);
66
+ // Return null when the platform package is installed but contains no binary
67
+ // (can happen if a platform build failed during release).
68
+ return require('fs').existsSync(binPath) ? binPath : null;
69
+ } catch {
70
+ return null;
71
+ }
72
+ }
73
+
74
+ const key = getPlatformKey();
75
+ const pkg = PLATFORM_PACKAGES[key] ?? null;
76
+
77
+ if (!pkg) {
78
+ process.stderr.write(
79
+ `@dbdiff/cli: Unsupported platform: ${process.platform}-${process.arch}\n` +
80
+ `Please open an issue at https://github.com/DBDiff/DBDiff/issues\n`
81
+ );
82
+ process.exit(1);
83
+ }
84
+
85
+ const binaryPath = getBinaryPath(pkg);
86
+
87
+ // If no native binary is available, fall back to the PHAR bundled in this
88
+ // package and run it with system PHP. DBDiff targets PHP developers so php
89
+ // is expected to be in PATH on any machine where it isn't available natively
90
+ // (e.g. win32-x64 while the Windows static build is being stabilised).
91
+ if (!binaryPath) {
92
+ const fs = require('fs');
93
+ const pharPath = path.join(__dirname, '..', 'dbdiff.phar');
94
+
95
+ if (fs.existsSync(pharPath)) {
96
+ const phpExe = process.platform === 'win32' ? 'php.exe' : 'php';
97
+ try {
98
+ execFileSync(phpExe, [pharPath, ...process.argv.slice(2)], { stdio: 'inherit' });
99
+ } catch (err) {
100
+ if (err.code === 'ENOENT') {
101
+ process.stderr.write(
102
+ `@dbdiff/cli: No native binary is available for ${process.platform}-${process.arch}.\n` +
103
+ `Attempted PHAR fallback but 'php' was not found in PATH.\n` +
104
+ `Install PHP 8.1+ from https://www.php.net/downloads and add it to your PATH,\n` +
105
+ `or open an issue at https://github.com/DBDiff/DBDiff/issues\n`
106
+ );
107
+ process.exit(1);
108
+ }
109
+ process.exit(err.status ?? 1);
110
+ }
111
+ } else {
112
+ process.stderr.write(
113
+ `@dbdiff/cli: Could not locate the binary for ${process.platform}-${process.arch}.\n` +
114
+ `The platform-specific package '${pkg}' may not have been installed.\n` +
115
+ `Try reinstalling: npm install -g @dbdiff/cli\n`
116
+ );
117
+ process.exit(1);
118
+ }
119
+ } else {
120
+ try {
121
+ execFileSync(binaryPath, process.argv.slice(2), { stdio: 'inherit' });
122
+ } catch (err) {
123
+ process.exit(err.status ?? 1);
124
+ }
125
+ }
package/dbdiff.phar ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@dbdiff/cli",
3
+ "version": "3.0.0-rc.1",
4
+ "description": "Compare MySQL, Postgres or SQLite databases & automatically create schema & data change migrations",
5
+ "homepage": "https://github.com/DBDiff/DBDiff",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/DBDiff/DBDiff.git",
9
+ "directory": "packages/@dbdiff/cli"
10
+ },
11
+ "license": "MIT",
12
+ "bin": {
13
+ "dbdiff": "bin/dbdiff.js"
14
+ },
15
+ "files": [
16
+ "bin/dbdiff.js",
17
+ "dbdiff.phar",
18
+ "README.md",
19
+ "LICENSE"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18.0.0"
23
+ },
24
+ "optionalDependencies": {
25
+ "@dbdiff/cli-linux-x64": "3.0.0-rc.1",
26
+ "@dbdiff/cli-linux-arm64": "3.0.0-rc.1",
27
+ "@dbdiff/cli-linux-x64-musl": "3.0.0-rc.1",
28
+ "@dbdiff/cli-linux-arm64-musl": "3.0.0-rc.1",
29
+ "@dbdiff/cli-darwin-x64": "3.0.0-rc.1",
30
+ "@dbdiff/cli-darwin-arm64": "3.0.0-rc.1",
31
+ "@dbdiff/cli-win32-x64": "3.0.0-rc.1",
32
+ "@dbdiff/cli-win32-arm64": "3.0.0-rc.1"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }