@analogjs/platform 3.0.0-alpha.91 → 3.0.0-alpha.93
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.d.ts +2 -0
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js +203 -0
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js.map +1 -0
- package/package.json +11 -7
- package/src/lib/clear-client-page-endpoint.js +1 -0
- package/src/lib/clear-client-page-endpoint.js.map +1 -1
- package/src/lib/deps-plugin.js +17 -6
- package/src/lib/deps-plugin.js.map +1 -1
- package/src/lib/nitro/analog-nitro-plugin.js +102 -45
- package/src/lib/nitro/analog-nitro-plugin.js.map +1 -1
- package/src/lib/nitro/get-server-fn-handlers.d.ts +29 -0
- package/src/lib/nitro/get-server-fn-handlers.js +66 -0
- package/src/lib/nitro/get-server-fn-handlers.js.map +1 -0
- package/src/lib/nitro/server-fn-endpoints.d.ts +41 -0
- package/src/lib/nitro/server-fn-endpoints.js +57 -0
- package/src/lib/nitro/server-fn-endpoints.js.map +1 -0
- package/src/lib/nx-plugin/src/generators/app/files/template-angular/src/server/routes/api/v1/hello.ts__template__ +2 -2
- package/src/lib/nx-plugin/src/generators/app/files/template-angular/vite.config.ts__template__ +4 -0
- package/src/lib/nx-plugin/src/generators/app/generator.js +5 -0
- package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.d.ts +8 -6
- package/src/lib/nx-plugin/src/generators/app/versions/nx_18_X/versions.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js +4 -7
- package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +3 -1
- package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.d.ts +6 -6
- package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js +6 -6
- package/src/lib/nx-plugin/src/utils/versions/ng_19_X/versions.js.map +1 -1
- package/src/lib/options.d.ts +17 -1
- package/src/lib/platform-plugin.js +34 -3
- package/src/lib/platform-plugin.js.map +1 -1
- package/src/lib/ssr/defer-streaming-plugin.d.ts +3 -35
- package/src/lib/ssr/defer-streaming-plugin.js +103 -0
- package/src/lib/ssr/defer-streaming-plugin.js.map +1 -0
- package/src/lib/ssr/ssr-build-plugin.d.ts +1 -1
- package/src/lib/ssr/ssr-build-plugin.js.map +1 -1
- package/src/lib/utils/rolldown.js +1 -1
- package/src/server-mode-plugin.d.ts +1 -1
- package/src/server-mode-plugin.js +13 -1
- package/src/server-mode-plugin.js.map +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export declare const V18_X_NX_DEVKIT = "^20.0.0";
|
|
2
2
|
export declare const V18_X_NX_ANGULAR = "^20.0.0";
|
|
3
|
-
export declare const V18_X_ANALOG_JS_CONTENT = "^3.0.0-alpha.
|
|
4
|
-
export declare const V18_X_ANALOG_JS_ROUTER = "^3.0.0-alpha.
|
|
5
|
-
export declare const V18_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = "^3.0.0-alpha.
|
|
6
|
-
export declare const V18_X_ANALOG_JS_VITEST_ANGULAR = "^3.0.0-alpha.
|
|
3
|
+
export declare const V18_X_ANALOG_JS_CONTENT = "^3.0.0-alpha.93";
|
|
4
|
+
export declare const V18_X_ANALOG_JS_ROUTER = "^3.0.0-alpha.93";
|
|
5
|
+
export declare const V18_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = "^3.0.0-alpha.93";
|
|
6
|
+
export declare const V18_X_ANALOG_JS_VITEST_ANGULAR = "^3.0.0-alpha.93";
|
|
7
7
|
export declare const V18_X_FRONT_MATTER = "^4.0.2";
|
|
8
8
|
export declare const V18_X_MARKED = "^18.0.0";
|
|
9
9
|
export declare const V18_X_MARKED_GFM_HEADING_ID = "^4.1.1";
|
|
@@ -15,12 +15,14 @@ export declare const V18_X_TAILWINDCSS = "^4.2.2";
|
|
|
15
15
|
export declare const V18_X_TAILWINDCSS_POSTCSS = "^4.2.2";
|
|
16
16
|
export declare const V18_X_TAILWINDCSS_VITE = "^4.2.2";
|
|
17
17
|
export declare const V18_X_POSTCSS = "^8.5.6";
|
|
18
|
-
export declare const V18_X_ANALOG_JS_PLATFORM = "^3.0.0-alpha.
|
|
18
|
+
export declare const V18_X_ANALOG_JS_PLATFORM = "^3.0.0-alpha.93";
|
|
19
|
+
export declare const V18_X_ANALOG_JS_VITE_PLUGIN_NITRO = "^3.0.0-alpha.93";
|
|
20
|
+
export declare const V18_X_H3 = "^1.13.0";
|
|
19
21
|
export declare const V18_X_ANGULAR_DEVKIT_BUILD_ANGULAR = "^19.0.0";
|
|
20
22
|
export declare const V18_X_NX_VITE = "^21.0.0";
|
|
21
23
|
export declare const V18_X_NX_LINTER = "^21.0.0";
|
|
22
24
|
export declare const V18_X_JSDOM = "^22.1.0";
|
|
23
25
|
export declare const V18_X_VITE = "^8.0.0";
|
|
24
26
|
export declare const V18_X_VITE_TSCONFIG_PATHS = "^4.2.0";
|
|
25
|
-
export declare const V18_X_VITEST = "^
|
|
27
|
+
export declare const V18_X_VITEST = "^5.0.0";
|
|
26
28
|
export declare const V18_X_ZOD = "^3.21.4";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versions.js","names":[],"sources":["../../../../../../../../../../nx-plugin/src/generators/app/versions/nx_18_X/versions.ts"],"sourcesContent":["// V18_X\n// dependencies\nexport const V18_X_NX_DEVKIT = '^20.0.0';\nexport const V18_X_NX_ANGULAR = '^20.0.0';\nexport const V18_X_ANALOG_JS_CONTENT = '^3.0.0-alpha.
|
|
1
|
+
{"version":3,"file":"versions.js","names":[],"sources":["../../../../../../../../../../nx-plugin/src/generators/app/versions/nx_18_X/versions.ts"],"sourcesContent":["// V18_X\n// dependencies\nexport const V18_X_NX_DEVKIT = '^20.0.0';\nexport const V18_X_NX_ANGULAR = '^20.0.0';\nexport const V18_X_ANALOG_JS_CONTENT = '^3.0.0-alpha.93';\nexport const V18_X_ANALOG_JS_ROUTER = '^3.0.0-alpha.93';\nexport const V18_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = '^3.0.0-alpha.93';\nexport const V18_X_ANALOG_JS_VITEST_ANGULAR = '^3.0.0-alpha.93';\nexport const V18_X_FRONT_MATTER = '^4.0.2';\nexport const V18_X_MARKED = '^18.0.0';\nexport const V18_X_MARKED_GFM_HEADING_ID = '^4.1.1';\nexport const V18_X_MARKED_HIGHLIGHT = '^2.2.1';\nexport const V18_X_MARKED_MANGLE = '^1.1.10';\nexport const V18_X_MERMAID = '^10.2.4';\nexport const V18_X_PRISMJS = '^1.29.0';\nexport const V18_X_TAILWINDCSS = '^4.2.2';\nexport const V18_X_TAILWINDCSS_POSTCSS = '^4.2.2';\nexport const V18_X_TAILWINDCSS_VITE = '^4.2.2';\nexport const V18_X_POSTCSS = '^8.5.6';\n\n// devDependencies\nexport const V18_X_ANALOG_JS_PLATFORM = '^3.0.0-alpha.93';\nexport const V18_X_ANALOG_JS_VITE_PLUGIN_NITRO = '^3.0.0-alpha.93';\nexport const V18_X_H3 = '^1.13.0';\nexport const V18_X_ANGULAR_DEVKIT_BUILD_ANGULAR = '^19.0.0';\nexport const V18_X_NX_VITE = '^21.0.0';\nexport const V18_X_NX_LINTER = '^21.0.0';\nexport const V18_X_JSDOM = '^22.1.0';\nexport const V18_X_VITE = '^8.0.0';\nexport const V18_X_VITE_TSCONFIG_PATHS = '^4.2.0';\nexport const V18_X_VITEST = '^5.0.0';\nexport const V18_X_ZOD = '^3.21.4';\n"],"mappings":";AAeA,IAAa,oBAAoB;AACjC,IAAa,4BAA4B;AACzC,IAAa,yBAAyB;AACtC,IAAa,gBAAgB"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
//#region packages/nx-plugin/src/generators/init/lib/update-git-ignore.ts
|
|
2
2
|
function updateGitIgnore(tree) {
|
|
3
3
|
const gitIgnorePath = "/.gitignore";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (gitIgnoreContents && !gitIgnoreContents.includes(".nx/cache")) {
|
|
7
|
-
const updatedGitIgnore = `${gitIgnoreContents}\n
|
|
4
|
+
let gitIgnoreContents = tree.read(gitIgnorePath, "utf-8") ?? "";
|
|
5
|
+
if (!gitIgnoreContents.includes(".nx/cache")) gitIgnoreContents += `\n
|
|
8
6
|
.nx/cache
|
|
9
7
|
.nx/workspace-data`;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
8
|
+
if (!gitIgnoreContents.includes(".vitest/")) gitIgnoreContents += "\n.vitest/\n";
|
|
9
|
+
tree.write(gitIgnorePath, gitIgnoreContents);
|
|
13
10
|
}
|
|
14
11
|
//#endregion
|
|
15
12
|
exports.updateGitIgnore = updateGitIgnore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-git-ignore.js","names":[],"sources":["../../../../../../../../../nx-plugin/src/generators/init/lib/update-git-ignore.ts"],"sourcesContent":["import { Tree } from '@nx/devkit';\n\nexport function updateGitIgnore(tree: Tree): void {\n const gitIgnorePath = '/.gitignore';\n
|
|
1
|
+
{"version":3,"file":"update-git-ignore.js","names":[],"sources":["../../../../../../../../../nx-plugin/src/generators/init/lib/update-git-ignore.ts"],"sourcesContent":["import { Tree } from '@nx/devkit';\n\nexport function updateGitIgnore(tree: Tree): void {\n const gitIgnorePath = '/.gitignore';\n let gitIgnoreContents = tree.read(gitIgnorePath, 'utf-8') ?? '';\n\n if (!gitIgnoreContents.includes('.nx/cache')) {\n gitIgnoreContents += `\\n\n.nx/cache\n.nx/workspace-data`;\n }\n\n if (!gitIgnoreContents.includes('.vitest/')) {\n gitIgnoreContents += '\\n.vitest/\\n';\n }\n\n tree.write(gitIgnorePath, gitIgnoreContents);\n}\n"],"mappings":";AAEA,SAAgB,gBAAgB,MAAkB;CAChD,MAAM,gBAAgB;CACtB,IAAI,oBAAoB,KAAK,KAAK,eAAe,QAAQ,IAAI;AAE7D,KAAI,CAAC,kBAAkB,SAAS,YAAY,CAC1C,sBAAqB;;;AAKvB,KAAI,CAAC,kBAAkB,SAAS,WAAW,CACzC,sBAAqB;AAGvB,MAAK,MAAM,eAAe,kBAAkB"}
|
|
@@ -101,6 +101,8 @@ exports[`preset generator > should match vite.config.ts 1`] = `
|
|
|
101
101
|
"/// <reference types="vitest" />
|
|
102
102
|
|
|
103
103
|
import analog from '@analogjs/platform';
|
|
104
|
+
import angular from '@analogjs/vite-plugin-angular';
|
|
105
|
+
import nitro from '@analogjs/vite-plugin-nitro';
|
|
104
106
|
import { defineConfig } from 'vite';
|
|
105
107
|
|
|
106
108
|
import tailwindcss from '@tailwindcss/vite';
|
|
@@ -120,7 +122,7 @@ export default defineConfig(({ mode }) => {
|
|
|
120
122
|
allow: ['.'],
|
|
121
123
|
},
|
|
122
124
|
},
|
|
123
|
-
plugins: [analog(), tailwindcss()],
|
|
125
|
+
plugins: [analog(), angular(), nitro(), tailwindcss()],
|
|
124
126
|
test: {
|
|
125
127
|
globals: true,
|
|
126
128
|
environment: 'jsdom',
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export declare const V19_X_ANALOG_JS_ROUTER = "^3.0.0-alpha.
|
|
2
|
-
export declare const V19_X_ANALOG_JS_CONTENT = "^3.0.0-alpha.
|
|
1
|
+
export declare const V19_X_ANALOG_JS_ROUTER = "^3.0.0-alpha.93";
|
|
2
|
+
export declare const V19_X_ANALOG_JS_CONTENT = "^3.0.0-alpha.93";
|
|
3
3
|
export declare const V19_X_MARKED = "^18.0.0";
|
|
4
4
|
export declare const V19_X_MARKED_GFM_HEADING_ID = "^4.1.1";
|
|
5
5
|
export declare const V19_X_MARKED_HIGHLIGHT = "^2.2.1";
|
|
6
6
|
export declare const V19_X_MARKED_MANGLE = "^1.1.10";
|
|
7
7
|
export declare const V19_X_PRISMJS = "^1.29.0";
|
|
8
|
-
export declare const V19_X_ANALOG_JS_PLATFORM = "^3.0.0-alpha.
|
|
9
|
-
export declare const V19_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = "^3.0.0-alpha.
|
|
10
|
-
export declare const V19_X_ANALOG_JS_VITEST_ANGULAR = "^3.0.0-alpha.
|
|
8
|
+
export declare const V19_X_ANALOG_JS_PLATFORM = "^3.0.0-alpha.93";
|
|
9
|
+
export declare const V19_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = "^3.0.0-alpha.93";
|
|
10
|
+
export declare const V19_X_ANALOG_JS_VITEST_ANGULAR = "^3.0.0-alpha.93";
|
|
11
11
|
export declare const V19_X_NX_ANGULAR = "^22.0.0";
|
|
12
12
|
export declare const V19_X_NX_VITE = "^22.0.0";
|
|
13
13
|
export declare const V19_X_JSDOM = "^22.0.0";
|
|
@@ -15,5 +15,5 @@ export declare const V19_X_VITE_TSCONFIG_PATHS = "^4.2.0";
|
|
|
15
15
|
export declare const V19_X_VITEST = "^3.0.0";
|
|
16
16
|
export declare const V19_X_VITE = "^6.0.0";
|
|
17
17
|
export declare const NX_X_LATEST_VITE = "^8.0.0";
|
|
18
|
-
export declare const NX_X_LATEST_VITEST = "^
|
|
18
|
+
export declare const NX_X_LATEST_VITEST = "^5.0.0";
|
|
19
19
|
export declare const NX_X_LATEST_NX = "^23.0.0";
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
//#region packages/nx-plugin/src/utils/versions/ng_19_X/versions.ts
|
|
2
|
-
var V19_X_ANALOG_JS_ROUTER = "^3.0.0-alpha.
|
|
3
|
-
var V19_X_ANALOG_JS_CONTENT = "^3.0.0-alpha.
|
|
2
|
+
var V19_X_ANALOG_JS_ROUTER = "^3.0.0-alpha.93";
|
|
3
|
+
var V19_X_ANALOG_JS_CONTENT = "^3.0.0-alpha.93";
|
|
4
4
|
var V19_X_MARKED = "^18.0.0";
|
|
5
5
|
var V19_X_MARKED_GFM_HEADING_ID = "^4.1.1";
|
|
6
6
|
var V19_X_MARKED_HIGHLIGHT = "^2.2.1";
|
|
7
7
|
var V19_X_MARKED_MANGLE = "^1.1.10";
|
|
8
8
|
var V19_X_PRISMJS = "^1.29.0";
|
|
9
|
-
var V19_X_ANALOG_JS_PLATFORM = "^3.0.0-alpha.
|
|
10
|
-
var V19_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = "^3.0.0-alpha.
|
|
11
|
-
var V19_X_ANALOG_JS_VITEST_ANGULAR = "^3.0.0-alpha.
|
|
9
|
+
var V19_X_ANALOG_JS_PLATFORM = "^3.0.0-alpha.93";
|
|
10
|
+
var V19_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = "^3.0.0-alpha.93";
|
|
11
|
+
var V19_X_ANALOG_JS_VITEST_ANGULAR = "^3.0.0-alpha.93";
|
|
12
12
|
var V19_X_NX_VITE = "^22.0.0";
|
|
13
13
|
var V19_X_JSDOM = "^22.0.0";
|
|
14
14
|
var V19_X_VITE_TSCONFIG_PATHS = "^4.2.0";
|
|
15
15
|
var V19_X_VITEST = "^3.0.0";
|
|
16
16
|
var V19_X_VITE = "^6.0.0";
|
|
17
17
|
var NX_X_LATEST_VITE = "^8.0.0";
|
|
18
|
-
var NX_X_LATEST_VITEST = "^
|
|
18
|
+
var NX_X_LATEST_VITEST = "^5.0.0";
|
|
19
19
|
var NX_X_LATEST_NX = "^23.0.0";
|
|
20
20
|
//#endregion
|
|
21
21
|
exports.NX_X_LATEST_NX = NX_X_LATEST_NX;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"versions.js","names":[],"sources":["../../../../../../../../../nx-plugin/src/utils/versions/ng_19_X/versions.ts"],"sourcesContent":["// V19_X\nexport const V19_X_ANALOG_JS_ROUTER = '^3.0.0-alpha.
|
|
1
|
+
{"version":3,"file":"versions.js","names":[],"sources":["../../../../../../../../../nx-plugin/src/utils/versions/ng_19_X/versions.ts"],"sourcesContent":["// V19_X\nexport const V19_X_ANALOG_JS_ROUTER = '^3.0.0-alpha.93';\nexport const V19_X_ANALOG_JS_CONTENT = '^3.0.0-alpha.93';\nexport const V19_X_MARKED = '^18.0.0';\nexport const V19_X_MARKED_GFM_HEADING_ID = '^4.1.1';\nexport const V19_X_MARKED_HIGHLIGHT = '^2.2.1';\nexport const V19_X_MARKED_MANGLE = '^1.1.10';\nexport const V19_X_PRISMJS = '^1.29.0';\n\n// devDependencies\nexport const V19_X_ANALOG_JS_PLATFORM = '^3.0.0-alpha.93';\nexport const V19_X_ANALOG_JS_VITE_PLUGIN_ANGULAR = '^3.0.0-alpha.93';\nexport const V19_X_ANALOG_JS_VITEST_ANGULAR = '^3.0.0-alpha.93';\nexport const V19_X_NX_ANGULAR = '^22.0.0';\nexport const V19_X_NX_VITE = '^22.0.0';\nexport const V19_X_JSDOM = '^22.0.0';\nexport const V19_X_VITE_TSCONFIG_PATHS = '^4.2.0';\nexport const V19_X_VITEST = '^3.0.0';\nexport const V19_X_VITE = '^6.0.0';\nexport const NX_X_LATEST_VITE = '^8.0.0';\nexport const NX_X_LATEST_VITEST = '^5.0.0';\nexport const NX_X_LATEST_NX = '^23.0.0';\n"],"mappings":";AACA,IAAa,yBAAyB;AACtC,IAAa,0BAA0B;AACvC,IAAa,eAAe;AAC5B,IAAa,8BAA8B;AAC3C,IAAa,yBAAyB;AACtC,IAAa,sBAAsB;AACnC,IAAa,gBAAgB;AAG7B,IAAa,2BAA2B;AACxC,IAAa,sCAAsC;AACnD,IAAa,iCAAiC;AAE9C,IAAa,gBAAgB;AAC7B,IAAa,cAAc;AAC3B,IAAa,4BAA4B;AACzC,IAAa,eAAe;AAC5B,IAAa,aAAa;AAC1B,IAAa,mBAAmB;AAChC,IAAa,qBAAqB;AAClC,IAAa,iBAAiB"}
|
package/src/lib/options.d.ts
CHANGED
|
@@ -30,6 +30,14 @@ export interface PrerenderOptions {
|
|
|
30
30
|
postRenderingHooks?: ((routes: PrerenderRoute) => Promise<void>)[];
|
|
31
31
|
}
|
|
32
32
|
export interface I18nOptions {
|
|
33
|
+
/** Path to the translation loader module, relative to the app root. */
|
|
34
|
+
loader?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Fixed-locale SSR workers. Automatically enabled for supported
|
|
37
|
+
* Node server builds with a loader and multiple locales. Set false to opt out.
|
|
38
|
+
* Set true to require workers and fail on unsupported configurations.
|
|
39
|
+
*/
|
|
40
|
+
workers?: boolean;
|
|
33
41
|
/**
|
|
34
42
|
* The default/source locale for the application.
|
|
35
43
|
*/
|
|
@@ -115,8 +123,16 @@ export interface Options {
|
|
|
115
123
|
i18n?: I18nOptions;
|
|
116
124
|
/** Opt-in experimental features. */
|
|
117
125
|
experimental?: {
|
|
118
|
-
/**
|
|
126
|
+
/** Opt into generated route types and typed navigation helpers. */
|
|
119
127
|
typedRouting?: boolean | import("./typed-routes-plugin.js").TypedRoutingOptions;
|
|
128
|
+
/**
|
|
129
|
+
* Opt into progressive streaming SSR. When enabled, the SSR build patches
|
|
130
|
+
* `@angular/core` with a per-`@defer` block resolution hook so
|
|
131
|
+
* `@analogjs/router`'s `renderStream` can flush the document head first and
|
|
132
|
+
* each `@defer (hydrate …)` block as it resolves on the server. Has no
|
|
133
|
+
* effect unless the server entry uses `renderStream`.
|
|
134
|
+
*/
|
|
135
|
+
streaming?: boolean;
|
|
120
136
|
};
|
|
121
137
|
}
|
|
122
138
|
export type { PrerenderContentDir, PrerenderContentFile, PrerenderSitemapConfig, SitemapConfig, SitemapEntry, SitemapExcludeRule, SitemapPriority, SitemapRouteDefinition, SitemapRouteInput, SitemapRouteSource, SitemapTransform };
|
|
@@ -6,13 +6,29 @@ import { contentPlugin } from "./content-plugin.js";
|
|
|
6
6
|
import { clearClientPageEndpointsPlugin } from "./clear-client-page-endpoint.js";
|
|
7
7
|
import { depsPlugin } from "./deps-plugin.js";
|
|
8
8
|
import { injectHTMLPlugin } from "./ssr/inject-html-plugin.js";
|
|
9
|
+
import { deferStreamingPlugin, streamingSupportedOnAngular } from "./ssr/defer-streaming-plugin.js";
|
|
9
10
|
import { serverModePlugin } from "../server-mode-plugin.js";
|
|
10
11
|
import { typedRoutes } from "./typed-routes-plugin.js";
|
|
11
12
|
import { i18nComponentRegistryPlugin } from "./i18n-component-registry-plugin.js";
|
|
12
13
|
import { analogNitroPlugin } from "./nitro/analog-nitro-plugin.js";
|
|
13
|
-
import "node:module";
|
|
14
|
-
import "node:path";
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
import { join } from "node:path";
|
|
15
16
|
//#region packages/platform/src/lib/platform-plugin.ts
|
|
17
|
+
/**
|
|
18
|
+
* The installed `@angular/core` major version, resolved from the workspace root
|
|
19
|
+
* (where the app's Angular is installed). Returns `null` when it cannot be
|
|
20
|
+
* detected, in which case streaming is not blocked and the build-time
|
|
21
|
+
* anchor-drift detection is relied on instead.
|
|
22
|
+
*/
|
|
23
|
+
function getAngularCoreMajor(workspaceRoot) {
|
|
24
|
+
try {
|
|
25
|
+
const { version } = createRequire(join(workspaceRoot, "noop.js"))("@angular/core/package.json");
|
|
26
|
+
const major = Number.parseInt(version.split(".")[0], 10);
|
|
27
|
+
return Number.isNaN(major) ? null : major;
|
|
28
|
+
} catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
16
32
|
function platformPlugin(opts = {}) {
|
|
17
33
|
applyDebugOption(opts.debug, opts.workspaceRoot);
|
|
18
34
|
const isTest = process.env.NODE_ENV === "test" || !!process.env["VITEST"];
|
|
@@ -20,6 +36,16 @@ function platformPlugin(opts = {}) {
|
|
|
20
36
|
ssr: true,
|
|
21
37
|
...opts
|
|
22
38
|
};
|
|
39
|
+
if (platformOptions.ssr && platformOptions.experimental?.streaming) {
|
|
40
|
+
const major = getAngularCoreMajor(platformOptions.workspaceRoot ?? process.cwd());
|
|
41
|
+
if (!streamingSupportedOnAngular(major)) {
|
|
42
|
+
console.warn(`[@analogjs/platform] experimental.streaming requires Angular 21+ (detected v${major}); streaming is disabled and rendering falls back to buffered SSR.`);
|
|
43
|
+
platformOptions.experimental = {
|
|
44
|
+
...platformOptions.experimental,
|
|
45
|
+
streaming: false
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
23
49
|
debugPlatform("experimental options resolved", { typedRouting: platformOptions.experimental?.typedRouting });
|
|
24
50
|
return [
|
|
25
51
|
...platformOptions.experimental?.typedRouting ? [typedRoutes({
|
|
@@ -34,14 +60,19 @@ function platformPlugin(opts = {}) {
|
|
|
34
60
|
activateDeferredDebug(command);
|
|
35
61
|
}
|
|
36
62
|
},
|
|
63
|
+
{
|
|
64
|
+
name: "@analogjs/platform-options",
|
|
65
|
+
api: { analogOptions: platformOptions }
|
|
66
|
+
},
|
|
37
67
|
...!isTest ? [analogNitroPlugin(platformOptions)] : [],
|
|
38
68
|
...platformOptions.ssr ? [...ssrBuildPlugin(), ...injectHTMLPlugin()] : [],
|
|
69
|
+
...platformOptions.ssr && platformOptions.experimental?.streaming ? [deferStreamingPlugin()] : [],
|
|
39
70
|
...!isTest ? depsPlugin(platformOptions) : [],
|
|
40
71
|
...routerPlugin(platformOptions),
|
|
41
72
|
analogIntegrationPlugin(platformOptions),
|
|
42
73
|
...contentPlugin(platformOptions?.content, platformOptions),
|
|
43
74
|
...platformOptions.i18n ? [i18nComponentRegistryPlugin()] : [],
|
|
44
|
-
...serverModePlugin(),
|
|
75
|
+
...serverModePlugin(platformOptions.entryServer),
|
|
45
76
|
clearClientPageEndpointsPlugin()
|
|
46
77
|
];
|
|
47
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-plugin.js","names":[],"sources":["../../../src/lib/platform-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { Plugin } from 'vite';\n\nimport { Options } from './options.js';\nimport {\n activateDeferredDebug,\n applyDebugOption,\n debugPlatform,\n} from './utils/debug.js';\nimport { routerPlugin } from './router-plugin.js';\nimport { analogIntegrationPlugin } from './analog-integration-plugin.js';\nimport { ssrBuildPlugin } from './ssr/ssr-build-plugin.js';\nimport { contentPlugin } from './content-plugin.js';\nimport { clearClientPageEndpointsPlugin } from './clear-client-page-endpoint.js';\nimport { depsPlugin } from './deps-plugin.js';\nimport { injectHTMLPlugin } from './ssr/inject-html-plugin.js';\nimport { serverModePlugin } from '../server-mode-plugin.js';\nimport { typedRoutes } from './typed-routes-plugin.js';\nimport { i18nComponentRegistryPlugin } from './i18n-component-registry-plugin.js';\nimport { analogNitroPlugin } from './nitro/analog-nitro-plugin.js';\n\n/**\n * The installed `@angular/core` major version, resolved from the workspace root\n * (where the app's Angular is installed). Returns `null` when it cannot be\n * detected, in which case streaming is not blocked and the build-time\n * anchor-drift detection is relied on instead.\n */\nfunction getAngularCoreMajor(workspaceRoot: string): number | null {\n try {\n const req = createRequire(join(workspaceRoot, 'noop.js'));\n const { version } = req('@angular/core/package.json') as {\n version: string;\n };\n const major = Number.parseInt(version.split('.')[0], 10);\n return Number.isNaN(major) ? null : major;\n } catch {\n return null;\n }\n}\n\nexport function platformPlugin(opts: Options = {}): Plugin[] {\n applyDebugOption(opts.debug, opts.workspaceRoot);\n\n const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];\n const { ...platformOptions } = {\n ssr: true,\n ...opts,\n };\n\n debugPlatform('experimental options resolved', {\n typedRouting: platformOptions.experimental?.typedRouting,\n });\n\n return [\n ...(platformOptions.experimental?.typedRouting\n ? [\n typedRoutes({\n ...(typeof platformOptions.experimental.typedRouting === 'object'\n ? platformOptions.experimental.typedRouting\n : {}),\n workspaceRoot: platformOptions.workspaceRoot,\n additionalPagesDirs: platformOptions.additionalPagesDirs,\n additionalContentDirs: platformOptions.additionalContentDirs,\n }),\n ]\n : []),\n {\n name: 'analogjs-debug-activate',\n config(_, { command }) {\n activateDeferredDebug(command);\n },\n },\n ...(!isTest ? [analogNitroPlugin(platformOptions)] : []),\n ...(platformOptions.ssr\n ? [...ssrBuildPlugin(), ...injectHTMLPlugin()]\n : []),\n ...(!isTest ? depsPlugin(platformOptions) : []),\n ...routerPlugin(platformOptions),\n analogIntegrationPlugin(platformOptions),\n ...contentPlugin(platformOptions?.content, platformOptions),\n ...(platformOptions.i18n ? [i18nComponentRegistryPlugin()] : []),\n ...serverModePlugin(),\n clearClientPageEndpointsPlugin(),\n ];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform-plugin.js","names":[],"sources":["../../../src/lib/platform-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { Plugin } from 'vite';\n\nimport { Options } from './options.js';\nimport {\n activateDeferredDebug,\n applyDebugOption,\n debugPlatform,\n} from './utils/debug.js';\nimport { routerPlugin } from './router-plugin.js';\nimport { analogIntegrationPlugin } from './analog-integration-plugin.js';\nimport { ssrBuildPlugin } from './ssr/ssr-build-plugin.js';\nimport { contentPlugin } from './content-plugin.js';\nimport { clearClientPageEndpointsPlugin } from './clear-client-page-endpoint.js';\nimport { depsPlugin } from './deps-plugin.js';\nimport { injectHTMLPlugin } from './ssr/inject-html-plugin.js';\nimport {\n deferStreamingPlugin,\n MIN_STREAMING_ANGULAR_MAJOR,\n streamingSupportedOnAngular,\n} from './ssr/defer-streaming-plugin.js';\nimport { serverModePlugin } from '../server-mode-plugin.js';\nimport { typedRoutes } from './typed-routes-plugin.js';\nimport { i18nComponentRegistryPlugin } from './i18n-component-registry-plugin.js';\nimport { analogNitroPlugin } from './nitro/analog-nitro-plugin.js';\n\n/**\n * The installed `@angular/core` major version, resolved from the workspace root\n * (where the app's Angular is installed). Returns `null` when it cannot be\n * detected, in which case streaming is not blocked and the build-time\n * anchor-drift detection is relied on instead.\n */\nfunction getAngularCoreMajor(workspaceRoot: string): number | null {\n try {\n const req = createRequire(join(workspaceRoot, 'noop.js'));\n const { version } = req('@angular/core/package.json') as {\n version: string;\n };\n const major = Number.parseInt(version.split('.')[0], 10);\n return Number.isNaN(major) ? null : major;\n } catch {\n return null;\n }\n}\n\nexport function platformPlugin(opts: Options = {}): Plugin[] {\n applyDebugOption(opts.debug, opts.workspaceRoot);\n\n const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];\n const { ...platformOptions } = {\n ssr: true,\n ...opts,\n };\n\n // Streaming patches the compiled @angular/core, which needs a supported\n // Angular version. Turn it off otherwise so the renderer stays buffered.\n if (platformOptions.ssr && platformOptions.experimental?.streaming) {\n const major = getAngularCoreMajor(\n platformOptions.workspaceRoot ?? process.cwd(),\n );\n if (!streamingSupportedOnAngular(major)) {\n console.warn(\n `[@analogjs/platform] experimental.streaming requires Angular ` +\n `${MIN_STREAMING_ANGULAR_MAJOR}+ (detected v${major}); streaming is ` +\n `disabled and rendering falls back to buffered SSR.`,\n );\n platformOptions.experimental = {\n ...platformOptions.experimental,\n streaming: false,\n };\n }\n }\n\n debugPlatform('experimental options resolved', {\n typedRouting: platformOptions.experimental?.typedRouting,\n });\n\n return [\n ...(platformOptions.experimental?.typedRouting\n ? [\n typedRoutes({\n ...(typeof platformOptions.experimental.typedRouting === 'object'\n ? platformOptions.experimental.typedRouting\n : {}),\n workspaceRoot: platformOptions.workspaceRoot,\n additionalPagesDirs: platformOptions.additionalPagesDirs,\n additionalContentDirs: platformOptions.additionalContentDirs,\n }),\n ]\n : []),\n {\n name: 'analogjs-debug-activate',\n config(_, { command }) {\n activateDeferredDebug(command);\n },\n },\n // `nitro()` from `@analogjs/vite-plugin-nitro` reads these as its defaults.\n {\n name: '@analogjs/platform-options',\n api: { analogOptions: platformOptions },\n },\n ...(!isTest ? [analogNitroPlugin(platformOptions)] : []),\n ...(platformOptions.ssr\n ? [...ssrBuildPlugin(), ...injectHTMLPlugin()]\n : []),\n ...(platformOptions.ssr && platformOptions.experimental?.streaming\n ? [deferStreamingPlugin()]\n : []),\n ...(!isTest ? depsPlugin(platformOptions) : []),\n ...routerPlugin(platformOptions),\n analogIntegrationPlugin(platformOptions),\n ...contentPlugin(platformOptions?.content, platformOptions),\n ...(platformOptions.i18n ? [i18nComponentRegistryPlugin()] : []),\n ...serverModePlugin(platformOptions.entryServer),\n clearClientPageEndpointsPlugin(),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiCA,SAAS,oBAAoB,eAAsC;AACjE,KAAI;EAEF,MAAM,EAAE,YADI,cAAc,KAAK,eAAe,UAAU,CAAC,CACjC,6BAA6B;EAGrD,MAAM,QAAQ,OAAO,SAAS,QAAQ,MAAM,IAAI,CAAC,IAAI,GAAG;AACxD,SAAO,OAAO,MAAM,MAAM,GAAG,OAAO;SAC9B;AACN,SAAO;;;AAIX,SAAgB,eAAe,OAAgB,EAAE,EAAY;AAC3D,kBAAiB,KAAK,OAAO,KAAK,cAAc;CAEhD,MAAM,SAAA,QAAA,IAAA,aAAqC,UAAU,CAAC,CAAC,QAAQ,IAAI;CACnE,MAAM,EAAE,GAAG,oBAAoB;EAC7B,KAAK;EACL,GAAG;EACJ;AAID,KAAI,gBAAgB,OAAO,gBAAgB,cAAc,WAAW;EAClE,MAAM,QAAQ,oBACZ,gBAAgB,iBAAiB,QAAQ,KAAK,CAC/C;AACD,MAAI,CAAC,4BAA4B,MAAM,EAAE;AACvC,WAAQ,KACN,+EACgD,MAAM,oEAEvD;AACD,mBAAgB,eAAe;IAC7B,GAAG,gBAAgB;IACnB,WAAW;IACZ;;;AAIL,eAAc,iCAAiC,EAC7C,cAAc,gBAAgB,cAAc,cAC7C,CAAC;AAEF,QAAO;EACL,GAAI,gBAAgB,cAAc,eAC9B,CACE,YAAY;GACV,GAAI,OAAO,gBAAgB,aAAa,iBAAiB,WACrD,gBAAgB,aAAa,eAC7B,EAAE;GACN,eAAe,gBAAgB;GAC/B,qBAAqB,gBAAgB;GACrC,uBAAuB,gBAAgB;GACxC,CAAC,CACH,GACD,EAAE;EACN;GACE,MAAM;GACN,OAAO,GAAG,EAAE,WAAW;AACrB,0BAAsB,QAAQ;;GAEjC;EAED;GACE,MAAM;GACN,KAAK,EAAE,eAAe,iBAAiB;GACxC;EACD,GAAI,CAAC,SAAS,CAAC,kBAAkB,gBAAgB,CAAC,GAAG,EAAE;EACvD,GAAI,gBAAgB,MAChB,CAAC,GAAG,gBAAgB,EAAE,GAAG,kBAAkB,CAAC,GAC5C,EAAE;EACN,GAAI,gBAAgB,OAAO,gBAAgB,cAAc,YACrD,CAAC,sBAAsB,CAAC,GACxB,EAAE;EACN,GAAI,CAAC,SAAS,WAAW,gBAAgB,GAAG,EAAE;EAC9C,GAAG,aAAa,gBAAgB;EAChC,wBAAwB,gBAAgB;EACxC,GAAG,cAAc,iBAAiB,SAAS,gBAAgB;EAC3D,GAAI,gBAAgB,OAAO,CAAC,6BAA6B,CAAC,GAAG,EAAE;EAC/D,GAAG,iBAAiB,gBAAgB,YAAY;EAChD,gCAAgC;EACjC"}
|
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
-
/**
|
|
3
|
-
* Minimum Angular major whose compiled `@angular/core` FESM matches the
|
|
4
|
-
* streaming patch anchors. Incremental hydration is a stable public API from
|
|
5
|
-
* v20 (`withIncrementalHydration`, `@publicApi 20.0`), but v20's FESM inlines
|
|
6
|
-
* the injection anchor's `DeferBlockStateEnd` profiler event to its numeric
|
|
7
|
-
* ordinal, whereas v21+ keeps the symbolic `ProfilerEvent.DeferBlockStateEnd`
|
|
8
|
-
* form the anchor matches on. Keying on the literal ordinal would be fragile
|
|
9
|
-
* (enum values shift between versions), so v21 is the floor.
|
|
10
|
-
*/
|
|
2
|
+
/** Minimum Angular major qualified for streaming; the actual runtime shape is checked below. */
|
|
11
3
|
export declare const MIN_STREAMING_ANGULAR_MAJOR = 21;
|
|
12
4
|
/**
|
|
13
5
|
* Whether the streaming SSR patch can be applied to the installed Angular.
|
|
@@ -16,33 +8,9 @@ export declare const MIN_STREAMING_ANGULAR_MAJOR = 21;
|
|
|
16
8
|
* build time and falls back to buffered rendering.
|
|
17
9
|
*/
|
|
18
10
|
export declare function streamingSupportedOnAngular(major: number | null): boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Pure transform that injects the streaming-SSR per-block resolution hook into
|
|
21
|
-
* `@angular/core`'s compiled output. It is the same class of transform as
|
|
22
|
-
* `i18nDefRegistryPlugin` in ./ssr-build-plugin — a string patch of Angular's
|
|
23
|
-
* bundle applied only to SSR builds. Exported separately so it can be unit
|
|
24
|
-
* tested against a bundle string.
|
|
25
|
-
*
|
|
26
|
-
* Two edits, both keyed on single-occurrence anchors in the module that holds
|
|
27
|
-
* the defer runtime:
|
|
28
|
-
* 1. Inside `applyDeferBlockState`, fire `globalThis.__analogSsrDeferCapture`
|
|
29
|
-
* when a `@defer` block reaches `Complete` on the server, passing the
|
|
30
|
-
* block's live `lContainer` — this is the per-block resolution signal a
|
|
31
|
-
* streaming renderer consumes.
|
|
32
|
-
* 2. Expose `collectNativeNodesInLContainer` via `globalThis.__analogSsrInternals`
|
|
33
|
-
* so the renderer can serialize a block's subtree.
|
|
34
|
-
*
|
|
35
|
-
* Returns `null` when the module is not the one carrying the defer runtime, so
|
|
36
|
-
* it is a no-op on every other Angular module.
|
|
37
|
-
*/
|
|
11
|
+
/** Inject capture before the named defer function's final profiler call, preserving its original source. */
|
|
38
12
|
export declare function injectDeferStreamingHook(code: string): string | null;
|
|
39
|
-
/**
|
|
40
|
-
* Classify an `@angular/core` module for the streaming patch. The patch anchors
|
|
41
|
-
* on internal symbol names, so when Angular changes those the transform would
|
|
42
|
-
* otherwise become a silent no-op and streaming would degrade to buffered with
|
|
43
|
-
* no signal. This distinguishes "not the target module" (skip quietly) from
|
|
44
|
-
* "this IS the `@defer` runtime module but the anchors drifted" (worth warning).
|
|
45
|
-
*/
|
|
13
|
+
/** Inspect the named function's final profiler call without depending on enum ordinals. */
|
|
46
14
|
export declare function inspectAngularCoreModule(code: string): {
|
|
47
15
|
kind: "not-target";
|
|
48
16
|
} | {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { parseSync } from "oxc-parser";
|
|
2
|
+
/**
|
|
3
|
+
* Whether the streaming SSR patch can be applied to the installed Angular.
|
|
4
|
+
* A `null` major (version undetectable) returns `true`: don't block on a failed
|
|
5
|
+
* detection — the plugin's anchor-drift detection catches a real mismatch at
|
|
6
|
+
* build time and falls back to buffered rendering.
|
|
7
|
+
*/
|
|
8
|
+
function streamingSupportedOnAngular(major) {
|
|
9
|
+
return major === null || major >= 21;
|
|
10
|
+
}
|
|
11
|
+
function analyzeDeferRuntime(code) {
|
|
12
|
+
if (!code.includes("function applyDeferBlockState(")) return { kind: "not-target" };
|
|
13
|
+
const parsed = parseSync("angular-core.mjs", code);
|
|
14
|
+
if (parsed.errors.length) return {
|
|
15
|
+
kind: "drifted",
|
|
16
|
+
reason: "invalid Angular core JavaScript"
|
|
17
|
+
};
|
|
18
|
+
const fn = parsed.program.body.find((node) => node.type === "FunctionDeclaration" && node.id?.name === "applyDeferBlockState");
|
|
19
|
+
if (!fn || fn.type !== "FunctionDeclaration" || !fn.body) return { kind: "not-target" };
|
|
20
|
+
if (fn.params.map((param) => param.type === "Identifier" ? param.name : "").join(",") !== "newState,lDetails,lContainer,tNode,hostLView") return {
|
|
21
|
+
kind: "drifted",
|
|
22
|
+
reason: "changed applyDeferBlockState parameters"
|
|
23
|
+
};
|
|
24
|
+
if (!parsed.program.body.some((node) => node.type === "FunctionDeclaration" && node.id?.name === "collectNativeNodesInLContainer")) return {
|
|
25
|
+
kind: "drifted",
|
|
26
|
+
reason: "missing collectNativeNodesInLContainer"
|
|
27
|
+
};
|
|
28
|
+
const offset = profilerEndOffset(fn.body.body[fn.body.body.length - 1]);
|
|
29
|
+
return offset === void 0 ? {
|
|
30
|
+
kind: "drifted",
|
|
31
|
+
reason: "missing DeferBlockStateEnd profiler anchor"
|
|
32
|
+
} : {
|
|
33
|
+
kind: "patchable",
|
|
34
|
+
offset
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function profilerEndOffset(statement) {
|
|
38
|
+
if (statement?.type !== "ExpressionStatement" || statement.expression.type !== "CallExpression") return;
|
|
39
|
+
const call = statement.expression;
|
|
40
|
+
if (call.callee.type !== "Identifier" || call.callee.name !== "profiler" || call.arguments.length !== 1) return;
|
|
41
|
+
return isEndEvent(call.arguments[0]) ? statement.start : void 0;
|
|
42
|
+
}
|
|
43
|
+
function isEndEvent(event) {
|
|
44
|
+
if (event?.type === "Literal") return typeof event.value === "number";
|
|
45
|
+
return event?.type === "MemberExpression" && !event.computed && event.object.type === "Identifier" && event.object.name === "ProfilerEvent" && event.property.type === "Identifier" && event.property.name === "DeferBlockStateEnd";
|
|
46
|
+
}
|
|
47
|
+
function patchDeferRuntime(code, offset) {
|
|
48
|
+
if (code.includes("globalThis.__analogSsrDeferCapture({")) return code;
|
|
49
|
+
return code.slice(0, offset) + "try { if (newState === DeferBlockState.Complete && typeof ngServerMode !== 'undefined' && ngServerMode && typeof globalThis.__analogSsrDeferCapture === 'function') { globalThis.__analogSsrDeferCapture({ ssrUniqueId: lDetails[SSR_UNIQUE_ID], lContainer, hostLView }); } } catch (e) {}\n " + code.slice(offset) + "\nglobalThis.__analogSsrInternals = Object.assign(globalThis.__analogSsrInternals || {}, { collectNativeNodesInLContainer });\n";
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Vite plugin that applies {@link injectDeferStreamingHook} to `@angular/core`
|
|
53
|
+
* during SSR builds, so `@analogjs/router`'s `renderStream` can flush `@defer`
|
|
54
|
+
* blocks as they resolve on the server — without hand-patching node_modules.
|
|
55
|
+
*
|
|
56
|
+
* Only active for SSR. Mirrors the enforce/filter/ssr-gate shape of
|
|
57
|
+
* `i18nDefRegistryPlugin`. If the `@defer` runtime module is found but its
|
|
58
|
+
* anchors have drifted (Angular changed internals), or if it is never
|
|
59
|
+
* encountered at all, the plugin warns rather than silently producing a build
|
|
60
|
+
* that falls back to buffered rendering.
|
|
61
|
+
*/
|
|
62
|
+
function deferStreamingPlugin() {
|
|
63
|
+
const applied = /* @__PURE__ */ new Set();
|
|
64
|
+
const warnedDrift = /* @__PURE__ */ new Set();
|
|
65
|
+
return {
|
|
66
|
+
name: "analogjs-defer-streaming",
|
|
67
|
+
enforce: "post",
|
|
68
|
+
config() {
|
|
69
|
+
return {
|
|
70
|
+
ssr: { noExternal: ["@angular/core"] },
|
|
71
|
+
environments: { ssr: { optimizeDeps: { exclude: ["@angular/core"] } } }
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
transform: {
|
|
75
|
+
filter: { id: /\/@angular\/core\// },
|
|
76
|
+
handler(code, _id, options) {
|
|
77
|
+
if (!options?.ssr) return;
|
|
78
|
+
const environment = this.environment.name;
|
|
79
|
+
const info = analyzeDeferRuntime(code);
|
|
80
|
+
if (info.kind === "not-target") return;
|
|
81
|
+
if (info.kind === "drifted") {
|
|
82
|
+
if (!warnedDrift.has(environment)) {
|
|
83
|
+
warnedDrift.add(environment);
|
|
84
|
+
this.warn(`experimental streaming SSR: found @angular/core's @defer runtime but could not apply the resolution hook (${info.reason}). The installed Angular version likely changed internals the patch depends on; streaming will fall back to buffered rendering.`);
|
|
85
|
+
}
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const out = patchDeferRuntime(code, info.offset);
|
|
89
|
+
applied.add(environment);
|
|
90
|
+
return { code: out };
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
buildEnd() {
|
|
94
|
+
const environment = this.environment.name;
|
|
95
|
+
if (environment !== "ssr") return;
|
|
96
|
+
if (!applied.has(environment) && !warnedDrift.has(environment)) this.warn("experimental streaming SSR is enabled but @angular/core's @defer runtime module was never encountered during the SSR build, so the resolution hook was not injected. Streaming will fall back to buffered rendering.");
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { deferStreamingPlugin, streamingSupportedOnAngular };
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=defer-streaming-plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer-streaming-plugin.js","names":[],"sources":["../../../../src/lib/ssr/defer-streaming-plugin.ts"],"sourcesContent":["import type { Plugin } from 'vite';\nimport { parseSync, type Argument, type Statement } from 'oxc-parser';\n\n/** Minimum Angular major qualified for streaming; the actual runtime shape is checked below. */\nexport const MIN_STREAMING_ANGULAR_MAJOR = 21;\n\n/**\n * Whether the streaming SSR patch can be applied to the installed Angular.\n * A `null` major (version undetectable) returns `true`: don't block on a failed\n * detection — the plugin's anchor-drift detection catches a real mismatch at\n * build time and falls back to buffered rendering.\n */\nexport function streamingSupportedOnAngular(major: number | null): boolean {\n return major === null || major >= MIN_STREAMING_ANGULAR_MAJOR;\n}\n\ntype DeferAnalysis =\n | { kind: 'not-target' }\n | { kind: 'patchable'; offset: number }\n | { kind: 'drifted'; reason: string };\n\nfunction analyzeDeferRuntime(code: string): DeferAnalysis {\n if (!code.includes('function applyDeferBlockState('))\n return { kind: 'not-target' };\n const parsed = parseSync('angular-core.mjs', code);\n if (parsed.errors.length)\n return { kind: 'drifted', reason: 'invalid Angular core JavaScript' };\n const fn = parsed.program.body.find(\n (node) =>\n node.type === 'FunctionDeclaration' &&\n node.id?.name === 'applyDeferBlockState',\n );\n if (!fn || fn.type !== 'FunctionDeclaration' || !fn.body)\n return { kind: 'not-target' };\n const names = fn.params\n .map((param) => (param.type === 'Identifier' ? param.name : ''))\n .join(',');\n if (names !== 'newState,lDetails,lContainer,tNode,hostLView')\n return {\n kind: 'drifted',\n reason: 'changed applyDeferBlockState parameters',\n };\n const collector = parsed.program.body.some(\n (node) =>\n node.type === 'FunctionDeclaration' &&\n node.id?.name === 'collectNativeNodesInLContainer',\n );\n if (!collector)\n return {\n kind: 'drifted',\n reason: 'missing collectNativeNodesInLContainer',\n };\n const offset = profilerEndOffset(fn.body.body[fn.body.body.length - 1]);\n return offset === undefined\n ? { kind: 'drifted', reason: 'missing DeferBlockStateEnd profiler anchor' }\n : { kind: 'patchable', offset };\n}\n\nfunction profilerEndOffset(\n statement: Statement | undefined,\n): number | undefined {\n if (\n statement?.type !== 'ExpressionStatement' ||\n statement.expression.type !== 'CallExpression'\n )\n return;\n const call = statement.expression;\n if (\n call.callee.type !== 'Identifier' ||\n call.callee.name !== 'profiler' ||\n call.arguments.length !== 1\n )\n return;\n return isEndEvent(call.arguments[0]) ? statement.start : undefined;\n}\n\nfunction isEndEvent(event: Argument | undefined): boolean {\n if (event?.type === 'Literal') return typeof event.value === 'number';\n return (\n event?.type === 'MemberExpression' &&\n !event.computed &&\n event.object.type === 'Identifier' &&\n event.object.name === 'ProfilerEvent' &&\n event.property.type === 'Identifier' &&\n event.property.name === 'DeferBlockStateEnd'\n );\n}\n\nfunction patchDeferRuntime(code: string, offset: number): string {\n if (code.includes('globalThis.__analogSsrDeferCapture({')) return code;\n const capture =\n `try { if (newState === DeferBlockState.Complete && ` +\n `typeof ngServerMode !== 'undefined' && ngServerMode && ` +\n `typeof globalThis.__analogSsrDeferCapture === 'function') { ` +\n `globalThis.__analogSsrDeferCapture({ ssrUniqueId: lDetails[SSR_UNIQUE_ID], lContainer, hostLView }); } } catch (e) {}\\n `;\n return (\n code.slice(0, offset) +\n capture +\n code.slice(offset) +\n '\\nglobalThis.__analogSsrInternals = Object.assign(globalThis.__analogSsrInternals || {}, { collectNativeNodesInLContainer });\\n'\n );\n}\n\n/** Inject capture before the named defer function's final profiler call, preserving its original source. */\nexport function injectDeferStreamingHook(code: string): string | null {\n const info = analyzeDeferRuntime(code);\n return info.kind === 'patchable'\n ? patchDeferRuntime(code, info.offset)\n : null;\n}\n\n/** Inspect the named function's final profiler call without depending on enum ordinals. */\nexport function inspectAngularCoreModule(\n code: string,\n):\n | { kind: 'not-target' }\n | { kind: 'patchable' }\n | { kind: 'drifted'; reason: string } {\n const info = analyzeDeferRuntime(code);\n return info.kind === 'patchable' ? { kind: 'patchable' } : info;\n}\n\n/**\n * Vite plugin that applies {@link injectDeferStreamingHook} to `@angular/core`\n * during SSR builds, so `@analogjs/router`'s `renderStream` can flush `@defer`\n * blocks as they resolve on the server — without hand-patching node_modules.\n *\n * Only active for SSR. Mirrors the enforce/filter/ssr-gate shape of\n * `i18nDefRegistryPlugin`. If the `@defer` runtime module is found but its\n * anchors have drifted (Angular changed internals), or if it is never\n * encountered at all, the plugin warns rather than silently producing a build\n * that falls back to buffered rendering.\n */\nexport function deferStreamingPlugin(): Plugin {\n const applied = new Set<string>();\n const warnedDrift = new Set<string>();\n return {\n name: 'analogjs-defer-streaming',\n enforce: 'post',\n config() {\n return {\n ssr: { noExternal: ['@angular/core'] },\n environments: { ssr: { optimizeDeps: { exclude: ['@angular/core'] } } },\n };\n },\n transform: {\n filter: {\n id: /\\/@angular\\/core\\//,\n },\n handler(code, _id, options) {\n if (!options?.ssr) return;\n const environment = this.environment.name;\n const info = analyzeDeferRuntime(code);\n if (info.kind === 'not-target') return;\n if (info.kind === 'drifted') {\n if (!warnedDrift.has(environment)) {\n warnedDrift.add(environment);\n this.warn(\n `experimental streaming SSR: found @angular/core's @defer runtime ` +\n `but could not apply the resolution hook (${info.reason}). The ` +\n `installed Angular version likely changed internals the patch ` +\n `depends on; streaming will fall back to buffered rendering.`,\n );\n }\n return;\n }\n const out = patchDeferRuntime(code, info.offset);\n applied.add(environment);\n return { code: out };\n },\n },\n buildEnd() {\n // Require coverage from the SSR service. A later Nitro rebundle may\n // also encounter Angular modules imported by endpoint handlers.\n const environment = this.environment.name;\n if (environment !== 'ssr') return;\n if (!applied.has(environment) && !warnedDrift.has(environment)) {\n this.warn(\n `experimental streaming SSR is enabled but @angular/core's @defer ` +\n `runtime module was never encountered during the SSR build, so the ` +\n `resolution hook was not injected. Streaming will fall back to ` +\n `buffered rendering.`,\n );\n }\n },\n };\n}\n"],"mappings":";;;;;;;AAYA,SAAgB,4BAA4B,OAA+B;AACzE,QAAO,UAAU,QAAQ,SAAA;;AAQ3B,SAAS,oBAAoB,MAA6B;AACxD,KAAI,CAAC,KAAK,SAAS,iCAAiC,CAClD,QAAO,EAAE,MAAM,cAAc;CAC/B,MAAM,SAAS,UAAU,oBAAoB,KAAK;AAClD,KAAI,OAAO,OAAO,OAChB,QAAO;EAAE,MAAM;EAAW,QAAQ;EAAmC;CACvE,MAAM,KAAK,OAAO,QAAQ,KAAK,MAC5B,SACC,KAAK,SAAS,yBACd,KAAK,IAAI,SAAS,uBACrB;AACD,KAAI,CAAC,MAAM,GAAG,SAAS,yBAAyB,CAAC,GAAG,KAClD,QAAO,EAAE,MAAM,cAAc;AAI/B,KAHc,GAAG,OACd,KAAK,UAAW,MAAM,SAAS,eAAe,MAAM,OAAO,GAAI,CAC/D,KAAK,IAAI,KACE,+CACZ,QAAO;EACL,MAAM;EACN,QAAQ;EACT;AAMH,KAAI,CALc,OAAO,QAAQ,KAAK,MACnC,SACC,KAAK,SAAS,yBACd,KAAK,IAAI,SAAS,iCACrB,CAEC,QAAO;EACL,MAAM;EACN,QAAQ;EACT;CACH,MAAM,SAAS,kBAAkB,GAAG,KAAK,KAAK,GAAG,KAAK,KAAK,SAAS,GAAG;AACvE,QAAO,WAAW,KAAA,IACd;EAAE,MAAM;EAAW,QAAQ;EAA8C,GACzE;EAAE,MAAM;EAAa;EAAQ;;AAGnC,SAAS,kBACP,WACoB;AACpB,KACE,WAAW,SAAS,yBACpB,UAAU,WAAW,SAAS,iBAE9B;CACF,MAAM,OAAO,UAAU;AACvB,KACE,KAAK,OAAO,SAAS,gBACrB,KAAK,OAAO,SAAS,cACrB,KAAK,UAAU,WAAW,EAE1B;AACF,QAAO,WAAW,KAAK,UAAU,GAAG,GAAG,UAAU,QAAQ,KAAA;;AAG3D,SAAS,WAAW,OAAsC;AACxD,KAAI,OAAO,SAAS,UAAW,QAAO,OAAO,MAAM,UAAU;AAC7D,QACE,OAAO,SAAS,sBAChB,CAAC,MAAM,YACP,MAAM,OAAO,SAAS,gBACtB,MAAM,OAAO,SAAS,mBACtB,MAAM,SAAS,SAAS,gBACxB,MAAM,SAAS,SAAS;;AAI5B,SAAS,kBAAkB,MAAc,QAAwB;AAC/D,KAAI,KAAK,SAAS,uCAAuC,CAAE,QAAO;AAMlE,QACE,KAAK,MAAM,GAAG,OAAO,GALrB,oSAOA,KAAK,MAAM,OAAO,GAClB;;;;;;;;;;;;;AAkCJ,SAAgB,uBAA+B;CAC7C,MAAM,0BAAU,IAAI,KAAa;CACjC,MAAM,8BAAc,IAAI,KAAa;AACrC,QAAO;EACL,MAAM;EACN,SAAS;EACT,SAAS;AACP,UAAO;IACL,KAAK,EAAE,YAAY,CAAC,gBAAgB,EAAE;IACtC,cAAc,EAAE,KAAK,EAAE,cAAc,EAAE,SAAS,CAAC,gBAAgB,EAAE,EAAE,EAAE;IACxE;;EAEH,WAAW;GACT,QAAQ,EACN,IAAI,sBACL;GACD,QAAQ,MAAM,KAAK,SAAS;AAC1B,QAAI,CAAC,SAAS,IAAK;IACnB,MAAM,cAAc,KAAK,YAAY;IACrC,MAAM,OAAO,oBAAoB,KAAK;AACtC,QAAI,KAAK,SAAS,aAAc;AAChC,QAAI,KAAK,SAAS,WAAW;AAC3B,SAAI,CAAC,YAAY,IAAI,YAAY,EAAE;AACjC,kBAAY,IAAI,YAAY;AAC5B,WAAK,KACH,6GAC8C,KAAK,OAAO,iIAG3D;;AAEH;;IAEF,MAAM,MAAM,kBAAkB,MAAM,KAAK,OAAO;AAChD,YAAQ,IAAI,YAAY;AACxB,WAAO,EAAE,MAAM,KAAK;;GAEvB;EACD,WAAW;GAGT,MAAM,cAAc,KAAK,YAAY;AACrC,OAAI,gBAAgB,MAAO;AAC3B,OAAI,CAAC,QAAQ,IAAI,YAAY,IAAI,CAAC,YAAY,IAAI,YAAY,CAC5D,MAAK,KACH,uNAID;;EAGN"}
|
|
@@ -23,4 +23,4 @@ export declare function ssrBuildPlugin(): vite.Plugin[];
|
|
|
23
23
|
* Only active when the platform's `i18n` option is configured.
|
|
24
24
|
* Only transforms `@angular/core` modules in SSR builds.
|
|
25
25
|
*/
|
|
26
|
-
export declare function i18nDefRegistryPlugin(): Plugin;
|
|
26
|
+
export declare function i18nDefRegistryPlugin(): vite.Plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-build-plugin.js","names":[],"sources":["../../../../src/lib/ssr/ssr-build-plugin.ts"],"sourcesContent":["import * as vite from 'vite';\n\n/**\n * SSR build patches for Angular platform-server, Zone.js, and Domino.\n *\n * **Why each patch exists:**\n * - zone-node: removes a `const global = globalThis` alias that shadows the\n * real global in strict mode.\n * - platform-server: rewrites `xhr2.XMLHttpRequest` for CJS/ESM compat and\n * replaces bare `global` references with `globalThis`.\n * - xhr2: strips Node-specific `os`/`process` references for SSR bundling.\n * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.\n */\nexport function ssrBuildPlugin(): vite.Plugin[] {\n const plugins: vite.Plugin[] = [\n {\n name: 'analogjs-ssr-build-plugin',\n apply: 'build',\n config() {\n return {\n ssr: {\n noExternal: ['xhr2'],\n },\n };\n },\n transform: {\n filter: {\n id: /zone-node|platform-server|xhr2\\.js|domino\\/lib\\/sloppy\\.js/,\n },\n handler(code, id) {\n if (\n id.includes('zone-node') &&\n code.includes('const global = globalThis;')\n ) {\n return {\n code: code.replace('const global = globalThis;', ''),\n };\n }\n\n if (id.includes('platform-server')) {\n let result = code.replace(\n 'new xhr2.XMLHttpRequest',\n 'new (xhr2.default.XMLHttpRequest || xhr2.default)',\n );\n\n // Narrowly scoped text replacement of the bare `global`\n // identifier. Matching `global.`, `global,` and ` global[`\n // targets the known occurrences in the @angular/platform-server\n // bundle while leaving strings, comments and asset paths that\n // merely contain the word `global` untouched (see #2426).\n result = result\n .replaceAll('global.', 'globalThis.')\n .replaceAll('global,', 'globalThis,')\n .replaceAll(' global[', ' globalThis[');\n\n return { code: result };\n }\n\n if (id.includes(vite.normalizePath('xhr2.js'))) {\n return {\n code: code\n .replace('os.type()', `''`)\n .replace('os.arch()', `''`)\n .replace('process.versions.node', `'node'`)\n .replace('process.versions.v8', `'v8'`),\n };\n }\n\n if (id.includes(vite.normalizePath('domino/lib/sloppy.js'))) {\n return {\n code: code.replace(/with\\(/gi, 'if('),\n };\n }\n\n return;\n },\n },\n },\n ];\n\n return plugins;\n}\n\n/**\n * Vite plugin that patches `@angular/core`'s `getComponentId()` to\n * mirror every compiled component definition to a global Set, bypassing\n * the `ngServerMode` guard that normally prevents registration on the\n * server. The set lives at `globalThis.__ngComponentDefs` and is read by\n * `@analogjs/router`'s SSR render function to null cached `tView`\n * objects between requests so that `$localize` tagged templates in\n * `consts()` re-evaluate with the freshly loaded translations.\n *\n * Only active when the platform's `i18n` option is configured.\n * Only transforms `@angular/core` modules in SSR builds.\n */\nexport function i18nDefRegistryPlugin(): Plugin {\n const DETECT_MARKER = 'GENERATED_COMP_IDS.set(compId, componentDef.type);';\n const RETURN_STMT = 'return compId;\\n}';\n\n return {\n name: 'analogjs-i18n-def-registry',\n enforce: 'post',\n\n transform: {\n filter: {\n id: /\\/@angular\\/core\\//,\n },\n handler(code, id, options) {\n if (!options?.ssr) return;\n if (!code.includes(DETECT_MARKER)) return;\n\n return {\n code: code.replace(\n RETURN_STMT,\n '(globalThis.__ngComponentDefs ??= new Set()).add(componentDef);\\n' +\n RETURN_STMT,\n ),\n };\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,iBAAgC;AAmE9C,QAlE+B,CAC7B;EACE,MAAM;EACN,OAAO;EACP,SAAS;AACP,UAAO,EACL,KAAK,EACH,YAAY,CAAC,OAAO,EACrB,EACF;;EAEH,WAAW;GACT,QAAQ,EACN,IAAI,8DACL;GACD,QAAQ,MAAM,IAAI;AAChB,QACE,GAAG,SAAS,YAAY,IACxB,KAAK,SAAS,6BAA6B,CAE3C,QAAO,EACL,MAAM,KAAK,QAAQ,8BAA8B,GAAG,EACrD;AAGH,QAAI,GAAG,SAAS,kBAAkB,EAAE;KAClC,IAAI,SAAS,KAAK,QAChB,2BACA,oDACD;AAOD,cAAS,OACN,WAAW,WAAW,cAAc,CACpC,WAAW,WAAW,cAAc,CACpC,WAAW,YAAY,eAAe;AAEzC,YAAO,EAAE,MAAM,QAAQ;;AAGzB,QAAI,GAAG,SAAS,KAAK,cAAc,UAAU,CAAC,CAC5C,QAAO,EACL,MAAM,KACH,QAAQ,aAAa,KAAK,CAC1B,QAAQ,aAAa,KAAK,CAC1B,QAAQ,yBAAyB,SAAS,CAC1C,QAAQ,uBAAuB,OAAO,EAC1C;AAGH,QAAI,GAAG,SAAS,KAAK,cAAc,uBAAuB,CAAC,CACzD,QAAO,EACL,MAAM,KAAK,QAAQ,YAAY,MAAM,EACtC;;GAKN;EACF,CACF"}
|
|
1
|
+
{"version":3,"file":"ssr-build-plugin.js","names":[],"sources":["../../../../src/lib/ssr/ssr-build-plugin.ts"],"sourcesContent":["import * as vite from 'vite';\n\n/**\n * SSR build patches for Angular platform-server, Zone.js, and Domino.\n *\n * **Why each patch exists:**\n * - zone-node: removes a `const global = globalThis` alias that shadows the\n * real global in strict mode.\n * - platform-server: rewrites `xhr2.XMLHttpRequest` for CJS/ESM compat and\n * replaces bare `global` references with `globalThis`.\n * - xhr2: strips Node-specific `os`/`process` references for SSR bundling.\n * - domino/sloppy.js: replaces `with()` statements that are illegal in ESM.\n */\nexport function ssrBuildPlugin(): vite.Plugin[] {\n const plugins: vite.Plugin[] = [\n {\n name: 'analogjs-ssr-build-plugin',\n apply: 'build',\n config() {\n return {\n ssr: {\n noExternal: ['xhr2'],\n },\n };\n },\n transform: {\n filter: {\n id: /zone-node|platform-server|xhr2\\.js|domino\\/lib\\/sloppy\\.js/,\n },\n handler(code, id) {\n if (\n id.includes('zone-node') &&\n code.includes('const global = globalThis;')\n ) {\n return {\n code: code.replace('const global = globalThis;', ''),\n };\n }\n\n if (id.includes('platform-server')) {\n let result = code.replace(\n 'new xhr2.XMLHttpRequest',\n 'new (xhr2.default.XMLHttpRequest || xhr2.default)',\n );\n\n // Narrowly scoped text replacement of the bare `global`\n // identifier. Matching `global.`, `global,` and ` global[`\n // targets the known occurrences in the @angular/platform-server\n // bundle while leaving strings, comments and asset paths that\n // merely contain the word `global` untouched (see #2426).\n result = result\n .replaceAll('global.', 'globalThis.')\n .replaceAll('global,', 'globalThis,')\n .replaceAll(' global[', ' globalThis[');\n\n return { code: result };\n }\n\n if (id.includes(vite.normalizePath('xhr2.js'))) {\n return {\n code: code\n .replace('os.type()', `''`)\n .replace('os.arch()', `''`)\n .replace('process.versions.node', `'node'`)\n .replace('process.versions.v8', `'v8'`),\n };\n }\n\n if (id.includes(vite.normalizePath('domino/lib/sloppy.js'))) {\n return {\n code: code.replace(/with\\(/gi, 'if('),\n };\n }\n\n return;\n },\n },\n },\n ];\n\n return plugins;\n}\n\n/**\n * Vite plugin that patches `@angular/core`'s `getComponentId()` to\n * mirror every compiled component definition to a global Set, bypassing\n * the `ngServerMode` guard that normally prevents registration on the\n * server. The set lives at `globalThis.__ngComponentDefs` and is read by\n * `@analogjs/router`'s SSR render function to null cached `tView`\n * objects between requests so that `$localize` tagged templates in\n * `consts()` re-evaluate with the freshly loaded translations.\n *\n * Only active when the platform's `i18n` option is configured.\n * Only transforms `@angular/core` modules in SSR builds.\n */\nexport function i18nDefRegistryPlugin(): vite.Plugin {\n let fixedLocale = false;\n const DETECT_MARKER = 'GENERATED_COMP_IDS.set(compId, componentDef.type);';\n const RETURN_STMT = 'return compId;\\n}';\n\n return {\n name: 'analogjs-i18n-def-registry',\n enforce: 'post',\n configResolved(config) {\n const locale = config.define?.['ANALOG_I18N_FIXED_LOCALE'];\n fixedLocale =\n config.command === 'build' && !!locale && locale !== 'undefined';\n },\n\n transform: {\n filter: {\n id: /\\/@angular\\/core\\//,\n },\n handler(code, id, options) {\n if (fixedLocale || !options?.ssr) return;\n if (!code.includes(DETECT_MARKER)) return;\n\n return {\n code: code.replace(\n RETURN_STMT,\n '(globalThis.__ngComponentDefs ??= new Set()).add(componentDef);\\n' +\n RETURN_STMT,\n ),\n };\n },\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,iBAAgC;AAmE9C,QAlE+B,CAC7B;EACE,MAAM;EACN,OAAO;EACP,SAAS;AACP,UAAO,EACL,KAAK,EACH,YAAY,CAAC,OAAO,EACrB,EACF;;EAEH,WAAW;GACT,QAAQ,EACN,IAAI,8DACL;GACD,QAAQ,MAAM,IAAI;AAChB,QACE,GAAG,SAAS,YAAY,IACxB,KAAK,SAAS,6BAA6B,CAE3C,QAAO,EACL,MAAM,KAAK,QAAQ,8BAA8B,GAAG,EACrD;AAGH,QAAI,GAAG,SAAS,kBAAkB,EAAE;KAClC,IAAI,SAAS,KAAK,QAChB,2BACA,oDACD;AAOD,cAAS,OACN,WAAW,WAAW,cAAc,CACpC,WAAW,WAAW,cAAc,CACpC,WAAW,YAAY,eAAe;AAEzC,YAAO,EAAE,MAAM,QAAQ;;AAGzB,QAAI,GAAG,SAAS,KAAK,cAAc,UAAU,CAAC,CAC5C,QAAO,EACL,MAAM,KACH,QAAQ,aAAa,KAAK,CAC1B,QAAQ,aAAa,KAAK,CAC1B,QAAQ,yBAAyB,SAAS,CAC1C,QAAQ,uBAAuB,OAAO,EAC1C;AAGH,QAAI,GAAG,SAAS,KAAK,cAAc,uBAAuB,CAAC,CACzD,QAAO,EACL,MAAM,KAAK,QAAQ,YAAY,MAAM,EACtC;;GAKN;EACF,CACF"}
|
|
@@ -10,6 +10,6 @@ function getBundleOptionsKey() {
|
|
|
10
10
|
return isRolldown() ? "rolldownOptions" : "rollupOptions";
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
13
|
-
export { getBundleOptionsKey, getJsTransformConfigKey };
|
|
13
|
+
export { getBundleOptionsKey, getJsTransformConfigKey, isRolldown };
|
|
14
14
|
|
|
15
15
|
//# sourceMappingURL=rolldown.js.map
|
|
@@ -10,4 +10,4 @@ export declare const SERVER_MODE_ID = "virtual:@analogjs/platform/server-mode";
|
|
|
10
10
|
* first so the flag is set before any application module evaluates. A text
|
|
11
11
|
* replacement cannot do this because Angular is pre-bundled for SSR.
|
|
12
12
|
*/
|
|
13
|
-
export declare function serverModePlugin(): Plugin[];
|
|
13
|
+
export declare function serverModePlugin(entryServer?: string): Plugin[];
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { normalizePath } from "vite";
|
|
1
3
|
//#region packages/platform/src/server-mode-plugin.ts
|
|
2
4
|
var SERVER_MODE_ID = "virtual:@analogjs/platform/server-mode";
|
|
3
5
|
var RESOLVED_SERVER_MODE_ID = `\0${SERVER_MODE_ID}`;
|
|
@@ -11,9 +13,19 @@ var RESOLVED_SERVER_MODE_ID = `\0${SERVER_MODE_ID}`;
|
|
|
11
13
|
* first so the flag is set before any application module evaluates. A text
|
|
12
14
|
* replacement cannot do this because Angular is pre-bundled for SSR.
|
|
13
15
|
*/
|
|
14
|
-
function serverModePlugin() {
|
|
16
|
+
function serverModePlugin(entryServer) {
|
|
17
|
+
let entryServerPath = "";
|
|
15
18
|
return [{
|
|
16
19
|
name: "analogjs-server-mode-plugin",
|
|
20
|
+
configResolved(config) {
|
|
21
|
+
entryServerPath = normalizePath(resolve(config.root, entryServer ?? "src/main.server.ts"));
|
|
22
|
+
},
|
|
23
|
+
transform(code, id, options) {
|
|
24
|
+
if (options?.ssr && normalizePath(id) === entryServerPath) return {
|
|
25
|
+
code: `import ${JSON.stringify(SERVER_MODE_ID)};\n${code}`,
|
|
26
|
+
map: null
|
|
27
|
+
};
|
|
28
|
+
},
|
|
17
29
|
resolveId(id) {
|
|
18
30
|
return id === "virtual:@analogjs/platform/server-mode" ? RESOLVED_SERVER_MODE_ID : void 0;
|
|
19
31
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-mode-plugin.js","names":[],"sources":["../../src/server-mode-plugin.ts"],"sourcesContent":["import { Plugin } from 'vite';\n\nexport const SERVER_MODE_ID = 'virtual:@analogjs/platform/server-mode';\nconst RESOLVED_SERVER_MODE_ID = `\\0${SERVER_MODE_ID}`;\n\n/**\n * Serves a module that sets `globalThis.ngServerMode = true`.\n *\n * Angular decides at provider-creation time whether browser-only features\n * such as event replay apply, and `provideClientHydration()` runs while the\n * app config module evaluates, before `platformServer()` or\n * `provideServerRendering()` set the flag. The SSR entry imports this module\n * first so the flag is set before any application module evaluates. A text\n * replacement cannot do this because Angular is pre-bundled for SSR.\n */\nexport function serverModePlugin(): Plugin[] {\n return [\n {\n name: 'analogjs-server-mode-plugin',\n resolveId(id) {\n return id === SERVER_MODE_ID ? RESOLVED_SERVER_MODE_ID : undefined;\n },\n load(id) {\n return id === RESOLVED_SERVER_MODE_ID\n ? 'globalThis.ngServerMode = true;\\nexport {};\\n'\n : undefined;\n },\n },\n ];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-mode-plugin.js","names":[],"sources":["../../src/server-mode-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { Plugin, normalizePath } from 'vite';\n\nexport const SERVER_MODE_ID = 'virtual:@analogjs/platform/server-mode';\nconst RESOLVED_SERVER_MODE_ID = `\\0${SERVER_MODE_ID}`;\n\n/**\n * Serves a module that sets `globalThis.ngServerMode = true`.\n *\n * Angular decides at provider-creation time whether browser-only features\n * such as event replay apply, and `provideClientHydration()` runs while the\n * app config module evaluates, before `platformServer()` or\n * `provideServerRendering()` set the flag. The SSR entry imports this module\n * first so the flag is set before any application module evaluates. A text\n * replacement cannot do this because Angular is pre-bundled for SSR.\n */\nexport function serverModePlugin(entryServer?: string): Plugin[] {\n let entryServerPath = '';\n\n return [\n {\n name: 'analogjs-server-mode-plugin',\n configResolved(config) {\n entryServerPath = normalizePath(\n resolve(config.root, entryServer ?? 'src/main.server.ts'),\n );\n },\n // Nitro v2 builds `main.server.ts` as the SSR entry directly, so set the\n // flag there too.\n transform(code, id, options) {\n if (options?.ssr && normalizePath(id) === entryServerPath) {\n return {\n code: `import ${JSON.stringify(SERVER_MODE_ID)};\\n${code}`,\n map: null,\n };\n }\n return undefined;\n },\n resolveId(id) {\n return id === SERVER_MODE_ID ? RESOLVED_SERVER_MODE_ID : undefined;\n },\n load(id) {\n return id === RESOLVED_SERVER_MODE_ID\n ? 'globalThis.ngServerMode = true;\\nexport {};\\n'\n : undefined;\n },\n },\n ];\n}\n"],"mappings":";;;AAGA,IAAa,iBAAiB;AAC9B,IAAM,0BAA0B,KAAK;;;;;;;;;;;AAYrC,SAAgB,iBAAiB,aAAgC;CAC/D,IAAI,kBAAkB;AAEtB,QAAO,CACL;EACE,MAAM;EACN,eAAe,QAAQ;AACrB,qBAAkB,cAChB,QAAQ,OAAO,MAAM,eAAe,qBAAqB,CAC1D;;EAIH,UAAU,MAAM,IAAI,SAAS;AAC3B,OAAI,SAAS,OAAO,cAAc,GAAG,KAAK,gBACxC,QAAO;IACL,MAAM,UAAU,KAAK,UAAU,eAAe,CAAC,KAAK;IACpD,KAAK;IACN;;EAIL,UAAU,IAAI;AACZ,UAAO,OAAA,2CAAwB,0BAA0B,KAAA;;EAE3D,KAAK,IAAI;AACP,UAAO,OAAO,0BACV,kDACA,KAAA;;EAEP,CACF"}
|