Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts[patch]: Fix reading original entrypoint file #6591

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading