Skip to content

Commit

Permalink
correction sub-component path in windows when import to ngModule #1719
Browse files Browse the repository at this point in the history
…#1736 (#1961)

* #1719 #1736

* #1719
Add a unit test

* fix tslint error
  • Loading branch information
chgc authored and hansl committed Sep 19, 2016
1 parent c935039 commit f6fa1a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/ast-tools/src/route-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ describe('route utils', () => {
expect(newContent).toEqual(`import { Router } from '@angular/router';\n`);
});
});
it('inserts subcomponent in win32 environment', () => {
let content = './level1\\level2/level2.component';
return nru.insertImport(sourceFile, 'level2', content).apply()
.then(() => readFile(sourceFile, 'utf8'))
.then(newContent => {
if (process.platform.startsWith('win')) {
expect(newContent).toEqual(
`import { level2 } from './level1/level2/level2.component';\n`);
} else {
expect(newContent).toEqual(
`import { level2 } from './level1\\level2/level2.component';\n`);

This comment has been minimized.

Copy link
@Meligy

Meligy Sep 29, 2016

Contributor

This is an invalid import statement, even on Windows, at least VS Code with TypeScript 2 told me so.
The \\ piece in level1\\level2 should be /.

}
});
});
});

describe('bootstrapItem', () => {
Expand Down Expand Up @@ -124,7 +138,7 @@ describe('route utils', () => {
.then(content => {
expect(content).toEqual(
`import routes from './routes';
import { provideRouter } from '@angular/router';
import { provideRouter } from '@angular/router';
bootstrap(AppComponent, [ provideRouter(routes) ]);`);
});
});
Expand Down Expand Up @@ -299,7 +313,7 @@ export default [
children: [
{ path: 'about', component: AboutComponent,
children: [
{ path: 'details', component: DetailsComponent },
{ path: 'details', component: DetailsComponent },
{ path: 'more', component: MoreComponent }
]
}
Expand Down Expand Up @@ -327,7 +341,7 @@ export default [
children: [
{ path: 'more', component: MoreComponent,
children: [
{ path: 'sections', component: SectionsComponent }
{ path: 'sections', component: SectionsComponent }
]
}
]
Expand Down Expand Up @@ -359,7 +373,7 @@ export default [
{ path: 'main', component: MainComponent }
{ path: 'home', component: HomeComponent,
children: [
{ path: 'about/:id', component: AboutComponent_1 },
{ path: 'about/:id', component: AboutComponent_1 },
{ path: 'about', component: AboutComponent }
]
}
Expand Down Expand Up @@ -447,7 +461,7 @@ export default [
export default [
{ path: 'home', component: HomeComponent,
children: [
{ path: 'trap-queen', component: TrapQueenComponent },
{ path: 'trap-queen', component: TrapQueenComponent },
{ path: 'about', component: AboutComponent,
children: [
{ path: 'more', component: MoreComponent }
Expand Down Expand Up @@ -478,7 +492,7 @@ import { HomeComponent as HomeComponent_1 } from './app/home/home/home.component
export default [
{ path: 'home', component: HomeComponent,
children: [
{ path: 'home', component: HomeComponent_1 }
{ path: 'home', component: HomeComponent_1 }
]
}
];`;
Expand All @@ -487,7 +501,7 @@ export default [
});
it('throws error if components collide and there is repitition', () => {
let editedFile = new InsertChange(routesFile, 16,
`\n { path: 'about', component: AboutComponent,
`\n { path: 'about', component: AboutComponent,
children: [
{ path: 'details/:id', component: DetailsComponent_1 },
{ path: 'details', component: DetailsComponent }
Expand Down Expand Up @@ -543,7 +557,7 @@ import { DetailsComponent as DetailsComponent_1 } from './app/about/description/
export default [
{ path: 'home', component: HomeComponent,
children: [
{ path: 'more', component: MoreComponent, canDeactivate: [ MyGuard ], useAsDefault: true }
{ path: 'more', component: MoreComponent, canDeactivate: [ MyGuard ], useAsDefault: true }
]
}
];`
Expand Down
3 changes: 3 additions & 0 deletions packages/ast-tools/src/route-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export function bootstrapItem(

export function insertImport(fileToEdit: string, symbolName: string,
fileName: string, isDefault = false): Change {
if (process.platform.startsWith('win')) {
fileName = fileName.replace(/\\/g, '/'); // correction in windows
}
let rootNode = getRootNode(fileToEdit);
let allImports = findNodes(rootNode, ts.SyntaxKind.ImportDeclaration);

Expand Down

0 comments on commit f6fa1a5

Please sign in to comment.