@bunode/cli 0.0.0-alpha.0 → 0.0.0

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/bunode.mjs ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ const wrapperMarker = process.env.BUNODE_WRAPPER_MARKER
3
+
4
+ try {
5
+ const { runCli } = await import('../dist/cli.mjs')
6
+
7
+ if (wrapperMarker) {
8
+ delete process.env.BUNODE_WRAPPER_MARKER
9
+ try {
10
+ const { writeFile } = await import('node:fs/promises')
11
+ await writeFile(wrapperMarker, '')
12
+ } catch {
13
+ // The launcher treats a missing marker as a wrapper startup failure.
14
+ }
15
+ }
16
+
17
+ await runCli(import.meta.url)
18
+ } catch (error) {
19
+ process.stderr.write(`Bunode failed: ${getErrorMessage(error)}\n`)
20
+ process.exitCode = 1
21
+ }
22
+
23
+ function getErrorMessage(error) {
24
+ return error instanceof Error ? error.message : String(error)
25
+ }
package/dist/cli.mjs CHANGED
@@ -1,3 +1,198 @@
1
- #!/usr/bin/env node
2
- process.stdout.write(`helloworld
3
- `);export{};
1
+ import{createRequire as e}from"module";import{execFile as t,execFileSync as n,spawn as r}from"child_process";import{fileURLToPath as i}from"url";import{access as a,chmod as o,copyFile as s,link as c,lstat as l,mkdir as u,readFile as d,readlink as ee,realpath as f,rename as p,rm as m,stat as h,unlink as te,writeFile as g}from"fs/promises";import{createHash as _,randomBytes as ne}from"crypto";import{EOL as re,homedir as v,platform as y,tmpdir as ie}from"os";import{basename as b,delimiter as ae,dirname as x,isAbsolute as oe,join as S,parse as se,resolve as C}from"path";import{constants as w,existsSync as T,readFileSync as ce}from"fs";import{promisify as le}from"util";import{arch as ue,platform as E,report as de}from"process";var fe=Object.create,pe=Object.defineProperty,me=Object.getOwnPropertyDescriptor,he=Object.getOwnPropertyNames,ge=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty,ve=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),ye=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=he(t),a=0,o=i.length,s;a<o;a++)s=i[a],!_e.call(e,s)&&s!==n&&pe(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=me(t,s))||r.enumerable});return e},be=(e,t,n)=>(n=e==null?{}:fe(ge(e)),ye(t||!e||!e.__esModule?pe(n,`default`,{value:e,enumerable:!0}):n,e)),xe=`// This script only removes its managed profile block after the owning package is uninstalled.
2
+ // Template literals keep the generated helper readable.
3
+ const crypto = require(\`node:crypto\`)
4
+ const fs = require(\`node:fs\`)
5
+ const path = require(\`node:path\`)
6
+
7
+ const [profile, startMarker, endMarker] = process.argv.slice(2)
8
+
9
+ if (cleanup()) {
10
+ try {
11
+ fs.unlinkSync(__filename)
12
+ fs.rmdirSync(path.dirname(__filename))
13
+ } catch {
14
+ /* Self-removal failure must not affect profile cleanup. */
15
+ }
16
+ }
17
+
18
+ function cleanup() {
19
+ /* 1. Read and decode the profile without losing its original encoding. */
20
+ const link = fs.lstatSync(profile).isSymbolicLink()
21
+ const target = link ? fs.realpathSync(profile) : profile
22
+ const original = fs.readFileSync(target)
23
+ const stat = fs.statSync(target)
24
+
25
+ let encoding = \`utf8\`
26
+ let offset = 0
27
+ if (original.subarray(0, 3).equals(Buffer.from([239, 187, 191]))) {
28
+ encoding = \`utf8-bom\`
29
+ offset = 3
30
+ } else if (original.subarray(0, 2).equals(Buffer.from([255, 254]))) {
31
+ encoding = \`utf16le\`
32
+ offset = 2
33
+ } else if (original.subarray(0, 2).equals(Buffer.from([254, 255]))) {
34
+ encoding = \`utf16be\`
35
+ offset = 2
36
+ }
37
+
38
+ const decoderEncoding =
39
+ encoding === \`utf8-bom\`
40
+ ? \`utf8\`
41
+ : encoding === \`utf16le\`
42
+ ? \`utf-16le\`
43
+ : encoding === \`utf16be\`
44
+ ? \`utf-16be\`
45
+ : encoding
46
+ const decoder = new TextDecoder(decoderEncoding, { fatal: true })
47
+ const text = decoder.decode(original.subarray(offset))
48
+ const lines = []
49
+ const lineEnding = /\\r\\n|\\n|\\r/g
50
+ let lineStart = 0
51
+ let match
52
+
53
+ /* 2. Locate only complete, exact managed blocks. */
54
+ while ((match = lineEnding.exec(text))) {
55
+ lines.push({
56
+ content: text.slice(lineStart, match.index),
57
+ contentEnd: match.index,
58
+ end: match.index + match[0].length,
59
+ start: lineStart
60
+ })
61
+ lineStart = match.index + match[0].length
62
+ }
63
+ if (lineStart < text.length) {
64
+ lines.push({
65
+ content: text.slice(lineStart),
66
+ contentEnd: text.length,
67
+ end: text.length,
68
+ start: lineStart
69
+ })
70
+ }
71
+
72
+ const blocks = []
73
+ let opening
74
+ for (const line of lines) {
75
+ if (line.content === startMarker) {
76
+ if (opening) {
77
+ return false
78
+ }
79
+ opening = line
80
+ } else if (line.content === endMarker) {
81
+ if (!opening) {
82
+ return false
83
+ }
84
+ blocks.push({ start: opening, end: line })
85
+ opening = undefined
86
+ }
87
+ }
88
+ if (opening || blocks.length === 0) {
89
+ return false
90
+ }
91
+
92
+ /* 3. Remove managed blocks while preserving every other character. */
93
+ let updated = text
94
+ for (const block of blocks.toReversed()) {
95
+ const previous = lines.find(line => line.end === block.start.start)
96
+ const from = previous
97
+ ? previous.content.length === 0
98
+ ? previous.start
99
+ : previous.contentEnd
100
+ : block.start.start
101
+ const to =
102
+ block.end.end < text.length && previous && previous.content.length > 0
103
+ ? block.end.contentEnd
104
+ : block.end.end
105
+ updated = updated.slice(0, from) + updated.slice(to)
106
+ }
107
+
108
+ /* 4. Restore the original byte encoding and byte-order mark. */
109
+ let content = Buffer.from(updated, encoding.startsWith(\`utf16\`) ? \`utf16le\` : \`utf8\`)
110
+ if (encoding === \`utf16be\`) {
111
+ for (let index = 0; index < content.length; index += 2) {
112
+ const first = content[index]
113
+ content[index] = content[index + 1]
114
+ content[index + 1] = first
115
+ }
116
+ }
117
+ if (encoding === \`utf8-bom\`) {
118
+ content = Buffer.concat([Buffer.from([239, 187, 191]), content])
119
+ } else if (encoding === \`utf16le\`) {
120
+ content = Buffer.concat([Buffer.from([255, 254]), content])
121
+ } else if (encoding === \`utf16be\`) {
122
+ content = Buffer.concat([Buffer.from([254, 255]), content])
123
+ }
124
+
125
+ /* 5. Replace the resolved target only if it has not changed. */
126
+ if (!fs.readFileSync(target).equals(original)) {
127
+ return false
128
+ }
129
+ const temporary = path.join(
130
+ path.dirname(target),
131
+ \`.free-shellrc-\${crypto.randomBytes(8).toString(\`hex\`)}\`
132
+ )
133
+ try {
134
+ fs.writeFileSync(temporary, content, { flag: \`wx\`, mode: stat.mode })
135
+ fs.chmodSync(temporary, stat.mode)
136
+ if (!fs.readFileSync(target).equals(original)) {
137
+ throw new Error(\`Concurrent profile change\`)
138
+ }
139
+ fs.renameSync(temporary, target)
140
+ } finally {
141
+ try {
142
+ fs.unlinkSync(temporary)
143
+ } catch {
144
+ /* Cleanup failure must not hide the original result. */
145
+ }
146
+ }
147
+ return true
148
+ }
149
+ `;async function Se(e,t,n){let r=_(`sha256`).update(e).digest(`hex`).slice(0,24),i=S(Ce(),r),a=S(i,`cleanup-${t}-${_(`sha256`).update(n).digest(`hex`).slice(0,16)}.cjs`),o=Buffer.from(xe);await u(i,{mode:448,recursive:!0});try{if((await d(a)).equals(o))return a}catch(e){if(e.code!==`ENOENT`)throw e}return await g(a,o,{mode:384}),a}function Ce(){return y()===`win32`?process.env.LOCALAPPDATA??S(v(),`AppData`,`Local`):y()===`darwin`?S(v(),`Library`,`Application Support`):process.env.XDG_STATE_HOME??S(v(),`.local`,`state`)}function D(e,t,n){return Object.assign(Error(t,n),{code:e})}const O=Buffer.from([239,187,191]),k=Buffer.from([255,254]),A=Buffer.from([254,255]),we=Buffer.from([255,254,0,0]);function Te(e){let t=`utf8`,n=e;if(e.subarray(0,4).equals(we))throw j();e.subarray(0,3).equals(O)?(t=`utf8-bom`,n=e.subarray(3)):e.subarray(0,2).equals(k)?(t=`utf16le`,n=e.subarray(2)):e.subarray(0,2).equals(A)&&(t=`utf16be`,n=e.subarray(2));try{return{encoding:t,text:new TextDecoder(t===`utf8-bom`?`utf8`:t===`utf16le`?`utf-16le`:t===`utf16be`?`utf-16be`:t,{fatal:!0}).decode(n)}}catch(e){throw j(e)}}function j(e){return D(`ERR_UNSUPPORTED_ENCODING`,`The shell profile uses an unsupported or invalid encoding.`,e===void 0?void 0:{cause:e})}function Ee(e,t){if(t===`utf8`)return Buffer.from(e,`utf8`);if(t===`utf8-bom`)return Buffer.concat([O,Buffer.from(e,`utf8`)]);let n=Buffer.from(e,`utf16le`);if(t===`utf16le`)return Buffer.concat([k,n]);for(let e=0;e<n.length;e+=2){let t=n[e];n[e]=n[e+1],n[e+1]=t}return Buffer.concat([A,n])}async function De(e){let t=await Ae(e);try{let[e,n]=await Promise.all([d(t),h(t)]);return{bytes:e,mode:n.mode,targetPath:t}}catch(e){if(M(e))return{bytes:Buffer.alloc(0),mode:void 0,targetPath:t};throw e}}async function Oe(e,t){await u(x(e.targetPath),{recursive:!0});let n=S(x(e.targetPath),`.free-shellrc-${ne(8).toString(`hex`)}`);try{await g(n,t,{flag:`wx`,mode:e.mode}),e.mode!==void 0&&await o(n,e.mode),await je(e),await p(n,e.targetPath)}finally{await ke(n)}}async function ke(e){try{return await te(e),!0}catch{return!1}}async function Ae(e){try{if(!(await l(e)).isSymbolicLink())return e;try{return await f(e)}catch(t){if(!M(t))throw t;let n=await ee(e);return oe(n)?n:C(x(e),n)}}catch(t){if(M(t))return e;throw t}}async function je(e){try{if((await d(e.targetPath)).equals(e.bytes)&&e.mode!==void 0)return}catch(t){if(M(t)&&e.mode===void 0)return;if(!M(t))throw t}throw D(`ERR_CONCURRENT_PROFILE_CHANGE`,`The shell profile changed while it was being updated: ${e.targetPath}`)}function M(e){return e.code===`ENOENT`}let N;function Me(e){N=void 0;let t=Re(e),n=ze(t);if(`code`in n)return n;let r=Fe();if(!r)return{code:`UNSUPPORTED_SHELL`,message:`The current terminal is not using Bash, Zsh, Fish, Windows PowerShell, or PowerShell 7.`};let i=Pe(n.name);if(T(i))return{code:`SHELL_RESTART_REQUIRED`,message:`Restart the current shell before running this command again.`};N={entryPath:t,packageName:n.name,packagePath:n.path,restartPath:i,shell:r}}function Ne(){if(N)return N;throw D(`ERR_SHELLRC_GUARD_REQUIRED`,`Call shellrcGuard(import.meta.url) at the top of the application entry before using free-shellrc.`)}function Pe(e){let t=_(`sha256`).update(e).digest(`hex`).slice(0,24);return S(ie(),`.free-shellrc-${t}.restart`)}function Fe(){return(y()===`win32`?Le():Ie())??P(process.env.SHELL)}function Ie(){try{return P(n(`ps`,[`-p`,String(process.ppid),`-o`,`comm=`],{encoding:`utf8`}).trim())}catch{return}}function Le(){try{return P(n(`powershell.exe`,[`-NoLogo`,`-NoProfile`,`-NonInteractive`,`-Command`,`(Get-CimInstance Win32_Process -Filter 'ProcessId = ${process.ppid}').Name`],{encoding:`utf8`,windowsHide:!0}).trim())}catch{return}}function P(e){if(!e)return;let t=b(e).toLowerCase().replace(/\.exe$/,``);return t===`bash`||t===`zsh`||t===`fish`||t===`pwsh`?t:t===`powershell`?`powershell`:void 0}function Re(e){return C(e instanceof URL||e.startsWith(`file:`)?i(e):e)}function ze(e){let t=x(e),{root:n}=se(t);for(let r=t;;r=x(r)){let t=S(r,`package.json`);if(T(t)){let n=JSON.parse(ce(t,`utf8`));return typeof n.name==`string`&&n.name.length>0?{name:n.name,path:t}:F(e)}if(r===n)return F(e)}}function F(e){return{code:`PACKAGE_NOT_FOUND`,message:`Could not find a package.json with a name for the application entry: ${e}`}}const Be=le(t);async function Ve(e){if(e===`bash`)return S(I(),`.bashrc`);if(e===`zsh`)return S(L(`ZDOTDIR`,I()),`.zshrc`);if(e===`fish`)return S(L(`XDG_CONFIG_HOME`,S(I(),`.config`)),`fish`,`config.fish`);if(e===`powershell`&&y()!==`win32`)throw Ue(e);let t=e===`powershell`?`powershell.exe`:`pwsh`;try{let e=(await He(t)).trim();if(!e)throw Error(`The shell returned an empty profile path.`);return e}catch(t){throw D(`ERR_UNAVAILABLE_SHELL`,`The ${e} executable is unavailable or could not resolve its profile.`,{cause:t})}}function I(){return L(`HOME`,v())}function L(e,t){let n=process.env[e];return n?.length?n:t}function He(e){return Be(e,[`-NoLogo`,`-NoProfile`,`-NonInteractive`,`-Command`,`$PROFILE.CurrentUserAllHosts`],{encoding:`utf8`,windowsHide:!0}).then(e=>e.stdout)}function Ue(e){return D(`ERR_UNAVAILABLE_SHELL`,`The ${e} shell is unavailable on this operating system.`)}function We(e,t,n,r,i,a,o,s,c){let l=t.replaceAll(/\r\n|\n|\r/g,c),u=`# Please do not edit the comments \`${s.start}\`, \`${s.end}\` and the script between them, which probably makes ${s.packageName}'s feature broken.`,d=e===`fish`?Ke(l,n,r,i,a,o,s):e===`powershell`||e===`pwsh`?qe(l,n,r,i,a,o,s):Ge(l,n,r,i,a,o,s);return[s.start,u,...d,s.end,``].join(c)}function Ge(e,t,n,r,i,a,o){return[`if [ -f ${R(t)} ] && [ -f ${R(n)} ]; then`,` command rm -f -- ${R(i)} >/dev/null 2>&1 || true`,e,`else`,` command node ${R(a)} ${R(r)} ${R(o.start)} ${R(o.end)} >/dev/null 2>&1 || true`,`fi`]}function Ke(e,t,n,r,i,a,o){return[`if test -f ${R(t)}; and test -f ${R(n)}`,` command rm -f -- ${R(i)} >/dev/null 2>&1; or true`,e,`else`,` command node ${R(a)} ${R(r)} ${R(o.start)} ${R(o.end)} >/dev/null 2>&1; or true`,`end`]}function qe(e,t,n,r,i,a,o){return[`if ((Test-Path -LiteralPath ${z(t)} -PathType Leaf) -and (Test-Path -LiteralPath ${z(n)} -PathType Leaf)) {`,` Remove-Item -LiteralPath ${z(i)} -Force -ErrorAction SilentlyContinue`,e,`} else {`,` try {`,` & node ${z(a)} ${z(r)} ${z(o.start)} ${z(o.end)} *> $null`,` } catch {}`,`}`]}function R(e){return`'${e.replaceAll(`'`,`'"'"'`)}'`}function z(e){return`'${e.replaceAll(`'`,`''`)}'`}function Je(e){return{start:`# >>> _${e}_START >>>`,end:`# <<< _${e}_END <<<`,packageName:e}}function B(e){return/\r\n|\n|\r/.exec(e)?.[0]??re}function Ye(e,t,n){let r=V(e),i=Ze(r,t);if(i.length===0)return e.length===0?n:`${e}${B(e)}${n}`;let a=i.map((t,i)=>({end:i===0?t.end.end:$e(t,r,e.length),start:i===0?t.start.start:Qe(t,r),value:i===0?n:``})),o=e;for(let e of a.toReversed())o=o.slice(0,e.start)+e.value+o.slice(e.end);return o}function Xe(e,t){V(e).some(e=>e.content===t.start||e.content===t.end)&&H()}function V(e){let t=[],n=/\r\n|\n|\r/g,r=0,i;for(;i=n.exec(e);)t.push({content:e.slice(r,i.index),contentEnd:i.index,end:i.index+i[0].length,start:r}),r=i.index+i[0].length;return r<e.length&&t.push({content:e.slice(r),contentEnd:e.length,end:e.length,start:r}),t}function Ze(e,t){let n=[],r;for(let i of e)i.content===t.start?(r&&H(),r=i):i.content===t.end&&(r||H(),n.push({start:r,end:i}),r=void 0);return r&&H(),n}function Qe(e,t){let n=t.find(t=>t.end===e.start.start);return n?n.content===``?n.start:n.contentEnd:e.start.start}function $e(e,t,n){let r=e.end.end<n,i=t.find(t=>t.end===e.start.start)?.content!==``;return r&&i?e.end.contentEnd:e.end.end}function H(){throw D(`ERR_INVALID_MARKERS`,`The shell profile contains incomplete, reversed, or nested managed markers.`)}async function et(e,t){let n=Ne(),r=t??[n.shell],i=!1;for(let t of r){let r=e(t),a=await Ve(t),o=await De(a),s=Te(o.bytes),c=Je(n.packageName);Xe(r,c);let l=B(s.text),u=!s.text.split(/\r\n|\n|\r/).includes(c.start),d=await Se(n.packageName,t,a),ee=We(t,r,n.entryPath,n.packagePath,a,n.restartPath,d,c,l),f=Ee(Ye(s.text,c,ee),o.mode===void 0&&t===`powershell`?`utf8-bom`:s.encoding);f.equals(o.bytes)||(await Oe(o,f),u&&await tt(n.restartPath),i=!0)}return i}async function tt(e){try{await g(e,``,{flag:`wx`})}catch(e){if(e.code!==`EEXIST`)throw e}}var U=be(ve(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1);const nt=[{arch:`arm64`,name:`@bunode/cli-darwin-arm64`,os:`darwin`,target:`aarch64-apple-darwin`},{arch:`x64`,name:`@bunode/cli-darwin-x64`,os:`darwin`,target:`x86_64-apple-darwin`},{arch:`arm64`,libc:`glibc`,name:`@bunode/cli-linux-arm64-gnu`,os:`linux`,target:`aarch64-unknown-linux-gnu`},{arch:`arm64`,libc:`musl`,name:`@bunode/cli-linux-arm64-musl`,os:`linux`,target:`aarch64-unknown-linux-musl`},{arch:`x64`,libc:`glibc`,name:`@bunode/cli-linux-x64-gnu`,os:`linux`,target:`x86_64-unknown-linux-gnu`},{arch:`x64`,libc:`musl`,name:`@bunode/cli-linux-x64-musl`,os:`linux`,target:`x86_64-unknown-linux-musl`},{arch:`arm64`,name:`@bunode/cli-win32-arm64-msvc`,os:`win32`,target:`aarch64-pc-windows-msvc`},{arch:`x64`,name:`@bunode/cli-win32-x64-msvc`,os:`win32`,target:`x86_64-pc-windows-msvc`}];function rt(){let e=E===`linux`?at():void 0,t=nt.find(t=>t.os===E&&t.arch===ue&&t.libc===e);if(!t)throw Error(`Bunode does not provide a binary for ${E}-${ue}${ot(e)}.`);return t}function it(){let t=rt(),n=e(import.meta.url);try{return x(n.resolve(`${t.name}/package.json`))}catch(e){let n=C(import.meta.dirname,`../../..`),r=S(n,`target/debug`),i=E===`win32`?`.exe`:``;if(T(S(n,`.git`))&&T(S(r,`bunode${i}`))&&T(S(r,`node${i}`)))return r;throw Error(`The optional package ${t.name} is missing. Reinstall @bunode/cli for this platform.`,{cause:e})}}function at(){let{header:e}=de.getReport();return e.glibcVersionRuntime?`glibc`:`musl`}function ot(e){return e?`-${e}`:``}const W=E===`win32`;async function st(e,t=v(),n=it()){let r=G(t),i=W?`.exe`:``;return await u(r.binDirectory,{recursive:!0}),await ut(S(n,`bunode${i}`),r.bunodeBinary),await ut(S(n,`node${i}`),r.nodeBinary),W?(await K(S(r.binDirectory,`bunode.cmd`),ft(e,r.bunodeBinary)),await K(S(r.binDirectory,`bunode.ps1`),pt(e,r.bunodeBinary))):await K(S(r.binDirectory,`bunode`),dt(e,r.bunodeBinary)),r}function G(e=v()){let t=S(e,`.bunode`),n=W?`.exe`:``;return{binDirectory:S(t,`bin`),bunodeBinary:S(t,`bunode${n}`),nodeBinary:S(t,`node${n}`)}}function ct(e,t){if(e===`fish`)return`fish_add_path --prepend --move ${mt(t)}`;if(e===`powershell`||e===`pwsh`){let e=W?`Path`:`PATH`;return`$env:${e} = ${Y(`${t}${ae}`)} + $env:${e}`}return`export PATH=${J(t)}:"$PATH"`}async function lt(e){try{return(await h(e)).isFile()?(await a(e,W?w.F_OK:w.X_OK),!0):!1}catch{return!1}}async function ut(e,t){let n=S(x(t),`.${b(t)}.${process.pid}.${Math.random().toString(16).slice(2)}`);try{try{await c(e,n)}catch(t){if(!ht(t))throw t;await s(e,n)}W||await o(n,493),await q(n,t)}finally{await m(n,{force:!0})}}async function K(e,t){try{if(await d(e,`utf8`)===t)return}catch(e){if(e.code!==`ENOENT`)throw e}let n=`${e}.${process.pid}.${Math.random().toString(16).slice(2)}`;try{await g(n,t,{mode:493}),await q(n,e)}finally{await m(n,{force:!0})}}async function q(e,t){try{await p(e,t)}catch(n){if(!W||!gt(n))throw n;await m(t,{force:!0}),await p(e,t)}}function dt(e,t){let n=S(x(t),`.wrapper-ready-`);return`#!/bin/sh
150
+ if [ -f ${J(e)} ] && command -v node >/dev/null 2>&1; then
151
+ marker=${J(n)}$$
152
+ rm -f "$marker"
153
+ BUNODE_WRAPPER_MARKER="$marker" node ${J(e)} "$@"
154
+ status=$?
155
+ if [ "$status" -eq 0 ] || [ -f "$marker" ]; then
156
+ rm -f "$marker"
157
+ exit "$status"
158
+ fi
159
+ fi
160
+ printf '%s\n' 'bunode: JavaScript wrapper unavailable; using installed native CLI.' >&2
161
+ exec ${J(t)} "$@"
162
+ `}function ft(e,t){return`@echo off\r
163
+ setlocal EnableDelayedExpansion\r
164
+ if exist ${X(e)} (\r
165
+ where node >nul 2>nul\r
166
+ if not errorlevel 1 (\r
167
+ set "BUNODE_WRAPPER_MARKER=${X(S(x(t),`.wrapper-ready-%RANDOM%-%RANDOM%`)).slice(1,-1)}"\r
168
+ del /q "!BUNODE_WRAPPER_MARKER!" >nul 2>nul\r
169
+ node ${X(e)} %*\r
170
+ set "BUNODE_WRAPPER_STATUS=!errorlevel!"\r
171
+ if "!BUNODE_WRAPPER_STATUS!"=="0" (\r
172
+ del /q "!BUNODE_WRAPPER_MARKER!" >nul 2>nul\r
173
+ exit /b 0\r
174
+ )\r
175
+ if exist "!BUNODE_WRAPPER_MARKER!" (\r
176
+ del /q "!BUNODE_WRAPPER_MARKER!" >nul 2>nul\r
177
+ exit /b !BUNODE_WRAPPER_STATUS!\r
178
+ )\r
179
+ )\r
180
+ )\r
181
+ >&2 echo bunode: JavaScript wrapper unavailable; using installed native CLI.\r
182
+ ${X(t)} %*\r
183
+ exit /b %errorlevel%\r
184
+ `}function pt(e,t){return`if ((Test-Path -LiteralPath ${Y(e)}) -and (Get-Command node -ErrorAction SilentlyContinue)) {
185
+ $marker = Join-Path ${Y(x(t))} ('.wrapper-ready-' + [guid]::NewGuid().ToString('N'))
186
+ $env:BUNODE_WRAPPER_MARKER = $marker
187
+ & node ${Y(e)} @args
188
+ $status = $LASTEXITCODE
189
+ Remove-Item Env:BUNODE_WRAPPER_MARKER -ErrorAction SilentlyContinue
190
+ if (($status -eq 0) -or (Test-Path -LiteralPath $marker)) {
191
+ Remove-Item -LiteralPath $marker -Force -ErrorAction SilentlyContinue
192
+ exit $status
193
+ }
194
+ }
195
+ [Console]::Error.WriteLine('bunode: JavaScript wrapper unavailable; using installed native CLI.')
196
+ & ${Y(t)} @args
197
+ exit $LASTEXITCODE
198
+ `}function J(e){return`'${e.replaceAll(`'`,`'"'"'`)}'`}function mt(e){return`'${e.replaceAll(`\\`,String.raw`\\`).replaceAll(`'`,String.raw`\'`)}'`}function Y(e){return`'${e.replaceAll(`'`,`''`)}'`}function X(e){return`"${e.replaceAll(`"`,`""`)}"`}function ht(e){let{code:t}=e;return t===`EXDEV`||t===`EPERM`||t===`EACCES`||t===`ENOTSUP`}function gt(e){let{code:t}=e;return t===`EEXIST`||t===`EPERM`||t===`EACCES`}async function _t(e){let t=i(e),n=Me(e),r,a;try{let{binDirectory:e,bunodeBinary:n}=await st(t);r=e,a=n}catch(e){Q(`JavaScript wrapper failed: ${$(e)}`),await vt();return}if(n){Q(n.message),await Z(a);return}try{await et(e=>ct(e,r))&&process.stderr.write(`${U.default.green(`Bunode is ready.`)} Restart this shell to use ${r}.\n`)}catch(e){Q(`JavaScript wrapper failed: ${$(e)}`),await vt();return}await Z(a)}async function vt(){let{bunodeBinary:e}=G();if(!await lt(e)){process.stderr.write(`${U.default.red(`Bunode could not find an installed native CLI.`)}\n`),process.exitCode=1;return}Q(`Using the previously installed native Bunode CLI.`),await Z(e)}function Z(e){return new Promise((t,n)=>{let i=r(e,process.argv.slice(2),{stdio:`inherit`});i.on(`error`,n),i.on(`exit`,(e,n)=>{if(n){process.kill(process.pid,n);return}process.exitCode=e??1,t()})})}function Q(e){process.stderr.write(`${U.default.yellow(`warning:`)} ${e}\n`)}function $(e){return e instanceof Error?e.message:String(e)}export{_t as runCli};
package/package.json CHANGED
@@ -1,18 +1,41 @@
1
1
  {
2
2
  "name": "@bunode/cli",
3
- "version": "0.0.0-alpha.0",
3
+ "version": "0.0.0",
4
4
  "description": "Node.js-compatible registry tooling for Bunode.",
5
+ "homepage": "https://github.com/liangmiQwQ/bunode#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/liangmiQwQ/bunode/issues"
8
+ },
9
+ "license": "MIT",
10
+ "author": "Liang Mi <hi@liangmi.dev>",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/liangmiQwQ/bunode.git"
14
+ },
5
15
  "bin": {
6
- "bunode-registry": "./dist/cli.mjs"
16
+ "bunode": "bin/bunode.mjs"
7
17
  },
8
18
  "files": [
9
- "dist"
19
+ "dist",
20
+ "bin"
10
21
  ],
11
22
  "type": "module",
12
- "scripts": {
13
- "build": "vp pack",
14
- "check": "vp check",
15
- "format": "vp format",
16
- "lint": "vp lint"
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "catalog:",
28
+ "free-shellrc": "catalog:",
29
+ "picocolors": "catalog:"
30
+ },
31
+ "optionalDependencies": {
32
+ "@bunode/cli-darwin-arm64": "0.0.0",
33
+ "@bunode/cli-darwin-x64": "0.0.0",
34
+ "@bunode/cli-linux-arm64-gnu": "0.0.0",
35
+ "@bunode/cli-linux-arm64-musl": "0.0.0",
36
+ "@bunode/cli-linux-x64-gnu": "0.0.0",
37
+ "@bunode/cli-linux-x64-musl": "0.0.0",
38
+ "@bunode/cli-win32-arm64-msvc": "0.0.0",
39
+ "@bunode/cli-win32-x64-msvc": "0.0.0"
17
40
  }
18
- }
41
+ }