-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (40 loc) · 1.55 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
'use strict';
const chalk = require('chalk');
const packageJson = require(getPackageJsonDir());
console.log(chalk.cyan('\nChecking dependencies for wildcards...'));
const dependencySections = [packageJson.dependencies, packageJson.devDependencies].filter(Boolean);
dependencySections.forEach(checkDependencySection);
console.log(chalk.green('All dependencies are wildcard free!'));
function getPackageJsonDir() {
return process.argv.slice(2)[0] || '../../package.json';
}
function checkDependencySection(dependencySection) {
Object.keys(dependencySection).forEach(checkDependency);
function checkDependency(dependencyName) {
const versionString = dependencySection[dependencyName];
if (versionString.includes('http')) {
console.log(
chalk.yellow(
`HTTP dependency ${chalk.magenta.bold(
dependencyName
)} detected (${chalk.magenta.bold(versionString)}), skipping.`
)
);
return;
}
const allowedCharacters = /^[a-zA-Z\d.-]+$/;
const valid = allowedCharacters.test(versionString);
if (!valid) {
const errorMessage = chalk.red(
`Dependency ${chalk.magenta.bold(
dependencyName
)} has a version string (${chalk.magenta.bold(
versionString
)}) with invalid characters`
);
console.log(errorMessage);
throw errorMessage;
}
}
}