New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tsarch

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsarch - npm Package Compare versions

Comparing version 3.3.2 to 3.4.0

4

dist/src/core/builder/RuleBuilder.d.ts

@@ -9,4 +9,5 @@ import { SubjectFilterStarter } from "../lang/SubjectFilterStarter";

import { FilterAccessor } from "../lang/FilterAccessor";
import { IgnoreConfig } from "../../..";
export declare class RuleBuilder implements SubjectFilterStarter, ObjectFilterStarter, FilterAccessor<ObjectFilterAccessor & SubjectFilterAccessor>, RuleAccessor, Buildable {
static defineThat(): SubjectFilterStarter;
private ignore;
private subjectFilter;

@@ -17,2 +18,3 @@ private objectFilter;

private currentCheckStrategy?;
constructor(ignore: IgnoreConfig);
build(): Checkable;

@@ -19,0 +21,0 @@ files(): SubjectFilterAccessor & ObjectFilterAccessor;

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

var RuleBuilder = /** @class */ (function () {
function RuleBuilder() {
function RuleBuilder(ignore) {
this.ignore = ignore;
this.subjectFilter = new EmptyFilter_1.EmptyFilter();

@@ -21,5 +22,2 @@ this.objectFilter = new EmptyFilter_1.EmptyFilter();

}
RuleBuilder.defineThat = function () {
return new RuleBuilder();
};
RuleBuilder.prototype.build = function () {

@@ -110,3 +108,3 @@ if (this.currentCheckStrategy) {

this.currentlyBuildingFilter = this.objectFilter;
this.currentCheckStrategy = new DependOnStrategy_1.DependOnStrategy();
this.currentCheckStrategy = new DependOnStrategy_1.DependOnStrategy(this.ignore);
return this;

@@ -113,0 +111,0 @@ };

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

var FileFactory_1 = require("../../noun/FileFactory");
var TSArch_1 = require("../../TSArch");
describe("dependency rule", function () {

@@ -68,3 +69,3 @@ var noDependenciesFile = FileFactory_1.FileFactory.buildFromPath(__dirname + "/samples/NoDependencies.ts");

return __generator(this, function (_a) {
rule = new DependOnStrategy_1.DependOnStrategy();
rule = new DependOnStrategy_1.DependOnStrategy(TSArch_1.TSArch.config.ignore);
result = rule.execute(false, [twoDependenciesFile], [dependOnStrategyFile, haveComplexityLowerThanStrategyFile]);

@@ -79,3 +80,3 @@ expect(result.hasRulePassed()).toBe(true);

return __generator(this, function (_a) {
rule = new DependOnStrategy_1.DependOnStrategy();
rule = new DependOnStrategy_1.DependOnStrategy(TSArch_1.TSArch.config.ignore);
result = rule.execute(true, [twoDependenciesFile], [dependOnStrategyFile, haveComplexityLowerThanStrategyFile]);

@@ -90,3 +91,3 @@ expect(result.hasRulePassed()).toBe(false);

return __generator(this, function (_a) {
rule = new DependOnStrategy_1.DependOnStrategy();
rule = new DependOnStrategy_1.DependOnStrategy(TSArch_1.TSArch.config.ignore);
result = rule.execute(false, [twoDependenciesFile], []);

@@ -101,3 +102,3 @@ expect(result.hasRulePassed()).toBe(false);

return __generator(this, function (_a) {
rule = new DependOnStrategy_1.DependOnStrategy();
rule = new DependOnStrategy_1.DependOnStrategy(TSArch_1.TSArch.config.ignore);
result = rule.execute(true, [twoDependenciesFile], []);

@@ -104,0 +105,0 @@ expect(result.hasRulePassed()).toBe(true);

@@ -6,3 +6,6 @@ import { ImportDeclaration } from "typescript";

import { Result } from "../../Result";
import { IgnoreConfig } from "../../TSArch";
export declare class DependOnStrategy implements CheckStrategy {
private ignore;
constructor(ignore: IgnoreConfig);
execute(isNegated: boolean, subjects: Noun[], objects: Noun[]): Result;

@@ -13,5 +16,5 @@ private buildHasNoDependenciesResult;

private buildHasDependencyString;
static getDependenciesOfSubject(subject: File, objects: File[]): File[];
static getImportDeclarationForObject(object: File, subject: File): ImportDeclaration | null;
static getDependenciesOfSubject(subject: File, objects: File[], ignoreJs?: boolean): File[];
static getImportDeclarationForObject(object: File, subject: File, ignoreJs?: boolean): ImportDeclaration | null;
static getImportDeclarations(subject: File): ImportDeclaration[];
}

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

var DependOnStrategy = /** @class */ (function () {
function DependOnStrategy() {
function DependOnStrategy(ignore) {
this.ignore = ignore;
}

@@ -17,3 +18,3 @@ DependOnStrategy.prototype.execute = function (isNegated, subjects, objects) {

fileSubjects.forEach(function (s) {
var dependencies = DependOnStrategy.getDependenciesOfSubject(s, fileObjects);
var dependencies = DependOnStrategy.getDependenciesOfSubject(s, fileObjects, _this.ignore.js);
if (dependencies.length > 0) {

@@ -51,6 +52,7 @@ dependencies.forEach(function (d) {

};
DependOnStrategy.getDependenciesOfSubject = function (subject, objects) {
DependOnStrategy.getDependenciesOfSubject = function (subject, objects, ignoreJs) {
if (ignoreJs === void 0) { ignoreJs = false; }
var result = [];
objects.forEach(function (object) {
var declaration = DependOnStrategy.getImportDeclarationForObject(object, subject);
var declaration = DependOnStrategy.getImportDeclarationForObject(object, subject, ignoreJs);
if (declaration) {

@@ -62,15 +64,28 @@ result.push(object);

};
DependOnStrategy.getImportDeclarationForObject = function (object, subject) {
DependOnStrategy.getImportDeclarationForObject = function (object, subject, ignoreJs) {
if (ignoreJs === void 0) { ignoreJs = false; }
var result = null;
this.getImportDeclarations(subject).forEach(function (i) {
// FIXME this is an assumption, we need to consider shortcutted imports e.g. from node_modules.
// FIXME It would be nice to use the typescript compilers resolution algorithm
var assumedPathTokens = subject.getPath().split("/").concat(i.moduleSpecifier["text"].split("/"));
// FIXME this is an assumption, we need to consider other types e.g. JS files
// FIXME It would be nice to use the typescript compilers resolution algorithm
var assumedPath = path.join.apply(path, assumedPathTokens) + ".ts";
if (path.normalize(assumedPath) ===
path.normalize(object.getPath() + "/" + object.getName())) {
result = i;
var assumedPath = path.join.apply(path, assumedPathTokens);
var isResult = function (p) {
return path.normalize(p) === path.normalize(object.getPath() + "/" + object.getName());
};
if (assumedPath.match(/.+(.ts)$/)) {
if (isResult(assumedPath)) {
result = i;
}
}
else if (assumedPath.match(/.+(.js)$/) && !ignoreJs) {
if (isResult(assumedPath)) {
result = i;
}
}
else {
var assumedTsPath = path.join.apply(path, assumedPathTokens) + ".ts";
var assumedJsPath = path.join.apply(path, assumedPathTokens) + ".js";
if (isResult(assumedTsPath) || (ignoreJs ? false : isResult(assumedJsPath))) {
result = i;
}
}
});

@@ -77,0 +92,0 @@ return result;

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

this.a = 2;
var b = new DependOnStrategy_1.DependOnStrategy();
var b = new DependOnStrategy_1.DependOnStrategy({ js: false, declarations: true, nodeModules: true });
var c = new HaveComplexityLowerThanStrategy_1.HaveComplexityLowerThanStrategy(2);

@@ -11,0 +11,0 @@ }

import { Project } from "../Project";
import { IgnoreConfig } from "../TSArch";
export declare class ProjectParser {
static parse(rootPath: string): Promise<Project>;
static parse(rootPath: string, config: IgnoreConfig): Promise<Project>;
static getFileNames(globPattern: string): Promise<string[]>;
}

@@ -44,8 +44,10 @@ "use strict";

}
ProjectParser.parse = function (rootPath) {
ProjectParser.parse = function (rootPath, config) {
return __awaiter(this, void 0, void 0, function () {
var fileNames, project, program;
var glob, fileNames, project, program;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, ProjectParser.getFileNames(rootPath + "/**/*.ts")];
case 0:
glob = config.js ? "/**/*.ts" : "/**/*.(js|ts)";
return [4 /*yield*/, ProjectParser.getFileNames(rootPath + glob)];
case 1:

@@ -58,4 +60,4 @@ fileNames = _a.sent();

program.getSourceFiles().forEach(function (s) {
// TODO make this configurable ?
if (!s.fileName.endsWith(".d.ts") && !s.fileName.includes("node_modules")) {
if ((config.declarations ? !s.fileName.endsWith(".d.ts") : true) &&
(config.nodeModules ? !s.fileName.includes("node_modules") : true)) {
var file = FileFactory_1.FileFactory.buildFromSourceFile(s);

@@ -62,0 +64,0 @@ project.addFile(file);

import { SubjectFilterStarter } from "./lang/SubjectFilterStarter";
import { Project } from "./Project";
export interface TSArchConfig {
ignore: IgnoreConfig;
}
export interface IgnoreConfig {
declarations: boolean;
nodeModules: boolean;
js: boolean;
}
export declare class TSArch {
static config: TSArchConfig;
static defineThat(): SubjectFilterStarter;
static parseTypescriptProject(path: string): Promise<Project>;
}

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

TSArch.defineThat = function () {
return RuleBuilder_1.RuleBuilder.defineThat();
return new RuleBuilder_1.RuleBuilder(TSArch.config.ignore);
};

@@ -52,3 +52,3 @@ TSArch.parseTypescriptProject = function (path) {

switch (_a.label) {
case 0: return [4 /*yield*/, ProjectParser_1.ProjectParser.parse(path)];
case 0: return [4 /*yield*/, ProjectParser_1.ProjectParser.parse(path, TSArch.config.ignore)];
case 1:

@@ -61,2 +61,9 @@ project = _a.sent();

};
TSArch.config = {
ignore: {
declarations: true,
nodeModules: true,
js: false
}
};
return TSArch;

@@ -63,0 +70,0 @@ }());

{
"name": "tsarch",
"version": "3.3.2",
"version": "3.4.0",
"description": "",

@@ -93,10 +93,2 @@ "keywords": [],

"rimraf": "^2.6.1",
"rollup": "^0.59.2",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-typescript": "^1.0.0",
"rollup-plugin-typescript2": "^0.11.1",
"semantic-release": "^15.8.1",

@@ -111,3 +103,2 @@ "travis-deploy-once": "^5.0.1",

"typedoc": "^0.14.0",
"typescript": "^3.3.4000",
"validate-commit-msg": "^2.12.2"

@@ -117,4 +108,5 @@ },

"fs": "0.0.1-security",
"typescript": "^3.3.4000",
"path": "^0.12.7"
}
}

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

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