remote-components 0.3.3 → 0.3.4
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/dist/config/nextjs.cjs +86 -37
- package/dist/config/nextjs.cjs.map +1 -1
- package/dist/config/nextjs.js +86 -37
- package/dist/config/nextjs.js.map +1 -1
- package/dist/config/webpack.cjs +5 -1
- package/dist/config/webpack.cjs.map +1 -1
- package/dist/config/webpack.js +5 -1
- package/dist/config/webpack.js.map +1 -1
- package/dist/host/html.cjs +524 -338
- package/dist/host/html.cjs.map +1 -1
- package/dist/host/html.js +524 -338
- package/dist/host/html.js.map +1 -1
- package/dist/host/nextjs/app/client-only.cjs +462 -259
- package/dist/host/nextjs/app/client-only.cjs.map +1 -1
- package/dist/host/nextjs/app/client-only.js +436 -233
- package/dist/host/nextjs/app/client-only.js.map +1 -1
- package/dist/host/react.cjs +403 -228
- package/dist/host/react.cjs.map +1 -1
- package/dist/host/react.js +403 -228
- package/dist/host/react.js.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.cjs +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.cjs.map +1 -1
- package/dist/internal/config/webpack/apply-shared-modules.js +6 -4
- package/dist/internal/config/webpack/apply-shared-modules.js.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.cjs +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.cjs.map +1 -1
- package/dist/internal/config/webpack/next-client-pages-loader.js +6 -7
- package/dist/internal/config/webpack/next-client-pages-loader.js.map +1 -1
- package/dist/internal/host/nextjs/app-client.cjs +4 -3
- package/dist/internal/host/nextjs/app-client.cjs.map +1 -1
- package/dist/internal/host/nextjs/app-client.js +4 -3
- package/dist/internal/host/nextjs/app-client.js.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.cjs +19 -39
- package/dist/internal/host/nextjs/dom-flight.cjs.map +1 -1
- package/dist/internal/host/nextjs/dom-flight.js +31 -39
- package/dist/internal/host/nextjs/dom-flight.js.map +1 -1
- package/dist/internal/host/nextjs/image-shared.cjs +39 -3
- package/dist/internal/host/nextjs/image-shared.cjs.map +1 -1
- package/dist/internal/host/nextjs/image-shared.d.ts +5 -10
- package/dist/internal/host/nextjs/image-shared.js +29 -3
- package/dist/internal/host/nextjs/image-shared.js.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.cjs +2 -1
- package/dist/internal/host/server/fetch-remote-component.cjs.map +1 -1
- package/dist/internal/host/server/fetch-remote-component.js +2 -1
- package/dist/internal/host/server/fetch-remote-component.js.map +1 -1
- package/dist/internal/host/shared/polyfill.cjs +8 -7
- package/dist/internal/host/shared/polyfill.cjs.map +1 -1
- package/dist/internal/host/shared/polyfill.js +8 -7
- package/dist/internal/host/shared/polyfill.js.map +1 -1
- package/dist/internal/host/shared/shared-module-resolver.cjs +117 -0
- package/dist/internal/host/shared/shared-module-resolver.cjs.map +1 -0
- package/dist/internal/host/shared/shared-module-resolver.d.ts +64 -0
- package/dist/internal/host/shared/shared-module-resolver.js +78 -0
- package/dist/internal/host/shared/shared-module-resolver.js.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.cjs +53 -0
- package/dist/internal/remote/nextjs/next-internals.cjs.map +1 -0
- package/dist/internal/remote/nextjs/next-internals.d.ts +42 -0
- package/dist/internal/remote/nextjs/next-internals.js +26 -0
- package/dist/internal/remote/nextjs/next-internals.js.map +1 -0
- package/dist/internal/runtime/html/apply-origin.cjs +11 -32
- package/dist/internal/runtime/html/apply-origin.cjs.map +1 -1
- package/dist/internal/runtime/html/apply-origin.js +11 -32
- package/dist/internal/runtime/html/apply-origin.js.map +1 -1
- package/dist/internal/runtime/html/html-spec.cjs +78 -0
- package/dist/internal/runtime/html/html-spec.cjs.map +1 -0
- package/dist/internal/runtime/html/html-spec.d.ts +23 -0
- package/dist/internal/runtime/html/html-spec.js +41 -0
- package/dist/internal/runtime/html/html-spec.js.map +1 -0
- package/dist/internal/runtime/html/parse-remote-html.cjs +15 -12
- package/dist/internal/runtime/html/parse-remote-html.cjs.map +1 -1
- package/dist/internal/runtime/html/parse-remote-html.js +29 -12
- package/dist/internal/runtime/html/parse-remote-html.js.map +1 -1
- package/dist/internal/runtime/html/rewrite-srcset.cjs +38 -0
- package/dist/internal/runtime/html/rewrite-srcset.cjs.map +1 -0
- package/dist/internal/runtime/html/rewrite-srcset.d.ts +12 -0
- package/dist/internal/runtime/html/rewrite-srcset.js +14 -0
- package/dist/internal/runtime/html/rewrite-srcset.js.map +1 -0
- package/dist/internal/runtime/loaders/component-loader.cjs +25 -44
- package/dist/internal/runtime/loaders/component-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/component-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/component-loader.js +28 -44
- package/dist/internal/runtime/loaders/component-loader.js.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.cjs +15 -21
- package/dist/internal/runtime/loaders/static-loader.cjs.map +1 -1
- package/dist/internal/runtime/loaders/static-loader.d.ts +3 -1
- package/dist/internal/runtime/loaders/static-loader.js +15 -21
- package/dist/internal/runtime/loaders/static-loader.js.map +1 -1
- package/dist/internal/runtime/namespace.cjs +82 -0
- package/dist/internal/runtime/namespace.cjs.map +1 -0
- package/dist/internal/runtime/namespace.d.ts +5 -0
- package/dist/internal/runtime/namespace.js +58 -0
- package/dist/internal/runtime/namespace.js.map +1 -0
- package/dist/internal/runtime/rsc-imports.cjs +86 -0
- package/dist/internal/runtime/rsc-imports.cjs.map +1 -0
- package/dist/internal/runtime/rsc-imports.d.ts +39 -0
- package/dist/internal/runtime/rsc-imports.js +50 -0
- package/dist/internal/runtime/rsc-imports.js.map +1 -0
- package/dist/internal/runtime/rsc-runtime.cjs +17 -0
- package/dist/internal/runtime/rsc-runtime.cjs.map +1 -0
- package/dist/internal/runtime/rsc-runtime.d.ts +37 -0
- package/dist/internal/runtime/rsc-runtime.js +1 -0
- package/dist/internal/runtime/rsc-runtime.js.map +1 -0
- package/dist/internal/runtime/rsc.cjs +23 -12
- package/dist/internal/runtime/rsc.cjs.map +1 -1
- package/dist/internal/runtime/rsc.d.ts +19 -2
- package/dist/internal/runtime/rsc.js +20 -11
- package/dist/internal/runtime/rsc.js.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.cjs +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.d.ts +1 -1
- package/dist/internal/runtime/turbopack/chunk-loader.js +53 -35
- package/dist/internal/runtime/turbopack/chunk-loader.js.map +1 -1
- package/dist/internal/runtime/turbopack/module.cjs +17 -4
- package/dist/internal/runtime/turbopack/module.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/module.d.ts +23 -1
- package/dist/internal/runtime/turbopack/module.js +16 -4
- package/dist/internal/runtime/turbopack/module.js.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.cjs +26 -10
- package/dist/internal/runtime/turbopack/patterns.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/patterns.d.ts +44 -49
- package/dist/internal/runtime/turbopack/patterns.js +23 -7
- package/dist/internal/runtime/turbopack/patterns.js.map +1 -1
- package/dist/internal/runtime/turbopack/{webpack-runtime.cjs → remote-scope-setup.cjs} +35 -32
- package/dist/internal/runtime/turbopack/remote-scope-setup.cjs.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope-setup.d.ts +25 -0
- package/dist/internal/runtime/turbopack/{webpack-runtime.js → remote-scope-setup.js} +36 -19
- package/dist/internal/runtime/turbopack/remote-scope-setup.js.map +1 -0
- package/dist/internal/runtime/turbopack/remote-scope.cjs +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/remote-scope.d.ts +20 -1
- package/dist/internal/runtime/turbopack/remote-scope.js +4 -6
- package/dist/internal/runtime/turbopack/remote-scope.js.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.cjs +21 -15
- package/dist/internal/runtime/turbopack/shared-modules.cjs.map +1 -1
- package/dist/internal/runtime/turbopack/shared-modules.d.ts +9 -2
- package/dist/internal/runtime/turbopack/shared-modules.js +24 -18
- package/dist/internal/runtime/turbopack/shared-modules.js.map +1 -1
- package/dist/internal/runtime/types.cjs.map +1 -1
- package/dist/internal/runtime/types.d.ts +5 -41
- package/dist/internal/utils/logger.cjs +1 -1
- package/dist/internal/utils/logger.cjs.map +1 -1
- package/dist/internal/utils/logger.d.ts +2 -2
- package/dist/internal/utils/logger.js +1 -1
- package/dist/internal/utils/logger.js.map +1 -1
- package/dist/remote/html.cjs +78 -22
- package/dist/remote/html.cjs.map +1 -1
- package/dist/remote/html.js +78 -22
- package/dist/remote/html.js.map +1 -1
- package/dist/remote/nextjs/app.cjs +14 -55
- package/dist/remote/nextjs/app.cjs.map +1 -1
- package/dist/remote/nextjs/app.js +24 -45
- package/dist/remote/nextjs/app.js.map +1 -1
- package/dist/types-59251814.d.ts +94 -0
- package/package.json +1 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.cjs.map +0 -1
- package/dist/internal/runtime/turbopack/webpack-runtime.d.ts +0 -23
- package/dist/internal/runtime/turbopack/webpack-runtime.js.map +0 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var shared_module_resolver_exports = {};
|
|
30
|
+
__export(shared_module_resolver_exports, {
|
|
31
|
+
CORE_REACT_PATH_MAP: () => CORE_REACT_PATH_MAP,
|
|
32
|
+
CORE_REACT_SHARED_KEYS: () => CORE_REACT_SHARED_KEYS,
|
|
33
|
+
VENDOR_SHARED: () => VENDOR_SHARED,
|
|
34
|
+
buildCoreShared: () => buildCoreShared,
|
|
35
|
+
buildHostShared: () => buildHostShared,
|
|
36
|
+
buildWebpackResolve: () => buildWebpackResolve
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(shared_module_resolver_exports);
|
|
39
|
+
var import_polyfill = require("#internal/host/shared/polyfill");
|
|
40
|
+
var import_logger = require("#internal/utils/logger");
|
|
41
|
+
const CORE_REACT_SHARED_KEYS = [
|
|
42
|
+
"react",
|
|
43
|
+
"react/jsx-dev-runtime",
|
|
44
|
+
"react/jsx-runtime",
|
|
45
|
+
"react-dom",
|
|
46
|
+
"react-dom/client"
|
|
47
|
+
];
|
|
48
|
+
const CORE_REACT_PATH_MAP = {
|
|
49
|
+
react: "/react/index.js",
|
|
50
|
+
"react/jsx-dev-runtime": "/react/jsx-dev-runtime.js",
|
|
51
|
+
"react/jsx-runtime": "/react/jsx-runtime.js",
|
|
52
|
+
"react-dom": "/react-dom/index.js",
|
|
53
|
+
"react-dom/client": "/react-dom/client.js"
|
|
54
|
+
};
|
|
55
|
+
const VENDOR_SHARED = Object.fromEntries(
|
|
56
|
+
Object.entries(CORE_REACT_PATH_MAP).filter(([key]) => key !== "react-dom/client").map(([key, path]) => [key, `'${path}'`])
|
|
57
|
+
);
|
|
58
|
+
function buildCoreShared(userShared) {
|
|
59
|
+
return {
|
|
60
|
+
react: async () => (await import("react")).default,
|
|
61
|
+
"react-dom": async () => (await import("react-dom")).default,
|
|
62
|
+
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
63
|
+
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
64
|
+
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
65
|
+
...userShared
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function buildHostShared(userShared, resolveClientUrl, options) {
|
|
69
|
+
const self = globalThis;
|
|
70
|
+
const result = {
|
|
71
|
+
...(0, import_polyfill.sharedPolyfills)(userShared, resolveClientUrl),
|
|
72
|
+
...self.__remote_component_host_shared_modules__,
|
|
73
|
+
...userShared
|
|
74
|
+
};
|
|
75
|
+
if (options?.includeRemoteComponentShared) {
|
|
76
|
+
Object.assign(result, self.__remote_component_shared__);
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModules, callerTag = "SharedModuleResolver") {
|
|
81
|
+
const resolve = {
|
|
82
|
+
...reactModules,
|
|
83
|
+
...Object.entries(remoteShared).reduce(
|
|
84
|
+
(acc, [key, value]) => {
|
|
85
|
+
if (typeof hostShared[value] !== "undefined") {
|
|
86
|
+
acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
|
|
87
|
+
} else {
|
|
88
|
+
(0, import_logger.logDebug)(
|
|
89
|
+
callerTag,
|
|
90
|
+
`Remote requests "${value}" but host doesn't provide it`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return acc;
|
|
94
|
+
},
|
|
95
|
+
{}
|
|
96
|
+
)
|
|
97
|
+
};
|
|
98
|
+
await Promise.all(
|
|
99
|
+
Object.entries(resolve).map(async ([key, value]) => {
|
|
100
|
+
if (typeof value === "function") {
|
|
101
|
+
resolve[key] = await value(bundle);
|
|
102
|
+
}
|
|
103
|
+
return Promise.resolve(value);
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
return resolve;
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
CORE_REACT_PATH_MAP,
|
|
111
|
+
CORE_REACT_SHARED_KEYS,
|
|
112
|
+
VENDOR_SHARED,
|
|
113
|
+
buildCoreShared,
|
|
114
|
+
buildHostShared,
|
|
115
|
+
buildWebpackResolve
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=shared-module-resolver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/shared-module-resolver.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { sharedPolyfills } from '#internal/host/shared/polyfill';\nimport type { LogLocation } from '#internal/utils/logger';\nimport { logDebug } from '#internal/utils/logger';\n\n/**\n * The core React packages that are always shared between host and remote.\n * These correspond to the `/react/*.js` and `/react-dom/*.js` path keys\n * used in the webpack module resolution map.\n */\nexport const CORE_REACT_SHARED_KEYS = [\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n] as const;\n\n/**\n * Maps each core React package to its webpack-style path key.\n * For example, `react` maps to `/react/index.js`.\n */\nexport const CORE_REACT_PATH_MAP: Record<string, string> = {\n react: '/react/index.js',\n 'react/jsx-dev-runtime': '/react/jsx-dev-runtime.js',\n 'react/jsx-runtime': '/react/jsx-runtime.js',\n 'react-dom': '/react-dom/index.js',\n 'react-dom/client': '/react-dom/client.js',\n};\n\n/**\n * The vendorShared record used by the Next.js config to map React packages\n * to their webpack path-key string literals. Derived from CORE_REACT_PATH_MAP\n * but excludes `react-dom/client` to match the existing config behavior.\n */\nexport const VENDOR_SHARED: Record<string, string> = Object.fromEntries(\n Object.entries(CORE_REACT_PATH_MAP)\n .filter(([key]) => key !== 'react-dom/client')\n .map(([key, path]) => [key, `'${path}'`]),\n);\n\ntype SharedModuleFactory = (bundle?: string) => Promise<unknown>;\n\n/**\n * Builds the `coreShared` map for the Turbopack runtime's\n * `initializeSharedModules`. Each entry is an async factory that dynamically\n * imports the corresponding React package. User-provided shared modules\n * override core entries (e.g. to supply a pinned React version).\n */\nexport function buildCoreShared(\n userShared?: Record<string, SharedModuleFactory>,\n): Record<string, SharedModuleFactory> {\n return {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...userShared,\n };\n}\n\ninterface HostSharedGlobals {\n __remote_component_host_shared_modules__?: Record<\n string,\n SharedModuleFactory\n >;\n __remote_component_shared__?: Record<string, SharedModuleFactory>;\n}\n\n/**\n * Builds the merged host shared modules map with a consistent merge priority:\n * 1. Polyfills (lowest priority — fallback implementations)\n * 2. Global host shared modules (`__remote_component_host_shared_modules__`)\n * 3. User-provided shared modules (highest priority — explicit overrides)\n *\n * Some callers also include `__remote_component_shared__` (the pages router\n * global). Pass `includeRemoteComponentShared: true` to include it at the end.\n */\nexport function buildHostShared(\n userShared?: Record<string, SharedModuleFactory>,\n resolveClientUrl?: InternalResolveClientUrl,\n options?: { includeRemoteComponentShared?: boolean },\n): Record<string, SharedModuleFactory> {\n const self = globalThis as typeof globalThis & HostSharedGlobals;\n const result: Record<string, SharedModuleFactory> = {\n ...sharedPolyfills(userShared, resolveClientUrl),\n ...self.__remote_component_host_shared_modules__,\n ...userShared,\n };\n if (options?.includeRemoteComponentShared) {\n Object.assign(result, self.__remote_component_shared__);\n }\n return result;\n}\n\n/**\n * React module instances keyed by their webpack path, e.g.\n * `{ '/react/index.js': React }`. Passed into `buildWebpackResolve` so it\n * can populate the resolve map without importing React itself.\n */\nexport interface ReactModules {\n '/react/index.js': unknown;\n '/react/jsx-dev-runtime.js': unknown;\n '/react/jsx-runtime.js': unknown;\n '/react-dom/index.js': unknown;\n '/react-dom/client.js': unknown;\n}\n\n/**\n * Builds the `resolve` map passed to `applySharedModules` for the webpack\n * runtime. Combines:\n * - Static React module path keys (`/react/index.js`, etc.)\n * - Remote shared modules matched against host shared, with `(ssr)/` prefix stripped\n *\n * After building the map, resolves any factory functions by awaiting them\n * with the given bundle name.\n */\nexport async function buildWebpackResolve(\n hostShared: Record<string, SharedModuleFactory | unknown>,\n remoteShared: Record<string, string | number>,\n bundle: string,\n reactModules: ReactModules,\n callerTag: LogLocation = 'SharedModuleResolver',\n): Promise<Record<string, unknown>> {\n const resolve: Record<string, unknown> = {\n ...reactModules,\n ...Object.entries(remoteShared).reduce<Record<string, unknown>>(\n (acc, [key, value]) => {\n if (typeof hostShared[value] !== 'undefined') {\n acc[key.replace(/^\\(ssr\\)\\/(?<relative>\\.\\/)?/, '')] =\n hostShared[value];\n } else {\n logDebug(\n callerTag,\n `Remote requests \"${value}\" but host doesn't provide it`,\n );\n }\n return acc;\n },\n {},\n ),\n };\n await Promise.all(\n Object.entries(resolve).map(async ([key, value]) => {\n if (typeof value === 'function') {\n resolve[key] = await value(bundle);\n }\n return Promise.resolve(value);\n }),\n );\n return resolve;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAAgC;AAEhC,oBAAyB;AAOlB,MAAM,yBAAyB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAMO,MAAM,sBAA8C;AAAA,EACzD,OAAO;AAAA,EACP,yBAAyB;AAAA,EACzB,qBAAqB;AAAA,EACrB,aAAa;AAAA,EACb,oBAAoB;AACtB;AAOO,MAAM,gBAAwC,OAAO;AAAA,EAC1D,OAAO,QAAQ,mBAAmB,EAC/B,OAAO,CAAC,CAAC,GAAG,MAAM,QAAQ,kBAAkB,EAC5C,IAAI,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,CAAC;AAC5C;AAUO,SAAS,gBACd,YACqC;AACrC,SAAO;AAAA,IACL,OAAO,aAAa,MAAM,OAAO,OAAO,GAAG;AAAA,IAC3C,aAAa,aAAa,MAAM,OAAO,WAAW,GAAG;AAAA,IACrD,yBAAyB,aACtB,MAAM,OAAO,uBAAuB,GAAG;AAAA,IAC1C,qBAAqB,aAClB,MAAM,OAAO,mBAAmB,GAAG;AAAA,IACtC,oBAAoB,aAAa,MAAM,OAAO,kBAAkB,GAAG;AAAA,IACnE,GAAG;AAAA,EACL;AACF;AAmBO,SAAS,gBACd,YACA,kBACA,SACqC;AACrC,QAAM,OAAO;AACb,QAAM,SAA8C;AAAA,IAClD,OAAG,iCAAgB,YAAY,gBAAgB;AAAA,IAC/C,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EACL;AACA,MAAI,SAAS,8BAA8B;AACzC,WAAO,OAAO,QAAQ,KAAK,2BAA2B;AAAA,EACxD;AACA,SAAO;AACT;AAwBA,eAAsB,oBACpB,YACA,cACA,QACA,cACA,YAAyB,wBACS;AAClC,QAAM,UAAmC;AAAA,IACvC,GAAG;AAAA,IACH,GAAG,OAAO,QAAQ,YAAY,EAAE;AAAA,MAC9B,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,YAAI,OAAO,WAAW,KAAK,MAAM,aAAa;AAC5C,cAAI,IAAI,QAAQ,gCAAgC,EAAE,CAAC,IACjD,WAAW,KAAK;AAAA,QACpB,OAAO;AACL;AAAA,YACE;AAAA,YACA,oBAAoB;AAAA,UACtB;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACA,QAAM,QAAQ;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,IAAI,OAAO,CAAC,KAAK,KAAK,MAAM;AAClD,UAAI,OAAO,UAAU,YAAY;AAC/B,gBAAQ,GAAG,IAAI,MAAM,MAAM,MAAM;AAAA,MACnC;AACA,aAAO,QAAQ,QAAQ,KAAK;AAAA,IAC9B,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { InternalResolveClientUrl } from '../../runtime/url/resolve-client-url.js';
|
|
2
|
+
import { LogLocation } from '../../utils/logger.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The core React packages that are always shared between host and remote.
|
|
6
|
+
* These correspond to the `/react/*.js` and `/react-dom/*.js` path keys
|
|
7
|
+
* used in the webpack module resolution map.
|
|
8
|
+
*/
|
|
9
|
+
declare const CORE_REACT_SHARED_KEYS: readonly ["react", "react/jsx-dev-runtime", "react/jsx-runtime", "react-dom", "react-dom/client"];
|
|
10
|
+
/**
|
|
11
|
+
* Maps each core React package to its webpack-style path key.
|
|
12
|
+
* For example, `react` maps to `/react/index.js`.
|
|
13
|
+
*/
|
|
14
|
+
declare const CORE_REACT_PATH_MAP: Record<string, string>;
|
|
15
|
+
/**
|
|
16
|
+
* The vendorShared record used by the Next.js config to map React packages
|
|
17
|
+
* to their webpack path-key string literals. Derived from CORE_REACT_PATH_MAP
|
|
18
|
+
* but excludes `react-dom/client` to match the existing config behavior.
|
|
19
|
+
*/
|
|
20
|
+
declare const VENDOR_SHARED: Record<string, string>;
|
|
21
|
+
type SharedModuleFactory = (bundle?: string) => Promise<unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Builds the `coreShared` map for the Turbopack runtime's
|
|
24
|
+
* `initializeSharedModules`. Each entry is an async factory that dynamically
|
|
25
|
+
* imports the corresponding React package. User-provided shared modules
|
|
26
|
+
* override core entries (e.g. to supply a pinned React version).
|
|
27
|
+
*/
|
|
28
|
+
declare function buildCoreShared(userShared?: Record<string, SharedModuleFactory>): Record<string, SharedModuleFactory>;
|
|
29
|
+
/**
|
|
30
|
+
* Builds the merged host shared modules map with a consistent merge priority:
|
|
31
|
+
* 1. Polyfills (lowest priority — fallback implementations)
|
|
32
|
+
* 2. Global host shared modules (`__remote_component_host_shared_modules__`)
|
|
33
|
+
* 3. User-provided shared modules (highest priority — explicit overrides)
|
|
34
|
+
*
|
|
35
|
+
* Some callers also include `__remote_component_shared__` (the pages router
|
|
36
|
+
* global). Pass `includeRemoteComponentShared: true` to include it at the end.
|
|
37
|
+
*/
|
|
38
|
+
declare function buildHostShared(userShared?: Record<string, SharedModuleFactory>, resolveClientUrl?: InternalResolveClientUrl, options?: {
|
|
39
|
+
includeRemoteComponentShared?: boolean;
|
|
40
|
+
}): Record<string, SharedModuleFactory>;
|
|
41
|
+
/**
|
|
42
|
+
* React module instances keyed by their webpack path, e.g.
|
|
43
|
+
* `{ '/react/index.js': React }`. Passed into `buildWebpackResolve` so it
|
|
44
|
+
* can populate the resolve map without importing React itself.
|
|
45
|
+
*/
|
|
46
|
+
interface ReactModules {
|
|
47
|
+
'/react/index.js': unknown;
|
|
48
|
+
'/react/jsx-dev-runtime.js': unknown;
|
|
49
|
+
'/react/jsx-runtime.js': unknown;
|
|
50
|
+
'/react-dom/index.js': unknown;
|
|
51
|
+
'/react-dom/client.js': unknown;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Builds the `resolve` map passed to `applySharedModules` for the webpack
|
|
55
|
+
* runtime. Combines:
|
|
56
|
+
* - Static React module path keys (`/react/index.js`, etc.)
|
|
57
|
+
* - Remote shared modules matched against host shared, with `(ssr)/` prefix stripped
|
|
58
|
+
*
|
|
59
|
+
* After building the map, resolves any factory functions by awaiting them
|
|
60
|
+
* with the given bundle name.
|
|
61
|
+
*/
|
|
62
|
+
declare function buildWebpackResolve(hostShared: Record<string, SharedModuleFactory | unknown>, remoteShared: Record<string, string | number>, bundle: string, reactModules: ReactModules, callerTag?: LogLocation): Promise<Record<string, unknown>>;
|
|
63
|
+
|
|
64
|
+
export { CORE_REACT_PATH_MAP, CORE_REACT_SHARED_KEYS, ReactModules, VENDOR_SHARED, buildCoreShared, buildHostShared, buildWebpackResolve };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { sharedPolyfills } from "#internal/host/shared/polyfill";
|
|
2
|
+
import { logDebug } from "#internal/utils/logger";
|
|
3
|
+
const CORE_REACT_SHARED_KEYS = [
|
|
4
|
+
"react",
|
|
5
|
+
"react/jsx-dev-runtime",
|
|
6
|
+
"react/jsx-runtime",
|
|
7
|
+
"react-dom",
|
|
8
|
+
"react-dom/client"
|
|
9
|
+
];
|
|
10
|
+
const CORE_REACT_PATH_MAP = {
|
|
11
|
+
react: "/react/index.js",
|
|
12
|
+
"react/jsx-dev-runtime": "/react/jsx-dev-runtime.js",
|
|
13
|
+
"react/jsx-runtime": "/react/jsx-runtime.js",
|
|
14
|
+
"react-dom": "/react-dom/index.js",
|
|
15
|
+
"react-dom/client": "/react-dom/client.js"
|
|
16
|
+
};
|
|
17
|
+
const VENDOR_SHARED = Object.fromEntries(
|
|
18
|
+
Object.entries(CORE_REACT_PATH_MAP).filter(([key]) => key !== "react-dom/client").map(([key, path]) => [key, `'${path}'`])
|
|
19
|
+
);
|
|
20
|
+
function buildCoreShared(userShared) {
|
|
21
|
+
return {
|
|
22
|
+
react: async () => (await import("react")).default,
|
|
23
|
+
"react-dom": async () => (await import("react-dom")).default,
|
|
24
|
+
"react/jsx-dev-runtime": async () => (await import("react/jsx-dev-runtime")).default,
|
|
25
|
+
"react/jsx-runtime": async () => (await import("react/jsx-runtime")).default,
|
|
26
|
+
"react-dom/client": async () => (await import("react-dom/client")).default,
|
|
27
|
+
...userShared
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function buildHostShared(userShared, resolveClientUrl, options) {
|
|
31
|
+
const self = globalThis;
|
|
32
|
+
const result = {
|
|
33
|
+
...sharedPolyfills(userShared, resolveClientUrl),
|
|
34
|
+
...self.__remote_component_host_shared_modules__,
|
|
35
|
+
...userShared
|
|
36
|
+
};
|
|
37
|
+
if (options?.includeRemoteComponentShared) {
|
|
38
|
+
Object.assign(result, self.__remote_component_shared__);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
async function buildWebpackResolve(hostShared, remoteShared, bundle, reactModules, callerTag = "SharedModuleResolver") {
|
|
43
|
+
const resolve = {
|
|
44
|
+
...reactModules,
|
|
45
|
+
...Object.entries(remoteShared).reduce(
|
|
46
|
+
(acc, [key, value]) => {
|
|
47
|
+
if (typeof hostShared[value] !== "undefined") {
|
|
48
|
+
acc[key.replace(/^\(ssr\)\/(?<relative>\.\/)?/, "")] = hostShared[value];
|
|
49
|
+
} else {
|
|
50
|
+
logDebug(
|
|
51
|
+
callerTag,
|
|
52
|
+
`Remote requests "${value}" but host doesn't provide it`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return acc;
|
|
56
|
+
},
|
|
57
|
+
{}
|
|
58
|
+
)
|
|
59
|
+
};
|
|
60
|
+
await Promise.all(
|
|
61
|
+
Object.entries(resolve).map(async ([key, value]) => {
|
|
62
|
+
if (typeof value === "function") {
|
|
63
|
+
resolve[key] = await value(bundle);
|
|
64
|
+
}
|
|
65
|
+
return Promise.resolve(value);
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
return resolve;
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
CORE_REACT_PATH_MAP,
|
|
72
|
+
CORE_REACT_SHARED_KEYS,
|
|
73
|
+
VENDOR_SHARED,
|
|
74
|
+
buildCoreShared,
|
|
75
|
+
buildHostShared,
|
|
76
|
+
buildWebpackResolve
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=shared-module-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/host/shared/shared-module-resolver.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { sharedPolyfills } from '#internal/host/shared/polyfill';\nimport type { LogLocation } from '#internal/utils/logger';\nimport { logDebug } from '#internal/utils/logger';\n\n/**\n * The core React packages that are always shared between host and remote.\n * These correspond to the `/react/*.js` and `/react-dom/*.js` path keys\n * used in the webpack module resolution map.\n */\nexport const CORE_REACT_SHARED_KEYS = [\n 'react',\n 'react/jsx-dev-runtime',\n 'react/jsx-runtime',\n 'react-dom',\n 'react-dom/client',\n] as const;\n\n/**\n * Maps each core React package to its webpack-style path key.\n * For example, `react` maps to `/react/index.js`.\n */\nexport const CORE_REACT_PATH_MAP: Record<string, string> = {\n react: '/react/index.js',\n 'react/jsx-dev-runtime': '/react/jsx-dev-runtime.js',\n 'react/jsx-runtime': '/react/jsx-runtime.js',\n 'react-dom': '/react-dom/index.js',\n 'react-dom/client': '/react-dom/client.js',\n};\n\n/**\n * The vendorShared record used by the Next.js config to map React packages\n * to their webpack path-key string literals. Derived from CORE_REACT_PATH_MAP\n * but excludes `react-dom/client` to match the existing config behavior.\n */\nexport const VENDOR_SHARED: Record<string, string> = Object.fromEntries(\n Object.entries(CORE_REACT_PATH_MAP)\n .filter(([key]) => key !== 'react-dom/client')\n .map(([key, path]) => [key, `'${path}'`]),\n);\n\ntype SharedModuleFactory = (bundle?: string) => Promise<unknown>;\n\n/**\n * Builds the `coreShared` map for the Turbopack runtime's\n * `initializeSharedModules`. Each entry is an async factory that dynamically\n * imports the corresponding React package. User-provided shared modules\n * override core entries (e.g. to supply a pinned React version).\n */\nexport function buildCoreShared(\n userShared?: Record<string, SharedModuleFactory>,\n): Record<string, SharedModuleFactory> {\n return {\n react: async () => (await import('react')).default,\n 'react-dom': async () => (await import('react-dom')).default,\n 'react/jsx-dev-runtime': async () =>\n (await import('react/jsx-dev-runtime')).default,\n 'react/jsx-runtime': async () =>\n (await import('react/jsx-runtime')).default,\n 'react-dom/client': async () => (await import('react-dom/client')).default,\n ...userShared,\n };\n}\n\ninterface HostSharedGlobals {\n __remote_component_host_shared_modules__?: Record<\n string,\n SharedModuleFactory\n >;\n __remote_component_shared__?: Record<string, SharedModuleFactory>;\n}\n\n/**\n * Builds the merged host shared modules map with a consistent merge priority:\n * 1. Polyfills (lowest priority — fallback implementations)\n * 2. Global host shared modules (`__remote_component_host_shared_modules__`)\n * 3. User-provided shared modules (highest priority — explicit overrides)\n *\n * Some callers also include `__remote_component_shared__` (the pages router\n * global). Pass `includeRemoteComponentShared: true` to include it at the end.\n */\nexport function buildHostShared(\n userShared?: Record<string, SharedModuleFactory>,\n resolveClientUrl?: InternalResolveClientUrl,\n options?: { includeRemoteComponentShared?: boolean },\n): Record<string, SharedModuleFactory> {\n const self = globalThis as typeof globalThis & HostSharedGlobals;\n const result: Record<string, SharedModuleFactory> = {\n ...sharedPolyfills(userShared, resolveClientUrl),\n ...self.__remote_component_host_shared_modules__,\n ...userShared,\n };\n if (options?.includeRemoteComponentShared) {\n Object.assign(result, self.__remote_component_shared__);\n }\n return result;\n}\n\n/**\n * React module instances keyed by their webpack path, e.g.\n * `{ '/react/index.js': React }`. Passed into `buildWebpackResolve` so it\n * can populate the resolve map without importing React itself.\n */\nexport interface ReactModules {\n '/react/index.js': unknown;\n '/react/jsx-dev-runtime.js': unknown;\n '/react/jsx-runtime.js': unknown;\n '/react-dom/index.js': unknown;\n '/react-dom/client.js': unknown;\n}\n\n/**\n * Builds the `resolve` map passed to `applySharedModules` for the webpack\n * runtime. Combines:\n * - Static React module path keys (`/react/index.js`, etc.)\n * - Remote shared modules matched against host shared, with `(ssr)/` prefix stripped\n *\n * After building the map, resolves any factory functions by awaiting them\n * with the given bundle name.\n */\nexport async function buildWebpackResolve(\n hostShared: Record<string, SharedModuleFactory | unknown>,\n remoteShared: Record<string, string | number>,\n bundle: string,\n reactModules: ReactModules,\n callerTag: LogLocation = 'SharedModuleResolver',\n): Promise<Record<string, unknown>> {\n const resolve: Record<string, unknown> = {\n ...reactModules,\n ...Object.entries(remoteShared).reduce<Record<string, unknown>>(\n (acc, [key, value]) => {\n if (typeof hostShared[value] !== 'undefined') {\n acc[key.replace(/^\\(ssr\\)\\/(?<relative>\\.\\/)?/, '')] =\n hostShared[value];\n } else {\n logDebug(\n callerTag,\n `Remote requests \"${value}\" but host doesn't provide it`,\n );\n }\n return acc;\n },\n {},\n ),\n };\n await Promise.all(\n Object.entries(resolve).map(async ([key, value]) => {\n if (typeof value === 'function') {\n resolve[key] = await value(bundle);\n }\n return Promise.resolve(value);\n }),\n );\n return resolve;\n}\n"],"mappings":"AACA,SAAS,uBAAuB;AAEhC,SAAS,gBAAgB;AAOlB,MAAM,yBAAyB;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAMO,MAAM,sBAA8C;AAAA,EACzD,OAAO;AAAA,EACP,yBAAyB;AAAA,EACzB,qBAAqB;AAAA,EACrB,aAAa;AAAA,EACb,oBAAoB;AACtB;AAOO,MAAM,gBAAwC,OAAO;AAAA,EAC1D,OAAO,QAAQ,mBAAmB,EAC/B,OAAO,CAAC,CAAC,GAAG,MAAM,QAAQ,kBAAkB,EAC5C,IAAI,CAAC,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,IAAI,OAAO,CAAC;AAC5C;AAUO,SAAS,gBACd,YACqC;AACrC,SAAO;AAAA,IACL,OAAO,aAAa,MAAM,OAAO,OAAO,GAAG;AAAA,IAC3C,aAAa,aAAa,MAAM,OAAO,WAAW,GAAG;AAAA,IACrD,yBAAyB,aACtB,MAAM,OAAO,uBAAuB,GAAG;AAAA,IAC1C,qBAAqB,aAClB,MAAM,OAAO,mBAAmB,GAAG;AAAA,IACtC,oBAAoB,aAAa,MAAM,OAAO,kBAAkB,GAAG;AAAA,IACnE,GAAG;AAAA,EACL;AACF;AAmBO,SAAS,gBACd,YACA,kBACA,SACqC;AACrC,QAAM,OAAO;AACb,QAAM,SAA8C;AAAA,IAClD,GAAG,gBAAgB,YAAY,gBAAgB;AAAA,IAC/C,GAAG,KAAK;AAAA,IACR,GAAG;AAAA,EACL;AACA,MAAI,SAAS,8BAA8B;AACzC,WAAO,OAAO,QAAQ,KAAK,2BAA2B;AAAA,EACxD;AACA,SAAO;AACT;AAwBA,eAAsB,oBACpB,YACA,cACA,QACA,cACA,YAAyB,wBACS;AAClC,QAAM,UAAmC;AAAA,IACvC,GAAG;AAAA,IACH,GAAG,OAAO,QAAQ,YAAY,EAAE;AAAA,MAC9B,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,YAAI,OAAO,WAAW,KAAK,MAAM,aAAa;AAC5C,cAAI,IAAI,QAAQ,gCAAgC,EAAE,CAAC,IACjD,WAAW,KAAK;AAAA,QACpB,OAAO;AACL;AAAA,YACE;AAAA,YACA,oBAAoB;AAAA,UACtB;AAAA,QACF;AACA,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACA,QAAM,QAAQ;AAAA,IACZ,OAAO,QAAQ,OAAO,EAAE,IAAI,OAAO,CAAC,KAAK,KAAK,MAAM;AAClD,UAAI,OAAO,UAAU,YAAY;AAC/B,gBAAQ,GAAG,IAAI,MAAM,MAAM,MAAM;AAAA,MACnC;AACA,aAAO,QAAQ,QAAQ,KAAK;AAAA,IAC9B,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var next_internals_exports = {};
|
|
20
|
+
__export(next_internals_exports, {
|
|
21
|
+
MANIFESTS_SINGLETON: () => MANIFESTS_SINGLETON,
|
|
22
|
+
SERVER_ACTION_MANIFESTS_SINGLETON: () => SERVER_ACTION_MANIFESTS_SINGLETON,
|
|
23
|
+
getWorkStore: () => getWorkStore,
|
|
24
|
+
resolveManifest: () => resolveManifest
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(next_internals_exports);
|
|
27
|
+
var import_work_async_storage = require("next/dist/server/app-render/work-async-storage.external");
|
|
28
|
+
const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
|
|
29
|
+
"next.server.action-manifests"
|
|
30
|
+
);
|
|
31
|
+
const MANIFESTS_SINGLETON = Symbol.for("next.server.manifests");
|
|
32
|
+
function getWorkStore() {
|
|
33
|
+
return import_work_async_storage.workAsyncStorage.getStore() ?? { page: "/", route: "/" };
|
|
34
|
+
}
|
|
35
|
+
function resolveManifest(route) {
|
|
36
|
+
const self = globalThis;
|
|
37
|
+
const manifests = self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};
|
|
38
|
+
if ("clientReferenceManifestsPerRoute" in manifests) {
|
|
39
|
+
return manifests.clientReferenceManifestsPerRoute?.get?.(route);
|
|
40
|
+
}
|
|
41
|
+
if ("clientReferenceManifestsPerPage" in manifests) {
|
|
42
|
+
return manifests.clientReferenceManifestsPerPage?.[route];
|
|
43
|
+
}
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
MANIFESTS_SINGLETON,
|
|
49
|
+
SERVER_ACTION_MANIFESTS_SINGLETON,
|
|
50
|
+
getWorkStore,
|
|
51
|
+
resolveManifest
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=next-internals.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/remote/nextjs/next-internals.ts"],"sourcesContent":["/**\n * Isolates Next.js internal symbols, work-store access, and manifest\n * resolution so that `app.tsx` doesn't couple directly to Next.js internals.\n *\n * The version-discriminating `in` checks for\n * `clientReferenceManifestsPerRoute` vs `clientReferenceManifestsPerPage`\n * live here — a single place to update when Next.js changes its internals.\n */\n\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\n\ninterface Manifest {\n clientModules?: Record<\n string,\n { id: string; name: string; chunks: string[]; async: boolean }\n >;\n moduleLoading: { prefix?: string; crossOrigin?: boolean | null };\n ssrModuleMapping?: Record<string, unknown>;\n}\n\n/** Internal Next.js symbol to access the server action manifests. */\nexport const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\n/** Internal Next.js symbol to access the manifests (newer versions). */\nexport const MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\n\n/**\n * Reads the current page and route from the Next.js async work store.\n * Returns `{ page: '/', route: '/' }` when the store is unavailable\n * (e.g. outside of a server component render).\n */\nexport function getWorkStore(): { page: string; route: string } {\n return workAsyncStorage.getStore() ?? { page: '/', route: '/' };\n}\n\n/**\n * Resolves the client-reference manifest for the given `route` by probing\n * both the newer `clientReferenceManifestsPerRoute` (Map) and the older\n * `clientReferenceManifestsPerPage` (Record) storage shapes.\n */\nexport function resolveManifest(route: string): Manifest | undefined {\n const self = globalThis as typeof globalThis & {\n [key: symbol]:\n | {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n }\n | undefined;\n };\n\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n\n if ('clientReferenceManifestsPerRoute' in manifests) {\n return manifests.clientReferenceManifestsPerRoute?.get?.(route);\n }\n if ('clientReferenceManifestsPerPage' in manifests) {\n return manifests.clientReferenceManifestsPerPage?.[route];\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,gCAAiC;AAY1B,MAAM,oCAAoC,OAAO;AAAA,EACtD;AACF;AAGO,MAAM,sBAAsB,OAAO,IAAI,uBAAuB;AAO9D,SAAS,eAAgD;AAC9D,SAAO,2CAAiB,SAAS,KAAK,EAAE,MAAM,KAAK,OAAO,IAAI;AAChE;AAOO,SAAS,gBAAgB,OAAqC;AACnE,QAAM,OAAO;AASb,QAAM,YACJ,KAAK,mBAAmB,KAAK,KAAK,iCAAiC,KAAK,CAAC;AAE3E,MAAI,sCAAsC,WAAW;AACnD,WAAO,UAAU,kCAAkC,MAAM,KAAK;AAAA,EAChE;AACA,MAAI,qCAAqC,WAAW;AAClD,WAAO,UAAU,kCAAkC,KAAK;AAAA,EAC1D;AACA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Isolates Next.js internal symbols, work-store access, and manifest
|
|
3
|
+
* resolution so that `app.tsx` doesn't couple directly to Next.js internals.
|
|
4
|
+
*
|
|
5
|
+
* The version-discriminating `in` checks for
|
|
6
|
+
* `clientReferenceManifestsPerRoute` vs `clientReferenceManifestsPerPage`
|
|
7
|
+
* live here — a single place to update when Next.js changes its internals.
|
|
8
|
+
*/
|
|
9
|
+
interface Manifest {
|
|
10
|
+
clientModules?: Record<string, {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
chunks: string[];
|
|
14
|
+
async: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
moduleLoading: {
|
|
17
|
+
prefix?: string;
|
|
18
|
+
crossOrigin?: boolean | null;
|
|
19
|
+
};
|
|
20
|
+
ssrModuleMapping?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
/** Internal Next.js symbol to access the server action manifests. */
|
|
23
|
+
declare const SERVER_ACTION_MANIFESTS_SINGLETON: unique symbol;
|
|
24
|
+
/** Internal Next.js symbol to access the manifests (newer versions). */
|
|
25
|
+
declare const MANIFESTS_SINGLETON: unique symbol;
|
|
26
|
+
/**
|
|
27
|
+
* Reads the current page and route from the Next.js async work store.
|
|
28
|
+
* Returns `{ page: '/', route: '/' }` when the store is unavailable
|
|
29
|
+
* (e.g. outside of a server component render).
|
|
30
|
+
*/
|
|
31
|
+
declare function getWorkStore(): {
|
|
32
|
+
page: string;
|
|
33
|
+
route: string;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Resolves the client-reference manifest for the given `route` by probing
|
|
37
|
+
* both the newer `clientReferenceManifestsPerRoute` (Map) and the older
|
|
38
|
+
* `clientReferenceManifestsPerPage` (Record) storage shapes.
|
|
39
|
+
*/
|
|
40
|
+
declare function resolveManifest(route: string): Manifest | undefined;
|
|
41
|
+
|
|
42
|
+
export { MANIFESTS_SINGLETON, SERVER_ACTION_MANIFESTS_SINGLETON, getWorkStore, resolveManifest };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external";
|
|
2
|
+
const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(
|
|
3
|
+
"next.server.action-manifests"
|
|
4
|
+
);
|
|
5
|
+
const MANIFESTS_SINGLETON = Symbol.for("next.server.manifests");
|
|
6
|
+
function getWorkStore() {
|
|
7
|
+
return workAsyncStorage.getStore() ?? { page: "/", route: "/" };
|
|
8
|
+
}
|
|
9
|
+
function resolveManifest(route) {
|
|
10
|
+
const self = globalThis;
|
|
11
|
+
const manifests = self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};
|
|
12
|
+
if ("clientReferenceManifestsPerRoute" in manifests) {
|
|
13
|
+
return manifests.clientReferenceManifestsPerRoute?.get?.(route);
|
|
14
|
+
}
|
|
15
|
+
if ("clientReferenceManifestsPerPage" in manifests) {
|
|
16
|
+
return manifests.clientReferenceManifestsPerPage?.[route];
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
MANIFESTS_SINGLETON,
|
|
22
|
+
SERVER_ACTION_MANIFESTS_SINGLETON,
|
|
23
|
+
getWorkStore,
|
|
24
|
+
resolveManifest
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=next-internals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/remote/nextjs/next-internals.ts"],"sourcesContent":["/**\n * Isolates Next.js internal symbols, work-store access, and manifest\n * resolution so that `app.tsx` doesn't couple directly to Next.js internals.\n *\n * The version-discriminating `in` checks for\n * `clientReferenceManifestsPerRoute` vs `clientReferenceManifestsPerPage`\n * live here — a single place to update when Next.js changes its internals.\n */\n\nimport { workAsyncStorage } from 'next/dist/server/app-render/work-async-storage.external';\n\ninterface Manifest {\n clientModules?: Record<\n string,\n { id: string; name: string; chunks: string[]; async: boolean }\n >;\n moduleLoading: { prefix?: string; crossOrigin?: boolean | null };\n ssrModuleMapping?: Record<string, unknown>;\n}\n\n/** Internal Next.js symbol to access the server action manifests. */\nexport const SERVER_ACTION_MANIFESTS_SINGLETON = Symbol.for(\n 'next.server.action-manifests',\n);\n\n/** Internal Next.js symbol to access the manifests (newer versions). */\nexport const MANIFESTS_SINGLETON = Symbol.for('next.server.manifests');\n\n/**\n * Reads the current page and route from the Next.js async work store.\n * Returns `{ page: '/', route: '/' }` when the store is unavailable\n * (e.g. outside of a server component render).\n */\nexport function getWorkStore(): { page: string; route: string } {\n return workAsyncStorage.getStore() ?? { page: '/', route: '/' };\n}\n\n/**\n * Resolves the client-reference manifest for the given `route` by probing\n * both the newer `clientReferenceManifestsPerRoute` (Map) and the older\n * `clientReferenceManifestsPerPage` (Record) storage shapes.\n */\nexport function resolveManifest(route: string): Manifest | undefined {\n const self = globalThis as typeof globalThis & {\n [key: symbol]:\n | {\n clientReferenceManifestsPerPage?: Record<string, Manifest>;\n clientReferenceManifestsPerRoute?: Map<string, Manifest>;\n }\n | undefined;\n };\n\n const manifests =\n self[MANIFESTS_SINGLETON] ?? self[SERVER_ACTION_MANIFESTS_SINGLETON] ?? {};\n\n if ('clientReferenceManifestsPerRoute' in manifests) {\n return manifests.clientReferenceManifestsPerRoute?.get?.(route);\n }\n if ('clientReferenceManifestsPerPage' in manifests) {\n return manifests.clientReferenceManifestsPerPage?.[route];\n }\n return undefined;\n}\n"],"mappings":"AASA,SAAS,wBAAwB;AAY1B,MAAM,oCAAoC,OAAO;AAAA,EACtD;AACF;AAGO,MAAM,sBAAsB,OAAO,IAAI,uBAAuB;AAO9D,SAAS,eAAgD;AAC9D,SAAO,iBAAiB,SAAS,KAAK,EAAE,MAAM,KAAK,OAAO,IAAI;AAChE;AAOO,SAAS,gBAAgB,OAAqC;AACnE,QAAM,OAAO;AASb,QAAM,YACJ,KAAK,mBAAmB,KAAK,KAAK,iCAAiC,KAAK,CAAC;AAE3E,MAAI,sCAAsC,WAAW;AACnD,WAAO,UAAU,kCAAkC,MAAM,KAAK;AAAA,EAChE;AACA,MAAI,qCAAqC,WAAW;AAClD,WAAO,UAAU,kCAAkC,KAAK;AAAA,EAC1D;AACA,SAAO;AACT;","names":[]}
|
|
@@ -21,21 +21,12 @@ __export(apply_origin_exports, {
|
|
|
21
21
|
applyOriginToNodes: () => applyOriginToNodes
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(apply_origin_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"source",
|
|
27
|
-
"video",
|
|
28
|
-
"audio",
|
|
29
|
-
"track",
|
|
30
|
-
"iframe",
|
|
31
|
-
"embed",
|
|
32
|
-
"script",
|
|
33
|
-
"link"
|
|
34
|
-
];
|
|
24
|
+
var import_html_spec = require("./html-spec");
|
|
25
|
+
var import_rewrite_srcset = require("./rewrite-srcset");
|
|
35
26
|
function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
36
27
|
if (url.origin !== location.origin) {
|
|
37
28
|
const nodes = doc.querySelectorAll(
|
|
38
|
-
|
|
29
|
+
import_html_spec.ORIGIN_REWRITE_TAGS.map(
|
|
39
30
|
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
40
31
|
).join(",")
|
|
41
32
|
);
|
|
@@ -53,29 +44,17 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
53
44
|
);
|
|
54
45
|
}
|
|
55
46
|
if (node.hasAttribute("srcset")) {
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
61
|
-
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
62
|
-
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
63
|
-
}).join(", ");
|
|
64
|
-
if (srcSet) {
|
|
65
|
-
node.setAttribute("srcset", srcSet);
|
|
47
|
+
const raw = node.getAttribute("srcset");
|
|
48
|
+
if (raw) {
|
|
49
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
50
|
+
node.setAttribute("srcset", (0, import_rewrite_srcset.rewriteSrcset)(raw, url, resolve));
|
|
66
51
|
}
|
|
67
52
|
}
|
|
68
53
|
if (node.hasAttribute("imagesrcset")) {
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
74
|
-
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
75
|
-
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
76
|
-
}).join(", ");
|
|
77
|
-
if (srcSet) {
|
|
78
|
-
node.setAttribute("imagesrcset", srcSet);
|
|
54
|
+
const raw = node.getAttribute("imagesrcset");
|
|
55
|
+
if (raw) {
|
|
56
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
57
|
+
node.setAttribute("imagesrcset", (0, import_rewrite_srcset.rewriteSrcset)(raw, url, resolve));
|
|
79
58
|
}
|
|
80
59
|
}
|
|
81
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/html/apply-origin.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/html/apply-origin.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { ORIGIN_REWRITE_TAGS } from './html-spec';\nimport { rewriteSrcset } from './rewrite-srcset';\n\nexport function applyOriginToNodes(\n doc: Document | HTMLElement,\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n ORIGIN_REWRITE_TAGS.map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n ).join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n const absoluteSrc = new URL(node.getAttribute('src') ?? '/', url).href;\n // Script elements are handled by the loaders (script-loader, static-loader)\n // which apply the callback themselves. Only apply it here for non-script elements.\n const isScript = node.tagName.toLowerCase() === 'script';\n node.src = isScript\n ? absoluteSrc\n : (resolveClientUrl?.(absoluteSrc) ?? absoluteSrc);\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n const absoluteHref = new URL(node.getAttribute('href') ?? '/', url)\n .href;\n node.setAttribute(\n 'href',\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n }\n if (node.hasAttribute('srcset')) {\n const raw = node.getAttribute('srcset');\n if (raw) {\n const resolve = resolveClientUrl\n ? (abs: string) => resolveClientUrl(abs) ?? abs\n : undefined;\n node.setAttribute('srcset', rewriteSrcset(raw, url, resolve));\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const raw = node.getAttribute('imagesrcset');\n if (raw) {\n const resolve = resolveClientUrl\n ? (abs: string) => resolveClientUrl(abs) ?? abs\n : undefined;\n node.setAttribute('imagesrcset', rewriteSrcset(raw, url, resolve));\n }\n }\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAoC;AACpC,4BAA8B;AAEvB,SAAS,mBACd,KACA,KACA,kBACA;AACA,MAAI,IAAI,WAAW,SAAS,QAAQ;AAClC,UAAM,QAAQ,IAAI;AAAA,MAChB,qCAAoB;AAAA,QAClB,CAAC,SACC,GAAG,aAAa,gBAAgB,cAAc;AAAA,MAClD,EAAE,KAAK,GAAG;AAAA,IACZ;AACA,UAAM,QAAQ,CAAC,SAAS;AACtB,UACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,cAAM,cAAc,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAGlE,cAAM,WAAW,KAAK,QAAQ,YAAY,MAAM;AAChD,aAAK,MAAM,WACP,cACC,mBAAmB,WAAW,KAAK;AAAA,MAC1C;AACA,UACE,KAAK,aAAa,MAAM,KACxB,YAAY,KAAK,KAAK,aAAa,MAAM,KAAK,EAAE,GAChD;AACA,cAAM,eAAe,IAAI,IAAI,KAAK,aAAa,MAAM,KAAK,KAAK,GAAG,EAC/D;AACH,aAAK;AAAA,UACH;AAAA,UACA,mBAAmB,YAAY,KAAK;AAAA,QACtC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,cAAM,MAAM,KAAK,aAAa,QAAQ;AACtC,YAAI,KAAK;AACP,gBAAM,UAAU,mBACZ,CAAC,QAAgB,iBAAiB,GAAG,KAAK,MAC1C;AACJ,eAAK,aAAa,cAAU,qCAAc,KAAK,KAAK,OAAO,CAAC;AAAA,QAC9D;AAAA,MACF;AACA,UAAI,KAAK,aAAa,aAAa,GAAG;AACpC,cAAM,MAAM,KAAK,aAAa,aAAa;AAC3C,YAAI,KAAK;AACP,gBAAM,UAAU,mBACZ,CAAC,QAAgB,iBAAiB,GAAG,KAAK,MAC1C;AACJ,eAAK,aAAa,mBAAe,qCAAc,KAAK,KAAK,OAAO,CAAC;AAAA,QACnE;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"source",
|
|
4
|
-
"video",
|
|
5
|
-
"audio",
|
|
6
|
-
"track",
|
|
7
|
-
"iframe",
|
|
8
|
-
"embed",
|
|
9
|
-
"script",
|
|
10
|
-
"link"
|
|
11
|
-
];
|
|
1
|
+
import { ORIGIN_REWRITE_TAGS } from "./html-spec";
|
|
2
|
+
import { rewriteSrcset } from "./rewrite-srcset";
|
|
12
3
|
function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
13
4
|
if (url.origin !== location.origin) {
|
|
14
5
|
const nodes = doc.querySelectorAll(
|
|
15
|
-
|
|
6
|
+
ORIGIN_REWRITE_TAGS.map(
|
|
16
7
|
(type) => `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`
|
|
17
8
|
).join(",")
|
|
18
9
|
);
|
|
@@ -30,29 +21,17 @@ function applyOriginToNodes(doc, url, resolveClientUrl) {
|
|
|
30
21
|
);
|
|
31
22
|
}
|
|
32
23
|
if (node.hasAttribute("srcset")) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
38
|
-
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
39
|
-
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
40
|
-
}).join(", ");
|
|
41
|
-
if (srcSet) {
|
|
42
|
-
node.setAttribute("srcset", srcSet);
|
|
24
|
+
const raw = node.getAttribute("srcset");
|
|
25
|
+
if (raw) {
|
|
26
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
27
|
+
node.setAttribute("srcset", rewriteSrcset(raw, url, resolve));
|
|
43
28
|
}
|
|
44
29
|
}
|
|
45
30
|
if (node.hasAttribute("imagesrcset")) {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const absoluteUrl = new URL(urlPart, url).href;
|
|
51
|
-
const resolvedUrl = resolveClientUrl?.(absoluteUrl) ?? absoluteUrl;
|
|
52
|
-
return descriptor ? `${resolvedUrl} ${descriptor}` : resolvedUrl;
|
|
53
|
-
}).join(", ");
|
|
54
|
-
if (srcSet) {
|
|
55
|
-
node.setAttribute("imagesrcset", srcSet);
|
|
31
|
+
const raw = node.getAttribute("imagesrcset");
|
|
32
|
+
if (raw) {
|
|
33
|
+
const resolve = resolveClientUrl ? (abs) => resolveClientUrl(abs) ?? abs : void 0;
|
|
34
|
+
node.setAttribute("imagesrcset", rewriteSrcset(raw, url, resolve));
|
|
56
35
|
}
|
|
57
36
|
}
|
|
58
37
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtime/html/apply-origin.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtime/html/apply-origin.ts"],"sourcesContent":["import type { InternalResolveClientUrl } from '#internal/host/server/types';\nimport { ORIGIN_REWRITE_TAGS } from './html-spec';\nimport { rewriteSrcset } from './rewrite-srcset';\n\nexport function applyOriginToNodes(\n doc: Document | HTMLElement,\n url: URL,\n resolveClientUrl?: InternalResolveClientUrl,\n) {\n if (url.origin !== location.origin) {\n const nodes = doc.querySelectorAll<HTMLImageElement>(\n ORIGIN_REWRITE_TAGS.map(\n (type) =>\n `${type}[src],${type}[srcset],${type}[href],${type}[imagesrcset]`,\n ).join(','),\n );\n nodes.forEach((node) => {\n if (\n node.hasAttribute('src') &&\n /^[./]+\\/?/.test(node.getAttribute('src') ?? '')\n ) {\n const absoluteSrc = new URL(node.getAttribute('src') ?? '/', url).href;\n // Script elements are handled by the loaders (script-loader, static-loader)\n // which apply the callback themselves. Only apply it here for non-script elements.\n const isScript = node.tagName.toLowerCase() === 'script';\n node.src = isScript\n ? absoluteSrc\n : (resolveClientUrl?.(absoluteSrc) ?? absoluteSrc);\n }\n if (\n node.hasAttribute('href') &&\n /^[./]+\\/?/.test(node.getAttribute('href') ?? '')\n ) {\n const absoluteHref = new URL(node.getAttribute('href') ?? '/', url)\n .href;\n node.setAttribute(\n 'href',\n resolveClientUrl?.(absoluteHref) ?? absoluteHref,\n );\n }\n if (node.hasAttribute('srcset')) {\n const raw = node.getAttribute('srcset');\n if (raw) {\n const resolve = resolveClientUrl\n ? (abs: string) => resolveClientUrl(abs) ?? abs\n : undefined;\n node.setAttribute('srcset', rewriteSrcset(raw, url, resolve));\n }\n }\n if (node.hasAttribute('imagesrcset')) {\n const raw = node.getAttribute('imagesrcset');\n if (raw) {\n const resolve = resolveClientUrl\n ? (abs: string) => resolveClientUrl(abs) ?? abs\n : undefined;\n node.setAttribute('imagesrcset', rewriteSrcset(raw, url, resolve));\n }\n }\n });\n }\n}\n"],"mappings":"AACA,SAAS,2BAA2B;AACpC,SAAS,qBAAqB;AAEvB,SAAS,mBACd,KACA,KACA,kBACA;AACA,MAAI,IAAI,WAAW,SAAS,QAAQ;AAClC,UAAM,QAAQ,IAAI;AAAA,MAChB,oBAAoB;AAAA,QAClB,CAAC,SACC,GAAG,aAAa,gBAAgB,cAAc;AAAA,MAClD,EAAE,KAAK,GAAG;AAAA,IACZ;AACA,UAAM,QAAQ,CAAC,SAAS;AACtB,UACE,KAAK,aAAa,KAAK,KACvB,YAAY,KAAK,KAAK,aAAa,KAAK,KAAK,EAAE,GAC/C;AACA,cAAM,cAAc,IAAI,IAAI,KAAK,aAAa,KAAK,KAAK,KAAK,GAAG,EAAE;AAGlE,cAAM,WAAW,KAAK,QAAQ,YAAY,MAAM;AAChD,aAAK,MAAM,WACP,cACC,mBAAmB,WAAW,KAAK;AAAA,MAC1C;AACA,UACE,KAAK,aAAa,MAAM,KACxB,YAAY,KAAK,KAAK,aAAa,MAAM,KAAK,EAAE,GAChD;AACA,cAAM,eAAe,IAAI,IAAI,KAAK,aAAa,MAAM,KAAK,KAAK,GAAG,EAC/D;AACH,aAAK;AAAA,UACH;AAAA,UACA,mBAAmB,YAAY,KAAK;AAAA,QACtC;AAAA,MACF;AACA,UAAI,KAAK,aAAa,QAAQ,GAAG;AAC/B,cAAM,MAAM,KAAK,aAAa,QAAQ;AACtC,YAAI,KAAK;AACP,gBAAM,UAAU,mBACZ,CAAC,QAAgB,iBAAiB,GAAG,KAAK,MAC1C;AACJ,eAAK,aAAa,UAAU,cAAc,KAAK,KAAK,OAAO,CAAC;AAAA,QAC9D;AAAA,MACF;AACA,UAAI,KAAK,aAAa,aAAa,GAAG;AACpC,cAAM,MAAM,KAAK,aAAa,aAAa;AAC3C,YAAI,KAAK;AACP,gBAAM,UAAU,mBACZ,CAAC,QAAgB,iBAAiB,GAAG,KAAK,MAC1C;AACJ,eAAK,aAAa,eAAe,cAAc,KAAK,KAAK,OAAO,CAAC;AAAA,QACnE;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|