@polar-sh/cli 0.0.1 → 2.0.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/LICENSE +0 -0
- package/README.md +22 -2
- package/bin/polar.exe +5 -0
- package/package.json +24 -4
- package/postinstall.mjs +123 -0
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Polar CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Tunnel webhooks to your local environment and manage your Polar organization from the terminal.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install -g @polar-sh/cli
|
|
7
|
+
polar login
|
|
8
|
+
polar listen http://localhost:3000/
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package installs the prebuilt `polar` binary for your platform from one of the
|
|
12
|
+
`@polar-sh/cli-*` packages in a postinstall step. pnpm and bun block
|
|
13
|
+
install scripts by default, so allow this one:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add -g --allow-build=@polar-sh/cli @polar-sh/cli
|
|
17
|
+
bun install -g --trust @polar-sh/cli
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
If installation scripts stay disabled, the `polar` command prints an error instead of
|
|
21
|
+
running. Install with `curl -fsSL https://polar.sh/install.sh | bash` in that case.
|
|
22
|
+
|
|
23
|
+
Version 2.0.1. Source and documentation: https://github.com/polarsource/polar/tree/main/clients/packages/cli
|
package/bin/polar.exe
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
echo "Error: @polar-sh/cli's postinstall script was not run." >&2
|
|
2
|
+
echo "" >&2
|
|
3
|
+
echo "This occurs when installation scripts are disabled." >&2
|
|
4
|
+
echo "Run the package postinstall script or reinstall with scripts enabled, or install with: curl -fsSL https://polar.sh/install.sh | bash" >&2
|
|
5
|
+
exit 1
|
package/package.json
CHANGED
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polar-sh/cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Polar CLI
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Polar CLI: tunnel webhooks locally and manage your Polar organization from the terminal",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/polarsource/polar.git",
|
|
9
9
|
"directory": "clients/packages/cli"
|
|
10
10
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
11
|
+
"homepage": "https://polar.sh",
|
|
12
|
+
"bin": {
|
|
13
|
+
"polar": "bin/polar.exe"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node ./postinstall.mjs"
|
|
17
|
+
},
|
|
18
|
+
"os": [
|
|
19
|
+
"darwin",
|
|
20
|
+
"linux",
|
|
21
|
+
"win32"
|
|
22
|
+
],
|
|
23
|
+
"cpu": [
|
|
24
|
+
"arm64",
|
|
25
|
+
"x64"
|
|
26
|
+
],
|
|
27
|
+
"optionalDependencies": {
|
|
28
|
+
"@polar-sh/cli-darwin-arm64": "2.0.1",
|
|
29
|
+
"@polar-sh/cli-darwin-x64": "2.0.1",
|
|
30
|
+
"@polar-sh/cli-linux-arm64": "2.0.1",
|
|
31
|
+
"@polar-sh/cli-linux-x64": "2.0.1",
|
|
32
|
+
"@polar-sh/cli-windows-x64": "2.0.1"
|
|
13
33
|
}
|
|
14
34
|
}
|
package/postinstall.mjs
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import childProcess from 'node:child_process'
|
|
4
|
+
import console from 'node:console'
|
|
5
|
+
import fs from 'node:fs'
|
|
6
|
+
import { createRequire } from 'node:module'
|
|
7
|
+
import os from 'node:os'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import process from 'node:process'
|
|
10
|
+
import { fileURLToPath } from 'node:url'
|
|
11
|
+
|
|
12
|
+
const directory = path.dirname(fileURLToPath(import.meta.url))
|
|
13
|
+
const require = createRequire(import.meta.url)
|
|
14
|
+
const manifest = JSON.parse(
|
|
15
|
+
fs.readFileSync(path.join(directory, 'package.json'), 'utf8'),
|
|
16
|
+
)
|
|
17
|
+
const command = Object.keys(manifest.bin ?? {})[0]
|
|
18
|
+
if (!command) throw new Error(`${manifest.name} does not declare a binary`)
|
|
19
|
+
|
|
20
|
+
const platform =
|
|
21
|
+
{ darwin: 'darwin', linux: 'linux', win32: 'windows' }[os.platform()] ??
|
|
22
|
+
os.platform()
|
|
23
|
+
const arch = { x64: 'x64', arm64: 'arm64' }[os.arch()] ?? os.arch()
|
|
24
|
+
const sourceBinary = platform === 'windows' ? `${command}.exe` : command
|
|
25
|
+
const targetBinary = path.resolve(directory, manifest.bin[command])
|
|
26
|
+
const dependencies = manifest.optionalDependencies ?? {}
|
|
27
|
+
const name = Object.keys(dependencies).find((item) =>
|
|
28
|
+
item.endsWith(`-${platform}-${arch}`),
|
|
29
|
+
)
|
|
30
|
+
if (!name) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`${manifest.name} does not provide a binary for ${platform}-${arch}. Install with: curl -fsSL https://polar.sh/install.sh | bash`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function copyBinary(source) {
|
|
37
|
+
if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)
|
|
38
|
+
fs.mkdirSync(path.dirname(targetBinary), { recursive: true })
|
|
39
|
+
fs.rmSync(targetBinary, { force: true })
|
|
40
|
+
try {
|
|
41
|
+
fs.linkSync(source, targetBinary)
|
|
42
|
+
} catch {
|
|
43
|
+
fs.copyFileSync(source, targetBinary)
|
|
44
|
+
}
|
|
45
|
+
fs.chmodSync(targetBinary, 0o755)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function resolveBinary() {
|
|
49
|
+
const packagePath = require.resolve(`${name}/package.json`)
|
|
50
|
+
return path.join(path.dirname(packagePath), 'bin', sourceBinary)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Package managers skip optional dependencies when the lockfile was generated on
|
|
54
|
+
// another platform; fetch the exact platform package into a temporary prefix instead.
|
|
55
|
+
// npm is a .cmd wrapper on Windows, so it has to go through the shell there. The
|
|
56
|
+
// arguments stay static and the prefix is passed as cwd, so nothing needs quoting.
|
|
57
|
+
function installPackage() {
|
|
58
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'polar-cli-install-'))
|
|
59
|
+
// A global install passes its flag down to lifecycle scripts as npm_config_global
|
|
60
|
+
// or npm_config_location, which would send the child install to the global prefix.
|
|
61
|
+
const env = { ...process.env }
|
|
62
|
+
delete env.npm_config_global
|
|
63
|
+
delete env.npm_config_location
|
|
64
|
+
try {
|
|
65
|
+
fs.writeFileSync(path.join(temp, 'package.json'), '{}')
|
|
66
|
+
const result = childProcess.spawnSync(
|
|
67
|
+
'npm',
|
|
68
|
+
[
|
|
69
|
+
'install',
|
|
70
|
+
'--ignore-scripts',
|
|
71
|
+
'--no-save',
|
|
72
|
+
'--loglevel=error',
|
|
73
|
+
`${name}@${dependencies[name]}`,
|
|
74
|
+
],
|
|
75
|
+
{
|
|
76
|
+
cwd: temp,
|
|
77
|
+
env,
|
|
78
|
+
shell: process.platform === 'win32',
|
|
79
|
+
stdio: 'inherit',
|
|
80
|
+
windowsHide: true,
|
|
81
|
+
},
|
|
82
|
+
)
|
|
83
|
+
if (result.status !== 0) return false
|
|
84
|
+
copyBinary(path.join(temp, 'node_modules', name, 'bin', sourceBinary))
|
|
85
|
+
return true
|
|
86
|
+
} finally {
|
|
87
|
+
fs.rmSync(temp, { recursive: true, force: true })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function verifyBinary() {
|
|
92
|
+
return (
|
|
93
|
+
childProcess.spawnSync(targetBinary, ['--version'], {
|
|
94
|
+
stdio: 'ignore',
|
|
95
|
+
windowsHide: true,
|
|
96
|
+
env: { ...process.env, POLAR_CLI_TELEMETRY_OPTOUT: '1' },
|
|
97
|
+
}).status === 0
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function linkInstalledPackage() {
|
|
102
|
+
try {
|
|
103
|
+
copyBinary(resolveBinary())
|
|
104
|
+
return verifyBinary()
|
|
105
|
+
} catch {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function main() {
|
|
111
|
+
if (linkInstalledPackage()) return
|
|
112
|
+
if (installPackage() && verifyBinary()) return
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Failed to install ${manifest.name}. Try manually installing ${JSON.stringify(name)}, or install with: curl -fsSL https://polar.sh/install.sh | bash`,
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
main()
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(error instanceof Error ? error.message : String(error))
|
|
122
|
+
process.exit(1)
|
|
123
|
+
}
|