Skip to content

Commit 1cacb8d

Browse files
committed
refactor(@angular/ssr): export tokens from the /tokens entry point
This commit relocates the DI tokens to a dedicated entry point. This change ensures that we do not depend on tree-shaking to eliminate server code from client bundles. Closes #28670
1 parent 446fd94 commit 1cacb8d

File tree

9 files changed

+61
-13
lines changed

9 files changed

+61
-13
lines changed

goldens/public-api/angular/ssr/index.api.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
```ts
66

77
import { EnvironmentProviders } from '@angular/core';
8-
import { InjectionToken } from '@angular/core';
98

109
// @public
1110
export class AngularAppEngine {
@@ -35,15 +34,6 @@ export enum RenderMode {
3534
Server = 1
3635
}
3736

38-
// @public
39-
export const REQUEST: InjectionToken<Request>;
40-
41-
// @public
42-
export const REQUEST_CONTEXT: InjectionToken<unknown>;
43-
44-
// @public
45-
export const RESPONSE_INIT: InjectionToken<ResponseInit>;
46-
4737
// @public
4838
export type ServerRoute = ServerRouteAppShell | ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;
4939

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## API Report File for "@angular/ssr_tokens"
2+
3+
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4+
5+
```ts
6+
7+
import { InjectionToken } from '@angular/core';
8+
9+
// @public
10+
export const REQUEST: InjectionToken<Request>;
11+
12+
// @public
13+
export const REQUEST_CONTEXT: InjectionToken<unknown>;
14+
15+
// @public
16+
export const RESPONSE_INIT: InjectionToken<ResponseInit>;
17+
18+
// (No @packageDocumentation comment for this package)
19+
20+
```

packages/angular/ssr/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ts_library(
2020
tsconfig = "//:tsconfig-build-ng",
2121
deps = [
2222
"//packages/angular/ssr/third_party/critters:bundled_critters_lib",
23+
"//packages/angular/ssr/tokens",
2324
"@npm//@angular/common",
2425
"@npm//@angular/core",
2526
"@npm//@angular/platform-server",
@@ -38,6 +39,7 @@ ng_package(
3839
externals = [
3940
"@angular/ssr",
4041
"@angular/ssr/node",
42+
"@angular/ssr/tokens",
4143
"../../third_party/critters",
4244
],
4345
nested_packages = [
@@ -47,6 +49,7 @@ ng_package(
4749
deps = [
4850
":ssr",
4951
"//packages/angular/ssr/node",
52+
"//packages/angular/ssr/tokens",
5053
],
5154
)
5255

packages/angular/ssr/public_api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,3 @@ export {
1717
provideServerRoutesConfig,
1818
RenderMode,
1919
} from './src/routes/route-config';
20-
21-
export { REQUEST, RESPONSE_INIT, REQUEST_CONTEXT } from './src/tokens';

packages/angular/ssr/src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
*/
88

99
import { LOCALE_ID, StaticProvider, ɵresetCompiledComponents } from '@angular/core';
10+
import { REQUEST, REQUEST_CONTEXT, RESPONSE_INIT } from '@angular/ssr/tokens';
1011
import { ServerAssets } from './assets';
1112
import { Hooks } from './hooks';
1213
import { getAngularAppManifest } from './manifest';
1314
import { RenderMode } from './routes/route-config';
1415
import { ServerRouter } from './routes/router';
15-
import { REQUEST, REQUEST_CONTEXT, RESPONSE_INIT } from './tokens';
1616
import { sha256 } from './utils/crypto';
1717
import { InlineCriticalCssProcessor } from './utils/inline-critical-css';
1818
import { LRUCache } from './utils/lru-cache';
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
load("//tools:defaults.bzl", "ts_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
ts_library(
6+
name = "tokens",
7+
srcs = glob(
8+
[
9+
"*.ts",
10+
"src/**/*.ts",
11+
],
12+
),
13+
module_name = "@angular/ssr/tokens",
14+
tsconfig = "//:tsconfig-build-ng",
15+
deps = [
16+
"@npm//@angular/core",
17+
"@npm//tslib",
18+
],
19+
)

packages/angular/ssr/tokens/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
export * from './public_api';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
export { REQUEST, RESPONSE_INIT, REQUEST_CONTEXT } from './src/tokens';

0 commit comments

Comments
 (0)