Skip to content

Commit

Permalink
scripts[patch]: Fix reading original entrypoint file (#6591)
Browse files Browse the repository at this point in the history
* scripts[patch]: Fix reading original entrypoint file

* chore: lint files
  • Loading branch information
bracesproul authored Aug 21, 2024
1 parent 4d419c7 commit 4225e82
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions libs/langchain-scripts/src/build_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,13 @@ function listEntrypoints(packageJson: Record<string, any>) {
const checkAllowSideEffects = async (entrypoint: string): Promise<boolean> => {
let entrypointContent: Buffer | undefined;
try {
entrypointContent = await fs.promises.readFile(
`./dist/${entrypoint.replace(/^\.\//, "")}`
);
entrypointContent = await fs.promises.readFile(`./dist/${entrypoint}.js`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (e: any) {
if (e.message.includes("ENOENT")) {
// Entrypoint is likely via an `index.js` file, retry with `index.js` appended to path
entrypointContent = await fs.promises.readFile(
`./dist/${entrypoint
.replace(/^\.\//, "")
.replace(/\.js$/, "")}/index.js`
`./dist/${entrypoint}/index.js`
);
}
}
Expand Down Expand Up @@ -542,7 +538,12 @@ async function checkTreeShaking(config: LangChainConfig) {

let hasUnexpectedSideEffects = sideEffects.length > 0;
if (hasUnexpectedSideEffects) {
hasUnexpectedSideEffects = !(await checkAllowSideEffects(entrypoint));
// Map the entrypoint back to the actual file entrypoint using the LangChainConfig file
const actualEntrypoint =
config.entrypoints[entrypoint.replace(/^\.\/|\.js$/g, "")];
hasUnexpectedSideEffects = !(await checkAllowSideEffects(
actualEntrypoint
));
}
reportMap.set(entrypoint, {
log: sideEffects,
Expand Down

0 comments on commit 4225e82

Please sign in to comment.