diff --git a/README.md b/README.md index c8cb44e..2207858 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,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 --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) diff --git a/package.json b/package.json index 9eacb06..ea41c0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "update-ts-references", - "version": "2.8.0", + "version": "2.9.0", "description": "Updates TypeScript references automatically while using workspaces", "bin": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index f7eda40..0a15a38 100755 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const { execute, defaultOptions } = require('./update-ts-references'); const { configName = defaultOptions.configName, + rootConfigName = defaultOptions.rootConfigName, createTsConfig = defaultOptions.createTsConfig, cwd = defaultOptions.cwd, verbose = defaultOptions.verbose, @@ -19,6 +20,7 @@ if (help || h) { Usage: update-ts-references [options] 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} --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) @@ -35,6 +37,7 @@ const run = async () => { verbose, check, configName, + rootConfigName, createTsConfig }); diff --git a/src/update-ts-references.js b/src/update-ts-references.js index 9aabaf4..ae6fa4a 100644 --- a/src/update-ts-references.js +++ b/src/update-ts-references.js @@ -14,7 +14,8 @@ const PACKAGE_JSON = 'package.json'; const TSCONFIG_JSON = 'tsconfig.json' const defaultOptions = { - configName: 'tsconfig.json', + configName: TSCONFIG_JSON, + rootConfigName: TSCONFIG_JSON, createTsConfig: false, cwd: process.cwd(), verbose: false, @@ -207,6 +208,7 @@ const execute = async ({ verbose, check, configName, + rootConfigName }) => { let changesCount = 0; // eslint-disable-next-line no-console @@ -293,7 +295,7 @@ const execute = async ({ console.log('rootReferences', rootReferences); } changesCount += updateTsConfig( - configName, + rootConfigName, rootReferences, check, {packageDir:cwd} diff --git a/test-scenarios/yarn-ws-custom-tsconfig-names/tsconfig.dev.json b/test-scenarios/yarn-ws-custom-tsconfig-names/tsconfig.ref.json similarity index 100% rename from test-scenarios/yarn-ws-custom-tsconfig-names/tsconfig.dev.json rename to test-scenarios/yarn-ws-custom-tsconfig-names/tsconfig.ref.json diff --git a/tests/update-ts-references.test.js b/tests/update-ts-references.test.js index f4b36f2..1507a67 100644 --- a/tests/update-ts-references.test.js +++ b/tests/update-ts-references.test.js @@ -36,7 +36,7 @@ const rootFolderConfigName = path.join( const compilerOptions = { outDir: 'dist', rootDir: 'src' }; -const setup = async (rootFolder, configName, createTsConfig) => { +const setup = async (rootFolder, configName, rootConfigName, createTsConfig) => { if (!fs.existsSync(rootFolder)) { throw new Error(`folder is missing -> ${rootFolder}`); } @@ -45,6 +45,8 @@ const setup = async (rootFolder, configName, createTsConfig) => { await execSh( `npx update-ts-references --verbose${ configName ? ` --configName ${configName}` : '' + }${ + rootConfigName ? ` --rootConfigName ${rootConfigName}` : '' }${createTsConfig ? ` --createTsConfig` : ''}`, { cwd: rootFolder, @@ -266,7 +268,7 @@ test('Support update-ts-reference.yaml workspaces', async () => { }); test('Test create tsconfig', async () => { - await setup(rootFolderYarnCreate, undefined, true); + await setup(rootFolderYarnCreate, undefined, undefined,true); const r = [ '.', { @@ -365,8 +367,9 @@ test('No changes detected with the --check option', async () => { test('Support custom tsconfig names', async () => { const configName = 'tsconfig.dev.json'; + const rootConfigName = 'tsconfig.ref.json'; const rootFolder = rootFolderConfigName; - await setup(rootFolder, configName); + await setup(rootFolder, configName, rootConfigName); const tsconfigs = [ [ @@ -397,6 +400,7 @@ test('Support custom tsconfig names', async () => { }, ], }, + rootConfigName ], [ './workspace-a',