Skip to content

Commit

Permalink
fix(core): fix resolving projects for imports to '.' (#3839)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Oct 9, 2020
1 parent 6377cef commit 8c85bf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/workspace/src/utils/fileutils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fs, vol } from 'memfs';
import { stripIndents } from '@angular-devkit/core/src/utils/literals';
import { createDirectory } from './fileutils';
import { createDirectory, isRelativePath } from './fileutils';

jest.mock('fs', () => require('memfs').fs);
jest.mock('./app-root', () => ({ appRootPath: '/root' }));
Expand Down Expand Up @@ -35,4 +35,18 @@ describe('fileutils', () => {
expect(fs.statSync('/root/b/c').isDirectory()).toBe(true);
});
});

describe('isRelativePath()', () => {
it('should return true for deeper imports', () => {
expect(isRelativePath('.')).toEqual(true);
expect(isRelativePath('./file')).toEqual(true);
});
it('should return true for upper imports', () => {
expect(isRelativePath('../file')).toEqual(true);
});
it('should return false for absolute imports', () => {
expect(isRelativePath('file')).toEqual(false);
expect(isRelativePath('@nrwl/angular')).toEqual(false);
});
});
});
2 changes: 1 addition & 1 deletion packages/workspace/src/utils/fileutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ export function renameSync(
}

export function isRelativePath(path: string): boolean {
return path.startsWith('./') || path.startsWith('../');
return path === '.' || path.startsWith('./') || path.startsWith('../');
}

0 comments on commit 8c85bf9

Please sign in to comment.