@boll/cli
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -40,6 +40,4 @@ "use strict"; | ||
var cli_1 = require("../cli"); | ||
var suite_1 = require("../lib/suite"); | ||
var logger_1 = require("../lib/logger"); | ||
var suite = new suite_1.Suite(); | ||
var cli = new cli_1.Cli(logger_1.DefaultLogger, suite); | ||
var cli = new cli_1.Cli(logger_1.DefaultLogger); | ||
function doStuff() { | ||
@@ -46,0 +44,0 @@ return __awaiter(this, void 0, void 0, function () { |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -40,4 +59,12 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
exports.Cli = exports.Status = void 0; | ||
var fs = __importStar(require("fs")); | ||
var bootstrap_1 = require("./config/bootstrap"); | ||
var config_1 = require("./lib/config"); | ||
var config_generator_1 = require("./config-generator"); | ||
var config_registry_1 = require("./lib/config-registry"); | ||
var rule_registry_1 = require("./lib/rule-registry"); | ||
var argparse_1 = require("argparse"); | ||
var config_generator_1 = require("./config-generator"); | ||
var util_1 = require("util"); | ||
var path_1 = require("path"); | ||
var fileExistsAsync = util_1.promisify(fs.exists); | ||
var parser = new argparse_1.ArgumentParser({ description: "@boll/cli" }); | ||
@@ -56,9 +83,9 @@ var subParser = parser.addSubparsers({ | ||
var Cli = /** @class */ (function () { | ||
function Cli(logger, suite) { | ||
function Cli(logger) { | ||
this.logger = logger; | ||
this.suite = suite; | ||
this.configFileName = ".boll.config.js"; | ||
} | ||
Cli.prototype.run = function (args) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var parsedCommand, result; | ||
var parsedCommand, suite, result; | ||
var _this = this; | ||
@@ -69,5 +96,8 @@ return __generator(this, function (_a) { | ||
parsedCommand = parser.parseArgs(args); | ||
if (!(parsedCommand.command === "run")) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.suite.run(this.logger)]; | ||
if (!(parsedCommand.command === "run")) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.buildSuite()]; | ||
case 1: | ||
suite = _a.sent(); | ||
return [4 /*yield*/, suite.run(this.logger)]; | ||
case 2: | ||
result = _a.sent(); | ||
@@ -81,9 +111,9 @@ result.errors.forEach(function (e) { | ||
return [2 /*return*/, Status.Ok]; | ||
case 2: | ||
if (!(parsedCommand.command === "init")) return [3 /*break*/, 4]; | ||
case 3: | ||
if (!(parsedCommand.command === "init")) return [3 /*break*/, 5]; | ||
return [4 /*yield*/, config_generator_1.ConfigGenerator.run()]; | ||
case 3: | ||
case 4: | ||
_a.sent(); | ||
return [2 /*return*/, Status.Ok]; | ||
case 4: return [2 /*return*/, Status.Error]; | ||
case 5: return [2 /*return*/, Status.Error]; | ||
} | ||
@@ -93,4 +123,25 @@ }); | ||
}; | ||
Cli.prototype.buildSuite = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var fullConfigPath, exists, config; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
fullConfigPath = path_1.resolve(this.configFileName); | ||
return [4 /*yield*/, fileExistsAsync(fullConfigPath)]; | ||
case 1: | ||
exists = _a.sent(); | ||
if (!exists) { | ||
this.logger.error("Unable to find " + fullConfigPath + "; consider running \"init\" to create example config."); | ||
} | ||
bootstrap_1.bootstrapConfigurations(); | ||
config = new config_1.Config(config_registry_1.ConfigRegistryInstance, rule_registry_1.RuleRegistryInstance); | ||
config.load(require(fullConfigPath)); | ||
return [2 /*return*/, config.buildSuite()]; | ||
} | ||
}); | ||
}); | ||
}; | ||
return Cli; | ||
}()); | ||
exports.Cli = Cli; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FileContext = void 0; | ||
exports.getSourceFile = exports.FileContext = void 0; | ||
var fs_1 = __importDefault(require("fs")); | ||
var path_1 = __importDefault(require("path")); | ||
var typescript_1 = __importDefault(require("typescript")); | ||
var util_1 = require("util"); | ||
var boll_file_1 = require("./boll-file"); | ||
var readFileAsync = util_1.promisify(fs_1.default.readFile); | ||
var FileContext = /** @class */ (function () { | ||
function FileContext(packageContext, filename, source) { | ||
function FileContext(packageRoot, packageContext, filename, source) { | ||
this.packageRoot = packageRoot; | ||
this.packageContext = packageContext; | ||
@@ -20,1 +66,18 @@ this.filename = filename; | ||
exports.FileContext = FileContext; | ||
function getSourceFile(projectRoot, filename, packageContext) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var normalizedFile, content, source; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
normalizedFile = path_1.default.normalize(filename).replace(/\\/g, "/"); | ||
return [4 /*yield*/, readFileAsync(normalizedFile)]; | ||
case 1: | ||
content = _a.sent(); | ||
source = typescript_1.default.createSourceFile(normalizedFile, content.toString("utf8"), typescript_1.default.ScriptTarget.ES5, true); | ||
return [2 /*return*/, new FileContext(projectRoot, packageContext, boll_file_1.asBollFile(filename), source)]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.getSourceFile = getSourceFile; |
@@ -43,33 +43,27 @@ "use strict"; | ||
exports.Suite = void 0; | ||
var fs_1 = __importDefault(require("fs")); | ||
var glob_1 = __importDefault(require("glob")); | ||
var path_1 = __importDefault(require("path")); | ||
var package_1 = require("./package"); | ||
var result_set_1 = require("./result-set"); | ||
var cross_package_dependency_detector_1 = require("../rules/cross-package-dependency-detector"); | ||
var src_detector_1 = require("../rules/src-detector"); | ||
var typescript_1 = __importDefault(require("typescript")); | ||
var fs_1 = __importDefault(require("fs")); | ||
var path_1 = __importDefault(require("path")); | ||
var glob_1 = __importDefault(require("glob")); | ||
var transitive_dependency_detector_1 = require("../rules/transitive-dependency-detector"); | ||
var util_1 = require("util"); | ||
var transitive_dep_detector_1 = require("../rules/transitive-dep-detector"); | ||
var package_1 = require("./package"); | ||
var boll_directory_1 = require("./boll-directory"); | ||
var file_context_1 = require("./file-context"); | ||
var redundant_imports_detector_1 = require("../rules/redundant-imports-detector"); | ||
var node_modules_reference_detector_1 = require("../rules/node-modules-reference-detector"); | ||
var readFileAsync = util_1.promisify(fs_1.default.readFile); | ||
var globAsync = util_1.promisify(glob_1.default); | ||
function getSourceFile(filename, packageContext) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var normalizedFile, content, source; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
normalizedFile = path_1.default.normalize(filename).replace(/\\/g, "/"); | ||
return [4 /*yield*/, readFileAsync(normalizedFile)]; | ||
case 1: | ||
content = _a.sent(); | ||
source = typescript_1.default.createSourceFile(normalizedFile, content.toString("utf8"), typescript_1.default.ScriptTarget.ES5, true); | ||
return [2 /*return*/, new file_context_1.FileContext(packageContext, filename, source)]; | ||
} | ||
}); | ||
}); | ||
} | ||
var Suite = /** @class */ (function () { | ||
function Suite() { | ||
this._hasRun = false; | ||
this.checks = [ | ||
new src_detector_1.SrcDetector(), | ||
new transitive_dependency_detector_1.TransitiveDependencyDetector(), | ||
new cross_package_dependency_detector_1.CrossPackageDependencyDetector(), | ||
new redundant_imports_detector_1.RedundantImportsDetector(), | ||
new node_modules_reference_detector_1.NodeModulesReferenceDetector(), | ||
]; | ||
} | ||
@@ -85,3 +79,3 @@ Object.defineProperty(Suite.prototype, "hasRun", { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var resultSet, rules, packageContext, sourceFilePaths, sourceFiles; | ||
var resultSet, packageContext, sourceFilePaths, projectRoot, sourceFiles; | ||
return __generator(this, function (_a) { | ||
@@ -92,3 +86,2 @@ switch (_a.label) { | ||
resultSet = new result_set_1.ResultSet(); | ||
rules = [new src_detector_1.SrcDetector(), new transitive_dep_detector_1.TransitiveDependencyDetector()]; | ||
return [4 /*yield*/, this.loadPackage(logger)]; | ||
@@ -100,6 +93,7 @@ case 1: | ||
sourceFilePaths = _a.sent(); | ||
return [4 /*yield*/, Promise.all(sourceFilePaths.map(function (filename) { return getSourceFile(filename, packageContext); }))]; | ||
projectRoot = boll_directory_1.asBollDirectory(process.cwd()); | ||
return [4 /*yield*/, Promise.all(sourceFilePaths.map(function (filename) { return file_context_1.getSourceFile(projectRoot, filename, packageContext); }))]; | ||
case 3: | ||
sourceFiles = _a.sent(); | ||
rules.forEach(function (r) { | ||
this.checks.forEach(function (r) { | ||
sourceFiles.forEach(function (s) { | ||
@@ -106,0 +100,0 @@ var results = r.check(s); |
@@ -40,4 +40,8 @@ "use strict"; | ||
var src_detector_test_1 = require("./src-detector.test"); | ||
var cross_package_dep_detector_test_1 = require("./cross-package-dep-detector.test"); | ||
var redundant_imports_detector_test_1 = require("./redundant-imports-detector.test"); | ||
var node_modules_reference_detector_test_1 = require("./node-modules-reference-detector.test"); | ||
var cli_test_1 = require("./cli.test"); | ||
var e2e_test_1 = require("./e2e.test"); | ||
var config_test_1 = require("./config.test"); | ||
function suite() { | ||
@@ -50,8 +54,20 @@ return __awaiter(this, void 0, void 0, function () { | ||
_a.sent(); | ||
return [4 /*yield*/, cli_test_1.test.run()]; | ||
return [4 /*yield*/, cross_package_dep_detector_test_1.test.run()]; | ||
case 2: | ||
_a.sent(); | ||
return [4 /*yield*/, e2e_test_1.test.run()]; | ||
return [4 /*yield*/, redundant_imports_detector_test_1.test.run()]; | ||
case 3: | ||
_a.sent(); | ||
return [4 /*yield*/, node_modules_reference_detector_test_1.test.run()]; | ||
case 4: | ||
_a.sent(); | ||
return [4 /*yield*/, cli_test_1.test.run()]; | ||
case 5: | ||
_a.sent(); | ||
return [4 /*yield*/, e2e_test_1.test.run()]; | ||
case 6: | ||
_a.sent(); | ||
return [4 /*yield*/, config_test_1.test.run()]; | ||
case 7: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
@@ -58,0 +74,0 @@ } |
@@ -62,28 +62,11 @@ "use strict"; | ||
exports.test = void 0; | ||
var assert = __importStar(require("assert")); | ||
var baretest_1 = __importDefault(require("baretest")); | ||
var assert = __importStar(require("assert")); | ||
var test_helper_1 = require("./test-helper"); | ||
var cli_1 = require("../cli"); | ||
var suite_1 = require("../lib/suite"); | ||
var logger_1 = require("../lib/logger"); | ||
var fs_1 = require("fs"); | ||
var util_1 = require("util"); | ||
var fs_1 = require("fs"); | ||
var test_helper_1 = require("./test-helper"); | ||
var existsAsync = util_1.promisify(fs_1.exists); | ||
exports.test = baretest_1.default("CLI"); | ||
var suite = new suite_1.Suite(); | ||
exports.test("should run lint suite when invoked with `run`", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var lintSuite, sut; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
lintSuite = new suite_1.Suite(); | ||
sut = new cli_1.Cli(logger_1.NullLogger, lintSuite); | ||
return [4 /*yield*/, sut.run(["run"])]; | ||
case 1: | ||
_a.sent(); | ||
assert.equal(true, lintSuite.hasRun); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
exports.test("should create example config file when invoked with `init`", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -100,3 +83,3 @@ return __generator(this, function (_a) { | ||
assert.equal(false, configExistsPrecondition); | ||
sut = new cli_1.Cli(logger_1.NullLogger, suite); | ||
sut = new cli_1.Cli(logger_1.NullLogger); | ||
return [4 /*yield*/, sut.run(["init"])]; | ||
@@ -103,0 +86,0 @@ case 2: |
@@ -62,7 +62,7 @@ "use strict"; | ||
exports.test = void 0; | ||
var assert = __importStar(require("assert")); | ||
var baretest_1 = __importDefault(require("baretest")); | ||
var assert = __importStar(require("assert")); | ||
var test_helper_1 = require("./test-helper"); | ||
var logger_1 = require("../lib/logger"); | ||
var suite_1 = require("../lib/suite"); | ||
var logger_1 = require("../lib/logger"); | ||
var test_helper_1 = require("./test-helper"); | ||
exports.test = baretest_1.default("e2e"); | ||
@@ -112,2 +112,65 @@ var suite = new suite_1.Suite(); | ||
}); }); | ||
exports.test("should catch an error in project-c", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, test_helper_1.inFixtureDir("project-c", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, suite.run(logger_1.NullLogger)]; | ||
case 1: | ||
result = _a.sent(); | ||
assert.equal(1, result.errors.length); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
exports.test("should catch an error in project-d", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, test_helper_1.inFixtureDir("project-d", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, suite.run(logger_1.NullLogger)]; | ||
case 1: | ||
result = _a.sent(); | ||
assert.equal(1, result.errors.length); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
exports.test("should catch an error in project-e", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, test_helper_1.inFixtureDir("project-e", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var result; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, suite.run(logger_1.NullLogger)]; | ||
case 1: | ||
result = _a.sent(); | ||
assert.equal(2, result.errors.length); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); })]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
exports.test("should find no issues with clean-project", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
@@ -114,0 +177,0 @@ return __generator(this, function (_a) { |
@@ -62,6 +62,6 @@ "use strict"; | ||
exports.test = void 0; | ||
var assert = __importStar(require("assert")); | ||
var baretest_1 = __importDefault(require("baretest")); | ||
var assert = __importStar(require("assert")); | ||
var result_set_1 = require("../lib/result-set"); | ||
var src_detector_1 = require("../rules/src-detector"); | ||
var result_set_1 = require("../lib/result-set"); | ||
exports.test = baretest_1.default("Source detector"); | ||
@@ -68,0 +68,0 @@ exports.test("Should pass if no `src` detected in imports", function () { return __awaiter(void 0, void 0, void 0, function () { |
@@ -43,6 +43,6 @@ "use strict"; | ||
exports.inFixtureDir = exports.inTmpDir = void 0; | ||
var util_1 = require("util"); | ||
var os_1 = __importDefault(require("os")); | ||
var path_1 = __importDefault(require("path")); | ||
var fs_1 = require("fs"); | ||
var util_1 = require("util"); | ||
var mkdtempAsync = util_1.promisify(fs_1.mkdtemp); | ||
@@ -49,0 +49,0 @@ exports.inTmpDir = function (cb) { return __awaiter(void 0, void 0, void 0, function () { |
@@ -27,3 +27,3 @@ { | ||
], | ||
"gitHead": "ed01fc1c6c7bf7cf7c2a47d935c897760e0ab8f5", | ||
"gitHead": "684bc8b2aa4b06d5e24fe0badd6b9b0f7bd751f0", | ||
"homepage": "https://github.com/jdhuntington/boll#readme", | ||
@@ -40,3 +40,7 @@ "license": "unlicensed", | ||
}, | ||
"version": "0.0.6" | ||
"scripts": { | ||
"build": "tsc -p .", | ||
"test": "node dist/tests/all.test.js" | ||
}, | ||
"version": "0.0.7" | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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 License Found
License(Experimental) License information could not be found.
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
98210
36
1943
1
7
1