jsii fails with bad error if outdir is under projectRoot
- Dominant language
- TypeScript
- Stars
- 50
- Forks
- 26
- Avg merge
- 7h 10m
- Merged PRs (30d)
- 37
Description
With the following setup:
```
# /path/to/projectDir
# package.json
{
"name": "teststatic",
"main": "index.js",
"types": "index.d.ts",
"jsii": {
"versionFormat": "full",
"targets": {
"dotnet": {
"namespace": "Bla.Module",
"packageId": "Bla.Module"
}
},
"tsc": {
"outDir": "dist"
}
},
}
```
So: we compile to an outdir `dist` *underneath* the project directory, if we then try to compile then `jsii` errors:
```
error JSII4: Could not find "main" file: /path/to/index.ts
```
It looks in the wrong directory for the entry point file.
The reason is this code (in JS form):
```js
const tscOutDir = (0, helpers_1.normalizeConfigPath)(projectInfo.projectRoot, program.getCompilerOptions().outDir);
if (tscOutDir != null) {
mainFile = path.relative(tscOutDir, mainFile);
// rootDir may be set explicitly or not. If not, inferRootDir replicates
// tsc's behavior of using the longest prefix of all built source files.
this.tscRootDir = program.getCompilerOptions().rootDir ?? inferRootDir(program);
if (this.tscRootDir != null) {
mainFile = path.join(this.tscRootDir, mainFile);
}
}
this.mainFile = path.resolve(projectInfo.projectRoot, mainFile);
```
Now `mainFile` contains `../index.ts` (outDir to mainFile), but it will be combined with `projectRoot` to come up with a file in the wrong directory.
What's worse, `jsii-config` recommended this setup with the `dist` directory to me.
Contributor guide
Research direction
Start with the package.json configuration shown and reproduce the failure using tsc.outDir set to dist beneath the project root. Trace the displayed mainFile path-resolution logic, then verify that compilation resolves the entry point to /path/to/projectDir/index.ts without JSII4.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100