From 93597723ce497effb78a692b0adff4484455897f Mon Sep 17 00:00:00 2001 From: Rhys Arkins <rhys@arkins.net> Date: Tue, 21 Dec 2021 18:58:51 +0100 Subject: [PATCH] fix: better yarn.lock regex --- .../yarn-lock/__fixtures__/2.yarn.lock | 9 +++++++ .../yarn-lock/replace.spec.ts | 24 +++++++++++++++++++ .../locked-dependency/yarn-lock/replace.ts | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/manager/npm/update/locked-dependency/yarn-lock/__fixtures__/2.yarn.lock b/lib/manager/npm/update/locked-dependency/yarn-lock/__fixtures__/2.yarn.lock index 2e1e684e51..fed53634f0 100644 --- a/lib/manager/npm/update/locked-dependency/yarn-lock/__fixtures__/2.yarn.lock +++ b/lib/manager/npm/update/locked-dependency/yarn-lock/__fixtures__/2.yarn.lock @@ -15,6 +15,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +"@embroider/addon-shim@^0.48.0": + version "0.48.0" + resolved "https://registry.yarnpkg.com/@embroider/addon-shim/-/addon-shim-0.48.0.tgz#2a950ecb82c45ae53e801bcddfd26dc420cac9e8" + integrity sha512-hu2Yzv5xXHl1vCzkcybjyjCK2/fHwKPDJ5xpwRlvASU/8WMBVLekQQ9Tt8WhPMZJHdMkzIWchAPGkLZaKaeXmA== + dependencies: + "@embroider/shared-internals" "^0.48.0" + ember-auto-import "^2.2.0" + semver "^7.3.5" + "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" diff --git a/lib/manager/npm/update/locked-dependency/yarn-lock/replace.spec.ts b/lib/manager/npm/update/locked-dependency/yarn-lock/replace.spec.ts index cfb56dd242..1163c3f689 100644 --- a/lib/manager/npm/update/locked-dependency/yarn-lock/replace.spec.ts +++ b/lib/manager/npm/update/locked-dependency/yarn-lock/replace.spec.ts @@ -117,5 +117,29 @@ describe('manager/npm/update/locked-dependency/yarn-lock/replace', () => { " `); }); + it('handles quoted', () => { + const res = replaceConstraintVersion( + yarnLock2, + '@embroider/addon-shim', + '^0.48.0', + '0.48.1' + ); + expect(res).not.toEqual(yarnLock2); + const diffRes = Diff.diffLines(yarnLock2, res); + const addedSections = diffRes.filter((item) => item.added); + const removedSections = diffRes.filter((item) => item.removed); + expect(addedSections).toHaveLength(1); + expect(removedSections).toHaveLength(1); + expect(addedSections[0].value).toMatchInlineSnapshot(` + " version: \\"0.48.1\\" + " + `); + expect(removedSections[0].value).toMatchInlineSnapshot(` + " version \\"0.48.0\\" + resolved \\"https://registry.yarnpkg.com/@embroider/addon-shim/-/addon-shim-0.48.0.tgz#2a950ecb82c45ae53e801bcddfd26dc420cac9e8\\" + integrity sha512-hu2Yzv5xXHl1vCzkcybjyjCK2/fHwKPDJ5xpwRlvASU/8WMBVLekQQ9Tt8WhPMZJHdMkzIWchAPGkLZaKaeXmA== + " + `); + }); }); }); diff --git a/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts b/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts index 7e09f3c835..dc7b0b5b5d 100644 --- a/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts +++ b/lib/manager/npm/update/locked-dependency/yarn-lock/replace.ts @@ -14,7 +14,7 @@ export function replaceConstraintVersion( } const depNameConstraint = `${depName}@${constraint}`; const escaped = depNameConstraint.replace(/(@|\^|\.|\\)/g, '\\$1'); - const matchString = `(${escaped}((",|,)[^\n:]+)?:\n)(.*\n)*?(\\s+dependencies|\n[@a-z])`; + const matchString = `(${escaped}(("|",|,)[^\n:]*)?:\n)(.*\n)*?(\\s+dependencies|\n[@a-z])`; // yarn will fill in the details later const matchResult = regEx(matchString).exec(lockFileContent); // istanbul ignore if -- GitLab