This repository was archived by the owner on Aug 7, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 40
fix(angular): support angular lazy routes in preview #753
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
80fee54
feat: transform the main angular module in order to include the lazy …
DimitarTachev c15e737
fix pr comments
sis0k0 73411d8
refactor: remove blank lines
sis0k0 4238daf
fix: move a typescript specific logic in ast utils in order to avoid …
DimitarTachev f7641dc
fix: normalize the app module paths in order to avoid incorrect compa…
DimitarTachev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
import { tags } from "@angular-devkit/core"; | ||
import { createTypescriptContext, transformTypescript } from "@ngtools/webpack/src/transformers"; | ||
import { nsReplaceLazyLoader, NgLazyLoaderCode, getConfigObjectSetupCode } from "./ns-replace-lazy-loader"; | ||
import { AngularCompilerPlugin } from "@ngtools/webpack"; | ||
|
||
describe("@ngtools/webpack transformers", () => { | ||
describe("ns-replace-lazy-loader", () => { | ||
const configObjectName = "testIdentifier"; | ||
const configObjectSetupCode = getConfigObjectSetupCode(configObjectName, "providers", "NgModuleFactoryLoader", "{ provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }"); | ||
const testCases = [ | ||
{ | ||
name: "should add providers and NgModuleFactoryLoader when providers is missing", | ||
rawAppModule: ` | ||
import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
|
||
@NgModule({ | ||
bootstrap: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
NativeScriptModule | ||
], | ||
declarations: [ | ||
AppComponent, | ||
] | ||
}) | ||
export class AppModule { } | ||
`, | ||
transformedAppModule: ` | ||
import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
${NgLazyLoaderCode} | ||
let AppModule = class AppModule { }; | ||
AppModule = tslib_1.__decorate([ NgModule({ | ||
bootstrap: [ AppComponent ], | ||
imports: [ NativeScriptModule ], | ||
declarations: [ AppComponent, ], | ||
providers: [{ provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }] }) | ||
], | ||
AppModule); | ||
export { AppModule };` | ||
}, | ||
{ | ||
name: "should add NgModuleFactoryLoader when the providers array is empty", | ||
rawAppModule: ` | ||
import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
|
||
@NgModule({ | ||
bootstrap: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
NativeScriptModule | ||
], | ||
declarations: [ | ||
AppComponent, | ||
], | ||
providers: [] | ||
}) | ||
export class AppModule { } | ||
`, | ||
transformedAppModule: ` | ||
import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
${NgLazyLoaderCode} | ||
let AppModule = class AppModule { }; | ||
AppModule = tslib_1.__decorate([ NgModule({ | ||
bootstrap: [ AppComponent ], | ||
imports: [ NativeScriptModule ], | ||
declarations: [ AppComponent, ], | ||
providers: [{ provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }] }) | ||
], | ||
AppModule); | ||
export { AppModule };` | ||
}, | ||
{ | ||
name: "should add NgModuleFactoryLoader at the end when the providers array is containing other providers", | ||
rawAppModule: ` | ||
import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
@NgModule({ | ||
bootstrap: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
NativeScriptModule | ||
], | ||
declarations: [ | ||
AppComponent, | ||
], | ||
providers: [MyCoolProvider] | ||
}) | ||
export class AppModule { } | ||
`, | ||
transformedAppModule: ` | ||
import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
${NgLazyLoaderCode} | ||
let AppModule = class AppModule { }; | ||
AppModule = tslib_1.__decorate([ NgModule({ | ||
bootstrap: [ AppComponent ], | ||
imports: [ NativeScriptModule ], | ||
declarations: [ AppComponent, ], | ||
providers: [MyCoolProvider, { provide: nsNgCoreImport_Generated.NgModuleFactoryLoader, useClass: NSLazyModulesLoader_Generated }] }) | ||
], | ||
AppModule); | ||
export { AppModule };` | ||
}, | ||
{ | ||
name: "should NOT add NgModuleFactoryLoader when it's already defined", | ||
rawAppModule: ` | ||
import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
|
||
@NgModule({ | ||
bootstrap: [ | ||
AppComponent | ||
], | ||
imports: [ | ||
NativeScriptModule | ||
], | ||
declarations: [ | ||
AppComponent, | ||
], | ||
providers: [{ provide: NgModuleFactoryLoader, useClass: CustomLoader }] | ||
}) | ||
export class AppModule { } | ||
`, | ||
transformedAppModule: ` | ||
import * as tslib_1 from "tslib"; import { NgModule } from "@angular/core"; | ||
import { NativeScriptModule } from "nativescript-angular/nativescript.module"; | ||
import { AppComponent } from "./app.component"; | ||
let AppModule = class AppModule { }; | ||
AppModule = tslib_1.__decorate([ NgModule({ | ||
bootstrap: [ AppComponent ], | ||
imports: [ NativeScriptModule ], | ||
declarations: [ AppComponent, ], | ||
providers: [{ provide: NgModuleFactoryLoader, useClass: CustomLoader }] }) | ||
], | ||
AppModule); | ||
export { AppModule };` | ||
}, | ||
{ | ||
name: "should setup the object when an object is passed to the NgModule", | ||
rawAppModule: ` | ||
import { NgModule } from "@angular/core"; | ||
import { ${configObjectName} } from "somewhere"; | ||
|
||
@NgModule(${configObjectName}) | ||
export class AppModule { } | ||
`, | ||
transformedAppModule: ` | ||
import * as tslib_1 from "tslib"; | ||
import { NgModule } from "@angular/core"; | ||
import { ${configObjectName} } from "somewhere"; | ||
|
||
${NgLazyLoaderCode} | ||
${configObjectSetupCode} | ||
let AppModule = class AppModule { }; | ||
AppModule = tslib_1.__decorate([ NgModule(${configObjectName}) ], AppModule); | ||
|
||
export { AppModule }; | ||
` | ||
}, | ||
{ | ||
name: "should setup the object after its initialization when a local object is passed to the NgModule", | ||
rawAppModule: ` | ||
import { NgModule } from "@angular/core"; | ||
const ${configObjectName} = { | ||
bootstrap: [ | ||
AppComponent | ||
], | ||
declarations: [ | ||
AppComponent | ||
] | ||
}; | ||
|
||
@NgModule(${configObjectName}) | ||
export class AppModule { } | ||
`, | ||
transformedAppModule: ` | ||
import * as tslib_1 from "tslib"; | ||
import { NgModule } from "@angular/core"; | ||
${NgLazyLoaderCode} | ||
const ${configObjectName} = { | ||
bootstrap: [ | ||
AppComponent | ||
], | ||
declarations: [ | ||
AppComponent | ||
] | ||
}; | ||
${configObjectSetupCode} | ||
let AppModule = class AppModule { }; | ||
AppModule = tslib_1.__decorate([ NgModule(${configObjectName}) ], AppModule); | ||
export { AppModule }; | ||
` | ||
} | ||
]; | ||
testCases.forEach((testCase: any) => { | ||
it(`${testCase.name}`, async () => { | ||
const input = tags.stripIndent`${testCase.rawAppModule}`; | ||
const output = tags.stripIndent`${testCase.transformedAppModule}`; | ||
const { program, compilerHost } = createTypescriptContext(input); | ||
const ngCompiler = <AngularCompilerPlugin>{ | ||
typeChecker: program.getTypeChecker(), | ||
entryModule: { | ||
path: "/project/src/test-file", | ||
className: "AppModule", | ||
}, | ||
}; | ||
const transformer = nsReplaceLazyLoader(() => ngCompiler); | ||
const result = transformTypescript(undefined, [transformer], program, compilerHost); | ||
|
||
expect(tags.oneLine`${result}`).toEqual(tags.oneLine`${output}`); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.