@nipurn/xprompt-v1 1.1.26

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/bin/100xprompt ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "child_process"
3
+ import path from "path"
4
+ import fs from "fs"
5
+ import { fileURLToPath } from "url"
6
+
7
+ const __filename = fileURLToPath(import.meta.url)
8
+ const __dirname = path.dirname(__filename)
9
+
10
+ function getPlatformPackageName() {
11
+ const platform = process.platform
12
+ const arch = process.arch
13
+ // @ts-ignore
14
+ const isMusl = process.report?.getReport?.()?.header?.glibcVersionRuntime === undefined
15
+
16
+ let osName
17
+ if (platform === 'darwin') osName = 'darwin'
18
+ else if (platform === 'linux') osName = 'linux'
19
+ else if (platform === 'win32') osName = 'windows'
20
+
21
+ let pkgName = `nipurn-xprompt-v1-${osName}-${arch}`
22
+ if (platform === 'linux' && isMusl) {
23
+ pkgName = `nipurn-xprompt-v1-linux-${arch}-musl`
24
+ }
25
+
26
+ return pkgName
27
+ }
28
+
29
+ const platformPackageName = getPlatformPackageName()
30
+ const binDir = path.join(__dirname, '..', 'node_modules', platformPackageName, 'bin')
31
+ const binPath = path.join(binDir, '100xprompt')
32
+
33
+ if (!fs.existsSync(binPath)) {
34
+ console.error(`Error: Binary not found at ${binPath}`)
35
+ console.error('This package requires a platform-specific optional dependency.')
36
+ console.error('Please ensure that the correct optional dependency is installed for your system.')
37
+ console.error('You might need to run "npm install" or "yarn install" again.')
38
+ process.exit(1)
39
+ }
40
+
41
+ const args = process.argv.slice(2)
42
+ const child = spawn(binPath, args, { stdio: 'inherit' })
43
+
44
+ child.on('close', (code) => {
45
+ process.exit(code ?? 0)
46
+ })
47
+
48
+ child.on('error', (err) => {
49
+ console.error('Failed to start binary:', err)
50
+ process.exit(1)
51
+ })
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process')
3
+ const path = require('path')
4
+ const fs = require('fs')
5
+
6
+ function getPlatformPackageName() {
7
+ const platform = process.platform
8
+ const arch = process.arch
9
+ const isMusl = process.report?.getReport?.()?.header?.glibcVersionRuntime === undefined
10
+
11
+ let osName
12
+ if (platform === 'darwin') osName = 'darwin'
13
+ else if (platform === 'linux') osName = 'linux'
14
+ else if (platform === 'win32') osName = 'windows'
15
+
16
+ let pkgName = `nipurn-xprompt-v1-${osName}-${arch}`
17
+ if (platform === 'linux' && isMusl) {
18
+ pkgName = `nipurn-xprompt-v1-linux-${arch}-musl`
19
+ }
20
+
21
+ return pkgName
22
+ }
23
+
24
+ function findBinary() {
25
+ const pkgName = getPlatformPackageName()
26
+ const possiblePaths = [
27
+ path.join(__dirname, '..', '..', pkgName, 'bin', '100xprompt'),
28
+ path.join(__dirname, '..', '..', pkgName, 'bin', '100xprompt.exe'),
29
+ path.join(__dirname, '..', '..', 'node_modules', pkgName, 'bin', '100xprompt'),
30
+ path.join(__dirname, '..', '..', 'node_modules', pkgName, 'bin', '100xprompt.exe'),
31
+ ]
32
+
33
+ for (const p of possiblePaths) {
34
+ if (fs.existsSync(p)) return p
35
+ }
36
+
37
+ try {
38
+ const pkgPath = require.resolve(pkgName + '/package.json')
39
+ const binPath = path.join(path.dirname(pkgPath), 'bin', '100xprompt')
40
+ if (fs.existsSync(binPath)) return binPath
41
+ if (fs.existsSync(binPath + '.exe')) return binPath + '.exe'
42
+ } catch {}
43
+
44
+ return null
45
+ }
46
+
47
+ const binaryPath = findBinary()
48
+ if (!binaryPath) {
49
+ console.error(`Could not find binary for platform: ${getPlatformPackageName()}`)
50
+ process.exit(1)
51
+ }
52
+
53
+ const child = spawn(binaryPath, process.argv.slice(2), {
54
+ stdio: 'inherit',
55
+ env: process.env
56
+ })
57
+
58
+ child.on('exit', (code) => process.exit(code || 0))
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@nipurn/xprompt-v1",
3
+ "bin": {
4
+ "100xprompt": "./bin/100xprompt"
5
+ },
6
+ "scripts": {
7
+ "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
8
+ },
9
+ "version": "1.1.26",
10
+ "optionalDependencies": {
11
+ "nipurn-xprompt-v1-linux-arm64": "1.1.26",
12
+ "nipurn-xprompt-v1-linux-x64": "1.1.26",
13
+ "nipurn-xprompt-v1-linux-x64-baseline": "1.1.26",
14
+ "nipurn-xprompt-v1-linux-arm64-musl": "1.1.26",
15
+ "nipurn-xprompt-v1-linux-x64-musl": "1.1.26",
16
+ "nipurn-xprompt-v1-linux-x64-baseline-musl": "1.1.26",
17
+ "nipurn-xprompt-v1-darwin-arm64": "1.1.26",
18
+ "nipurn-xprompt-v1-darwin-x64": "1.1.26",
19
+ "nipurn-xprompt-v1-darwin-x64-baseline": "1.1.26",
20
+ "nipurn-xprompt-v1-windows-x64": "1.1.26",
21
+ "nipurn-xprompt-v1-windows-x64-baseline": "1.1.26"
22
+ }
23
+ }
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "fs"
4
+ import path from "path"
5
+ import os from "os"
6
+ import { fileURLToPath } from "url"
7
+ import { createRequire } from "module"
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url))
10
+ const require = createRequire(import.meta.url)
11
+
12
+ function detectPlatformAndArch() {
13
+ // Map platform names
14
+ let platform
15
+ switch (os.platform()) {
16
+ case "darwin":
17
+ platform = "darwin"
18
+ break
19
+ case "linux":
20
+ platform = "linux"
21
+ break
22
+ case "win32":
23
+ platform = "windows"
24
+ break
25
+ default:
26
+ platform = os.platform()
27
+ break
28
+ }
29
+
30
+ // Map architecture names
31
+ let arch
32
+ switch (os.arch()) {
33
+ case "x64":
34
+ arch = "x64"
35
+ break
36
+ case "arm64":
37
+ arch = "arm64"
38
+ break
39
+ case "arm":
40
+ arch = "arm"
41
+ break
42
+ default:
43
+ arch = os.arch()
44
+ break
45
+ }
46
+
47
+ return { platform, arch }
48
+ }
49
+
50
+ function findBinary() {
51
+ const { platform, arch } = detectPlatformAndArch()
52
+ const packageName = `nipurn-xprompt-v1-${platform}-${arch}`
53
+ const binaryName = platform === "windows" ? "100xprompt.exe" : "100xprompt"
54
+
55
+ try {
56
+ // Use require.resolve to find the package
57
+ const packageJsonPath = require.resolve(`${packageName}/package.json`)
58
+ const packageDir = path.dirname(packageJsonPath)
59
+ const binaryPath = path.join(packageDir, "bin", binaryName)
60
+
61
+ if (!fs.existsSync(binaryPath)) {
62
+ throw new Error(`Binary not found at ${binaryPath}`)
63
+ }
64
+
65
+ return { binaryPath, binaryName }
66
+ } catch (error) {
67
+ throw new Error(`Could not find package ${packageName}: ${error.message}`)
68
+ }
69
+ }
70
+
71
+ function prepareBinDirectory(binaryName) {
72
+ const binDir = path.join(__dirname, "bin")
73
+ const targetPath = path.join(binDir, binaryName)
74
+
75
+ // Ensure bin directory exists
76
+ if (!fs.existsSync(binDir)) {
77
+ fs.mkdirSync(binDir, { recursive: true })
78
+ }
79
+
80
+ // Remove existing binary/symlink if it exists
81
+ if (fs.existsSync(targetPath)) {
82
+ fs.unlinkSync(targetPath)
83
+ }
84
+
85
+ return { binDir, targetPath }
86
+ }
87
+
88
+ function symlinkBinary(sourcePath, binaryName) {
89
+ const { targetPath } = prepareBinDirectory(binaryName)
90
+
91
+ fs.symlinkSync(sourcePath, targetPath)
92
+ console.log(`100xprompt binary symlinked: ${targetPath} -> ${sourcePath}`)
93
+
94
+ // Verify the file exists after operation
95
+ if (!fs.existsSync(targetPath)) {
96
+ throw new Error(`Failed to symlink binary to ${targetPath}`)
97
+ }
98
+ }
99
+
100
+ async function main() {
101
+ try {
102
+ if (os.platform() === "win32") {
103
+ // On Windows, the .exe is already included in the package and bin field points to it
104
+ // No postinstall setup needed
105
+ console.log("Windows detected: binary setup not needed (using packaged .exe)")
106
+ return
107
+ }
108
+
109
+ const { binaryPath, binaryName } = findBinary()
110
+ symlinkBinary(binaryPath, binaryName)
111
+ } catch (error) {
112
+ console.error("Failed to setup 100xprompt binary:", error.message)
113
+ process.exit(1)
114
+ }
115
+ }
116
+
117
+ try {
118
+ main()
119
+ } catch (error) {
120
+ console.error("Postinstall script error:", error.message)
121
+ process.exit(0)
122
+ }