Skip to content

Commit 84a09dd

Browse files
authored
Backport dual-build (and CI improvements) from express5 (#12)
1 parent 7d1faf4 commit 84a09dd

File tree

7 files changed

+56
-12
lines changed

7 files changed

+56
-12
lines changed

.changeset/tame-carpets-beam.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@as-integrations/express4': minor
3+
---
4+
5+
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.

.github/workflows/ci.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
name: CI
22

33
on:
4-
pull_request
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
# So you can add a label to make it run, including no-changeset-needed
10+
- labeled
11+
- unlabeled
512

613
jobs:
714
build-and-test:
@@ -61,11 +68,11 @@ jobs:
6168
changeset:
6269
runs-on: ubuntu-latest
6370
name: Changesets
71+
if: ${{ (! startsWith(github.head_ref, 'changeset-release/')) && (!contains(github.event.pull_request.labels.*.name, 'no-changeset-needed')) }}
6472
steps:
6573
- uses: actions/checkout@v4
6674
with:
6775
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
6876
fetch-depth: 0
6977
- uses: ./.github/actions/node
7078
- run: npm run changeset-check
71-
if: ${{ ! startsWith(github.head_ref, 'changeset-release/') }}

package.json

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,31 @@
1212
"bugs": {
1313
"url": "https://github.com/apollo-server-integrations/apollo-server-integration-express4/issues"
1414
},
15-
"main": "dist/index.js",
16-
"types": "dist/index.d.ts",
15+
"type": "module",
16+
"main": "dist/cjs/index.js",
17+
"module": "dist/esm/index.js",
18+
"types": "dist/esm/index.d.ts",
19+
"exports": {
20+
".": {
21+
"types": {
22+
"require": "./dist/cjs/index.d.ts",
23+
"default": "./dist/esm/index.d.ts"
24+
},
25+
"import": "./dist/esm/index.js",
26+
"require": "./dist/cjs/index.js"
27+
}
28+
},
1729
"engines": {
1830
"node": ">=20"
1931
},
2032
"scripts": {
21-
"build": "tsc --build tsconfig.build.json",
33+
"compile": "tsc --build tsconfig.build.json",
34+
"postcompile": "echo '{\"type\":\"module\"}' > dist/esm/package.json && echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
2235
"clean": "git clean -dfqX",
23-
"prepack": "npm run build",
36+
"prepack": "npm run compile",
2437
"prettier-check": "prettier --check .",
2538
"prettier-fix": "prettier --write .",
26-
"changeset-publish": "npm run build && changeset publish",
39+
"changeset-publish": "npm run compile && changeset publish",
2740
"changeset-check": "changeset status --verbose --since=origin/main",
2841
"changeset-version": "changeset version && npm i",
2942
"spell-check": "cspell lint '**' --no-progress || (echo 'Add any real words to cspell-dict.txt.'; exit 1)",

tsconfig.base.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"compilerOptions": {
3+
"composite": true,
34
"rootDir": "./src",
4-
"outDir": "./dist",
5+
"outDir": "./dist/esm",
56
"target": "es2020",
6-
"module": "commonjs",
7+
"module": "esnext",
78
"moduleResolution": "node",
89
"esModuleInterop": true,
910
"sourceMap": true,

tsconfig.build.cjs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.build.esm.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./dist/cjs"
6+
}
7+
}

tsconfig.build.esm.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"include": ["src/**/*"],
4+
"exclude": ["**/__tests__"]
5+
}

tsconfig.build.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
2-
"extends": "./tsconfig.base.json",
3-
"include": ["src/**/*"],
4-
"exclude": ["**/__tests__"],
2+
"compilerOptions": {
3+
"composite": true
4+
},
5+
"files": [],
6+
"include": [],
7+
"references": [
8+
{ "path": "./tsconfig.build.esm.json" },
9+
{ "path": "./tsconfig.build.cjs.json" }
10+
]
511
}

0 commit comments

Comments
 (0)