@pylonsync/cli 0.3.3
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 +5 -0
- package/bin/pylon.js +87 -0
- package/package.json +33 -0
package/README.md
ADDED
package/bin/pylon.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Pylon CLI dispatcher.
|
|
3
|
+
//
|
|
4
|
+
// Resolves the platform-specific binary package at runtime and execs it
|
|
5
|
+
// with the same argv. Mirrors the pattern used by esbuild, swc, turbo,
|
|
6
|
+
// rollup, etc.: one main package + N optionalDependencies, each shipping
|
|
7
|
+
// one prebuilt binary. No postinstall script — npm/bun install only the
|
|
8
|
+
// optional dep matching the current platform, and we look it up via
|
|
9
|
+
// require.resolve.
|
|
10
|
+
//
|
|
11
|
+
// Why not a single package with all binaries: tarball size. Each
|
|
12
|
+
// platform binary is ~16MB; bundling all four would balloon every
|
|
13
|
+
// install to 64MB regardless of platform. The optionalDependencies
|
|
14
|
+
// pattern keeps installs at ~16MB.
|
|
15
|
+
|
|
16
|
+
import { spawnSync } from "node:child_process";
|
|
17
|
+
import { createRequire } from "node:module";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
import { dirname, join } from "node:path";
|
|
20
|
+
import { existsSync } from "node:fs";
|
|
21
|
+
|
|
22
|
+
const require = createRequire(import.meta.url);
|
|
23
|
+
|
|
24
|
+
// Map (process.platform, process.arch) → package name. The name is also
|
|
25
|
+
// the platform-package's directory name on disk.
|
|
26
|
+
const PLATFORM_PACKAGES = {
|
|
27
|
+
"darwin-arm64": "@pylonsync/cli-darwin-arm64",
|
|
28
|
+
"darwin-x64": "@pylonsync/cli-darwin-x64",
|
|
29
|
+
"linux-arm64": "@pylonsync/cli-linux-arm64",
|
|
30
|
+
"linux-x64": "@pylonsync/cli-linux-x64",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function resolveBinary() {
|
|
34
|
+
const key = `${process.platform}-${process.arch}`;
|
|
35
|
+
const pkg = PLATFORM_PACKAGES[key];
|
|
36
|
+
if (!pkg) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`@pylonsync/cli: no prebuilt binary for ${key}.\n` +
|
|
39
|
+
`Supported: ${Object.keys(PLATFORM_PACKAGES).join(", ")}.\n` +
|
|
40
|
+
`Build from source: https://github.com/pylonsync/pylon`,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// require.resolve returns the package's main file; the binary lives
|
|
45
|
+
// at <package-root>/bin/pylon. Walk up from main to find the dir.
|
|
46
|
+
let entry;
|
|
47
|
+
try {
|
|
48
|
+
entry = require.resolve(`${pkg}/package.json`);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
`@pylonsync/cli: ${pkg} is not installed.\n` +
|
|
52
|
+
`This usually means npm/bun install skipped the optional dependency.\n` +
|
|
53
|
+
`Try: npm install --no-optional=false @pylonsync/cli\n\n` +
|
|
54
|
+
`Underlying error: ${e.message}`,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const binPath = join(dirname(entry), "bin", "pylon");
|
|
59
|
+
if (!existsSync(binPath)) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
`@pylonsync/cli: binary missing at ${binPath}.\n` +
|
|
62
|
+
`The platform package was installed but doesn't contain the binary.\n` +
|
|
63
|
+
`Try reinstalling: npm install --force @pylonsync/cli`,
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return binPath;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
let binary;
|
|
70
|
+
try {
|
|
71
|
+
binary = resolveBinary();
|
|
72
|
+
} catch (err) {
|
|
73
|
+
process.stderr.write(`${err.message}\n`);
|
|
74
|
+
process.exit(1);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Pass argv straight through. `inherit` for stdio so colors / progress
|
|
78
|
+
// bars / TTY-aware output work unchanged.
|
|
79
|
+
const result = spawnSync(binary, process.argv.slice(2), { stdio: "inherit" });
|
|
80
|
+
|
|
81
|
+
// Forward the binary's exit code so callers get an honest signal —
|
|
82
|
+
// `pylon dev && next dev` should fail fast if pylon dev crashes.
|
|
83
|
+
if (result.error) {
|
|
84
|
+
process.stderr.write(`@pylonsync/cli: failed to spawn binary: ${result.error.message}\n`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
process.exit(result.status ?? 0);
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pylonsync/cli",
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "Pylon CLI — `pylon dev`, `pylon start`, `pylon migrate`, etc. Bundles the native binary for your platform via optionalDependencies, no postinstall script required.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://pylonsync.com",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/pylonsync/pylon.git",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./bin/pylon.js",
|
|
17
|
+
"bin": {
|
|
18
|
+
"pylon": "./bin/pylon.js"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"bin/pylon.js",
|
|
22
|
+
"README.md"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"optionalDependencies": {
|
|
28
|
+
"@pylonsync/cli-darwin-arm64": "0.3.3",
|
|
29
|
+
"@pylonsync/cli-darwin-x64": "0.3.3",
|
|
30
|
+
"@pylonsync/cli-linux-arm64": "0.3.3",
|
|
31
|
+
"@pylonsync/cli-linux-x64": "0.3.3"
|
|
32
|
+
}
|
|
33
|
+
}
|