From c28303b0b7f1e8e60954aee432a391e20659336b Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Thu, 22 Aug 2024 12:59:41 -0700 Subject: [PATCH] scripts[minor]infra[patch]: Remove deprecated build script (#6595) --- langchain-core/package.json | 12 +- langchain/package.json | 12 +- .../template/package.json | 11 +- libs/langchain-anthropic/package.json | 2 +- libs/langchain-aws/package.json | 11 +- libs/langchain-azure-cosmosdb/package.json | 14 +- .../package.json | 14 +- libs/langchain-azure-openai/package.json | 2 +- libs/langchain-baidu-qianfan/package.json | 2 +- libs/langchain-cloudflare/package.json | 2 +- libs/langchain-cohere/package.json | 2 +- libs/langchain-community/package.json | 2 +- libs/langchain-exa/package.json | 12 +- libs/langchain-google-common/package.json | 20 +- libs/langchain-google-gauth/package.json | 2 +- libs/langchain-google-genai/package.json | 2 +- .../package.json | 12 +- libs/langchain-google-vertexai/package.json | 15 +- libs/langchain-google-webauth/package.json | 20 +- libs/langchain-groq/package.json | 2 +- libs/langchain-mistralai/package.json | 2 +- libs/langchain-mixedbread-ai/package.json | 2 +- libs/langchain-mongodb/package.json | 12 +- libs/langchain-nomic/package.json | 12 +- libs/langchain-ollama/package.json | 7 +- libs/langchain-openai/package.json | 2 +- libs/langchain-pinecone/package.json | 11 +- libs/langchain-qdrant/package.json | 11 +- libs/langchain-redis/package.json | 11 +- libs/langchain-scripts/bin/build.js | 912 +----------------- libs/langchain-scripts/bin/build_v2.js | 1 - libs/langchain-scripts/langchain.config.js | 2 +- libs/langchain-scripts/package.json | 7 +- libs/langchain-scripts/src/build.ts | 121 --- .../src/{build_v2.ts => build/index.ts} | 81 +- .../src/{ => build}/utils.ts | 2 +- .../src/check-tree-shaking.ts | 122 --- .../src/create-entrypoints.ts | 385 -------- .../langchain-scripts/src/identify-secrets.ts | 100 -- .../langchain-scripts/src/move-cjs-to-dist.ts | 55 -- .../src/tests/config_file.test.ts | 2 +- libs/langchain-scripts/tsconfig.build.json | 3 +- libs/langchain-standard-tests/package.json | 2 +- libs/langchain-textsplitters/package.json | 11 +- libs/langchain-weaviate/package.json | 12 +- libs/langchain-yandex/package.json | 12 +- yarn.lock | 3 +- 47 files changed, 119 insertions(+), 1955 deletions(-) delete mode 100755 libs/langchain-scripts/bin/build_v2.js delete mode 100644 libs/langchain-scripts/src/build.ts rename libs/langchain-scripts/src/{build_v2.ts => build/index.ts} (93%) rename libs/langchain-scripts/src/{ => build}/utils.ts (98%) delete mode 100644 libs/langchain-scripts/src/check-tree-shaking.ts delete mode 100644 libs/langchain-scripts/src/create-entrypoints.ts delete mode 100644 libs/langchain-scripts/src/identify-secrets.ts delete mode 100644 libs/langchain-scripts/src/move-cjs-to-dist.ts diff --git a/langchain-core/package.json b/langchain-core/package.json index 613cb1522b01..1307d14027b3 100644 --- a/langchain-core/package.json +++ b/langchain-core/package.json @@ -15,13 +15,8 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/langchain-core/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/core", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "clean": "rm -rf .turbo dist/", - "build:deps": "yarn turbo build", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -33,10 +28,7 @@ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/langchain/package.json b/langchain/package.json index fe3c6ee0b599..18aa16d1c363 100644 --- a/langchain/package.json +++ b/langchain/package.json @@ -574,12 +574,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/langchain/", "scripts": { "build": "yarn turbo:command build:internal --filter=langchain", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking --gen-maps", - "build:deps": "yarn run turbo:command build --filter=@langchain/openai --filter=@langchain/textsplitters --filter=@langchain/cohere --concurrency=1", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rimraf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rimraf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking --gen-maps", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -593,10 +588,7 @@ "test:integration": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/create-langchain-integration/template/package.json b/libs/create-langchain-integration/template/package.json index 4b3cb068bf24..dea7417b214a 100644 --- a/libs/create-langchain-integration/template/package.json +++ b/libs/create-langchain-integration/template/package.json @@ -15,11 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-INTEGRATION_NAME/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/INTEGRATION_NAME", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-anthropic/package.json b/libs/langchain-anthropic/package.json index f4ef0778ee65..550bb654c321 100644 --- a/libs/langchain-anthropic/package.json +++ b/libs/langchain-anthropic/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-anthropic/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/anthropic", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking --gen-maps", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking --gen-maps", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-aws/package.json b/libs/langchain-aws/package.json index d9a4990e1146..a4a18e716fa9 100644 --- a/libs/langchain-aws/package.json +++ b/libs/langchain-aws/package.json @@ -15,11 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-aws/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/aws", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-azure-cosmosdb/package.json b/libs/langchain-azure-cosmosdb/package.json index f825d546f520..6a8a02adebb1 100644 --- a/libs/langchain-azure-cosmosdb/package.json +++ b/libs/langchain-azure-cosmosdb/package.json @@ -14,26 +14,20 @@ }, "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-azure-cosmosdb/", "scripts": { - "build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build": "yarn turbo:command build:internal --filter=@langchain/azure-cosmosdb", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", - "clean": "rm -rf dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn lc-build --config ./langchain.config.js --create-entrypoints --pre", + "clean": "rm -rf dist/ .turbo", "prepack": "yarn build", "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-azure-dynamic-sessions/package.json b/libs/langchain-azure-dynamic-sessions/package.json index c726d00e93cf..2c8e0ef7e80c 100644 --- a/libs/langchain-azure-dynamic-sessions/package.json +++ b/libs/langchain-azure-dynamic-sessions/package.json @@ -14,26 +14,20 @@ }, "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-INTEGRATION_NAME/", "scripts": { - "build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build": "yarn turbo:command build:internal --filter=@langchain/azure-dynamic-sessions", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", - "clean": "rm -rf dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn lc-build --config ./langchain.config.js --create-entrypoints --pre", + "clean": "rm -rf .turbo dist/", "prepack": "yarn build", "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-azure-openai/package.json b/libs/langchain-azure-openai/package.json index 26631a07a7d8..7d342c60ec33 100644 --- a/libs/langchain-azure-openai/package.json +++ b/libs/langchain-azure-openai/package.json @@ -14,7 +14,7 @@ }, "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/azure-openai", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-baidu-qianfan/package.json b/libs/langchain-baidu-qianfan/package.json index 50d9b678f926..84cf871e7e09 100644 --- a/libs/langchain-baidu-qianfan/package.json +++ b/libs/langchain-baidu-qianfan/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-baidu-qianfan/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/baidu-qianfan", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-cloudflare/package.json b/libs/langchain-cloudflare/package.json index 45bd5752740e..171bd43a0fdc 100644 --- a/libs/langchain-cloudflare/package.json +++ b/libs/langchain-cloudflare/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-cloudflare/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/cloudflare", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-cohere/package.json b/libs/langchain-cohere/package.json index 634afa79e05a..eeb1035c0fde 100644 --- a/libs/langchain-cohere/package.json +++ b/libs/langchain-cohere/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-cohere/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/cohere", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-community/package.json b/libs/langchain-community/package.json index 39547db6b2db..57fa2d83e33f 100644 --- a/libs/langchain-community/package.json +++ b/libs/langchain-community/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-community/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/community", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking --gen-maps", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking --gen-maps", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-exa/package.json b/libs/langchain-exa/package.json index 6f112e3223a1..20b313377c36 100644 --- a/libs/langchain-exa/package.json +++ b/libs/langchain-exa/package.json @@ -15,12 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-exa/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/exa", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/core", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -32,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-google-common/package.json b/libs/langchain-google-common/package.json index 0d96e938a1db..634c32d400e7 100644 --- a/libs/langchain-google-common/package.json +++ b/libs/langchain-google-common/package.json @@ -15,27 +15,19 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-common/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/google-common", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/core", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", "clean": "rm -rf .turbo dist/", "prepack": "yarn build", - "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", - "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", - "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", - "test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", + "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", + "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", + "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", + "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-google-gauth/package.json b/libs/langchain-google-gauth/package.json index 0fea7767dba0..f6821c67f17c 100644 --- a/libs/langchain-google-gauth/package.json +++ b/libs/langchain-google-gauth/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-gauth/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/google-gauth", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-google-genai/package.json b/libs/langchain-google-genai/package.json index dd54061733df..d6792fd43c07 100644 --- a/libs/langchain-google-genai/package.json +++ b/libs/langchain-google-genai/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-genai/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/google-genai", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-google-vertexai-web/package.json b/libs/langchain-google-vertexai-web/package.json index 13fec9df09b7..26341f930fa3 100644 --- a/libs/langchain-google-vertexai-web/package.json +++ b/libs/langchain-google-vertexai-web/package.json @@ -15,12 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-vertexai-web/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/google-vertexai-web", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/google-gauth", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -32,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-google-vertexai/package.json b/libs/langchain-google-vertexai/package.json index 5a0faf98f3b7..176d427f54fe 100644 --- a/libs/langchain-google-vertexai/package.json +++ b/libs/langchain-google-vertexai/package.json @@ -15,12 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-vertexai/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/google-vertexai", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/google-gauth", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,14 +26,8 @@ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", - "test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%", - "test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", - "test:standard": "yarn test:standard:unit && yarn test:standard:int", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-google-webauth/package.json b/libs/langchain-google-webauth/package.json index e427d62c0ddd..efdd9a744a48 100644 --- a/libs/langchain-google-webauth/package.json +++ b/libs/langchain-google-webauth/package.json @@ -15,27 +15,19 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-google-webauth/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/google-webauth", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/google-common", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", "clean": "rm -rf .turbo dist/", "prepack": "yarn build", - "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", - "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", - "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", - "test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", + "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", + "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", + "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", + "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-groq/package.json b/libs/langchain-groq/package.json index 42c79b7b73fd..616bebcf750b 100644 --- a/libs/langchain-groq/package.json +++ b/libs/langchain-groq/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-groq/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/groq", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-mistralai/package.json b/libs/langchain-mistralai/package.json index 605178330fe0..556f579d4083 100644 --- a/libs/langchain-mistralai/package.json +++ b/libs/langchain-mistralai/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-mistralai/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/mistralai", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-mixedbread-ai/package.json b/libs/langchain-mixedbread-ai/package.json index 68d207ac8877..4a9015891868 100644 --- a/libs/langchain-mixedbread-ai/package.json +++ b/libs/langchain-mixedbread-ai/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-mixedbread-ai/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/mixedbread-ai", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-mongodb/package.json b/libs/langchain-mongodb/package.json index cd526c859df5..9b6b1557e330 100644 --- a/libs/langchain-mongodb/package.json +++ b/libs/langchain-mongodb/package.json @@ -15,12 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-mongodb/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/mongodb", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/openai", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -32,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-nomic/package.json b/libs/langchain-nomic/package.json index 76daa46b574b..0c676b062876 100644 --- a/libs/langchain-nomic/package.json +++ b/libs/langchain-nomic/package.json @@ -15,12 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-nomic/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/nomic", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/core", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -32,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-ollama/package.json b/libs/langchain-ollama/package.json index 88d5c74d7917..c18f33538808 100644 --- a/libs/langchain-ollama/package.json +++ b/libs/langchain-ollama/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-ollama/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/ollama", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -27,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-openai/package.json b/libs/langchain-openai/package.json index 4ba163dd8703..831946ffc1fd 100644 --- a/libs/langchain-openai/package.json +++ b/libs/langchain-openai/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-openai/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/openai", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-pinecone/package.json b/libs/langchain-pinecone/package.json index 702a8ff3d590..eed6620abc5f 100644 --- a/libs/langchain-pinecone/package.json +++ b/libs/langchain-pinecone/package.json @@ -15,11 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-pinecone/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/pinecone", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "Pinecone, Inc", "license": "MIT", diff --git a/libs/langchain-qdrant/package.json b/libs/langchain-qdrant/package.json index 40548cfe9e44..b67aaa635d4c 100644 --- a/libs/langchain-qdrant/package.json +++ b/libs/langchain-qdrant/package.json @@ -15,11 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-qdrant", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/qdrant", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-redis/package.json b/libs/langchain-redis/package.json index fda7d74d59a6..d321f4e47a42 100644 --- a/libs/langchain-redis/package.json +++ b/libs/langchain-redis/package.json @@ -15,11 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-redis/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/redis", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-scripts/bin/build.js b/libs/langchain-scripts/bin/build.js index 40b80ac0d611..ec93df06484c 100755 --- a/libs/langchain-scripts/bin/build.js +++ b/libs/langchain-scripts/bin/build.js @@ -1,911 +1 @@ -#!/usr/bin/env node - -import { Command } from "commander"; -import * as fs from "node:fs"; -import path from "node:path"; -import ts from "typescript"; -import { rollup } from "rollup"; - -/** - * @typedef {Object} ExtraImportMapEntry - * @property {Array} modules - * @property {Array} alias - * @property {string} path - */ - -/** - * @typedef {Object} ImportData - * @property {Record} exportedAliases - * @property {Record} imports - */ - -/** - * @param {any} obj - * @returns {obj is LangChainConfig} - */ -function _verifyObjectIsLangChainConfig( - obj -) { - if (typeof obj !== "object") { - console.error("LangChain config file is not an object"); - return false; - } - if ( - !("entrypoints" in obj) || - !("tsConfigPath" in obj) || - !("cjsSource" in obj) || - !("cjsDestination" in obj) || - !("abs" in obj) - ) { - console.error(`LangChain config file is missing required fields. One of: entrypoints, tsConfigPath, cjsSource, cjsDestination, abs`); - return false; - } - if (typeof obj.entrypoints !== "object") { - console.error("entrypoints field in LangChain config file is not an object"); - return false; - } - if (Object.values(obj.entrypoints).some((v) => typeof v !== "string")) { - console.error("entrypoints field in LangChain config file is not an object of strings"); - return false; - } - if ( - typeof obj.tsConfigPath !== "string" || - typeof obj.cjsSource !== "string" || - typeof obj.cjsDestination !== "string" - ) { - console.error("tsConfigPath, cjsSource, or cjsDestination fields in LangChain config file are not strings"); - return false; - } - if (typeof obj.abs !== "function") { - console.error("abs field in LangChain config file is not a function"); - return false; - } - - // Optional fields - if ( - "requiresOptionalDependency" in obj && - (!Array.isArray(obj.requiresOptionalDependency) || - obj.requiresOptionalDependency.some((v) => typeof v !== "string")) - ) { - console.error("requiresOptionalDependency field in LangChain config file is not an array of strings"); - return false; - } - if ( - "deprecatedNodeOnly" in obj && - (!Array.isArray(obj.deprecatedNodeOnly) || - obj.deprecatedNodeOnly.some((v) => typeof v !== "string")) - ) { - console.error("deprecatedNodeOnly field in LangChain config file is not an array of strings"); - return false; - } - if ( - "deprecatedOmitFromImportMap" in obj && - (!Array.isArray(obj.deprecatedOmitFromImportMap) || - obj.deprecatedOmitFromImportMap.some((v) => typeof v !== "string")) - ) { - console.error("deprecatedOmitFromImportMap field in LangChain config file is not an array of strings"); - return false; - } - if ("packageSuffix" in obj && typeof obj.packageSuffix !== "string") { - console.error("packageSuffix field in LangChain config file is not a string"); - return false; - } - if ( - "shouldTestExports" in obj && - typeof obj.shouldTestExports !== "boolean" - ) { - console.error("shouldTestExports field in LangChain config file is not a boolean"); - return false; - } - if ( - "extraImportMapEntries" in obj && - !Array.isArray(obj.extraImportMapEntries) - ) { - console.error("extraImportMapEntries field in LangChain config file is not an array"); - return false; - } - if ( - "gitignorePaths" in obj && - (!Array.isArray(obj.gitignorePaths) || - obj.gitignorePaths.some((v) => typeof v !== "string")) - ) { - console.error("gitignorePaths field in LangChain config file is not an array of strings"); - return false; - } - if ("internals" in obj && !Array.isArray(obj.internals)) { - console.error("internals field in LangChain config file is not an array"); - return false; - } - return true; -} - - -async function moveAndRename({ - /** @type {string} */ - source, - /** @type {string} */ - dest, - /** @type {(p: string) => string} */ - abs, -}) { - try { - for (const file of await fs.promises.readdir(abs(source), { withFileTypes: true })) { - if (file.isDirectory()) { - await moveAndRename({ - source: `${source}/${file.name}`, - dest: `${dest}/${file.name}`, - abs, - }); - } else if (file.isFile()) { - const parsed = path.parse(file.name); - - // Ignore anything that's not a .js file - if (parsed.ext !== ".js") { - continue; - } - - // Rewrite any require statements to use .cjs - const content = await fs.promises.readFile(abs(`${source}/${file.name}`), "utf8"); - const rewritten = content.replace( - /require\("(\..+?).js"\)/g, - (_, p1) => `require("${p1}.cjs")` - ); - - // Rename the file to .cjs - const renamed = path.format({ name: parsed.name, ext: ".cjs" }); - - await fs.promises.writeFile(abs(`${dest}/${renamed}`), rewritten, "utf8"); - } - } - } catch (err) { - console.error(err); - process.exit(1); - } -} - -/** @returns {Promise} */ -async function getPackageJson() { - return JSON.parse(await fs.promises.readFile("package.json", "utf-8")); -} - -async function listEntrypoints() { - const { exports } = await getPackageJson(); - /** @type {Record | null} */ - const exportsWithoutPackageJSON = exports - ? Object.entries(exports) - .filter(([k]) => k !== "./package.json") - .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}) - : null; - - if (!exportsWithoutPackageJSON) { - throw new Error("No exports found in package.json"); - } - /** @type {string[]} */ - const entrypoints = []; - - for (const [key, value] of Object.entries(exportsWithoutPackageJSON)) { - if (key === "./package.json") { - continue; - } - if (typeof value === "string") { - entrypoints.push(value); - } else if ( - "import" in value && - value.import && - typeof value.import === "string" - ) { - entrypoints.push(value.import); - } - } - - return entrypoints; -} - -/** - * - * @param {Array} extraInternals - * @default [...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.peerDependencies ?? {})] - * @returns {Promise>} - */ -async function listExternals( - extraInternals -) { - const packageJson = await getPackageJson(); - return [ - ...Object.keys(packageJson.dependencies ?? {}), - ...Object.keys(packageJson.peerDependencies ?? {}), - ...extraInternals, - ]; -} - -/** - * - * @param {undefined | TreeShakingArgs} options - */ -export async function checkTreeShaking(options) { - const externals = await listExternals(options?.extraInternals ?? []); - const entrypoints = await listEntrypoints(); - const consoleInfo = console.info; - const reportMap = new Map(); - - for (const entrypoint of entrypoints) { - let sideEffects = ""; - - console.info = function (...args) { - const line = args.length ? args.join(" ") : ""; - if (line.includes("First side effect in")) { - sideEffects += `${line}\n`; - } - }; - - await rollup({ - external: externals, - input: entrypoint, - experimentalLogSideEffects: true, - }); - - let hasUnexpectedSideEffects = sideEffects.length > 0; - if (hasUnexpectedSideEffects) { - const entrypointContent = await fs.promises.readFile(`./dist/${entrypoint.replace(/^\.\//, "")}`); - // Allow escaping side effects strictly within code directly - // within an entrypoint - hasUnexpectedSideEffects = !entrypointContent - .toString() - .includes("/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */"); - } - reportMap.set(entrypoint, { - log: sideEffects, - hasUnexpectedSideEffects, - }); - } - - console.info = consoleInfo; - - let failed = false; - for (const [entrypoint, report] of reportMap) { - if (report.hasUnexpectedSideEffects) { - failed = true; - console.log("---------------------------------"); - console.log(`Tree shaking failed for ${entrypoint}`); - console.log(report.log); - } - } - - if (failed) { - throw new Error("Tree shaking checks failed."); - } else { - console.log("Tree shaking checks passed!"); - } -} - - -function identifySecrets(absTsConfigPath) { - const secrets = new Set(); - - const tsConfig = ts.parseJsonConfigFileContent( - ts.readJsonConfigFile(absTsConfigPath, (p) => fs.readFileSync(p, "utf-8")), - ts.sys, - "./src/" - ); - - // `tsConfig.options.target` is not always defined when running this - // via the `@langchain/scripts` package. Instead, fallback to the raw - // tsConfig.json file contents. - const tsConfigFileContentsText = - "text" in tsConfig.raw - ? JSON.parse(tsConfig.raw.text) - : { compilerOptions: {} }; - - const tsConfigTarget = - tsConfig.options.target || tsConfigFileContentsText.compilerOptions.target; - - for (const fileName of tsConfig.fileNames.filter( - (fn) => !fn.endsWith("test.ts") - )) { - if (!tsConfigTarget) { - continue; - } - - const sourceFile = ts.createSourceFile( - fileName, - fs.readFileSync(fileName, "utf-8"), - tsConfigTarget, - true - ); - - sourceFile.forEachChild((node) => { - switch (node.kind) { - case ts.SyntaxKind.ClassDeclaration: - case ts.SyntaxKind.ClassExpression: { - node.forEachChild((node) => { - // look for get lc_secrets() - switch (node.kind) { - case ts.SyntaxKind.GetAccessor: { - const property = node; - if ( - ts.isGetAccessor(property) && - property.name.getText() === "lc_secrets" - ) { - // look for return { ... } - property.body?.statements.forEach((stmt) => { - if ( - ts.isReturnStatement(stmt) && - stmt.expression && - ts.isObjectLiteralExpression(stmt.expression) - ) { - stmt.expression.properties.forEach((element) => { - if (ts.isPropertyAssignment(element)) { - // Type guard for PropertyAssignment - if ( - element.initializer && - ts.isStringLiteral(element.initializer) - ) { - const secret = element.initializer.text; - - if (secret.toUpperCase() !== secret) { - throw new Error( - `Secret identifier must be uppercase: ${secret} at ${fileName}` - ); - } - if (/\s/.test(secret)) { - throw new Error( - `Secret identifier must not contain whitespace: ${secret} at ${fileName}` - ); - } - - secrets.add(secret); - } - } - }); - } - }); - } - break; - } - default: - break; - } - }); - break; - } - default: - break; - } - }); - } - - return secrets; -} - -// .gitignore -const DEFAULT_GITIGNORE_PATHS = ["node_modules", "dist", ".yarn"]; - -/** - * List of test-exports-* packages which we use to test that the exports field - * works correctly across different JS environments. - * Each entry is a tuple of [package name, import statement]. - * @type {Array<[string, (p: string) => string]>} - */ -const testExports = [ - [ - "test-exports-esm", - (p) => - `import * as ${p.replace(/\//g, "_")} from "langchain/${p}";`, - ], - [ - "test-exports-esbuild", - (p) => - `import * as ${p.replace(/\//g, "_")} from "langchain/${p}";`, - ], - [ - "test-exports-cjs", - (p) => - `const ${p.replace(/\//g, "_")} = require("langchain/${p}");`, - ], - ["test-exports-cf", (p) => `export * from "langchain/${p}";`], - ["test-exports-vercel", (p) => `export * from "langchain/${p}";`], - ["test-exports-vite", (p) => `export * from "langchain/${p}";`], - ["test-exports-bun", (p) => `export * from "langchain/${p}";`], -]; - -/** - * - * @param {string} relativePath - * @param {(json: Record) => Record} updateFunction - */ -const updateJsonFile = ( - relativePath, - updateFunction -) => { - const contents = fs.readFileSync(relativePath).toString(); - const res = updateFunction(JSON.parse(contents)); - fs.writeFileSync(relativePath, `${JSON.stringify(res, null, 2)}\n`); -}; - -/** - * @param {Record} entrypoints - * @returns {Record} - */ -const generateFiles = ( - entrypoints -) => { - const files = [...Object.entries(entrypoints)].flatMap(([key, value]) => { - const nrOfDots = key.split("/").length - 1; - const relativePath = "../".repeat(nrOfDots) || "./"; - const compiledPath = `${relativePath}dist/${value}.js`; - return [ - [ - `${key}.cjs`, - `module.exports = require('${relativePath}dist/${value}.cjs');`, - ], - [`${key}.js`, `export * from '${compiledPath}'`], - [`${key}.d.ts`, `export * from '${compiledPath}'`], - [`${key}.d.cts`, `export * from '${compiledPath}'`], - ]; - }); - - return Object.fromEntries(files); -}; - -const updateConfig = ({ - /** @type {Record} */ - entrypoints, - /** @type {Array} */ - deprecatedNodeOnly, - /** @type {Array} */ - requiresOptionalDependency, - /** @type {boolean} */ - shouldTestExports, - /** @type {Array | undefined} */ - additionalGitignorePaths = [], -}) => { - const generatedFiles = generateFiles(entrypoints); - const filenames = Object.keys(generatedFiles); - - // Update package.json `exports` and `files` fields - updateJsonFile("./package.json", (json) => ({ - ...json, - exports: Object.assign( - Object.fromEntries( - [...Object.keys(entrypoints)].map((key) => { - const entryPoint = { - types: { - import: `./${key}.d.ts`, - require: `./${key}.d.cts`, - default: `./${key}.d.ts`, - }, - import: `./${key}.js`, - require: `./${key}.cjs`, - }; - - return [key === "index" ? "." : `./${key}`, entryPoint]; - }) - ), - { "./package.json": "./package.json" } - ), - files: ["dist/", ...filenames], - })); - - // Write generated files - Object.entries(generatedFiles).forEach(([filename, content]) => { - fs.mkdirSync(path.dirname(filename), { recursive: true }); - fs.writeFileSync(filename, content); - }); - - const gitignorePaths = [...filenames, ...DEFAULT_GITIGNORE_PATHS, ...(additionalGitignorePaths ? additionalGitignorePaths : [])]; - - // Update .gitignore - fs.writeFileSync( - "./.gitignore", - `${gitignorePaths.join("\n")}\n` - ); - - if (shouldTestExports) { - // Update test-exports-*/entrypoints.js - const entrypointsToTest = Object.keys(entrypoints) - .filter((key) => !deprecatedNodeOnly.includes(key)) - .filter((key) => !requiresOptionalDependency.includes(key)); - testExports.forEach(([pkg, importStatement]) => { - const contents = `${entrypointsToTest - .map((key) => importStatement(key)) - .join("\n")}\n`; - fs.writeFileSync( - `../environment_tests/${pkg}/src/entrypoints.js`, - contents - ); - }); - } -}; - -const cleanGenerated = ({ - /** @type {Record} */ - entrypoints, -}) => { - const filenames = Object.keys(generateFiles(entrypoints)); - filenames.forEach((fname) => { - try { - fs.unlinkSync(fname); - } catch { - // ignore error - } - }); -}; - -// Tuple describing the auto-generated import map (used by langchain/load) -// [package name, import statement, import map path] -// This will not include entrypoints deprecated or requiring optional deps. -/** - * - * @param {string | null} packageSuffix - * @returns {[string, (k: string, p: string) => string, string]} - */ -const importMap = ( - packageSuffix -) => [ - `langchain${packageSuffix ? `-${packageSuffix}` : ""}`, - (k, p) => - `export * as ${k.replace(/\//g, "__")} from "../${p}.js";`, - "src/load/import_map.ts", - ]; - -const generateImportMap = ({ - /** @type {Record} */ - entrypoints, - /** @type {Array} */ - requiresOptionalDependency, - /** @type {Array} */ - deprecatedNodeOnly, - /** @type {Array} */ - deprecatedOmitFromImportMap, - /** @type {string | null} */ - packageSuffix, - /** @type {Array} */ - extraImportMapEntries, -}) => { - // Generate import map - const entrypointsToInclude = Object.keys(entrypoints) - .filter((key) => key !== "load") - .filter((key) => !deprecatedNodeOnly.includes(key)) - .filter((key) => !requiresOptionalDependency.includes(key)) - .filter((key) => !deprecatedOmitFromImportMap.includes(key)); - const [pkg, importStatement, importMapPath] = importMap(packageSuffix); - const contents = `${entrypointsToInclude - .map((key) => importStatement(key, entrypoints[key])) - .join("\n")}\n`; - const extraImportData = extraImportMapEntries.reduce( - (data, { modules, alias, path }) => { - const newData = { ...data }; - if (!newData.imports[path]) { - newData.imports[path] = []; - } - newData.imports[path] = [ - ...new Set(newData.imports[path].concat(modules)), - ]; - const exportAlias = alias.join("__"); - if (!newData.exportedAliases[exportAlias]) { - newData.exportedAliases[exportAlias] = []; - } - newData.exportedAliases[exportAlias] = - newData.exportedAliases[exportAlias].concat(modules); - return newData; - }, - { - imports: {}, - exportedAliases: {}, - } - ); - const extraImportStatements = Object.entries(extraImportData.imports).map( - ([path, modules]) => - `import {\n ${modules.join(",\n ")}\n} from "${path}";` - ); - const extraDeclarations = Object.entries(extraImportData.exportedAliases).map( - ([exportAlias, modules]) => - [ - `const ${exportAlias} = {\n ${modules.join(",\n ")}\n};`, - `export { ${exportAlias} };`, - ].join("\n") - ); - let extraContent = `${extraImportStatements.join( - "\n" - )}\n${extraDeclarations.join("\n")}\n`; - - extraContent.trim(); - if (!/[a-zA-Z0-9]/.test(extraContent)) { - extraContent = "" - } - - fs.writeFileSync( - `../${pkg}/${importMapPath}`, - `// Auto-generated by \`scripts/create-entrypoints.js\`. Do not edit manually.\n\n${contents}${extraContent}` - ); -}; - -/** - * - * @param {string | null} packageSuffix - * @returns {[string, string]} - */ -const importTypes = (packageSuffix) => [ - `langchain${packageSuffix ? `-${packageSuffix}` : ""}`, - "src/load/import_type.ts", -]; - -const generateImportTypes = ({ - /** @type {string} */ - absTsConfigPath, - /** @type {string | null} */ - packageSuffix, -}) => { - // Generate import types - const [pkg, importTypesPath] = importTypes(packageSuffix); - - fs.writeFileSync( - `../${pkg}/${importTypesPath}`, - `// Auto-generated by \`scripts/create-entrypoints.js\`. Do not edit manually. - -export interface OptionalImportMap {} - -export interface SecretMap { -${[...identifySecrets(absTsConfigPath)] - .sort() - .map((secret) => ` ${secret}?: string;`) - .join("\n")} -} -` - ); -}; - -/** - * @param {string | null} packageSuffix - * @returns {[string, (k: string) => string, string]} - */ -const importConstants = ( - packageSuffix -) => [ - `langchain${packageSuffix ? `-${packageSuffix}` : ""}`, - (k) => - ` "langchain${packageSuffix ? `_${packageSuffix}` : ""}/${k}"`, - "src/load/import_constants.ts", - ]; - -const generateImportConstants = ({ - /** @type {Record} */ - entrypoints, - /** @type {Array} */ - requiresOptionalDependency, - /** @type {Array} */ - deprecatedNodeOnly, - /** @type {string | null} */ - packageSuffix, -}) => { - // Generate import constants - const entrypointsToInclude = Object.keys(entrypoints) - .filter((key) => !deprecatedNodeOnly.includes(key)) - .filter((key) => requiresOptionalDependency.includes(key)); - const [pkg, importStatement, importConstantsPath] = - importConstants(packageSuffix); - const contents = - entrypointsToInclude.length > 0 - ? `\n${entrypointsToInclude - .map((key) => importStatement(key)) - .join(",\n")},\n];\n` - : "];\n"; - fs.writeFileSync( - `../${pkg}/${importConstantsPath}`, - `// Auto-generated by \`scripts/create-entrypoints.js\`. Do not edit manually.\n\nexport const optionalImportEntrypoints: string[] = [${contents}` - ); -}; - -export function createEntrypoints({ - /** - * This lists all the entrypoints for the library. Each key corresponds to an - * importable path, eg. `import { AgentExecutor } from "langchain/agents"`. - * The value is the path to the file in `src/` that exports the entrypoint. - * This is used to generate the `exports` field in package.json. - * Order is not important. - * @type {Record} - */ - entrypoints, - /** - * Entrypoints in this list require an optional dependency to be installed. - * Therefore they are not tested in the generated test-exports-* packages. - * @type {undefined | string[]} - */ - requiresOptionalDependency = [], - /** - * Entrypoints in this list will - * 1. Be excluded from the documentation - * 2. Be only available in Node.js environments (for backwards compatibility) - * @type {undefined | string[]} - */ - deprecatedNodeOnly = [], - /** - * Endpoints that are deprecated due to redundancy. Will not appear in the import map. - * @type {string[]} - */ - deprecatedOmitFromImportMap = [], - /** - * The suffix of the package. Eg. `community` for `@langchain/community`. - * Used in the generated import map. - * @type {undefined | string} - */ - packageSuffix, - /** - * Whether or not to write to the test exports files. At the moment this only - * applies to the `langchain` package. - * @type {undefined | boolean} - */ - shouldTestExports = false, - /** - * Extra entries to add to the import map. - * @type {undefined | Array} - */ - extraImportMapEntries = [], - /** - * The absolute path to the tsconfig.json file. - * @type {string} - */ - absTsConfigPath, - /** - * Whether or not the pre command was passed. - * @type {boolean} - */ - isPre, - /** - * Whether or not to generate import maps - * @type {boolean} - */ - shouldGenMaps, - /** - * Additional paths to add to the .gitignore file. - * @type {Array | undefined} - */ - additionalGitignorePaths, -}) { - if (isPre) { - cleanGenerated({ entrypoints }); - if (shouldGenMaps) { - generateImportMap({ - entrypoints, - requiresOptionalDependency, - deprecatedNodeOnly, - deprecatedOmitFromImportMap, - packageSuffix: packageSuffix ?? null, - extraImportMapEntries, - }); - generateImportTypes({ - absTsConfigPath, - packageSuffix: packageSuffix ?? null, - }); - generateImportConstants({ - entrypoints, - requiresOptionalDependency, - deprecatedNodeOnly, - packageSuffix: packageSuffix ?? null, - }); - } - } else { - updateConfig({ - entrypoints, - deprecatedNodeOnly, - requiresOptionalDependency, - shouldTestExports, - additionalGitignorePaths, - }); - } -} - - -// --------SCRIPT CONTENT-------- - -async function main() { - const program = new Command(); - program - .description("Run a build script for a LangChain package.") - .option( - "--config ", - "Path to the config file, defaults to ./langchain.config.js" - ) - .option( - "--create-entrypoints", - "Pass only if you want to create entrypoints" - ) - .option("--tree-shaking", "Pass only if you want to check tree shaking") - .option("--move-cjs-dist", "Pass only if you want to move cjs to dist") - .option("--pre") - .option("--gen-maps"); - - program.parse(); - - const options = program.opts(); - - const shouldCreateEntrypoints = options.createEntrypoints; - const shouldCheckTreeShaking = options.treeShaking; - const shouldMoveCjsDist = options.moveCjsDist; - const isPre = options.pre; - const shouldGenMaps = options.genMaps; - const configFilePath = options.config ?? "./langchain.config.js"; - const resolvedConfigPath = path.resolve(process.cwd(), configFilePath); - - /** @type {LangChainConfig} */ - let config; - try { - const { config: lcConfig } = await import(resolvedConfigPath); - if (!_verifyObjectIsLangChainConfig(lcConfig)) { - throw new Error("Invalid config object."); - } - config = lcConfig; - } catch (e) { - console.error( - `Failed to read config file at path: ${configFilePath}.\n\n${e}` - ); - process.exit(1); - } - - if ( - [shouldCreateEntrypoints, shouldCheckTreeShaking, shouldMoveCjsDist].filter( - Boolean - ).length > 1 - ) { - console.error( - "Can only run one script at a time. Please pass only one of --create-entrypoints, --tree-shaking, --move-cjs-dist" - ); - process.exit(1); - } - - if ( - [shouldCreateEntrypoints, shouldCheckTreeShaking, shouldMoveCjsDist].filter( - Boolean - ).length === 0 - ) { - console.error( - "No script specified. Please pass one of --create-entrypoints, --tree-shaking, --move-cjs-dist" - ); - process.exit(1); - } - - if ( - (isPre || shouldGenMaps) && - [shouldCheckTreeShaking, shouldMoveCjsDist].filter(Boolean).length >= 1 - ) { - console.error( - "Can not pass --pre or --gen-maps with --tree-shaking or --move-cjs-dist" - ); - process.exit(1); - } - - if (shouldCreateEntrypoints) { - createEntrypoints({ - entrypoints: config.entrypoints, - requiresOptionalDependency: config.requiresOptionalDependency, - deprecatedNodeOnly: config.deprecatedNodeOnly, - deprecatedOmitFromImportMap: config.deprecatedOmitFromImportMap, - packageSuffix: config.packageSuffix, - shouldTestExports: config.shouldTestExports, - extraImportMapEntries: config.extraImportMapEntries, - absTsConfigPath: config.tsConfigPath, - isPre, - shouldGenMaps, - additionalGitignorePaths: config.additionalGitignorePaths, - }); - } - - if (shouldCheckTreeShaking) { - await checkTreeShaking({ - extraInternals: config.internals, - }); - } - - if (shouldMoveCjsDist) { - await moveAndRename({ - source: config.cjsSource, - dest: config.cjsDestination, - abs: config.abs, - }); - } -} - -/* #__PURE__ */ main().catch((e) => { - console.error(e); - process.exit(1); -}); +import "../dist/build/index.js"; diff --git a/libs/langchain-scripts/bin/build_v2.js b/libs/langchain-scripts/bin/build_v2.js deleted file mode 100755 index 0e57864f2fe0..000000000000 --- a/libs/langchain-scripts/bin/build_v2.js +++ /dev/null @@ -1 +0,0 @@ -import "../dist/build_v2.js"; diff --git a/libs/langchain-scripts/langchain.config.js b/libs/langchain-scripts/langchain.config.js index 64ea4089853a..1d83aa030070 100644 --- a/libs/langchain-scripts/langchain.config.js +++ b/libs/langchain-scripts/langchain.config.js @@ -13,7 +13,7 @@ export const config = { internals: [/node\:/], entrypoints: { index: "index", - build: "build", + build: "build/index", migrations: "migrations/index", check_broken_links: "check_broken_links", }, diff --git a/libs/langchain-scripts/package.json b/libs/langchain-scripts/package.json index bd069a48e35f..db77d0a36d68 100644 --- a/libs/langchain-scripts/package.json +++ b/libs/langchain-scripts/package.json @@ -14,15 +14,14 @@ }, "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-scripts/", "bin": { - "lc-build": "bin/build.js", - "lc_build_v2": "bin/build_v2.js", + "lc_build": "bin/build.js", "notebook_validate": "bin/validate_notebook.js" }, "scripts": { - "build": "yarn turbo:command build:internal --filter=@langchain/scripts", + "build": "yarn clean && yarn turbo:command build:internal --filter=@langchain/scripts", "build:internal": "tsc --project ./tsconfig.build.json && yarn move:artifacts && yarn build:generated", "move:artifacts": "mkdir -p ./dist && mv ./dist_build/* ./dist/", - "build:generated": "node bin/build_v2.js --create-entrypoints --pre --tree-shaking", + "build:generated": "node bin/build.js --create-entrypoints --pre --tree-shaking", "build:turbo": "yarn turbo:command build --filter=@langchain/scripts", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", diff --git a/libs/langchain-scripts/src/build.ts b/libs/langchain-scripts/src/build.ts deleted file mode 100644 index 64468ed968e3..000000000000 --- a/libs/langchain-scripts/src/build.ts +++ /dev/null @@ -1,121 +0,0 @@ -#!/usr/bin/env node - -import { Command } from "commander"; -import path from "node:path"; -import { createEntrypoints } from "./create-entrypoints.js"; -import { checkTreeShaking } from "./check-tree-shaking.js"; -import { moveAndRename } from "./move-cjs-to-dist.js"; -import type { LangChainConfig } from "./types.js"; -import { _verifyObjectIsLangChainConfig } from "./utils.js"; - -export type { LangChainConfig } from "./types.js"; - -async function main() { - const program = new Command(); - program - .description("Run a build script for a LangChain package.") - .option( - "--config ", - "Path to the config file, defaults to ./langchain.config.js" - ) - .option( - "--create-entrypoints", - "Pass only if you want to create entrypoints" - ) - .option("--tree-shaking", "Pass only if you want to check tree shaking") - .option("--move-cjs-dist", "Pass only if you want to move cjs to dist") - .option("--pre") - .option("--gen-maps"); - - program.parse(); - - const options = program.opts(); - - const shouldCreateEntrypoints = options.createEntrypoints; - const shouldCheckTreeShaking = options.treeShaking; - const shouldMoveCjsDist = options.moveCjsDist; - const isPre = options.pre; - const shouldGenMaps = options.genMaps; - const configFilePath = options.config ?? "./langchain.config.js"; - const resolvedConfigPath = path.resolve(process.cwd(), configFilePath); - - let config: LangChainConfig; - try { - const { config: lcConfig } = await import(resolvedConfigPath); - if (!_verifyObjectIsLangChainConfig(lcConfig)) { - throw new Error("Invalid config object."); - } - config = lcConfig; - } catch (e) { - console.error( - `Failed to read config file at path: ${configFilePath}.\n\n${e}` - ); - process.exit(1); - } - - if ( - [shouldCreateEntrypoints, shouldCheckTreeShaking, shouldMoveCjsDist].filter( - Boolean - ).length > 1 - ) { - console.error( - "Can only run one script at a time. Please pass only one of --create-entrypoints, --tree-shaking, --move-cjs-dist" - ); - process.exit(1); - } - - if ( - [shouldCreateEntrypoints, shouldCheckTreeShaking, shouldMoveCjsDist].filter( - Boolean - ).length === 0 - ) { - console.error( - "No script specified. Please pass one of --create-entrypoints, --tree-shaking, --move-cjs-dist" - ); - process.exit(1); - } - - if ( - (isPre || shouldGenMaps) && - [shouldCheckTreeShaking, shouldMoveCjsDist].filter(Boolean).length >= 1 - ) { - console.error( - "Can not pass --pre or --gen-maps with --tree-shaking or --move-cjs-dist" - ); - process.exit(1); - } - - if (shouldCreateEntrypoints) { - createEntrypoints({ - entrypoints: config.entrypoints, - requiresOptionalDependency: config.requiresOptionalDependency, - deprecatedNodeOnly: config.deprecatedNodeOnly, - deprecatedOmitFromImportMap: config.deprecatedOmitFromImportMap, - packageSuffix: config.packageSuffix, - shouldTestExports: config.shouldTestExports, - extraImportMapEntries: config.extraImportMapEntries, - absTsConfigPath: config.tsConfigPath, - isPre, - shouldGenMaps, - }); - } - - if (shouldCheckTreeShaking) { - await checkTreeShaking({ - extraInternals: config.internals, - }); - } - - if (shouldMoveCjsDist) { - await moveAndRename({ - source: config.cjsSource, - dest: config.cjsDestination, - abs: config.abs, - }); - } -} - -/* #__PURE__ */ main().catch((e) => { - console.error(e); - process.exit(1); -}); diff --git a/libs/langchain-scripts/src/build_v2.ts b/libs/langchain-scripts/src/build/index.ts similarity index 93% rename from libs/langchain-scripts/src/build_v2.ts rename to libs/langchain-scripts/src/build/index.ts index 4c4b42653c60..0efb6f720379 100644 --- a/libs/langchain-scripts/src/build_v2.ts +++ b/libs/langchain-scripts/src/build/index.ts @@ -5,7 +5,8 @@ import { Command } from "commander"; import { rollup } from "@rollup/wasm-node"; import path from "node:path"; import { glob } from "glob"; -import { ExportsMapValue, ImportData, LangChainConfig } from "./types.js"; +import { setTimeout } from "node:timers/promises"; +import { ExportsMapValue, ImportData, LangChainConfig } from "../types.js"; async function asyncSpawn(command: string, args: string[]) { return new Promise((resolve, reject) => { @@ -28,47 +29,55 @@ async function asyncSpawn(command: string, args: string[]) { }); } -const deleteFolderRecursive = async function (inputPath: string) { - try { - // Verify the path exists - if ( - await fs.promises - .access(inputPath) - .then(() => true) - .catch(() => false) - ) { - const pathStat = await fs.promises.lstat(inputPath); - // If it's a file, delete it and return - if (pathStat.isFile()) { - await fs.promises.unlink(inputPath); - } else if (pathStat.isDirectory()) { - // List contents of directory - const directoryContents = await fs.promises.readdir(inputPath); - if (directoryContents.length) { - for await (const item of directoryContents) { - const itemStat = await fs.promises.lstat( - path.join(inputPath, item) - ); - if (itemStat.isFile()) { - // Delete file - await fs.promises.unlink(path.join(inputPath, item)); - } else if (itemStat.isDirectory()) { - await deleteFolderRecursive(path.join(inputPath, item)); +const deleteFolderRecursive = async function ( + inputPath: string, + retries = 3, + delay = 100 +) { + for (let attempt = 0; attempt < retries; attempt += 1) { + try { + // Verify the path exists + if ( + await fs.promises + .access(inputPath) + .then(() => true) + .catch(() => false) + ) { + const pathStat = await fs.promises.lstat(inputPath); + // If it's a file, delete it and return + if (pathStat.isFile()) { + await fs.promises.unlink(inputPath); + } else if (pathStat.isDirectory()) { + // List contents of directory + const directoryContents = await fs.promises.readdir(inputPath); + if (directoryContents.length) { + for await (const item of directoryContents) { + await deleteFolderRecursive( + path.join(inputPath, item), + retries, + delay + ); } } - } else if (directoryContents.length === 0) { - // If the directory is empty, delete it + // If the directory is empty or all contents have been deleted, delete it await fs.promises.rmdir(inputPath); } } + // If we reach here, the operation was successful + return; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (error: any) { + if (error.code === "ENOENT") { + // File or directory doesn't exist, consider it deleted + return; + } + if (attempt === retries - 1) { + // If this was the last attempt, throw the error + throw error; + } + // Wait before the next attempt + await setTimeout(delay); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (error: any) { - if (error.code !== "ENOENT") { - // If the error is not "file or directory doesn't exist", rethrow it - throw error; - } - // Otherwise, ignore the error (file or directory already doesn't exist) } }; diff --git a/libs/langchain-scripts/src/utils.ts b/libs/langchain-scripts/src/build/utils.ts similarity index 98% rename from libs/langchain-scripts/src/utils.ts rename to libs/langchain-scripts/src/build/utils.ts index 2189cdfa2c29..1f2210f87a36 100644 --- a/libs/langchain-scripts/src/utils.ts +++ b/libs/langchain-scripts/src/build/utils.ts @@ -1,4 +1,4 @@ -import { LangChainConfig } from "./types.js"; +import { LangChainConfig } from "../types.js"; export function _verifyObjectIsLangChainConfig( // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/libs/langchain-scripts/src/check-tree-shaking.ts b/libs/langchain-scripts/src/check-tree-shaking.ts deleted file mode 100644 index cabec3b60200..000000000000 --- a/libs/langchain-scripts/src/check-tree-shaking.ts +++ /dev/null @@ -1,122 +0,0 @@ -import fs from "node:fs/promises"; -import { rollup } from "rollup"; -import { ExportsMapValue, PackageJSON, TreeShakingArgs } from "./types.js"; - -async function getPackageJson(): Promise { - return JSON.parse(await fs.readFile("package.json", "utf-8")); -} - -async function listEntrypoints() { - const { exports } = await getPackageJson(); - const exportsWithoutPackageJSON: Record< - string, - ExportsMapValue | string - > | null = exports - ? Object.entries(exports) - .filter(([k]) => k !== "./package.json") - .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {}) - : null; - - if (!exportsWithoutPackageJSON) { - throw new Error("No exports found in package.json"); - } - const entrypoints: string[] = []; - - for (const [key, value] of Object.entries(exportsWithoutPackageJSON)) { - if (key === "./package.json") { - continue; - } - if (typeof value === "string") { - entrypoints.push(value); - } else if ( - "import" in value && - value.import && - typeof value.import === "string" - ) { - entrypoints.push(value.import); - } - } - - return entrypoints; -} - -/** - * - * @param {Array | undefined} extraInternals - * @default [...Object.keys(packageJson.dependencies ?? {}), ...Object.keys(packageJson.peerDependencies ?? {})] - * @returns {Promise>} - */ -async function listExternals( - extraInternals: Array -): Promise> { - const packageJson = await getPackageJson(); - return [ - ...Object.keys(packageJson.dependencies ?? {}), - ...Object.keys(packageJson.peerDependencies ?? {}), - ...extraInternals, - ]; -} - -export async function checkTreeShaking(options?: TreeShakingArgs) { - const externals = await listExternals(options?.extraInternals ?? []); - const entrypoints = await listEntrypoints(); - const consoleInfo = console.info; - const reportMap: Map< - string, - { - log: string; - hasUnexpectedSideEffects: boolean; - } - > = new Map(); - - for (const entrypoint of entrypoints) { - let sideEffects = ""; - - console.info = function (...args) { - const line = args.length ? args.join(" ") : ""; - if (line.includes("First side effect in")) { - sideEffects += `${line}\n`; - } - }; - - await rollup({ - external: externals, - input: entrypoint, - experimentalLogSideEffects: true, - }); - - let hasUnexpectedSideEffects = sideEffects.length > 0; - if (hasUnexpectedSideEffects) { - const entrypointContent = await fs.readFile( - `./dist/${entrypoint.replace(/^\.\//, "")}` - ); - // Allow escaping side effects strictly within code directly - // within an entrypoint - hasUnexpectedSideEffects = !entrypointContent - .toString() - .includes("/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */"); - } - reportMap.set(entrypoint, { - log: sideEffects, - hasUnexpectedSideEffects, - }); - } - - console.info = consoleInfo; - - let failed = false; - for (const [entrypoint, report] of reportMap) { - if (report.hasUnexpectedSideEffects) { - failed = true; - console.log("---------------------------------"); - console.log(`Tree shaking failed for ${entrypoint}`); - console.log(report.log); - } - } - - if (failed) { - throw new Error("Tree shaking checks failed."); - } else { - console.log("Tree shaking checks passed!"); - } -} diff --git a/libs/langchain-scripts/src/create-entrypoints.ts b/libs/langchain-scripts/src/create-entrypoints.ts deleted file mode 100644 index 5c96d2bbfb4d..000000000000 --- a/libs/langchain-scripts/src/create-entrypoints.ts +++ /dev/null @@ -1,385 +0,0 @@ -import * as fs from "node:fs"; -import * as path from "node:path"; -import { identifySecrets } from "./identify-secrets.js"; -import type { ExtraImportMapEntry, ImportData } from "./types.js"; - -// .gitignore -const DEFAULT_GITIGNORE_PATHS = ["node_modules", "dist", ".yarn"]; - -// List of test-exports-* packages which we use to test that the exports field -// works correctly across different JS environments. -// Each entry is a tuple of [package name, import statement]. -const testExports: Array<[string, (p: string) => string]> = [ - [ - "test-exports-esm", - (p: string) => - `import * as ${p.replace(/\//g, "_")} from "langchain/${p}";`, - ], - [ - "test-exports-esbuild", - (p: string) => - `import * as ${p.replace(/\//g, "_")} from "langchain/${p}";`, - ], - [ - "test-exports-cjs", - (p: string) => - `const ${p.replace(/\//g, "_")} = require("langchain/${p}");`, - ], - ["test-exports-cf", (p: string) => `export * from "langchain/${p}";`], - ["test-exports-vercel", (p: string) => `export * from "langchain/${p}";`], - ["test-exports-vite", (p: string) => `export * from "langchain/${p}";`], - ["test-exports-bun", (p: string) => `export * from "langchain/${p}";`], -]; - -const updateJsonFile = ( - relativePath: string, - updateFunction: (json: Record) => Record -) => { - const contents = fs.readFileSync(relativePath).toString(); - const res = updateFunction(JSON.parse(contents)); - fs.writeFileSync(relativePath, `${JSON.stringify(res, null, 2)}\n`); -}; - -const generateFiles = ( - entrypoints: Record -): Record => { - const files = [...Object.entries(entrypoints)].flatMap(([key, value]) => { - const nrOfDots = key.split("/").length - 1; - const relativePath = "../".repeat(nrOfDots) || "./"; - const compiledPath = `${relativePath}dist/${value}.js`; - return [ - [ - `${key}.cjs`, - `module.exports = require('${relativePath}dist/${value}.cjs');`, - ], - [`${key}.js`, `export * from '${compiledPath}'`], - [`${key}.d.ts`, `export * from '${compiledPath}'`], - [`${key}.d.cts`, `export * from '${compiledPath}'`], - ]; - }); - - return Object.fromEntries(files); -}; - -const updateConfig = ({ - entrypoints, - deprecatedNodeOnly, - requiresOptionalDependency, - shouldTestExports, -}: { - entrypoints: Record; - deprecatedNodeOnly: Array; - requiresOptionalDependency: Array; - shouldTestExports: boolean; -}) => { - const generatedFiles = generateFiles(entrypoints); - const filenames = Object.keys(generatedFiles); - - // Update package.json `exports` and `files` fields - updateJsonFile("./package.json", (json) => ({ - ...json, - exports: Object.assign( - Object.fromEntries( - [...Object.keys(entrypoints)].map((key) => { - const entryPoint = { - types: { - import: `./${key}.d.ts`, - require: `./${key}.d.cts`, - default: `./${key}.d.ts`, - }, - import: `./${key}.js`, - require: `./${key}.cjs`, - }; - - return [key === "index" ? "." : `./${key}`, entryPoint]; - }) - ), - { "./package.json": "./package.json" } - ), - files: ["dist/", ...filenames], - })); - - // Write generated files - Object.entries(generatedFiles).forEach(([filename, content]) => { - fs.mkdirSync(path.dirname(filename), { recursive: true }); - fs.writeFileSync(filename, content); - }); - - // Update .gitignore - fs.writeFileSync( - "./.gitignore", - `${filenames.join("\n")}\n${DEFAULT_GITIGNORE_PATHS.join("\n")}\n` - ); - - if (shouldTestExports) { - // Update test-exports-*/entrypoints.js - const entrypointsToTest = Object.keys(entrypoints) - .filter((key) => !deprecatedNodeOnly.includes(key)) - .filter((key) => !requiresOptionalDependency.includes(key)); - testExports.forEach(([pkg, importStatement]) => { - const contents = `${entrypointsToTest - .map((key) => importStatement(key)) - .join("\n")}\n`; - fs.writeFileSync( - `../environment_tests/${pkg}/src/entrypoints.js`, - contents - ); - }); - } -}; - -const cleanGenerated = ({ - entrypoints, -}: { - entrypoints: Record; -}) => { - const filenames = Object.keys(generateFiles(entrypoints)); - filenames.forEach((fname) => { - try { - fs.unlinkSync(fname); - } catch { - // ignore error - } - }); -}; - -// Tuple describing the auto-generated import map (used by langchain/load) -// [package name, import statement, import map path] -const importMap = ( - packageSuffix: string | null -): [string, (k: string, p: string) => string, string] => [ - `langchain${packageSuffix ? `-${packageSuffix}` : ""}`, - (k: string, p: string) => - `export * as ${k.replace(/\//g, "__")} from "../${p}.js";`, - "src/load/import_map.ts", -]; - -const generateImportMap = ({ - entrypoints, - requiresOptionalDependency, - deprecatedNodeOnly, - deprecatedOmitFromImportMap, - packageSuffix, - extraImportMapEntries, -}: { - entrypoints: Record; - requiresOptionalDependency: Array; - deprecatedNodeOnly: Array; - deprecatedOmitFromImportMap: Array; - packageSuffix: string | null; - extraImportMapEntries: Array; -}) => { - // Generate import map - const entrypointsToInclude = Object.keys(entrypoints) - .filter((key) => key !== "load") - .filter((key) => !deprecatedNodeOnly.includes(key)) - .filter((key) => !requiresOptionalDependency.includes(key)) - .filter((key) => !deprecatedOmitFromImportMap.includes(key)); - const [pkg, importStatement, importMapPath] = importMap(packageSuffix); - const contents = `${entrypointsToInclude - .map((key) => importStatement(key, entrypoints[key])) - .join("\n")}\n`; - const extraImportData = extraImportMapEntries.reduce( - (data, { modules, alias, path }) => { - const newData = { ...data }; - if (!newData.imports[path]) { - newData.imports[path] = []; - } - newData.imports[path] = [ - ...new Set(newData.imports[path].concat(modules)), - ]; - const exportAlias = alias.join("__"); - if (!newData.exportedAliases[exportAlias]) { - newData.exportedAliases[exportAlias] = []; - } - newData.exportedAliases[exportAlias] = - newData.exportedAliases[exportAlias].concat(modules); - return newData; - }, - { - imports: {}, - exportedAliases: {}, - } - ); - const extraImportStatements = Object.entries(extraImportData.imports).map( - ([path, modules]) => - `import {\n ${modules.join(",\n ")}\n} from "${path}";` - ); - const extraDeclarations = Object.entries(extraImportData.exportedAliases).map( - ([exportAlias, modules]) => - [ - `const ${exportAlias} = {\n ${modules.join(",\n ")}\n};`, - `export { ${exportAlias} };`, - ].join("\n") - ); - const extraContent = `${extraImportStatements.join( - "\n" - )}\n${extraDeclarations.join("\n")}\n`; - fs.writeFileSync( - `../${pkg}/${importMapPath}`, - `// Auto-generated by \`scripts/create-entrypoints.js\`. Do not edit manually.\n\n${contents}${extraContent}` - ); -}; - -const importTypes = (packageSuffix: string | null): [string, string] => [ - `langchain${packageSuffix ? `-${packageSuffix}` : ""}`, - "src/load/import_type.ts", -]; - -const generateImportTypes = ({ - absTsConfigPath, - packageSuffix, -}: { - absTsConfigPath: string; - packageSuffix: string | null; -}) => { - // Generate import types - const [pkg, importTypesPath] = importTypes(packageSuffix); - - fs.writeFileSync( - `../${pkg}/${importTypesPath}`, - `// Auto-generated by \`scripts/create-entrypoints.js\`. Do not edit manually. - -export interface OptionalImportMap {} - -export interface SecretMap { -${[...identifySecrets(absTsConfigPath)] - .sort() - .map((secret) => ` ${secret}?: string;`) - .join("\n")} -} -` - ); -}; - -const importConstants = ( - packageSuffix: string | null -): [string, (k: string) => string, string] => [ - `langchain${packageSuffix ? `-${packageSuffix}` : ""}`, - (k: string) => - ` "langchain${packageSuffix ? `_${packageSuffix}` : ""}/${k}"`, - "src/load/import_constants.ts", -]; - -const generateImportConstants = ({ - entrypoints, - requiresOptionalDependency, - deprecatedNodeOnly, - packageSuffix, -}: { - entrypoints: Record; - requiresOptionalDependency: Array; - deprecatedNodeOnly: Array; - packageSuffix: string | null; -}) => { - // Generate import constants - const entrypointsToInclude = Object.keys(entrypoints) - .filter((key) => !deprecatedNodeOnly.includes(key)) - .filter((key) => requiresOptionalDependency.includes(key)); - const [pkg, importStatement, importConstantsPath] = - importConstants(packageSuffix); - const contents = - entrypointsToInclude.length > 0 - ? `\n${entrypointsToInclude - .map((key) => importStatement(key)) - .join(",\n")},\n];\n` - : "];\n"; - fs.writeFileSync( - `../${pkg}/${importConstantsPath}`, - `// Auto-generated by \`scripts/create-entrypoints.js\`. Do not edit manually.\n\nexport const optionalImportEntrypoints: string[] = [${contents}` - ); -}; - -export function createEntrypoints({ - entrypoints, - requiresOptionalDependency = [], - deprecatedNodeOnly = [], - deprecatedOmitFromImportMap = [], - packageSuffix, - shouldTestExports = false, - extraImportMapEntries = [], - absTsConfigPath, - isPre, - shouldGenMaps, -}: { - /** - * This lists all the entrypoints for the library. Each key corresponds to an - * importable path, eg. `import { AgentExecutor } from "langchain/agents"`. - * The value is the path to the file in `src/` that exports the entrypoint. - * This is used to generate the `exports` field in package.json. - * Order is not important. - */ - entrypoints: Record; - /** - * Entrypoints in this list require an optional dependency to be installed. - * Therefore they are not tested in the generated test-exports-* packages. - */ - requiresOptionalDependency?: string[]; - /** - * Entrypoints in this list will - * 1. Be excluded from the documentation - * 2. Be only available in Node.js environments (for backwards compatibility) - */ - deprecatedNodeOnly?: string[]; - /** - * Endpoints that are deprecated due to redundancy. Will not appear in the import map. - */ - deprecatedOmitFromImportMap?: string[]; - /** - * The suffix of the package. Eg. `community` for `@langchain/community`. - * Used in the generated import map. - */ - packageSuffix?: string; - /** - * Whether or not to write to the test exports files. At the moment this only - * applies to the `langchain` package. - */ - shouldTestExports?: boolean; - /** - * Extra entries to add to the import map. - */ - extraImportMapEntries?: Array; - /** - * The absolute path to the tsconfig.json file. - */ - absTsConfigPath: string; - /** - * Whether or not the pre command was passed. - */ - isPre: boolean; - /** - * Whether or not to generate import maps - */ - shouldGenMaps: boolean; -}) { - if (isPre) { - cleanGenerated({ entrypoints }); - if (shouldGenMaps) { - generateImportMap({ - entrypoints, - requiresOptionalDependency, - deprecatedNodeOnly, - deprecatedOmitFromImportMap, - packageSuffix: packageSuffix ?? null, - extraImportMapEntries, - }); - generateImportTypes({ - absTsConfigPath, - packageSuffix: packageSuffix ?? null, - }); - generateImportConstants({ - entrypoints, - requiresOptionalDependency, - deprecatedNodeOnly, - packageSuffix: packageSuffix ?? null, - }); - } - } else { - updateConfig({ - entrypoints, - deprecatedNodeOnly, - requiresOptionalDependency, - shouldTestExports, - }); - } -} diff --git a/libs/langchain-scripts/src/identify-secrets.ts b/libs/langchain-scripts/src/identify-secrets.ts deleted file mode 100644 index fe26009acd9c..000000000000 --- a/libs/langchain-scripts/src/identify-secrets.ts +++ /dev/null @@ -1,100 +0,0 @@ -import ts from "typescript"; -import * as fs from "node:fs"; - -export function identifySecrets(absTsConfigPath: string) { - const secrets = new Set(); - - const tsConfig = ts.parseJsonConfigFileContent( - ts.readJsonConfigFile(absTsConfigPath, (p) => fs.readFileSync(p, "utf-8")), - ts.sys, - "./src/" - ); - - // `tsConfig.options.target` is not always defined when running this - // via the `@langchain/scripts` package. Instead, fallback to the raw - // tsConfig.json file contents. - const tsConfigFileContentsText = - "text" in tsConfig.raw - ? JSON.parse(tsConfig.raw.text as string) - : { compilerOptions: {} }; - - const tsConfigTarget = - tsConfig.options.target || tsConfigFileContentsText.compilerOptions.target; - - for (const fileName of tsConfig.fileNames.filter( - (fn) => !fn.endsWith("test.ts") - )) { - if (!tsConfigTarget) { - continue; - } - - const sourceFile = ts.createSourceFile( - fileName, - fs.readFileSync(fileName, "utf-8"), - tsConfigTarget, - true - ); - - sourceFile.forEachChild((node) => { - switch (node.kind) { - case ts.SyntaxKind.ClassDeclaration: - case ts.SyntaxKind.ClassExpression: { - node.forEachChild((node) => { - // look for get lc_secrets() - switch (node.kind) { - case ts.SyntaxKind.GetAccessor: { - const property = node; - if ( - ts.isGetAccessor(property) && - property.name.getText() === "lc_secrets" - ) { - // look for return { ... } - property.body?.statements.forEach((stmt) => { - if ( - ts.isReturnStatement(stmt) && - stmt.expression && - ts.isObjectLiteralExpression(stmt.expression) - ) { - stmt.expression.properties.forEach((element) => { - if (ts.isPropertyAssignment(element)) { - // Type guard for PropertyAssignment - if ( - element.initializer && - ts.isStringLiteral(element.initializer) - ) { - const secret = element.initializer.text; - - if (secret.toUpperCase() !== secret) { - throw new Error( - `Secret identifier must be uppercase: ${secret} at ${fileName}` - ); - } - if (/\s/.test(secret)) { - throw new Error( - `Secret identifier must not contain whitespace: ${secret} at ${fileName}` - ); - } - - secrets.add(secret); - } - } - }); - } - }); - } - break; - } - default: - break; - } - }); - break; - } - default: - break; - } - }); - } - - return secrets; -} diff --git a/libs/langchain-scripts/src/move-cjs-to-dist.ts b/libs/langchain-scripts/src/move-cjs-to-dist.ts deleted file mode 100644 index b809cb206ef6..000000000000 --- a/libs/langchain-scripts/src/move-cjs-to-dist.ts +++ /dev/null @@ -1,55 +0,0 @@ -import path from "node:path"; -import fs from "node:fs"; - -export async function moveAndRename({ - source, - dest, - abs, -}: { - source: string; - dest: string; - abs: (p: string) => string; -}) { - try { - for (const file of await fs.promises.readdir(abs(source), { - withFileTypes: true, - })) { - if (file.isDirectory()) { - await moveAndRename({ - source: `${source}/${file.name}`, - dest: `${dest}/${file.name}`, - abs, - }); - } else if (file.isFile()) { - const parsed = path.parse(file.name); - - // Ignore anything that's not a .js file - if (parsed.ext !== ".js") { - continue; - } - - // Rewrite any require statements to use .cjs - const content = await fs.promises.readFile( - abs(`${source}/${file.name}`), - "utf8" - ); - const rewritten = content.replace( - /require\("(\..+?).js"\)/g, - (_, p1) => `require("${p1}.cjs")` - ); - - // Rename the file to .cjs - const renamed = path.format({ name: parsed.name, ext: ".cjs" }); - - await fs.promises.writeFile( - abs(`${dest}/${renamed}`), - rewritten, - "utf8" - ); - } - } - } catch (err) { - console.error(err); - process.exit(1); - } -} diff --git a/libs/langchain-scripts/src/tests/config_file.test.ts b/libs/langchain-scripts/src/tests/config_file.test.ts index 2d1c64d5e92a..c1a92e109e07 100644 --- a/libs/langchain-scripts/src/tests/config_file.test.ts +++ b/libs/langchain-scripts/src/tests/config_file.test.ts @@ -1,5 +1,5 @@ import { test, expect } from "@jest/globals"; -import { _verifyObjectIsLangChainConfig } from "../utils.js"; +import { _verifyObjectIsLangChainConfig } from "../build/utils.js"; test("_verifyObjectIsLangChainConfig successfully fails an invalid object", async () => { const { config } = await import("./langchain.invalid.config.js"); diff --git a/libs/langchain-scripts/tsconfig.build.json b/libs/langchain-scripts/tsconfig.build.json index 191e76c228c2..23cde926083d 100644 --- a/libs/langchain-scripts/tsconfig.build.json +++ b/libs/langchain-scripts/tsconfig.build.json @@ -23,8 +23,7 @@ "strict": true }, "include": [ - "src/build_v2.ts", - "src/types.ts" + "src/build/*" ], "exclude": [ "node_modules/", diff --git a/libs/langchain-standard-tests/package.json b/libs/langchain-standard-tests/package.json index 529be1d4445c..2cedaaccd878 100644 --- a/libs/langchain-standard-tests/package.json +++ b/libs/langchain-standard-tests/package.json @@ -15,7 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-standard-tests/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/standard-tests", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", diff --git a/libs/langchain-textsplitters/package.json b/libs/langchain-textsplitters/package.json index 65869485c723..67bfea71f685 100644 --- a/libs/langchain-textsplitters/package.json +++ b/libs/langchain-textsplitters/package.json @@ -15,11 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-textsplitters/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/textsplitters", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -31,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-weaviate/package.json b/libs/langchain-weaviate/package.json index 521f99b02a31..c29d97674172 100644 --- a/libs/langchain-weaviate/package.json +++ b/libs/langchain-weaviate/package.json @@ -15,12 +15,7 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-weaviate/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/weaviate", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:deps": "yarn run turbo:command build --filter=@langchain/core", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", @@ -32,10 +27,7 @@ "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/libs/langchain-yandex/package.json b/libs/langchain-yandex/package.json index 21e3cf3eb257..fce662e8c06d 100644 --- a/libs/langchain-yandex/package.json +++ b/libs/langchain-yandex/package.json @@ -15,27 +15,19 @@ "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-yandex/", "scripts": { "build": "yarn turbo:command build:internal --filter=@langchain/yandex", - "build:internal": "yarn lc_build_v2 --create-entrypoints --pre --tree-shaking", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", "clean": "rm -rf .turbo dist/", "prepack": "yarn build", - "release": "release-it --only-version --config .release-it.json", "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", diff --git a/yarn.lock b/yarn.lock index c2c007140bf3..7375b4850f0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12438,8 +12438,7 @@ __metadata: tsx: ^4.16.2 typescript: ^5.4.5 bin: - lc-build: bin/build.js - lc_build_v2: bin/build_v2.js + lc_build: bin/build.js notebook_validate: bin/validate_notebook.js languageName: unknown linkType: soft