Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@statoscope/cli

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@statoscope/cli - npm Package Compare versions

Comparing version 5.6.2 to 5.7.0-alpha.0

dist/commands/legacyWebpackValidator.d.ts

19

dist/commands/validate.d.ts
import { Argv } from 'yargs';
import { NormalizedFile } from '@statoscope/webpack-model/dist/normalize';
export declare type TestEntryType = 'error' | 'warn' | 'info';
export declare type TestEntry = {
type?: TestEntryType;
assert?: boolean;
message: string;
filename?: string;
};
export declare type Data = {
files: Object[];
compilations: Object[];
query: (query: string, data?: NormalizedFile[]) => unknown;
};
export declare type API = {
error(message: string, filename?: string): void;
warn(message: string, filename?: string): void;
info(message: string, filename?: string): void;
};
export declare type ValidatorFn = (data: Data, api: API) => Promise<string | void>;
export default function (yargs: Argv): Argv;

193

dist/commands/validate.js

@@ -6,73 +6,28 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// @ts-ignore
const json_ext_1 = require("@discoveryjs/json-ext");
const webpack_model_1 = require("@statoscope/webpack-model");
const helpers_1 = require("@statoscope/helpers");
function makeQueryValidator(query) {
function validate(type, message) {
if (!(!type || type === 'error' || type === 'warn' || type === 'info')) {
throw new Error(`Unknown message type [${type}]`);
}
if (!message) {
throw new Error(`Message must be specified`);
}
}
function callAPI(api, { type, filename, message }) {
validate(type, message);
if (typeof type === 'undefined' || type === 'error') {
api.error(message, filename);
}
else if (type === 'warn') {
api.warn(message, filename);
}
else if (type === 'info') {
api.info(message, filename);
}
else {
console.log('Unknown message type:', type);
api.error(message, filename);
}
}
return async (data, api) => {
const result = data.query(query);
for (const item of result) {
let type = item.type;
if (!item.assert) {
if (type === undefined && !Object.prototype.hasOwnProperty.call(item, 'assert')) {
type = 'info';
}
callAPI(api, { type, message: item.message, filename: item.filename });
}
}
};
}
function handleValidator(validator) {
const validatorPath = path_1.default.resolve(validator);
const ext = path_1.default.extname(validatorPath);
let validatorFn;
if (ext === '.js') {
validatorFn = require(validatorPath);
}
else {
validatorFn = fs_1.default.readFileSync(validatorPath, 'utf8');
}
if (typeof validatorFn === 'string') {
validatorFn = makeQueryValidator(validatorFn);
}
return validatorFn;
}
const stats_validator_1 = __importDefault(require("@statoscope/stats-validator"));
const stats_validator_reporter_console_1 = __importDefault(require("@statoscope/stats-validator-reporter-console"));
const make_reporter_instance_1 = require("@statoscope/config/dist/make-reporter-instance");
const legacyWebpackValidator_1 = __importDefault(require("./legacyWebpackValidator"));
function default_1(yargs) {
return yargs.command('validate [validator] [input]', `[BETA] Validate one or more JSON stats
return yargs.command('validate [validator] [input]', `Validate or compare JSON stats
Examples:
Single stats: validate path/to/validator.js path/to/stats.json
Multiple stats: generate path/to/validator.js --input path/to/stats-1.json path/to/stats-2.json`, (yargs) => {
return yargs
.positional('validator', {
describe: 'path to validator script',
Validate stats: validate --input path/to/stats.json
Compare stats: validate --input path/to/branch.json --reference path/to/master.json
Validate stats [DEPRECATED]: validate --validator path/to/validator.js --input path/to/stats.json
Validate multiple stats [DEPRECATED]: validate --validator path/to/validator.js --input path/to/stats.json --input path/to/another/stats.json`, (yargs) => {
return (yargs
// todo remove in 6.0
.option('validator', {
describe: 'path to validator script [DEPRECATED]',
alias: 'v',
type: 'string',
})
.positional('input', {
.option('config', {
describe: 'path to statoscope config',
alias: 'c',
type: 'string',
default: path_1.default.join(process.cwd(), 'statoscope.config.js'),
})
.option('input', {
describe: 'path to a stats.json',

@@ -82,72 +37,62 @@ alias: 'i',

})
.option('reference', {
describe: 'path to a stats-file to compare with',
alias: 'r',
type: 'string',
})
.option('warn-as-error', {
describe: 'treat warn as error',
alias: 'w',
type: 'boolean',
describe: 'Treat warnings as errors',
alias: 'w',
})
.array('input')
.demandOption(['validator', 'input']);
.demandOption(['input'])
.array('input'));
}, async (argv) => {
const files = [];
for (const file of argv.input) {
const data = await json_ext_1.parseChunked(fs_1.default.createReadStream(file));
files.push({
name: path_1.default.basename(file),
data,
var _a, _b;
if (argv.validator) {
await legacyWebpackValidator_1.default({
validator: argv.validator,
input: argv.input,
warnAsError: argv['warn-as-error'],
});
return;
}
const prepared = webpack_model_1.prepareWithJora(files, { helpers: helpers_1.jora() });
const validator = handleValidator(argv.validator);
const storage = {};
let hasErrors = false;
let errors = 0;
let warnings = 0;
let infos = 0;
const api = {
warn(message, filename = 'unknown') {
if (argv['warn-as-error']) {
hasErrors = true;
const configPath = path_1.default.resolve(argv.config);
let config;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
config = require(configPath);
}
catch (e) {
console.log('[WARN]: No Statoscope-config found');
config = {};
}
const rootPath = path_1.default.dirname(configPath);
const validateConfig = (_a = config.validate) !== null && _a !== void 0 ? _a : { rules: {} };
if (argv['warn-as-error']) {
validateConfig.warnAsError = true;
}
const validator = new stats_validator_1.default(validateConfig, rootPath);
const reporters = [];
if ((config === null || config === void 0 ? void 0 : config.silent) !== true) {
if ((_b = config === null || config === void 0 ? void 0 : config.validate) === null || _b === void 0 ? void 0 : _b.reporters) {
for (const item of config.validate.reporters) {
reporters.push(make_reporter_instance_1.makeReporterInstance(item, rootPath));
}
storage[filename] = storage[filename] || [];
storage[filename].push({ type: 'warn', filename, message });
warnings++;
},
error(message, filename = 'unknown') {
hasErrors = true;
storage[filename] = storage[filename] || [];
storage[filename].push({ type: 'error', filename, message });
errors++;
},
info(message, filename = 'unknown') {
storage[filename] = storage[filename] || [];
storage[filename].push({ type: 'info', filename, message });
infos++;
},
};
await validator({
files: prepared.files,
compilations: prepared.compilations,
query: prepared.query,
}, api);
for (const [filename, items] of Object.entries(storage)) {
console.log(filename);
for (const item of items) {
console.log(` ${item.type}: ${item.message}`);
}
else {
reporters.push(new stats_validator_reporter_console_1.default());
}
}
console.log('');
if (errors) {
console.log(`Errors: ${errors}`);
const result = await validator.validate(path_1.default.resolve(argv.input[0]), argv.reference ? path_1.default.resolve(argv.reference) : void 0);
for (const rule of result.rules) {
const storage = rule.api.getStorage();
if (rule.execParams.mode === 'error' && storage.length) {
process.exitCode = 1;
break;
}
}
if (warnings) {
console.log(`Warnings: ${warnings}`);
for (const reporter of reporters) {
await reporter.run(result);
}
if (infos) {
console.log(`Info: ${infos}`);
}
console.log('Done');
if (hasErrors) {
// eslint-disable-next-line no-process-exit
process.exitCode = 1;
}
});

@@ -154,0 +99,0 @@ }

@@ -1,4 +0,1 @@

/// <reference types="node" />
import { Readable, Writable } from 'stream';
export declare function waitFinished(stream: Readable | Writable): Promise<void>;
export declare function transform(from: string[], to?: string): Promise<string>;

@@ -6,35 +6,19 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.transform = exports.waitFinished = void 0;
const fs_1 = __importDefault(require("fs"));
exports.transform = void 0;
const path_1 = __importDefault(require("path"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const report_writer_1 = __importDefault(require("@statoscope/report-writer"));
function waitFinished(stream) {
return new Promise((resolve, reject) => {
stream.once('end', resolve);
stream.once('finish', resolve);
stream.once('error', reject);
});
}
exports.waitFinished = waitFinished;
const utils_1 = require("@statoscope/report-writer/dist/utils");
async function transform(from, to) {
const id = from.length === 1 ? path_1.default.basename(from[0], '.json') : Date.now();
to = to || path_1.default.join(os_1.default.tmpdir(), `statoscope-report-${id}.html`);
const outputStream = fs_1.default.createWriteStream(to);
const htmlWriter = new report_writer_1.default({
scripts: [{ type: 'path', path: require.resolve('@statoscope/webpack-ui') }],
init: `function (data) {
Statoscope.default(data.map((item) => ({ name: item.id, data: item.data })));
}`,
});
for (const file of from) {
const id = path_1.default.basename(file);
htmlWriter.addChunkWriter(fs_1.default.createReadStream(file), id);
}
htmlWriter.getStream().pipe(outputStream);
htmlWriter.write();
await waitFinished(outputStream);
return to;
const id = path_1.default.basename(from[0], '.json');
const reportPath = to || path_1.default.join(os_1.default.tmpdir(), `statoscope-report-${id}-${Date.now()}.html`);
return utils_1.transform({
writer: {
scripts: [{ type: 'path', path: require.resolve('@statoscope/webpack-ui') }],
init: `function (data) {
Statoscope.default(data.map((item) => ({ name: item.id, data: item.data })));
}`,
},
}, from, reportPath);
}
exports.transform = transform;
//# sourceMappingURL=utils.js.map
{
"name": "@statoscope/cli",
"version": "5.6.2",
"version": "5.7.0-alpha.0",
"description": "Statoscope CLI tools",

@@ -28,13 +28,15 @@ "scripts": {

"@discoveryjs/json-ext": "^0.5.3",
"@statoscope/helpers": "^5.6.1",
"@statoscope/report-writer": "^5.5.1",
"@statoscope/webpack-model": "^5.6.2",
"@statoscope/webpack-ui": "^5.6.2",
"@statoscope/config": "5.7.0-alpha.0",
"@statoscope/helpers": "5.7.0-alpha.0",
"@statoscope/report-writer": "5.7.0-alpha.0",
"@statoscope/stats-validator": "5.7.0-alpha.0",
"@statoscope/stats-validator-reporter-console": "5.7.0-alpha.0",
"@statoscope/types": "5.7.0-alpha.0",
"@statoscope/webpack-model": "5.7.0-alpha.0",
"@statoscope/webpack-ui": "5.7.0-alpha.0",
"@types/yargs": "^17.0.0",
"open": "^8.0.4",
"yargs": "^17.0.1"
},
"devDependencies": {
"@types/yargs": "^17.0.0"
},
"gitHead": "d0ac649118f394b2dd8a22f2fb980a1e0483fc93"
"gitHead": "d87b4b850ad9ff1f94110fb017bb915a77ed4c62"
}

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