Skip to content
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

Merged
merged 4 commits into from
Jan 11, 2017
Merged

Add dependency unification script #293

merged 4 commits into from
Jan 11, 2017

Conversation

ace-n
Copy link
Contributor

@ace-n ace-n commented Jan 9, 2017

No description provided.

@ace-n ace-n requested a review from jmdobry January 9, 2017 22:54
// See the License for the specific language governing permissions and
// limitations under the License.

const async = require(`async`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Copy link
Member

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);
Copy link
Member

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 = {};
Copy link
Member

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`));
Copy link
Member

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) =>

Copy link
Member

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) {
Copy link
Member

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`];
Copy link
Member

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];
}
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove line.

Copy link
Contributor Author

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`]));
Copy link
Member

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]}`]));
Copy link
Member

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(' ')));

@ace-n ace-n force-pushed the add-unify branch 2 times, most recently from 7b02ead to 2bca91f Compare January 10, 2017 20:33
@codecov-io
Copy link

Current coverage is 91.78% (diff: 100%)

Merging #293 into master will decrease coverage by 0.28%

@@             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          

Powered by Codecov. Last update f0f1e17...2bca91f


// 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 = {};
Copy link
Member

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);
})
Copy link
Member

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 = {};
Copy link
Member

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);
})
Copy link
Member

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]}`)));
Copy link
Member

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

@ace-n
Copy link
Contributor Author

ace-n commented Jan 11, 2017

Messed up a rebase; don't merge this until it's fixed.

Rebase has been fixed - feel free to review + merge.

@googlebot
Copy link

CLAs look good, thanks!

@ace-n
Copy link
Contributor Author

ace-n commented Jan 11, 2017

@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.)

@ace-n ace-n merged commit 4e82315 into master Jan 11, 2017
@ace-n ace-n deleted the add-unify branch January 11, 2017 23:47
NimJay pushed a commit that referenced this pull request Nov 11, 2022
There are some slight breaking changes in the newest UUID.
ace-n pushed a commit that referenced this pull request Nov 11, 2022
There are some slight breaking changes in the newest UUID.
ace-n pushed a commit that referenced this pull request Nov 11, 2022
* 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 <bencoe@google.com>
ace-n pushed a commit that referenced this pull request Nov 11, 2022
* 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 <bencoe@google.com>
ace-n pushed a commit that referenced this pull request Nov 14, 2022
* 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 <bencoe@google.com>
ace-n pushed a commit that referenced this pull request Nov 15, 2022
* 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 <bencoe@google.com>
ace-n pushed a commit that referenced this pull request Nov 15, 2022
* 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 <bencoe@google.com>
ace-n pushed a commit that referenced this pull request Nov 16, 2022
* [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
ace-n pushed a commit that referenced this pull request Nov 17, 2022
* [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
ace-n pushed a commit that referenced this pull request Nov 17, 2022
* 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 <bencoe@google.com>
ace-n pushed a commit that referenced this pull request Nov 17, 2022
* 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 <bencoe@google.com>
ahrarmonsur pushed a commit that referenced this pull request Nov 17, 2022
* [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
ahrarmonsur pushed a commit that referenced this pull request Nov 17, 2022
* 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 <bencoe@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants