From 2028879cce61938b5b33a377e0151394fa9d47e3 Mon Sep 17 00:00:00 2001 From: xsbchen Date: Fri, 2 Feb 2024 12:48:07 +0800 Subject: [PATCH] fix: slug string conflict with scope --- packages/yarnpkg-core/sources/structUtils.ts | 2 +- packages/yarnpkg-core/tests/structUtils.test.ts | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/yarnpkg-core/tests/structUtils.test.ts diff --git a/packages/yarnpkg-core/sources/structUtils.ts b/packages/yarnpkg-core/sources/structUtils.ts index b47708ebed8a..62316eea9bf1 100644 --- a/packages/yarnpkg-core/sources/structUtils.ts +++ b/packages/yarnpkg-core/sources/structUtils.ts @@ -665,7 +665,7 @@ export function stringifyLocator(locator: Locator) { */ export function slugifyIdent(ident: Ident) { if (ident.scope !== null) { - return `@${ident.scope}-${ident.name}`; + return `@${ident.scope}_${ident.name}`; } else { return ident.name; } diff --git a/packages/yarnpkg-core/tests/structUtils.test.ts b/packages/yarnpkg-core/tests/structUtils.test.ts new file mode 100644 index 000000000000..f0e33f2247cd --- /dev/null +++ b/packages/yarnpkg-core/tests/structUtils.test.ts @@ -0,0 +1,13 @@ +import * as structUtils from '../sources/structUtils'; + +describe(`structUtils`, () => { + describe(`slugifyIdent`, () => { + it(`should return a unique slug string with scope`, () => { + const slugA = structUtils.slugifyIdent({scope: `myscope`, name: `user-email`}); + expect(slugA).toEqual(`@myscope_user-email`); + const slugB = structUtils.slugifyIdent({scope: `myscope-user`, name: `email`}); + expect(slugB).toEqual(`@myscope-user_email`); + expect(slugA).not.toEqual(slugB); + }); + }); +});