diff --git a/lib/manager/swift/__snapshots__/index.spec.ts.snap b/lib/manager/swift/__snapshots__/index.spec.ts.snap index f29363555b9a04d511d044140adf2b8886613863..0929928316b6b69c2dace3a36cde8b43c5b98e66 100644 --- a/lib/manager/swift/__snapshots__/index.spec.ts.snap +++ b/lib/manager/swift/__snapshots__/index.spec.ts.snap @@ -8,21 +8,18 @@ Object { ", "datasource": "git-tags", "depName": "0x7fs/CountedSet", - "fileReplacePosition": 939, "lookupName": "https://github.com/0x7fs/CountedSet", }, Object { "currentValue": "0.1.0", "datasource": "git-tags", "depName": "avito-tech/GraphiteClient", - "fileReplacePosition": 1177, "lookupName": "https://github.com/avito-tech/GraphiteClient.git", }, Object { "currentValue": "1.0.16", "datasource": "git-tags", "depName": "IBM-Swift/BlueSignals", - "fileReplacePosition": 1268, "lookupName": "https://github.com/IBM-Swift/BlueSignals.git", }, Object { @@ -30,28 +27,24 @@ Object { ", "datasource": "git-tags", "depName": "beefon/Shout", - "fileReplacePosition": 1345, "lookupName": "https://github.com/beefon/Shout", }, Object { "currentValue": "3.0.6", "datasource": "git-tags", "depName": "daltoniam/Starscream", - "fileReplacePosition": 1439, "lookupName": "https://github.com/daltoniam/Starscream.git", }, Object { "currentValue": "1.4.6", "datasource": "git-tags", "depName": "httpswift/swifter", - "fileReplacePosition": 1523, "lookupName": "https://github.com/httpswift/swifter.git", }, Object { "currentValue": "from : \\"0.9.6\\"", "datasource": "git-tags", "depName": "weichsel/ZIPFoundation", - "fileReplacePosition": 1626, "lookupName": "https://github.com/weichsel/ZIPFoundation/", }, Object { @@ -59,7 +52,6 @@ Object { ", "datasource": "git-tags", "depName": "apple/swift-package-manager", - "fileReplacePosition": 1726, "lookupName": "https://github.com/apple/swift-package-manager.git", }, ], @@ -74,7 +66,6 @@ Object { "currentValue": "from:\\"1.2.3\\"", "datasource": "git-tags", "depName": "vapor/vapor", - "fileReplacePosition": 64, "lookupName": "https://github.com/vapor/vapor.git", }, ], @@ -89,7 +80,6 @@ Object { "currentValue": "\\"1.2.3\\"...", "datasource": "git-tags", "depName": "vapor/vapor", - "fileReplacePosition": 64, "lookupName": "https://github.com/vapor/vapor.git", }, ], @@ -104,7 +94,6 @@ Object { "currentValue": "\\"1.2.3\\"...\\"1.2.4\\"", "datasource": "git-tags", "depName": "vapor/vapor", - "fileReplacePosition": 64, "lookupName": "https://github.com/vapor/vapor.git", }, ], @@ -119,7 +108,6 @@ Object { "currentValue": "\\"1.2.3\\"..<\\"1.2.4\\"", "datasource": "git-tags", "depName": "vapor/vapor", - "fileReplacePosition": 64, "lookupName": "https://github.com/vapor/vapor.git", }, ], @@ -134,7 +122,6 @@ Object { "currentValue": "...\\"1.2.3\\"", "datasource": "git-tags", "depName": "vapor/vapor", - "fileReplacePosition": 64, "lookupName": "https://github.com/vapor/vapor.git", }, ], @@ -149,7 +136,6 @@ Object { "currentValue": "..<\\"1.2.3\\"", "datasource": "git-tags", "depName": "vapor/vapor", - "fileReplacePosition": 64, "lookupName": "https://github.com/vapor/vapor.git", }, ], diff --git a/lib/manager/swift/extract.ts b/lib/manager/swift/extract.ts index 525cad71fc37ad47a4f96d5805813cb9605a5a97..1569ee0a5c1030c65b0f366a100600792bec4287 100644 --- a/lib/manager/swift/extract.ts +++ b/lib/manager/swift/extract.ts @@ -146,36 +146,31 @@ export function extractPackageFile( }; const deps: PackageDependency[] = []; - let offset = 0; let restStr = content; let state: string = null; let match = getMatch(restStr, state); let lookupName: string = null; let currentValue: string = null; - let fileReplacePosition: number = null; function yieldDep(): void { const depName = getDepName(lookupName); - if (depName && currentValue && fileReplacePosition) { + if (depName && currentValue) { const dep: PackageDependency = { datasource: datasourceGitTags.id, depName, lookupName, currentValue, - fileReplacePosition, }; deps.push(dep); } lookupName = null; currentValue = null; - fileReplacePosition = null; } while (match) { const { idx, len, label, substr } = match; - offset += idx; // eslint-disable-next-line default-case switch (state) { case null: @@ -258,15 +253,12 @@ export function extractPackageFile( yieldDep(); state = null; } else if (label === FROM) { - fileReplacePosition = offset; currentValue = substr; state = '.package(url: [depName], from'; } else if (label === STRING_LITERAL) { - fileReplacePosition = offset; currentValue = substr; state = '.package(url: [depName], [value]'; } else if (label === RANGE_OP) { - fileReplacePosition = offset; currentValue = substr; state = '.package(url: [depName], [rangeFrom][rangeOp]'; } else if (label === EXACT_VERSION) { @@ -282,7 +274,6 @@ export function extractPackageFile( state = null; } else if (label === STRING_LITERAL) { currentValue = substr.slice(1, substr.length - 1); - fileReplacePosition = offset; yieldDep(); } else if (label === PACKAGE) { yieldDep(); @@ -347,7 +338,6 @@ export function extractPackageFile( } break; } - offset += len; restStr = restStr.slice(idx + len); match = getMatch(restStr, state); } diff --git a/lib/manager/swift/index.spec.ts b/lib/manager/swift/index.spec.ts index 41ee9e93ebce5f2b99b7f43d00e589bbd33fe9ff..c82e5f7af5125b5b3d6e7635cbdf9132e5f477af 100644 --- a/lib/manager/swift/index.spec.ts +++ b/lib/manager/swift/index.spec.ts @@ -1,7 +1,6 @@ import { readFileSync } from 'fs'; import { resolve } from 'path'; import { extractPackageFile } from './extract'; -import { updateDependency } from './update'; const pkgContent = readFileSync( resolve(__dirname, `./__fixtures__/SamplePackage.swift`), @@ -137,75 +136,4 @@ describe('lib/manager/swift', () => { expect(extractPackageFile(pkgContent)).toMatchSnapshot(); }); }); - describe('updateDependency()', () => { - it('updates successfully', () => { - [ - [ - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git",.exact("1.2.3")]', - '1.2.4', - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git",.exact("1.2.4")]', - ], - [ - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", from: "1.2.3")]', - '1.2.4', - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", from: "1.2.4")]', - ], - [ - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", "1.2.3"..."1.2.4")]', - '"1.2.3"..."1.2.5"', - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", "1.2.3"..."1.2.5")]', - ], - [ - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", "1.2.3"..<"1.2.4")]', - '"1.2.3"..<"1.2.5"', - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", "1.2.3"..<"1.2.5")]', - ], - [ - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", ..."1.2.4")]', - '..."1.2.5"', - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", ..."1.2.5")]', - ], - [ - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", ..<"1.2.4")]', - '..<"1.2.5"', - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git", ..<"1.2.5")]', - ], - ].forEach(([content, newValue, result]) => { - const { deps } = extractPackageFile(content); - const [dep] = deps; - const upgrade = { ...dep, newValue }; - const updated = updateDependency({ - fileContent: content, - upgrade, - }); - expect(updated).toEqual(result); - }); - }); - it('returns content if already updated', () => { - const content = - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git",.exact("1.2.3")]'; - const currentValue = '1.2.3'; - const newValue = '1.2.4'; - const { deps } = extractPackageFile(content); - const [dep] = deps; - const upgrade = { ...dep, newValue }; - const replaced = content.replace(currentValue, newValue); - const updated = updateDependency({ - fileContent: replaced, - upgrade, - }); - expect(updated).toBe(replaced); - }); - it('returns null if content is different', () => { - const content = - 'dependencies:[.package(url:"https://github.com/vapor/vapor.git",.exact("1.2.3")]'; - const currentValue = '1.2.3'; - const newValue = '1.2.4'; - const { deps } = extractPackageFile(content); - const [dep] = deps; - const upgrade = { ...dep, newValue }; - const replaced = content.replace(currentValue, '1.2.5'); - expect(updateDependency({ fileContent: replaced, upgrade })).toBe(null); - }); - }); }); diff --git a/lib/manager/swift/index.ts b/lib/manager/swift/index.ts index 3ed2e6a32c843fe0ad559dd352be8e587b4982a0..b94f2f434b286d28272d18e29a9e61b800ff7ad4 100644 --- a/lib/manager/swift/index.ts +++ b/lib/manager/swift/index.ts @@ -1,7 +1,8 @@ import * as swiftVersioning from '../../versioning/swift'; export { extractPackageFile } from './extract'; -export { updateDependency } from './update'; + +export const autoReplace = true; export const defaultConfig = { fileMatch: ['(^|/)Package\\.swift'], diff --git a/lib/manager/swift/update.ts b/lib/manager/swift/update.ts deleted file mode 100644 index 6700cec41c72166a433e7d97173a13f5d9a4254a..0000000000000000000000000000000000000000 --- a/lib/manager/swift/update.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { isVersion } from '../../versioning/swift'; -import { UpdateDependencyConfig } from '../common'; - -const fromParam = /^\s*from\s*:\s*"([^"]+)"\s*$/; - -export function updateDependency({ - fileContent, - upgrade, -}: UpdateDependencyConfig): string | null { - const { currentValue, newValue, fileReplacePosition } = upgrade; - const leftPart = fileContent.slice(0, fileReplacePosition); - const rightPart = fileContent.slice(fileReplacePosition); - const oldVal = isVersion(currentValue) ? `"${currentValue}"` : currentValue; - let newVal; - if (fromParam.test(oldVal)) { - const [, version] = fromParam.exec(oldVal); - newVal = oldVal.replace(version, newValue); - } else if (isVersion(newValue)) { - newVal = `"${newValue}"`; - } else { - newVal = newValue; - } - if (rightPart.startsWith(oldVal)) { - return leftPart + rightPart.replace(oldVal, newVal); - } - if (rightPart.startsWith(newVal)) { - return fileContent; - } - return null; -} diff --git a/lib/versioning/swift/index.spec.ts b/lib/versioning/swift/index.spec.ts index 3c5b9f069405b1a88f6b8b2397bf9f3acbabe9f7..7ccd7dc03df4d38f8b0253b03349d4e232ab87b5 100644 --- a/lib/versioning/swift/index.spec.ts +++ b/lib/versioning/swift/index.spec.ts @@ -4,6 +4,7 @@ import { RangeStrategy } from '..'; const { getNewValue, isValid, + isVersion, minSatisfyingVersion, maxSatisfyingVersion, isLessThanRange, @@ -11,6 +12,10 @@ const { } = swift; describe('isValid(input)', () => { + it('supports isVersion', () => { + expect(isVersion('from: "1.2.3"')).toBe(false); + expect(isVersion('1.2.3')).toBe(true); + }); it('understands Swift version ranges', () => { expect(isValid('from: "1.2.3"')).toBe(true); expect(isValid('from : "1.2.3"')).toBe(true);