-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dependency unification script #293
Conversation
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
const async = require(`async`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In combination with #293 (comment)
const fs = require(`fs`); | ||
const path = require(`path`); | ||
|
||
const PROJECT_ROOT = path.dirname(__dirname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be:
const PROJECT_ROOT = path.join(__dirname, '..');
// Dedupe package.json dependencies | ||
// WARNING: This will fail if two different versions of the same package are required. | ||
let pkgSet = {}; | ||
let devPkgSet = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should have to look at dev dependencies at all. They've all moved to the root package already.
|
||
// Get subdirectories with a `package.json` file | ||
const directories = fs.readdirSync(PROJECT_ROOT) | ||
.filter(dir => fs.existsSync(`${PROJECT_ROOT}/${dir}/package.json`)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nit: Change dir =>
to (dir) =>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, use path.join(PROJECT_ROOT, dir, 'package.json')
instead of a template string.
let pkgSet = {}; | ||
let devPkgSet = {}; | ||
let pkgJson; | ||
for (const dir of directories) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer Array#forEach
for arrays.
pkgJson = JSON.parse(fs.readFileSync(`${PROJECT_ROOT}/${dir}/package.json`)); | ||
|
||
const deps = pkgJson[`dependencies`]; | ||
const devDeps = pkgJson[`devDependencies`]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use bracket syntax, use pkgJson.dependencies
|
||
for (p in deps) { | ||
pkgSet[p] = deps[p]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of these 3 lines just do:
Object.assign(pkgSet, deps);
|
||
// Update root-level package.json (by shelling to npm) | ||
const spawn = require('child_process').spawn; | ||
process.chdir(PROJECT_ROOT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
const spawn = require('child_process').spawn; | ||
process.chdir(PROJECT_ROOT); | ||
Object.keys(pkgSet).forEach(pkg => spawn(`yarn`, [`add`, `${pkg}@${pkgSet[pkg]}`])); | ||
Object.keys(devPkgSet).forEach(pkg => spawn(`yarn`, [`add`, `${pkg}@${devPkgSet[pkg]}`, `-D`])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line.
// Update root-level package.json (by shelling to npm) | ||
const spawn = require('child_process').spawn; | ||
process.chdir(PROJECT_ROOT); | ||
Object.keys(pkgSet).forEach(pkg => spawn(`yarn`, [`add`, `${pkg}@${pkgSet[pkg]}`])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of spawning 30+ processes, just spawn one:
spawn(`yarn`, [`add`].concat(Object.keys(pkgSet).map((pkg) => `${pkg}@${pkgSet[pkg]}`).join(' ')));
7b02ead
to
2bca91f
Compare
Current coverage is 91.78% (diff: 100%)@@ master #293 diff @@
==========================================
Files 71 70 -1
Lines 2838 2702 -136
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 2613 2480 -133
+ Misses 225 222 -3
Partials 0 0
|
|
||
// Get subdirectories with a `package.json` file | ||
const directories = fs.readdirSync(PROJECT_ROOT) | ||
.filter(dir => fs.existsSync(`${PROJECT_ROOT}/${dir}/package.json`)); | ||
.filter((dir) => fs.existsSync(path.join(PROJECT_ROOT, dir, `package.json`))); | ||
|
||
// Dedupe package.json dependencies | ||
// WARNING: This will fail if two different versions of the same package are required. | ||
let pkgSet = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This let
can be a const
directories.forEach((dir) => { | ||
pkgJson = JSON.parse(fs.readFileSync(path.join(PROJECT_ROOT, dir, `package.json`))); | ||
Object.assign(pkgSet, pkgJson.dependencies); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon. I don't think the lint script is seeing this file. We'll need to update the lint script to look at scripts/*
|
||
// Dedupe package.json dependencies | ||
// WARNING: This will fail if two different versions of the same package are required. | ||
let pkgSet = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This let
can be a const
directories.forEach((dir) => { | ||
pkgJson = JSON.parse(fs.readFileSync(path.join(PROJECT_ROOT, dir, `package.json`))); | ||
Object.assign(pkgSet, pkgJson.dependencies); | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon; Looks like the linter isn't checking this file.
|
||
// Update root-level package.json (by shelling to npm) | ||
const spawn = require('child_process').spawn; | ||
spawn(`yarn`, [`add`].concat(Object.keys(pkgSet).map(pkg => `${pkg}@${pkgSet[pkg]}`))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline at end of file
Rebase has been fixed - feel free to review + merge. |
CLAs look good, thanks! |
@jmdobry it looks like the CircleCI failures are unrelated to this, so I'm merging this now. (If they are in fact related, let me know and I'll try to fix things.) |
🤖 I have created a release \*beep\* \*boop\* --- ### [2.2.4](https://www.github.com/googleapis/nodejs-datalabeling/compare/v2.2.3...v2.2.4) (2021-06-30) ### Bug Fixes * **deps:** google-gax v2.17.0 with mTLS ([#291](https://www.github.com/googleapis/nodejs-datalabeling/issues/291)) ([ba455a8](https://www.github.com/googleapis/nodejs-datalabeling/commit/ba455a8d574f9bb87c9f7531ba56e199ad0dc8be)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release \*beep\* \*boop\* --- ### [2.2.4](https://www.github.com/googleapis/nodejs-datalabeling/compare/v2.2.3...v2.2.4) (2021-06-30) ### Bug Fixes * **deps:** google-gax v2.17.0 with mTLS ([#291](https://www.github.com/googleapis/nodejs-datalabeling/issues/291)) ([ba455a8](https://www.github.com/googleapis/nodejs-datalabeling/commit/ba455a8d574f9bb87c9f7531ba56e199ad0dc8be)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release \*beep\* \*boop\* --- ### [3.1.1](https://www.github.com/googleapis/nodejs-containeranalysis/compare/v3.1.0...v3.1.1) (2021-04-27) ### Bug Fixes * specify valid go_package option ([#293](https://www.github.com/googleapis/nodejs-containeranalysis/issues/293)) ([84ba201](https://www.github.com/googleapis/nodejs-containeranalysis/commit/84ba201c2d2eb81faf36461cf1ff3bfccf33f5ed)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
There are some slight breaking changes in the newest UUID.
There are some slight breaking changes in the newest UUID.
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* [CHANGE ME] Re-generated to pick up changes in the API or client library generator. * add protos to eslintignore * chore: hunted down missing videos * chore: fix video path * test: other resources are missing, let's use the cat for now * chore: updating URLs
* [CHANGE ME] Re-generated to pick up changes in the API or client library generator. * add protos to eslintignore * chore: hunted down missing videos * chore: fix video path * test: other resources are missing, let's use the cat for now * chore: updating URLs
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
* [CHANGE ME] Re-generated to pick up changes in the API or client library generator. * add protos to eslintignore * chore: hunted down missing videos * chore: fix video path * test: other resources are missing, let's use the cat for now * chore: updating URLs
* docs: add base samples for automl ga * update package.json * lint fix * License header update * Fix cleanup on GCS prefix * Lint Co-authored-by: Benjamin E. Coe <[email protected]>
No description provided.