Commit graph

29561 commits

Author SHA1 Message Date
Paul Gschwendtner
a50e2da64a fix(localize): ensure transitively loaded compiler code is tree-shakable (#45405)
The localize primary entry-point (used at runtime in application code)
indirectly loads from the compiler package for computing message ids.
The compiler package has a couple of constants which cannot be DCE-ded/
tree-shaken due to side-effect reliance that is detected by Terser.

We fix these constants to be three-shakable. Note that another issue
technically would be that the compiler package has a side-effect call
for `publishFacade` (for JIT), but that invocation is marked as pure by
the Angular CLI babel optimization pipeline. So this results is no
unused code currently but is risky and should be addressed in the future.

PR Close #45405
2022-04-21 11:09:39 -07:00
Paul Gschwendtner
4c56c45075 refactor(localize): init APF entry-point should not duplicate code (#45405)
This commit addresses two issues:

* The init entry-point currenly access code from another entry-point
  using relative imports, resulting in code to be duplicated.
* The init types are now bundled as part of the ng_package APF rule.
  There is an API extractor bundling issue with global module
  augmentations.

API extractor does not properly handle module augmentation. We need to disable
dts bundling for this entry-point to ensure `$localize` remains globally accessible
for users. This is an option in the `ng_package` rule.

Note that this worked before because `localize/init` was a `ts_library` that did not
have its types bundled.

As part of this change, the `MessageId` and `TargetMessage` exports are
also made public. The localize exported functions rely on these types but
they were not exported.

Related to types, an exception is added for three private exports from the primary
entry-point so that they will show up in the API golden. These private
exports are re-exposed publicly in the init entry-point but no golden
would capture them due to the private symbol prefix. One might wonder
why the symbols are not guarded in the init golden. The reason is that
goldens never inline signatures from cross-entry-points/packages to avoid
duplication.

Lastly, the i18n integration test golden had to be updated because the
polyfills bundle increased slightly. After thorough and time-consuming
investigation, this mostly happens due to different mangle identifies
being used (the input code changed --> so the mangling determinism)

Size before this change:

```
SUCCESS: Commit undefined uncompressed runtime did NOT cross size threshold of 500 bytes or >1% (expected: 929, actual: 926).
SUCCESS: Commit undefined uncompressed main did NOT cross size threshold of 500 bytes or >1% (expected: 124544, actual: 124660).
SUCCESS: Commit undefined uncompressed polyfills did NOT cross size threshold of 500 bytes or >1% (expected: 34530, actual: 34641).
```

After:

```
SUCCESS: Commit undefined uncompressed runtime did NOT cross size threshold of 500 bytes or >1% (expected: 929, actual: 926).
SUCCESS: Commit undefined uncompressed main did NOT cross size threshold of 500 bytes or >1% (expected: 124544, actual: 124650).
FAIL: Commit undefined uncompressed polyfills exceeded expected size by 500 bytes or >1% (expected: 34530, actual: 35252).
```

Inspecting/comparing without mangling shows that the new changes would
actually result in a bundle reduction (potentially visible with
gzip/brotli):

```
➜  Desktop stat -f%z  master-nomangle.js
101357
➜  Desktop stat -f%z  with-changes-nomangle.js
101226
```

PR Close #45405
2022-04-21 11:09:39 -07:00
Paul Gschwendtner
7a8a929da7 refactor: fix duplication in platform-server NPM package (#45405)
The platform-server init entry-point imported code from another
entry-point using a relative import. This resulted in the code to be
bundled into the `init` entry-point as well. This has no breaking
impact but resulted in a little code duplication that we should
clean up.

PR Close #45405
2022-04-21 11:09:39 -07:00
Paul Gschwendtner
dd0fc0f237 test: add test for new types_bundle rule from Angular bazel package (#45405)
Adds a little golden test for the new `types_bundle` rule that ensures
the rule works at a general level. This rule will be useful for non-APF
ESM packages like the Angular compiler-cli (for which we also want to
bundle types to make them compatible with TypeScripts ESM type
resolution)

PR Close #45405
2022-04-21 11:09:39 -07:00
Paul Gschwendtner
68597bb0ca feat(bazel): speed up dev-turnaround by bundling types only when packaging (#45405)
Speeds up the dev-turnaround by only bundling types when packaging. Currently
bundling occurs for all the `ng_module` targets in devmode.

This has various positive benefits:

* Avoidance of this rather slower operation in development
* Makes APF-built packages also handle types for `ts_library` targets consistently.
* Allows us to ensure APF entry-points have `d.ts` _always_ bundled (working with ESM
module resolution in TypeScript -- currently experimental)
* Allows us to remove the secondary `package.json` files from APF (maybe APF v14? - seems
low-impact). This would clean-up the APF even more and fix resolution issues (like in Vite)

PR Close #45405
2022-04-21 11:09:39 -07:00
George Kalpakas
3dee3d107b fix(docs-infra): fix placement of "Edit source" button on errors and diagnostics pages (#45634)
This commit aligns the layout of errors and extended diagnostics pages
more closely with other docs pages to ensure that the "Edit source"
button is displayed correctly even when the heading is too long to fit
on a single line. For error pages, in particular, this ensures that the
button is not obscured by the error video.

**Before:**
![error-pages before][1]

**After:**
![error-pages after][2]

[1]: https://user-images.githubusercontent.com/8604205/163408291-7aebd029-891c-4045-8fa2-a8e2b2b06dab.png
[2]: https://user-images.githubusercontent.com/8604205/163408296-40e6df8e-aadc-4a82-978a-ab4d902b6f6e.png

PR Close #45634
2022-04-21 11:07:27 -07:00
Andrew Kushnir
9292953c56 fix(docs-infra): include tslib into SystemJS config in upgrade-module example app (#45706)
This commit updates the SystemJS for one of the example apps (the `upgrade-module` one) to include a resolution rule for the `tslib`. This is needed in case `tslib` is referenced from the framework code (for example in case of downleveling of some operators). This makes it consistent with other example app configs.

PR Close #45706
2022-04-21 11:05:37 -07:00
Pawel Kozlowski
9e4c4bc42a docs(core): add API documentation to standalone-related classes (#45687)
This commit adds some internal documentation.

PR Close #45687
2022-04-20 16:01:56 -07:00
Pawel Kozlowski
e162fa3735 test(core): add more tests for the standalone injector (#45687)
This commit reorganizes the tests around the EnvironmentInjector and its use
for standalone injectors, and adds a number of new test cases.

PR Close #45687
2022-04-20 16:01:56 -07:00
Pawel Kozlowski
3616d7eb59 refactor(core): implement standalone injectors (#45687)
This commit implements the `StandaloneFeature` which provides for the
creation of standalone injectors, for those components which need them. The
feature-based implementation ensures the machinery for standalone injectors
is properly tree-shakable.

PR Close #45687
2022-04-20 16:01:56 -07:00
Alex Rickabaugh
9f795134fa refactor(core): support standalone components in importProvidersFrom (#45687)
This commit refactors `importProvidersFrom` to support pulling providers
from the dependencies of a standalone component, in addition to NgModules.
Tests will be added in a future commit when standalone components can be
created without calling private APIs.

PR Close #45687
2022-04-20 16:01:55 -07:00
Alex Rickabaugh
5a10fc4f82 feat(core): implement standalone directives, components, and pipes (#45687)
This commit exposes the `standalone` flag on `@Directive`, `@Component`, and
`@Pipe`, effectively making standalone components a part of Angular's public
API. As part of this operation, it also implements JIT compilation for
standalone types.

Standalone types are Angular-decorated types which act as their own
"declarations", where they would otherwise be declared in an NgModule.
Marking an Angular type as standalone means that it can be used directly in
other standalone components and in NgModules, without needing an associated
NgModule to depend on it. In the case of a standalone component, template
dependencies which would otherwise be specified by an NgModule are instead
specified directly on the component itself, via the `imports` field. Other
standalone types can be imported, as well as NgModules.

PR Close #45687
2022-04-20 16:01:55 -07:00
Alex Rickabaugh
bb6e11c7e4 refactor(compiler-cli): reorganize importProvidersFrom to avoid cycles (#45687)
This commit extracts the `importProvidersFrom` function and associated
machinery into a separate file, as opposed to being colocated with
`R3Injector`. Separating these functions will mitigate potential future
circular dependencies as `importProvidersFrom` starts being used in
different parts of the codebase.

PR Close #45687
2022-04-20 16:01:55 -07:00
dario-piotrowicz
dea8c86cd5 feat(router): add ariaCurrentWhenActive input to RouterLinkActive directive (#45167)
add the ariaCurrentWhenActive input to the RouterLinkActive directive so that
users can easily set the aria-current property to their active router
links

resolves #35051

PR Close #45167
2022-04-20 15:14:01 -07:00
Dylan Hunn
d8226de647 release: cut the v14.0.0-next.14 release (#45704)
PR Close #45704
2022-04-20 14:47:03 -07:00
Dylan Hunn
f14763e4a3 docs: release notes for the v13.3.4 release (#45703)
PR Close #45703
2022-04-20 14:41:58 -07:00
Andrew Scott
1d2f5c1101 refactor(router): deprecate no longer needed resolver fields (#45597)
DEPRECATED:

The `resolver` argument of the `RouterOutletContract.activateWith` function and the `resolver` field of the `OutletContext` class are deprecated. Passing component factory resolvers are no longer needed. The `ComponentFactoryResolver`-related symbols were deprecated in `@angular/core` package since v13.

PR Close #45597
2022-04-20 12:57:37 -07:00
Andrew Scott
f4fd1a8262 feat(router): Add EnvironmentInjector to RouterOutlet.activateWith (#45597)
The current API for `activateWith` uses the deprecated
`ComponentFactoryResolver`. The replacement for this is to use
`EnvironmentInjector`. That is, instead of

```
const factory = componentFactoryResolver.resolveComponentFactory(component);
location.createComponent(factory, location.length, injector);
```

the replacement would be

```
location.createComponent(
    component, {index: location.length, injector, environmentInjector});
```

PR Close #45597
2022-04-20 12:57:37 -07:00
Andrew Scott
4e0957a4e1 feat(router): Add ability to specify providers on a Route (#45673)
Currently, the only way to specify new providers for a `Route` and the
children is to create a new `NgModule` with those providers and use the
`loadChildren` feature. This is pretty confusing and a wholly indirect
way of accomplishing this task. With this commit, developers will be
able to specify a list of providers directly on the `Route` itself.
These providers will apply the that route and its children.

This feature was inspired by the upcoming standalone components feature.
This ties in there because, as mentioned before, the prior art for lazy
loading configs was to load an `NgModule`. This loaded module contained
new route configs _and_ could specify new providers. Separating those
two concepts, there should be a way to load _just_ some new routes, but
there should also be a way to specify new providers as well (something
you could do in the `NgModule` world and now will be able to do in the
world without any `NgModule` through this feature).

PR Close #45673
2022-04-20 11:32:07 -07:00
Andrew Kushnir
ba4542889e ci: update payload size golden file (#45699)
This commit updates the payload size for the Forms-related test app.
The CI started to fail after merging ff3f5a8d12. The payload size increase is most likely accumulated.

PR Close #45699
2022-04-20 10:29:38 -07:00
Dylan Hunn
ff3f5a8d12 fix(forms): Fix a typing bug in FormBuilder. (#45684)
Previously, the following code would fail to compile:

```
let form: FormGroup<{email: FormControl<string | null>}>;
form = fb.group({
    email: ['', Validators.required]
});
```

This is because the compiler was unable to properly infer the inner type of `ControlConfig` arrays in some cases. The same issue applies to `FormArray` as well under certain circumstances.

This change cleans up the `FormBuilder` type signatures to always use the explicit Element type, and to catch `ControlConfig` types that might fall through.

PR Close #45684
2022-04-20 09:15:46 -07:00
Andrew Kushnir
788f587367 fix(docs-infra): avoid internal symbols from being referenced during auto-linking (#45689)
This commit adds extra logic to avoid internal and privately exported symbols from being referenced during auto-linking. Currently such symbols can be used for linking, thus resulting in a non-existing link and causing the linking process to fail.

PR Close #45689
2022-04-20 09:11:22 -07:00
Adrian Kunz
47e5b056ec test(http): Add + to encoding test (#45111)
Changes the existing test for query parameter encoding to include the +
symbol and its expected encoding to %2B.

PR Close #45111
2022-04-20 09:00:19 -07:00
Adrian Kunz
76a9a24cdc fix(http): encode + signs in query params as %2B (angular#11058) (#45111)
Servers always decode + as a space, which is undesirable when one
actually wants to query for a plus.

BREAKING CHANGE:

Queries including + will now actually query for + instead of space.
Most workarounds involving custom codecs will be unaffected.
Possible server-side workarounds will need to be undone.

Fixes angular#11058

PR Close #45111
2022-04-20 09:00:19 -07:00
Alex Rickabaugh
b8d3389173 test(compiler-cli): tests for standalone components/directives/pipes (#45672)
This commit bundles tests for standalone components that are possible after
previous implementation commits. Most new tests are compliance tests, but
a test is also included to validate that the template type-checking system
can work with standalone components as well.

PR Close #45672
2022-04-20 05:45:57 -07:00
Alex Rickabaugh
d3c0fa3b1a refactor(compiler-cli): propagate standalone flag in .d.ts metadata (#45672)
This commit adds a type field to .d.ts metadata for directives, components,
and pipes which carries a boolean literal indicating whether the given type
is standalone or not. For backwards compatibility, this flag defaults to
`false`.

Tests are added to validate that standalone types coming from .d.ts files
can be correctly imported into new standalone components.

PR Close #45672
2022-04-20 05:45:57 -07:00
Alex Rickabaugh
80d2cdab8b test: set skipLibCheck on ngcc integration test (#45672)
The ngcc integration test is in an awkward state: it's attempting to test
that the current ngcc can process @angular/core at v12. We need to make a
forwards-incompatible change to the typings of @angular/core, which means
that the compiled typings from the current ngcc won't be compatible with
core as of v12.

To get around this and allow the integration test to have some value, we're
disabling library checking for the time being.

PR Close #45672
2022-04-20 05:45:57 -07:00
Alex Rickabaugh
99b3af4ee6 refactor(compiler-cli): emit isStandalone flag in partial declarations (#45672)
This commit propagates the `isStandalone` flag for a component, directive,
or pipe during partial compilation of a standalone declaration. This flag
allows the linker to properly process a standalone declaration that it
encounters.

PR Close #45672
2022-04-20 05:45:57 -07:00
Alex Rickabaugh
1244a14a36 refactor(compiler-cli): move standalone scope computation out of handler (#45672)
Standalone component scopes were first implemented in the
`ComponentDecoratorHandler` itself, due to an assumption that "standalone"
allowed for a localized analysis of the component's dependencies. However,
this is not strictly true. Other compiler machinery also needs to understand
component scopes, including standalone component scopes. A good example is
the template type-checking engine, which uses a `ComponentScopeReader` to
build full metadata objects (that is, metadata that considers the entire
inheritance chain) for type-checking purposes. Therefore, the
`ComponentScopeReader` should be able to give the scope for a standalone
component.

To achieve this, a new `StandaloneComponentScopeReader` is implemented, and
the return type of `ComponentScopeReader.getScopeForComponent` is expanded
to express standalone scopes. This cleanly integrates the "standalone"
concept into the existing machinery.

PR Close #45672
2022-04-20 05:45:56 -07:00
Alex Rickabaugh
d8086a1dbf refactor(compiler-cli): emit StandaloneFeature for standalone components (#45672)
This commit adds an emit for standalone components of the
`StandaloneFeature`, which will support creation of standalone injectors and
any other mechanisms necessary for standalone component functionality at
runtime.

Using a feature allows for standalone functionality to be tree-shaken in
applications that aren't using them.

PR Close #45672
2022-04-20 05:45:56 -07:00
Alex Rickabaugh
f9f8ef9051 refactor(compiler-cli): emit NgModule dependencies of standalone components (#45672)
This commit expands on the unified dependency tracking in the previous
commit and adds tracking of NgModule dependencies. These are not used for
standard components, but are emitted for standalone components to allow the
runtime to roll up providers from those NgModules into standalone injectors.

PR Close #45672
2022-04-20 05:45:56 -07:00
Alex Rickabaugh
9b35787bb3 refactor(compiler-cli): unify tracked template scope dependencies (#45672)
Previously, the compiler tracked directives and pipes in template scopes
separately. This commit refactors the scope system to unify them into a
single data structure, disambiguated by a `kind` field.

PR Close #45672
2022-04-20 05:45:56 -07:00
Alex Rickabaugh
1527e8f4c0 refactor(core): change component emit to 'dependencies' (#45672)
Previously, the compiler would represent template dependencies of a
component in its component definition through separate fields (`directives`,
`pipes`).

This commit refactors the compiler/runtime interface to use a single field
(`dependencies`). The runtime component definition object still has separate
`directiveDefs` and `pipeDefs`, which are calculated from the `dependencies`
when the definition is evaluated.

This change is also reflected in partially compiled declarations. To ensure
compatibility with partially compiled code already on NPM, the linker
will still honor the old form of declaration (with separate fields).

PR Close #45672
2022-04-20 05:45:56 -07:00
Alex Rickabaugh
046dad1a8d fix(compiler-cli): fix issue with incremental tracking of APIs for pipes (#45672)
`PipeSymbol` contains logic to detect changes in the public API surface of
pipes, which includes the pipe name. However, the pipe handler inadvertently
uses the pipe class name instead of the actual pipe name to initialize the
`PipeSymbol`, which breaks incremental compilation when pipe names change.

There is a test which attempts to verify that this logic is working, but the
test actually passes for a different reason. The test swaps the names of 2
pipes that are both used in a component, and asserts that the component is
re-emitted, theoretically because the public APIs of the pipes is changed.
However, the emit order of the references to the pipes depends on the order
in which they match in the template, which changes when the names are
swapped. This ordering dependency is picked up by the semantic dependency
tracking system, and is what actually causes the component to be re-emitted
and therefore the pipe test to pass in spite of the bug with name tracking.

This commit fixes the `PipeSymbol` initialization to use the correct pipe
name. The test is still flawed in that it's sensitive to the ordering of
pipe emits, but this ordering is due to change soon as a result of the
standalone components work, so this issue will be resolved in a future
commit.

PR Close #45672
2022-04-20 05:45:56 -07:00
Andrew Scott
989e840cce fix(router): Remove unused string type for ActivatedRoute.component (#45625)
BREAKING CHANGE:
The type of `component` on `ActivatedRoute` and `ActivatedRouteSnapshot`
includes `string`. In reality, this is not the case. The component
cannot be anything other than a component class.

PR Close #45625
2022-04-19 20:21:35 -07:00
Mangalraj
4ad7c2e4df docs: Update aio/content/guide/setup-local.md (#45644)
Co-authored-by: George Kalpakas <kalpakas.g@gmail.com>
PR Close #45644
2022-04-19 20:20:39 -07:00
Mangalraj
89f9d28097 docs: correct the example command to install angular (#45644)
PR Close #45644
2022-04-19 20:20:39 -07:00
Paul Gschwendtner
0231a363fe build: preparation for primary branch rename in the Angular repos (#45681)
Preparation for the framework repo as outlined our planning
document.

PR Close #45681
2022-04-19 20:19:46 -07:00
Andrew Scott
6c4d9ebd3a test(common): Fix flaky Location test (#45683)
This test has proven to be flaky. This commit greatly simplifies the
test and moves it to a more appropriate location (pun intended).

PR Close #45683
2022-04-19 20:17:56 -07:00
Saurabh Kamble
5d155950e3 Fix typo (#45680)
PR Close #45680
2022-04-19 09:26:12 -07:00
George Kalpakas
ceffdeda69 docs(common): fix links to locales in i18n guides (#45661)
In PR #42230, the locale file generation process was modified so that
generated locale files are no longer checked into the repository. Update
a few links in the docs that pointed to the previously checked in files
to point to other places where the files exist.

PR Close #45661
2022-04-19 09:17:33 -07:00
Jeremy Elbourn
c6feb0a7ae build: don't assign jelbourn to most review categories (#45668)
Configure pullapprove to not automatically assign jelbourn to most review categories.

PR Close #45668
2022-04-19 09:15:39 -07:00
Louis Gombert
f5299a3b8f docs: update decorators proposal stage and link in glossary (#45669)
PR Close #45669
2022-04-19 09:14:36 -07:00
Andrew Kushnir
63202b9893 test: reset counters before running a styling test (#45670)
This commit updates one of the styling tests to reset perf counters, making it order-independent and non-flaky (previously the test got random failures depending on whether there are other tests invoked before).

PR Close #45670
2022-04-19 09:14:09 -07:00
Andrew Scott
ea8256f43d refactor(router): Move config loader tracking to the RouterConfigLoader (#45656)
This wasn't exactly possible before because the `RouterConfigLoader` was
not an Injectable so there wasn't a straightforward way to share
information between `ApplyRedirects` and the preloader. They each had
their own implementation so they needed to store the values on the
`Route` so they both had access to them. I imagine this was the case
because trying to inject `Router` (to get access to the events) into the
preloader would have caused a circular dependency.

This refactor co-locates the loading details with the loader itself
rather than leaking implementation into the public route config and
mutating the object in an awkward way. This also promotes
`RouterConfigLoader` to a proper `Injectable` so data can be shared
throughout the system.

PR Close #45656
2022-04-18 16:05:45 -07:00
Marko Kaznovac
ec5cb0bb54 docs: use language agnostic mdn urls (#45666)
PR Close #45666
2022-04-18 14:10:16 -07:00
Marko Kaznovac
3477364852 docs: fix mdn links (#45666)
PR Close #45666
2022-04-18 14:10:16 -07:00
Andrew Kushnir
174ce7dd13 feat(core): add ApplicationRef.destroy method (#45624)
This commit implements the `destroy` method on the `ApplicationRef` class. This feature is a preparation for the new logic to bootstrap (and teardown) standalone components (without going through the `NgModuleRef` destroy), which would return an instance of the `ApplicationRef` (the current bootstrap APIs return an instance of the `NgModuleRef`).

PR Close #45624
2022-04-18 14:09:47 -07:00
Andrew Scott
aa966fd715 refactor(router): Use EnvironmentInjector for lazy loading APIs (#45671)
The `EnvironmentInjector` should be used instead of `Injector` for the
lazy loading. A future refactor will further update `RouterOutlet` to
use this injector to create the component rather the deprecated
`ComponentFactoryResolver`.

PR Close #45671
2022-04-18 14:08:43 -07:00
Andrew Scott
eb7661c072 refactor(router): unbundle the lazy loaded routes from the lazy loaded module injector (#45593)
In the standalone world, these concepts will no longer be one and the
same. You can load routes without them being inside an `NgModule` with
`RouterModule.forChild`. In addition, routes will be able to define
their own providers, which will be included in an injector that is not
necessarily lazy loaded.

PR Close #45593
2022-04-18 09:52:56 -07:00