mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 23:46:14 -04:00
lint rest pluginfw
This commit is contained in:
parent
698a76a1c8
commit
b18a0e48da
2 changed files with 41 additions and 35 deletions
|
@ -24,7 +24,7 @@ let tasks = 0;
|
||||||
function wrapTaskCb(cb) {
|
function wrapTaskCb(cb) {
|
||||||
tasks++;
|
tasks++;
|
||||||
|
|
||||||
return function () {
|
return function (...arguments) {
|
||||||
cb && cb.apply(this, arguments);
|
cb && cb.apply(this, arguments);
|
||||||
tasks--;
|
tasks--;
|
||||||
if (tasks === 0) onAllTasksFinished();
|
if (tasks === 0) onAllTasksFinished();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
'use strict'
|
||||||
// A copy of npm/lib/utils/read-installed.js
|
// A copy of npm/lib/utils/read-installed.js
|
||||||
// that is hacked to not cache everything :)
|
// that is hacked to not cache everything :)
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ const asyncMap = require('slide').asyncMap;
|
||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
const log = require('log4js').getLogger('pluginfw');
|
const log = require('log4js').getLogger('pluginfw');
|
||||||
|
|
||||||
function readJson(file, callback) {
|
const readJson = (file, callback) => {
|
||||||
fs.readFile(file, (er, buf) => {
|
fs.readFile(file, (er, buf) => {
|
||||||
if (er) {
|
if (er) {
|
||||||
callback(er);
|
callback(er);
|
||||||
|
@ -108,17 +109,13 @@ function readJson(file, callback) {
|
||||||
callback(er);
|
callback(er);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
module.exports = readInstalled;
|
const readInstalled = (folder, cb) => {
|
||||||
|
|
||||||
function readInstalled(folder, cb) {
|
|
||||||
/* This is where we clear the cache, these three lines are all the
|
/* This is where we clear the cache, these three lines are all the
|
||||||
* new code there is */
|
* new code there is */
|
||||||
rpSeen = {};
|
rpSeen = {};
|
||||||
riSeen = [];
|
riSeen = [];
|
||||||
const fuSeen = [];
|
|
||||||
|
|
||||||
const d = npm.config.get('depth');
|
const d = npm.config.get('depth');
|
||||||
readInstalled_(folder, null, null, null, 0, d, (er, obj) => {
|
readInstalled_(folder, null, null, null, 0, d, (er, obj) => {
|
||||||
if (er) return cb(er);
|
if (er) return cb(er);
|
||||||
|
@ -127,10 +124,12 @@ function readInstalled(folder, cb) {
|
||||||
resolveInheritance(obj);
|
resolveInheritance(obj);
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
var rpSeen = {};
|
module.exports = readInstalled;
|
||||||
function readInstalled_(folder, parent, name, reqver, depth, maxDepth, cb) {
|
|
||||||
|
let rpSeen = {};
|
||||||
|
const readInstalled_ = (folder, parent, name, reqver, depth, maxDepth, cb) => {
|
||||||
// console.error(folder, name)
|
// console.error(folder, name)
|
||||||
|
|
||||||
let installed,
|
let installed,
|
||||||
|
@ -170,7 +169,7 @@ function readInstalled_(folder, parent, name, reqver, depth, maxDepth, cb) {
|
||||||
|
|
||||||
let errState = null;
|
let errState = null;
|
||||||
let called = false;
|
let called = false;
|
||||||
function next(er) {
|
const next = (er) => {
|
||||||
if (errState) return;
|
if (errState) return;
|
||||||
if (er) {
|
if (er) {
|
||||||
errState = er;
|
errState = er;
|
||||||
|
@ -230,12 +229,12 @@ function readInstalled_(folder, parent, name, reqver, depth, maxDepth, cb) {
|
||||||
}
|
}
|
||||||
return cb(null, obj);
|
return cb(null, obj);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
// starting from a root object, call findUnmet on each layer of children
|
// starting from a root object, call findUnmet on each layer of children
|
||||||
var riSeen = [];
|
let riSeen = [];
|
||||||
function resolveInheritance(obj) {
|
const resolveInheritance = (obj) => {
|
||||||
if (typeof obj !== 'object') return;
|
if (typeof obj !== 'object') return;
|
||||||
if (riSeen.indexOf(obj) !== -1) return;
|
if (riSeen.indexOf(obj) !== -1) return;
|
||||||
riSeen.push(obj);
|
riSeen.push(obj);
|
||||||
|
@ -248,12 +247,13 @@ function resolveInheritance(obj) {
|
||||||
Object.keys(obj.dependencies).forEach((dep) => {
|
Object.keys(obj.dependencies).forEach((dep) => {
|
||||||
resolveInheritance(obj.dependencies[dep]);
|
resolveInheritance(obj.dependencies[dep]);
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// find unmet deps by walking up the tree object.
|
// find unmet deps by walking up the tree object.
|
||||||
// No I/O
|
// No I/O
|
||||||
const fuSeen = [];
|
const fuSeen = [];
|
||||||
function findUnmet(obj) {
|
const findUnmet = obj => {
|
||||||
|
if (typeof obj === 'string') return;
|
||||||
if (fuSeen.indexOf(obj) !== -1) return;
|
if (fuSeen.indexOf(obj) !== -1) return;
|
||||||
fuSeen.push(obj);
|
fuSeen.push(obj);
|
||||||
// console.error("find unmet", obj.name, obj.parent && obj.parent.name)
|
// console.error("find unmet", obj.name, obj.parent && obj.parent.name)
|
||||||
|
@ -287,16 +287,20 @@ function findUnmet(obj) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
}
|
};
|
||||||
|
|
||||||
function copy(obj) {
|
const copy = (obj) => {
|
||||||
if (!obj || typeof obj !== 'object') return obj;
|
if (!obj || typeof obj !== 'object') return obj;
|
||||||
if (Array.isArray(obj)) return obj.map(copy);
|
if (Array.isArray(obj)) return obj.map(copy);
|
||||||
|
|
||||||
const o = {};
|
const o = {};
|
||||||
for (const i in obj) o[i] = copy(obj[i]);
|
for (const i in obj) {
|
||||||
|
if (Object.prototype.hasOwnProperty.call(obj, i)){
|
||||||
|
o[i] = copy(obj[i]);
|
||||||
|
}
|
||||||
|
};
|
||||||
return o;
|
return o;
|
||||||
}
|
};
|
||||||
|
|
||||||
if (module === require.main) {
|
if (module === require.main) {
|
||||||
const util = require('util');
|
const util = require('util');
|
||||||
|
@ -311,29 +315,31 @@ if (module === require.main) {
|
||||||
});
|
});
|
||||||
|
|
||||||
const seen = [];
|
const seen = [];
|
||||||
function cleanup(map) {
|
const cleanup = (map) => {
|
||||||
if (seen.indexOf(map) !== -1) return;
|
if (seen.indexOf(map) !== -1) return;
|
||||||
seen.push(map);
|
seen.push(map);
|
||||||
for (var i in map) {
|
for (const i in map) {
|
||||||
switch (i) {
|
if (Object.prototype.hasOwnProperty.call(map, i)){
|
||||||
case '_id':
|
switch (i) {
|
||||||
case 'path':
|
case '_id':
|
||||||
case 'extraneous': case 'invalid':
|
case 'path':
|
||||||
case 'dependencies': case 'name':
|
case 'extraneous': case 'invalid':
|
||||||
continue;
|
case 'dependencies': case 'name':
|
||||||
default: delete map[i];
|
continue;
|
||||||
|
default: delete map[i];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const dep = map.dependencies;
|
const dep = map.dependencies;
|
||||||
// delete map.dependencies
|
// delete map.dependencies
|
||||||
if (dep) {
|
if (dep) {
|
||||||
// map.dependencies = dep
|
// map.dependencies = dep
|
||||||
for (var i in dep) {
|
for (const j in dep) {
|
||||||
if (typeof dep[i] === 'object') {
|
if (typeof dep[j] === 'object') {
|
||||||
cleanup(dep[i]);
|
cleanup(dep[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue