Skip to content

Commit

Permalink
fix(core): allow npmScope to be single @
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Apr 3, 2023
1 parent 9b60863 commit 30ab78e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/nx/src/utils/path.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { normalizePath, joinPathFragments } from './path';
import { getImportPath, joinPathFragments, normalizePath } from './path';

describe('normalizePath', () => {
it('should remove drive letters', () => {
Expand All @@ -21,3 +21,17 @@ describe('joinPathFragments', () => {
);
});
});

describe('getImportPath', () => {
it('should use the npmScope if it is set to anything other than @', () => {
expect(getImportPath('myorg', 'my-package')).toEqual('@myorg/my-package');
});

it('should allow for a single @ to be used as the npmScope', () => {
expect(getImportPath('@', 'my-package')).toEqual('@/my-package');
});

it('should just use the package name if npmScope is empty', () => {
expect(getImportPath('', 'my-package')).toEqual('my-package');
});
});
4 changes: 3 additions & 1 deletion packages/nx/src/utils/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export function getImportPath(
npmScope: string,
projectDirectory: string
): string {
return npmScope ? `@${npmScope}/${projectDirectory}` : projectDirectory;
return npmScope
? `${npmScope === '@' ? '' : '@'}${npmScope}/${projectDirectory}`
: projectDirectory;
}

0 comments on commit 30ab78e

Please sign in to comment.