Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
) Adds a new attribute to the `ng_module` rule that allows users to set the Angular compiler `compilationMode` flag. An alternative would have been to just enable the option in the user-specified tsconfig. Though that is more inconvenient if a Bazel workspace wants to change the compilation mode conditionally at anaylsis phase through build settings. Related to: https://github.com/angular/components/pull/22351t PR Close #41418
- Loading branch information
1 parent
aa36121
commit e6da38a
Showing
6 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,45 @@ | ||
load("//tools:defaults.bzl", "jasmine_node_test", "ng_module", "ts_library") | ||
|
||
ts_library( | ||
name = "ng_module_ivy_test_lib", | ||
testonly = True, | ||
srcs = ["ng_module_ivy_test.ts"], | ||
tags = ["ivy-only"], | ||
) | ||
|
||
# `ng_module` with `compilation_mode` explicitly set to `partial`. | ||
ng_module( | ||
name = "test_module_partial_compilation", | ||
srcs = ["test_module_partial_compilation.ts"], | ||
compilation_mode = "partial", | ||
tags = ["ivy-only"], | ||
deps = ["//packages/core"], | ||
) | ||
|
||
# `ng_module` with `compilation_mode` explicitly set to `full`. | ||
ng_module( | ||
name = "test_module_full_compilation", | ||
srcs = ["test_module_full_compilation.ts"], | ||
compilation_mode = "full", | ||
tags = ["ivy-only"], | ||
deps = ["//packages/core"], | ||
) | ||
|
||
# `ng_module` with no specific `compilation_mode` attribute specified. | ||
ng_module( | ||
name = "test_module_default_compilation", | ||
srcs = ["test_module_default_compilation.ts"], | ||
tags = ["ivy-only"], | ||
deps = ["//packages/core"], | ||
) | ||
|
||
jasmine_node_test( | ||
name = "ng_module_ivy_test", | ||
srcs = [":ng_module_ivy_test_lib"], | ||
data = [ | ||
":test_module_default_compilation", | ||
":test_module_full_compilation", | ||
":test_module_partial_compilation", | ||
], | ||
tags = ["ivy-only"], | ||
) |
41 changes: 41 additions & 0 deletions
41
packages/bazel/test/ngc-wrapped/ivy_enabled/ng_module_ivy_test.ts
This file contains 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,41 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {readFileSync} from 'fs'; | ||
|
||
/** Runfiles helper from bazel to resolve file name paths. */ | ||
const runfiles = require(process.env['BAZEL_NODE_RUNFILES_HELPER']!); | ||
|
||
describe('ng_module with ivy enabled', () => { | ||
describe('default compilation mode', () => { | ||
it('should generate definitions', () => { | ||
const outputFile = runfiles.resolveWorkspaceRelative( | ||
'packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_default_compilation.js'); | ||
const fileContent = readFileSync(outputFile, 'utf8'); | ||
expect(fileContent).toContain(`TestComponent.ɵcmp = i0.ɵɵdefineComponent(`); | ||
}); | ||
}); | ||
|
||
describe('full compilation mode', () => { | ||
it('should generate definitions', () => { | ||
const outputFile = runfiles.resolveWorkspaceRelative( | ||
'packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_full_compilation.js'); | ||
const fileContent = readFileSync(outputFile, 'utf8'); | ||
expect(fileContent).toContain(`TestComponent.ɵcmp = i0.ɵɵdefineComponent(`); | ||
}); | ||
}); | ||
|
||
describe('partial compilation mode', () => { | ||
it('should generate declarations', () => { | ||
const outputFile = runfiles.resolveWorkspaceRelative( | ||
'packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_partial_compilation.js'); | ||
const fileContent = readFileSync(outputFile, 'utf8'); | ||
expect(fileContent).toContain(`TestComponent.ɵcmp = i0.ɵɵngDeclareComponent(`); | ||
}); | ||
}); | ||
}); |
15 changes: 15 additions & 0 deletions
15
packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_default_compilation.ts
This file contains 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,15 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
template: 'Hello', | ||
}) | ||
export class TestComponent { | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_full_compilation.ts
This file contains 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,15 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
template: 'Hello', | ||
}) | ||
export class TestComponent { | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_partial_compilation.ts
This file contains 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,15 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
template: 'Hello', | ||
}) | ||
export class TestComponent { | ||
} |