Socket
Socket
Sign inDemoInstall

@rushstack/node-core-library

Package Overview
Dependencies
Maintainers
3
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rushstack/node-core-library - npm Package Compare versions

Comparing version 4.3.0 to 5.0.0

2

dist/tsdoc-metadata.json

@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.

"packageName": "@microsoft/api-extractor",
"packageVersion": "7.41.0"
"packageVersion": "7.43.7"
}
]
}

@@ -155,6 +155,2 @@ /**

/**
* @deprecated Use {@link Async.sleepAsync} instead.
*/
static sleep(ms: number): Promise<void>;
/**
* Executes an async function and optionally retries it if it fails.

@@ -161,0 +157,0 @@ */

@@ -128,9 +128,2 @@ "use strict";

/**
* @deprecated Use {@link Async.sleepAsync} instead.
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
static async sleep(ms) {
await Async.sleepAsync(ms);
}
/**
* Executes an async function and optionally retries it if it fails.

@@ -137,0 +130,0 @@ */

@@ -6,8 +6,8 @@ /**

*/
export declare enum FileConstants {
export declare const FileConstants: {
/**
* "package.json" - the configuration file that defines an NPM package
*/
PackageJson = "package.json"
}
readonly PackageJson: "package.json";
};
/**

@@ -18,12 +18,12 @@ * String constants for common folder names.

*/
export declare enum FolderConstants {
export declare const FolderConstants: {
/**
* ".git" - the data storage for a Git working folder
*/
Git = ".git",
readonly Git: ".git";
/**
* "node_modules" - the folder where package managers install their files
*/
NodeModules = "node_modules"
}
readonly NodeModules: "node_modules";
};
//# sourceMappingURL=Constants.d.ts.map

@@ -11,9 +11,9 @@ "use strict";

*/
var FileConstants;
(function (FileConstants) {
// eslint-disable-next-line @typescript-eslint/typedef
exports.FileConstants = {
/**
* "package.json" - the configuration file that defines an NPM package
*/
FileConstants["PackageJson"] = "package.json";
})(FileConstants || (exports.FileConstants = FileConstants = {}));
PackageJson: 'package.json'
};
/**

@@ -24,13 +24,13 @@ * String constants for common folder names.

*/
var FolderConstants;
(function (FolderConstants) {
// eslint-disable-next-line @typescript-eslint/typedef
exports.FolderConstants = {
/**
* ".git" - the data storage for a Git working folder
*/
FolderConstants["Git"] = ".git";
Git: '.git',
/**
* "node_modules" - the folder where package managers install their files
*/
FolderConstants["NodeModules"] = "node_modules";
})(FolderConstants || (exports.FolderConstants = FolderConstants = {}));
NodeModules: 'node_modules'
};
//# sourceMappingURL=Constants.js.map

@@ -319,4 +319,4 @@ "use strict";

}
let errorThrown = false;
const exitCode = await new Promise((resolve, reject) => {
let errorThrown = undefined;
const promiseExitCode = await new Promise((resolve, reject) => {
if (encoding) {

@@ -331,15 +331,17 @@ childProcess.stdout.on('data', (chunk) => {

childProcess.on('error', (error) => {
errorThrown = true;
reject(error);
// Wait to call reject() until any output is collected
errorThrown = error;
});
childProcess.on('exit', (code) => {
childProcess.on('close', (exitCode, signal) => {
if (errorThrown) {
// We've already rejected the promise
return;
reject(errorThrown);
}
if (code !== 0 && throwOnNonZeroExitCode) {
reject(new Error(`Process exited with code ${code}`));
if (signal) {
reject(new Error(`Process terminated by ${signal}`));
}
else if (exitCode !== 0 && throwOnNonZeroExitCode) {
reject(new Error(`Process exited with code ${exitCode}`));
}
else {
resolve(code);
resolve(exitCode);
}

@@ -349,3 +351,3 @@ });

const result = {
exitCode
exitCode: promiseExitCode
};

@@ -352,0 +354,0 @@ if (encoding === 'buffer') {

@@ -18,3 +18,3 @@ /**

export { JsonObject, JsonNull, JsonSyntax, IJsonFileParseOptions, IJsonFileLoadAndValidateOptions, IJsonFileStringifyOptions, IJsonFileSaveOptions, JsonFile } from './JsonFile';
export { JsonSchema, IJsonSchemaErrorInfo, IJsonSchemaValidateOptions, IJsonSchemaFromFileOptions } from './JsonSchema';
export { IJsonSchemaErrorInfo, IJsonSchemaFromFileOptions, IJsonSchemaFromObjectOptions, IJsonSchemaLoadOptions, IJsonSchemaValidateOptions, JsonSchema, JsonSchemaVersion } from './JsonSchema';
export { LockFile } from './LockFile';

@@ -21,0 +21,0 @@ export { MapExtensions } from './MapExtensions';

import { type JsonObject } from './JsonFile';
/**
* Specifies the version of json-schema to be validated against.
* https://json-schema.org/specification
* @public
*/
export type JsonSchemaVersion = 'draft-04' | 'draft-07';
/**
* Callback function arguments for JsonSchema.validateObjectWithCallback();

@@ -8,3 +14,3 @@ * @public

/**
* The z-schema error tree, formatted as an indented text string.
* The ajv error list, formatted as an indented text string.
*/

@@ -22,3 +28,3 @@ details: string;

* If omitted, the default header is "JSON validation failed:". The error message starts with
* the header, followed by the full input filename, followed by the z-schema error tree.
* the header, followed by the full input filename, followed by the ajv error list.
* If you wish to customize all aspects of the error message, use JsonFile.loadAndValidateWithCallback()

@@ -30,6 +36,6 @@ * or JsonSchema.validateObjectWithCallback().

/**
* Options for JsonSchema.fromFile()
* Options for JsonSchema.fromFile() and JsonSchema.fromLoadedObject()
* @public
*/
export interface IJsonSchemaFromFileOptions {
export interface IJsonSchemaLoadOptions {
/**

@@ -39,3 +45,3 @@ * Other schemas that this schema references, e.g. via the "$ref" directive.

* The tree of dependent schemas may reference the same schema more than once.
* However, if the same schema "id" is used by two different JsonSchema instances,
* However, if the same schema "$id" is used by two different JsonSchema instances,
* an error will be reported. This means you cannot load the same filename twice

@@ -49,4 +55,25 @@ * and use them both together, and you cannot have diamond dependencies on different

dependentSchemas?: JsonSchema[];
/**
* The json-schema version to target for validation.
*
* @defaultValue draft-07
*
* @remarks
* If the a version is not explicitly set, the schema object's `$schema` property
* will be inspected to determine the version. If a `$schema` property is not found
* or does not match an expected URL, the default version will be used.
*/
schemaVersion?: JsonSchemaVersion;
}
/**
* Options for JsonSchema.fromFile()
* @public
*/
export type IJsonSchemaFromFileOptions = IJsonSchemaLoadOptions;
/**
* Options for JsonSchema.fromLoadedObject()
* @public
*/
export type IJsonSchemaFromObjectOptions = IJsonSchemaLoadOptions;
/**
* Represents a JSON schema that can be used to validate JSON data files loaded by the JsonFile class.

@@ -65,2 +92,3 @@ * @remarks

private _schemaObject;
private _schemaVersion;
private constructor();

@@ -75,8 +103,5 @@ /**

/**
* Registers a JsonSchema that will be loaded from a file on disk.
* @remarks
* NOTE: An error occurs if the file does not exist; however, the file itself is not loaded or validated
* until it the schema is actually used.
* Registers a JsonSchema that will be loaded from an object.
*/
static fromLoadedObject(schemaObject: JsonObject): JsonSchema;
static fromLoadedObject(schemaObject: JsonObject, options?: IJsonSchemaFromObjectOptions): JsonSchema;
private static _collectDependentSchemas;

@@ -94,3 +119,3 @@ /**

* @remarks
* If the schema was loaded from a file, then the base filename is used. Otherwise, the "id"
* If the schema was loaded from a file, then the base filename is used. Otherwise, the "$id"
* field is used if available.

@@ -97,0 +122,0 @@ */

@@ -27,2 +27,5 @@ "use strict";

};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -32,6 +35,24 @@ exports.JsonSchema = void 0;

const path = __importStar(require("path"));
const FileSystem_1 = require("./FileSystem");
const JsonFile_1 = require("./JsonFile");
const FileSystem_1 = require("./FileSystem");
const Validator = require('z-schema/dist/ZSchema-browser-min');
const ajv_1 = __importDefault(require("ajv"));
const ajv_draft_04_1 = __importDefault(require("ajv-draft-04"));
const ajv_formats_1 = __importDefault(require("ajv-formats"));
const JSON_SCHEMA_URL_PREFIX_BY_JSON_SCHEMA_VERSION = new Map([
['draft-04', 'http://json-schema.org/draft-04/schema'],
['draft-07', 'http://json-schema.org/draft-07/schema']
]);
/**
* Helper function to determine the json-schema version to target for validation.
*/
function _inferJsonSchemaVersion({ $schema }) {
if ($schema) {
for (const [jsonSchemaVersion, urlPrefix] of JSON_SCHEMA_URL_PREFIX_BY_JSON_SCHEMA_VERSION) {
if ($schema.startsWith(urlPrefix)) {
return jsonSchemaVersion;
}
}
}
}
/**
* Represents a JSON schema that can be used to validate JSON data files loaded by the JsonFile class.

@@ -51,2 +72,3 @@ * @remarks

this._schemaObject = undefined;
this._schemaVersion = undefined;
}

@@ -69,2 +91,3 @@ /**

schema._dependentSchemas = options.dependentSchemas || [];
schema._schemaVersion = options.schemaVersion;
}

@@ -74,10 +97,11 @@ return schema;

/**
* Registers a JsonSchema that will be loaded from a file on disk.
* @remarks
* NOTE: An error occurs if the file does not exist; however, the file itself is not loaded or validated
* until it the schema is actually used.
* Registers a JsonSchema that will be loaded from an object.
*/
static fromLoadedObject(schemaObject) {
static fromLoadedObject(schemaObject, options) {
const schema = new JsonSchema();
schema._schemaObject = schemaObject;
if (options) {
schema._dependentSchemas = options.dependentSchemas || [];
schema._schemaVersion = options.schemaVersion;
}
return schema;

@@ -95,6 +119,6 @@ }

throw new Error(`This schema ${dependentSchema.shortName} cannot be referenced` +
' because is missing the "id" field');
' because is missing the "id" (draft-04) or "$id" field');
}
if (seenIds.has(schemaId)) {
throw new Error(`This schema ${dependentSchema.shortName} has the same "id" as another schema in this set`);
throw new Error(`This schema ${dependentSchema.shortName} has the same "id" (draft-04) or "$id" as another schema in this set`);
}

@@ -116,15 +140,8 @@ seenIds.add(schemaId);

static _formatErrorDetailsHelper(errorDetails, indent, buffer) {
var _a, _b;
for (const errorDetail of errorDetails) {
buffer += os.EOL + indent + `Error: ${errorDetail.path}`;
if (errorDetail.description) {
const MAX_LENGTH = 40;
let truncatedDescription = errorDetail.description.trim();
if (truncatedDescription.length > MAX_LENGTH) {
truncatedDescription = truncatedDescription.substr(0, MAX_LENGTH - 3) + '...';
}
buffer += ` (${truncatedDescription})`;
}
buffer += os.EOL + indent + `Error: #${errorDetail.instancePath}`;
buffer += os.EOL + indent + ` ${errorDetail.message}`;
if (errorDetail.inner) {
buffer = JsonSchema._formatErrorDetailsHelper(errorDetail.inner, indent + ' ', buffer);
if ((_a = errorDetail.params) === null || _a === void 0 ? void 0 : _a.additionalProperty) {
buffer += `: ${(_b = errorDetail.params) === null || _b === void 0 ? void 0 : _b.additionalProperty}`;
}

@@ -137,3 +154,3 @@ }

* @remarks
* If the schema was loaded from a file, then the base filename is used. Otherwise, the "id"
* If the schema was loaded from a file, then the base filename is used. Otherwise, the "$id"
* field is used if available.

@@ -148,2 +165,5 @@ */

}
else if (schemaWithId.$id) {
return schemaWithId.$id;
}
}

@@ -162,15 +182,26 @@ return '(anonymous schema)';

ensureCompiled() {
var _a;
this._ensureLoaded();
if (!this._validator) {
// Don't assign this to _validator until we're sure everything was successful
const newValidator = new Validator({
breakOnFirstError: false,
noTypeless: true,
noExtraKeywords: true
});
const anythingSchema = {
type: ['array', 'boolean', 'integer', 'number', 'object', 'string']
const targetSchemaVersion = (_a = this._schemaVersion) !== null && _a !== void 0 ? _a : _inferJsonSchemaVersion(this._schemaObject);
const validatorOptions = {
strictSchema: true,
allowUnionTypes: true
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
newValidator.setRemoteReference('http://json-schema.org/draft-04/schema', anythingSchema);
let validator;
// Keep legacy support for older draft-04 schema
switch (targetSchemaVersion) {
case 'draft-04': {
validator = new ajv_draft_04_1.default(validatorOptions);
break;
}
case 'draft-07':
default: {
validator = new ajv_1.default(validatorOptions);
break;
}
}
// Enable json-schema format validation
// https://ajv.js.org/packages/ajv-formats.html
(0, ajv_formats_1.default)(validator);
const collectedSchemas = [];

@@ -183,9 +214,11 @@ const seenObjects = new Set();

for (const collectedSchema of collectedSchemas) {
if (!newValidator.validateSchema(collectedSchema._schemaObject)) {
validator.validateSchema(collectedSchema._schemaObject);
if (validator.errors && validator.errors.length > 0) {
throw new Error(`Failed to validate schema "${collectedSchema.shortName}":` +
os.EOL +
JsonSchema._formatErrorDetails(newValidator.getLastErrors()));
JsonSchema._formatErrorDetails(validator.errors));
}
validator.addSchema(collectedSchema._schemaObject);
}
this._validator = newValidator;
this._validator = validator.compile(this._schemaObject);
}

@@ -213,4 +246,4 @@ }

this.ensureCompiled();
if (!this._validator.validate(jsonObject, this._schemaObject)) {
const errorDetails = JsonSchema._formatErrorDetails(this._validator.getLastErrors());
if (this._validator && !this._validator(jsonObject)) {
const errorDetails = JsonSchema._formatErrorDetails(this._validator.errors);
const args = {

@@ -226,3 +259,3 @@ details: errorDetails

}
return this._schemaObject.id || '';
return this._schemaObject.id || this._schemaObject.$id || '';
}

@@ -229,0 +262,0 @@ }

@@ -42,3 +42,3 @@ "use strict";

}
subprocess.on('close', (code, signal) => {
subprocess.on('close', (exitCode, signal) => {
if (SubprocessTerminator._subprocessesByPid.delete(pid)) {

@@ -45,0 +45,0 @@ SubprocessTerminator._logDebug(`untracking #${pid}`);

@@ -240,4 +240,4 @@ "use strict";

*/
static readLinesFromIterableAsync(iterable, options = {}) {
return __asyncGenerator(this, arguments, function* readLinesFromIterableAsync_1() {
static readLinesFromIterableAsync(iterable_1) {
return __asyncGenerator(this, arguments, function* readLinesFromIterableAsync_1(iterable, options = {}) {
var _a, e_1, _b, _c;

@@ -247,4 +247,4 @@ const { encoding = Encoding.Utf8, ignoreEmptyLines = false } = options;

try {
for (var _d = true, iterable_1 = __asyncValues(iterable), iterable_1_1; iterable_1_1 = yield __await(iterable_1.next()), _a = iterable_1_1.done, !_a; _d = true) {
_c = iterable_1_1.value;
for (var _d = true, iterable_2 = __asyncValues(iterable), iterable_2_1; iterable_2_1 = yield __await(iterable_2.next()), _a = iterable_2_1.done, !_a; _d = true) {
_c = iterable_2_1.value;
_d = false;

@@ -258,3 +258,3 @@ const chunk = _c;

try {
if (!_d && !_a && (_b = iterable_1.return)) yield __await(_b.call(iterable_1));
if (!_d && !_a && (_b = iterable_2.return)) yield __await(_b.call(iterable_2));
}

@@ -261,0 +261,0 @@ finally { if (e_1) throw e_1.error; }

{
"name": "@rushstack/node-core-library",
"version": "4.3.0",
"version": "5.0.0",
"description": "Core libraries that every NodeJS toolchain project should use",

@@ -19,7 +19,9 @@ "main": "lib/index.js",

"semver": "~7.5.4",
"z-schema": "~5.0.2"
"ajv": "~8.13.0",
"ajv-draft-04": "~1.0.0",
"ajv-formats": "~3.0.1"
},
"devDependencies": {
"@rushstack/heft": "0.65.5",
"@rushstack/heft-node-rig": "2.4.18",
"@rushstack/heft": "0.66.9",
"@rushstack/heft-node-rig": "2.6.7",
"@types/fs-extra": "7.0.0",

@@ -26,0 +28,0 @@ "@types/heft-jest": "1.0.1",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc