diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index d8ad4635bd..febce716c5 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -339,6 +339,7 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs): # Summaries are only enabled if Angular outputs are to be produced. "enableSummariesForJit": is_legacy_ngc, "enableIvy": is_ivy_enabled(ctx), + "compilationMode": ctx.attr.compilation_mode, "fullTemplateTypeCheck": ctx.attr.type_check, # In Google3 we still want to use the symbol factory re-exports in order to # not break existing apps inside Google. Unlike Bazel, Google3 does not only @@ -725,6 +726,14 @@ NG_MODULE_ATTRIBUTES = { "filter_summaries": attr.bool(default = False), "type_check": attr.bool(default = True), "inline_resources": attr.bool(default = True), + "compilation_mode": attr.string( + doc = """Set the compilation mode for the Angular compiler. + + This attribute is a noop if Ivy is not enabled. + """, + values = ["partial", "full", ""], + default = "", + ), "no_i18n": attr.bool(default = False), "compiler": attr.label( doc = """Sets a different ngc compiler binary to use for this library. diff --git a/packages/bazel/test/ngc-wrapped/ivy_enabled/BUILD.bazel b/packages/bazel/test/ngc-wrapped/ivy_enabled/BUILD.bazel new file mode 100644 index 0000000000..93f9263fe0 --- /dev/null +++ b/packages/bazel/test/ngc-wrapped/ivy_enabled/BUILD.bazel @@ -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"], +) diff --git a/packages/bazel/test/ngc-wrapped/ivy_enabled/ng_module_ivy_test.ts b/packages/bazel/test/ngc-wrapped/ivy_enabled/ng_module_ivy_test.ts new file mode 100644 index 0000000000..9e64b1e628 --- /dev/null +++ b/packages/bazel/test/ngc-wrapped/ivy_enabled/ng_module_ivy_test.ts @@ -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 = /*@__PURE__*/ 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 = /*@__PURE__*/ 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(`); + }); + }); +}); diff --git a/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_default_compilation.ts b/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_default_compilation.ts new file mode 100644 index 0000000000..8fb7607675 --- /dev/null +++ b/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_default_compilation.ts @@ -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 { +} diff --git a/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_full_compilation.ts b/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_full_compilation.ts new file mode 100644 index 0000000000..8fb7607675 --- /dev/null +++ b/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_full_compilation.ts @@ -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 { +} diff --git a/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_partial_compilation.ts b/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_partial_compilation.ts new file mode 100644 index 0000000000..8fb7607675 --- /dev/null +++ b/packages/bazel/test/ngc-wrapped/ivy_enabled/test_module_partial_compilation.ts @@ -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 { +}