From 369fe95e3f42bda208e78c78c36be90db6bef81b Mon Sep 17 00:00:00 2001 From: David Glasser Date: Fri, 6 Jun 2025 22:38:17 -0700 Subject: [PATCH] Backport dual-build (and CI improvements) from express5 --- .changeset/tame-carpets-beam.md | 5 +++++ .github/workflows/ci.yml | 11 +++++++++-- package.json | 23 ++++++++++++++++++----- tsconfig.base.json | 5 +++-- tsconfig.build.cjs.json | 7 +++++++ tsconfig.build.esm.json | 5 +++++ tsconfig.build.json | 12 +++++++++--- 7 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 .changeset/tame-carpets-beam.md create mode 100644 tsconfig.build.cjs.json create mode 100644 tsconfig.build.esm.json diff --git a/.changeset/tame-carpets-beam.md b/.changeset/tame-carpets-beam.md new file mode 100644 index 0000000..5362ba9 --- /dev/null +++ b/.changeset/tame-carpets-beam.md @@ -0,0 +1,5 @@ +--- +'@as-integrations/express4': minor +--- + +The package is now built for both CJS and ESM, instead of only for CJS; this is the same build approach taken by `@apollo/server`. This provides better compatibility with ESM-based build systems. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c2f180..59aee80 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,14 @@ name: CI on: - pull_request + pull_request: + types: + - opened + - reopened + - synchronize + # So you can add a label to make it run, including no-changeset-needed + - labeled + - unlabeled jobs: build-and-test: @@ -61,6 +68,7 @@ jobs: changeset: runs-on: ubuntu-latest name: Changesets + if: ${{ (! startsWith(github.head_ref, 'changeset-release/')) && (!contains(github.event.pull_request.labels.*.name, 'no-changeset-needed')) }} steps: - uses: actions/checkout@v4 with: @@ -68,4 +76,3 @@ jobs: fetch-depth: 0 - uses: ./.github/actions/node - run: npm run changeset-check - if: ${{ ! startsWith(github.head_ref, 'changeset-release/') }} diff --git a/package.json b/package.json index 35ecfb8..56b53a6 100644 --- a/package.json +++ b/package.json @@ -12,18 +12,31 @@ "bugs": { "url": "https://github.com/apollo-server-integrations/apollo-server-integration-express4/issues" }, - "main": "dist/index.js", - "types": "dist/index.d.ts", + "type": "module", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "dist/esm/index.d.ts", + "exports": { + ".": { + "types": { + "require": "./dist/cjs/index.d.ts", + "default": "./dist/esm/index.d.ts" + }, + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + } + }, "engines": { "node": ">=20" }, "scripts": { - "build": "tsc --build tsconfig.build.json", + "compile": "tsc --build tsconfig.build.json", + "postcompile": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json", "clean": "git clean -dfqX", - "prepack": "npm run build", + "prepack": "npm run compile", "prettier-check": "prettier --check .", "prettier-fix": "prettier --write .", - "changeset-publish": "npm run build && changeset publish", + "changeset-publish": "npm run compile && changeset publish", "changeset-check": "changeset status --verbose --since=origin/main", "changeset-version": "changeset version && npm i", "spell-check": "cspell lint '**' --no-progress || (echo 'Add any real words to cspell-dict.txt.'; exit 1)", diff --git a/tsconfig.base.json b/tsconfig.base.json index 63a2e7d..cf4dc8b 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1,9 +1,10 @@ { "compilerOptions": { + "composite": true, "rootDir": "./src", - "outDir": "./dist", + "outDir": "./dist/esm", "target": "es2020", - "module": "commonjs", + "module": "esnext", "moduleResolution": "node", "esModuleInterop": true, "sourceMap": true, diff --git a/tsconfig.build.cjs.json b/tsconfig.build.cjs.json new file mode 100644 index 0000000..808c81b --- /dev/null +++ b/tsconfig.build.cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.build.esm.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "./dist/cjs" + } +} \ No newline at end of file diff --git a/tsconfig.build.esm.json b/tsconfig.build.esm.json new file mode 100644 index 0000000..5106133 --- /dev/null +++ b/tsconfig.build.esm.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.base.json", + "include": ["src/**/*"], + "exclude": ["**/__tests__"] +} \ No newline at end of file diff --git a/tsconfig.build.json b/tsconfig.build.json index 555be5d..df681aa 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -1,5 +1,11 @@ { - "extends": "./tsconfig.base.json", - "include": ["src/**/*"], - "exclude": ["**/__tests__"], + "compilerOptions": { + "composite": true + }, + "files": [], + "include": [], + "references": [ + { "path": "./tsconfig.build.esm.json" }, + { "path": "./tsconfig.build.cjs.json" } + ] }