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 30b3cc6
Show file tree
Hide file tree
Showing 3 changed files with 16 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
13 changes: 13 additions & 0 deletions 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`});

Check failure on line 6 in packages/yarnpkg-core/tests/structUtils.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Argument of type '{ scope: string; name: string; }' is not assignable to parameter of type 'Ident'.
expect(slugA).toEqual(`@myscope_user-email`);
const slugB = structUtils.slugifyIdent({scope: `myscope-user`, name: `email`});

Check failure on line 8 in packages/yarnpkg-core/tests/structUtils.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Argument of type '{ scope: string; name: string; }' is not assignable to parameter of type 'Ident'.
expect(slugB).toEqual(`@myscope-user_email`);
expect(slugA).not.toEqual(slugB);
});
});
});

0 comments on commit 30b3cc6

Please sign in to comment.