Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@yarnpkg/lockfile": "^1.1.0",
"chalk": "^5.0.1",
"node-exceptions": "^4.0.1",
"package-json-validator": "0.6.4",
"package-json-validator": "1.4.1",
"semver": "^7.3.7",
"semver-intersect": "^1.4.0"
},
Expand Down
95 changes: 72 additions & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 17 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import semver from "semver";
import { intersect as semverIntersect } from "semver-intersect";
import { PJV, INpmValidateResult } from "package-json-validator";
import { validate as packageJsonValidator } from "package-json-validator";
import fs from "fs";
import path from "path";
import chalk from "chalk";
Expand All @@ -14,8 +14,6 @@ export {
InvalidBowerPackageException,
} from "./exceptions.js";

const packageJsonValidator = PJV.validate;

// Known dependency keys
const npmDependencyTypes = [
"dependencies",
Expand Down Expand Up @@ -61,6 +59,14 @@ interface ITemplatePath {
path: string;
}

interface INpmValidateResult {
valid: boolean;
errors?: { field: string; message: string }[];
critical?: Record<string, string> | string;
warnings?: string[];
recommendations?: string[];
}

/**
* @public
*/
Expand Down Expand Up @@ -296,7 +302,10 @@ function npmValidate(pkg: INodeTemplate, pkgSpec: string, log: LogOption): void
if (pkg[depType] && typeof pkg[depType] !== 'object') {
if (!results.errors) results.errors = [];
results.valid = false;
results.errors.push(`"${depType}" must be an object.`);
results.errors.push({
field: depType,
message: "must be an object."
});
}
}
}
Expand Down Expand Up @@ -328,14 +337,16 @@ function npmErrors(results: INpmValidateResult, log: LogOption): void {
if (log) {
// Announce critical errors.
if (results.critical) {
log(chalk.bgRed("Critical Error: ") + chalk.red(results.critical));
const criticalError = typeof results.critical === "string" ? results.critical : JSON.stringify(results.critical);
log(chalk.bgRed("Critical Error: ") + chalk.red(criticalError));
}

// Announce errors.
if (results.errors) {
log(chalk.underline.red("Errors:"));
for (let error of results.errors) {
log(" " + chalk.red(error));
const errorMessage = `${error.field}: ${error.message}`;
log(" " + chalk.red(errorMessage));
}
}

Expand Down
31 changes: 0 additions & 31 deletions src/missing-types.d.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
declare module "semver-intersect" {
export function intersect(...versions: string[]): string;
}

declare module "package-json-validator" {
export interface INpmValidateResult {
valid: boolean;
errors?: string[];
critical?: string;
warnings?: string[];
recommendations?: string[]
}
type PackageSpecs = "npm" | "commonjs_1.0" | "commonjs_1.1";
type PJV = {
packageFormat: string,
versionFormat: string,
urlFormat: string,
emailFormat: string,
getSpecMap(specName: PackageSpecs): false | {},
parse(data: string): string;
validate(
data: string,
specName?: PackageSpecs,
options?: {}
): INpmValidateResult,
validateType(name: string, field: {}, value: any): string[],
validateDependencies(name: string, deps: {}): string[],
isValidVersionRange(v: string): boolean,
validateUrlOrMailto(name: string, obj: {}): string[],
validatePeople(name: string, obj: {}): string[],
validateUrlTypes(name: string, obj: {}): string[],
}
export const PJV: PJV;
}
Loading