update-ts-references
Advanced tools
Comparing version 2.2.0 to 2.3.0
{ | ||
"name": "update-ts-references", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"bin": "src/index.js", | ||
@@ -14,2 +14,6 @@ "scripts": { | ||
"email": "mirko.kruschke@gmail.com" | ||
}, | ||
{ | ||
"name": "Juan Picado", | ||
"email": "juanpicado19@gmail.com" | ||
} | ||
@@ -16,0 +20,0 @@ ], |
# update-ts-references | ||
If your repository is a multi package repository (via [lerna.js](https://lerna.js.org/), [yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/)) or [pnpm workspaces](https://pnpm.js.org/workspaces) in combination with [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) from TypeScript, this tool will be very helpful by reading dependencies out of the _package.json_ and applying them to the _tsconfig.json_ as references. | ||
If your repository is a multi package repository (via [lerna.js](https://lerna.js.org/), [yarn workspaces](https://classic.yarnpkg.com/en/docs/workspaces/) or [pnpm workspaces](https://pnpm.js.org/workspaces)) in combination with [project references](https://www.typescriptlang.org/docs/handbook/project-references.html) from TypeScript, this tool will be very helpful by reading dependencies out of the _package.json_ and applying them to the _tsconfig.json_ as references. | ||
@@ -17,2 +17,3 @@ There's a blog post that's a good introduction to it [Optimizing multi-package apps with TypeScript Project References](https://ebaytech.berlin/optimizing-multi-package-apps-with-typescript-project-references-d5c57a3b4440). | ||
Options: | ||
--configName The name of the config files which needs to be updated. Default: tsconfig.json | ||
--check Checks if updates would be necessary (without applying them) | ||
@@ -19,0 +20,0 @@ --help Show help |
@@ -8,2 +8,3 @@ #!/usr/bin/env node | ||
const { | ||
configName = defaultOptions.configName, | ||
cwd = defaultOptions.cwd, | ||
@@ -21,2 +22,3 @@ verbose = defaultOptions.verbose, | ||
Options: | ||
--configName The name of the config files which needs to be updated. Default: ${defaultOptions.configName} | ||
--check Checks if updates would be necessary (without applying them) | ||
@@ -38,2 +40,3 @@ --help Show help | ||
check, | ||
configName, | ||
}); | ||
@@ -40,0 +43,0 @@ |
@@ -11,5 +11,5 @@ const glob = require('glob'); | ||
const PACKAGE_JSON = 'package.json'; | ||
const TS_CONFIG_JSON = 'tsconfig.json'; | ||
const defaultOptions = { | ||
configName: 'tsconfig.json', | ||
cwd: process.cwd(), | ||
@@ -76,2 +76,3 @@ verbose: false, | ||
const getReferencesFromDependencies = ( | ||
configName, | ||
{ packageDir }, | ||
@@ -107,3 +108,3 @@ packageName, | ||
const { packageDir: dependencyDir } = packagesMap.get(dependency); | ||
if (fs.existsSync(path.join(dependencyDir, TS_CONFIG_JSON))) { | ||
if (fs.existsSync(path.join(dependencyDir, configName))) { | ||
const relativePath = path.relative(packageDir, dependencyDir); | ||
@@ -130,2 +131,3 @@ | ||
const updateTsConfig = ( | ||
configName, | ||
win32OrPosixReferences, | ||
@@ -137,3 +139,3 @@ discardComments, | ||
const references = (win32OrPosixReferences || []).map(ensurePosixPathStyle); | ||
const tsconfigFilePath = path.join(packageDir, TS_CONFIG_JSON); | ||
const tsconfigFilePath = path.join(packageDir, configName); | ||
let pureJson = true; | ||
@@ -197,3 +199,9 @@ try { | ||
const execute = async ({ cwd, verbose, discardComments, check }) => { | ||
const execute = async ({ | ||
cwd, | ||
verbose, | ||
discardComments, | ||
check, | ||
configName, | ||
}) => { | ||
let changesCount = 0; | ||
@@ -240,3 +248,3 @@ // eslint-disable-next-line no-console | ||
packagesMap.forEach((packageEntry, packageName) => { | ||
const tsconfigFilePath = path.join(packageEntry.packageDir, TS_CONFIG_JSON); | ||
const tsconfigFilePath = path.join(packageEntry.packageDir, configName); | ||
if (fs.existsSync(tsconfigFilePath)) { | ||
@@ -247,2 +255,3 @@ rootReferences.push({ | ||
const references = getReferencesFromDependencies( | ||
configName, | ||
packageEntry, | ||
@@ -257,2 +266,3 @@ packageName, | ||
changesCount += updateTsConfig( | ||
configName, | ||
references, | ||
@@ -265,3 +275,3 @@ discardComments, | ||
// eslint-disable-next-line no-console | ||
console.log(`NO ${TS_CONFIG_JSON} for ${packageName}`); | ||
console.log(`NO ${configName} for ${packageName}`); | ||
} | ||
@@ -273,3 +283,8 @@ }); | ||
} | ||
changesCount += updateTsConfig(rootReferences, discardComments, check); | ||
changesCount += updateTsConfig( | ||
configName, | ||
rootReferences, | ||
discardComments, | ||
check | ||
); | ||
@@ -276,0 +291,0 @@ if (verbose) { |
15487
313
57