From 1cacb8de15400b54f21d3bcc94e0ab3d2e7cdc02 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Mon, 21 Oct 2024 08:30:12 +0000 Subject: [PATCH] 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 --- goldens/public-api/angular/ssr/index.api.md | 10 ---------- .../angular/ssr/tokens/index.api.md | 20 +++++++++++++++++++ packages/angular/ssr/BUILD.bazel | 3 +++ packages/angular/ssr/public_api.ts | 2 -- packages/angular/ssr/src/app.ts | 2 +- packages/angular/ssr/tokens/BUILD.bazel | 19 ++++++++++++++++++ packages/angular/ssr/tokens/index.ts | 9 +++++++++ packages/angular/ssr/tokens/public_api.ts | 9 +++++++++ .../angular/ssr/{ => tokens}/src/tokens.ts | 0 9 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 goldens/public-api/angular/ssr/tokens/index.api.md create mode 100644 packages/angular/ssr/tokens/BUILD.bazel create mode 100644 packages/angular/ssr/tokens/index.ts create mode 100644 packages/angular/ssr/tokens/public_api.ts rename packages/angular/ssr/{ => tokens}/src/tokens.ts (100%) diff --git a/goldens/public-api/angular/ssr/index.api.md b/goldens/public-api/angular/ssr/index.api.md index 07bd14eb3537..840e3c987b3f 100644 --- a/goldens/public-api/angular/ssr/index.api.md +++ b/goldens/public-api/angular/ssr/index.api.md @@ -5,7 +5,6 @@ ```ts import { EnvironmentProviders } from '@angular/core'; -import { InjectionToken } from '@angular/core'; // @public export class AngularAppEngine { @@ -35,15 +34,6 @@ export enum RenderMode { Server = 1 } -// @public -export const REQUEST: InjectionToken; - -// @public -export const REQUEST_CONTEXT: InjectionToken; - -// @public -export const RESPONSE_INIT: InjectionToken; - // @public export type ServerRoute = ServerRouteAppShell | ServerRouteClient | ServerRoutePrerender | ServerRoutePrerenderWithParams | ServerRouteServer; diff --git a/goldens/public-api/angular/ssr/tokens/index.api.md b/goldens/public-api/angular/ssr/tokens/index.api.md new file mode 100644 index 000000000000..6ac87558b1ad --- /dev/null +++ b/goldens/public-api/angular/ssr/tokens/index.api.md @@ -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; + +// @public +export const REQUEST_CONTEXT: InjectionToken; + +// @public +export const RESPONSE_INIT: InjectionToken; + +// (No @packageDocumentation comment for this package) + +``` diff --git a/packages/angular/ssr/BUILD.bazel b/packages/angular/ssr/BUILD.bazel index ed516a838606..71269b09047a 100644 --- a/packages/angular/ssr/BUILD.bazel +++ b/packages/angular/ssr/BUILD.bazel @@ -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", @@ -38,6 +39,7 @@ ng_package( externals = [ "@angular/ssr", "@angular/ssr/node", + "@angular/ssr/tokens", "../../third_party/critters", ], nested_packages = [ @@ -47,6 +49,7 @@ ng_package( deps = [ ":ssr", "//packages/angular/ssr/node", + "//packages/angular/ssr/tokens", ], ) diff --git a/packages/angular/ssr/public_api.ts b/packages/angular/ssr/public_api.ts index deaefc99bb39..256a0169c89b 100644 --- a/packages/angular/ssr/public_api.ts +++ b/packages/angular/ssr/public_api.ts @@ -17,5 +17,3 @@ export { provideServerRoutesConfig, RenderMode, } from './src/routes/route-config'; - -export { REQUEST, RESPONSE_INIT, REQUEST_CONTEXT } from './src/tokens'; diff --git a/packages/angular/ssr/src/app.ts b/packages/angular/ssr/src/app.ts index 8d14b31f6f95..4008b09f6e12 100644 --- a/packages/angular/ssr/src/app.ts +++ b/packages/angular/ssr/src/app.ts @@ -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'; diff --git a/packages/angular/ssr/tokens/BUILD.bazel b/packages/angular/ssr/tokens/BUILD.bazel new file mode 100644 index 000000000000..b0c63d234c55 --- /dev/null +++ b/packages/angular/ssr/tokens/BUILD.bazel @@ -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", + ], +) diff --git a/packages/angular/ssr/tokens/index.ts b/packages/angular/ssr/tokens/index.ts new file mode 100644 index 000000000000..36d8b2a62dff --- /dev/null +++ b/packages/angular/ssr/tokens/index.ts @@ -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'; diff --git a/packages/angular/ssr/tokens/public_api.ts b/packages/angular/ssr/tokens/public_api.ts new file mode 100644 index 000000000000..4a03e3fdbfe6 --- /dev/null +++ b/packages/angular/ssr/tokens/public_api.ts @@ -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'; diff --git a/packages/angular/ssr/src/tokens.ts b/packages/angular/ssr/tokens/src/tokens.ts similarity index 100% rename from packages/angular/ssr/src/tokens.ts rename to packages/angular/ssr/tokens/src/tokens.ts