Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .codefresh/codefresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ steps:
- yarn bazel test //tools/ts-api-guardian:all //packages/language-service/test
- yarn test-ivy-aot //packages/animations/test //packages/common/test //packages/forms/test //packages/http/test //packages/platform-browser/test //packages/platform-browser-dynamic/test //packages/router/test
- yarn bazel test //tools/public_api_guard/...
- yarn bazel test //packages/compiler-cli/ngcc/test:test
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ModuleResolver {
*/
private resolveAsEntryPoint(moduleName: string, fromPath: AbsoluteFsPath): ResolvedModule|null {
let folder = fromPath;
while (folder !== '/') {
while (!isRoot(folder)) {
folder = AbsoluteFsPath.dirname(folder);
if (folder.endsWith('node_modules')) {
// Skip up if the folder already ends in node_modules
Expand Down Expand Up @@ -225,7 +225,7 @@ export class ModuleResolver {
*/
private findPackagePath(path: AbsoluteFsPath): AbsoluteFsPath|null {
let folder = path;
while (folder !== '/') {
while (!isRoot(folder)) {
folder = AbsoluteFsPath.dirname(folder);
if (this.fs.exists(AbsoluteFsPath.join(folder, 'package.json'))) {
return folder;
Expand Down Expand Up @@ -267,6 +267,10 @@ function splitOnStar(str: string): PathMappingPattern {
return {prefix, postfix: postfix || '', hasWildcard: postfix !== undefined};
}

function isRoot(path: AbsoluteFsPath): boolean {
return AbsoluteFsPath.dirname(path) === path;
}

interface ProcessedPathMapping {
baseUrl: AbsoluteFsPath;
matcher: PathMappingPattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class NgccCompilerHost implements ts.CompilerHost {
}

getDefaultLibLocation(): string {
const nodeLibPath = AbsoluteFsPath.fromUnchecked(require.resolve('typescript'));
const nodeLibPath = AbsoluteFsPath.from(require.resolve('typescript'));
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved
return AbsoluteFsPath.join(nodeLibPath, '..');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('DependencyHost', () => {
expect(dependencies.size).toBe(0);
expect(missing.size).toBe(0);
expect(deepImports.size).toBe(1);
expect(deepImports.has('/node_modules/lib-1/deep/import')).toBe(true);
expect(deepImports.has(_('/node_modules/lib-1/deep/import'))).toBe(true);
});

it('should recurse into internal dependencies', () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/compiler-cli/ngcc/test/helpers/mock_file_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {FileStats, FileSystem} from '../../src/file_system/file_system';
export class MockFileSystem implements FileSystem {
files: Folder = {};
constructor(...folders: Folder[]) {
folders.forEach(files => this.processFiles(this.files, files));
folders.forEach(files => this.processFiles(this.files, files, true));
}

exists(path: AbsoluteFsPath): boolean { return this.findFromPath(path) !== null; }
Expand Down Expand Up @@ -67,7 +67,7 @@ export class MockFileSystem implements FileSystem {
return new MockFileStats(fileOrFolder);
}

pwd(): AbsoluteFsPath { return AbsoluteFsPath.fromUnchecked('/'); }
pwd(): AbsoluteFsPath { return AbsoluteFsPath.from('/'); }
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved

copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void {
this.writeFile(to, this.readFile(from));
Expand All @@ -82,9 +82,10 @@ export class MockFileSystem implements FileSystem {

ensureDir(path: AbsoluteFsPath): void { this.ensureFolders(this.files, path.split('/')); }

private processFiles(current: Folder, files: Folder): void {
private processFiles(current: Folder, files: Folder, isRootPath = false): void {
Object.keys(files).forEach(path => {
const segments = path.split('/');
const pathResolved = isRootPath ? AbsoluteFsPath.from(path) : path;
const segments = pathResolved.split('/');
const lastSegment = segments.pop() !;
const containingFolder = this.ensureFolders(current, segments);
const entity = files[path];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {getEntryPointInfo} from '../../src/packages/entry_point';
import {MockFileSystem} from '../helpers/mock_file_system';
import {MockLogger} from '../helpers/mock_logger';

const _ = AbsoluteFsPath.fromUnchecked;
const _ = AbsoluteFsPath.from;

describe('getEntryPointInfo()', () => {
const SOME_PACKAGE = _('/some_package');
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/ngcc/test/rendering/renderer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ describe('Renderer', () => {
decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses,
moduleWithProvidersAnalyses);
const addDefinitionsSpy = renderer.addDefinitions as jasmine.Spy;
expect(addDefinitionsSpy.calls.first().args[2])
expect(addDefinitionsSpy.calls.first().args[2].replace(/\r\n/g, '\n'))
.toEqual(
`A.ngComponentDef = ɵngcc0.ɵɵdefineComponent({ type: A, selectors: [["a"]], factory: function A_Factory(t) { return new (t || A)(); }, consts: 1, vars: 1, template: function A_Template(rf, ctx) { if (rf & 1) {
ɵngcc0.ɵɵtext(0);
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('Renderer', () => {
name: _('A'),
decorators: [jasmine.objectContaining({name: _('Directive')})]
}));
expect(addDefinitionsSpy.calls.first().args[2])
expect(addDefinitionsSpy.calls.first().args[2].replace(/\r\n/g, '\n'))
.toEqual(
`A.ngDirectiveDef = ɵngcc0.ɵɵdefineDirective({ type: A, selectors: [["", "a", ""]], factory: function A_Factory(t) { return new (t || A)(); } });
/*@__PURE__*/ ɵngcc0.ɵsetClassMetadata(A, [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {EntryPointBundle} from '../../src/packages/entry_point_bundle';
import {InPlaceFileWriter} from '../../src/writing/in_place_file_writer';
import {MockFileSystem} from '../helpers/mock_file_system';

const _ = AbsoluteFsPath.fromUnchecked;
const _ = AbsoluteFsPath.from;

function createMockFileSystem() {
return new MockFileSystem({
Expand Down Expand Up @@ -71,13 +71,14 @@ describe('InPlaceFileWriter', () => {
it('should error if the backup file already exists', () => {
const fs = createMockFileSystem();
const fileWriter = new InPlaceFileWriter(fs);
const absoluteBackupPath = _('/package/path/already-backed-up.js');
expect(
() => fileWriter.writeBundle(
{} as EntryPoint, {} as EntryPointBundle,
[
{path: _('/package/path/already-backed-up.js'), contents: 'MODIFIED BACKED UP'},
{path: absoluteBackupPath, contents: 'MODIFIED BACKED UP'},
]))
.toThrowError(
'Tried to overwrite /package/path/already-backed-up.js.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.');
`Tried to overwrite ${absoluteBackupPath}.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.`);
});
});
6 changes: 6 additions & 0 deletions packages/compiler-cli/src/ngtsc/path/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export const AbsoluteFsPath = {
* Convert the path `str` to an `AbsoluteFsPath`, throwing an error if it's not an absolute path.
*/
from: function(str: string): AbsoluteFsPath {
if (str.startsWith('/') && process.platform === 'win32') {
// in Windows if it's absolute path and starts with `/` we shall
// resolve it and return it including the drive.
str = path.resolve(str);
}

const normalized = normalizeSeparators(str);
if (!isAbsolutePath(normalized)) {
Comment thread
petebacondarwin marked this conversation as resolved.
Resolved
throw new Error(`Internal Error: AbsoluteFsPath.from(${str}): path is not absolute`);
Expand Down