Skip to content

Commit

Permalink
fix: slug string conflict with scope
Browse files Browse the repository at this point in the history
  • Loading branch information
xsbchen committed Feb 2, 2024
1 parent 943a9f0 commit 86c1e37
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
Expand Up @@ -765,7 +765,7 @@ describe(`Commands`, () => {
await run(`install`);

await run(`pack`, `--out`, `%s.tgz`);
expect(xfs.existsSync(`${path}/@scope-test.tgz`)).toEqual(true);
expect(xfs.existsSync(`${path}/@scope_test.tgz`)).toEqual(true);
}),
);

Expand All @@ -791,7 +791,7 @@ describe(`Commands`, () => {
await run(`install`);

await run(`pack`, `--out`, `%s-%v.tgz`);
expect(xfs.existsSync(`${path}/@scope-test-0.0.1.tgz`)).toEqual(true);
expect(xfs.existsSync(`${path}/@scope_test-0.0.1.tgz`)).toEqual(true);
}),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/yarnpkg-core/sources/structUtils.ts
Expand Up @@ -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;
}
Expand Down
23 changes: 23 additions & 0 deletions packages/yarnpkg-core/tests/structUtils.test.ts
@@ -0,0 +1,23 @@
import * as structUtils from '../sources/structUtils';

describe(`structUtils`, () => {
describe(`makeIdent`, () => {
it(`should return a unique slug string with scope`, () => {
const slugA = structUtils.slugifyIdent(structUtils.makeIdent(`myscope`, `user-email`));
expect(slugA).toEqual(`@myscope_user-email`);
const slugB = structUtils.slugifyIdent(structUtils.makeIdent(`myscope-user`, `email`));
expect(slugB).toEqual(`@myscope-user_email`);
expect(slugA).not.toEqual(slugB);
});
});

describe(`slugifyIdent`, () => {
it(`should return a unique slug string with scope`, () => {
const slugA = structUtils.slugifyIdent(structUtils.makeIdent(`myscope`, `user-email`));
expect(slugA).toEqual(`@myscope_user-email`);
const slugB = structUtils.slugifyIdent(structUtils.makeIdent(`myscope-user`, `email`));
expect(slugB).toEqual(`@myscope-user_email`);
expect(slugA).not.toEqual(slugB);
});
});
});

0 comments on commit 86c1e37

Please sign in to comment.