Socket
Socket
Sign inDemoInstall

wsrun

Package Overview
Dependencies
Maintainers
8
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wsrun - npm Package Compare versions

Comparing version 5.0.2 to 5.1.0

build/console.js

24

build/cmd-process.js

@@ -12,3 +12,4 @@ "use strict";

class CmdProcess {
constructor(cmd, pkgName, opts) {
constructor(console, cmd, pkgName, opts) {
this.console = console;
this.cmd = cmd;

@@ -67,3 +68,3 @@ this.pkgName = pkgName;

if (!this.opts.silent)
console.error(this.autoAugmentLine(msg));
this.console.error(this.autoAugmentLine(msg));
if (this.opts.rejectOnNonZeroExit)

@@ -110,4 +111,2 @@ return this._finished.reject(new Error(msg));

}
const stdOutBuffer = [];
const stdErrBuffer = [];
this.cmd = cmd;

@@ -124,6 +123,3 @@ this.cp = child_process_1.spawn(sh, args, {

this.cp.stdout.pipe(split()).on('data', (line) => {
if (this.opts.collectLogs)
stdOutBuffer.push(line);
else
console.log(this.autoAugmentLine(line));
this.console.log(this.autoAugmentLine(line));
if (this.doneCriteria && this.doneCriteria.test(line))

@@ -134,16 +130,6 @@ this._finished.resolve();

this.cp.stderr.pipe(split()).on('data', (line) => {
if (this.opts.collectLogs)
stdErrBuffer.push(line);
else
console.error(this.autoAugmentLine(line));
this.console.error(this.autoAugmentLine(line));
if (this.doneCriteria && this.doneCriteria.test(line))
this._finished.resolve();
});
if (this.opts.collectLogs)
this._closed.promise.then(() => {
if (stdOutBuffer.length)
console.log(stdOutBuffer.map(line => this.autoAugmentLine(line)).join('\n'));
if (stdErrBuffer.length)
console.error(stdErrBuffer.map(line => this.autoAugmentLine(line)).join('\n'));
});
}

@@ -150,0 +136,0 @@ }

@@ -28,2 +28,3 @@ "use strict";

parallel: {
alias: 'a',
boolean: true,

@@ -33,2 +34,3 @@ describe: 'Fully parallel mode (default)'

stages: {
alias: 't',
boolean: true,

@@ -38,2 +40,3 @@ describe: 'Run in stages: start with packages that have no deps'

serial: {
alias: 's',
boolean: true,

@@ -56,2 +59,3 @@ describe: 'Same as "stages" but with no parallelism at the stage level'

alias: 'r',
default: false,
boolean: true,

@@ -83,2 +87,4 @@ describe: 'Execute the same script on all of its dependencies, too'

'fast-exit': {
alias: 'e',
default: false,
boolean: true,

@@ -88,10 +94,14 @@ describe: 'If at least one script exits with code > 0, abort'

'collect-logs': {
alias: 'l',
default: false,
boolean: true,
describe: 'Collect per-package output and print it at the end of each script'
},
'no-prefix': {
prefix: {
default: true,
boolean: true,
describe: "Don't prefix output"
describe: 'Prefix output with package name'
},
'rewrite-paths': {
default: false,
boolean: true,

@@ -109,2 +119,3 @@ describe: 'Rewrite relative paths in the standard output, by prepending the <root_folder>/<package_name>.'

exclude: {
alias: 'x',
type: 'string',

@@ -114,2 +125,4 @@ describe: 'Skip running the command for that package'

'exclude-missing': {
alias: 'm',
default: false,
boolean: true,

@@ -119,2 +132,3 @@ describe: 'Skip packages which lack the specified command in the scripts section of their package.json'

report: {
default: false,
boolean: true,

@@ -124,2 +138,3 @@ describe: 'Show an execution report once the command has finished in each package'

concurrency: {
alias: 'y',
type: 'number',

@@ -140,3 +155,2 @@ describe: 'Maximum number of commands to be executed at once'

const argv = parsePositionally(yargsParser, process.argv.slice(2)); // yargs.argv
const bin = argv.bin || 'yarn';
let mode;

@@ -152,12 +166,3 @@ if (argv.stages) {

}
// should we run the command on all the dependencies, too?
const recursive = argv.recursive || argv.r || false;
const fastExit = argv.fastExit || false;
const collectLogs = argv.collectLogs || false;
const addPrefix = argv.prefix === undefined ? true : false;
const rewritePaths = Boolean(argv.rewritePaths);
const doneCriteria = argv.doneCriteria;
const exclude = (argv.exclude && (Array.isArray(argv.exclude) ? argv.exclude : [argv.exclude])) || [];
const excludeMissing = argv.excludeMissing || false;
const showReport = argv.report || false;
const concurrency = typeof argv.concurrency === 'number' ? argv.concurrency : null;

@@ -183,13 +188,13 @@ const cmd = argv._;

let runner = new run_graph_1.RunGraph(pkgJsons, {
bin,
fastExit,
collectLogs,
addPrefix,
rewritePaths,
bin: argv.bin,
fastExit: argv.fastExit,
collectLogs: argv.collectLogs,
addPrefix: argv.prefix,
rewritePaths: argv.rewritePaths,
mode: mode,
recursive,
doneCriteria,
recursive: argv.recursive,
doneCriteria: argv.doneCriteria,
exclude,
excludeMissing,
showReport,
excludeMissing: argv.excludeMissing,
showReport: argv.report,
if: argv.if || null,

@@ -207,3 +212,3 @@ ifDependency: argv.ifDependency || false,

runner.run(cmd, runlist.length > 0 ? runlist : undefined).then(hadError => {
if (hadError && fastExit) {
if (hadError && argv.fastExit) {
console.error(chalk_1.default.red(`Aborted execution due to previous error`));

@@ -210,0 +215,0 @@ }

@@ -10,2 +10,3 @@ "use strict";

const fix_paths_1 = require("./fix-paths");
const console_1 = require("./console");
let mkThroat = require('throat')(Bromise);

@@ -49,2 +50,6 @@ let passThrough = f => f();

this.throat = mkThroat(opts.concurrency);
if (opts.collectLogs)
this.consoles = new console_1.SerializedConsole(console);
else
this.consoles = new console_1.DefaultConsole();
}

@@ -100,3 +105,4 @@ closeAll() {

let cmdLine = this.makeCmd(cmd.split(' '));
const child = new cmd_process_1.CmdProcess(cmdLine, pkg, {
let c = this.consoles.create();
const child = new cmd_process_1.CmdProcess(c, cmdLine, pkg, {
rejectOnNonZeroExit: false,

@@ -109,2 +115,3 @@ silent: true,

});
child.finished.then(() => this.consoles.done(c));
let rres = child.exitCode.then(code => code === 0);

@@ -145,3 +152,4 @@ child.start();

let cmdLine = this.makeCmd(cmdArray);
const child = new cmd_process_1.CmdProcess(cmdLine, pkg, {
let c = this.consoles.create();
const child = new cmd_process_1.CmdProcess(c, cmdLine, pkg, {
rejectOnNonZeroExit: this.opts.fastExit,

@@ -154,2 +162,3 @@ collectLogs: this.opts.collectLogs,

});
child.finished.then(() => this.consoles.done(c));
child.exitCode.then(code => this.resultMap.set(pkg, code));

@@ -156,0 +165,0 @@ this.children.push(child);

@@ -15,21 +15,21 @@ "use strict";

function listPkgs(wsRoot, globs) {
let filesAndDirs = lodash_1.flatMap(globs, g => glob.sync(g));
// based on yarn v1.18.0 workspace resolution: https://github.com/yarnpkg/yarn/blob/v1.18.0/src/config.js#L794
const registryFilenames = ['package.json', 'yarn.json'];
const registryFolders = ['node_modules'];
const trailingPattern = `/+(${registryFilenames.join('|')})`;
const ignorePatterns = registryFolders.map(folder => `/${folder}/**/+(${registryFilenames.join('|')})`);
const pkgJsonPaths = lodash_1.flatMap(globs, (g) => glob.sync(g.replace(/\/?$/, trailingPattern), {
cwd: wsRoot,
ignore: ignorePatterns.map(ignorePattern => g.replace(/\/?$/, ignorePattern))
}));
const packages = {};
filesAndDirs.forEach(f => {
const isDir = fs.lstatSync(path.resolve(wsRoot, f)).isDirectory();
if (isDir) {
const pkgJsonPath = path.resolve(wsRoot, f, 'package.json');
const hasPkgJson = fs.existsSync(pkgJsonPath);
if (!hasPkgJson) {
// console.warn(`Warning: ${f} is a directory, but has no package.json`)
return;
}
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
if (!pkgJson.name)
throw new Error(`Package in directory ${f} has no name in package.json`);
packages[pkgJson.name] = {
path: path.join(wsRoot, f),
json: pkgJson
};
}
pkgJsonPaths.forEach(pkgJsonPath => {
const pkgDir = path.dirname(pkgJsonPath);
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
if (!pkgJson.name)
throw new Error(`Package in directory ${pkgDir} has no name in ${path.basename(pkgJsonPath)}`);
packages[pkgJson.name] = {
path: path.join(wsRoot, pkgDir),
json: pkgJson
};
});

@@ -36,0 +36,0 @@ return packages;

{
"name": "wsrun",
"version": "5.0.2",
"version": "5.1.0",
"description": "executes commands on packages in parallel, but is aware of the dependencies between them",

@@ -43,3 +43,3 @@ "main": "./build/index.js",

"@types/split": "^0.3.28",
"@types/yargs": "^10.0.0",
"@types/yargs": "^11.1.3",
"jest": "^23.0.0",

@@ -52,3 +52,5 @@ "mkdirp": "^0.5.1",

"ts-jest": "23.10.5",
"typescript": "^3.1.1"
"ts-mockito": "^2.5.0",
"typescript": "^3.1.1",
"prettier": "^1.19.1"
},

@@ -58,3 +60,4 @@ "scripts": {

"watch": "tsc -w",
"test": "yarn build && jest",
"test": "yarn build && yarn test:prettier && jest",
"test:prettier": "prettier -c '**/*.ts' '**/*.json'",
"test:watch": "jest --watch",

@@ -73,4 +76,4 @@ "dev": "run-p test:watch watch",

"throat": "^4.1.0",
"yargs": "^10.0.3"
"yargs": "^11.1.1"
}
}

@@ -11,32 +11,32 @@ # Workspace script runner

Mode (choose one):
--parallel Fully parallel mode (default) [boolean]
--stages Run in stages: start with packages that have no deps [boolean]
--serial Same as "stages" but with no parallelism at the stage level [boolean]
--parallel, -a Fully parallel mode (default) [boolean]
--stages, -t Run in stages: start with packages that have no deps [boolean]
--serial, -s Same as "stages" but with no parallelism at the stage level [boolean]
Package Options:
--recursive, -r Execute the same script on all of its dependencies, too [boolean]
--package, -p Run only for packages matching this glob. Can be used multiple times. [array]
--recursive, -r Execute the same script on all of its dependencies, too [boolean]
--package, -p Run only for packages matching this glob. Can be used multiple times. [array]
Misc Options:
--fast-exit If at least one script exits with code > 0, abort [boolean]
--collect-logs Collect per-package output and print it at the end of each script [boolean]
--no-prefix Don't prefix output [boolean]
--rewrite-paths Rewrite relative paths in the standard output, by prepending the
<root_folder>/<package_name>. [boolean]
--bin The program to pass the command to [string] [default: "yarn"]
--done-criteria Consider a process "done" when an output line matches the specified RegExp
--exclude Skip running the command for that package [string]
--exclude-missing Skip packages which lack the specified command in the scripts section of their
package.json [boolean]
--report Show an execution report once the command has finished in each package[boolean]
--if Run main command only if this condition runs successfully
--ifDependency Run main command only if packages dependencies passed the condition (not
available in parallel mode) [boolean]
--fast-exit, e If at least one script exits with code > 0, abort [boolean]
--collect-logs, l Collect per-package output and print it at the end of each script [boolean]
--no-prefix Don't prefix output [boolean]
--rewrite-paths Rewrite relative paths in the standard output, by prepending the
<root_folder>/<package_name>. [boolean]
--bin The program to pass the command to [string] [default: "yarn"]
--done-criteria Consider a process "done" when an output line matches the specified RegExp
--exclude, x Skip running the command for that package [string]
--exclude-missing, m Skip packages which lack the specified command in the scripts section of their
package.json [boolean]
--report Show an execution report once the command has finished in each package[boolean]
--if Run main command only if this condition runs successfully
--ifDependency Run main command only if packages dependencies passed the condition (not
available in parallel mode) [boolean]
Other Options:
--help Show help [boolean]
--version Show version number [boolean]
--help Show help [boolean]
--version Show version number [boolean]
-c Denotes the end of the package list and the beginning of the command. Can be used
instead of "--" [boolean]
--concurrency Maximum number of commands to be executed at once [number]
instead of "--" [boolean]
--concurrency, y Maximum number of commands to be executed at once [number]

@@ -43,0 +43,0 @@ ```

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