mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 14:36:25 +00:00
chore(manager): add more type annotations (#4344)
This commit is contained in:
parent
6be9ee0418
commit
081a23e6fc
70 changed files with 228 additions and 158 deletions
|
@ -2,7 +2,9 @@ import { logger } from '../../logger';
|
|||
import { getDep } from '../dockerfile/extract';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export default function extractPackageFile(content: string): PackageFile {
|
||||
export default function extractPackageFile(
|
||||
content: string
|
||||
): PackageFile | null {
|
||||
logger.trace('ansible.extractPackageFile()');
|
||||
let deps: PackageDependency[] = [];
|
||||
let lineNumber = 0;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export default function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
) {
|
||||
): string | null {
|
||||
try {
|
||||
const newFrom = getNewFrom(upgrade);
|
||||
logger.debug(`ansible.updateDependency(): ${newFrom}`);
|
||||
|
|
|
@ -4,7 +4,12 @@ import { parse as _parse } from 'url';
|
|||
import { logger } from '../../logger';
|
||||
import { PackageDependency, PackageFile } from '../common';
|
||||
|
||||
function parseUrl(urlString: string) {
|
||||
interface UrlParsedResult {
|
||||
repo: string;
|
||||
currentValue: string;
|
||||
}
|
||||
|
||||
function parseUrl(urlString: string): UrlParsedResult | null {
|
||||
// istanbul ignore if
|
||||
if (!urlString) {
|
||||
return null;
|
||||
|
@ -29,7 +34,7 @@ function parseUrl(urlString: string) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function findBalancedParenIndex(longString: string) {
|
||||
function findBalancedParenIndex(longString: string): number {
|
||||
/**
|
||||
* Minimalistic string parser with single task -> find last char in def.
|
||||
* It treats [)] as the last char.
|
||||
|
@ -63,7 +68,7 @@ function findBalancedParenIndex(longString: string) {
|
|||
});
|
||||
}
|
||||
|
||||
function parseContent(content: string) {
|
||||
function parseContent(content: string): string[] {
|
||||
return [
|
||||
'container_pull',
|
||||
'http_archive',
|
||||
|
@ -86,7 +91,7 @@ function parseContent(content: string) {
|
|||
);
|
||||
}
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
const definitions = parseContent(content);
|
||||
if (!definitions.length) {
|
||||
logger.debug('No matching WORKSPACE definitions found');
|
||||
|
|
|
@ -7,7 +7,7 @@ function updateWithNewVersion(
|
|||
content: string,
|
||||
currentValue: string,
|
||||
newValue: string
|
||||
) {
|
||||
): string {
|
||||
const currentVersion = currentValue.replace(/^v/, '');
|
||||
const newVersion = newValue.replace(/^v/, '');
|
||||
let newContent = content;
|
||||
|
@ -17,7 +17,7 @@ function updateWithNewVersion(
|
|||
return newContent;
|
||||
}
|
||||
|
||||
function extractUrl(flattened: string) {
|
||||
function extractUrl(flattened: string): string[] | null {
|
||||
const urlMatch = flattened.match(/url="(.*?)"/);
|
||||
if (!urlMatch) {
|
||||
logger.debug('Cannot locate urls in new definition');
|
||||
|
@ -26,7 +26,7 @@ function extractUrl(flattened: string) {
|
|||
return [urlMatch[1]];
|
||||
}
|
||||
|
||||
function extractUrls(content: string) {
|
||||
function extractUrls(content: string): string[] | null {
|
||||
const flattened = content.replace(/\n/g, '').replace(/\s/g, '');
|
||||
const urlsMatch = flattened.match(/urls?=\[.*?\]/);
|
||||
if (!urlsMatch) {
|
||||
|
@ -40,9 +40,12 @@ function extractUrls(content: string) {
|
|||
return urls;
|
||||
}
|
||||
|
||||
async function getHashFromUrl(url: string) {
|
||||
async function getHashFromUrl(url: string): Promise<string | null> {
|
||||
const cacheNamespace = 'url-sha256';
|
||||
const cachedResult = await renovateCache.get(cacheNamespace, url);
|
||||
const cachedResult = await renovateCache.get<string | null>(
|
||||
cacheNamespace,
|
||||
url
|
||||
);
|
||||
/* istanbul ignore next line */
|
||||
if (cachedResult) return cachedResult;
|
||||
try {
|
||||
|
@ -57,7 +60,7 @@ async function getHashFromUrl(url: string) {
|
|||
}
|
||||
}
|
||||
|
||||
async function getHashFromUrls(urls: string[]) {
|
||||
async function getHashFromUrls(urls: string[]): Promise<string | null> {
|
||||
const hashes = (await Promise.all(
|
||||
urls.map(url => getHashFromUrl(url))
|
||||
)).filter(Boolean);
|
||||
|
@ -73,14 +76,14 @@ async function getHashFromUrls(urls: string[]) {
|
|||
return distinctHashes[0];
|
||||
}
|
||||
|
||||
function setNewHash(content: string, hash: string) {
|
||||
function setNewHash(content: string, hash: string): string {
|
||||
return content.replace(/(sha256\s*=\s*)"[^"]+"/, `$1"${hash}"`);
|
||||
}
|
||||
|
||||
export async function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): Promise<string> {
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
logger.debug(
|
||||
`bazel.updateDependency(): ${upgrade.newValue || upgrade.newDigest}`
|
||||
|
|
|
@ -4,7 +4,7 @@ import { PackageFile, PackageDependency } from '../common';
|
|||
|
||||
export { extractPackageFile };
|
||||
|
||||
function extractPackageFile(content: string): PackageFile {
|
||||
function extractPackageFile(content: string): PackageFile | null {
|
||||
const deps: PackageDependency[] = [];
|
||||
try {
|
||||
const lines = content.split('\n');
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { logger } from '../../logger';
|
||||
import { Upgrade } from '../common';
|
||||
|
||||
export function updateDependency(currentFileContent: string, upgrade: Upgrade) {
|
||||
export function updateDependency(
|
||||
currentFileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string | null {
|
||||
try {
|
||||
const lineIdx = upgrade.managerData.lineNumber - 1;
|
||||
logger.debug(`buildkite.updateDependency: ${upgrade.newValue}`);
|
||||
|
|
|
@ -10,7 +10,7 @@ import {
|
|||
matches,
|
||||
sortVersions,
|
||||
} from '../../versioning/ruby';
|
||||
import { UpdateArtifactsConfig } from '../common';
|
||||
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
|
||||
|
||||
// istanbul ignore next
|
||||
export async function updateArtifacts(
|
||||
|
@ -18,7 +18,7 @@ export async function updateArtifacts(
|
|||
updatedDeps: string[],
|
||||
newPackageFileContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
) {
|
||||
): Promise<UpdateArtifactsResult[] | null> {
|
||||
logger.debug(`bundler.updateArtifacts(${packageFileName})`);
|
||||
// istanbul ignore if
|
||||
if (global.repoCache.bundlerArtifactsError) {
|
||||
|
|
|
@ -7,7 +7,7 @@ export { extractPackageFile };
|
|||
async function extractPackageFile(
|
||||
content: string,
|
||||
fileName?: string
|
||||
): Promise<PackageFile> {
|
||||
): Promise<PackageFile | null> {
|
||||
const res: PackageFile = {
|
||||
registryUrls: [],
|
||||
deps: [],
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import { RangeStrategy } from '../../versioning';
|
||||
|
||||
/*
|
||||
* The getRangeStrategy() function is optional and can be removed if not applicable.
|
||||
* It is used when the user configures rangeStrategy=auto.
|
||||
|
@ -11,6 +13,6 @@
|
|||
*
|
||||
*/
|
||||
|
||||
export function getRangeStrategy() {
|
||||
export function getRangeStrategy(): RangeStrategy {
|
||||
return 'replace';
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
currentFileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const delimiter =
|
||||
currentFileContent.split('"').length >
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function updateArtifacts(
|
|||
updatedDeps: string[],
|
||||
newPackageFileContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
): Promise<UpdateArtifactsResult[]> {
|
||||
): Promise<UpdateArtifactsResult[] | null> {
|
||||
await logger.debug(`cargo.updateArtifacts(${packageFileName})`);
|
||||
if (updatedDeps === undefined || updatedDeps.length < 1) {
|
||||
logger.debug('No updated cargo deps - returning null');
|
||||
|
|
|
@ -7,7 +7,7 @@ import { CargoConfig, CargoSection } from './types';
|
|||
export function extractPackageFile(
|
||||
content: string,
|
||||
fileName: string
|
||||
): PackageFile {
|
||||
): PackageFile | null {
|
||||
logger.trace(`cargo.extractPackageFile(${fileName})`);
|
||||
let parsedContent: CargoConfig;
|
||||
try {
|
||||
|
@ -55,7 +55,7 @@ function extractFromSection(
|
|||
parsedContent: CargoSection,
|
||||
section: keyof CargoSection,
|
||||
target?: string
|
||||
) {
|
||||
): PackageDependency[] {
|
||||
const deps: PackageDependency[] = [];
|
||||
const sectionContent = parsedContent[section];
|
||||
if (!sectionContent) {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
import { CargoConfig, CargoSection } from './types';
|
||||
|
||||
// Return true if the match string is found at index in content
|
||||
function matchAt(content: string, index: number, match: string) {
|
||||
function matchAt(content: string, index: number, match: string): boolean {
|
||||
return content.substring(index, index + match.length) === match;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ function replaceAt(
|
|||
index: number,
|
||||
oldString: string,
|
||||
newString: string
|
||||
) {
|
||||
): string {
|
||||
logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
|
||||
return (
|
||||
content.substr(0, index) +
|
||||
|
@ -27,7 +27,7 @@ function replaceAt(
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade<{ nestedVersion?: boolean }>
|
||||
) {
|
||||
): string {
|
||||
logger.trace({ config: upgrade }, 'poetry.updateDependency()');
|
||||
if (!upgrade) {
|
||||
return fileContent;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
|||
import { getDep } from '../dockerfile/extract';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
const deps: PackageDependency[] = [];
|
||||
try {
|
||||
const lines = content.split('\n');
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const lines = fileContent.split('\n');
|
||||
const lineToChange = lines[upgrade.managerData.lineNumber];
|
||||
|
|
|
@ -173,15 +173,17 @@ export interface ManagerApi {
|
|||
extractAllPackageFiles?(
|
||||
config: ExtractConfig,
|
||||
files: string[]
|
||||
): Result<PackageFile[]>;
|
||||
): Result<PackageFile[] | null>;
|
||||
|
||||
extractPackageFile?(
|
||||
content: string,
|
||||
packageFile?: string,
|
||||
config?: ExtractConfig
|
||||
): Result<PackageFile>;
|
||||
): Result<PackageFile | null>;
|
||||
|
||||
getPackageUpdates(config: PackageUpdateConfig): Result<PackageUpdateResult[]>;
|
||||
getPackageUpdates?(
|
||||
config: PackageUpdateConfig
|
||||
): Result<PackageUpdateResult[]>;
|
||||
|
||||
getRangeStrategy(config: RangeConfig): RangeStrategy;
|
||||
|
||||
|
@ -190,9 +192,12 @@ export interface ManagerApi {
|
|||
updatedDeps: string[],
|
||||
newPackageFileContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
): Result<UpdateArtifactsResult[]>;
|
||||
): Result<UpdateArtifactsResult[] | null>;
|
||||
|
||||
updateDependency(fileContent: string, upgrade: Upgrade): Result<string>;
|
||||
updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): Result<string | null>;
|
||||
}
|
||||
|
||||
// TODO: name and properties used by npm manager
|
||||
|
|
|
@ -3,7 +3,7 @@ import URL from 'url';
|
|||
import fs from 'fs-extra';
|
||||
import upath from 'upath';
|
||||
import { exec } from '../../util/exec';
|
||||
import { UpdateArtifactsConfig } from '../common';
|
||||
import { UpdateArtifactsConfig, UpdateArtifactsResult } from '../common';
|
||||
import { logger } from '../../logger';
|
||||
import * as hostRules from '../../util/host-rules';
|
||||
import { getChildProcessEnv } from '../../util/env';
|
||||
|
@ -13,7 +13,7 @@ export async function updateArtifacts(
|
|||
updatedDeps: string[],
|
||||
newPackageFileContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
) {
|
||||
): Promise<UpdateArtifactsResult[] | null> {
|
||||
logger.debug(`composer.updateArtifacts(${packageFileName})`);
|
||||
process.env.COMPOSER_CACHE_DIR =
|
||||
process.env.COMPOSER_CACHE_DIR ||
|
||||
|
|
|
@ -81,7 +81,10 @@ function parseRepositories(
|
|||
}
|
||||
}
|
||||
|
||||
export async function extractPackageFile(content: string, fileName: string) {
|
||||
export async function extractPackageFile(
|
||||
content: string,
|
||||
fileName: string
|
||||
): Promise<PackageFile | null> {
|
||||
logger.trace(`composer.extractPackageFile(${fileName})`);
|
||||
let composerJson: ComposerConfig;
|
||||
try {
|
||||
|
|
|
@ -28,7 +28,7 @@ export function splitImageParts(currentFrom: string): PackageDependency {
|
|||
return dep;
|
||||
}
|
||||
|
||||
export function getDep(currentFrom: string) {
|
||||
export function getDep(currentFrom: string): PackageDependency {
|
||||
const dep = splitImageParts(currentFrom);
|
||||
dep.datasource = 'docker';
|
||||
if (
|
||||
|
@ -41,7 +41,7 @@ export function getDep(currentFrom: string) {
|
|||
return dep;
|
||||
}
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
const deps: PackageDependency[] = [];
|
||||
const stageNames: string[] = [];
|
||||
let lineNumber = 0;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { logger } from '../../logger';
|
||||
import { Upgrade } from '../common';
|
||||
|
||||
export function getNewFrom(upgrade: Upgrade) {
|
||||
export function getNewFrom(upgrade: Upgrade): string {
|
||||
const { depName, newValue, newDigest } = upgrade;
|
||||
let newFrom = depName;
|
||||
if (newValue) {
|
||||
|
@ -13,7 +13,10 @@ export function getNewFrom(upgrade: Upgrade) {
|
|||
return newFrom;
|
||||
}
|
||||
|
||||
export function updateDependency(fileContent: string, upgrade: Upgrade) {
|
||||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string | null {
|
||||
try {
|
||||
const { lineNumber, fromSuffix } = upgrade.managerData;
|
||||
let { fromPrefix } = upgrade.managerData;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
|||
import { getDep } from '../dockerfile/extract';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
const deps: PackageDependency[] = [];
|
||||
try {
|
||||
const lines = content.split('\n');
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const lines = fileContent.split('\n');
|
||||
const lineToChange = lines[upgrade.managerData.lineNumber];
|
||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
|||
import { getDep } from '../dockerfile/extract';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.debug('github-actions.extractPackageFile()');
|
||||
const deps: PackageDependency[] = [];
|
||||
let lineNumber = 0;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const newFrom = getNewFrom(upgrade);
|
||||
logger.debug(`github-actions.updateDependency(): ${newFrom}`);
|
||||
|
|
|
@ -7,7 +7,7 @@ function extractDepFromInclude(includeObj: {
|
|||
file: any;
|
||||
project: string;
|
||||
ref: string;
|
||||
}) {
|
||||
}): PackageDependency | null {
|
||||
if (!includeObj.file || !includeObj.project) {
|
||||
return null;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ export function extractPackageFile(
|
|||
content: string,
|
||||
_packageFile: string,
|
||||
config: ExtractConfig
|
||||
): PackageFile {
|
||||
): PackageFile | null {
|
||||
const deps: PackageDependency[] = [];
|
||||
try {
|
||||
const doc = yaml.safeLoad(content);
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
currentFileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const { depName, newValue } = upgrade;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
|||
import { getDep } from '../dockerfile/extract';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
const deps: PackageDependency[] = [];
|
||||
try {
|
||||
const lines = content.split('\n');
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
currentFileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const newFrom = getNewFrom(upgrade);
|
||||
const lines = currentFileContent.split('\n');
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function updateArtifacts(
|
|||
_updatedDeps: string[],
|
||||
newGoModContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
): Promise<UpdateArtifactsResult[]> {
|
||||
): Promise<UpdateArtifactsResult[] | null> {
|
||||
logger.debug(`gomod.updateArtifacts(${goModFileName})`);
|
||||
process.env.GOPATH =
|
||||
process.env.GOPATH || join(config.cacheDir, './others/go');
|
||||
|
|
|
@ -2,7 +2,11 @@ import { logger } from '../../logger';
|
|||
import { isVersion } from '../../versioning/semver';
|
||||
import { PackageDependency, PackageFile } from '../common';
|
||||
|
||||
function getDep(lineNumber: number, match: RegExpMatchArray, type: string) {
|
||||
function getDep(
|
||||
lineNumber: number,
|
||||
match: RegExpMatchArray,
|
||||
type: string
|
||||
): PackageDependency {
|
||||
const [, , currentValue] = match;
|
||||
let [, depName] = match;
|
||||
depName = depName.replace(/"/g, '');
|
||||
|
@ -35,7 +39,7 @@ function getDep(lineNumber: number, match: RegExpMatchArray, type: string) {
|
|||
return dep;
|
||||
}
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.trace({ content }, 'gomod.extractPackageFile()');
|
||||
const deps: PackageDependency[] = [];
|
||||
try {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
currentFileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
logger.debug(`gomod.updateDependency: ${upgrade.newValue}`);
|
||||
const { depName, depType } = upgrade;
|
||||
|
|
|
@ -2,7 +2,7 @@ import { coerce } from 'semver';
|
|||
import { logger } from '../../logger';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(fileContent: string): PackageFile {
|
||||
export function extractPackageFile(fileContent: string): PackageFile | null {
|
||||
logger.debug('gradle-wrapper.extractPackageFile()');
|
||||
const lines = fileContent.split('\n');
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export async function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): Promise<string> {
|
||||
): Promise<string | null> {
|
||||
try {
|
||||
logger.debug(upgrade, 'gradle-wrapper.updateDependency()');
|
||||
const lines = fileContent.split('\n');
|
||||
|
@ -35,14 +35,14 @@ export async function updateDependency(
|
|||
}
|
||||
}
|
||||
|
||||
function replaceType(url: string) {
|
||||
function replaceType(url: string): string {
|
||||
return url.replace('bin', 'all');
|
||||
}
|
||||
|
||||
async function getChecksum(url: string) {
|
||||
async function getChecksum(url: string): Promise<string> {
|
||||
try {
|
||||
const response = await got(url);
|
||||
return response.body;
|
||||
return response.body as string;
|
||||
} catch (err) {
|
||||
if (err.statusCode === 404 || err.code === 'ENOTFOUND') {
|
||||
logger.info('Gradle checksum lookup failure: not found');
|
||||
|
|
|
@ -26,7 +26,7 @@ export function updateGradleVersion(
|
|||
buildGradleContent: string,
|
||||
dependency: GradleDependency,
|
||||
newVersion: string
|
||||
) {
|
||||
): string {
|
||||
if (dependency) {
|
||||
const updateFunctions: UpdateFunction[] = [
|
||||
updateVersionLiterals,
|
||||
|
@ -84,7 +84,7 @@ function updateVersionLiterals(
|
|||
dependency: GradleDependency,
|
||||
buildGradleContent: string,
|
||||
newVersion: string
|
||||
) {
|
||||
): string | null {
|
||||
const regexes: RegExp[] = [
|
||||
moduleStringVersionFormatMatch(dependency),
|
||||
groovyPluginStringVersionFormatMatch(dependency),
|
||||
|
@ -104,7 +104,7 @@ function updateLocalVariables(
|
|||
dependency: GradleDependency,
|
||||
buildGradleContent: string,
|
||||
newVersion: string
|
||||
) {
|
||||
): string | null {
|
||||
const regexes: RegExp[] = [
|
||||
moduleMapVariableVersionFormatMatch(dependency),
|
||||
moduleStringVariableInterpolationVersionFormatMatch(dependency),
|
||||
|
@ -127,7 +127,7 @@ function updateGlobalVariables(
|
|||
dependency: GradleDependency,
|
||||
buildGradleContent: string,
|
||||
newVersion: string
|
||||
) {
|
||||
): string | null {
|
||||
const variable = variables[`${dependency.group}:${dependency.name}`];
|
||||
if (variable) {
|
||||
const regex = variableDefinitionFormatMatch(variable);
|
||||
|
@ -146,7 +146,7 @@ function updatePropertyFileGlobalVariables(
|
|||
dependency: GradleDependency,
|
||||
buildGradleContent: string,
|
||||
newVersion: string
|
||||
) {
|
||||
): string | null {
|
||||
const variable = variables[`${dependency.group}:${dependency.name}`];
|
||||
if (variable) {
|
||||
const regex = new RegExp(`(${variable}\\s*=\\s*)(.*)`);
|
||||
|
@ -159,25 +159,29 @@ function updatePropertyFileGlobalVariables(
|
|||
}
|
||||
|
||||
// https://github.com/patrikerdes/gradle-use-latest-versions-plugin/blob/8cf9c3917b8b04ba41038923cab270d2adda3aa6/src/main/groovy/se/patrikerdes/DependencyUpdate.groovy#L27-L29
|
||||
function moduleStringVersionFormatMatch(dependency: GradleDependency) {
|
||||
function moduleStringVersionFormatMatch(dependency: GradleDependency): RegExp {
|
||||
return new RegExp(
|
||||
`(["']${dependency.group}:${dependency.name}:)[^$].*?(([:@].*?)?["'])`
|
||||
);
|
||||
}
|
||||
|
||||
function groovyPluginStringVersionFormatMatch(dependency: GradleDependency) {
|
||||
function groovyPluginStringVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
): RegExp {
|
||||
return new RegExp(
|
||||
`(id\\s+["']${dependency.group}["']\\s+version\\s+["'])[^$].*?(["'])`
|
||||
);
|
||||
}
|
||||
|
||||
function kotlinPluginStringVersionFormatMatch(dependency: GradleDependency) {
|
||||
function kotlinPluginStringVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
): RegExp {
|
||||
return new RegExp(
|
||||
`(id\\("${dependency.group}"\\)\\s+version\\s+")[^$].*?(")`
|
||||
);
|
||||
}
|
||||
|
||||
function moduleMapVersionFormatMatch(dependency: GradleDependency) {
|
||||
function moduleMapVersionFormatMatch(dependency: GradleDependency): RegExp {
|
||||
// prettier-ignore
|
||||
return new RegExp(
|
||||
`(group\\s*:\\s*["']${dependency.group}["']\\s*,\\s*` +
|
||||
|
@ -188,7 +192,7 @@ function moduleMapVersionFormatMatch(dependency: GradleDependency) {
|
|||
|
||||
function moduleKotlinNamedArgumentVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
) {
|
||||
): RegExp {
|
||||
// prettier-ignore
|
||||
return new RegExp(
|
||||
`(group\\s*=\\s*"${dependency.group}"\\s*,\\s*` +
|
||||
|
@ -197,7 +201,9 @@ function moduleKotlinNamedArgumentVersionFormatMatch(
|
|||
);
|
||||
}
|
||||
|
||||
function moduleMapVariableVersionFormatMatch(dependency: GradleDependency) {
|
||||
function moduleMapVariableVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
): RegExp {
|
||||
// prettier-ignore
|
||||
return new RegExp(
|
||||
`group\\s*:\\s*["']${dependency.group}["']\\s*,\\s*` +
|
||||
|
@ -208,7 +214,7 @@ function moduleMapVariableVersionFormatMatch(dependency: GradleDependency) {
|
|||
|
||||
function moduleKotlinNamedArgumentVariableVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
) {
|
||||
): RegExp {
|
||||
// prettier-ignore
|
||||
return new RegExp(
|
||||
`group\\s*=\\s*"${dependency.group}"\\s*,\\s*` +
|
||||
|
@ -219,7 +225,7 @@ function moduleKotlinNamedArgumentVariableVersionFormatMatch(
|
|||
|
||||
function moduleStringVariableInterpolationVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
) {
|
||||
): RegExp {
|
||||
return new RegExp(
|
||||
`["']${dependency.group}:${dependency.name}:\\$([^{].*?)["']`
|
||||
);
|
||||
|
@ -227,12 +233,12 @@ function moduleStringVariableInterpolationVersionFormatMatch(
|
|||
|
||||
function moduleStringVariableExpressionVersionFormatMatch(
|
||||
dependency: GradleDependency
|
||||
) {
|
||||
): RegExp {
|
||||
return new RegExp(
|
||||
`["']${dependency.group}:${dependency.name}:\\$\{([^{].*?)}["']`
|
||||
);
|
||||
}
|
||||
|
||||
function variableDefinitionFormatMatch(variable: string) {
|
||||
function variableDefinitionFormatMatch(variable: string): RegExp {
|
||||
return new RegExp(`(${variable}\\s*=\\s*?["'])(.*)(["'])`);
|
||||
}
|
||||
|
|
|
@ -67,7 +67,9 @@ gradle.buildFinished {
|
|||
await writeFile(gradleInitFile, content);
|
||||
}
|
||||
|
||||
async function extractDependenciesFromUpdatesReport(localDir: string) {
|
||||
async function extractDependenciesFromUpdatesReport(
|
||||
localDir: string
|
||||
): Promise<BuildDependency[]> {
|
||||
const gradleProjectConfigurations = await readGradleReport(localDir);
|
||||
|
||||
const dependencies = gradleProjectConfigurations
|
||||
|
@ -111,7 +113,7 @@ function mergeDependenciesWithRepositories(
|
|||
function flatternDependencies(
|
||||
accumulator: GradleDependencyWithRepos[],
|
||||
currentValue: GradleDependencyWithRepos[]
|
||||
) {
|
||||
): GradleDependencyWithRepos[] {
|
||||
accumulator.push(...currentValue);
|
||||
return accumulator;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ const TIMEOUT_CODE = 143;
|
|||
export async function extractAllPackageFiles(
|
||||
config: ExtractConfig,
|
||||
packageFiles: string[]
|
||||
): Promise<PackageFile[]> {
|
||||
): Promise<PackageFile[] | null> {
|
||||
if (
|
||||
!packageFiles.some(packageFile =>
|
||||
['build.gradle', 'build.gradle.kts'].includes(packageFile)
|
||||
|
@ -117,7 +117,7 @@ async function executeGradle(config: ExtractConfig) {
|
|||
logger.info('Gradle report complete');
|
||||
}
|
||||
|
||||
async function getGradleCommandLine(config: ExtractConfig) {
|
||||
async function getGradleCommandLine(config: ExtractConfig): Promise<string> {
|
||||
let cmd: string;
|
||||
const gradlewExists = await exists(config.localDir + '/gradlew');
|
||||
if (config.binarySource === 'docker') {
|
||||
|
@ -129,4 +129,5 @@ async function getGradleCommandLine(config: ExtractConfig) {
|
|||
}
|
||||
return cmd + ' ' + GRADLE_DEPENDENCY_REPORT_OPTIONS;
|
||||
}
|
||||
|
||||
export const language = 'java';
|
||||
|
|
|
@ -4,7 +4,7 @@ import { logger } from '../../logger';
|
|||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
// TODO: Maybe check if quotes/double-quotes are balanced
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.trace('extractPackageFile()');
|
||||
/*
|
||||
1. match "class className < Formula"
|
||||
|
@ -57,7 +57,7 @@ export function extractPackageFile(content: string): PackageFile {
|
|||
return { deps };
|
||||
}
|
||||
|
||||
function extractSha256(content: string) {
|
||||
function extractSha256(content: string): string | null {
|
||||
const sha256RegExp = /(^|\s)sha256(\s)/;
|
||||
let i = content.search(sha256RegExp);
|
||||
if (isSpace(content[i])) {
|
||||
|
@ -66,7 +66,7 @@ function extractSha256(content: string) {
|
|||
return parseSha256(i, content);
|
||||
}
|
||||
|
||||
function parseSha256(idx: number, content: string) {
|
||||
function parseSha256(idx: number, content: string): string | null {
|
||||
let i = idx;
|
||||
i += 'sha256'.length;
|
||||
i = skip(i, content, c => {
|
||||
|
@ -84,7 +84,7 @@ function parseSha256(idx: number, content: string) {
|
|||
return sha256;
|
||||
}
|
||||
|
||||
function extractUrl(content: string) {
|
||||
function extractUrl(content: string): string | null {
|
||||
const urlRegExp = /(^|\s)url(\s)/;
|
||||
let i = content.search(urlRegExp);
|
||||
// content.search() returns -1 if not found
|
||||
|
@ -98,7 +98,13 @@ function extractUrl(content: string) {
|
|||
return parseUrl(i, content);
|
||||
}
|
||||
|
||||
export function parseUrlPath(urlStr: string) {
|
||||
export interface UrlPathParsedResult {
|
||||
currentValue: string;
|
||||
ownerName: string;
|
||||
repoName: string;
|
||||
}
|
||||
|
||||
export function parseUrlPath(urlStr: string): UrlPathParsedResult | null {
|
||||
if (!urlStr) {
|
||||
return null;
|
||||
}
|
||||
|
@ -136,7 +142,7 @@ export function parseUrlPath(urlStr: string) {
|
|||
}
|
||||
}
|
||||
|
||||
function parseUrl(idx: number, content: string) {
|
||||
function parseUrl(idx: number, content: string): string | null {
|
||||
let i = idx;
|
||||
i += 'url'.length;
|
||||
i = skip(i, content, c => {
|
||||
|
@ -155,7 +161,7 @@ function parseUrl(idx: number, content: string) {
|
|||
return url;
|
||||
}
|
||||
|
||||
function extractClassName(content: string) {
|
||||
function extractClassName(content: string): string | null {
|
||||
const classRegExp = /(^|\s)class\s/;
|
||||
let i = content.search(classRegExp);
|
||||
if (isSpace(content[i])) {
|
||||
|
@ -166,7 +172,7 @@ function extractClassName(content: string) {
|
|||
|
||||
/* This function parses the "class className < Formula" header
|
||||
and returns the className and index of the character just after the header */
|
||||
function parseClassHeader(idx: number, content: string) {
|
||||
function parseClassHeader(idx: number, content: string): string | null {
|
||||
let i = idx;
|
||||
i += 'class'.length;
|
||||
i = skip(i, content, c => {
|
||||
|
|
|
@ -77,7 +77,11 @@ export async function updateDependency(
|
|||
return newContent;
|
||||
}
|
||||
|
||||
function updateUrl(content: string, oldUrl: string, newUrl: string) {
|
||||
function updateUrl(
|
||||
content: string,
|
||||
oldUrl: string,
|
||||
newUrl: string
|
||||
): string | null {
|
||||
const urlRegExp = /(^|\s)url(\s)/;
|
||||
let i = content.search(urlRegExp);
|
||||
if (i === -1) {
|
||||
|
@ -102,7 +106,11 @@ function updateUrl(content: string, oldUrl: string, newUrl: string) {
|
|||
return newContent;
|
||||
}
|
||||
|
||||
function getUrlTestContent(content: string, oldUrl: string, newUrl: string) {
|
||||
function getUrlTestContent(
|
||||
content: string,
|
||||
oldUrl: string,
|
||||
newUrl: string
|
||||
): string {
|
||||
const urlRegExp = /(^|\s)url(\s)/;
|
||||
const cleanContent = removeComments(content);
|
||||
let j = cleanContent.search(urlRegExp);
|
||||
|
@ -118,7 +126,7 @@ function replaceUrl(
|
|||
content: string,
|
||||
oldUrl: string,
|
||||
newUrl: string
|
||||
) {
|
||||
): string | null {
|
||||
let i = idx;
|
||||
i += 'url'.length;
|
||||
i = skip(i, content, c => isSpace(c));
|
||||
|
@ -132,7 +140,11 @@ function replaceUrl(
|
|||
return newContent;
|
||||
}
|
||||
|
||||
function updateSha256(content: string, oldSha256: string, newSha256: string) {
|
||||
function updateSha256(
|
||||
content: string,
|
||||
oldSha256: string,
|
||||
newSha256: string
|
||||
): string | null {
|
||||
const sha256RegExp = /(^|\s)sha256(\s)/;
|
||||
let i = content.search(sha256RegExp);
|
||||
if (i === -1) {
|
||||
|
@ -161,7 +173,7 @@ function getSha256TestContent(
|
|||
content: string,
|
||||
oldSha256: string,
|
||||
newSha256: string
|
||||
) {
|
||||
): string | null {
|
||||
const sha256RegExp = /(^|\s)sha256(\s)/;
|
||||
const cleanContent = removeComments(content);
|
||||
let j = cleanContent.search(sha256RegExp);
|
||||
|
@ -177,7 +189,7 @@ function replaceSha256(
|
|||
content: string,
|
||||
oldSha256: string,
|
||||
newSha256: string
|
||||
) {
|
||||
): string | null {
|
||||
let i = idx;
|
||||
i += 'sha256'.length;
|
||||
i = skip(i, content, c => isSpace(c));
|
||||
|
|
|
@ -2,7 +2,7 @@ export function skip(
|
|||
idx: number,
|
||||
content: string,
|
||||
cond: (s: string) => boolean
|
||||
) {
|
||||
): number {
|
||||
let i = idx;
|
||||
while (i < content.length) {
|
||||
if (!cond(content[i])) {
|
||||
|
@ -13,18 +13,18 @@ export function skip(
|
|||
return i;
|
||||
}
|
||||
|
||||
export function isSpace(c: string) {
|
||||
export function isSpace(c: string): boolean {
|
||||
return /\s/.test(c);
|
||||
}
|
||||
|
||||
export function removeComments(content: string) {
|
||||
export function removeComments(content: string): string {
|
||||
let newContent = removeLineComments(content);
|
||||
newContent = removeMultiLineComments(newContent);
|
||||
return newContent;
|
||||
}
|
||||
|
||||
// Remove line comments starting with #
|
||||
function removeLineComments(content: string) {
|
||||
function removeLineComments(content: string): string {
|
||||
let newContent = '';
|
||||
let comment = false;
|
||||
for (let i = 0; i < content.length; i += 1) {
|
||||
|
@ -45,7 +45,7 @@ function removeLineComments(content: string) {
|
|||
}
|
||||
|
||||
// Remove multi-line comments enclosed between =begin and =end
|
||||
function removeMultiLineComments(content: string) {
|
||||
function removeMultiLineComments(content: string): string {
|
||||
const beginRegExp = /(^|\n)=begin\s/;
|
||||
const endRegExp = /(^|\n)=end\s/;
|
||||
let newContent = content;
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import {
|
||||
ManagerApi,
|
||||
ExtractConfig,
|
||||
RangeConfig,
|
||||
ManagerApi,
|
||||
PackageFile,
|
||||
PackageUpdateConfig,
|
||||
RangeConfig,
|
||||
Result,
|
||||
PackageUpdateResult,
|
||||
} from './common';
|
||||
import { RangeStrategy } from '../versioning';
|
||||
|
||||
const managerList = [
|
||||
'ansible',
|
||||
|
@ -63,25 +67,25 @@ const languageList = [
|
|||
|
||||
export const get = <T extends keyof ManagerApi>(manager: string, name: T) =>
|
||||
managers[manager][name];
|
||||
export const getLanguageList = () => languageList;
|
||||
export const getManagerList = () => managerList;
|
||||
export const getLanguageList = (): string[] => languageList;
|
||||
export const getManagerList = (): string[] => managerList;
|
||||
|
||||
export function extractAllPackageFiles(
|
||||
manager: string,
|
||||
config: ExtractConfig,
|
||||
files: string[]
|
||||
) {
|
||||
return managers[manager] && get(manager, 'extractAllPackageFiles')
|
||||
? get(manager, 'extractAllPackageFiles')(config, files)
|
||||
): Result<PackageFile[] | null> {
|
||||
return managers[manager] && managers[manager].extractAllPackageFiles
|
||||
? managers[manager].extractAllPackageFiles(config, files)
|
||||
: null;
|
||||
}
|
||||
|
||||
export function getPackageUpdates(
|
||||
manager: string,
|
||||
config: PackageUpdateConfig
|
||||
) {
|
||||
return managers[manager] && get(manager, 'getPackageUpdates')
|
||||
? get(manager, 'getPackageUpdates')(config)
|
||||
): Result<PackageUpdateResult[]> | null {
|
||||
return managers[manager] && managers[manager].getPackageUpdates
|
||||
? managers[manager].getPackageUpdates(config)
|
||||
: null;
|
||||
}
|
||||
|
||||
|
@ -90,13 +94,13 @@ export function extractPackageFile(
|
|||
content: string,
|
||||
fileName?: string,
|
||||
config?: ExtractConfig
|
||||
) {
|
||||
return managers[manager] && get(manager, 'extractPackageFile')
|
||||
? get(manager, 'extractPackageFile')(content, fileName, config)
|
||||
): Result<PackageFile | null> {
|
||||
return managers[manager] && managers[manager].extractPackageFile
|
||||
? managers[manager].extractPackageFile(content, fileName, config)
|
||||
: null;
|
||||
}
|
||||
|
||||
export function getRangeStrategy(config: RangeConfig) {
|
||||
export function getRangeStrategy(config: RangeConfig): RangeStrategy {
|
||||
const { manager, rangeStrategy } = config;
|
||||
if (managers[manager].getRangeStrategy) {
|
||||
// Use manager's own function if it exists
|
||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
|||
import { getDep } from '../dockerfile/extract';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.trace('kubernetes.extractPackageFile()');
|
||||
let deps: PackageDependency[] = [];
|
||||
let lineNumber = 0;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const newFrom = getNewFrom(upgrade);
|
||||
logger.debug(`kubernetes.updateDependency(): ${newFrom}`);
|
||||
|
|
|
@ -3,7 +3,7 @@ import { PackageDependency, PackageFile } from '../common';
|
|||
|
||||
export const DEFAULT_CLOJARS_REPO = 'https://clojars.org/repo/';
|
||||
|
||||
export function trimAtKey(str: string, kwName: string) {
|
||||
export function trimAtKey(str: string, kwName: string): string | null {
|
||||
const regex = new RegExp(`:${kwName}(?=\\s)`);
|
||||
const keyOffset = str.search(regex);
|
||||
if (keyOffset < 0) return null;
|
||||
|
@ -13,7 +13,7 @@ export function trimAtKey(str: string, kwName: string) {
|
|||
return withSpaces.slice(valueOffset);
|
||||
}
|
||||
|
||||
export function expandDepName(name: string) {
|
||||
export function expandDepName(name: string): string {
|
||||
return name.indexOf('/') === -1 ? `${name}:${name}` : name.replace('/', ':');
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ export function extractFromVectors(
|
|||
return result;
|
||||
}
|
||||
|
||||
function extractLeinRepos(content: string) {
|
||||
function extractLeinRepos(content: string): string[] {
|
||||
const result = [DEFAULT_CLOJARS_REPO, DEFAULT_MAVEN_REPO];
|
||||
|
||||
const repoContent = trimAtKey(
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { logger } from '../../logger';
|
||||
import { PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
let deps: PackageDependency[] = [];
|
||||
const npmDepends = content.match(/\nNpm\.depends\({([\s\S]*?)}\);/);
|
||||
if (!npmDepends) {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { logger } from '../../logger';
|
||||
import { Upgrade } from '../common';
|
||||
|
||||
export function updateDependency(fileContent: string, upgrade: Upgrade) {
|
||||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
const { depName, currentValue, newValue } = upgrade;
|
||||
logger.debug(`meteor.updateDependency(): ${depName} = ${newValue}`);
|
||||
const regexReplace = new RegExp(
|
||||
|
|
|
@ -44,7 +44,7 @@ export async function extractPackageFile(
|
|||
content: string,
|
||||
fileName: string,
|
||||
config: ExtractConfig
|
||||
): Promise<PackageFile> {
|
||||
): Promise<PackageFile | null> {
|
||||
logger.trace(`npm.extractPackageFile(${fileName})`);
|
||||
logger.trace({ content });
|
||||
const deps: PackageDependency[] = [];
|
||||
|
|
|
@ -6,7 +6,7 @@ import upath from 'upath';
|
|||
import { logger } from '../../../logger';
|
||||
import { PackageFile } from '../../common';
|
||||
|
||||
function matchesAnyPattern(val: string, patterns: string[]) {
|
||||
function matchesAnyPattern(val: string, patterns: string[]): boolean {
|
||||
const res = patterns.some(
|
||||
pattern => pattern === val + '/' || minimatch(val, pattern, { dot: true })
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { NpmPackage } from './common';
|
||||
|
||||
export function mightBeABrowserLibrary(packageJson: NpmPackage) {
|
||||
export function mightBeABrowserLibrary(packageJson: NpmPackage): boolean {
|
||||
// return true unless we're sure it's not a browser library
|
||||
if (packageJson.private === true) {
|
||||
// it's not published
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
const { depType, depName } = upgrade;
|
||||
let { newValue } = upgrade;
|
||||
if (upgrade.currentRawValue) {
|
||||
|
@ -137,7 +137,7 @@ export function updateDependency(
|
|||
}
|
||||
|
||||
// Return true if the match string is found at index in content
|
||||
function matchAt(content: string, index: number, match: string) {
|
||||
function matchAt(content: string, index: number, match: string): boolean {
|
||||
return content.substring(index, index + match.length) === match;
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ function replaceAt(
|
|||
index: number,
|
||||
oldString: string,
|
||||
newString: string
|
||||
) {
|
||||
): string {
|
||||
logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
|
||||
return (
|
||||
content.substr(0, index) +
|
||||
|
@ -160,7 +160,7 @@ export function bumpPackageVersion(
|
|||
content: string,
|
||||
currentValue: string,
|
||||
bumpVersion: ReleaseType | string
|
||||
) {
|
||||
): string {
|
||||
logger.debug('bumpVersion()');
|
||||
if (!bumpVersion) {
|
||||
return content;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
logger.debug(`nuget.updateDependency(): ${upgrade.newFrom}`);
|
||||
const lines = fileContent.split('\n');
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import { logger } from '../../logger';
|
||||
import { Upgrade } from '../common';
|
||||
|
||||
export function updateDependency(_fileContent: string, upgrade: Upgrade) {
|
||||
export function updateDependency(
|
||||
_fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
logger.debug(`nvm.updateDependency(): ${upgrade.newVersion}`);
|
||||
return `${upgrade.newValue}\n`;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export function extractPackageFile(
|
|||
content: string,
|
||||
_: string,
|
||||
config: ExtractConfig
|
||||
) {
|
||||
): PackageFile | null {
|
||||
logger.trace('pip_requirements.extractPackageFile()');
|
||||
|
||||
let indexUrl: string;
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
logger.debug(`pip_requirements.updateDependency(): ${upgrade.newValue}`);
|
||||
const lines = fileContent.split('\n');
|
||||
|
|
|
@ -6,14 +6,14 @@ import { dependencyPattern } from '../pip_requirements/extract';
|
|||
import { ExtractConfig, PackageFile, PackageDependency } from '../common';
|
||||
|
||||
export const pythonVersions = ['python', 'python3', 'python3.7'];
|
||||
let pythonAlias: string = null;
|
||||
let pythonAlias: string | null = null;
|
||||
|
||||
export function parsePythonVersion(str: string) {
|
||||
export function parsePythonVersion(str: string): number[] {
|
||||
const arr = str.split(' ')[1].split('.');
|
||||
return [parseInt(arr[0], 10), parseInt(arr[1], 10)];
|
||||
}
|
||||
|
||||
export async function getPythonAlias() {
|
||||
export async function getPythonAlias(): Promise<string> {
|
||||
if (pythonAlias) {
|
||||
return pythonAlias;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ export async function extractPackageFile(
|
|||
content: string,
|
||||
packageFile: string,
|
||||
config: ExtractConfig
|
||||
): Promise<PackageFile> {
|
||||
): Promise<PackageFile | null> {
|
||||
logger.debug('pip_setup.extractPackageFile()');
|
||||
let setup: PythonSetup;
|
||||
try {
|
||||
|
|
|
@ -10,7 +10,7 @@ export async function updateArtifacts(
|
|||
_updatedDeps: string[],
|
||||
newPipfileContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
): Promise<UpdateArtifactsResult[]> {
|
||||
): Promise<UpdateArtifactsResult[] | null> {
|
||||
logger.debug(`pipenv.updateArtifacts(${pipfileName})`);
|
||||
process.env.PIPENV_CACHE_DIR =
|
||||
process.env.PIPENV_CACHE_DIR || join(config.cacheDir, './others/pipenv');
|
||||
|
|
|
@ -33,7 +33,7 @@ interface PipRequirement {
|
|||
git?: string;
|
||||
}
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.debug('pipenv.extractPackageFile()');
|
||||
|
||||
let pipfile: PipFile;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { logger } from '../../logger';
|
|||
import { Upgrade } from '../common';
|
||||
|
||||
// Return true if the match string is found at index in content
|
||||
function matchAt(content: string, index: number, match: string) {
|
||||
function matchAt(content: string, index: number, match: string): boolean {
|
||||
return content.substring(index, index + match.length) === match;
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ function replaceAt(
|
|||
index: number,
|
||||
oldString: string,
|
||||
newString: string
|
||||
) {
|
||||
): string {
|
||||
logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
|
||||
return (
|
||||
content.substr(0, index) +
|
||||
|
@ -26,7 +26,7 @@ function replaceAt(
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
const { depType, depName, newValue, managerData = {} } = upgrade;
|
||||
const { nestedVersion } = managerData;
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function updateArtifacts(
|
|||
updatedDeps: string[],
|
||||
newPackageFileContent: string,
|
||||
config: UpdateArtifactsConfig
|
||||
): Promise<UpdateArtifactsResult[]> {
|
||||
): Promise<UpdateArtifactsResult[] | null> {
|
||||
await logger.debug(`poetry.updateArtifacts(${packageFileName})`);
|
||||
if (updatedDeps === undefined || updatedDeps.length < 1) {
|
||||
logger.debug('No updated poetry deps - returning null');
|
||||
|
|
|
@ -7,7 +7,7 @@ import { PoetryFile, PoetrySection } from './types';
|
|||
export function extractPackageFile(
|
||||
content: string,
|
||||
fileName: string
|
||||
): PackageFile {
|
||||
): PackageFile | null {
|
||||
logger.trace(`poetry.extractPackageFile(${fileName})`);
|
||||
let pyprojectfile: PoetryFile;
|
||||
try {
|
||||
|
|
|
@ -6,7 +6,7 @@ import { PoetryFile } from './types';
|
|||
|
||||
// TODO: Maybe factor out common code from pipenv.updateDependency and poetry.updateDependency
|
||||
// Return true if the match string is found at index in content
|
||||
function matchAt(content: string, index: number, match: string) {
|
||||
function matchAt(content: string, index: number, match: string): boolean {
|
||||
return content.substring(index, index + match.length) === match;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ function replaceAt(
|
|||
index: number,
|
||||
oldString: string,
|
||||
newString: string
|
||||
) {
|
||||
): string {
|
||||
logger.debug(`Replacing ${oldString} with ${newString} at index ${index}`);
|
||||
return (
|
||||
content.substr(0, index) +
|
||||
|
@ -28,7 +28,7 @@ function replaceAt(
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade<{ nestedVersion?: boolean }>
|
||||
): string {
|
||||
): string | null {
|
||||
logger.trace({ config: upgrade }, 'poetry.updateDependency()');
|
||||
if (!upgrade) {
|
||||
return null;
|
||||
|
|
|
@ -34,7 +34,7 @@ function getDeps(
|
|||
export function extractPackageFile(
|
||||
content: string,
|
||||
packageFile: string
|
||||
): PackageFile {
|
||||
): PackageFile | null {
|
||||
try {
|
||||
const doc = safeLoad(content);
|
||||
const deps = [
|
||||
|
|
|
@ -52,7 +52,10 @@ interface ParseContext {
|
|||
depType?: string;
|
||||
}
|
||||
|
||||
function parseDepExpr(expr: string, ctx: ParseContext) {
|
||||
function parseDepExpr(
|
||||
expr: string,
|
||||
ctx: ParseContext
|
||||
): PackageDependency | null {
|
||||
const { scalaVersion, fileOffset, variables } = ctx;
|
||||
let { depType } = ctx;
|
||||
|
||||
|
@ -139,7 +142,7 @@ function parseSbtLine(
|
|||
line: string,
|
||||
lineIndex: number,
|
||||
lines: string[]
|
||||
): PackageFile & ParseOptions {
|
||||
): (PackageFile & ParseOptions) | null {
|
||||
const { deps, registryUrls, fileOffset, variables } = acc;
|
||||
|
||||
let { isMultiDeps, scalaVersion } = acc;
|
||||
|
|
|
@ -47,7 +47,7 @@ const searchLabels = {
|
|||
exactVersion: EXACT_VERSION,
|
||||
};
|
||||
|
||||
function searchKeysForState(state) {
|
||||
function searchKeysForState(state): string[] {
|
||||
switch (state) {
|
||||
case 'dependencies':
|
||||
return [SPACE, COLON, WILDCARD];
|
||||
|
@ -94,7 +94,7 @@ interface MatchResult {
|
|||
substr: string;
|
||||
}
|
||||
|
||||
function getMatch(str: string, state: string): MatchResult {
|
||||
function getMatch(str: string, state: string): MatchResult | null {
|
||||
const keys = searchKeysForState(state);
|
||||
let result = null;
|
||||
for (let i = 0; i < keys.length; i += 1) {
|
||||
|
@ -117,7 +117,7 @@ function getMatch(str: string, state: string): MatchResult {
|
|||
return result;
|
||||
}
|
||||
|
||||
function getDepName(url: string) {
|
||||
function getDepName(url: string): string | null {
|
||||
try {
|
||||
const { host, pathname } = new URL(url);
|
||||
if (host === 'github.com' || host === 'gitlab.com') {
|
||||
|
@ -135,7 +135,7 @@ function getDepName(url: string) {
|
|||
export function extractPackageFile(
|
||||
content: string,
|
||||
packageFile: string = null
|
||||
): PackageFile {
|
||||
): PackageFile | null {
|
||||
if (!content) return null;
|
||||
|
||||
const result: PackageFile = {
|
||||
|
|
|
@ -6,7 +6,7 @@ const fromParam = /^\s*from\s*:\s*"([^"]+)"\s*$/;
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
const { currentValue, newValue, fileReplacePosition } = upgrade;
|
||||
const leftPart = fileContent.slice(0, fileReplacePosition);
|
||||
const rightPart = fileContent.slice(fileReplacePosition);
|
||||
|
|
|
@ -2,7 +2,7 @@ import { logger } from '../../logger';
|
|||
import { isValid, isVersion } from '../../versioning/hashicorp';
|
||||
import { PackageDependency, PackageFile } from '../common';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
logger.trace({ content }, 'terraform.extractPackageFile()');
|
||||
if (!content.includes('module "')) {
|
||||
return null;
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Upgrade } from '../common';
|
|||
export function updateDependency(
|
||||
currentFileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
logger.debug(`terraform.updateDependency: ${upgrade.newValue}`);
|
||||
const lines = currentFileContent.split('\n');
|
||||
|
|
|
@ -3,7 +3,7 @@ import yaml from 'js-yaml';
|
|||
import { PackageFile, PackageDependency } from '../common';
|
||||
import { logger } from '../../logger';
|
||||
|
||||
export function extractPackageFile(content: string): PackageFile {
|
||||
export function extractPackageFile(content: string): PackageFile | null {
|
||||
let doc;
|
||||
try {
|
||||
doc = yaml.safeLoad(content);
|
||||
|
|
|
@ -6,7 +6,7 @@ import { logger } from '../../logger';
|
|||
export function updateDependency(
|
||||
fileContent: string,
|
||||
upgrade: Upgrade
|
||||
): string {
|
||||
): string | null {
|
||||
try {
|
||||
logger.debug(`travis.updateDependency(): ${upgrade.newValue}`);
|
||||
const indent = detectIndent(fileContent).indent || ' ';
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`lib/manager/node/package getPackageUpdates detects pinning 1`] = `
|
||||
exports[`lib/manager/travis/package getPackageUpdates detects pinning 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"isRange": true,
|
||||
|
@ -14,7 +14,7 @@ Array [
|
|||
]
|
||||
`;
|
||||
|
||||
exports[`lib/manager/node/package getPackageUpdates returns result if needing updates 1`] = `
|
||||
exports[`lib/manager/travis/package getPackageUpdates returns result if needing updates 1`] = `
|
||||
Array [
|
||||
Object {
|
||||
"isRange": true,
|
||||
|
|
|
@ -7,7 +7,7 @@ const getPkgReleases: any = _getPkgReleases;
|
|||
|
||||
jest.mock('../../../lib/datasource/github');
|
||||
|
||||
describe('lib/manager/node/package', () => {
|
||||
describe('lib/manager/travis/package', () => {
|
||||
describe('getPackageUpdates', () => {
|
||||
// TODO: should be `PackageUpdateConfig`
|
||||
let config: any;
|
||||
|
|
Loading…
Reference in a new issue