Skip to content
Snippets Groups Projects
Unverified Commit 05a11782 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

refactor(deps-edn): use autoReplace (#5910)

parent b34018b7
No related branches found
No related tags found
No related merge requests found
...@@ -7,84 +7,72 @@ Object { ...@@ -7,84 +7,72 @@ Object {
"currentValue": "0.1.2", "currentValue": "0.1.2",
"datasource": "clojure", "datasource": "clojure",
"depName": "persistent-sorted-set:persistent-sorted-set", "depName": "persistent-sorted-set:persistent-sorted-set",
"fileReplacePosition": 53,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "1.9.0", "currentValue": "1.9.0",
"datasource": "clojure", "datasource": "clojure",
"depName": "org.clojure:clojure", "depName": "org.clojure:clojure",
"fileReplacePosition": 147,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "1.10.0", "currentValue": "1.10.0",
"datasource": "clojure", "datasource": "clojure",
"depName": "org.clojure:clojure", "depName": "org.clojure:clojure",
"fileReplacePosition": 241,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "1.10.520", "currentValue": "1.10.520",
"datasource": "clojure", "datasource": "clojure",
"depName": "org.clojure:clojurescript", "depName": "org.clojure:clojurescript",
"fileReplacePosition": 389,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.2.11", "currentValue": "0.2.11",
"datasource": "clojure", "datasource": "clojure",
"depName": "org.clojure:tools.namespace", "depName": "org.clojure:tools.namespace",
"fileReplacePosition": 451,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "1.10.520", "currentValue": "1.10.520",
"datasource": "clojure", "datasource": "clojure",
"depName": "org.clojure:clojurescript", "depName": "org.clojure:clojurescript",
"fileReplacePosition": 584,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.0-389", "currentValue": "0.0-389",
"datasource": "clojure", "datasource": "clojure",
"depName": "lambdaisland:kaocha", "depName": "lambdaisland:kaocha",
"fileReplacePosition": 644,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.0-21", "currentValue": "0.0-21",
"datasource": "clojure", "datasource": "clojure",
"depName": "lambdaisland:kaocha-cljs", "depName": "lambdaisland:kaocha-cljs",
"fileReplacePosition": 703,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.21.1", "currentValue": "0.21.1",
"datasource": "clojure", "datasource": "clojure",
"depName": "cider:cider-nrepl", "depName": "cider:cider-nrepl",
"fileReplacePosition": 810,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.6.0", "currentValue": "0.6.0",
"datasource": "clojure", "datasource": "clojure",
"depName": "nrepl:nrepl", "depName": "nrepl:nrepl",
"fileReplacePosition": 870,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.2.11", "currentValue": "0.2.11",
"datasource": "clojure", "datasource": "clojure",
"depName": "org.clojure:tools.namespace", "depName": "org.clojure:tools.namespace",
"fileReplacePosition": 929,
"registryUrls": Array [], "registryUrls": Array [],
}, },
Object { Object {
"currentValue": "0.9.5703", "currentValue": "0.9.5703",
"datasource": "clojure", "datasource": "clojure",
"depName": "com.datomic:datomic-free", "depName": "com.datomic:datomic-free",
"fileReplacePosition": 1141,
"registryUrls": Array [], "registryUrls": Array [],
}, },
], ],
......
...@@ -11,9 +11,6 @@ export function extractPackageFile(content: string): PackageFile { ...@@ -11,9 +11,6 @@ export function extractPackageFile(content: string): PackageFile {
let offset = 0; let offset = 0;
while (match) { while (match) {
const [wholeSubstr, depName, currentValue] = match; const [wholeSubstr, depName, currentValue] = match;
const fileReplacePosition =
offset + match.index + wholeSubstr.indexOf(currentValue);
offset += match.index + wholeSubstr.length; offset += match.index + wholeSubstr.length;
rest = content.slice(offset); rest = content.slice(offset);
match = regex.exec(rest); match = regex.exec(rest);
...@@ -22,7 +19,6 @@ export function extractPackageFile(content: string): PackageFile { ...@@ -22,7 +19,6 @@ export function extractPackageFile(content: string): PackageFile {
datasource: datasourceClojure.id, datasource: datasourceClojure.id,
depName: expandDepName(depName), depName: expandDepName(depName),
currentValue, currentValue,
fileReplacePosition,
registryUrls: [], registryUrls: [],
}); });
} }
......
import * as mavenVersioning from '../../versioning/maven'; import * as mavenVersioning from '../../versioning/maven';
import { extractPackageFile } from './extract'; import { extractPackageFile } from './extract';
import { updateDependency } from './update';
export { extractPackageFile, updateDependency }; export { extractPackageFile };
export const autoReplace = true;
export const defaultConfig = { export const defaultConfig = {
fileMatch: ['(^|/)deps\\.edn$'], fileMatch: ['(^|/)deps\\.edn$'],
......
/* eslint-disable no-template-curly-in-string */
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { extractPackageFile } from './extract';
import { updateDependency } from './update';
const depsEdn = readFileSync(
resolve(__dirname, `./__fixtures__/deps.edn`),
'utf8'
);
describe('manager/deps-edn/update', () => {
it('updateDependency', () => {
const { deps } = extractPackageFile(depsEdn);
const dep = deps.pop();
const upgrade = {
...dep,
newValue: `${dep.currentValue}-9999`,
};
const { currentValue, newValue } = upgrade;
const newFileContent = updateDependency({ fileContent: depsEdn, upgrade });
const cmpContent = depsEdn.replace(currentValue, newValue);
expect(newFileContent).toEqual(cmpContent);
});
});
import { UpdateDependencyConfig } from '../common';
import { updateAtPosition } from '../maven/update';
export function updateDependency({
fileContent,
upgrade,
}: UpdateDependencyConfig): string | null {
return updateAtPosition(fileContent, upgrade);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment