Skip to content

Commit 813e99a

Browse files
authored
Add chains to test-exports (#639)
* Add chains to test-exports * Add one more test that requires every entrypoint
1 parent 72dfe6c commit 813e99a

File tree

11 files changed

+47
-10
lines changed

11 files changed

+47
-10
lines changed

test-exports-cjs/entrypoints.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const package = require("langchain/package.json");
2+
3+
Object.keys(package.exports).forEach((key) => {
4+
if (key === "./package.json") return;
5+
6+
if (key === ".") {
7+
require("langchain");
8+
} else {
9+
require(`langchain/${key.slice(2)}`);
10+
// If this fails probably means that a ESM-only dependency is being imported
11+
}
12+
});

test-exports-cjs/import.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
async function test() {
22
const { default: assert } = await import("assert");
33
const { OpenAI } = await import("langchain");
4-
const { loadPrompt } = await import("langchain/prompts");
4+
const { LLMChain } = await import("langchain/chains");
5+
const { loadPrompt, ChatPromptTemplate } = await import("langchain/prompts");
56
const { HNSWLib } = await import("langchain/vectorstores");
67
const { OpenAIEmbeddings } = await import("langchain/embeddings");
78
const { InMemoryDocstore, Document } = await import("langchain/docstore");
89
const { CSVLoader } = await import("langchain/document_loaders");
910

1011
// Test exports
1112
assert(typeof OpenAI === "function");
13+
assert(typeof LLMChain === "function");
1214
assert(typeof loadPrompt === "function");
15+
assert(typeof ChatPromptTemplate === "function");
1316
assert(typeof HNSWLib === "function");
1417

1518
// Test dynamic imports of peer dependencies

test-exports-cjs/index.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import assert from "assert";
22
import { OpenAI } from "langchain";
3-
import { loadPrompt } from "langchain/prompts";
3+
import { LLMChain } from "langchain/chains";
4+
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
45
import { HNSWLib } from "langchain/vectorstores";
56
import { OpenAIEmbeddings } from "langchain/embeddings";
67
import { InMemoryDocstore, Document } from "langchain/docstore";
78
import { CSVLoader } from "langchain/document_loaders";
89

910
// Test exports
1011
assert(typeof OpenAI === "function");
12+
assert(typeof LLMChain === "function");
1113
assert(typeof loadPrompt === "function");
14+
assert(typeof ChatPromptTemplate === "function");
1215
assert(typeof HNSWLib === "function");
1316

1417
// Test dynamic imports of peer dependencies

test-exports-cjs/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from "assert";
22
import { OpenAI } from "langchain";
3-
import { loadPrompt } from "langchain/prompts";
3+
import { LLMChain } from "langchain/chains";
4+
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
45
import { HNSWLib } from "langchain/vectorstores";
56
import { OpenAIEmbeddings } from "langchain/embeddings";
67
import { InMemoryDocstore, Document } from "langchain/docstore";
@@ -9,7 +10,9 @@ import { CSVLoader } from "langchain/document_loaders";
910
async function test() {
1011
// Test exports
1112
assert(typeof OpenAI === "function");
13+
assert(typeof LLMChain === "function");
1214
assert(typeof loadPrompt === "function");
15+
assert(typeof ChatPromptTemplate === "function");
1316
assert(typeof HNSWLib === "function");
1417

1518
// Test dynamic imports of peer dependencies

test-exports-cjs/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
"description": "CJS Tests for the things exported by the langchain package",
66
"main": "./index.mjs",
77
"scripts": {
8-
"test": "npm run test:esm && npm run test:cjs && npm run test:cjs:import && npm run test:ts",
8+
"test": "npm run test:esm && npm run test:cjs && npm run test:cjs:import && npm run test:cjs:entrypoints && npm run test:ts",
99
"test:esm": "node ./index.mjs",
1010
"test:cjs": "node ./require.js",
1111
"test:cjs:import": "node ./import.js",
12+
"test:cjs:entrypoints": "node ./entrypoints.js",
1213
"test:ts": "tsc && node dist/index.js",
1314
"format": "prettier --write \"**/*.ts\"",
1415
"format:check": "prettier --list-different \"**/*.ts\""

test-exports-cjs/require.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const assert = require("assert");
22
const { OpenAI } = require("langchain");
3-
const { loadPrompt } = require("langchain/prompts");
3+
const { LLMChain } = require("langchain/chains");
4+
const { loadPrompt, ChatPromptTemplate } = require("langchain/prompts");
45
const { HNSWLib } = require("langchain/vectorstores");
56
const { OpenAIEmbeddings } = require("langchain/embeddings");
67
const { InMemoryDocstore, Document } = require("langchain/docstore");
@@ -9,7 +10,9 @@ const { CSVLoader } = require("langchain/document_loaders");
910
async function test() {
1011
// Test exports
1112
assert(typeof OpenAI === "function");
13+
assert(typeof LLMChain === "function");
1214
assert(typeof loadPrompt === "function");
15+
assert(typeof ChatPromptTemplate === "function");
1316
assert(typeof HNSWLib === "function");
1417

1518
// Test dynamic imports of peer dependencies

test-exports/import.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
async function test() {
22
const { default: assert } = await import("assert");
33
const { OpenAI } = await import("langchain");
4-
const { loadPrompt } = await import("langchain/prompts");
4+
const { LLMChain } = await import("langchain/chains");
5+
const { loadPrompt, ChatPromptTemplate } = await import("langchain/prompts");
56
const { HNSWLib } = await import("langchain/vectorstores");
67
const { OpenAIEmbeddings } = await import("langchain/embeddings");
78
const { InMemoryDocstore, Document } = await import("langchain/docstore");
89
const { CSVLoader } = await import("langchain/document_loaders");
910

1011
// Test exports
1112
assert(typeof OpenAI === "function");
13+
assert(typeof LLMChain === "function");
1214
assert(typeof loadPrompt === "function");
15+
assert(typeof ChatPromptTemplate === "function");
1316
assert(typeof HNSWLib === "function");
1417

1518
// Test dynamic imports of peer dependencies

test-exports/index.mjs renamed to test-exports/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import assert from "assert";
22
import { OpenAI } from "langchain";
3-
import { loadPrompt } from "langchain/prompts";
3+
import { LLMChain } from "langchain/chains";
4+
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
45
import { HNSWLib } from "langchain/vectorstores";
56
import { OpenAIEmbeddings } from "langchain/embeddings";
67
import { InMemoryDocstore, Document } from "langchain/docstore";
78
import { CSVLoader } from "langchain/document_loaders";
89

910
// Test exports
1011
assert(typeof OpenAI === "function");
12+
assert(typeof LLMChain === "function");
1113
assert(typeof loadPrompt === "function");
14+
assert(typeof ChatPromptTemplate === "function");
1215
assert(typeof HNSWLib === "function");
1316

1417
// Test dynamic imports of peer dependencies

test-exports/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import assert from "assert";
22
import { OpenAI } from "langchain";
3-
import { loadPrompt } from "langchain/prompts";
3+
import { LLMChain } from "langchain/chains";
4+
import { loadPrompt, ChatPromptTemplate } from "langchain/prompts";
45
import { HNSWLib } from "langchain/vectorstores";
56
import { OpenAIEmbeddings } from "langchain/embeddings";
67
import { InMemoryDocstore, Document } from "langchain/docstore";
@@ -9,7 +10,9 @@ import { CSVLoader } from "langchain/document_loaders";
910
async function test() {
1011
// Test exports
1112
assert(typeof OpenAI === "function");
13+
assert(typeof LLMChain === "function");
1214
assert(typeof loadPrompt === "function");
15+
assert(typeof ChatPromptTemplate === "function");
1316
assert(typeof HNSWLib === "function");
1417

1518
// Test dynamic imports of peer dependencies

test-exports/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "module",
88
"scripts": {
99
"test": "npm run test:esm && npm run test:cjs && npm run test:cjs:import && npm run test:ts",
10-
"test:esm": "node ./index.mjs",
10+
"test:esm": "node ./index.js",
1111
"test:cjs": "node ./require.cjs",
1212
"test:cjs:import": "node ./import.cjs",
1313
"test:ts": "tsc && node dist/index.js",

test-exports/require.cjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const assert = require("assert");
22
const { OpenAI } = require("langchain");
3-
const { loadPrompt } = require("langchain/prompts");
3+
const { LLMChain } = require("langchain/chains");
4+
const { loadPrompt, ChatPromptTemplate } = require("langchain/prompts");
45
const { HNSWLib } = require("langchain/vectorstores");
56
const { OpenAIEmbeddings } = require("langchain/embeddings");
67
const { InMemoryDocstore, Document } = require("langchain/docstore");
@@ -9,7 +10,9 @@ const { CSVLoader } = require("langchain/document_loaders");
910
async function test() {
1011
// Test exports
1112
assert(typeof OpenAI === "function");
13+
assert(typeof LLMChain === "function");
1214
assert(typeof loadPrompt === "function");
15+
assert(typeof ChatPromptTemplate === "function");
1316
assert(typeof HNSWLib === "function");
1417

1518
// Test dynamic imports of peer dependencies

0 commit comments

Comments
 (0)