Socket
Socket
Sign inDemoInstall

esprint

Package Overview
Dependencies
Maintainers
5
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

esprint - npm Package Compare versions

Comparing version 0.7.0 to 1.0.0

39

build/Client.js

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

var _dnodeWeakNapi = _interopRequireDefault(require("dnode-weak-napi"));
var _jayson = _interopRequireDefault(require("jayson"));

@@ -31,20 +31,27 @@ var _eslint = require("eslint");

connect() {
const d = _dnodeWeakNapi.default.connect(this.port);
const client = _jayson.default.client.http({
port: this.port
});
const formatter = this.formatter;
const maxWarnings = this.maxWarnings;
d.on('remote', function (remote) {
setInterval(() => {
remote.status('', results => {
if (!results.message) {
d.end();
console.log(formatter(results.records));
process.exit(results && (results.errorCount > 0 ? 1 : 0 || results.warningCount > maxWarnings ? 1 : 0));
} else {
(0, _cliUtils.clearLine)();
process.stdout.write(results.message);
}
});
}, 1000);
});
setInterval(() => {
client.request('status', null, function (error, response) {
if (error) {
throw error;
}
const {
result
} = response;
if (!result.message) {
console.log(formatter(result.records));
process.exit(result && (result.errorCount > 0 ? 1 : 0 || result.warningCount > maxWarnings ? 1 : 0));
} else {
(0, _cliUtils.clearLine)();
process.stdout.write(result.message);
}
});
}, 1000);
}

@@ -51,0 +58,0 @@

@@ -16,4 +16,2 @@ "use strict";

var _util = require("../util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -38,6 +36,6 @@

});
const filePaths = (0, _util.flatten)(paths.map(globPath => _glob.default.sync(globPath, {
const filePaths = (paths.map(globPath => _glob.default.sync(globPath, {
cwd: rcDir,
absolute: true
}))); // filter out the files that we tell eslint to ignore
})) || []).flat(); // filter out the files that we tell eslint to ignore

@@ -44,0 +42,0 @@ const nonIgnoredFilePaths = filePaths.filter(filePath => {

@@ -8,6 +8,4 @@ "use strict";

var _workerFarm = _interopRequireDefault(require("worker-farm"));
var _jestWorker = _interopRequireDefault(require("jest-worker"));
var _util = require("./util");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -17,8 +15,7 @@

constructor(numThreads, suppressWarnings, fix) {
const workers = (0, _workerFarm.default)({
autoStart: true,
maxConcurrentCallsPerWorker: Infinity,
maxConcurrentWorkers: numThreads
}, require.resolve('./LintWorker'));
this.workers = (0, _util.promisify)(workers);
this.worker = new _jestWorker.default(require.resolve('./LintWorker'), {
exposedMethods: ['worker'],
numWorkers: numThreads,
enableWorkerThreads: true
});
this.suppressWarnings = suppressWarnings;

@@ -31,3 +28,3 @@ this.fix = fix;

return Promise.all(files.map(file => {
return that.workers({
return that.worker.worker({
fileArg: file,

@@ -38,3 +35,3 @@ suppressWarnings: that.suppressWarnings,

})).then(results => {
const records = (0, _util.flatten)(results); // produce a sum of total num of errors/warnings
const records = (results || []).flat(); // produce a sum of total num of errors/warnings

@@ -41,0 +38,0 @@ const {

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.worker = worker;
var _eslint = require("eslint");

@@ -21,10 +26,11 @@

module.exports = (options, callback) => {
const results = lintFile(options.fileArg, options.fix);
if (options.suppressWarnings) {
callback(null, _eslint.CLIEngine.getErrorResults(results));
} else {
callback(null, results);
}
};
async function worker({
fileArg,
fix,
suppressWarnings
}) {
return new Promise(resolve => {
const results = lintFile(fileArg, fix);
resolve(suppressWarnings ? _eslint.CLIEngine.getErrorResults(results) : results);
});
}

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

var _dnodeWeakNapi = _interopRequireDefault(require("dnode-weak-napi"));
var _chokidar = _interopRequireDefault(require("chokidar"));
var _path = _interopRequireDefault(require("path"));
var _glob = _interopRequireDefault(require("glob"));
var _sane = _interopRequireDefault(require("sane"));
var _jayson = _interopRequireDefault(require("jayson"));
var _glob = _interopRequireDefault(require("glob"));
var _path = _interopRequireDefault(require("path"));

@@ -49,9 +49,11 @@ var _LintRunner = _interopRequireDefault(require("./LintRunner"));

const server = (0, _dnodeWeakNapi.default)({
status: (param, cb) => {
if (this.filesToProcess === 0) {
return cb(this.getResultsFromCache());
const that = this;
const server = _jayson.default.server({
status: function (args, cb) {
if (that.filesToProcess === 0) {
cb(null, that.getResultsFromCache());
} else {
return cb({
message: `Linting...${this.filesToProcess} left to lint`
cb(null, {
message: `Linting...${that.filesToProcess} left to lint`
});

@@ -61,15 +63,17 @@ }

});
process.send({
server: server
});
server.listen(this.port);
server.http().listen(this.port);
}
_setupWatcher(root, paths, ignored) {
const watcher = (0, _sane.default)(root, {
glob: paths,
const watcher = _chokidar.default.watch(paths, {
disableGlobbing: true,
ignored: ignored,
dot: true,
watchman: process.env.NODE_ENV !== 'test'
ignoreInitial: true,
ignorePermissionErrors: true
});
watcher.on('ready', () => {

@@ -76,0 +80,0 @@ process.send({

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

});
exports.findFile = exports.isPortTaken = exports.flatten = exports.promisify = void 0;
exports.findFile = exports.isPortTaken = void 0;

@@ -17,28 +17,2 @@ var _net = _interopRequireDefault(require("net"));

const promisify = fn => {
return function () {
var args = Array.prototype.slice.call(arguments);
return new Promise(function (resolve, reject) {
args.push(function (err, res) {
if (err) {
reject(err);
} else {
resolve(res);
}
});
fn.apply(this, args);
});
};
};
exports.promisify = promisify;
const flatten = array => {
return array.reduce(function (acc, curr) {
return curr.concat(acc);
}, []);
};
exports.flatten = flatten;
const isPortTaken = port => {

@@ -45,0 +19,0 @@ return new Promise((resolve, reject) => {

{
"name": "esprint",
"version": "0.7.0",
"version": "1.0.0",
"description": "Parallelized eslint",

@@ -26,15 +26,8 @@ "main": "index.js",

"homepage": "https://github.com/pinterest/esprint#readme",
"resolutions": {
"js-yaml": "^3.13.1",
"lodash": "^4.17.15",
"randomatic": ">=3.0.0",
"sshpk": "^1.16.1"
},
"dependencies": {
"dnode-weak-napi": "1.2.2",
"fb-watchman": "^2.0.0",
"glob": "^7.1.4",
"sane": "^4.1.0",
"worker-farm": "^1.7.0",
"yargs": "^14.0.0"
"chokidar": "^3.4.3",
"glob": "^7.1.6",
"jayson": "^3.3.4",
"jest-worker": "^26.6.2",
"yargs": "^16.2.0"
},

@@ -45,3 +38,3 @@ "peerDependencies": {

"engines": {
"node": ">=8"
"node": ">=12"
},

@@ -52,12 +45,11 @@ "bin": {

"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^9.0.0",
"babel-jest": "^23.4.2",
"chalk": "^2.0.1",
"eslint": "^6.8.0",
"jest": "^24.9.0"
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.10",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",
"chalk": "^4.1.0",
"eslint": "^7.15.0",
"jest": "^26.6.3"
}
}

@@ -1,2 +0,2 @@

# esprint - a fast eslint runner [![Build Status](https://img.shields.io/travis/pinterest/esprint/master.svg?style=flat)](https://travis-ci.org/pinterest/esprint) [![npm version](https://img.shields.io/npm/v/esprint.svg?style=flat)](https://www.npmjs.com/package/esprint)
# esprint - a fast eslint runner [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/pinterest/esprint/Main%20workflow%20(PR))](https://github.com/pinterest/esprint/actions?query=workflow%3A%22Main+workflow+%28PR%29%22) [![npm version](https://img.shields.io/npm/v/esprint)](https://www.npmjs.com/package/esprint)

@@ -3,0 +3,0 @@ esprint (pronounced E-S-sprint) speeds up eslint by running the linting engine across multiple threads.

@@ -1,2 +0,2 @@

import dnode from 'dnode-weak-napi';
import jayson from 'jayson';
import { CLIEngine } from 'eslint';

@@ -15,21 +15,27 @@ import { clearLine } from './cliUtils';

connect() {
const d = dnode.connect(this.port);
const client = jayson.client.http({
port: this.port
});
const formatter = this.formatter;
const maxWarnings = this.maxWarnings;
d.on('remote', function(remote) {
setInterval(() => {
remote.status('', results => {
if (!results.message) {
d.end();
console.log(formatter(results.records));
process.exit(results && (results.errorCount > 0 ? 1 : 0
|| results.warningCount > maxWarnings ? 1 : 0));
} else {
clearLine();
process.stdout.write(results.message);
}
});
}, 1000);
});
setInterval(() => {
client.request('status', null, function(error, response) {
if (error) {
throw error;
}
const { result } = response;
if (!result.message) {
console.log(formatter(result.records));
process.exit(result && (result.errorCount > 0 ? 1 : 0
|| result.warningCount > maxWarnings ? 1 : 0));
} else {
clearLine();
process.stdout.write(result.message);
}
});
}, 1000);
}
}

@@ -5,3 +5,2 @@ import glob from 'glob';

import LintRunner from '../LintRunner';
import { flatten } from '../util';

@@ -23,3 +22,3 @@ export const check = (options) => {

const filePaths = flatten(paths.map(globPath => glob.sync(globPath, { cwd: rcDir, absolute: true })));
const filePaths = (paths.map(globPath => glob.sync(globPath, { cwd: rcDir, absolute: true })) || []).flat();
// filter out the files that we tell eslint to ignore

@@ -26,0 +25,0 @@ const nonIgnoredFilePaths = filePaths.filter((filePath) => {

@@ -21,7 +21,9 @@ import { fork } from 'child_process';

if (!isTaken) {
const child = fork(require.resolve('../startServer.js'), args, {
silent: true,
});
const child = fork(
require.resolve('../startServer.js'), args, {
silent: true
}
);
child.on('message', (message) => {
child.on('message', message => {
if (message.server) {

@@ -28,0 +30,0 @@ // Wait for the server to start before connecting

@@ -1,16 +0,14 @@

import workerFarm from 'worker-farm';
import { promisify, flatten } from './util';
import JestWorker from 'jest-worker';
export default class LintRunner {
constructor(numThreads, suppressWarnings, fix) {
const workers = workerFarm(
this.worker = new JestWorker(
require.resolve('./LintWorker'),
{
autoStart: true,
maxConcurrentCallsPerWorker: Infinity,
maxConcurrentWorkers: numThreads,
},
require.resolve('./LintWorker')
exposedMethods: ['worker'],
numWorkers: numThreads,
enableWorkerThreads: true,
}
);
this.workers = promisify(workers);
this.suppressWarnings = suppressWarnings;

@@ -24,3 +22,3 @@ this.fix = fix;

files.map((file) => {
return that.workers({
return that.worker.worker({
fileArg: file,

@@ -33,3 +31,3 @@ suppressWarnings: that.suppressWarnings,

.then(results => {
const records = flatten(results);
const records = (results || []).flat();

@@ -36,0 +34,0 @@ // produce a sum of total num of errors/warnings

@@ -13,9 +13,11 @@ import { CLIEngine } from 'eslint';

module.exports = (options, callback) => {
const results = lintFile(options.fileArg, options.fix);
if (options.suppressWarnings) {
callback(null, CLIEngine.getErrorResults(results));
} else {
callback(null, results);
}
};
export async function worker({
fileArg,
fix,
suppressWarnings
}) {
return new Promise((resolve) => {
const results = lintFile(fileArg, fix);
resolve(suppressWarnings ? CLIEngine.getErrorResults(results) : results);
});
}

@@ -1,5 +0,5 @@

import dnode from 'dnode-weak-napi';
import chokidar from 'chokidar';
import glob from 'glob';
import jayson from 'jayson';
import path from 'path';
import sane from 'sane';
import glob from 'glob';
import LintRunner from './LintRunner';

@@ -35,8 +35,10 @@ import { CLIEngine } from 'eslint';

const server = dnode({
status: (param, cb) => {
if (this.filesToProcess === 0) {
return cb(this.getResultsFromCache());
const that = this;
const server = jayson.server({
status: function(args, cb) {
if (that.filesToProcess === 0) {
cb(null, that.getResultsFromCache());
} else {
return cb({message: `Linting...${this.filesToProcess} left to lint`});
cb(null, {message: `Linting...${that.filesToProcess} left to lint`});
}

@@ -48,11 +50,11 @@ }

server.listen(this.port);
server.http().listen(this.port);
}
_setupWatcher(root, paths, ignored) {
const watcher = sane(root, {
glob: paths,
const watcher = chokidar.watch(paths, {
disableGlobbing: true,
ignored: ignored,
dot: true,
watchman: process.env.NODE_ENV !== 'test',
ignoreInitial: true,
ignorePermissionErrors: true,
});

@@ -59,0 +61,0 @@

@@ -5,28 +5,2 @@ import net from 'net';

export const promisify = (fn) => {
return function() {
var args = Array.prototype.slice.call(arguments);
return new Promise(function(resolve, reject) {
args.push(function(err, res) {
if (err) {
reject(err);
} else {
resolve(res);
}
});
fn.apply(this, args);
});
};
};
export const flatten = (array) => {
return array.reduce(
function(acc, curr) {
return curr.concat(acc);
},
[]
);
};
export const isPortTaken = (port) => {

@@ -33,0 +7,0 @@ return new Promise((resolve, reject) => {

@@ -21,2 +21,2 @@ const execSync = require('child_process').execSync;

module.exports = runEsprint;
module.exports = runEsprint;

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