Skip to content

Commit

Permalink
feat: create additional paths mappings under compilerOptions (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
MKruschke authored Nov 27, 2023
1 parent 9f8a283 commit e643c7b
Show file tree
Hide file tree
Showing 26 changed files with 1,110 additions and 622 deletions.
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ npx update-ts-references --help
--check Checks if updates would be necessary (without applying them)
--help Show help
--createTsConfig Create default TS configs for packages where the main entry in the package.json have a ts|tsx extension (Note: respects the --configName parameter)
--cwd Set working directory. Default: /Users/mirko.kruschke/coding/ecg-public/update-ts-references
-createPathMappings Create paths mappings under compilerOptions for a better IDE support. It respects the rootDir if no rootDir available it falls back to "src"
--cwd Set working directory. Default: /Users/john-doe/projects/my-project
--verbose Show verbose output. Default: false
```
Expand All @@ -46,7 +47,7 @@ npx husky add .husky/pre-push "npx update-ts-references --check"
git add .husky/pre-push
```

## using --creatTsConfig
## using --createTsConfig
Creates a basic tsconfig file for each package where the main entry in the package.json have a `.ts` or `.tsx` extension. It will respect the `--configName` parameter.

The output for the created file looks like the following
Expand All @@ -66,10 +67,37 @@ The output for the created file looks like the following
}
```

## using --createPathMappings
will create path mappings under `compilerOptions` for a better IDE support. It respects the `rootDir` if no `rootDir` available it falls back to `src`

```json
{
"extends": "../tsconfig.base.json", // add's extends in case you have a base config in the root directory
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"paths": { // will be added after running update-ts-references with --createPathMappings
"@my-project/some-other-package": ["../some-other-package/src"]
}
},
"references": [ // will be added after running update-ts-references
{
"path": "../some-other-package"
}
]
}
```


## using update-ts-references.yaml for configurations
You can configure paths via the _update-ts-references.yaml_ file. This is useful if your repo is having **no** _package.json_ or _pnp-workspace.yaml_ in the root folder. Additional to that it can also being used to extend the paths config next to the normal workspace setup via npm, pnpm, yarn and lerna so you can include or exclude some packages.
You can configure workspace paths via the _update-ts-references.yaml_ file. This is useful if your repo is having **no** _package.json_ or _pnp-workspace.yaml_ in the root folder. Additional to that it can also being used to extend the paths config next to the normal workspace setup via npm, pnpm, yarn and lerna so you can include or exclude some packages.

Additional to that you can configure also the following options:
- configName (default: tsconfig.json)
- rootConfigName (default: tsconfig.json)
- createPathMappings (default: false)

Example configuration see [here](./test-scenarios/ts-ref-yaml/update-ts-references.yaml)
Example configuration see [here](./test-scenarios/ts-options-yaml/update-ts-references.yaml)



Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "update-ts-references",
"version": "3.0.0",
"version": "3.1.0",
"description": "Updates TypeScript references automatically while using workspaces",
"bin": "src/index.js",
"scripts": {
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const {
help = defaultOptions.help,
h = defaultOptions.help,
check = defaultOptions.check,
createPathMappings = defaultOptions.createPathMappings,
} = minimist(process.argv.slice(2));
console.log('->',createTsConfig)
if (help || h) {
console.log(`
Usage: update-ts-references [options]
Expand All @@ -24,6 +24,7 @@ if (help || h) {
--check Checks if updates would be necessary (without applying them)
--help Show help
--createTsConfig Create default TS configs for packages where the main entry in the package.json have a ts|tsx extension (Note: respects the --configName parameter)
--createPathMappings Create paths mappings under compilerOptions for a better IDE support. It respects the rootDir if no rootDir available it falls back to "src"
--cwd Set working directory. Default: ${defaultOptions.cwd}
--verbose Show verbose output. Default: ${defaultOptions.verbose}
`);
Expand All @@ -38,7 +39,8 @@ const run = async () => {
check,
configName,
rootConfigName,
createTsConfig
createTsConfig,
createPathMappings
});

if (check && changesCount > 0) {
Expand Down
Loading

0 comments on commit e643c7b

Please sign in to comment.