Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spike: test command paket support #362

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/detect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const DETECTABLE_FILES = [
'project.assets.json',
'packages.config',
'composer.lock',
'paket.dependencies',
];

// when file is specified with --file, we look it up here
Expand All @@ -44,6 +45,7 @@ const DETECTABLE_PACKAGE_MANAGERS = {
'packages.config': 'nuget',
'project.json': 'nuget',
'composer.lock': 'composer',
'paket.dependencies': 'paket',
};

export function isPathToPackageFile(path) {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function loadPlugin(packageManager, options) {
case 'composer': {
return require('snyk-php-plugin');
}
case 'paket': {
return require('./paket');
}
default: {
throw new Error('Unsupported package manager: ' + packageManager);
}
Expand Down
55 changes: 55 additions & 0 deletions src/lib/plugins/paket/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import * as fs from 'fs';
import * as path from 'path';
import {parse} from 'snyk-paket-parser';

export async function inspect(root: string, targetFile: string, options: any) {
const manifestFileFullPath = path.resolve(root, targetFile);

if (!fs.existsSync(manifestFileFullPath)) {
throw new Error('Manifest ' + targetFile + ' not found at location: ' +
manifestFileFullPath);
}

const fullPath = path.parse(manifestFileFullPath);
const lockFileFullPath = path.resolve(fullPath.dir, 'paket.lock');

if (!fs.existsSync(lockFileFullPath)) {
throw new Error('Lockfile paket.lock not found at location: ' +
lockFileFullPath + '. Please run `paket install` and re-run your snyk command.');
}

return {
plugin: {
name: 'paket',
packageManager: 'nuget',
},
package: {
dependencies: buildTree(fs.readFileSync(manifestFileFullPath, 'utf8')),
hasDevDependencies: false,
name: manifestFileFullPath,
version: '',
},
};
}

// TODO: use function from snyk-paket-parser to build the tree
function buildTree(data) {
const parsed = parse(data);
const dependencies = {} as any;

for (const group of parsed) {
for (const dep of group.dependencies) {
if (dep.source === 'nuget') {
const nugetDep = dep as any;

dependencies[nugetDep.name] = {
name: nugetDep.name,
version: nugetDep.versionRange,
dependencies: {},
};
}
}
}

return dependencies;
}
1 change: 1 addition & 0 deletions src/lib/snyk-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function run(root, options) {
'govendor',
'nuget',
'composer',
'paket',
].indexOf(packageManager) === -1) {
throw new Error('Unsupported package manager: ' + packageManager);
}
Expand Down