Skip to content

Commit

Permalink
feat(peer-api-check): error differently if devDep not pinned (open-te…
Browse files Browse the repository at this point in the history
  • Loading branch information
rauno56 authored Jun 10, 2021
1 parent 3f15baf commit 6a8f1f4
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions scripts/peer-api-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@
* limitations under the License.
*/

const fs = require('fs');
const os = require('os');
const path = require('path');

const appRoot = process.cwd();

const packageJsonUrl = path.resolve(`${appRoot}/package.json`);
const pjson = require(packageJsonUrl);

if (pjson.dependencies && pjson.dependencies["@opentelemetry/api"])
throw new Error(`Package ${pjson.name} depends on API but it should be a peer dependency`);
if (pjson.dependencies && pjson.dependencies['@opentelemetry/api']) {
throw new Error(`Package ${pjson.name} depends on API but it should be a peer dependency`);
}

const peerVersion = pjson.peerDependencies && pjson.peerDependencies["@opentelemetry/api"]
const devVersion = pjson.devDependencies && pjson.devDependencies["@opentelemetry/api"]
const peerVersion = pjson.peerDependencies && pjson.peerDependencies['@opentelemetry/api'];
const devVersion = pjson.devDependencies && pjson.devDependencies['@opentelemetry/api'];
if (peerVersion) {
if (peerVersion !== `^${devVersion}`) {
throw new Error(`Package ${pjson.name} depends on peer API version ${peerVersion} but version ${devVersion} in development`);
}
console.log(`${pjson.name} OK`);
// error if not pinned
if (!/^[0-9]/.test(devVersion)) {
throw new Error(
`Package ${pjson.name} does't have API version pinned in dev dependencies: ${devVersion}`
);
}
if (peerVersion !== `^${devVersion}`) {
throw new Error(
`Package ${pjson.name} depends on peer API version ${peerVersion} ` +
`but version ${devVersion} in development`
);
}
console.log(`${pjson.name} OK`);
}

0 comments on commit 6a8f1f4

Please sign in to comment.