Issue
I am trying to create a repo that houses our company's common linting rules in our locally hosted github instance. This way we all have a common set of rules we can share easily. There are also configs for our typescript definitions, and PrettierJs rules.
The file structure looks like:
/lint-common
/config
.eslintrc.js
.pretterrc
tsconfig.json
package.json
When installed in another project it looks like this:
/node_modules
/lint-common
/config
.eslintrc.js
.pretterrc
tsconfig.json
package.json
package.json <-- Consuming package for the project that lint-common has been installed into
From my consuming project that has lint-common installed, I have scripts in the package.json that looks like this:
"scripts": {
"lint": "eslint -c /node_modules/lint-common/config/.eslintrc.js --ext .js src",
"pretty": "prettier --write --config /node_modules/lint-common/config/.prettierrc src/**/*.js"
}
This works fine so far. But when I try to do this for TypeScript, it behaves quite differently. Where lint and pretty process from the src directory I specify, the tsconfig insists on processing files from its own location.
For TypeScript, I tried to add a script like this:
"tsc": "tsc --p ../../config/tsconfig.json",
The --p is the --project option - which allows me to stipulate where the tsconfig file is. Inside the tsconfig I have:
"include": ["src/**/*]
However, I only get the following error:
No inputs were found in config file ...
I can fix this by changing it to:
"include": ["../../../src/**/*]
The include option inside the tsconfig is searching for the files relative to the location of the tsconfig - not from where I am running the npm command from.
Is there a way I can get around this? I have tried using the rootDir option, but that doesn't seem to have any effect.
Solution
Is there a way I can get around this?
The documentation doesn't mention a way, and AFAIK, there isn't.
I think a workable solution would be to include an npm [post-install] script which creates a tsconfig.json file, at the top level of a new project, which utilizes the extends property to reference the config nested within node_modules.
Answered By - jsejcksn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.