Skip to content

Commit

Permalink
cr
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jul 24, 2024
1 parent 97f9c34 commit a84bbaa
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions libs/langchain-scripts/src/build_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Check failure on line 8 in libs/langchain-scripts/src/build_v2.ts

View workflow job for this annotation

GitHub Actions / Check linting

`rimraf` import should occur before import of `./types.js`

async function asyncSpawn(command: string, args: string[]) {
return new Promise<void>((resolve, reject) => {
Expand All @@ -27,6 +27,16 @@ async function asyncSpawn(command: string, args: string[]) {
});
}

async function rmRf(dir: string) {

Check warning on line 30 in libs/langchain-scripts/src/build_v2.ts

View workflow job for this annotation

GitHub Actions / Check linting

'rmRf' is defined but never used
// 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 = `
`;

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}),
Expand All @@ -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;
}),
Expand All @@ -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;
}),
Expand Down

0 comments on commit a84bbaa

Please sign in to comment.