Skip to content

Commit 4e82315

Browse files
author
Ace Nassri
authored
Add dependency unification script (#293)
* Add dependency unification script * Address comments * Add use strict to unify script * Address comments + fix lint
1 parent 2799aa5 commit 4e82315

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"system-test": "npm run st -- --verbose system-test/**/*.test.js **/system-test/**/*.test.js",
6868
"system-cover": "npm run pretest && nyc --cache npm run system-test && nyc report --reporter=html",
6969
"all-test": "npm run st -- --no-power-assert bigquery/system-test/*.test.js test/**/*.test.js **/test/**/*.test.js system-test/**/*.test.js **/system-test/**/*.test.js",
70-
"all-cover": "npm run pretest && nyc --cache npm run all-test && nyc report --reporter=html"
70+
"all-cover": "npm run pretest && nyc --cache npm run all-test && nyc report --reporter=html",
71+
"unify": "node scripts/unify"
7172
},
7273
"devDependencies": {
7374
"@google-cloud/bigquery": "0.6.0",

scripts/unify

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
// Copyright 2016, Google, Inc.
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
const fs = require(`fs`);
17+
const path = require(`path`);
18+
19+
const PROJECT_ROOT = path.join(__dirname, `..`);
20+
21+
// Get subdirectories with a `package.json` file
22+
const directories = fs.readdirSync(PROJECT_ROOT)
23+
.filter((dir) => fs.existsSync(path.join(PROJECT_ROOT, dir, `package.json`)));
24+
25+
// Dedupe package.json dependencies
26+
// WARNING: This will fail if two different versions of the same package are required.
27+
const pkgSet = {};
28+
let pkgJson;
29+
directories.forEach((dir) => {
30+
pkgJson = JSON.parse(fs.readFileSync(path.join(PROJECT_ROOT, dir, `package.json`)));
31+
Object.assign(pkgSet, pkgJson.dependencies);
32+
});
33+
34+
// Update root-level package.json (by shelling to npm)
35+
const spawn = require('child_process').spawn;
36+
spawn(`yarn`, [`add`].concat(Object.keys(pkgSet).map(pkg => `${pkg}@${pkgSet[pkg]}`)));

0 commit comments

Comments
 (0)