fix(ngc): Revert "fix(ngc): add an option to produce TS1.9-pathMapping imports (#10602)" (#10765)

This reverts commit beadf6167a.
This commit is contained in:
Alex Eagle
2016-08-12 17:38:29 -07:00
committed by vikerman
parent a235ae16ed
commit 9317056138
6 changed files with 80 additions and 127 deletions

View File

@ -17,8 +17,6 @@ export interface Directory { [name: string]: Entry; }
export class MockContext implements ReflectorHostContext {
constructor(public currentDirectory: string, private files: Entry) {}
trace(s: string) { console.log(s); }
fileExists(fileName: string): boolean { return typeof this.getEntry(fileName) === 'string'; }
directoryExists(path: string): boolean { return typeof this.getEntry(path) === 'object'; }

View File

@ -20,8 +20,6 @@ describe('reflector_host', () => {
var reflectorNestedGenDir: ReflectorHost;
var reflectorSiblingGenDir: ReflectorHost;
const DEBUG = false;
beforeEach(() => {
context = new MockContext('/tmp/src', clone(FILES));
host = new MockCompilerHost(context);
@ -37,9 +35,8 @@ describe('reflector_host', () => {
}
reflectorNestedGenDir = new ReflectorHost(
program, host, {
// Intentional trailing slash, check for regression of #10533
genDir: '/tmp/src/gen/',
basePath: '/tmp/src',
genDir: '/tmp/project/src/gen/',
basePath: '/tmp/project/src',
skipMetadataEmit: false,
skipTemplateCodegen: false,
trace: false
@ -47,97 +44,77 @@ describe('reflector_host', () => {
context);
reflectorSiblingGenDir = new ReflectorHost(
program, host, {
genDir: '/tmp/gen',
// Intentional trailing slash, check for regression of #10533
basePath: '/tmp/src/',
genDir: '/tmp/project/gen',
basePath: '/tmp/project/src/',
skipMetadataEmit: false,
skipTemplateCodegen: false,
trace: false
},
context);
});
describe('path mapping', () => {
it('should use rootDirs for calculating relative imports', () => {
const reflectorHost = new ReflectorHost(
program, host, {
genDir: '/tmp/gen',
basePath: '/tmp/src/',
skipMetadataEmit: false,
skipTemplateCodegen: false,
trace: false,
traceResolution: DEBUG,
rootDirs: ['/tmp/src/', '/tmp/genfiles/'],
writeImportsForRootDirs: true,
},
context);
expect(reflectorHost.getImportPath(
'/tmp/src/pathmapping/bootstrap.ts', '/tmp/genfiles/pathmapping/comp.d.ts'))
.toEqual('./comp');
});
});
describe('nested genDir', () => {
describe('nestedGenDir', () => {
it('should import node_module from factory', () => {
expect(reflectorNestedGenDir.getImportPath(
'/tmp/src/gen/my.ngfactory.ts', '/tmp/src/node_modules/@angular/core.d.ts'))
'/tmp/project/src/gen/my.ngfactory.ts',
'/tmp/project/node_modules/@angular/core.d.ts'))
.toEqual('@angular/core');
});
it('should import factory from factory', () => {
expect(reflectorNestedGenDir.getImportPath(
'/tmp/src/my.ngfactory.ts', '/tmp/src/my.other.ngfactory.ts'))
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/my.other.ngfactory.ts'))
.toEqual('./my.other.ngfactory');
expect(reflectorNestedGenDir.getImportPath(
'/tmp/src/a/my.ngfactory.ts', '/tmp/src/my.other.css.ts'))
'/tmp/project/src/a/my.ngfactory.ts', '/tmp/project/src/my.other.css.ts'))
.toEqual('../my.other.css');
expect(reflectorNestedGenDir.getImportPath(
'/tmp/src/my.ngfactory.ts', '/tmp/src/a/my.other.css.shim.ts'))
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/a/my.other.css.shim.ts'))
.toEqual('./a/my.other.css.shim');
});
it('should import application from factory', () => {
expect(
reflectorNestedGenDir.getImportPath('/tmp/src/my.ngfactory.ts', '/tmp/src/my.other.ts'))
expect(reflectorNestedGenDir.getImportPath(
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/my.other.ts'))
.toEqual('../my.other');
expect(
reflectorNestedGenDir.getImportPath('/tmp/src/a/my.ngfactory.ts', '/tmp/src/my.other.ts'))
expect(reflectorNestedGenDir.getImportPath(
'/tmp/project/src/a/my.ngfactory.ts', '/tmp/project/src/my.other.ts'))
.toEqual('../../my.other');
expect(
reflectorNestedGenDir.getImportPath('/tmp/src/my.ngfactory.ts', '/tmp/src/a/my.other.ts'))
expect(reflectorNestedGenDir.getImportPath(
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/a/my.other.ts'))
.toEqual('../a/my.other');
});
});
describe('sibling genDir', () => {
describe('nestedGenDir', () => {
it('should import node_module from factory', () => {
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/src/gen/my.ngfactory.ts', '/tmp/src/node_modules/@angular/core.d.ts'))
'/tmp/project/src/gen/my.ngfactory.ts',
'/tmp/project/node_modules/@angular/core.d.ts'))
.toEqual('@angular/core');
});
it('should import factory from factory', () => {
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/src/my.ngfactory.ts', '/tmp/src/my.other.ngfactory.ts'))
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/my.other.ngfactory.ts'))
.toEqual('./my.other.ngfactory');
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/src/a/my.ngfactory.ts', '/tmp/src/my.other.css.ts'))
'/tmp/project/src/a/my.ngfactory.ts', '/tmp/project/src/my.other.css.ts'))
.toEqual('../my.other.css');
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/src/my.ngfactory.ts', '/tmp/src/a/my.other.css.shim.ts'))
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/a/my.other.css.shim.ts'))
.toEqual('./a/my.other.css.shim');
});
it('should import application from factory', () => {
expect(
reflectorSiblingGenDir.getImportPath('/tmp/src/my.ngfactory.ts', '/tmp/src/my.other.ts'))
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/my.other.ts'))
.toEqual('./my.other');
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/src/a/my.ngfactory.ts', '/tmp/src/my.other.ts'))
'/tmp/project/src/a/my.ngfactory.ts', '/tmp/project/src/my.other.ts'))
.toEqual('../my.other');
expect(reflectorSiblingGenDir.getImportPath(
'/tmp/src/my.ngfactory.ts', '/tmp/src/a/my.other.ts'))
'/tmp/project/src/my.ngfactory.ts', '/tmp/project/src/a/my.other.ts'))
.toEqual('./a/my.other');
});
});
@ -154,7 +131,7 @@ describe('reflector_host', () => {
it('should be able to produce an import from main @angular/core', () => {
expect(reflectorNestedGenDir.getImportPath(
'/tmp/src/main.ts', '/tmp/src/node_modules/@angular/core.d.ts'))
'/tmp/project/src/main.ts', '/tmp/project/node_modules/@angular/core.d.ts'))
.toEqual('@angular/core');
});
@ -322,11 +299,6 @@ const FILES: Entry = {
})
}
},
'pathmapping': {'bootstrap.ts': `import {a} from './comp.d.ts';`},
'a': {
'my.other.css.shim.ts': dummyModule,
},
'my.other.ts': dummyModule,
'node_modules': {
'@angular': {
'core.d.ts': dummyModule,
@ -338,13 +310,6 @@ const FILES: Entry = {
'empty.metadata.json': '[]',
}
}
},
'genfiles': {
'pathmapping': {
'comp.d.ts': `
export declare let a: string;
`
}
}
}
};