-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test for
composite: true
errors in CI, ensuring we can't ship those…
… issues (#501) ## Summary <!-- Succinctly describe your change, providing context, what you've changed, and why. --> We've seen some issues crop up when `composite: true` is present in `tsconfig.json` files. This PR adds a `composite: true` project where we test the Inngest package for compliance for the types that it exports. We purposefully want to limit the number of types exported from the main `"inngest"` entrypoint, as each type exported here becomes part of the public API, where changing those types is a breaking change. Therefore, the composite check gives us a (albeit inaccurate) test that can stop us shipping these dangerous changes. ## Checklist <!-- Tick these items off as you progress. --> <!-- If an item isn't applicable, ideally please strikeout the item by wrapping it in "~~"" and suffix it with "N/A My reason for skipping this." --> <!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" --> - [ ] ~Added a [docs PR](https://github.com/inngest/website) that references this PR~ N/A Bug fix and testing - [x] Added unit/integration tests - [x] Added changesets if applicable ## Related <!-- A space for any related links, issues, or PRs. --> <!-- Linear issues are autolinked. --> <!-- e.g. - INN-123 --> <!-- GitHub issues/PRs can be linked using shorthand. --> <!-- e.g. "- inngest/inngest#123" --> <!-- Feel free to remove this section if there are no applicable related links.--> - #384 - #385 - #437 - #460
- Loading branch information
1 parent
1b9f101
commit 0048c94
Showing
12 changed files
with
218 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"inngest": patch | ||
--- | ||
|
||
Fix failures for `composite: true` errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
dist | ||
tsconfig.tsbuildinfo | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Composite test project | ||
|
||
## What is this? | ||
|
||
This is a small project that uses `composite: true` in a `tsconfig.json` file. | ||
|
||
Projects with this setting require that imported packages directly export all | ||
types that are needed for inference from the entrypoint. | ||
|
||
Every type we export is also part of the public API of a project; breaking | ||
changes to those types are breaking changes for the package, too. Having a large | ||
number of internal types exported at the entrypoint can make it very difficult | ||
to avoid bumping the major version number. | ||
|
||
## How do I use it? | ||
|
||
You should test against this package by running `pnpm run test:composite` in | ||
`packages/inngest`. This will: | ||
- Build and pack `inngest` | ||
- Install the packaged `inngest` into the composite project | ||
- Attempt to build the project using `tsc` | ||
|
||
Any inference errors will appear as a TS2742 error, like so: | ||
``` | ||
src/index.ts:3:14 - error TS2742: The inferred type of 'inngest' cannot be named without a reference to '../node_modules/inngest/types'. This is likely not portable. A type annotation is necessary. | ||
``` | ||
|
||
## Do I need to update it? | ||
|
||
The main tests this project is performing is that types are correctly inferred | ||
by the various functions exported by the `"inngest"`. Therefore, if adding new | ||
API methods and calls, it's ideal to add them into this project. | ||
|
||
This code is only built and is never run, so don't worry about it actually | ||
working. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "t_composite_test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tsc --build --force" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"typescript": "^5.3.3" | ||
}, | ||
"dependencies": { | ||
"inngest": "file:../../inngest.tgz" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as Inngest from "inngest"; | ||
|
||
export const inngest = new Inngest.Inngest({ | ||
id: "me", | ||
schemas: new Inngest.EventSchemas().fromRecord<{ | ||
foo: { data: { foo: string } }; | ||
bar: { data: { bar: string } }; | ||
}>(), | ||
middleware: [ | ||
new Inngest.InngestMiddleware({ | ||
name: "foo", | ||
init() { | ||
return { | ||
onFunctionRun(ctx) { | ||
console.log(ctx); | ||
|
||
return { | ||
transformInput(ctx) { | ||
console.log(ctx); | ||
}, | ||
afterExecution() { | ||
console.log("afterExecution"); | ||
}, | ||
afterMemoization() { | ||
console.log("afterMemoization"); | ||
}, | ||
beforeExecution() { | ||
console.log("beforeExecution"); | ||
}, | ||
beforeMemoization() { | ||
console.log("beforeMemoization"); | ||
}, | ||
beforeResponse() { | ||
console.log("beforeResponse"); | ||
}, | ||
transformOutput(ctx) { | ||
console.log(ctx); | ||
}, | ||
}; | ||
}, | ||
onSendEvent() { | ||
return { | ||
transformInput(ctx) { | ||
console.log(ctx); | ||
}, | ||
transformOutput(ctx) { | ||
console.log(ctx); | ||
}, | ||
}; | ||
}, | ||
}; | ||
}, | ||
}), | ||
], | ||
}); | ||
|
||
void inngest.send({ name: "foo", data: { foo: "bar" } }); | ||
|
||
inngest.createFunction({ id: "my-fn" }, { event: "foo" }, async (ctx) => { | ||
console.log(ctx); | ||
return { foo: "bar" }; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"target": "es5", | ||
"forceConsistentCasingInFileNames": true, | ||
"composite": true, | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": false, | ||
"strict": true, | ||
"noEmit": false, | ||
"outDir": "dist", | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"typeRoots": ["./types"], | ||
"plugins": [ | ||
{ | ||
"name": "next", | ||
}, | ||
], | ||
"paths": { | ||
"~/*": ["./src/*"], | ||
}, | ||
}, | ||
"include": [ | ||
"next-env.d.ts", | ||
"src/**/*.ts", | ||
"**/*.tsx", | ||
".next/types/**/*.ts", | ||
], | ||
"exclude": ["node_modules"], | ||
} |