2021-06-28 13:50:44 -04:00
|
|
|
load("//tools:defaults.bzl", "api_golden_test_npm_package", "ng_module", "ng_package")
|
2017-12-06 09:56:49 -05:00
|
|
|
|
2019-01-16 04:19:01 -05:00
|
|
|
package(default_visibility = ["//visibility:public"])
|
|
|
|
|
2018-02-02 12:18:44 -05:00
|
|
|
ng_module(
|
2017-12-06 09:56:49 -05:00
|
|
|
name = "platform-server",
|
|
|
|
srcs = glob(
|
|
|
|
[
|
|
|
|
"*.ts",
|
|
|
|
"src/**/*.ts",
|
|
|
|
],
|
|
|
|
),
|
|
|
|
deps = [
|
|
|
|
"//packages/animations/browser",
|
|
|
|
"//packages/common",
|
|
|
|
"//packages/common/http",
|
|
|
|
"//packages/compiler",
|
|
|
|
"//packages/core",
|
|
|
|
"//packages/platform-browser",
|
|
|
|
"//packages/platform-browser-dynamic",
|
|
|
|
"//packages/platform-browser/animations",
|
2019-10-05 23:06:53 -04:00
|
|
|
"//packages/zone.js/lib:zone_d_ts",
|
2019-02-20 12:54:42 -05:00
|
|
|
"@npm//@types/node",
|
2021-02-11 12:24:50 -05:00
|
|
|
"@npm//domino",
|
2019-02-20 12:54:42 -05:00
|
|
|
"@npm//rxjs",
|
2017-12-06 09:56:49 -05:00
|
|
|
],
|
|
|
|
)
|
2018-03-07 14:26:11 -05:00
|
|
|
|
|
|
|
ng_package(
|
|
|
|
name = "npm_package",
|
2018-03-13 14:00:53 -04:00
|
|
|
srcs = [
|
|
|
|
"package.json",
|
feat(platform-server): allow shimming the global env sooner (#40559)
`@angular/platform-server` provides the foundation for rendering an
Angular app on the server. In order to achieve that, it uses a
server-side DOM implementation (currently [domino][1]).
For rendering on the server to work as closely as possible to running
the app on the browser, we need to make DOM globals (such as `Element`,
`HTMLElement`, etc.), which are normally provided by the browser,
available as globals on the server as well.
Currently, `@angular/platform-server` achieves this by extending the
`global` object with the DOM implementation provided by `domino`. This
assignment happens in the [setDomTypes()][2] function, which is
[called in a `PLATFORM_INITIALIZER`][3]. While this works in most cases,
there are some scenarios where the DOM globals are needed sooner (i.e.
before initializing the platform). See, for example, #24551 and #39950
for more details on such issues.
This commit provides a way to solve this problem by exposing a
side-effect-ful entry-point (`@angular/platform-server/init`), that
shims the `global` object with DOM globals. People will be able to
import this entry-point in their server-rendered apps before
bootstrapping the app (for example, in their `main.server.ts` file).
(See also [#39950 (comment)][4].)
In a future update, the [`universal` schematics][5] will include such an
import by default in newly generated projects.
[1]: https://www.npmjs.com/package/domino
[2]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/domino_adapter.ts#L17-L21
[3]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/server.ts#L33
[4]: https://github.com/angular/angular/issues/39950#issuecomment-747598403
[5]: https://github.com/angular/angular-cli/blob/cc51432661eb4ab4b6a3/packages/schematics/angular/universal
PR Close #40559
2021-02-11 12:24:52 -05:00
|
|
|
"//packages/platform-server/init:package.json",
|
2018-03-13 14:00:53 -04:00
|
|
|
"//packages/platform-server/testing:package.json",
|
|
|
|
],
|
2019-06-07 16:38:06 -04:00
|
|
|
entry_point = ":index.ts",
|
2018-06-05 14:38:46 -04:00
|
|
|
tags = [
|
|
|
|
"release-with-framework",
|
|
|
|
],
|
2018-12-11 19:53:42 -05:00
|
|
|
# Do not add more to this list.
|
|
|
|
# Dependencies on the full npm_package cause long re-builds.
|
2019-01-22 12:46:51 -05:00
|
|
|
visibility = [
|
2020-02-04 14:45:40 -05:00
|
|
|
"//integration:__pkg__",
|
2019-01-22 12:46:51 -05:00
|
|
|
"//packages/compiler-cli/integrationtest:__pkg__",
|
|
|
|
],
|
2018-03-07 14:26:11 -05:00
|
|
|
deps = [
|
|
|
|
":platform-server",
|
feat(platform-server): allow shimming the global env sooner (#40559)
`@angular/platform-server` provides the foundation for rendering an
Angular app on the server. In order to achieve that, it uses a
server-side DOM implementation (currently [domino][1]).
For rendering on the server to work as closely as possible to running
the app on the browser, we need to make DOM globals (such as `Element`,
`HTMLElement`, etc.), which are normally provided by the browser,
available as globals on the server as well.
Currently, `@angular/platform-server` achieves this by extending the
`global` object with the DOM implementation provided by `domino`. This
assignment happens in the [setDomTypes()][2] function, which is
[called in a `PLATFORM_INITIALIZER`][3]. While this works in most cases,
there are some scenarios where the DOM globals are needed sooner (i.e.
before initializing the platform). See, for example, #24551 and #39950
for more details on such issues.
This commit provides a way to solve this problem by exposing a
side-effect-ful entry-point (`@angular/platform-server/init`), that
shims the `global` object with DOM globals. People will be able to
import this entry-point in their server-rendered apps before
bootstrapping the app (for example, in their `main.server.ts` file).
(See also [#39950 (comment)][4].)
In a future update, the [`universal` schematics][5] will include such an
import by default in newly generated projects.
[1]: https://www.npmjs.com/package/domino
[2]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/domino_adapter.ts#L17-L21
[3]: https://github.com/angular/angular/blob/0fc8466f1be392917e0c/packages/platform-server/src/server.ts#L33
[4]: https://github.com/angular/angular/issues/39950#issuecomment-747598403
[5]: https://github.com/angular/angular-cli/blob/cc51432661eb4ab4b6a3/packages/schematics/angular/universal
PR Close #40559
2021-02-11 12:24:52 -05:00
|
|
|
"//packages/platform-server/init",
|
2018-03-07 14:26:11 -05:00
|
|
|
"//packages/platform-server/testing",
|
|
|
|
],
|
|
|
|
)
|
2020-02-26 12:09:35 -05:00
|
|
|
|
2021-06-28 13:50:44 -04:00
|
|
|
api_golden_test_npm_package(
|
2020-02-26 12:09:35 -05:00
|
|
|
name = "platform-server_api",
|
|
|
|
data = [
|
|
|
|
":npm_package",
|
|
|
|
"//goldens:public-api",
|
|
|
|
],
|
2021-06-28 13:50:44 -04:00
|
|
|
golden_dir = "angular/goldens/public-api/platform-server",
|
|
|
|
npm_package = "angular/packages/platform-server/npm_package",
|
2020-02-26 12:09:35 -05:00
|
|
|
)
|