11import semver from "semver" ;
22import { intersect as semverIntersect } from "semver-intersect" ;
3- import { PJV , INpmValidateResult } from "package-json-validator" ;
3+ import { validate as packageJsonValidator } from "package-json-validator" ;
44import fs from "fs" ;
55import path from "path" ;
66import 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
2018const 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
0 commit comments