Skip to content

Commit

Permalink
feat: introduce option --withoutRootConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirko Kruschke committed Nov 20, 2024
1 parent 4a7a93d commit 952d923
Show file tree
Hide file tree
Showing 48 changed files with 2,390 additions and 2,150 deletions.
Binary file added .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ npx update-ts-references --help
Options:
--configName The name of the config files which needs to be updated. Default: tsconfig.json
--rootConfigName The name of the root config file which needs to be updated. Default: tsconfig.json
--withoutRootConfig If you will not have a tsconfig in the root directory or don't want to update it. Default: false
--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)
Expand Down Expand Up @@ -97,6 +98,7 @@ Additional to that you can configure also the following options:
- configName (default: tsconfig.json)
- rootConfigName (default: tsconfig.json)
- createPathMappings (default: false)
- withoutRootConfig (default: false)

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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@
"<rootDir>/test-scenarios/",
"<rootDir>/test-run/"
]
}
},
"packageManager": "yarn@1.22.22+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { execute, defaultOptions } = require('./update-ts-references');
const {
configName = defaultOptions.configName,
rootConfigName = defaultOptions.rootConfigName,
withoutRootConfig= defaultOptions.withoutRootConfig,
createTsConfig = defaultOptions.createTsConfig,
cwd = defaultOptions.cwd,
verbose = defaultOptions.verbose,
Expand All @@ -22,6 +23,7 @@ if (help || h) {
Options:
--configName The name of the config files which needs to be updated. Default: ${defaultOptions.configName}
--rootConfigName The name of the root config file which needs to be updated. Default: ${defaultOptions.configName}
--withoutRootConfig If you will not have a tsconfig in the root directory or don't want to update it. Default: ${defaultOptions.withoutRootConfig}
--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)
Expand All @@ -41,6 +43,7 @@ const run = async () => {
check,
configName,
rootConfigName,
withoutRootConfig,
createTsConfig,
createPathMappings,
usecase
Expand Down
19 changes: 12 additions & 7 deletions src/update-ts-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const TSCONFIG_JSON = 'tsconfig.json'
const defaultOptions = {
configName: TSCONFIG_JSON,
rootConfigName: TSCONFIG_JSON,
withoutRootConfig: false,
createTsConfig: false,
cwd: process.cwd(),
verbose: false,
Expand Down Expand Up @@ -259,7 +260,8 @@ const execute = async ({
let {
configName,
rootConfigName,
createPathMappings
createPathMappings,
withoutRootConfig
} = configurable

if (fs.existsSync(path.join(cwd, usecase))) {
Expand All @@ -269,6 +271,7 @@ const execute = async ({
configName = yamlConfig.configName ?? configName
rootConfigName = yamlConfig.rootConfigName ?? rootConfigName
createPathMappings = yamlConfig.createPathMappings ?? createPathMappings
withoutRootConfig = yamlConfig.withoutRootConfig ?? withoutRootConfig
workspaces = [...(yamlConfig.packages ? yamlConfig.packages : []), ...(workspaces ? workspaces : [])];

if (verbose) {
Expand Down Expand Up @@ -347,12 +350,14 @@ const execute = async ({
console.log('rootReferences', rootReferences);
console.log('rootPaths', rootPaths);
}
changesCount += updateTsConfig(
rootConfigName,
rootReferences,
rootPaths,
check, createPathMappings, {packageDir: cwd}
);
if(withoutRootConfig === false) {
changesCount += updateTsConfig(
rootConfigName,
rootReferences,
rootPaths,
check, createPathMappings, {packageDir: cwd}
);
}

if (verbose) {
console.log(`counted changes ${changesCount}`);
Expand Down
13 changes: 13 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "ts-ref-yaml-workspace",
"version": "0.0.1",
"private": true,
"workspaces": [
"workspace-b",
"shared/*",
"utils/**/"
],
"devDependencies": {
"typescript": "latest"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/shared/workspace-c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-c",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"peerDependencies": {
"foo-a": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-d",
"version": "1.0.0",
"dependencies": {
"workspace-c": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
8 changes: 8 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [],
"compilerOptions": {
/* Basic Options */
// "allowJs": true,
"composite": true
}
}
7 changes: 7 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/update-ts-references.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
withoutRootConfig: true
packages:
# all packages in subdirs of packages/ and components/
- 'workspace-a'
# exclude packages that are inside test directories
- '!**/tests/**'
- '!workspace-ignore'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "foo-a",
"version": "1.0.0",
"dependencies": {
"foo-b": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "foo-b",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test-a",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/workspace-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-a",
"version": "1.0.0",
"dependencies": {
"workspace-b": "1.0.0"
},
"devDependencies": {
"foo-a": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/workspace-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/workspace-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-b",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"devDependencies": {
"foo-b": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/workspace-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot-yaml/workspace-ignore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "ignore",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"devDependencies": {
"foo-b": "1.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
13 changes: 13 additions & 0 deletions test-scenarios/ts-ref-noroot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "ts-ref-yaml-workspace",
"version": "0.0.1",
"private": true,
"workspaces": [
"workspace-b",
"shared/*",
"utils/**/"
],
"devDependencies": {
"typescript": "latest"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot/shared/workspace-c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-c",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"peerDependencies": {
"foo-a": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/shared/workspace-c/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
7 changes: 7 additions & 0 deletions test-scenarios/ts-ref-noroot/shared/workspace-d/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "workspace-d",
"version": "1.0.0",
"dependencies": {
"workspace-c": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/shared/workspace-d/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
8 changes: 8 additions & 0 deletions test-scenarios/ts-ref-noroot/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"files": [],
"compilerOptions": {
/* Basic Options */
// "allowJs": true,
"composite": true
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/update-ts-references.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
packages:
# all packages in subdirs of packages/ and components/
- 'workspace-a'
# exclude packages that are inside test directories
- '!**/tests/**'
- '!workspace-ignore'
7 changes: 7 additions & 0 deletions test-scenarios/ts-ref-noroot/utils/foos/foo-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "foo-a",
"version": "1.0.0",
"dependencies": {
"foo-b": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/utils/foos/foo-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
4 changes: 4 additions & 0 deletions test-scenarios/ts-ref-noroot/utils/foos/foo-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "foo-b",
"version": "1.0.0"
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/utils/foos/foo-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "test-a",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot/workspace-a/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-a",
"version": "1.0.0",
"dependencies": {
"workspace-b": "1.0.0"
},
"devDependencies": {
"foo-a": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/workspace-a/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
10 changes: 10 additions & 0 deletions test-scenarios/ts-ref-noroot/workspace-b/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "workspace-b",
"version": "1.0.0",
"dependencies": {
"cross-env": "5.0.5"
},
"devDependencies": {
"foo-b": "1.0.0"
}
}
6 changes: 6 additions & 0 deletions test-scenarios/ts-ref-noroot/workspace-b/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"outDir": "dist",
"rootDir": "src"
}
}
Loading

0 comments on commit 952d923

Please sign in to comment.