From e66d9e03dbdd7bdc10289a6841bb90e86a9fc315 Mon Sep 17 00:00:00 2001 From: Steve Ayers Date: Tue, 13 Feb 2024 10:49:34 -0500 Subject: [PATCH 1/4] Remove node export condition --- packages/connect-express/package.json | 4 ---- packages/connect-fastify/package.json | 4 ---- packages/connect-next/package.json | 4 ---- packages/connect-node/package.json | 4 ---- packages/connect-web/package.json | 4 ---- packages/connect/package.json | 20 -------------------- 6 files changed, 40 deletions(-) diff --git a/packages/connect-express/package.json b/packages/connect-express/package.json index 1cac9bef9..8396d1674 100644 --- a/packages/connect-express/package.json +++ b/packages/connect-express/package.json @@ -20,10 +20,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..050cce11f 100644 --- a/packages/connect-fastify/package.json +++ b/packages/connect-fastify/package.json @@ -20,10 +20,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..621351971 100644 --- a/packages/connect-next/package.json +++ b/packages/connect-next/package.json @@ -20,10 +20,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..fed669a39 100644 --- a/packages/connect-node/package.json +++ b/packages/connect-node/package.json @@ -20,10 +20,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..b5526eb91 100644 --- a/packages/connect-web/package.json +++ b/packages/connect-web/package.json @@ -20,10 +20,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..0897d15b2 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -23,46 +23,26 @@ "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" From 682e5289c528f0748dbfcab3ec4b31e775f1efd7 Mon Sep 17 00:00:00 2001 From: Steve Ayers Date: Thu, 15 Feb 2024 18:14:17 -0500 Subject: [PATCH 2/4] Remove module condition --- packages/connect/package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/connect/package.json b/packages/connect/package.json index 0897d15b2..ea1637ce3 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -23,27 +23,22 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" }, "./protocol": { - "module": "./dist/esm/protocol/index.js", "import": "./dist/esm/protocol/index.js", "require": "./dist/cjs/protocol/index.js" }, "./protocol-connect": { - "module": "./dist/esm/protocol-connect/index.js", "import": "./dist/esm/protocol-connect/index.js", "require": "./dist/cjs/protocol-connect/index.js" }, "./protocol-grpc": { - "module": "./dist/esm/protocol-grpc/index.js", "import": "./dist/esm/protocol-grpc/index.js", "require": "./dist/cjs/protocol-grpc/index.js" }, "./protocol-grpc-web": { - "module": "./dist/esm/protocol-grpc-web/index.js", "import": "./dist/esm/protocol-grpc-web/index.js", "require": "./dist/cjs/protocol-grpc-web/index.js" } From 6c6f89c2add090ba4f5251ab82924cbcee867316 Mon Sep 17 00:00:00 2001 From: Steve Ayers Date: Thu, 15 Feb 2024 18:18:32 -0500 Subject: [PATCH 3/4] Remove proxy script --- packages/connect-express/package.json | 3 +- packages/connect-fastify/package.json | 3 +- packages/connect-next/package.json | 3 +- packages/connect-node/package.json | 3 +- packages/connect-web/package.json | 3 +- packages/connect/package.json | 3 +- scripts/gen-esm-proxy.mjs | 117 -------------------------- 7 files changed, 6 insertions(+), 129 deletions(-) delete mode 100644 scripts/gen-esm-proxy.mjs diff --git a/packages/connect-express/package.json b/packages/connect-express/package.json index 8396d1674..ad3b1d306 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", diff --git a/packages/connect-fastify/package.json b/packages/connect-fastify/package.json index 050cce11f..fbeeac6e0 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", diff --git a/packages/connect-next/package.json b/packages/connect-next/package.json index 621351971..9d3f0548b 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", diff --git a/packages/connect-node/package.json b/packages/connect-node/package.json index fed669a39..0a3277c78 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" }, diff --git a/packages/connect-web/package.json b/packages/connect-web/package.json index b5526eb91..6535a3152 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", diff --git a/packages/connect/package.json b/packages/connect/package.json index ea1637ce3..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" }, 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"; -} From 91b09c34b6428e300ff27ee592d9acdf64d33f25 Mon Sep 17 00:00:00 2001 From: Steve Ayers Date: Thu, 15 Feb 2024 18:20:08 -0500 Subject: [PATCH 4/4] Remove module condition in all places --- packages/connect-express/package.json | 1 - packages/connect-fastify/package.json | 1 - packages/connect-next/package.json | 1 - packages/connect-node/package.json | 1 - packages/connect-web/package.json | 1 - 5 files changed, 5 deletions(-) diff --git a/packages/connect-express/package.json b/packages/connect-express/package.json index ad3b1d306..d4cdbce17 100644 --- a/packages/connect-express/package.json +++ b/packages/connect-express/package.json @@ -19,7 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "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 fbeeac6e0..c2bd6b685 100644 --- a/packages/connect-fastify/package.json +++ b/packages/connect-fastify/package.json @@ -19,7 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "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 9d3f0548b..fe3c53db2 100644 --- a/packages/connect-next/package.json +++ b/packages/connect-next/package.json @@ -19,7 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "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 0a3277c78..adf299dc7 100644 --- a/packages/connect-node/package.json +++ b/packages/connect-node/package.json @@ -19,7 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "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 6535a3152..525d6b5a1 100644 --- a/packages/connect-web/package.json +++ b/packages/connect-web/package.json @@ -19,7 +19,6 @@ "main": "./dist/cjs/index.js", "exports": { ".": { - "module": "./dist/esm/index.js", "import": "./dist/esm/index.js", "require": "./dist/cjs/index.js" }