35 lines
2.4 KiB
JavaScript
35 lines
2.4 KiB
JavaScript
'use strict';
|
|
// Installs outside the repository. No package.json or lockfile in this checkout is changed.
|
|
const fs=require('node:fs/promises');
|
|
const sync=require('node:fs');
|
|
const path=require('node:path');
|
|
const {spawn}=require('node:child_process');
|
|
const {installedRuntime,VERSION,PACKAGE}=require('../src/modules/assistant/dsh-runtime.cjs');
|
|
|
|
// Patches the official runtime's exact vulnerable transitive pins without changing DSH.
|
|
const OVERRIDES=Object.freeze({zod:'4.6.7',undici:'8.12.2',fflate:'0.8.3','@modelcontextprotocol/client':'2.3.0'});
|
|
|
|
async function main(args=process.argv.slice(2)) {
|
|
if(args.some(arg=>arg!=='--check')||args.length>1)throw new Error('Unsupported option. Usage: node scripts/install-dsh-runtime.cjs [--check]');
|
|
if(!process.env.LOCALAPPDATA)throw new Error('LOCALAPPDATA is required for the isolated Windows runtime installation.');
|
|
const prefix=path.join(process.env.LOCALAPPDATA,'OrderNotificationAutomationRuntimes','dsh-'+VERSION);
|
|
if(!args.includes('--check')) {
|
|
// Run the npm shipped beside this Node binary, not a PATH-provided command or shell string.
|
|
const npmCli=path.join(path.dirname(process.execPath),'node_modules','npm','bin','npm-cli.js');
|
|
sync.accessSync(npmCli);
|
|
await fs.mkdir(prefix,{recursive:true});
|
|
await fs.writeFile(path.join(prefix,'package.json'),JSON.stringify({name:'order-assistant-dsh-runtime',private:true,dependencies:{[PACKAGE]:VERSION},overrides:OVERRIDES},null,2)+'\n');
|
|
const env={...process.env};delete env.NODE_OPTIONS;delete env.NODE_PATH;
|
|
await new Promise((resolve,reject)=>{
|
|
const child=spawn(process.execPath,[npmCli,'install','--prefix',prefix,'--save-exact','--ignore-scripts','--omit=dev','--no-audit','--no-fund',PACKAGE+'@'+VERSION],{cwd:prefix,env,shell:false,windowsHide:true,stdio:['ignore','inherit','inherit']});
|
|
child.once('error',reject);
|
|
child.once('close',code=>code===0?resolve():reject(new Error('Pinned DSH installation failed (exit '+code+').')));
|
|
});
|
|
}
|
|
const runtimePath=installedRuntime();
|
|
if(!runtimePath)throw new Error('Pinned official DSH '+VERSION+' is not installed or does not pass package/entry validation.');
|
|
process.stdout.write(JSON.stringify({available:true,package:PACKAGE,version:VERSION,runtimePath})+'\n');
|
|
}
|
|
if(require.main===module)main().catch(error=>{process.stderr.write(error.message+'\n');process.exitCode=1;});
|
|
module.exports={main,OVERRIDES};
|