From a84bbaa666bb5724491fa47b4419285861e51fdd Mon Sep 17 00:00:00 2001 From: bracesproul Date: Tue, 23 Jul 2024 19:43:18 -0700 Subject: [PATCH] cr --- libs/langchain-scripts/src/build_v2.ts | 30 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/libs/langchain-scripts/src/build_v2.ts b/libs/langchain-scripts/src/build_v2.ts index db0e496b5a0b..37ed8994bdf4 100644 --- a/libs/langchain-scripts/src/build_v2.ts +++ b/libs/langchain-scripts/src/build_v2.ts @@ -4,8 +4,8 @@ import fs from "node:fs"; import { Command } from "commander"; import { rollup } from "@rollup/wasm-node"; import path from "node:path"; -import { rm } from "node:fs/promises"; import { ExportsMapValue, ImportData, LangChainConfig } from "./types.js"; +import { rimraf } from "rimraf"; async function asyncSpawn(command: string, args: string[]) { return new Promise((resolve, reject) => { @@ -27,6 +27,16 @@ async function asyncSpawn(command: string, args: string[]) { }); } +async function rmRf(dir: string) { + // Check if the directory exists + const exists = fs.existsSync(dir); + if (!exists) { + return; + } + // Remove the directory + await fs.promises.rm(dir, { recursive: true }); +} + const NEWLINE = ` `; @@ -560,6 +570,10 @@ export async function moveAndRename({ dest: string; abs: (p: string) => string; }) { + if (!fs.existsSync(abs(source))) { + return; + } + try { for (const file of await fs.promises.readdir(abs(source), { withFileTypes: true, @@ -625,11 +639,11 @@ export async function buildWithTSup() { // Clean & generate build files if (pre && shouldGenMaps) { await Promise.all([ - rm("dist", { recursive: true, force: true }).catch((e) => { + rimraf("dist").catch((e) => { console.error("Error removing dist (pre && shouldGenMaps)"); throw e; }), - rm(".turbo", { recursive: true, force: true }).catch((e) => { + rimraf(".turbo").catch((e) => { console.error("Error removing .turbo (pre && shouldGenMaps)"); throw e; }), @@ -640,11 +654,11 @@ export async function buildWithTSup() { ]); } else if (pre && !shouldGenMaps) { await Promise.all([ - rm("dist", { recursive: true, force: true }).catch((e) => { + rimraf("dist").catch((e) => { console.error("Error removing dist (pre && !shouldGenMaps)"); throw e; }), - rm(".turbo", { recursive: true, force: true }).catch((e) => { + rimraf(".turbo").catch((e) => { console.error("Error removing .turbo (pre && !shouldGenMaps)"); throw e; }), @@ -665,15 +679,15 @@ export async function buildWithTSup() { // move CJS to dist await Promise.all([ updatePackageJson(config), - rm("dist-cjs", { recursive: true, force: true }).catch((e) => { + rimraf("dist-cjs").catch((e) => { console.error("Error removing dist-cjs"); throw e; }), - rm("dist/tests", { recursive: true, force: true }).catch((e) => { + rimraf("dist/tests").catch((e) => { console.error("Error removing dist/tests"); throw e; }), - rm("dist/**/tests", { recursive: true, force: true }).catch((e) => { + rimraf("dist/**/tests").catch((e) => { console.error("Error removing dist/**/tests"); throw e; }),