I have a fairly simple mono repo. It is available on GitLab
here. This uses yarn workspaces, TypeScript, Jest, ts-jest
and ESLint with eslint-plugin-import.
I am trying to properly build the project packages using TypeScript. Previously I was just publishing the TypeScript files alongside their JavaScript code in the same directory.
My attempt to build the project is available in a GitLab merge request here
Now the repository follows the following layout:
|- example/
| |- index.ts
| |- package.json
| `- tsconfig.json
|- packages/
| |- koas-core/
| | |- src/
| | | `- index.ts
| | |- package.json
| | `- tsconfig.json
| |- koas-status-code/
| | |- src/
| | | `- index.ts
| | |- package.json
| | `- tsconfig.json
| `- more similar workspaces…
|- package.json
|- tsconfig.json
`- more configuration files…
Some packages depend on each other. I have managed to get Jest tests and eslint-plugin-import to
work with this setup, but I’m having trouble building the project.
The root tsconfig.json looks like this:
{
"compilerOptions": {
"baseUrl": ".",
"composite": true,
"declaration": true,
"module": "commonjs",
"noEmit": true,
"resolveJsonModule": true,
"target": "esnext",
"paths": {
"koas-*": ["packages/koas-*/src"]
}
},
"exclude": ["**/*.test.ts"]
}
The workspace tsconfig.json files look like this:
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib"
}
}
Each workspace has a prepack script defined in package.json that looks like this:
{
"scripts": {
"prepack": "tsc --noEmit false"
}
}
The main field refers to lib.
If I run yarn workspace koas-status-code prepack, I get the following error:
$ tsc --noEmit false
error TS6059: File 'koas/packages/koas-core/src/SchemaValidationError.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/SchemaValidationError.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/createDefaultValidator.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/createDefaultValidator.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/createMatcher.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/createMatcher.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/index.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
error TS6059: File 'koas/packages/koas-core/src/index.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
error TS6307: File 'koas/packages/koas-core/src/SchemaValidationError.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
error TS6307: File 'koas/packages/koas-core/src/createDefaultValidator.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
error TS6307: File 'koas/packages/koas-core/src/createMatcher.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
error TS6307: File 'koas/packages/koas-core/src/index.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
Found 12 errors.
I have also tried this tsconfig.json for koas-status-code:
{
"extends": "../../tsconfig.json",
"include": ["src"],
"references": [{ "path": "../koas-core" }],
"compilerOptions": {
"outDir": "lib"
}
}
This builds the workspace, but still gives me the following error:
$ tsc --noEmit false
src/index.ts:1:23 - error TS6305: Output file '/home/remco/Projects/koas/packages/koas-core/lib/src/index.d.ts' has not been built from source file '/home/remco/Projects/koas/packages/koas-core/src/index.ts'.
1 import * as Koas from 'koas-core';
~~~~~~~~~~~
Found 1 error.
How do I fix this?