Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: slug string conflict with scope #6115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
});
});
});