-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: always include tslint and typescript in project dev-dependencies
This change is necessary to allow `@loopback/tslint-config` to include tslint extensions from 3rd-party packages, because these extensions typically have a peer dependency on `tslint`. Another benefit is that projects can decide now which version of `tsc` and `tslint` they want to use, independently of the version bundled inside `@loopback/build`. To make it easier to keep typescript & tslint version specifiers in different places in sync, a new helper script is added to propagate changes in dev-dependencies from monorepo's root package.json to example projects: "npm run sync-dev-deps"
- Loading branch information
Showing
12 changed files
with
117 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env node | ||
// Copyright IBM Corp. 2017,2018. All Rights Reserved. | ||
// Node module: loopback-next | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
/** | ||
* This is an internal script to synchronize versions of dev-dependencies | ||
* from monorepo's package.json to individual example packages. | ||
*/ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
|
||
const Project = require('@lerna/project'); | ||
|
||
async function syncDevDeps() { | ||
const project = new Project(process.cwd()); | ||
const packages = await project.getPackages(); | ||
|
||
const rootPath = project.rootPath; | ||
|
||
// Load dependencies from `packages/build/package.json` | ||
const buildDeps = require(path.join(rootPath, 'packages/build/package.json')) | ||
.dependencies; | ||
|
||
const masterDeps = { | ||
typescript: buildDeps.typescript, | ||
tslint: buildDeps.tslint, | ||
}; | ||
|
||
// Update typescript & tslint dependencies in individual packages | ||
for (const pkg of packages) { | ||
const data = readJsonFile(pkg.manifestLocation); | ||
let modified = false; | ||
for (const dep in masterDeps) { | ||
if (data.devDependencies && dep in data.devDependencies) { | ||
data.devDependencies[dep] = masterDeps[dep]; | ||
modified = true; | ||
} | ||
} | ||
if (!modified) continue; | ||
writeJsonFile(pkg.manifestLocation, data); | ||
} | ||
|
||
// Update dependencies in monorepo root | ||
const rootPackage = path.join(rootPath, 'package.json'); | ||
const data = readJsonFile(rootPackage); | ||
Object.assign(data.devDependencies, masterDeps); | ||
writeJsonFile(rootPackage, data); | ||
} | ||
|
||
if (require.main === module) syncDevDeps(); | ||
|
||
function readJsonFile(filePath) { | ||
return JSON.parse(fs.readFileSync(filePath, 'utf-8')); | ||
} | ||
|
||
function writeJsonFile(filePath, data) { | ||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2) + '\n', 'utf-8'); | ||
console.log('%s has been updated.', filePath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters