diff --git a/packages/connect-express/package.json b/packages/connect-express/package.json index 1cac9bef9..d4cdbce17 100644 --- a/packages/connect-express/package.json +++ b/packages/connect-express/package.json @@ -9,10 +9,9 @@ }, "scripts": { "clean": "rm -rf ./dist/*", - "build": "npm run build:cjs && npm run build:esm && npm run build:proxy", + "build": "npm run build:cjs && npm run build:esm", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", - "build:proxy": "node ../../scripts/gen-esm-proxy.mjs .", "attw": "attw --pack" }, "type": "module", @@ -20,11 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "node": { - "import": "./dist/proxy/index.js", - "require": "./dist/cjs/index.js" - }, - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" } diff --git a/packages/connect-fastify/package.json b/packages/connect-fastify/package.json index f95105e72..c2bd6b685 100644 --- a/packages/connect-fastify/package.json +++ b/packages/connect-fastify/package.json @@ -9,10 +9,9 @@ }, "scripts": { "clean": "rm -rf ./dist/*", - "build": "npm run build:cjs && npm run build:esm && npm run build:proxy", + "build": "npm run build:cjs && npm run build:esm", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", - "build:proxy": "node ../../scripts/gen-esm-proxy.mjs .", "attw": "attw --pack" }, "type": "module", @@ -20,11 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "node": { - "import": "./dist/proxy/index.js", - "require": "./dist/cjs/index.js" - }, - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" } diff --git a/packages/connect-next/package.json b/packages/connect-next/package.json index d0505aca0..fe3c53db2 100644 --- a/packages/connect-next/package.json +++ b/packages/connect-next/package.json @@ -9,10 +9,9 @@ }, "scripts": { "clean": "rm -rf ./dist/*", - "build": "npm run build:cjs && npm run build:esm && npm run build:proxy", + "build": "npm run build:cjs && npm run build:esm", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", - "build:proxy": "node ../../scripts/gen-esm-proxy.mjs .", "attw": "attw --pack" }, "type": "module", @@ -20,11 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "node": { - "import": "./dist/proxy/index.js", - "require": "./dist/cjs/index.js" - }, - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" } diff --git a/packages/connect-node/package.json b/packages/connect-node/package.json index 1e4ff3643..adf299dc7 100644 --- a/packages/connect-node/package.json +++ b/packages/connect-node/package.json @@ -9,10 +9,9 @@ }, "scripts": { "clean": "rm -rf ./dist/*", - "build": "npm run build:cjs && npm run build:esm && npm run build:proxy", + "build": "npm run build:cjs && npm run build:esm", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", - "build:proxy": "node ../../scripts/gen-esm-proxy.mjs .", "attw": "attw --pack", "jasmine": "jasmine --config=jasmine.json" }, @@ -20,11 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "node": { - "import": "./dist/proxy/index.js", - "require": "./dist/cjs/index.js" - }, - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" } diff --git a/packages/connect-web/package.json b/packages/connect-web/package.json index 21613a4fd..525d6b5a1 100644 --- a/packages/connect-web/package.json +++ b/packages/connect-web/package.json @@ -9,10 +9,9 @@ }, "scripts": { "clean": "rm -rf ./dist/*", - "build": "npm run build:cjs && npm run build:esm && npm run build:proxy", + "build": "npm run build:cjs && npm run build:esm", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", - "build:proxy": "node ../../scripts/gen-esm-proxy.mjs .", "attw": "attw --pack" }, "type": "module", @@ -20,11 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "node": { - "import": "./dist/proxy/index.js", - "require": "./dist/cjs/index.js" - }, - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" } diff --git a/packages/connect/package.json b/packages/connect/package.json index 6318d224e..51d1397e5 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -11,10 +11,9 @@ "scripts": { "clean": "rm -rf ./dist/*", "generate": "buf generate src/protocol-grpc/proto", - "build": "npm run build:cjs && npm run build:esm && npm run build:proxy && node scripts/update-user-agent.mjs", + "build": "npm run build:cjs && npm run build:esm && node scripts/update-user-agent.mjs", "build:cjs": "tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'", "build:esm": "tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm", - "build:proxy": "node ../../scripts/gen-esm-proxy.mjs . protocol protocol-connect protocol-grpc protocol-grpc-web", "jasmine": "jasmine --config=jasmine.json", "attw": "attw --pack" }, @@ -23,47 +22,22 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "node": { - "import": "./dist/proxy/index.js", - "require": "./dist/cjs/index.js" - }, - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" }, "./protocol": { - "node": { - "import": "./dist/proxy/protocol/index.js", - "require": "./dist/cjs/protocol/index.js" - }, - "module": "./dist/esm/protocol/index.js", "import": "./dist/esm/protocol/index.js", "require": "./dist/cjs/protocol/index.js" }, "./protocol-connect": { - "node": { - "import": "./dist/proxy/protocol-connect/index.js", - "require": "./dist/cjs/protocol-connect/index.js" - }, - "module": "./dist/esm/protocol-connect/index.js", "import": "./dist/esm/protocol-connect/index.js", "require": "./dist/cjs/protocol-connect/index.js" }, "./protocol-grpc": { - "node": { - "import": "./dist/proxy/protocol-grpc/index.js", - "require": "./dist/cjs/protocol-grpc/index.js" - }, - "module": "./dist/esm/protocol-grpc/index.js", "import": "./dist/esm/protocol-grpc/index.js", "require": "./dist/cjs/protocol-grpc/index.js" }, "./protocol-grpc-web": { - "node": { - "import": "./dist/proxy/protocol-grpc-web/index.js", - "require": "./dist/cjs/protocol-grpc-web/index.js" - }, - "module": "./dist/esm/protocol-grpc-web/index.js", "import": "./dist/esm/protocol-grpc-web/index.js", "require": "./dist/cjs/protocol-grpc-web/index.js" } diff --git a/scripts/gen-esm-proxy.mjs b/scripts/gen-esm-proxy.mjs deleted file mode 100644 index b15b9e52c..000000000 --- a/scripts/gen-esm-proxy.mjs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2021-2024 The Connect Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; -import * as path from "node:path"; -import { exit, stderr, stdout, argv } from "node:process"; - -const args = argv.slice(2); - -if (args.length === 0) { - stdout.write(`USAGE: ${path.basename(argv[1])} [...path] -path: One or more subpath exports. A dot (.) is valid. - -Generates ESM wrappers for dual packages. - -Example: - - ${path.basename(argv[1])} . foo - -Assumes that the following CJS artifacts exist: - - dist/cjs - ├── index.d.ts - ├── index.js - └── foo - ├── index.d.ts - └── index.js - -Generates the following ESM wrappers: - - dist/proxy - ├── index.d.ts - ├── index.js - └── foo - ├── index.d.ts - └── index.js - -package.json must contain: - - "type": "module", - "exports": { - ".": { - "require": "./dist/cjs/index.js", - "import": "./dist/proxy/index.js" - }, - "./protocol": { - "require": "./dist/cjs/foo/index.js", - "import": "./dist/proxy/foo/index.js" - }, - -Known limitations: -- expects CJS files with a .js extension, not .cjs -- does not support default exports -- supports only simple subpath directory exports, assuming a index.js file -- does not support export patterns -`); - exit(1); -} - -const cjsDist = "dist/cjs"; -const proxyDist = "dist/proxy"; - -const packageType = readPackageJsonType(); -if (packageType !== "module") { - stderr.write(`package.json is missing "type": "module" field.\n`); - exit(1); -} - -for (const subpath of args) { - const cjsPath = path.join(cjsDist, subpath, "index.js"); - if (!existsSync(cjsPath)) { - stderr.write( - `CommonJS artifact for subpath "${subpath}" not found at expected path ${cjsPath}\n`, - ); - exit(1); - } - const proxyDir = path.join(proxyDist, subpath); - if (!existsSync(proxyDir)) { - mkdirSync(proxyDir, { recursive: true }); - } - const cjsImportPath = path.relative(proxyDir, cjsPath); - writeFileSync( - path.join(proxyDir, "index.js"), - `export * from "${cjsImportPath}";\n`, - ); - writeFileSync( - path.join(proxyDir, "index.d.ts"), - `export * from "${cjsImportPath}";\n`, - ); -} - -/** - * @return {"commonjs"|"module"} - */ -function readPackageJsonType() { - const pkgString = readFileSync("package.json", "utf-8"); - const pkg = JSON.parse(pkgString); - const t = pkg.type; - if (typeof t !== "string") { - return "commonjs"; - } - if (t.toLowerCase() === "module") { - return "module"; - } - return "commonjs"; -}