Skip to content
Snippets Groups Projects
Unverified Commit e5049e49 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

feat(cake): Add support for Cake manager (#9512)

parent 893df627
Branches
Tags
No related merge requests found
......@@ -6,6 +6,7 @@ import * as batectWrapper from './batect-wrapper';
import * as bazel from './bazel';
import * as buildkite from './buildkite';
import * as bundler from './bundler';
import * as cake from './cake';
import * as cargo from './cargo';
import * as cdnurl from './cdnurl';
import * as circleci from './circleci';
......@@ -70,6 +71,7 @@ api.set('batect-wrapper', batectWrapper);
api.set('bazel', bazel);
api.set('buildkite', buildkite);
api.set('bundler', bundler);
api.set('cake', cake);
api.set('cargo', cargo);
api.set('cdnurl', cdnurl);
api.set('circleci', circleci);
......
foo
#addin nuget:?package=Foo.Foo&version=1.1.1
#tool nuget:https://example.com?package=Bar.Bar&version=2.2.2
#module nuget:file:///tmp/?package=Baz.Baz&version=3.3.3
// #module nuget:?package=Qux.Qux&version=4.4.4
/*
#module nuget:?package=Quux.Quux&version=5.5.5
*/
bar
#module nuget:foobar!@#
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`manager/cake/index extracts 1`] = `
Object {
"deps": Array [
Object {
"currentValue": "1.1.1",
"datasource": "nuget",
"depName": "Foo.Foo",
},
Object {
"currentValue": "2.2.2",
"datasource": "nuget",
"depName": "Bar.Bar",
"registryUrls": Array [
"https://example.com",
],
},
Object {
"currentValue": "3.3.3",
"datasource": "nuget",
"depName": "Baz.Baz",
"skipReason": "unsupported-url",
},
],
}
`;
import { readFileSync } from 'fs';
import { getName } from '../../../test/util';
import { extractPackageFile } from '.';
const content = readFileSync(
'lib/manager/cake/__fixtures__/build.cake',
'utf8'
);
describe(getName(__filename), () => {
it('extracts', () => {
expect(extractPackageFile(content)).toMatchSnapshot();
});
});
import moo from 'moo';
import { LANGUAGE_DOT_NET } from '../../constants/languages';
import { id as datasource } from '../../datasource/nuget';
import { SkipReason } from '../../types';
import { PackageDependency, PackageFile } from '../types';
export const language = LANGUAGE_DOT_NET;
export const defaultConfig = {
fileMatch: ['\\.cake$'],
};
const lexerStates = {
main: {
lineComment: { match: /\/\/.*?$/ },
multiLineComment: { match: /\/\*[^]*?\*\//, lineBreaks: true },
dependency: {
match: /^#(?:addin|tool|module)\s+(?:nuget|dotnet):.*$/,
},
unknown: { match: /[^]/, lineBreaks: true },
},
};
function parseDependencyLine(line: string): PackageDependency | null {
try {
let url = line.replace(/^[^:]*:/, '');
const isEmptyHost = url.startsWith('?');
url = isEmptyHost ? `http://localhost/${url}` : url;
const { origin: registryUrl, protocol, searchParams } = new URL(url);
const depName = searchParams.get('package');
const currentValue = searchParams.get('version');
const result: PackageDependency = { datasource, depName, currentValue };
if (!isEmptyHost) {
if (protocol.startsWith('http')) {
result.registryUrls = [registryUrl];
} else {
result.skipReason = SkipReason.UnsupportedUrl;
}
}
return result;
} catch (err) {
return null;
}
}
export function extractPackageFile(content: string): PackageFile {
const deps = [];
const lexer = moo.states(lexerStates);
lexer.reset(content);
let token = lexer.next();
while (token) {
const { type, value } = token;
if (type === 'dependency') {
const dep = parseDependencyLine(value);
if (dep) {
deps.push(dep);
}
}
token = lexer.next();
}
return { deps };
}
Extracts dependencies from `*.cake` files.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment