Skip to content

Commit

Permalink
refactor(@angular/ssr): export tokens from the /tokens entry point
Browse files Browse the repository at this point in the history
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
  • Loading branch information
alan-agius4 committed Oct 21, 2024
1 parent 446fd94 commit 1cacb8d
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 13 deletions.
10 changes: 0 additions & 10 deletions goldens/public-api/angular/ssr/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
```ts

import { EnvironmentProviders } from '@angular/core';
import { InjectionToken } from '@angular/core';

// @public
export class AngularAppEngine {
Expand Down Expand Up @@ -35,15 +34,6 @@ export enum RenderMode {
Server = 1
}

// @public
export const REQUEST: InjectionToken<Request>;

// @public
export const REQUEST_CONTEXT: InjectionToken<unknown>;

// @public
export const RESPONSE_INIT: InjectionToken<ResponseInit>;

// @public
export type ServerRoute = ServerRouteAppShell | ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer;

Expand Down
20 changes: 20 additions & 0 deletions goldens/public-api/angular/ssr/tokens/index.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## API Report File for "@angular/ssr_tokens"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts

import { InjectionToken } from '@angular/core';

// @public
export const REQUEST: InjectionToken<Request>;

// @public
export const REQUEST_CONTEXT: InjectionToken<unknown>;

// @public
export const RESPONSE_INIT: InjectionToken<ResponseInit>;

// (No @packageDocumentation comment for this package)

```
3 changes: 3 additions & 0 deletions packages/angular/ssr/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ts_library(
tsconfig = "//:tsconfig-build-ng",
deps = [
"//packages/angular/ssr/third_party/critters:bundled_critters_lib",
"//packages/angular/ssr/tokens",
"@npm//@angular/common",
"@npm//@angular/core",
"@npm//@angular/platform-server",
Expand All @@ -38,6 +39,7 @@ ng_package(
externals = [
"@angular/ssr",
"@angular/ssr/node",
"@angular/ssr/tokens",
"../../third_party/critters",
],
nested_packages = [
Expand All @@ -47,6 +49,7 @@ ng_package(
deps = [
":ssr",
"//packages/angular/ssr/node",
"//packages/angular/ssr/tokens",
],
)

Expand Down
2 changes: 0 additions & 2 deletions packages/angular/ssr/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ export {
provideServerRoutesConfig,
RenderMode,
} from './src/routes/route-config';

export { REQUEST, RESPONSE_INIT, REQUEST_CONTEXT } from './src/tokens';
2 changes: 1 addition & 1 deletion packages/angular/ssr/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/

import { LOCALE_ID, StaticProvider, ɵresetCompiledComponents } from '@angular/core';
import { REQUEST, REQUEST_CONTEXT, RESPONSE_INIT } from '@angular/ssr/tokens';
import { ServerAssets } from './assets';
import { Hooks } from './hooks';
import { getAngularAppManifest } from './manifest';
import { RenderMode } from './routes/route-config';
import { ServerRouter } from './routes/router';
import { REQUEST, REQUEST_CONTEXT, RESPONSE_INIT } from './tokens';
import { sha256 } from './utils/crypto';
import { InlineCriticalCssProcessor } from './utils/inline-critical-css';
import { LRUCache } from './utils/lru-cache';
Expand Down
19 changes: 19 additions & 0 deletions packages/angular/ssr/tokens/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//tools:defaults.bzl", "ts_library")

package(default_visibility = ["//visibility:public"])

ts_library(
name = "tokens",
srcs = glob(
[
"*.ts",
"src/**/*.ts",
],
),
module_name = "@angular/ssr/tokens",
tsconfig = "//:tsconfig-build-ng",
deps = [
"@npm//@angular/core",
"@npm//tslib",
],
)
9 changes: 9 additions & 0 deletions packages/angular/ssr/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

export * from './public_api';
9 changes: 9 additions & 0 deletions packages/angular/ssr/tokens/public_api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/

export { REQUEST, RESPONSE_INIT, REQUEST_CONTEXT } from './src/tokens';
File renamed without changes.

0 comments on commit 1cacb8d

Please sign in to comment.