angular-cn/packages/compiler-cli/BUILD.bazel

84 lines
2.3 KiB
Python
Raw Normal View History

package(default_visibility = ["//visibility:public"])
load("//tools:defaults.bzl", "pkg_npm", "ts_api_guardian_test", "ts_library")
load("@npm_bazel_typescript//:index.bzl", "ts_config")
ts_config(
name = "tsconfig",
src = "tsconfig-build.json",
deps = ["//packages:tsconfig-build.json"],
)
ts_library(
name = "compiler-cli",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
exclude = [
"src/integrationtest/**/*.ts",
],
),
tsconfig = ":tsconfig",
deps = [
"//packages/compiler",
refactor(ivy): introduce the 'core' package and split apart NgtscProgram (#34887) Previously, NgtscProgram lived in the main @angular/compiler-cli package alongside the legacy View Engine compiler. As a result, the main package depended on all of the ngtsc internal packages, and a significant portion of ngtsc logic lived in NgtscProgram. This commit refactors NgtscProgram and moves the main logic of compilation into a new 'core' package. The new package defines a new API which enables implementers of TypeScript compilers (compilers built using the TS API) to support Angular transpilation as well. It involves a new NgCompiler type which takes a ts.Program and performs Angular analysis and transformations, as well as an NgCompilerHost which wraps an input ts.CompilerHost and adds any extra Angular files. Together, these two classes are used to implement a new NgtscProgram which adapts the legacy api.Program interface used by the View Engine compiler onto operations on the new types. The new NgtscProgram implementation is significantly smaller and easier to reason about. The new NgCompilerHost replaces the previous GeneratedShimsHostWrapper which lived in the 'shims' package. A new 'resource' package is added to support the HostResourceLoader which previously lived in the outer compiler package. As a result of the refactoring, the dependencies of the outer @angular/compiler-cli package on ngtsc internal packages are significantly trimmed. This refactoring was driven by the desire to build a plugin interface to the compiler so that tsc_wrapped (another consumer of the TS compiler APIs) can perform Angular transpilation on user request. PR Close #34887
2020-01-17 19:00:07 -05:00
"//packages/compiler-cli/src/ngtsc/core",
"//packages/compiler-cli/src/ngtsc/core:api",
"//packages/compiler-cli/src/ngtsc/diagnostics",
refactor(ivy): implement a virtual file-system layer in ngtsc + ngcc (#30921) To improve cross platform support, all file access (and path manipulation) is now done through a well known interface (`FileSystem`). For testing a number of `MockFileSystem` implementations are provided. These provide an in-memory file-system which emulates operating systems like OS/X, Unix and Windows. The current file system is always available via the static method, `FileSystem.getFileSystem()`. This is also used by a number of static methods on `AbsoluteFsPath` and `PathSegment`, to avoid having to pass `FileSystem` objects around all the time. The result of this is that one must be careful to ensure that the file-system has been initialized before using any of these static methods. To prevent this happening accidentally the current file system always starts out as an instance of `InvalidFileSystem`, which will throw an error if any of its methods are called. You can set the current file-system by calling `FileSystem.setFileSystem()`. During testing you can call the helper function `initMockFileSystem(os)` which takes a string name of the OS to emulate, and will also monkey-patch aspects of the TypeScript library to ensure that TS is also using the current file-system. Finally there is the `NgtscCompilerHost` to be used for any TypeScript compilation, which uses a given file-system. All tests that interact with the file-system should be tested against each of the mock file-systems. A series of helpers have been provided to support such tests: * `runInEachFileSystem()` - wrap your tests in this helper to run all the wrapped tests in each of the mock file-systems. * `addTestFilesToFileSystem()` - use this to add files and their contents to the mock file system for testing. * `loadTestFilesFromDisk()` - use this to load a mirror image of files on disk into the in-memory mock file-system. * `loadFakeCore()` - use this to load a fake version of `@angular/core` into the mock file-system. All ngcc and ngtsc source and tests now use this virtual file-system setup. PR Close #30921
2019-06-06 15:22:32 -04:00
"//packages/compiler-cli/src/ngtsc/file_system",
"//packages/compiler-cli/src/ngtsc/indexer",
"//packages/compiler-cli/src/ngtsc/perf",
fix(compiler-cli): downlevel angular decorators to static properties (#37382) In v7 of Angular we removed `tsickle` from the default `ngc` pipeline. This had the negative potential of breaking ES2015 output and SSR due to a limitation in TypeScript. TypeScript by default preserves type information for decorated constructor parameters when `emitDecoratorMetadata` is enabled. For example, consider this snippet below: ``` @Directive() export class MyDirective { constructor(button: MyButton) {} } export class MyButton {} ``` TypeScript would generate metadata for the `MyDirective` class it has a decorator applied. This metadata would be needed in JIT mode, or for libraries that provide `MyDirective` through NPM. The metadata would look as followed: ``` let MyDirective = class MyDir {} MyDirective = __decorate([ Directive(), __metadata("design:paramtypes", [MyButton]), ], MyDirective); let MyButton = class MyButton {} ``` Notice that TypeScript generated calls to `__decorate` and `__metadata`. These calls are needed so that the Angular compiler is able to determine whether `MyDirective` is actually an directive, and what types are needed for dependency injection. The limitation surfaces in this concrete example because `MyButton` is declared after the `__metadata(..)` call, while `__metadata` actually directly references `MyButton`. This is illegal though because `MyButton` has not been declared at this point. This is due to the so-called temporal dead zone in JavaScript. Errors like followed will be reported at runtime when such file/code evaluates: ``` Uncaught ReferenceError: Cannot access 'MyButton' before initialization ``` As noted, this is a TypeScript limitation because ideally TypeScript shouldn't evaluate `__metadata`/reference `MyButton` immediately. Instead, it should defer the reference until `MyButton` is actually declared. This limitation will not be fixed by the TypeScript team though because it's a limitation as per current design and they will only revisit this once the tc39 decorator proposal is finalized (currently stage-2 at time of writing). Given this wontfix on the TypeScript side, and our heavy reliance on this metadata in libraries (and for JIT mode), we intend to fix this from within the Angular compiler by downleveling decorators to static properties that don't need to evaluate directly. For example: ``` MyDirective.ctorParameters = () => [MyButton]; ``` With this snippet above, `MyButton` is not referenced directly. Only lazily when the Angular runtime needs it. This mitigates the temporal dead zone issue caused by a limitation in TypeScript's decorator metadata output. See: https://github.com/microsoft/TypeScript/issues/27519. In the past (as noted; before version 7), the Angular compiler by default used tsickle that already performed this transformation. We moved the transformation to the CLI for JIT and `ng-packager`, but now we realize that we can move this all to a single place in the compiler so that standalone ngc consumers can benefit too, and that we can disable tsickle in our Bazel `ngc-wrapped` pipeline (that currently still relies on tsickle to perform this decorator processing). This transformation also has another positive side-effect of making Angular application/library code more compatible with server-side rendering. In principle, TypeScript would also preserve type information for decorated class members (similar to how it did that for constructor parameters) at runtime. This becomes an issue when your application relies on native DOM globals for decorated class member types. e.g. ``` @Input() panelElement: HTMLElement; ``` Your application code would then reference `HTMLElement` directly whenever the source file is loaded in NodeJS for SSR. `HTMLElement` does not exist on the server though, so that will become an invalid reference. One could work around this by providing global mocks for these DOM symbols, but that doesn't match up with other places where dependency injection is used for mocking DOM/browser specific symbols. More context in this issue: #30586. The TL;DR here is that the Angular compiler does not care about types for these class members, so it won't ever reference `HTMLElement` at runtime. Fixes #30106. Fixes #30586. Fixes #30141. Resolves FW-2196. Resolves FW-2199. PR Close #37382
2020-06-05 10:26:23 -04:00
"//packages/compiler-cli/src/ngtsc/reflection",
perf(compiler-cli): split Ivy template type-checking into multiple files (#36211) As a performance optimization, this commit splits the single __ngtypecheck__.ts file which was previously added to the user's program as a container for all template type-checking code into multiple .ngtypecheck shim files, one for each original file in the user's program. In larger applications, the generation, parsing, and checking of this single type-checking file was a huge performance bottleneck, with the file often exceeding 1 MB in text content. Particularly in incremental builds, regenerating this single file for the entire application proved especially expensive. This commit introduces a new strategy for template type-checking code which makes use of a new interface, the `TypeCheckingProgramStrategy`. This interface abstracts the process of creating a new `ts.Program` to type-check a particular compilation, and allows the mechanism there to be kept separate from the more complex logic around dealing with multiple .ngtypecheck files. A new `TemplateTypeChecker` hosts that logic and interacts with the `TypeCheckingProgramStrategy` to actually generate and return diagnostics. The `TypeCheckContext` class, previously the workhorse of template type- checking, is now solely focused on collecting and generating type-checking file contents. A side effect of implementing the new `TypeCheckingProgramStrategy` in this way is that the API is designed to be suitable for use by the Angular Language Service as well. The LS also needs to type-check components, but has its own method for constructing a `ts.Program` with type-checking code. Note that this commit does not make the actual checking of templates at all _incremental_ just yet. That will happen in a future commit. PR Close #36211
2020-03-04 18:50:12 -05:00
"//packages/compiler-cli/src/ngtsc/typecheck",
"@npm//@bazel/typescript",
build: fix build failures with worker mode cache and @types/events (#31325) Errors observed only in tests on CircleCI — was not reproducible locally. ``` ERROR: /home/circleci/ng/packages/http/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/http/test:test_lib failed (Exit 1): tsc_wrapped failed: error executing command (cd /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular && \ exec env - \ BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \ PATH=/bin:/usr/bin:/usr/local/bin \ bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped @@bazel-out/k8-fastbuild/bin/packages/http/test/test_lib_es5_tsconfig.json) Execution platform: //tools:rbe_ubuntu1604-angular Compilation failed Error: missing input digest for /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/external/npm/node_modules/@types/events/index.d.ts. ERROR: /home/circleci/ng/packages/benchpress/test/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/benchpress/test:test_lib failed (Exit 1): tsc_wrapped failed: error executing command (cd /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular && \ exec env - \ BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \ PATH=/bin:/usr/bin:/usr/local/bin \ bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped @@bazel-out/k8-fastbuild/bin/packages/benchpress/test/test_lib_es5_tsconfig.json) Execution platform: //tools:rbe_ubuntu1604-angular Compilation failed Error: missing input digest for /home/circleci/.cache/bazel/_bazel_circleci/9ce5c2144ecf75d11717c0aa41e45a8d/execroot/angular/external/npm/node_modules/@types/events/index.d.ts ERROR: C:/codefresh/volume/angular/packages/compiler/test/css_parser/BUILD.bazel:3:1: Compiling TypeScript (devmode) //packages/compiler/test/css_parser:css_parser_lib failed (Exit 1): tsc_wrapped.exe failed: error executing command cd C:/users/containeradministrator/_bazel_containeradministrator/zquin2l6/execroot/angular SET PATH=C:\msys64\usr\bin;C:\msys64\bin;C:\Windows;C:\Windows\System32;C:\Windows\System32\WindowsPowerShell\v1.0 SET RUNFILES_MANIFEST_ONLY=1 bazel-out/host/bin/external/npm/@bazel/typescript/bin/tsc_wrapped.exe @@bazel-out/x64_windows-fastbuild/bin/packages/compiler/test/css_parser/css_parser_lib_es5_tsconfig.json Execution platform: @bazel_tools//platforms:host_platform Compilation failed Error: missing input digest for C:/users/containeradministrator/_bazel_containeradministrator/zquin2l6/execroot/angular/external/npm/node_modules/@types/events/index. d.ts ``` PR Close #31325
2019-06-22 00:52:00 -04:00
"@npm//@types/node",
"@npm//chokidar",
"@npm//fs-extra",
"@npm//minimist",
"@npm//reflect-metadata",
"@npm//tsickle",
"@npm//typescript",
],
)
pkg_npm(
name = "npm_package",
srcs = [
"package.json",
],
tags = [
"release-with-framework",
],
# Do not add more to this list.
# Dependencies on the full npm_package cause long re-builds.
visibility = [
build: add npm_integration_test && angular_integration_test (#33927) * it's tricky to get out of the runfiles tree with `bazel test` as `BUILD_WORKSPACE_DIRECTORY` is not set but I employed a trick to read the `DO_NOT_BUILD_HERE` file that is one level up from `execroot` and that contains the workspace directory. This is experimental and if `bazel test //:test.debug` fails than `bazel run` is still guaranteed to work as `BUILD_WORKSPACE_DIRECTORY` will be set in that context * test //integration:bazel_test and //integration:bazel-schematics_test exclusively * run "exclusive" and "manual" bazel-in-bazel integration tests in their own CI job as they take 8m+ to execute ``` //integration:bazel-schematics_test PASSED in 317.2s //integration:bazel_test PASSED in 167.8s ``` * Skip all integration tests that are now handled by angular_integration_test except the tests that are tracked for payload size; these are: - cli-hello-world* - hello_world__closure * add & pin @babel deps as newer versions of babel break //packages/localize/src/tools/test:test @babel/core dep had to be pinned to 7.6.4 or else //packages/localize/src/tools/test:test failed. Also //packages/localize uses @babel/generator, @babel/template, @babel/traverse & @babel/types so these deps were added to package.json as they were not being hoisted anymore from @babel/core transitive. NB: integration/hello_world__systemjs_umd test must run with systemjs 0.20.0 NB: systemjs must be at 0.18.10 for legacy saucelabs job to pass NB: With Bazel 2.0, the glob for the files to test `"integration/bazel/**"` is empty if integation/bazel is in .bazelignore. This glob worked under these conditions with 1.1.0. I did not bother testing with 1.2.x as not having integration/bazel in .bazelignore is correct. PR Close #33927
2020-02-04 14:45:40 -05:00
"//integration:__pkg__",
"//packages/compiler-cli/integrationtest:__pkg__",
],
deps = [
":compiler-cli",
"//packages/compiler-cli/ngcc",
],
)
ts_api_guardian_test(
name = "error_code_api",
build: provide full paths to `ts_api_guardian_test_npm_package` and `ts_api_guardian_test` (#36034) ts-api-guardian uses `require.resolve` to resolve the actual and golden files under bazel. In Windows for these files to be resolved correct the full path including the workspace name as per the MANIFEST entries is required. This used to be the case until the recent changes done to use npm_integration tests https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L19 https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L28 ``` bazel test //packages/... --test_tag_filters=api_guard //packages/animations:animations_api (cached) PASSED in 18.4s //packages/common:common_api (cached) PASSED in 25.5s //packages/compiler-cli:compiler_options_api (cached) PASSED in 12.4s //packages/compiler-cli:error_code_api (cached) PASSED in 11.6s //packages/core:core_api (cached) PASSED in 20.6s //packages/core:ng_global_utils_api (cached) PASSED in 13.5s //packages/elements:elements_api (cached) PASSED in 11.9s //packages/forms:forms_api (cached) PASSED in 13.9s //packages/http:http_api (cached) PASSED in 14.8s //packages/localize:localize_api (cached) PASSED in 6.3s //packages/platform-browser:platform-browser_api (cached) PASSED in 18.1s //packages/platform-browser-dynamic:platform-browser-dynamic_api (cached) PASSED in 14.0s //packages/platform-server:platform-server_api (cached) PASSED in 13.9s //packages/platform-webworker:platform-webworker_api (cached) PASSED in 13.7s //packages/platform-webworker-dynamic:platform-webworker-dynamic_api (cached) PASSED in 11.7s //packages/router:router_api (cached) PASSED in 19.9s //packages/service-worker:service-worker_api (cached) PASSED in 18.1s //packages/upgrade:upgrade_api (cached) PASSED in 13.5s ``` Reference: DEV-71 PR Close #36034
2020-03-12 07:36:28 -04:00
actual = "angular/packages/compiler-cli/npm_package/src/ngtsc/diagnostics/src/error_code.d.ts",
data = [
":npm_package",
"//goldens:public-api",
],
build: provide full paths to `ts_api_guardian_test_npm_package` and `ts_api_guardian_test` (#36034) ts-api-guardian uses `require.resolve` to resolve the actual and golden files under bazel. In Windows for these files to be resolved correct the full path including the workspace name as per the MANIFEST entries is required. This used to be the case until the recent changes done to use npm_integration tests https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L19 https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L28 ``` bazel test //packages/... --test_tag_filters=api_guard //packages/animations:animations_api (cached) PASSED in 18.4s //packages/common:common_api (cached) PASSED in 25.5s //packages/compiler-cli:compiler_options_api (cached) PASSED in 12.4s //packages/compiler-cli:error_code_api (cached) PASSED in 11.6s //packages/core:core_api (cached) PASSED in 20.6s //packages/core:ng_global_utils_api (cached) PASSED in 13.5s //packages/elements:elements_api (cached) PASSED in 11.9s //packages/forms:forms_api (cached) PASSED in 13.9s //packages/http:http_api (cached) PASSED in 14.8s //packages/localize:localize_api (cached) PASSED in 6.3s //packages/platform-browser:platform-browser_api (cached) PASSED in 18.1s //packages/platform-browser-dynamic:platform-browser-dynamic_api (cached) PASSED in 14.0s //packages/platform-server:platform-server_api (cached) PASSED in 13.9s //packages/platform-webworker:platform-webworker_api (cached) PASSED in 13.7s //packages/platform-webworker-dynamic:platform-webworker-dynamic_api (cached) PASSED in 11.7s //packages/router:router_api (cached) PASSED in 19.9s //packages/service-worker:service-worker_api (cached) PASSED in 18.1s //packages/upgrade:upgrade_api (cached) PASSED in 13.5s ``` Reference: DEV-71 PR Close #36034
2020-03-12 07:36:28 -04:00
golden = "angular/goldens/public-api/compiler-cli/error_code.d.ts",
)
ts_api_guardian_test(
name = "compiler_options_api",
build: provide full paths to `ts_api_guardian_test_npm_package` and `ts_api_guardian_test` (#36034) ts-api-guardian uses `require.resolve` to resolve the actual and golden files under bazel. In Windows for these files to be resolved correct the full path including the workspace name as per the MANIFEST entries is required. This used to be the case until the recent changes done to use npm_integration tests https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L19 https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L28 ``` bazel test //packages/... --test_tag_filters=api_guard //packages/animations:animations_api (cached) PASSED in 18.4s //packages/common:common_api (cached) PASSED in 25.5s //packages/compiler-cli:compiler_options_api (cached) PASSED in 12.4s //packages/compiler-cli:error_code_api (cached) PASSED in 11.6s //packages/core:core_api (cached) PASSED in 20.6s //packages/core:ng_global_utils_api (cached) PASSED in 13.5s //packages/elements:elements_api (cached) PASSED in 11.9s //packages/forms:forms_api (cached) PASSED in 13.9s //packages/http:http_api (cached) PASSED in 14.8s //packages/localize:localize_api (cached) PASSED in 6.3s //packages/platform-browser:platform-browser_api (cached) PASSED in 18.1s //packages/platform-browser-dynamic:platform-browser-dynamic_api (cached) PASSED in 14.0s //packages/platform-server:platform-server_api (cached) PASSED in 13.9s //packages/platform-webworker:platform-webworker_api (cached) PASSED in 13.7s //packages/platform-webworker-dynamic:platform-webworker-dynamic_api (cached) PASSED in 11.7s //packages/router:router_api (cached) PASSED in 19.9s //packages/service-worker:service-worker_api (cached) PASSED in 18.1s //packages/upgrade:upgrade_api (cached) PASSED in 13.5s ``` Reference: DEV-71 PR Close #36034
2020-03-12 07:36:28 -04:00
actual = "angular/packages/compiler-cli/npm_package/src/ngtsc/core/api/src/public_options.d.ts",
data = [
":npm_package",
"//goldens:public-api",
],
build: provide full paths to `ts_api_guardian_test_npm_package` and `ts_api_guardian_test` (#36034) ts-api-guardian uses `require.resolve` to resolve the actual and golden files under bazel. In Windows for these files to be resolved correct the full path including the workspace name as per the MANIFEST entries is required. This used to be the case until the recent changes done to use npm_integration tests https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L19 https://github.com/angular/angular/blob/83c74ceacf620535673ec141fc8a1003aed187ef/tools/public_api_guard/public_api_guard.bzl#L28 ``` bazel test //packages/... --test_tag_filters=api_guard //packages/animations:animations_api (cached) PASSED in 18.4s //packages/common:common_api (cached) PASSED in 25.5s //packages/compiler-cli:compiler_options_api (cached) PASSED in 12.4s //packages/compiler-cli:error_code_api (cached) PASSED in 11.6s //packages/core:core_api (cached) PASSED in 20.6s //packages/core:ng_global_utils_api (cached) PASSED in 13.5s //packages/elements:elements_api (cached) PASSED in 11.9s //packages/forms:forms_api (cached) PASSED in 13.9s //packages/http:http_api (cached) PASSED in 14.8s //packages/localize:localize_api (cached) PASSED in 6.3s //packages/platform-browser:platform-browser_api (cached) PASSED in 18.1s //packages/platform-browser-dynamic:platform-browser-dynamic_api (cached) PASSED in 14.0s //packages/platform-server:platform-server_api (cached) PASSED in 13.9s //packages/platform-webworker:platform-webworker_api (cached) PASSED in 13.7s //packages/platform-webworker-dynamic:platform-webworker-dynamic_api (cached) PASSED in 11.7s //packages/router:router_api (cached) PASSED in 19.9s //packages/service-worker:service-worker_api (cached) PASSED in 18.1s //packages/upgrade:upgrade_api (cached) PASSED in 13.5s ``` Reference: DEV-71 PR Close #36034
2020-03-12 07:36:28 -04:00
golden = "angular/goldens/public-api/compiler-cli/compiler_options.d.ts",
)