Socket
Socket
Sign inDemoInstall

snyk-paket-parser

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snyk-paket-parser - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

dist/errors/index.d.ts

8

dist/dependencies-parser.d.ts

@@ -17,5 +17,11 @@ interface Options {

}
export interface NugetDependency extends Dependency {
source: 'nuget';
name: string;
versionRange: string;
options: Options;
}
export interface PaketDependencies extends Array<DependencyGroup> {
}
export declare function parse(input: string): PaketDependencies;
export declare function parseDependenciesFile(input: string): PaketDependencies;
export {};

6

dist/dependencies-parser.js

@@ -77,4 +77,4 @@ "use strict";

}
function parse(input) {
const lines = line_parser_1.parse(input);
function parseDependenciesFile(input) {
const lines = line_parser_1.parseLines(input);
const result = [];

@@ -131,3 +131,3 @@ let group = {

}
exports.parse = parse;
exports.parseDependenciesFile = parseDependenciesFile;
//# sourceMappingURL=dependencies-parser.js.map

@@ -1,7 +0,6 @@

import { PaketLock } from './lock-parser';
interface DepTree {
export interface DepTree {
name: string;
version: string;
dependencies: {
[dep: string]: DepTree;
[dep: string]: {};
};

@@ -13,7 +12,7 @@ depType?: DepType;

}
declare enum DepType {
export declare enum DepType {
prod = "prod",
dev = "dev"
}
export declare function buildDependencyTree(lockFile: PaketLock, includeDev?: boolean): DepTree;
export {};
export declare function buildDepTreeFromFiles(root: string, manifestFilePath: string, lockFilePath: string, includeDev?: boolean, strict?: boolean): Promise<DepTree>;
export declare function buildDepTree(manifestFileContents: string, lockFileContents: string, includeDev?: boolean, strict?: boolean, defaultManifestFileName?: string): Promise<DepTree>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const lock_parser_1 = require("./lock-parser");
const dependencies_parser_1 = require("./dependencies-parser");
const path = require("path");
const fs = require("fs");
const errors_1 = require("./errors");
const DEV_GROUPS = ['build', 'test', 'tests'];
var DepType;

@@ -10,28 +13,28 @@ (function (DepType) {

DepType["dev"] = "dev";
})(DepType || (DepType = {}));
function parse(manifestFileContents, lockFileContents, includeDev = false) {
// parse manifestFileContents here too when the time comes
const lockFile = lock_parser_1.parseLockFile(lockFileContents);
return buildDependencyTree(lockFile, includeDev);
}
function parseFromFile(root, manifestFilePath, lockFilePath, includeDev = false) {
if (!root || !manifestFilePath || !lockFilePath) {
throw new Error('Missing required parameters for parseFromFile()');
}
})(DepType = exports.DepType || (exports.DepType = {}));
async function buildDepTreeFromFiles(root, manifestFilePath, lockFilePath, includeDev = false, strict = true) {
const manifestFileFullPath = path.resolve(root, manifestFilePath);
const lockFileeFullPath = path.resolve(root, lockFilePath);
const lockFileFullPath = path.resolve(root, lockFilePath);
if (!fs.existsSync(manifestFileFullPath)) {
throw new Error('No paket.dependencies file found at ' +
throw new errors_1.InvalidUserInputError('Target file paket.dependencies not found at ' +
`location: ${manifestFileFullPath}`);
}
if (!fs.existsSync(lockFileeFullPath)) {
throw new Error('No paket.lock file found at ' +
`location: ${lockFileeFullPath}`);
if (!fs.existsSync(lockFileFullPath)) {
throw new errors_1.InvalidUserInputError('Lockfile not found at location: ' +
lockFileFullPath);
}
const manifestFileContents = fs.readFileSync(manifestFileFullPath, 'utf-8');
const lockFileContents = fs.readFileSync(manifestFileFullPath, 'utf-8');
return parse(manifestFileContents, manifestFileContents, includeDev);
const lockFileContents = fs.readFileSync(lockFileFullPath, 'utf-8');
return await buildDepTree(manifestFileContents, lockFileContents, includeDev, strict, manifestFileFullPath);
}
function buildDependencyTree(
/* manifestFile: PaketManifest, */ lockFile, includeDev = false) {
exports.buildDepTreeFromFiles = buildDepTreeFromFiles;
async function buildDepTree(manifestFileContents, lockFileContents, includeDev = false, strict = true, defaultManifestFileName = 'paket.dependencies') {
const manifestFile = dependencies_parser_1.parseDependenciesFile(manifestFileContents);
const lockFile = lock_parser_1.parseLockFile(lockFileContents);
const tree = buildDependencyTree(manifestFile, lockFile, includeDev);
tree.name = defaultManifestFileName;
return tree;
}
exports.buildDepTree = buildDepTree;
function buildDependencyTree(manifestFile, lockFile, includeDev = false) {
const depTree = {

@@ -42,4 +45,15 @@ dependencies: {},

};
const dependencies = {};
for (const group of manifestFile) {
for (const dep of group.dependencies) {
const current = dep;
if (current.name) {
dependencies[current.name] = {
name: current.name,
};
}
}
}
for (const group of lockFile.groups) {
const isDev = group.name === 'build' || group.name === 'test' || group.name === 'tests';
const isDev = DEV_GROUPS.includes((group.name || '').toLowerCase());
if (isDev && !includeDev) {

@@ -49,21 +63,28 @@ continue;

for (const dep of group.dependencies) {
depTree.dependencies[dep.name] = {
depType: isDev ? DepType.dev : DepType.prod,
dependencies: buildSubTree(dep.dependencies),
name: dep.name,
version: dep.version,
};
if (dependencies[dep.name]) {
dependencies[dep.name] = {
depType: isDev ? DepType.dev : DepType.prod,
dependencies: buildSubTree(dep.dependencies, group.dependencies, isDev),
name: dep.name,
version: dep.version,
};
}
}
}
depTree.dependencies = dependencies;
return depTree;
}
exports.buildDependencyTree = buildDependencyTree;
function buildSubTree(dependency) {
function buildSubTree(dependencies, groupDeps, isDev) {
const subTree = {};
for (const dep of dependency) {
subTree[dep.name] = {
dependencies: {},
name: dep.name,
version: dep.version,
};
for (const currDep of dependencies) {
for (const dep of groupDeps) {
if (dep.name === currDep.name) {
subTree[dep.name] = {
depType: isDev ? DepType.dev : DepType.prod,
dependencies: buildSubTree(dep.dependencies, groupDeps, isDev),
name: dep.name,
version: dep.version,
};
}
}
}

@@ -70,0 +91,0 @@ return subTree;

@@ -6,2 +6,2 @@ export declare class Line {

}
export declare function parse(input: string, indent?: string, lineSeparator?: RegExp): Line[];
export declare function parseLines(input: string, indent?: string, lineSeparator?: RegExp): Line[];

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

// parse space indented lines into array of Lines
function parse(input, indent = ' ' /* two spaces */, lineSeparator = /\r?\n/) {
function parseLines(input, indent = ' ' /* two spaces */, lineSeparator = /\r?\n/) {
const lines = input.split(lineSeparator);

@@ -33,3 +33,3 @@ const result = [];

}
exports.parse = parse;
exports.parseLines = parseLines;
//# sourceMappingURL=line-parser.js.map
interface Option {
[name: string]: string | null;
}
interface Dependency {
export interface Dependency {
name: string;

@@ -6,0 +6,0 @@ version: string;

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

};
const lines = line_parser_1.parse(input);
const lines = line_parser_1.parseLines(input);
let group = {

@@ -100,5 +100,2 @@ name: null,

if (line.indentation === 2) { // Resolved Dependency
if (dependency) {
group.dependencies.push(dependency);
}
dep.remote = depContext.remote;

@@ -112,7 +109,6 @@ dep.repository = depContext.repository;

}
if (group && dependency && !group.dependencies.includes(dependency)) {
group.dependencies.push(dependency);
}
}
// handles final dependency & group
if (dependency) {
group.dependencies.push(dependency);
}
result.groups.push(group);

@@ -119,0 +115,0 @@ return result;

@@ -41,3 +41,3 @@ {

},
"version": "1.2.1"
"version": "1.3.0"
}

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