@jxtools/promptline 1.3.20 → 1.3.21

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 CHANGED
@@ -10,6 +10,12 @@ Ever been watching Claude Code work and thought of three more things you need it
10
10
  npm install -g @jxtools/promptline
11
11
  ```
12
12
 
13
+ If your environment requires an explicit npm registry:
14
+
15
+ ```bash
16
+ npm install -g @jxtools/promptline --registry https://registry.npmjs.org/
17
+ ```
18
+
13
19
  ## Usage
14
20
 
15
21
  ```bash
@@ -3,13 +3,77 @@
3
3
  import { existsSync, readFileSync, writeFileSync, readdirSync, renameSync } from 'fs'
4
4
  import { resolve, dirname, join } from 'path'
5
5
  import { fileURLToPath } from 'url'
6
- import { spawn, execSync } from 'child_process'
6
+ import { spawn, execFileSync } from 'child_process'
7
7
  import { homedir } from 'os'
8
8
  import { installHooks as installPromptlineHooks, toErrorMessage } from './install-hooks.mjs'
9
9
 
10
10
  const __dirname = dirname(fileURLToPath(import.meta.url))
11
11
  const pkgDir = resolve(__dirname, '..')
12
12
  const pkg = JSON.parse(readFileSync(resolve(pkgDir, 'package.json'), 'utf-8'))
13
+ const registryFile = resolve(pkgDir, '.npm-registry')
14
+
15
+ function savedRegistry() {
16
+ if (!existsSync(registryFile)) return ''
17
+ return readFileSync(registryFile, 'utf-8').trim()
18
+ }
19
+
20
+ function npmRegistry() {
21
+ const explicit = process.env.npm_config_registry || process.env.NPM_CONFIG_REGISTRY
22
+ if (explicit) return explicit
23
+
24
+ const saved = savedRegistry()
25
+ if (saved) return saved
26
+
27
+ try {
28
+ return execFileSync('npm', ['config', 'get', 'registry'], {
29
+ encoding: 'utf-8',
30
+ stdio: ['ignore', 'pipe', 'ignore'],
31
+ }).trim()
32
+ } catch {
33
+ return ''
34
+ }
35
+ }
36
+
37
+ function versionKey(version) {
38
+ return version
39
+ .replace(/^v/, '')
40
+ .split('.')
41
+ .map(part => part.padStart(6, '0'))
42
+ .join('')
43
+ }
44
+
45
+ function isNewerVersion(candidate, current) {
46
+ return versionKey(candidate) > versionKey(current)
47
+ }
48
+
49
+ function npmViewLatestVersion(registry) {
50
+ const args = ['view', '@jxtools/promptline', 'version']
51
+ if (registry) args.push('--registry', registry)
52
+
53
+ return execFileSync('npm', args, {
54
+ encoding: 'utf-8',
55
+ stdio: ['ignore', 'pipe', 'ignore'],
56
+ env: {
57
+ ...process.env,
58
+ npm_config_fetch_retries: '0',
59
+ npm_config_fetch_timeout: '5000',
60
+ },
61
+ }).trim()
62
+ }
63
+
64
+ function npmInstallLatest(registry) {
65
+ const args = ['install', '-g', '@jxtools/promptline@latest']
66
+ if (registry) args.push('--registry', registry)
67
+
68
+ execFileSync('npm', args, {
69
+ stdio: 'inherit',
70
+ env: {
71
+ ...process.env,
72
+ npm_config_fetch_retries: '0',
73
+ npm_config_fetch_timeout: '10000',
74
+ },
75
+ })
76
+ }
13
77
 
14
78
  // --version
15
79
  if (process.argv.includes('--version') || process.argv.includes('-v')) {
@@ -20,13 +84,14 @@ if (process.argv.includes('--version') || process.argv.includes('-v')) {
20
84
  // update
21
85
  if (process.argv[2] === 'update') {
22
86
  const current = pkg.version
87
+ const registry = npmRegistry()
23
88
  console.log(`\x1b[36m⟳\x1b[0m Current version: v${current}`)
24
89
  console.log(` Checking for updates...`)
25
90
 
26
91
  try {
27
- const latest = execSync('npm view @jxtools/promptline version', { encoding: 'utf-8' }).trim()
92
+ const latest = npmViewLatestVersion(registry)
28
93
 
29
- if (latest === current) {
94
+ if (!isNewerVersion(latest, current)) {
30
95
  console.log(`\x1b[32m✓\x1b[0m Already on the latest version (v${current})`)
31
96
  process.exit(0)
32
97
  }
@@ -34,10 +99,11 @@ if (process.argv[2] === 'update') {
34
99
  console.log(`\x1b[33m↑\x1b[0m New version available: v${latest}`)
35
100
  console.log(` Updating...`)
36
101
 
37
- execSync('npm install -g @jxtools/promptline@latest', { stdio: 'inherit' })
102
+ npmInstallLatest(registry)
38
103
  console.log(`\n\x1b[32m✓\x1b[0m Updated to v${latest}`)
39
104
  } catch (err) {
40
- console.error(`\x1b[31m✗\x1b[0m Update failed: ${toErrorMessage(err)}`)
105
+ const suffix = registry ? ` (registry: ${registry})` : ''
106
+ console.error(`\x1b[31m✗\x1b[0m Update failed${suffix}: ${toErrorMessage(err)}`)
41
107
  process.exit(1)
42
108
  }
43
109
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jxtools/promptline",
3
- "version": "1.3.20",
3
+ "version": "1.3.21",
4
4
  "type": "module",
5
5
  "license": "ISC",
6
6
  "bin": {
@@ -8,6 +8,7 @@
8
8
  },
9
9
  "files": [
10
10
  "bin/",
11
+ "scripts/",
11
12
  "src/",
12
13
  "promptline-*.sh",
13
14
  "vite-plugin-api.ts",
@@ -26,6 +27,7 @@
26
27
  "access": "public"
27
28
  },
28
29
  "scripts": {
30
+ "postinstall": "node scripts/postinstall.js",
29
31
  "dev": "vite",
30
32
  "build": "tsc -b && vite build",
31
33
  "lint": "eslint .",
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { execFileSync } from 'child_process'
4
+ import { writeFileSync } from 'fs'
5
+ import { dirname, resolve } from 'path'
6
+ import { fileURLToPath } from 'url'
7
+
8
+ const __dirname = dirname(fileURLToPath(import.meta.url))
9
+ const pkgDir = resolve(__dirname, '..')
10
+ const registryFile = resolve(pkgDir, '.npm-registry')
11
+
12
+ function resolveRegistry(env) {
13
+ const explicit = env.npm_config_registry || env.NPM_CONFIG_REGISTRY
14
+ if (explicit) return explicit
15
+
16
+ try {
17
+ return execFileSync('npm', ['config', 'get', 'registry'], {
18
+ encoding: 'utf-8',
19
+ stdio: ['ignore', 'pipe', 'ignore'],
20
+ }).trim()
21
+ } catch {
22
+ return ''
23
+ }
24
+ }
25
+
26
+ const registry = resolveRegistry(process.env)
27
+ if (registry) {
28
+ writeFileSync(registryFile, `${registry}\n`)
29
+ }