Skip to content

Commit d62ac88

Browse files
Bump package-json-validator from 0.6.4 to 1.4.1 (#1089)
* Bump package-json-validator from 0.6.4 to 1.4.1 Bumps [package-json-validator](https://github.com/michaelfaith/package-json-validator) from 0.6.4 to 1.4.1. - [Release notes](https://github.com/michaelfaith/package-json-validator/releases) - [Changelog](https://github.com/michaelfaith/package-json-validator/blob/main/CHANGELOG.md) - [Commits](https://github.com/michaelfaith/package-json-validator/commits/v1.4.1) --- updated-dependencies: - dependency-name: package-json-validator dependency-version: 0.32.1 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Handle `package-json-validator` breaking changes --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jordan Mele <jordan.mele@outlook.com.au>
1 parent 33e87ea commit d62ac88

4 files changed

Lines changed: 90 additions & 61 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@yarnpkg/lockfile": "^1.1.0",
4242
"chalk": "^5.0.1",
4343
"node-exceptions": "^4.0.1",
44-
"package-json-validator": "0.6.4",
44+
"package-json-validator": "1.4.1",
4545
"semver": "^7.3.7",
4646
"semver-intersect": "^1.4.0"
4747
},

pnpm-lock.yaml

Lines changed: 72 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import semver from "semver";
22
import { intersect as semverIntersect } from "semver-intersect";
3-
import { PJV, INpmValidateResult } from "package-json-validator";
3+
import { validate as packageJsonValidator } from "package-json-validator";
44
import fs from "fs";
55
import path from "path";
66
import chalk from "chalk";
@@ -14,8 +14,6 @@ export {
1414
InvalidBowerPackageException,
1515
} from "./exceptions.js";
1616

17-
const packageJsonValidator = PJV.validate;
18-
1917
// Known dependency keys
2018
const npmDependencyTypes = [
2119
"dependencies",
@@ -61,6 +59,14 @@ interface ITemplatePath {
6159
path: string;
6260
}
6361

62+
interface INpmValidateResult {
63+
valid: boolean;
64+
errors?: { field: string; message: string }[];
65+
critical?: Record<string, string> | string;
66+
warnings?: string[];
67+
recommendations?: string[];
68+
}
69+
6470
/**
6571
* @public
6672
*/
@@ -296,7 +302,10 @@ function npmValidate(pkg: INodeTemplate, pkgSpec: string, log: LogOption): void
296302
if (pkg[depType] && typeof pkg[depType] !== 'object') {
297303
if (!results.errors) results.errors = [];
298304
results.valid = false;
299-
results.errors.push(`"${depType}" must be an object.`);
305+
results.errors.push({
306+
field: depType,
307+
message: "must be an object."
308+
});
300309
}
301310
}
302311
}
@@ -328,14 +337,16 @@ function npmErrors(results: INpmValidateResult, log: LogOption): void {
328337
if (log) {
329338
// Announce critical errors.
330339
if (results.critical) {
331-
log(chalk.bgRed("Critical Error: ") + chalk.red(results.critical));
340+
const criticalError = typeof results.critical === "string" ? results.critical : JSON.stringify(results.critical);
341+
log(chalk.bgRed("Critical Error: ") + chalk.red(criticalError));
332342
}
333343

334344
// Announce errors.
335345
if (results.errors) {
336346
log(chalk.underline.red("Errors:"));
337347
for (let error of results.errors) {
338-
log(" " + chalk.red(error));
348+
const errorMessage = `${error.field}: ${error.message}`;
349+
log(" " + chalk.red(errorMessage));
339350
}
340351
}
341352

src/missing-types.d.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,3 @@
11
declare module "semver-intersect" {
22
export function intersect(...versions: string[]): string;
33
}
4-
5-
declare module "package-json-validator" {
6-
export interface INpmValidateResult {
7-
valid: boolean;
8-
errors?: string[];
9-
critical?: string;
10-
warnings?: string[];
11-
recommendations?: string[]
12-
}
13-
type PackageSpecs = "npm" | "commonjs_1.0" | "commonjs_1.1";
14-
type PJV = {
15-
packageFormat: string,
16-
versionFormat: string,
17-
urlFormat: string,
18-
emailFormat: string,
19-
getSpecMap(specName: PackageSpecs): false | {},
20-
parse(data: string): string;
21-
validate(
22-
data: string,
23-
specName?: PackageSpecs,
24-
options?: {}
25-
): INpmValidateResult,
26-
validateType(name: string, field: {}, value: any): string[],
27-
validateDependencies(name: string, deps: {}): string[],
28-
isValidVersionRange(v: string): boolean,
29-
validateUrlOrMailto(name: string, obj: {}): string[],
30-
validatePeople(name: string, obj: {}): string[],
31-
validateUrlTypes(name: string, obj: {}): string[],
32-
}
33-
export const PJV: PJV;
34-
}

0 commit comments

Comments
 (0)