@statoscope/cli
Advanced tools
Comparing version 5.6.2 to 5.7.0-alpha.0
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; |
@@ -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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33281
0
22
395
12
1
2
+ Added@statoscope/stats-validator-reporter-console@5.7.0-alpha.0
+ Added@types/yargs@^17.0.0
+ Added@statoscope/config@5.7.0-alpha.0(transitive)
+ Added@statoscope/extensions@5.7.0-alpha.0(transitive)
+ Added@statoscope/helpers@5.7.0-alpha.0(transitive)
+ Added@statoscope/report-writer@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-extension-compressed@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-extension-package-info@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-extension-stats-validation-result@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-validator@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-validator-reporter-console@5.7.0-alpha.0(transitive)
+ Added@statoscope/types@5.7.0-alpha.0(transitive)
+ Added@statoscope/webpack-model@5.7.0-alpha.0(transitive)
+ Added@statoscope/webpack-ui@5.7.0-alpha.0(transitive)
+ Added@types/yargs@17.0.33(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedjora@1.0.0-beta.13(transitive)
+ Addedsupports-color@7.2.0(transitive)
- Removed@jridgewell/gen-mapping@0.3.8(transitive)
- Removed@jridgewell/resolve-uri@3.1.2(transitive)
- Removed@jridgewell/set-array@1.2.1(transitive)
- Removed@jridgewell/source-map@0.3.6(transitive)
- Removed@jridgewell/sourcemap-codec@1.5.0(transitive)
- Removed@jridgewell/trace-mapping@0.3.25(transitive)
- Removed@statoscope/extensions@5.28.1(transitive)
- Removed@statoscope/helpers@5.28.1(transitive)
- Removed@statoscope/report-writer@5.28.1(transitive)
- Removed@statoscope/stats@5.28.1(transitive)
- Removed@statoscope/stats-extension-compressed@5.28.1(transitive)
- Removed@statoscope/stats-extension-custom-reports@5.28.1(transitive)
- Removed@statoscope/stats-extension-package-info@5.28.1(transitive)
- Removed@statoscope/stats-extension-stats-validation-result@5.28.1(transitive)
- Removed@statoscope/types@5.28.1(transitive)
- Removed@statoscope/webpack-model@5.28.3(transitive)
- Removed@statoscope/webpack-ui@5.28.3(transitive)
- Removed@types/eslint@9.6.1(transitive)
- Removed@types/eslint-scope@3.7.7(transitive)
- Removed@types/estree@1.0.6(transitive)
- Removed@types/json-schema@7.0.15(transitive)
- Removed@types/md5@2.3.5(transitive)
- Removed@types/node@18.19.70(transitive)
- Removed@types/pako@2.0.3(transitive)
- Removed@types/webpack@5.28.5(transitive)
- Removed@webassemblyjs/ast@1.14.1(transitive)
- Removed@webassemblyjs/floating-point-hex-parser@1.13.2(transitive)
- Removed@webassemblyjs/helper-api-error@1.13.2(transitive)
- Removed@webassemblyjs/helper-buffer@1.14.1(transitive)
- Removed@webassemblyjs/helper-numbers@1.13.2(transitive)
- Removed@webassemblyjs/helper-wasm-bytecode@1.13.2(transitive)
- Removed@webassemblyjs/helper-wasm-section@1.14.1(transitive)
- Removed@webassemblyjs/ieee754@1.13.2(transitive)
- Removed@webassemblyjs/leb128@1.13.2(transitive)
- Removed@webassemblyjs/utf8@1.13.2(transitive)
- Removed@webassemblyjs/wasm-edit@1.14.1(transitive)
- Removed@webassemblyjs/wasm-gen@1.14.1(transitive)
- Removed@webassemblyjs/wasm-opt@1.14.1(transitive)
- Removed@webassemblyjs/wasm-parser@1.14.1(transitive)
- Removed@webassemblyjs/wast-printer@1.14.1(transitive)
- Removed@xtuc/ieee754@1.2.0(transitive)
- Removed@xtuc/long@4.2.2(transitive)
- Removedacorn@8.14.0(transitive)
- Removedajv@6.12.6(transitive)
- Removedajv-formats@2.1.1(transitive)
- Removedajv-keywords@3.5.25.1.0(transitive)
- Removedbrowserslist@4.24.4(transitive)
- Removedbuffer-from@1.1.2(transitive)
- Removedcaniuse-lite@1.0.30001690(transitive)
- Removedchrome-trace-event@1.0.4(transitive)
- Removedcommander@2.20.3(transitive)
- Removedelectron-to-chromium@1.5.79(transitive)
- Removedenhanced-resolve@5.18.0(transitive)
- Removedes-module-lexer@1.6.0(transitive)
- Removedeslint-scope@5.1.1(transitive)
- Removedesrecurse@4.3.0(transitive)
- Removedestraverse@4.3.05.3.0(transitive)
- Removedevents@3.3.0(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedglob-to-regexp@0.4.1(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedjest-worker@27.5.1(transitive)
- Removedjora@1.0.0-beta.8(transitive)
- Removedjson-parse-even-better-errors@2.3.1(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedloader-runner@4.3.0(transitive)
- Removedmerge-stream@2.0.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedneo-async@2.6.2(transitive)
- Removednode-releases@2.0.19(transitive)
- Removedpako@2.1.0(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedrandombytes@2.1.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedschema-utils@3.3.04.3.0(transitive)
- Removedserialize-javascript@6.0.2(transitive)
- Removedsource-map@0.6.1(transitive)
- Removedsource-map-support@0.5.21(transitive)
- Removedsupports-color@8.1.1(transitive)
- Removedtapable@2.2.1(transitive)
- Removedterser@5.37.0(transitive)
- Removedterser-webpack-plugin@5.3.11(transitive)
- Removedundici-types@5.26.5(transitive)
- Removedupdate-browserslist-db@1.1.2(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedwatchpack@2.4.2(transitive)
- Removedwebpack@5.97.1(transitive)
- Removedwebpack-sources@3.2.3(transitive)