From 5ab79b778fd540454a727486849580ea6efe1789 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 11 Mar 2024 08:27:58 -0700 Subject: [PATCH 1/2] feat: delete tmp dir after proposal build --- packages/boot/tools/supports.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index cbb2198d7f3..3337cbfd09a 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -157,23 +157,21 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => { const scriptPath = await importSpec(builderPath); - // XXX use '@agoric/inter-protocol'? const out = await runPackageScript(tmpDir, scriptPath, scriptEnv); const built = parseProposalParts(out.toString()); - const loadAndRmPkgFile = async fileName => { - const filePath = join(tmpDir, fileName); - const content = await fs.readFile(filePath, 'utf8'); - await fs.rm(filePath); - return content; - }; + const loadPkgFile = fileName => fs.readFile(join(tmpDir, fileName), 'utf8'); const evalsP = Promise.all( built.evals.map(async ({ permit, script }) => { const [permits, code] = await Promise.all([ - loadAndRmPkgFile(permit), - loadAndRmPkgFile(script), + loadPkgFile(permit), + loadPkgFile(script), ]); + // Fire and forget. There's a chance the Node process could terminate + // before the deletion completes. This is a minor inconvenience to clean + // up manually and not worth slowing down the test execution to prevent. + void fsAmbientPromises.rm(tmpDir, { recursive: true, force: true }); return { json_permits: permits, js_code: code } as CoreEvalSDKType; }), ); From 5520375241f09f6342bd0898c4e96f740562335d Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Mon, 11 Mar 2024 08:36:22 -0700 Subject: [PATCH 2/2] refactor: fewer bindings in proposal extractor --- packages/boot/tools/supports.ts | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/packages/boot/tools/supports.ts b/packages/boot/tools/supports.ts index 3337cbfd09a..f85d62de827 100644 --- a/packages/boot/tools/supports.ts +++ b/packages/boot/tools/supports.ts @@ -110,9 +110,13 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => { const importSpec = spec => importMetaResolve(spec, import.meta.url).then(u => new URL(u).pathname); - const runPackageScript = async (outputDir, scriptPath, env) => { + const runPackageScript = ( + outputDir: string, + scriptPath: string, + env: NodeJS.ProcessEnv, + ) => { console.info('running package script:', scriptPath); - const out = await childProcess.execFileSync('yarn', ['bin', 'agoric'], { + const out = childProcess.execFileSync('yarn', ['bin', 'agoric'], { cwd: outputDir, env, }); @@ -150,15 +154,17 @@ export const makeProposalExtractor = ({ childProcess, fs }: Powers) => { }; const buildAndExtract = async (builderPath: string) => { - const scriptEnv = Object.assign(Object.create(process.env)); - - const pkgPath = getPkgPath('builders'); - const tmpDir = await fsAmbientPromises.mkdtemp(join(pkgPath, 'proposal-')); - - const scriptPath = await importSpec(builderPath); + const tmpDir = await fsAmbientPromises.mkdtemp( + join(getPkgPath('builders'), 'proposal-'), + ); - const out = await runPackageScript(tmpDir, scriptPath, scriptEnv); - const built = parseProposalParts(out.toString()); + const built = parseProposalParts( + runPackageScript( + tmpDir, + await importSpec(builderPath), + process.env, + ).toString(), + ); const loadPkgFile = fileName => fs.readFile(join(tmpDir, fileName), 'utf8');