Commit graph

9260 commits

Author SHA1 Message Date
Paul Gschwendtner
b60df2aa6f build: update angular-in-memory-web-api to work with ESM (#48521)
Properly imports `jasmine-ajax` instead of attempting to load
some CommonJS bundle as a bootstrap dependency in Karma.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
f44b322113 build: override schematics to be built and tested using CommonJS (#48521)
The Angular CLI does not yet support schematics running as ESM. For
this reason we switch the schematics BUILD targets to explicitly
use ESM (as an exception in the repo).

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
57a0499529 build: bundle tests for karma web test suites (#48521)
Since Karma with Bazel does not support ESM natively, we bundle the
tests using ESBuild into a single AMD file. This not only solves the
ESM issue until we can run browser ESM tests natively (also pending
in the components repo - the esbuild generation follows ESM semantics
but since collapsed we don't rely on the real module system).

A benefit of bundling is also faster and more reliable Karma browser
tests since only a single file needs to be loaded- compared to hundreds
of individual files.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
15c3e11359 test: refactor render3 definition feature test to be less sensitive to JS output (#48521)
If tests are bundled using e.g. esbuild, the `ee` symbols may
be rewritten to `\u0275\u0275`. This breaks assertions that
rely on `Function.toString`. We can avoid this string comparison
and make it more future proof by just comparing the symbols directly.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
f89a6dbf05 test: refactor core bundling tests to work with ESM (#48521)
Switches all `core/test/bundling` tests to not rely on
CommonJS-specific features like `require.resolve

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
5c670b8f77 refactor: adjust packages/core/test to work with ESM (#48521)
The `packages/core/test` test code was relying on non-ESM
compatible features like untyped `require` calls.

We switch these to ESM `import` statements/expressions and
make it strongly typed. It's a trade-off between type-safety
and the dependency graph- but it feels more reasonable typing
this properly to actually benefit from the type system provided
by using TypeScript.

Additionally, we align the IDE tsconfigs to use `esnext` as module
because that is what we use in Bazel and it allows us to use
top-level await.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
211d178f0d refactor(platform-server): use proper ESM-compatible import to domino (#48521)
Now that everything runs from within ESM, we need to use the proper
default-import variant to be able to load `domino` from ESM.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
c9415e4d75 build: ensure bootstrap transitive runfiles are made available (#48521)
Since we generate a `.mjs` file as entry-point for jasmine tests,
a couple of issues prevented the transitive dependencies from
bootstrap targets to be brought in (causing resolution errors):

1. The `_files` (previously `_esm2015`) targets are no longer needed,
   and they also miss all the information on runfiles.
2. The aspect for computing linker mappings does not respect the
   `bootstrap` attribute from the `spec_entrypoint` so we manually
   add the extract ESM output targets (this rule works with the aspect
   and forwards linker mappings).

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
4b2cbc0334 build: update jasmine_node_test macro to support ESM (#48521)
Note: `--require` does not work for ESM. `--import` does not exist
in the current Node versions. Started being available in NodeJS v19.

A custom entry-point script, already supported by dev-infra, simplifies
the whole logic and solves the ESM case.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
20551503fa build: replace _es2015 shorthand with more flexible _files suffix (#48521)
For every `ts_library` target we expose a shorthand that grants
access to the JS files because `DefaultInfo` of a ts library
only exposes the `.d.ts` files.

We rename this away from `es2015` since in practice it's a much
higher target these days. Additionally we no longer use the devmode
output but rather use the prodmode output which has the explicit
`.mjs` output- compatible with ESM.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
e1513bf58a build: update madge circular deps tests to use .mjs output (#48521)
The underlyijng nodejs tests of the rule now also use the ESM
output, so normal `.js` artifacts are not even available there.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
d3d22a9009 build: refactor ng_package to work with ESM (#48521)
Removes `shelljs` which is a known ESM-problematic dependency.
We don't need it anyway.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
5c51c48f98 refactor: remove __ESM_IMPORT_META_URL__ workaround now that we can use ESM (#48521)
The `__ESM_IMPORT_META_URL__` trick was used because we used both ESM
and CommonJS in this repo. It was an interop needed because
`import.meta.url` syntax couldn't be used as it woud have caused syntax
errors.

We still need to keep the CommonJS/ESM interop in the compiler-cli
because g3 relies on the compiler and uses CommonJS. This affects very
few places, just in the compiler- so this is acceptable.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
0e1cbecc2c build: refactor generate-locales-tool to ESM (#48521)
The `generate-locales-tool` now needs to run as ESM because we changed
the `ts_library` rule. This commit accounts for the ESM syntax but
removing CJS code parts like `require.main === module`.

Also imports using `require` need to be changed to their ESM
equivalents.

PR Close #48521
2022-12-19 19:50:40 +00:00
Paul Gschwendtner
9e91bbd329 build: refactor ngc-wrapped to support ESM (#48521)
Since this repo will now be strict ESM, and Angular Compiler packages
on NPM are also ESM-only, we can rework `ngc-wrapped` to remove
the CJS/ESM interop and we make it strict ESM too.

PR Close #48521
2022-12-19 19:50:40 +00:00
Paul Gschwendtner
ba5fe263b5 build: switch ng_module and ts_library devmode to ES2020 ESM (#48521)
Currently the devmode output for `ng_module` and `ts_library` is
using ES5 CommonJS UMD. To bring it in sync with prodmode and
to start with our long-term migration to full ESM- the devmode
is updated to to ES2020 ES modules too.

This will require more tricks to make devmod work with the bazel
setup and also tests may need to be refactored given them relying
on ES5 CJS features, like for `spyOn` jasmine patching etc.

PR Close #48521
2022-12-19 19:50:40 +00:00
Andrew Scott
fe50813664 feat(common): Add BrowserPlatformLocation to the public API (#48488)
`PlatformLocation` is already part of the public API so developers can
create their own. This means that developers would already be able to
access the existing `BrowserPlatformLocation` at runtime by injecting
it. The motivation for adding `BrowserPlatformLocation` to the public
API is because of those facts, but driven more by the fact that we are
looking to include `MockPlatformLocation` by default in TestBed.
Developers would need a way to revert back to the current behavior for
some tests that rely directly on browser interaction.

PR Close #48488
2022-12-14 09:54:28 -08:00
Andrew Scott
81203c6ec1 refactor(router): Add opt-in provider for upcoming router change (#47988)
This commit adds a swappable provider for an upcoming change to the
implementation of `Router#createUrlTree`. This will be a breaking change
and is planned to be included in V16.

PR Close #47988
2022-12-13 16:57:46 -08:00
Andrew Scott
ff84c73603 docs(core): Document invalid multi token (#48267)
Add error page for invalid multi token runtime error

PR Close #48267
2022-12-13 14:05:59 -08:00
Andrew Scott
f58ad86e51 feat(router): Add feature provider for enabling hash navigation (#48301)
The argument against this feature:

Firstly, this isn't a navigation strategy that's very commonly desired.
Secondly, the hash strategy is a location configuration in `@angular/common`
and you can use it outside of the Router or with any custom router implementations.
So while the net effect of using the router is that it updates the URL which is
controlled by the strategy, this feature provider doesn't necessarily need to
exist in the Router. The location strategy is an application-wide configuration
and affects anything that imports `Location`.  Of course, the Router does this
in a few places but plenty of other things might as well.

The argument for this feature:

* Discoverability. While `LocationStrategy` is technically in `@angular/common`, the most
  common use-case _is_ when using it with the Router.
* Precedence in the `RouterModule.forRoot([], {useHash: true})`
* Precedence in other routing libraries (`createWebHashHistory` in VueJS
  and `HashRouter` in React, for example)
* The implementation of `withHashLocation` is much more clear than
  `useHash` was. You can look at the function and see that all it's
  doing is adding the `HashLocationStrategy` to the providers list.

resolves #48295 / #47986

PR Close #48301
2022-12-13 08:28:38 -08:00
Jessica Janiuk
e0d62cb734 Revert "fix(common): Update Location to get a normalized URL valid in case a represented URL starts with the substring equals APP_BASE_HREF" (#48461)
This reverts commit ae0efb6a09.

PR Close #48461
2022-12-12 16:18:46 -08:00
dario-piotrowicz
c86484507f fix(animations): fix incorrect handling of camel-case css properties (#48436)
fix the issue of camel-case properties not being handled correctly in
state transition causing them not to be applied to the element

resolves #48246

PR Close #48436
2022-12-12 15:17:44 -08:00
Bob Watson
a6d953e145 docs: move tour of heroes tutorial to a subdirectory (#48162)
This commit prepares the documentation directories for future tutorials organized by directory.

Also, it moves the Angular Libraries topic from the Tutorials section to Developer Guides in TOC

PR Close #48162
2022-12-12 12:07:46 -08:00
Andrew Scott
e362214924 fix(common): Fix TestBed.overrideProvider type to include multi (#48424)
TestBed.overrideProvider should include `multi` support in its type. The
underlying implementation already supports it, as documented by the
tests which are currently casting the override to `any` to get around
the bad type.

PR Close #48424
2022-12-12 09:40:22 -08:00
Konstantin Kharitonov
d87285c363 fix(common): Update Location to get a normalized URL valid in case a represented URL starts with the substring equals APP_BASE_HREF (#48394)
```ts
@NgModule({
  imports: [RouterModule.forRoot([{path: '/enigma', component: EnigmaComponent}])],
  providers: [{provide: APP_BASE_HREF, useValue: '/en'}]
})
export class AppModule {}
```

Navigating to `/enigma` will redirect to `/en/igma` not to `/en/enigma` as it expects

Fixes: #45744

PR Close #48394
2022-12-12 09:37:35 -08:00
Andrew Scott
caa1ad000e docs(router): Update ROUTES docs to not point to provideRoutes (#48417)
provideRoutes is deprecated in favor of the ROUTES token directly
for complex situations where it's necessary.

fixes #48411

PR Close #48417
2022-12-12 09:36:38 -08:00
Andrew Scott
dcfbe22434 docs(common): Add note to location about investigating base href handling (#48422)
There have been/are several bugs related to base href handling in
Angular (#45744, #48175, #19296).
These all stem from the attempted custom handling of base href
in the `Location` class. This logic does not really make an attempt
to be fully compliant with the spec.

PR Close #48422
2022-12-09 12:38:59 -08:00
Alan Agius
e376e924d8 refactor(migrations): remove unused migrations (#48414)
These migrations can no longer run due to a single update version policy (IE: from 13 to 14, 14 to 15 etc..). Therefore these are redundant and can be deleted.

We also remove the `-beta` suffix from the version which is not needed as the Angular CLI will add the prerelease suffixes automatically.

PR Close #48414
2022-12-09 10:04:03 -08:00
Matthieu Riegler
0fa70dfb6d refactor(router): code cleaning (#48259)
Removing unnecessary type assertions, null assertions etc.

PR Close #48259
2022-12-09 09:59:20 -08:00
Andrew Kushnir
83f694752a refactor(router): use RegExp to check if a URL is absolute (#48406)
Previously, this check looked like this: `/^(https?:)?\/\//.test(baseHref)`,
but that resulted in syntactically incorrect code after Closure Compiler minification.
This was likely caused by a bug in Closure Compiler, but for now, the check is rewritten
to use `new RegExp` instead.

PR Close #48406
2022-12-08 15:06:16 -08:00
JoostK
a6849f27af fix(compiler-cli): evaluate const tuple types statically (#48091)
For standalone components it may be beneficial to group multiple declarations
into a single array, that can then be imported all at once in `Component.imports`.
If this array is declared within a library, however, would the AOT compiler
need to extract the contents of the array from the declaration file. This
requires that the array is constructed using an `as const` cast, which results
in a readonly tuple declaration in the generated .d.ts file of the library:

```ts
export declare const DECLARATIONS: readonly [typeof StandaloneDir];
```

The partial evaluator logic did not support this syntax, so this pattern was
not functional when a library is involved. This commit adds the necessary
logic in the static interpreter to evaluate this type at compile time.

Closes #48089

PR Close #48091
2022-12-07 14:10:26 -08:00
Alan Agius
ee78e73e8c refactor(compiler): replace deprecated sourcemap-codec (#48387)
`sourcemap-codec` as been deprecated in favor of `@jridgewell/sourcemap-codec`.

See: https://www.npmjs.com/package/sourcemap-codec?activeTab=versions

PR Close #48387
2022-12-07 14:09:17 -08:00
Konstantin Kharitonov
f8ecc194e9 fix(common): Update Location to support base href containing origin (#48327)
In case `APP_BASE_HREF` is set including `origin` the further usage of it might cause failure

e.g.
If an app is placed on `https://example.com` and bundles are on `https://cdn-example.com` you have to set `APP_BASE_HREF` up as `https://example.com/` and build the app with `--base-href` as `https://cdn-example.com/` but it does not work because of the bug

Fixes #48175

PR Close #48327
2022-12-07 09:18:00 -08:00
Alan Agius
146d2ee246 refactor(compiler): replace flatten and map with flatMap. (#48378)
Replace custom `flatten` and `map` with native `flatMap` usage.

Benchmark:
| Test case name 	| Result                                                 	|
|----------------	|--------------------------------------------------------	|
| flatten & map  	| flatten & map x 1,182 ops/sec ±2.18% (63 runs sampled) 	|
| flatMap        	| flatMap x 6,011 ops/sec ±0.91% (35 runs sampled)       	|

The fact that `flatMap` is faster is also highlighted in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap

PR Close #48378
2022-12-07 09:08:25 -08:00
Kristiyan Kostadinov
5f9c7ceb90 fix(core): unable to inject ChangeDetectorRef inside host directives (#48355)
When injecting the `ChangeDetectorRef` into a node that matches a component, we create a new ref using the component's LView. This breaks down for host directives, because they run before the component's LView has been created.

These changes resolve the issue by creating the LView before creating the node injector for the directives.

Fixes #48249.

PR Close #48355
2022-12-07 09:06:46 -08:00
sr5434
02691a74bb refactor(forms): make FormBuilder classes provided in root (#48245)
refactor(forms): make FormBuilder classes provided in root

This commit updates the FormBuilder classes to provide them in root
instead of using a deprecated pattern of providing a service in a specific
module using the `providedIn` syntax.

Closes #48237.

PR Close #48245
2022-12-06 13:29:41 -08:00
Alan Agius
eae182da84 refactor(core): simplify array flatten logic (#48358)
We can now use modern Javascript to get the same result.

PR Close #48358
2022-12-06 12:48:41 -08:00
Angular Robot
7c4e9ce5c0 build: update cross-repo angular dependencies (#47882)
See associated pull request for more information.

PR Close #47882
2022-12-06 12:48:11 -08:00
Charles Lyding
a403286cfa refactor(compiler): reduce complexity for legacy i18n digest string output (#48362)
When using the legacy digest algorithm for i18n messages, the output hexadecimal
string now leverages a number's `toString()` function in addition to the `padStart`
string function to generate the result. This removes the need for several helper
functions which involved a series of iteration and bitwise operations to previously
generate the same output.

PR Close #48362
2022-12-06 11:48:56 -08:00
Angular Robot
126573d76b build: update all non-major dependencies (#48372)
See associated pull request for more information.

PR Close #48372
2022-12-06 11:06:39 -08:00
Kristiyan Kostadinov
dd42974b07 feat(core): support TypeScript 4.9 (#48005)
Updates to TypeScript 4.9 and resolves some of the errors and deprecation warnings that showed up as a result.

PR Close #48005
2022-12-06 10:45:33 -08:00
dario-piotrowicz
4c023956d8 fix(compiler): make sure selectors inside container queries are correctly scoped (#48353)
improve the emulated shadowDom implementation so that it can correctly
scope selectors present inside the @container at-rule (recently added
to the css specs)

resolves #48264

PR Close #48353
2022-12-06 09:58:59 -08:00
Alan Agius
8189b64d7d refactor(core): remove old AJD workaround for G3 (#48363)
This workaround does not seem to be needed any longer.

PR Close #48363
2022-12-06 09:14:23 -08:00
Alan Agius
cf51690341 refactor(core): remove several private utils and APIs (#48357)
These APIs are no longer used.

PR Close #48357
2022-12-05 14:35:08 -08:00
Alan Agius
e7feaa1412 refactor(compiler): remove unused projection const (#48357)
`projection` const is unused in `serializePlaceholderValue`.

PR Close #48357
2022-12-05 14:35:08 -08:00
Alan Agius
ffbc9679e4 refactor(common): remove unused setDOM (#48357)
Remove unused `setDOM` method is unused.

PR Close #48357
2022-12-05 14:35:08 -08:00
Alex Castle
8e52ca2714 fix(common): Don't generate srcsets with very large sources (#47997)
Fix an issue where users could inadvertently generate very large source images in ngOptimizedImage

PR Close #47997
2022-12-05 12:12:13 -08:00
Alan Agius
4f7456c71d refactor(platform-browser): simplify flattenStyles method (#48293)
With this change we simplify the `flattenStyles` logic using modern JavaScript.

PR Close #48293
2022-12-02 11:36:13 -08:00
Charles Lyding
7f36221101 refactor(compiler): use TypedArrays and DataViews to calculate i18n message IDs (#48256)
The native UTF-8 encoder (`TextEncoder`) provides its output as a `Uint8Array`
which is a specialized `TypedArray` for storing byte values. To remove the need
to copy and transform this data multiple times, a `DataView` is used to allow
for low-level access to the data in a variety of bit-widths and endianness.
The `DataView` class is natively available and supported by all browsers and
Node.js versions support by the framework (https://caniuse.com/mdn-javascript_builtins_dataview).

PR Close #48256
2022-12-01 14:38:09 -08:00
Charles Lyding
0827091d49 refactor(compiler): use native UTF-8 text encoding when calculating i18n IDs (#48256)
Instead of relying on a custom implementation of a UTF-8 text encoder that needs to
be maintained by the Angular team, the i18n message digesting process now uses the
native `TextEncoder` class. This class is available for use in all browsers and Node.js
versions supported by the Angular framework (https://caniuse.com/textencoder). The
custom encoder is still used by the compiler's source map generator and cannot yet be
fully removed.

PR Close #48256
2022-12-01 14:38:08 -08:00