Skip to content

Commit

Permalink
Replace 'var' with 'let'/'const'
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobq committed Jul 15, 2018
1 parent 7f22624 commit 9947062
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 182 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

var Reporter = require('./lib/reporter');
var DependencyChecker = require('./lib/dependency-checker');
const Reporter = require('./lib/reporter');
const DependencyChecker = require('./lib/dependency-checker');

module.exports = {
name: 'ember-cli-dependency-checker',
init: function() {
this._super.init && this._super.init.apply(this, arguments);
var reporter = new Reporter();
var dependencyChecker = new DependencyChecker(this.project, reporter);

const reporter = new Reporter();
const dependencyChecker = new DependencyChecker(this.project, reporter);
dependencyChecker.checkDependencies();
}
};
78 changes: 39 additions & 39 deletions lib/dependency-checker.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
'use strict';

var path = require('path');
var resolve = require('resolve');
var fs = require('fs');
var findYarnWorkspaceRoot = require('find-yarn-workspace-root');
var readFile = fs.readFileSync;
var readDir = fs.readdirSync;
var fileExists = fs.existsSync;
var Package = require('./package');
var buildBowerPackagePath = require('./utils/build-bower-package-path');
var isTarGz = require('./utils/is-tar-gz');
var unknownVersion = require('./utils/unknown-version');

var alreadyChecked = false;
const path = require('path');
const resolve = require('resolve');
const fs = require('fs');
const findYarnWorkspaceRoot = require('find-yarn-workspace-root');
const readFile = fs.readFileSync;
const readDir = fs.readdirSync;
const fileExists = fs.existsSync;
const Package = require('./package');
const buildBowerPackagePath = require('./utils/build-bower-package-path');
const isTarGz = require('./utils/is-tar-gz');
const unknownVersion = require('./utils/unknown-version');

let alreadyChecked = false;

function isUnsatisfied(pkg) {
return !!pkg.needsUpdate;
Expand Down Expand Up @@ -40,18 +40,18 @@ EmberCLIDependencyChecker.prototype.checkDependencies = function() {
return;
}

var bowerDeps = this.readBowerDependencies();
const bowerDeps = this.readBowerDependencies();
this.reporter.unsatisifedPackages('bower', bowerDeps.filter(isUnsatisfied));

var npmDeps = this.readNPMDependencies();
var filteredDeps = npmDeps.filter(isUnsatisfied);
var unsatisfiedDeps = filteredDeps.filter(isNotSymlinked);
var symlinkedDeps = filteredDeps.filter(isSymlinked);
const npmDeps = this.readNPMDependencies();
const filteredDeps = npmDeps.filter(isUnsatisfied);
const unsatisfiedDeps = filteredDeps.filter(isNotSymlinked);
const symlinkedDeps = filteredDeps.filter(isSymlinked);

var yarnPath = path.join(this.project.root, 'yarn.lock');
var yarnWorkspacePath = findYarnWorkspaceRoot(this.project.root);
const yarnPath = path.join(this.project.root, 'yarn.lock');
const yarnWorkspacePath = findYarnWorkspaceRoot(this.project.root);

var packageManagerName = 'npm';
let packageManagerName = 'npm';
if (fileExists(yarnPath) || yarnWorkspacePath) {
packageManagerName = 'yarn';
}
Expand All @@ -60,7 +60,7 @@ EmberCLIDependencyChecker.prototype.checkDependencies = function() {
this.reporter.unsatisifedPackages(packageManagerName, unsatisfiedDeps);

if (unsatisfiedDeps.length === 0) {
var shrinkWrapDeps = this.readShrinkwrapDeps();
const shrinkWrapDeps = this.readShrinkwrapDeps();
this.reporter.unsatisifedPackages('npm-shrinkwrap', shrinkWrapDeps.filter(isUnsatisfied));
}

Expand All @@ -70,11 +70,11 @@ EmberCLIDependencyChecker.prototype.checkDependencies = function() {
};

EmberCLIDependencyChecker.prototype.readShrinkwrapDeps = function() {
var filePath = path.join(this.project.root, 'npm-shrinkwrap.json');
const filePath = path.join(this.project.root, 'npm-shrinkwrap.json');
if (fileExists(filePath)) {
var ShrinkWrapChecker = require('./shrinkwrap-checker');
var shrinkWrapBody = readFile(filePath);
var shrinkWrapJSON = {};
const ShrinkWrapChecker = require('./shrinkwrap-checker');
const shrinkWrapBody = readFile(filePath);
let shrinkWrapJSON = {};
try {
shrinkWrapJSON = JSON.parse(shrinkWrapBody);
} catch(e) {
Expand All @@ -88,22 +88,22 @@ EmberCLIDependencyChecker.prototype.readShrinkwrapDeps = function() {

EmberCLIDependencyChecker.prototype.lookupNodeModule = function(name, versionSpecified) {
try {
var nodePackage = resolve.sync(path.join(name, 'package.json'), { basedir: this.project.root });
var version = this.lookupPackageVersion(nodePackage, versionSpecified);
const nodePackage = resolve.sync(path.join(name, 'package.json'), { basedir: this.project.root });
const version = this.lookupPackageVersion(nodePackage, versionSpecified);
return { version: version, path: path.dirname(nodePackage) };
} catch(err) {
return { version: null, path: null };
}
};

EmberCLIDependencyChecker.prototype.lookupBowerPackageVersion = function(name) {
var packageDirectory = path.resolve(this.project.root, this.project.bowerDirectory, name);
var version = null;
const packageDirectory = path.resolve(this.project.root, this.project.bowerDirectory, name);
let version = null;
if (fileExists(packageDirectory) && readDir(packageDirectory).length > 0) {
var dotBowerFile = path.join(packageDirectory, '.bower.json');
const dotBowerFile = path.join(packageDirectory, '.bower.json');
version = this.lookupPackageVersion(dotBowerFile);
if (!version) {
var bowerFile = path.join(packageDirectory, 'bower.json');
const bowerFile = path.join(packageDirectory, 'bower.json');
version = this.lookupPackageVersion(bowerFile) || '*';
}
}
Expand All @@ -112,10 +112,10 @@ EmberCLIDependencyChecker.prototype.lookupBowerPackageVersion = function(name) {

EmberCLIDependencyChecker.prototype.lookupPackageVersion = function(path, versionSpecified) {
if (fileExists(path)) {
var pkg = readFile(path);
var version = null;
const pkg = readFile(path);
let version = null;
try {
var pkgContent = JSON.parse(pkg);
const pkgContent = JSON.parse(pkg);
version = pkgContent.version || null;
if (isTarGz(versionSpecified)) {
version = pkgContent._from || unknownVersion;
Expand All @@ -139,16 +139,16 @@ EmberCLIDependencyChecker.prototype.readNPMDependencies = function() {

EmberCLIDependencyChecker.prototype.readDependencies = function(dependencies, type) {
return Object.keys(dependencies).map(function(name) {
var versionSpecified = dependencies[name];
const versionSpecified = dependencies[name];
if (type === 'npm') {
var result = this.lookupNodeModule(name, versionSpecified);
const result = this.lookupNodeModule(name, versionSpecified);
return new Package(name, versionSpecified, result.version, result.path);
} else {
var versionInstalled = this.lookupBowerPackageVersion(name);
let versionInstalled = this.lookupBowerPackageVersion(name);
if (isTarGz(versionSpecified)) {
versionInstalled = unknownVersion;
}
var path = buildBowerPackagePath(this.project, name);
const path = buildBowerPackagePath(this.project, name);
return new Package(name, versionSpecified, versionInstalled, path);
}
}, this);
Expand Down
8 changes: 4 additions & 4 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ Package.prototype.init = function(name, versionSpecified, versionInstalled, path
this.path = path;
this.versionSpecified = versionSpecified;
this.versionInstalled = versionInstalled;

try {
this.needsUpdate = this.updateRequired();
this.isSymlinked = this.symlinked();
} catch(e) {
var versionText = '(version specified: ' + versionSpecified + ', version installed: ' + versionInstalled + '): ';
const versionText = '(version specified: ' + versionSpecified + ', version installed: ' + versionInstalled + '): ';
e.message = 'Failed processing module "' + name + '" ' + versionText + e.message;
throw e;
}
};

Package.prototype.updateRequired = function() {
var VersionChecker = require('./version-checker');
const VersionChecker = require('./version-checker');
return !VersionChecker.satisfies(this.versionSpecified, this.versionInstalled);
};

Package.prototype.symlinked = function() {
var isSymlink = require('./utils/is-symlink');
const isSymlink = require('./utils/is-symlink');
return isSymlink(this.path);
};

Expand Down
16 changes: 8 additions & 8 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ function installCommand(type) {
}
}

var Reporter = function() {
const Reporter = function() {
this.messages = [];
};

Reporter.prototype.unsatisifedPackages = function(type, packages) {
this.chalk = this.chalk || require('chalk');
this.EOL = this.EOL || require('os').EOL;

var chalk = this.chalk;
var EOL = this.EOL;
const chalk = this.chalk;
const EOL = this.EOL;

if (packages.length > 0) {
var message = '';
let message = '';
message += EOL + chalk.red('Missing ' + type + ' packages: ') + EOL;

packages.forEach(function(pkg) {
Expand All @@ -46,11 +46,11 @@ Reporter.prototype.reportUnsatisfiedSymlinkedPackages = function(type, packages)
this.chalk = this.chalk || require('chalk');
this.EOL = this.EOL || require('os').EOL;

var chalk = this.chalk;
var EOL = this.EOL;
const chalk = this.chalk;
const EOL = this.EOL;

if (packages.length > 0) {
var message = '';
let message = '';
message += EOL + chalk.yellow('Missing symlinked ' + type + ' packages: ') + EOL;
packages.forEach(function(pkg) {
message += chalk.reset('Package: ') + chalk.cyan(pkg.name) + EOL;
Expand All @@ -63,7 +63,7 @@ Reporter.prototype.reportUnsatisfiedSymlinkedPackages = function(type, packages)

Reporter.prototype.report = function() {
if (this.messages.length) {
var DependencyError = require('./dependency-error');
const DependencyError = require('./dependency-error');
throw new DependencyError(this.messages.join(''));
}
};
Expand Down
29 changes: 13 additions & 16 deletions lib/shrinkwrap-checker.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

var readPackageJSON = require('./utils/read-package-json');
var ShrinkwrapPackage = require('./shrinkwrap-package');
var path = require('path');
var resolve = require('resolve');
const readPackageJSON = require('./utils/read-package-json');
const ShrinkwrapPackage = require('./shrinkwrap-package');
const path = require('path');
const resolve = require('resolve');

var ShrinkwrapChecker = function(root, name, versionSpecified, parents, requiredFrom){
const ShrinkwrapChecker = function(root, name, versionSpecified, parents, requiredFrom){
this.root = root;
this.name = name;
this.versionSpecified = versionSpecified;
Expand All @@ -21,35 +21,32 @@ ShrinkwrapChecker.prototype.check = function() {
// not found
}
}
var packageJSON;
let packageJSON;
if (!this.root) {
packageJSON = {};
} else {
packageJSON = readPackageJSON(this.root) || {};
}

var versionInstalled = packageJSON.version;
var resolvedInstalled = packageJSON['_resolved'];
const versionInstalled = packageJSON.version;
const resolvedInstalled = packageJSON['_resolved'];

return new ShrinkwrapPackage(
this.name, this.versionSpecified, versionInstalled, resolvedInstalled, this.parents);
};


ShrinkwrapChecker.checkDependencies = function(root, shrinkWrapJSON) {
var resolvedDependencies = [];
var currentNode;

var nodesToCheck = [{
const nodesToCheck = [{
root: root,
parents: [],
childDependencies: shrinkWrapJSON.dependencies,
name: shrinkWrapJSON.name,
version: shrinkWrapJSON.version
}];

var checker, resolved;

const resolvedDependencies = [];
let currentNode, checker, resolved;
while ((currentNode = nodesToCheck.pop())) {
checker = new ShrinkwrapChecker(
currentNode.root, currentNode.name, currentNode.version, currentNode.parents, currentNode.requiredFrom);
Expand All @@ -59,9 +56,9 @@ ShrinkwrapChecker.checkDependencies = function(root, shrinkWrapJSON) {

if (!resolved.needsUpdate && currentNode.childDependencies) {
/* jshint loopfunc:true*/
var parents = currentNode.parents.concat(currentNode.name);
const parents = currentNode.parents.concat(currentNode.name);
Object.keys(currentNode.childDependencies).forEach(function(childDepName){
var childDep = currentNode.childDependencies[childDepName];
const childDep = currentNode.childDependencies[childDepName];

nodesToCheck.push({
requiredFrom: checker.root,
Expand Down
2 changes: 1 addition & 1 deletion lib/shrinkwrap-package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var Package = require('./package');
const Package = require('./package');

function ShrinkwrapPackage(name, versionSpecified, versionInstalled, resolvedInstalled, parents) {
this._super$init.call(this, name, versionSpecified, versionInstalled);
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/build-bower-package-path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var path = require('path');
const path = require('path');

module.exports = function buildBowerPackagePath(project, name) {
return path.join(project.bowerDirectory, name);
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/is-symlink.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var fs = require('fs');
const fs = require('fs');

module.exports = function isSymlink(path) {
if (fs.existsSync(path)) {
var stats = fs.lstatSync(path);
const stats = fs.lstatSync(path);
return stats.isSymbolicLink();
} else {
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/read-package-json.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

var path = require('path');
var fs = require('fs');
const path = require('path');
const fs = require('fs');
function readFile(path){
if (fs.existsSync(path)) {
return fs.readFileSync(path);
}
}

module.exports = function readPackageJSON(projectRoot) {
var filePath = path.join(projectRoot, 'package.json');
const filePath = path.join(projectRoot, 'package.json');
try {
return JSON.parse(readFile(filePath));
} catch (e) {
Expand Down
12 changes: 6 additions & 6 deletions lib/version-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ VersionChecker.satisfies = function(versionSpecified, versionInstalled) {
return false;
}

var version = versionSpecified;
var isGitRepo = require('is-git-url');
var semver = require('semver');
var isTarGz = require('./utils/is-tar-gz');
var unknownVersion = require('./utils/unknown-version');
let version = versionSpecified;
const isGitRepo = require('is-git-url');
const semver = require('semver');
const isTarGz = require('./utils/is-tar-gz');
const unknownVersion = require('./utils/unknown-version');

if (version === '*') {
return true;
} else if (isGitRepo(version)) {
var parts = version.split('#');
const parts = version.split('#');
if (parts.length === 2) {
version = semver.valid(parts[1]);
if (!version) {
Expand Down
6 changes: 3 additions & 3 deletions tests/helpers/assert-error.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict';

var assert = require('chai').assert;
var DependencyError = require('../../lib/dependency-error');
const assert = require('chai').assert;
const DependencyError = require('../../lib/dependency-error');

module.exports = function(project, type) {
var checkDependencies = require('./check-dependencies')(project);
const checkDependencies = require('./check-dependencies')(project);
assert.throws(checkDependencies, DependencyError, 'Missing ' + type + ' packages');
};
Loading

0 comments on commit 9947062

Please sign in to comment.