Skip to content

Commit

Permalink
feat: using a different name for the root tsconfig (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
MKruschke authored Nov 24, 2023
1 parent 483da24 commit 5ac2f5b
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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": "2.8.0",
"version": "2.9.0",
"description": "Updates TypeScript references automatically while using workspaces",
"bin": "src/index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -35,6 +37,7 @@ const run = async () => {
verbose,
check,
configName,
rootConfigName,
createTsConfig
});

Expand Down
6 changes: 4 additions & 2 deletions src/update-ts-references.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -207,6 +208,7 @@ const execute = async ({
verbose,
check,
configName,
rootConfigName
}) => {
let changesCount = 0;
// eslint-disable-next-line no-console
Expand Down Expand Up @@ -293,7 +295,7 @@ const execute = async ({
console.log('rootReferences', rootReferences);
}
changesCount += updateTsConfig(
configName,
rootConfigName,
rootReferences,
check, {packageDir:cwd}

Expand Down
10 changes: 7 additions & 3 deletions tests/update-ts-references.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
Expand All @@ -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,
Expand Down Expand Up @@ -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 = [
'.',
{
Expand Down Expand Up @@ -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 = [
[
Expand Down Expand Up @@ -397,6 +400,7 @@ test('Support custom tsconfig names', async () => {
},
],
},
rootConfigName
],
[
'./workspace-a',
Expand Down

0 comments on commit 5ac2f5b

Please sign in to comment.