Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions test-exports-cjs/entrypoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const package = require("langchain/package.json");

Object.keys(package.exports).forEach((key) => {
if (key === "./package.json") return;

if (key === ".") {
require("langchain");
} else {
require(`langchain/${key.slice(2)}`);
// If this fails probably means that a ESM-only dependency is being imported
}
});
5 changes: 4 additions & 1 deletion test-exports-cjs/import.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
async function test() {
const { default: assert } = await import("assert");
const { OpenAI } = await import("langchain");
const { loadPrompt } = await import("langchain/prompts");
const { LLMChain } = await import("langchain/chains");
const { loadPrompt, ChatPromptTemplate } = await import("langchain/prompts");
const { HNSWLib } = await import("langchain/vectorstores");
const { OpenAIEmbeddings } = await import("langchain/embeddings");
const { InMemoryDocstore, Document } = await import("langchain/docstore");
const { CSVLoader } = await import("langchain/document_loaders");

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
5 changes: 4 additions & 1 deletion test-exports-cjs/index.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import assert from "assert";
import { OpenAI } from "langchain";
import { loadPrompt } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
import { HNSWLib } from "langchain/vectorstores";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { InMemoryDocstore, Document } from "langchain/docstore";
import { CSVLoader } from "langchain/document_loaders";

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
5 changes: 4 additions & 1 deletion test-exports-cjs/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from "assert";
import { OpenAI } from "langchain";
import { loadPrompt } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
import { HNSWLib } from "langchain/vectorstores";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { InMemoryDocstore, Document } from "langchain/docstore";
Expand All @@ -9,7 +10,9 @@ import { CSVLoader } from "langchain/document_loaders";
async function test() {
// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
3 changes: 2 additions & 1 deletion test-exports-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"description": "CJS Tests for the things exported by the langchain package",
"main": "./index.mjs",
"scripts": {
"test": "npm run test:esm && npm run test:cjs && npm run test:cjs:import && npm run test:ts",
"test": "npm run test:esm && npm run test:cjs && npm run test:cjs:import && npm run test:cjs:entrypoints && npm run test:ts",
"test:esm": "node ./index.mjs",
"test:cjs": "node ./require.js",
"test:cjs:import": "node ./import.js",
"test:cjs:entrypoints": "node ./entrypoints.js",
"test:ts": "tsc && node dist/index.js",
"format": "prettier --write \"**/*.ts\"",
"format:check": "prettier --list-different \"**/*.ts\""
Expand Down
5 changes: 4 additions & 1 deletion test-exports-cjs/require.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const assert = require("assert");
const { OpenAI } = require("langchain");
const { loadPrompt } = require("langchain/prompts");
const { LLMChain } = require("langchain/chains");
const { loadPrompt, ChatPromptTemplate } = require("langchain/prompts");
const { HNSWLib } = require("langchain/vectorstores");
const { OpenAIEmbeddings } = require("langchain/embeddings");
const { InMemoryDocstore, Document } = require("langchain/docstore");
Expand All @@ -9,7 +10,9 @@ const { CSVLoader } = require("langchain/document_loaders");
async function test() {
// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
5 changes: 4 additions & 1 deletion test-exports/import.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
async function test() {
const { default: assert } = await import("assert");
const { OpenAI } = await import("langchain");
const { loadPrompt } = await import("langchain/prompts");
const { LLMChain } = await import("langchain/chains");
const { loadPrompt, ChatPromptTemplate } = await import("langchain/prompts");
const { HNSWLib } = await import("langchain/vectorstores");
const { OpenAIEmbeddings } = await import("langchain/embeddings");
const { InMemoryDocstore, Document } = await import("langchain/docstore");
const { CSVLoader } = await import("langchain/document_loaders");

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
5 changes: 4 additions & 1 deletion test-exports/index.mjs → test-exports/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import assert from "assert";
import { OpenAI } from "langchain";
import { loadPrompt } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
import { HNSWLib } from "langchain/vectorstores";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { InMemoryDocstore, Document } from "langchain/docstore";
import { CSVLoader } from "langchain/document_loaders";

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
5 changes: 4 additions & 1 deletion test-exports/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from "assert";
import { OpenAI } from "langchain";
import { loadPrompt } from "langchain/prompts";
import { LLMChain } from "langchain/chains";
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
import { HNSWLib } from "langchain/vectorstores";
import { OpenAIEmbeddings } from "langchain/embeddings";
import { InMemoryDocstore, Document } from "langchain/docstore";
Expand All @@ -9,7 +10,9 @@ import { CSVLoader } from "langchain/document_loaders";
async function test() {
// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down
2 changes: 1 addition & 1 deletion test-exports/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "module",
"scripts": {
"test": "npm run test:esm && npm run test:cjs && npm run test:cjs:import && npm run test:ts",
"test:esm": "node ./index.mjs",
"test:esm": "node ./index.js",
"test:cjs": "node ./require.cjs",
"test:cjs:import": "node ./import.cjs",
"test:ts": "tsc && node dist/index.js",
Expand Down
5 changes: 4 additions & 1 deletion test-exports/require.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const assert = require("assert");
const { OpenAI } = require("langchain");
const { loadPrompt } = require("langchain/prompts");
const { LLMChain } = require("langchain/chains");
const { loadPrompt, ChatPromptTemplate } = require("langchain/prompts");
const { HNSWLib } = require("langchain/vectorstores");
const { OpenAIEmbeddings } = require("langchain/embeddings");
const { InMemoryDocstore, Document } = require("langchain/docstore");
Expand All @@ -9,7 +10,9 @@ const { CSVLoader } = require("langchain/document_loaders");
async function test() {
// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");

// Test dynamic imports of peer dependencies
Expand Down