thinkncollab-shell 2.0.0-beta.1 → 2.0.0-beta.1.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.
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* PROPRIETARY INTELLECTUAL PROPERTY & TRADE SECRETS.
|
|
5
5
|
* UNAUTHORIZED REVERSE ENGINEERING, DECOMPILATION, OR RE-DISTRIBUTION IS STRICTLY PROHIBITED.
|
|
6
6
|
*/
|
|
7
|
-
"use strict";const fs=require("fs"),os=require("os"),path=require("path"),crypto=require("crypto"),{spawnSync}=require("child_process"),TNC_DIR=path.join(os.homedir(),".tnc"),BUNDLE_VERSION="0.2.2",DEFAULT_BASE_URL=process.env.TNC_DOCK_BUNDLE_URL||"https://thinkncollab.com/downloads/dock/0.2.2",WSL_DISTRO="tnc-dock",linuxArch=(n=process.arch)=>({arm64:"aarch64",x64:"x86_64"}[n]);function setupError(n){const t=new Error(n);return t.setup=!0,t}function sha256File(n){const t=crypto.createHash("sha256"),e=fs.openSync(n,"r"),r=Buffer.alloc(1<<20);let i;for(;(i=fs.readSync(e,r,0,r.length,null))>0;)t.update(r.subarray(0,i));return fs.closeSync(e),t.digest("hex")}const OPTIONAL_FILES=/^(tnc-busybox-linux-|tnc-menubar-)/;function wantedFiles(n=process.platform,t=process.arch){const e=linuxArch(t);if(!e)throw setupError(`unsupported CPU architecture ${t}`);if("darwin"===n)return[`tnc-dock-vm-${e}.tar.gz`,"tnc-vz-darwin-universal","tnc-menubar-darwin-universal"];if("win32"===n)return[`tnc-dock-wsl-${e}.tar.gz`];if("linux"===n)return[`tnc-shim-linux-${e}`,`crun-linux-${e}`,`tnc-busybox-linux-${e}`];throw setupError(`unsupported platform ${n}`)}async function download(n,t){const e=await fetch(n,{redirect:"follow"});if(!e.ok)throw setupError(`download failed: ${n} (HTTP ${e.status})`);fs.mkdirSync(path.dirname(t),{recursive:!0}),fs.writeFileSync(`${t}.part`,Buffer.from(await e.arrayBuffer())),fs.renameSync(`${t}.part`,t)}async function fetchBundle({from:n,baseUrl:t=DEFAULT_BASE_URL,log:e}){let r,i;if(n)i=path.resolve(n),r=JSON.parse(fs.readFileSync(path.join(i,"manifest.json"),"utf8"));else{
|
|
7
|
+
"use strict";const fs=require("fs"),os=require("os"),path=require("path"),crypto=require("crypto"),{spawnSync}=require("child_process"),TNC_DIR=path.join(os.homedir(),".tnc"),BUNDLE_VERSION="0.2.2",DEFAULT_BASE_URL=process.env.TNC_DOCK_BUNDLE_URL||"https://thinkncollab.com/downloads/dock/0.2.2",WSL_DISTRO="tnc-dock",linuxArch=(n=process.arch)=>({arm64:"aarch64",x64:"x86_64"}[n]);function setupError(n){const t=new Error(n);return t.setup=!0,t}function sha256File(n){const t=crypto.createHash("sha256"),e=fs.openSync(n,"r"),r=Buffer.alloc(1<<20);let i;for(;(i=fs.readSync(e,r,0,r.length,null))>0;)t.update(r.subarray(0,i));return fs.closeSync(e),t.digest("hex")}const OPTIONAL_FILES=/^(tnc-busybox-linux-|tnc-menubar-)/;function wantedFiles(n=process.platform,t=process.arch){const e=linuxArch(t);if(!e)throw setupError(`unsupported CPU architecture ${t}`);if("darwin"===n)return[`tnc-dock-vm-${e}.tar.gz`,"tnc-vz-darwin-universal","tnc-menubar-darwin-universal"];if("win32"===n)return[`tnc-dock-wsl-${e}.tar.gz`];if("linux"===n)return[`tnc-shim-linux-${e}`,`crun-linux-${e}`,`tnc-busybox-linux-${e}`];throw setupError(`unsupported platform ${n}`)}async function download(n,t){const e=await fetch(n,{redirect:"follow"});if(!e.ok)throw setupError(`download failed: ${n} (HTTP ${e.status})`);fs.mkdirSync(path.dirname(t),{recursive:!0}),fs.writeFileSync(`${t}.part`,Buffer.from(await e.arrayBuffer())),fs.renameSync(`${t}.part`,t)}async function fetchBundle({from:n,baseUrl:t=DEFAULT_BASE_URL,log:e}){let r,i;if(n)i=path.resolve(n),r=JSON.parse(fs.readFileSync(path.join(i,"manifest.json"),"utf8"));else{let n=await fetch(`${t}/manifest.json`,{redirect:"follow"});if(!n.ok){const e="https://thinkncollab.com/downloads/dock",i=await fetch(`${e}/manifest.json`,{redirect:"follow"});i.ok&&(r=await i.json(),t=`${e}/${r.version}`,n=i)}if(!n.ok)throw setupError(`cannot fetch bundle manifest from ${t} (HTTP ${n.status})`);r||(r=await n.json()),i=path.join(TNC_DIR,"cache","bundles",r.version)}const s={};for(const o of wantedFiles()){const c=r.files[o];if(!c&&OPTIONAL_FILES.test(o)){e(`bundle ${r.version} has no ${o}; ${o.startsWith("tnc-menubar")?"the menu bar app":"cp"} needs a newer bundle`);continue}if(!c)throw setupError(`bundle ${r.version} has no ${o}`);const a=path.join(i,o);if(n||fs.existsSync(a)&&sha256File(a)===c.sha256||(e(`downloading ${o} (${(c.size/1024/1024).toFixed(1)} MB)`),await download(`${t}/${o}`,a)),!fs.existsSync(a))throw setupError(`missing ${a}`);if(sha256File(a)!==c.sha256)throw setupError(`sha256 mismatch for ${o}; refusing to install`);s[o]=a}return{manifest:r,files:s}}function run(n,t,e={}){const r=spawnSync(n,t,{encoding:"utf8",...e});return{code:r.status,out:`${r.stdout||""}${r.stderr||""}`.replace(/\0/g,"")}}function installDarwin(n,t){const e=linuxArch(),r=path.join(TNC_DIR,"kernel"),i=path.join(TNC_DIR,"bin");fs.mkdirSync(r,{recursive:!0}),fs.mkdirSync(i,{recursive:!0}),run(path.join(i,"tnc-vz"),["stop"]);for(const n of["vmlinuz","initramfs.img"]){const t=path.join(r,n);fs.existsSync(t)&&!fs.existsSync(`${t}.pre-bundle`)&&fs.copyFileSync(t,`${t}.pre-bundle`)}const s=run("tar",["-xzf",n[`tnc-dock-vm-${e}.tar.gz`],"-C",r]);if(0!==s.code)throw setupError(`cannot unpack VM image: ${s.out}`);const o=path.join(i,"tnc-vz");if(fs.existsSync(o)&&!fs.existsSync(`${o}.pre-bundle`)&&fs.copyFileSync(o,`${o}.pre-bundle`),fs.copyFileSync(n["tnc-vz-darwin-universal"],`${o}.new`),fs.chmodSync(`${o}.new`,493),fs.renameSync(`${o}.new`,o),t(`MicroVM image (${e}) and tnc-vz installed`),n["tnc-menubar-darwin-universal"]){const e=path.join(i,"tnc-menubar");fs.copyFileSync(n["tnc-menubar-darwin-universal"],`${e}.new`),fs.chmodSync(`${e}.new`,493),fs.renameSync(`${e}.new`,e),t("menu bar app installed (open it with: thinknsh dock app)")}}function wslDistros(){const n=run("wsl.exe",["--list","--quiet"]);return 0===n.code?n.out.split(/\r?\n/).map(n=>n.trim()).filter(Boolean):null}function installWindows(n,t,{force:e=!1}={}){const r=linuxArch();if(0!==run("wsl.exe",["--status"]).code)throw setupError("WSL is not installed. Run in an admin PowerShell: wsl --install --no-distribution, reboot, then run thinknsh dock setup again");const i=wslDistros()||[],s=n[`tnc-dock-wsl-${r}.tar.gz`];if(i.includes("tnc-dock")&&!e){const n=run("wsl.exe",["-d","tnc-dock","-u","root","--","tar","-xzf","-","-C","/","./usr/bin/tnc-shim","./usr/bin/crun","./usr/local/bin/tnc-wsl-init","./etc/wsl.conf","./bin/busybox.static"],{input:fs.readFileSync(s)});if(0!==n.code)throw setupError(`cannot upgrade WSL distro: ${n.out}`);return run("wsl.exe",["--terminate","tnc-dock"]),void t("WSL distro tnc-dock upgraded in place (layers and volumes kept)")}i.includes("tnc-dock")&&run("wsl.exe",["--unregister","tnc-dock"]);const o=path.join(TNC_DIR,"wsl","tnc-dock");fs.mkdirSync(o,{recursive:!0});const c=run("wsl.exe",["--import","tnc-dock",o,s,"--version","2"]);if(0!==c.code)throw setupError(`wsl --import failed: ${c.out.trim()}`);t(`WSL2 distro tnc-dock created in ${o}`)}function installLinux(n,t){const e=linuxArch(),r=path.join(TNC_DIR,"bin");fs.mkdirSync(r,{recursive:!0});for(const t of[`tnc-shim-linux-${e}`,`crun-linux-${e}`,`tnc-busybox-linux-${e}`]){const e=t;n[t]&&(fs.copyFileSync(n[t],path.join(r,`${e}.new`)),fs.chmodSync(path.join(r,`${e}.new`),493),fs.renameSync(path.join(r,`${e}.new`),path.join(r,e)))}t(`tnc-shim, crun and busybox installed in ${r}${0===process.getuid?.()?"":" (dock must run as root on Linux)"}`)}async function prefetchBuildKit(n){if("0"===process.env.TNC_DOCK_BUILDKIT)return;const{installBuildKit:t,buildKitDir:e,buildKitInstalled:r,VERSION:i}=require("../build/buildkit"),s={arm64:"arm64",x64:"amd64"}[process.arch];if(!s)return;const o=e(process.env.TNC_DOCK_HOME||path.join(TNC_DIR,"dock"),s);if(r(o))return n(`BuildKit ${i} already installed`);try{n(`downloading BuildKit ${i} (linux/${s})`),await t(o,s),n(`BuildKit ${i} installed in ${o}`)}catch(t){n(`warning: ${t.message}; it will be downloaded on the first BuildKit build`)}}async function setup({from:n,baseUrl:t,force:e=!1,log:r=()=>{}}={}){const{manifest:i,files:s}=await fetchBundle({from:n,baseUrl:t,log:r});return"darwin"===process.platform?installDarwin(s,r):"win32"===process.platform?installWindows(s,r,{force:e}):installLinux(s,r),await prefetchBuildKit(r),fs.mkdirSync(path.join(TNC_DIR,"dock"),{recursive:!0}),fs.writeFileSync(path.join(TNC_DIR,"dock","runtime.json"),JSON.stringify({version:i.version,platform:process.platform,arch:process.arch,installedAt:(new Date).toISOString()},null,2)),i.version}module.exports={setup,prefetchBuildKit,wantedFiles,fetchBundle,linuxArch,WSL_DISTRO:"tnc-dock",sha256File,BUNDLE_VERSION:"0.2.2"};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "thinkncollab-shell",
|
|
3
|
-
"version": "2.0.0-beta.1",
|
|
3
|
+
"version": "2.0.0-beta.1.1",
|
|
4
4
|
"description": "Lightweight MicroVM Sandbox & Zero-Daemon Dev Runner: Fast MicroVM Containers, Native Microservices, Live Database Snapshots, and End-to-End Encrypted State Sync",
|
|
5
5
|
"main": "dist/src/core/shell.js",
|
|
6
6
|
"bin": {
|