@module-federation/nextjs-mf 0.0.0-chore-bump-node-22-20260710161714

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.
Files changed (110) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/_virtual/_rolldown/runtime.js +29 -0
  5. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  6. package/dist/client/UrlNode.js +92 -0
  7. package/dist/client/UrlNode.js.map +1 -0
  8. package/dist/client/UrlNode.mjs +91 -0
  9. package/dist/client/UrlNode.mjs.map +1 -0
  10. package/dist/src/federation-noop.d.mts +1 -0
  11. package/dist/src/federation-noop.d.ts +1 -0
  12. package/dist/src/federation-noop.js +17 -0
  13. package/dist/src/federation-noop.js.map +1 -0
  14. package/dist/src/federation-noop.mjs +23 -0
  15. package/dist/src/federation-noop.mjs.map +1 -0
  16. package/dist/src/index.d.mts +2 -0
  17. package/dist/src/index.d.ts +2 -0
  18. package/dist/src/index.js +14 -0
  19. package/dist/src/index.js.map +1 -0
  20. package/dist/src/index.mjs +8 -0
  21. package/dist/src/index.mjs.map +1 -0
  22. package/dist/src/internal.js +152 -0
  23. package/dist/src/internal.js.map +1 -0
  24. package/dist/src/internal.mjs +152 -0
  25. package/dist/src/internal.mjs.map +1 -0
  26. package/dist/src/loaders/fixImageLoader.d.mts +27 -0
  27. package/dist/src/loaders/fixImageLoader.d.ts +27 -0
  28. package/dist/src/loaders/fixImageLoader.js +104 -0
  29. package/dist/src/loaders/fixImageLoader.js.map +1 -0
  30. package/dist/src/loaders/fixImageLoader.mjs +101 -0
  31. package/dist/src/loaders/fixImageLoader.mjs.map +1 -0
  32. package/dist/src/loaders/fixUrlLoader.d.mts +16 -0
  33. package/dist/src/loaders/fixUrlLoader.d.ts +16 -0
  34. package/dist/src/loaders/fixUrlLoader.js +22 -0
  35. package/dist/src/loaders/fixUrlLoader.js.map +1 -0
  36. package/dist/src/loaders/fixUrlLoader.mjs +19 -0
  37. package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
  38. package/dist/src/loaders/helpers.js +82 -0
  39. package/dist/src/loaders/helpers.js.map +1 -0
  40. package/dist/src/loaders/helpers.mjs +79 -0
  41. package/dist/src/loaders/helpers.mjs.map +1 -0
  42. package/dist/src/loaders/nextPageMapLoader.d.mts +29 -0
  43. package/dist/src/loaders/nextPageMapLoader.d.ts +29 -0
  44. package/dist/src/loaders/nextPageMapLoader.js +148 -0
  45. package/dist/src/loaders/nextPageMapLoader.js.map +1 -0
  46. package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
  47. package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
  48. package/dist/src/logger.js +9 -0
  49. package/dist/src/logger.js.map +1 -0
  50. package/dist/src/logger.mjs +8 -0
  51. package/dist/src/logger.mjs.map +1 -0
  52. package/dist/src/plugins/CopyFederationPlugin.js +67 -0
  53. package/dist/src/plugins/CopyFederationPlugin.js.map +1 -0
  54. package/dist/src/plugins/CopyFederationPlugin.mjs +65 -0
  55. package/dist/src/plugins/CopyFederationPlugin.mjs.map +1 -0
  56. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +41 -0
  57. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -0
  58. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +40 -0
  59. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -0
  60. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +117 -0
  61. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -0
  62. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs +111 -0
  63. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs.map +1 -0
  64. package/dist/src/plugins/NextFederationPlugin/index.d.mts +31 -0
  65. package/dist/src/plugins/NextFederationPlugin/index.d.ts +31 -0
  66. package/dist/src/plugins/NextFederationPlugin/index.js +156 -0
  67. package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -0
  68. package/dist/src/plugins/NextFederationPlugin/index.mjs +153 -0
  69. package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -0
  70. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.mts +18 -0
  71. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +18 -0
  72. package/dist/src/plugins/NextFederationPlugin/next-fragments.js +65 -0
  73. package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -0
  74. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +63 -0
  75. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -0
  76. package/dist/src/plugins/NextFederationPlugin/set-options.js +20 -0
  77. package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -0
  78. package/dist/src/plugins/NextFederationPlugin/set-options.mjs +19 -0
  79. package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -0
  80. package/dist/src/plugins/NextFederationPlugin/validate-options.js +37 -0
  81. package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -0
  82. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs +35 -0
  83. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs.map +1 -0
  84. package/dist/src/plugins/container/InvertedContainerPlugin.js +26 -0
  85. package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -0
  86. package/dist/src/plugins/container/InvertedContainerPlugin.mjs +27 -0
  87. package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -0
  88. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +57 -0
  89. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -0
  90. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs +57 -0
  91. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs.map +1 -0
  92. package/dist/src/plugins/container/runtimePlugin.d.mts +7 -0
  93. package/dist/src/plugins/container/runtimePlugin.d.ts +6 -0
  94. package/dist/src/plugins/container/runtimePlugin.js +168 -0
  95. package/dist/src/plugins/container/runtimePlugin.js.map +1 -0
  96. package/dist/src/plugins/container/runtimePlugin.mjs +167 -0
  97. package/dist/src/plugins/container/runtimePlugin.mjs.map +1 -0
  98. package/dist/utils/flushedChunks.d.mts +29 -0
  99. package/dist/utils/flushedChunks.d.ts +29 -0
  100. package/dist/utils/flushedChunks.js +37 -0
  101. package/dist/utils/flushedChunks.js.map +1 -0
  102. package/dist/utils/flushedChunks.mjs +35 -0
  103. package/dist/utils/flushedChunks.mjs.map +1 -0
  104. package/dist/utils/index.d.mts +14 -0
  105. package/dist/utils/index.d.ts +14 -0
  106. package/dist/utils/index.js +31 -0
  107. package/dist/utils/index.js.map +1 -0
  108. package/dist/utils/index.mjs +22 -0
  109. package/dist/utils/index.mjs.map +1 -0
  110. package/package.json +106 -0
@@ -0,0 +1,152 @@
1
+ import { __require } from "../_virtual/_rolldown/runtime.mjs";
2
+
3
+ //#region src/internal.ts
4
+ const WEBPACK_LAYERS_NAMES = {
5
+ shared: "shared",
6
+ reactServerComponents: "rsc",
7
+ serverSideRendering: "ssr",
8
+ actionBrowser: "action-browser",
9
+ api: "api",
10
+ middleware: "middleware",
11
+ instrument: "instrument",
12
+ edgeAsset: "edge-asset",
13
+ appPagesBrowser: "app-pages-browser"
14
+ };
15
+ const createSharedConfig = (name, layers, options = {}) => {
16
+ return layers.reduce((acc, layer) => {
17
+ const key = layer ? `${name}-${layer}` : name;
18
+ acc[key] = {
19
+ singleton: true,
20
+ requiredVersion: false,
21
+ import: layer ? void 0 : options.import ?? false,
22
+ shareKey: options.request ?? name,
23
+ request: options.request ?? name,
24
+ layer,
25
+ issuerLayer: layer
26
+ };
27
+ return acc;
28
+ }, {});
29
+ };
30
+ const defaultLayers = [
31
+ WEBPACK_LAYERS_NAMES.reactServerComponents,
32
+ WEBPACK_LAYERS_NAMES.serverSideRendering,
33
+ void 0
34
+ ];
35
+ const navigationLayers = [WEBPACK_LAYERS_NAMES.reactServerComponents, WEBPACK_LAYERS_NAMES.serverSideRendering];
36
+ createSharedConfig("react", defaultLayers);
37
+ createSharedConfig("react", defaultLayers, { request: "react-dom" });
38
+ createSharedConfig("react/", navigationLayers, {
39
+ request: "react/",
40
+ import: void 0
41
+ });
42
+ createSharedConfig("next-navigation", navigationLayers, { request: "next/navigation" });
43
+ /**
44
+ * @typedef SharedObject
45
+ * @type {object}
46
+ * @property {object} [key] - The key representing the shared object's package name.
47
+ * @property {boolean} key.singleton - Whether the shared object should be a singleton.
48
+ * @property {boolean} key.requiredVersion - Whether a specific version of the shared object is required.
49
+ * @property {boolean} key.eager - Whether the shared object should be eagerly loaded.
50
+ * @property {boolean} key.import - Whether the shared object should be imported or not.
51
+ * @property {string} key.layer - The webpack layer this shared module belongs to.
52
+ * @property {string|string[]} key.issuerLayer - The webpack layer that can import this shared module.
53
+ */
54
+ const DEFAULT_SHARE_SCOPE = {
55
+ "next/dynamic": {
56
+ requiredVersion: void 0,
57
+ singleton: true,
58
+ import: void 0
59
+ },
60
+ "next/head": {
61
+ requiredVersion: void 0,
62
+ singleton: true,
63
+ import: void 0
64
+ },
65
+ "next/link": {
66
+ requiredVersion: void 0,
67
+ singleton: true,
68
+ import: void 0
69
+ },
70
+ "next/router": {
71
+ requiredVersion: false,
72
+ singleton: true,
73
+ import: void 0
74
+ },
75
+ "next/image": {
76
+ requiredVersion: void 0,
77
+ singleton: true,
78
+ import: void 0
79
+ },
80
+ "next/script": {
81
+ requiredVersion: void 0,
82
+ singleton: true,
83
+ import: void 0
84
+ },
85
+ react: {
86
+ singleton: true,
87
+ requiredVersion: false,
88
+ import: false
89
+ },
90
+ "react/": {
91
+ singleton: true,
92
+ requiredVersion: false,
93
+ import: false
94
+ },
95
+ "react-dom/": {
96
+ singleton: true,
97
+ requiredVersion: false,
98
+ import: false
99
+ },
100
+ "react-dom": {
101
+ singleton: true,
102
+ requiredVersion: false,
103
+ import: false
104
+ },
105
+ "react/jsx-dev-runtime": {
106
+ singleton: true,
107
+ requiredVersion: false
108
+ },
109
+ "react/jsx-runtime": {
110
+ singleton: true,
111
+ requiredVersion: false
112
+ },
113
+ "styled-jsx": {
114
+ singleton: true,
115
+ import: void 0,
116
+ version: __require("styled-jsx/package.json").version,
117
+ requiredVersion: "^" + __require("styled-jsx/package.json").version
118
+ },
119
+ "styled-jsx/style": {
120
+ singleton: true,
121
+ import: false,
122
+ version: __require("styled-jsx/package.json").version,
123
+ requiredVersion: "^" + __require("styled-jsx/package.json").version
124
+ },
125
+ "styled-jsx/css": {
126
+ singleton: true,
127
+ import: void 0,
128
+ version: __require("styled-jsx/package.json").version,
129
+ requiredVersion: "^" + __require("styled-jsx/package.json").version
130
+ }
131
+ };
132
+ /**
133
+ * Defines a default share scope for the browser environment.
134
+ * This function takes the DEFAULT_SHARE_SCOPE and sets eager to undefined and import to undefined for all entries.
135
+ * For 'react', 'react-dom', 'next/router', and 'next/link', it sets eager to true.
136
+ * The module hoisting system relocates these modules into the right runtime and out of the remote.
137
+ *
138
+ * @type {SharedObject}
139
+ * @returns {SharedObject} - The modified share scope for the browser environment.
140
+ */
141
+ const DEFAULT_SHARE_SCOPE_BROWSER = Object.entries(DEFAULT_SHARE_SCOPE).reduce((acc, item) => {
142
+ const [key, value] = item;
143
+ acc[key] = {
144
+ ...value,
145
+ import: void 0
146
+ };
147
+ return acc;
148
+ }, {});
149
+
150
+ //#endregion
151
+ export { DEFAULT_SHARE_SCOPE, DEFAULT_SHARE_SCOPE_BROWSER };
152
+ //# sourceMappingURL=internal.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.mjs","names":[],"sources":["../../src/internal.ts"],"sourcesContent":["import type { moduleFederationPlugin } from '@module-federation/sdk';\n\n// Extend the SharedConfig type to include layer properties\ntype ExtendedSharedConfig = moduleFederationPlugin.SharedConfig & {\n layer?: string;\n issuerLayer?: string | string[];\n request?: string;\n shareKey?: string;\n};\n\nconst WEBPACK_LAYERS_NAMES = {\n /**\n * The layer for the shared code between the client and server bundles.\n */\n shared: 'shared',\n /**\n * The layer for server-only runtime and picking up `react-server` export conditions.\n * Including app router RSC pages and app router custom routes and metadata routes.\n */\n reactServerComponents: 'rsc',\n /**\n * Server Side Rendering layer for app (ssr).\n */\n serverSideRendering: 'ssr',\n /**\n * The browser client bundle layer for actions.\n */\n actionBrowser: 'action-browser',\n /**\n * The layer for the API routes.\n */\n api: 'api',\n /**\n * The layer for the middleware code.\n */\n middleware: 'middleware',\n /**\n * The layer for the instrumentation hooks.\n */\n instrument: 'instrument',\n /**\n * The layer for assets on the edge.\n */\n edgeAsset: 'edge-asset',\n /**\n * The browser client bundle layer for App directory.\n */\n appPagesBrowser: 'app-pages-browser',\n} as const;\n\nconst createSharedConfig = (\n name: string,\n layers: (string | undefined)[],\n options: { request?: string; import?: false | undefined } = {},\n) => {\n return layers.reduce(\n (acc, layer) => {\n const key = layer ? `${name}-${layer}` : name;\n acc[key] = {\n singleton: true,\n requiredVersion: false,\n import: layer ? undefined : (options.import ?? false),\n shareKey: options.request ?? name,\n request: options.request ?? name,\n layer,\n issuerLayer: layer,\n };\n return acc;\n },\n {} as Record<string, ExtendedSharedConfig>,\n );\n};\n\nconst defaultLayers = [\n WEBPACK_LAYERS_NAMES.reactServerComponents,\n WEBPACK_LAYERS_NAMES.serverSideRendering,\n undefined,\n];\n\nconst navigationLayers = [\n WEBPACK_LAYERS_NAMES.reactServerComponents,\n WEBPACK_LAYERS_NAMES.serverSideRendering,\n];\n\nconst reactShares = createSharedConfig('react', defaultLayers);\nconst reactDomShares = createSharedConfig('react', defaultLayers, {\n request: 'react-dom',\n});\nconst jsxRuntimeShares = createSharedConfig('react/', navigationLayers, {\n request: 'react/',\n import: undefined,\n});\nconst nextNavigationShares = createSharedConfig(\n 'next-navigation',\n navigationLayers,\n { request: 'next/navigation' },\n);\n\n/**\n * @typedef SharedObject\n * @type {object}\n * @property {object} [key] - The key representing the shared object's package name.\n * @property {boolean} key.singleton - Whether the shared object should be a singleton.\n * @property {boolean} key.requiredVersion - Whether a specific version of the shared object is required.\n * @property {boolean} key.eager - Whether the shared object should be eagerly loaded.\n * @property {boolean} key.import - Whether the shared object should be imported or not.\n * @property {string} key.layer - The webpack layer this shared module belongs to.\n * @property {string|string[]} key.issuerLayer - The webpack layer that can import this shared module.\n */\nexport const DEFAULT_SHARE_SCOPE: moduleFederationPlugin.SharedObject = {\n // ...reactShares,\n // ...reactDomShares,\n // ...nextNavigationShares,\n // ...jsxRuntimeShares,\n 'next/dynamic': {\n requiredVersion: undefined,\n singleton: true,\n import: undefined,\n },\n 'next/head': {\n requiredVersion: undefined,\n singleton: true,\n import: undefined,\n },\n 'next/link': {\n requiredVersion: undefined,\n singleton: true,\n import: undefined,\n },\n 'next/router': {\n requiredVersion: false,\n singleton: true,\n import: undefined,\n },\n 'next/image': {\n requiredVersion: undefined,\n singleton: true,\n import: undefined,\n },\n 'next/script': {\n requiredVersion: undefined,\n singleton: true,\n import: undefined,\n },\n react: {\n singleton: true,\n requiredVersion: false,\n import: false,\n },\n 'react/': {\n singleton: true,\n requiredVersion: false,\n import: false,\n },\n 'react-dom/': {\n singleton: true,\n requiredVersion: false,\n import: false,\n },\n 'react-dom': {\n singleton: true,\n requiredVersion: false,\n import: false,\n },\n 'react/jsx-dev-runtime': {\n singleton: true,\n requiredVersion: false,\n },\n 'react/jsx-runtime': {\n singleton: true,\n requiredVersion: false,\n },\n 'styled-jsx': {\n singleton: true,\n import: undefined,\n version: require('styled-jsx/package.json').version,\n requiredVersion: '^' + require('styled-jsx/package.json').version,\n },\n 'styled-jsx/style': {\n singleton: true,\n import: false,\n version: require('styled-jsx/package.json').version,\n requiredVersion: '^' + require('styled-jsx/package.json').version,\n },\n 'styled-jsx/css': {\n singleton: true,\n import: undefined,\n version: require('styled-jsx/package.json').version,\n requiredVersion: '^' + require('styled-jsx/package.json').version,\n },\n};\n\n/**\n * Defines a default share scope for the browser environment.\n * This function takes the DEFAULT_SHARE_SCOPE and sets eager to undefined and import to undefined for all entries.\n * For 'react', 'react-dom', 'next/router', and 'next/link', it sets eager to true.\n * The module hoisting system relocates these modules into the right runtime and out of the remote.\n *\n * @type {SharedObject}\n * @returns {SharedObject} - The modified share scope for the browser environment.\n */\n\nexport const DEFAULT_SHARE_SCOPE_BROWSER: moduleFederationPlugin.SharedObject =\n Object.entries(DEFAULT_SHARE_SCOPE).reduce((acc, item) => {\n const [key, value] = item as [string, moduleFederationPlugin.SharedConfig];\n\n // Set eager and import to undefined for all entries, except for the ones specified above\n acc[key] = { ...value, import: undefined };\n\n return acc;\n }, {} as moduleFederationPlugin.SharedObject);\n\n/**\n * Checks if the remote value is an internal or promise delegate module reference.\n *\n * @param {string} value - The remote value to check.\n * @returns {boolean} - True if the value is an internal or promise delegate module reference, false otherwise.\n */\nconst isInternalOrPromise = (value: string): boolean =>\n ['internal ', 'promise '].some((prefix) => value.startsWith(prefix));\n\n/**\n * Parses the remotes object and checks if they are using a custom promise template or not.\n * If it's a custom promise template, the remote syntax is parsed to get the module name and version number.\n * If the remote value is using the standard remote syntax, a delegated module is created.\n *\n * @param {Record<string, any>} remotes - The remotes object to be parsed.\n * @returns {Record<string, string>} - The parsed remotes object with either the original value,\n * the value for internal or promise delegate module reference, or the created delegated module.\n */\nexport const parseRemotes = (\n remotes: Record<string, any>,\n): Record<string, string> => {\n return Object.entries(remotes).reduce(\n (acc, [key, value]) => {\n if (isInternalOrPromise(value)) {\n // If the value is an internal or promise delegate module reference, keep the original value\n return { ...acc, [key]: value };\n }\n\n return { ...acc, [key]: value };\n },\n {} as Record<string, string>,\n );\n};\n/**\n * Checks if the remote value is an internal delegate module reference.\n * An internal delegate module reference starts with the string 'internal '.\n *\n * @param {string} value - The remote value to check.\n * @returns {boolean} - Returns true if the value is an internal delegate module reference, otherwise returns false.\n */\nconst isInternalDelegate = (value: string): boolean => {\n return value.startsWith('internal ');\n};\n/**\n * Extracts the delegate modules from the provided remotes object.\n * This function iterates over the remotes object and checks if each remote value is an internal delegate module reference.\n * If it is, the function adds it to the returned object.\n *\n * @param {Record<string, any>} remotes - The remotes object containing delegate module references.\n * @returns {Record<string, string>} - An object containing only the delegate modules from the remotes object.\n */\nexport const getDelegates = (\n remotes: Record<string, any>,\n): Record<string, string> =>\n Object.entries(remotes).reduce(\n (acc, [key, value]) =>\n isInternalDelegate(value) ? { ...acc, [key]: value } : acc,\n {},\n );\n\n/**\n * Takes an error object and formats it into a displayable string.\n * If the error object contains a stack trace, it is appended to the error message.\n *\n * @param {Error} error - The error object to be formatted.\n * @returns {string} - The formatted error message string. If a stack trace is present in the error object, it is appended to the error message.\n */\nconst formatError = (error: Error): string => {\n let { message } = error;\n if (error.stack) {\n message += `\\n${error.stack}`;\n }\n return message;\n};\n\n/**\n * Transforms an array of Error objects into a single string. Each error message is formatted using the 'formatError' function.\n * The resulting error messages are then joined together, separated by newline characters.\n *\n * @param {Error[]} err - An array of Error objects that need to be formatted and combined.\n * @returns {string} - A single string containing all the formatted error messages, separated by newline characters.\n */\nexport const toDisplayErrors = (err: Error[]): string => {\n return err.map(formatError).join('\\n');\n};\n"],"mappings":";;;AAUA,MAAM,uBAAuB;CAI3B,QAAQ;CAKR,uBAAuB;CAIvB,qBAAqB;CAIrB,eAAe;CAIf,KAAK;CAIL,YAAY;CAIZ,YAAY;CAIZ,WAAW;CAIX,iBAAiB;CAClB;AAED,MAAM,sBACJ,MACA,QACA,UAA4D,EAAE,KAC3D;AACH,QAAO,OAAO,QACX,KAAK,UAAU;EACd,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,UAAU;AACzC,MAAI,OAAO;GACT,WAAW;GACX,iBAAiB;GACjB,QAAQ,QAAQ,SAAa,QAAQ,UAAU;GAC/C,UAAU,QAAQ,WAAW;GAC7B,SAAS,QAAQ,WAAW;GAC5B;GACA,aAAa;GACd;AACD,SAAO;IAET,EAAE,CACH;;AAGH,MAAM,gBAAgB;CACpB,qBAAqB;CACrB,qBAAqB;CACrB;CACD;AAED,MAAM,mBAAmB,CACvB,qBAAqB,uBACrB,qBAAqB,oBACtB;AAEmB,mBAAmB,SAAS,cAAc;AACvC,mBAAmB,SAAS,eAAe,EAChE,SAAS,aACV,CAAC;AACuB,mBAAmB,UAAU,kBAAkB;CACtE,SAAS;CACT,QAAQ;CACT,CAAC;AAC2B,mBAC3B,mBACA,kBACA,EAAE,SAAS,mBAAmB,CAC/B;;;;;;;;;;;;AAaD,MAAa,sBAA2D;CAKtE,gBAAgB;EACd,iBAAiB;EACjB,WAAW;EACX,QAAQ;EACT;CACD,aAAa;EACX,iBAAiB;EACjB,WAAW;EACX,QAAQ;EACT;CACD,aAAa;EACX,iBAAiB;EACjB,WAAW;EACX,QAAQ;EACT;CACD,eAAe;EACb,iBAAiB;EACjB,WAAW;EACX,QAAQ;EACT;CACD,cAAc;EACZ,iBAAiB;EACjB,WAAW;EACX,QAAQ;EACT;CACD,eAAe;EACb,iBAAiB;EACjB,WAAW;EACX,QAAQ;EACT;CACD,OAAO;EACL,WAAW;EACX,iBAAiB;EACjB,QAAQ;EACT;CACD,UAAU;EACR,WAAW;EACX,iBAAiB;EACjB,QAAQ;EACT;CACD,cAAc;EACZ,WAAW;EACX,iBAAiB;EACjB,QAAQ;EACT;CACD,aAAa;EACX,WAAW;EACX,iBAAiB;EACjB,QAAQ;EACT;CACD,yBAAyB;EACvB,WAAW;EACX,iBAAiB;EAClB;CACD,qBAAqB;EACnB,WAAW;EACX,iBAAiB;EAClB;CACD,cAAc;EACZ,WAAW;EACX,QAAQ;EACR,mBAAiB,0BAA0B,CAAC;EAC5C,iBAAiB,gBAAc,0BAA0B,CAAC;EAC3D;CACD,oBAAoB;EAClB,WAAW;EACX,QAAQ;EACR,mBAAiB,0BAA0B,CAAC;EAC5C,iBAAiB,gBAAc,0BAA0B,CAAC;EAC3D;CACD,kBAAkB;EAChB,WAAW;EACX,QAAQ;EACR,mBAAiB,0BAA0B,CAAC;EAC5C,iBAAiB,gBAAc,0BAA0B,CAAC;EAC3D;CACF;;;;;;;;;;AAYD,MAAa,8BACX,OAAO,QAAQ,oBAAoB,CAAC,QAAQ,KAAK,SAAS;CACxD,MAAM,CAAC,KAAK,SAAS;AAGrB,KAAI,OAAO;EAAE,GAAG;EAAO,QAAQ;EAAW;AAE1C,QAAO;GACN,EAAE,CAAwC"}
@@ -0,0 +1,27 @@
1
+ import { LoaderContext } from "webpack";
2
+
3
+ //#region src/loaders/fixImageLoader.d.ts
4
+ /**
5
+ * This loader is specifically created for tuning the next-image-loader result.
6
+ * It modifies the regular string output of the next-image-loader.
7
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
8
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
9
+ * After these injections, it selects the full URI before _next.
10
+ *
11
+ * @example
12
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
13
+ * will become
14
+ * http://localhost:1234/test/test2
15
+ *
16
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
17
+ * @param {string} remaining - The remaining part of the resource path.
18
+ * @returns {string} The modified source code with the injected code.
19
+ */
20
+ declare function fixImageLoader(this: LoaderContext<Record<string, unknown>>, remaining: string): Promise<string>;
21
+ /**
22
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
23
+ */
24
+ declare const pitch: typeof fixImageLoader;
25
+ //#endregion
26
+ export { fixImageLoader, pitch };
27
+ //# sourceMappingURL=fixImageLoader.d.mts.map
@@ -0,0 +1,27 @@
1
+ import { LoaderContext } from "webpack";
2
+
3
+ //#region src/loaders/fixImageLoader.d.ts
4
+ /**
5
+ * This loader is specifically created for tuning the next-image-loader result.
6
+ * It modifies the regular string output of the next-image-loader.
7
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
8
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
9
+ * After these injections, it selects the full URI before _next.
10
+ *
11
+ * @example
12
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
13
+ * will become
14
+ * http://localhost:1234/test/test2
15
+ *
16
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
17
+ * @param {string} remaining - The remaining part of the resource path.
18
+ * @returns {string} The modified source code with the injected code.
19
+ */
20
+ declare function fixImageLoader(this: LoaderContext<Record<string, unknown>>, remaining: string): Promise<string>;
21
+ /**
22
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
23
+ */
24
+ declare const pitch: typeof fixImageLoader;
25
+ //#endregion
26
+ export { fixImageLoader, pitch };
27
+ //# sourceMappingURL=fixImageLoader.d.ts.map
@@ -0,0 +1,104 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ let path = require("path");
4
+ path = require_runtime.__toESM(path);
5
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
6
+
7
+ //#region src/loaders/fixImageLoader.ts
8
+ const { Template } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
9
+ /**
10
+ * This loader is specifically created for tuning the next-image-loader result.
11
+ * It modifies the regular string output of the next-image-loader.
12
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
13
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
14
+ * After these injections, it selects the full URI before _next.
15
+ *
16
+ * @example
17
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
18
+ * will become
19
+ * http://localhost:1234/test/test2
20
+ *
21
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
22
+ * @param {string} remaining - The remaining part of the resource path.
23
+ * @returns {string} The modified source code with the injected code.
24
+ */
25
+ async function fixImageLoader(remaining) {
26
+ this.cacheable(true);
27
+ const isServer = this._compiler?.options?.name !== "client";
28
+ const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? "";
29
+ const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
30
+ const content = result.default || result;
31
+ const computedAssetPrefix = isServer ? `${Template.asString([
32
+ "function getSSRImagePath(){",
33
+ `const pubpath = ${publicPath};`,
34
+ Template.asString([
35
+ "try {",
36
+ Template.indent([
37
+ "const globalThisVal = new Function('return globalThis')();",
38
+ "const name = __webpack_require__.federation.instance.name",
39
+ `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
40
+ (instance) => {
41
+ if(!instance) return;
42
+ if (!instance.moduleCache.has(name)) return;
43
+ const container = instance.moduleCache.get(name);
44
+ if (!container.remoteInfo) return;
45
+ return container.remoteInfo.entry;
46
+ },
47
+ );`,
48
+ "if(!container) return \"\";",
49
+ "const cache = container.moduleCache",
50
+ "const remote = cache.get(name).remoteInfo",
51
+ `const remoteEntry = remote.entry;`,
52
+ `if (remoteEntry) {`,
53
+ Template.indent([`const splitted = remoteEntry.split('/_next')`, `return splitted.length === 2 ? splitted[0] : '';`]),
54
+ `}`,
55
+ `return '';`
56
+ ]),
57
+ "} catch (e) {",
58
+ Template.indent([`console.error('failed generating SSR image path', e);`, "return \"\";"]),
59
+ "}"
60
+ ]),
61
+ "}()"
62
+ ])}` : `${Template.asString([
63
+ "function getCSRImagePath(){",
64
+ Template.indent([
65
+ "try {",
66
+ Template.indent([`const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`, `return splitted.length === 2 ? splitted[0] : '';`]),
67
+ "} catch (e) {",
68
+ Template.indent([
69
+ `const path = document.currentScript && document.currentScript.src;`,
70
+ `console.error('failed generating CSR image path', e, path);`,
71
+ "return \"\";"
72
+ ]),
73
+ "}"
74
+ ]),
75
+ "}()"
76
+ ])}`;
77
+ const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
78
+ if (key === "src") {
79
+ if (value && !value.includes("://")) value = path.default.join(value);
80
+ acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
81
+ return acc;
82
+ }
83
+ acc.push(`${key}: ${JSON.stringify(value)}`);
84
+ return acc;
85
+ }, []);
86
+ return Template.asString([
87
+ "let computedAssetsPrefixReference = '';",
88
+ "try {",
89
+ Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
90
+ "} catch (e) {}",
91
+ "export default {",
92
+ Template.indent(constructedObject.join(",\n")),
93
+ "}"
94
+ ]);
95
+ }
96
+ /**
97
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
98
+ */
99
+ const pitch = fixImageLoader;
100
+
101
+ //#endregion
102
+ exports.fixImageLoader = fixImageLoader;
103
+ exports.pitch = pitch;
104
+ //# sourceMappingURL=fixImageLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixImageLoader.js","names":[],"sources":["../../../src/loaders/fixImageLoader.ts"],"sourcesContent":["import type { LoaderContext } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nimport path from 'path';\n\n/**\n * This loader is specifically created for tuning the next-image-loader result.\n * It modifies the regular string output of the next-image-loader.\n * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.\n * For client-side rendering (CSR), it injects the document.currentScript.src.\n * After these injections, it selects the full URI before _next.\n *\n * @example\n * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg\n * will become\n * http://localhost:1234/test/test2\n *\n * @param {LoaderContext<Record<string, unknown>>} this - The loader context.\n * @param {string} remaining - The remaining part of the resource path.\n * @returns {string} The modified source code with the injected code.\n */\nexport async function fixImageLoader(\n this: LoaderContext<Record<string, unknown>>,\n remaining: string,\n) {\n this.cacheable(true);\n\n const isServer = this._compiler?.options?.name !== 'client';\n const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? '';\n\n const result = await this.importModule(\n `${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,\n );\n\n const content = (result.default || result) as Record<string, string>;\n\n const computedAssetPrefix = isServer\n ? `${Template.asString([\n 'function getSSRImagePath(){',\n //TODO: use auto public path plugin instead\n `const pubpath = ${publicPath};`,\n Template.asString([\n 'try {',\n Template.indent([\n \"const globalThisVal = new Function('return globalThis')();\",\n 'const name = __webpack_require__.federation.instance.name',\n `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(\n (instance) => {\n if(!instance) return;\n if (!instance.moduleCache.has(name)) return;\n const container = instance.moduleCache.get(name);\n if (!container.remoteInfo) return;\n return container.remoteInfo.entry;\n },\n );`,\n 'if(!container) return \"\";',\n 'const cache = container.moduleCache',\n 'const remote = cache.get(name).remoteInfo',\n `const remoteEntry = remote.entry;`,\n `if (remoteEntry) {`,\n Template.indent([\n `const splitted = remoteEntry.split('/_next')`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n `}`,\n `return '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `console.error('failed generating SSR image path', e);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`\n : `${Template.asString([\n 'function getCSRImagePath(){',\n Template.indent([\n 'try {',\n Template.indent([\n `const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `const path = document.currentScript && document.currentScript.src;`,\n `console.error('failed generating CSR image path', e, path);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`;\n\n const constructedObject = Object.entries(content).reduce(\n (acc, [key, value]) => {\n if (key === 'src') {\n if (value && !value.includes('://')) {\n value = path.join(value);\n }\n acc.push(\n `${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`,\n );\n return acc;\n }\n acc.push(`${key}: ${JSON.stringify(value)}`);\n return acc;\n },\n [] as string[],\n );\n\n return Template.asString([\n \"let computedAssetsPrefixReference = '';\",\n 'try {',\n Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),\n '} catch (e) {}',\n 'export default {',\n Template.indent(constructedObject.join(',\\n')),\n '}',\n ]);\n}\n\n/**\n * The pitch function of the loader, which is the same as the fixImageLoader function.\n */\nexport const pitch = fixImageLoader;\n"],"mappings":";;;;;;;AAEA,MAAM,EAAE,aAAa,gFACE,UAAU,CAChC;;;;;;;;;;;;;;;;;AAmBD,eAAsB,eAEpB,WACA;AACA,MAAK,UAAU,KAAK;CAEpB,MAAM,WAAW,KAAK,WAAW,SAAS,SAAS;CACnD,MAAM,aAAa,KAAK,WAAW,SAAS,gBAAgB,cAAc;CAE1E,MAAM,SAAS,MAAM,KAAK,aACxB,GAAG,KAAK,aAAa,8BAA8B,YACpD;CAED,MAAM,UAAW,OAAO,WAAW;CAEnC,MAAM,sBAAsB,WACxB,GAAG,SAAS,SAAS;EACnB;EAEA,mBAAmB,WAAW;EAC9B,SAAS,SAAS;GAChB;GACA,SAAS,OAAO;IACd;IACA;IACA;;;;;;;;;IASA;IACA;IACA;IACA;IACA;IACA,SAAS,OAAO,CACd,gDACA,mDACD,CAAC;IACF;IACA;IACD,CAAC;GACF;GACA,SAAS,OAAO,CACd,yDACA,eACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC,KACF,GAAG,SAAS,SAAS;EACnB;EACA,SAAS,OAAO;GACd;GACA,SAAS,OAAO,CACd,oBAAoB,WAAW,KAAK,WAAW,yBAC/C,mDACD,CAAC;GACF;GACA,SAAS,OAAO;IACd;IACA;IACA;IACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC;CAEN,MAAM,oBAAoB,OAAO,QAAQ,QAAQ,CAAC,QAC/C,KAAK,CAAC,KAAK,WAAW;AACrB,MAAI,QAAQ,OAAO;AACjB,OAAI,SAAS,CAAC,MAAM,SAAS,MAAM,CACjC,SAAQ,aAAK,KAAK,MAAM;AAE1B,OAAI,KACF,GAAG,IAAI,oCAAoC,KAAK,UAAU,MAAM,GACjE;AACD,UAAO;;AAET,MAAI,KAAK,GAAG,IAAI,IAAI,KAAK,UAAU,MAAM,GAAG;AAC5C,SAAO;IAET,EAAE,CACH;AAED,QAAO,SAAS,SAAS;EACvB;EACA;EACA,SAAS,OAAO,mCAAmC,oBAAoB,GAAG;EAC1E;EACA;EACA,SAAS,OAAO,kBAAkB,KAAK,MAAM,CAAC;EAC9C;EACD,CAAC;;;;;AAMJ,MAAa,QAAQ"}
@@ -0,0 +1,101 @@
1
+ import { __require } from "../../_virtual/_rolldown/runtime.mjs";
2
+ import path from "path";
3
+ import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
4
+
5
+ //#region src/loaders/fixImageLoader.ts
6
+ const { Template } = __require(normalizeWebpackPath("webpack"));
7
+ /**
8
+ * This loader is specifically created for tuning the next-image-loader result.
9
+ * It modifies the regular string output of the next-image-loader.
10
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
11
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
12
+ * After these injections, it selects the full URI before _next.
13
+ *
14
+ * @example
15
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
16
+ * will become
17
+ * http://localhost:1234/test/test2
18
+ *
19
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
20
+ * @param {string} remaining - The remaining part of the resource path.
21
+ * @returns {string} The modified source code with the injected code.
22
+ */
23
+ async function fixImageLoader(remaining) {
24
+ this.cacheable(true);
25
+ const isServer = this._compiler?.options?.name !== "client";
26
+ const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? "";
27
+ const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
28
+ const content = result.default || result;
29
+ const computedAssetPrefix = isServer ? `${Template.asString([
30
+ "function getSSRImagePath(){",
31
+ `const pubpath = ${publicPath};`,
32
+ Template.asString([
33
+ "try {",
34
+ Template.indent([
35
+ "const globalThisVal = new Function('return globalThis')();",
36
+ "const name = __webpack_require__.federation.instance.name",
37
+ `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
38
+ (instance) => {
39
+ if(!instance) return;
40
+ if (!instance.moduleCache.has(name)) return;
41
+ const container = instance.moduleCache.get(name);
42
+ if (!container.remoteInfo) return;
43
+ return container.remoteInfo.entry;
44
+ },
45
+ );`,
46
+ "if(!container) return \"\";",
47
+ "const cache = container.moduleCache",
48
+ "const remote = cache.get(name).remoteInfo",
49
+ `const remoteEntry = remote.entry;`,
50
+ `if (remoteEntry) {`,
51
+ Template.indent([`const splitted = remoteEntry.split('/_next')`, `return splitted.length === 2 ? splitted[0] : '';`]),
52
+ `}`,
53
+ `return '';`
54
+ ]),
55
+ "} catch (e) {",
56
+ Template.indent([`console.error('failed generating SSR image path', e);`, "return \"\";"]),
57
+ "}"
58
+ ]),
59
+ "}()"
60
+ ])}` : `${Template.asString([
61
+ "function getCSRImagePath(){",
62
+ Template.indent([
63
+ "try {",
64
+ Template.indent([`const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`, `return splitted.length === 2 ? splitted[0] : '';`]),
65
+ "} catch (e) {",
66
+ Template.indent([
67
+ `const path = document.currentScript && document.currentScript.src;`,
68
+ `console.error('failed generating CSR image path', e, path);`,
69
+ "return \"\";"
70
+ ]),
71
+ "}"
72
+ ]),
73
+ "}()"
74
+ ])}`;
75
+ const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
76
+ if (key === "src") {
77
+ if (value && !value.includes("://")) value = path.join(value);
78
+ acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
79
+ return acc;
80
+ }
81
+ acc.push(`${key}: ${JSON.stringify(value)}`);
82
+ return acc;
83
+ }, []);
84
+ return Template.asString([
85
+ "let computedAssetsPrefixReference = '';",
86
+ "try {",
87
+ Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
88
+ "} catch (e) {}",
89
+ "export default {",
90
+ Template.indent(constructedObject.join(",\n")),
91
+ "}"
92
+ ]);
93
+ }
94
+ /**
95
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
96
+ */
97
+ const pitch = fixImageLoader;
98
+
99
+ //#endregion
100
+ export { fixImageLoader, pitch };
101
+ //# sourceMappingURL=fixImageLoader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixImageLoader.mjs","names":[],"sources":["../../../src/loaders/fixImageLoader.ts"],"sourcesContent":["import type { LoaderContext } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nimport path from 'path';\n\n/**\n * This loader is specifically created for tuning the next-image-loader result.\n * It modifies the regular string output of the next-image-loader.\n * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.\n * For client-side rendering (CSR), it injects the document.currentScript.src.\n * After these injections, it selects the full URI before _next.\n *\n * @example\n * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg\n * will become\n * http://localhost:1234/test/test2\n *\n * @param {LoaderContext<Record<string, unknown>>} this - The loader context.\n * @param {string} remaining - The remaining part of the resource path.\n * @returns {string} The modified source code with the injected code.\n */\nexport async function fixImageLoader(\n this: LoaderContext<Record<string, unknown>>,\n remaining: string,\n) {\n this.cacheable(true);\n\n const isServer = this._compiler?.options?.name !== 'client';\n const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? '';\n\n const result = await this.importModule(\n `${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,\n );\n\n const content = (result.default || result) as Record<string, string>;\n\n const computedAssetPrefix = isServer\n ? `${Template.asString([\n 'function getSSRImagePath(){',\n //TODO: use auto public path plugin instead\n `const pubpath = ${publicPath};`,\n Template.asString([\n 'try {',\n Template.indent([\n \"const globalThisVal = new Function('return globalThis')();\",\n 'const name = __webpack_require__.federation.instance.name',\n `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(\n (instance) => {\n if(!instance) return;\n if (!instance.moduleCache.has(name)) return;\n const container = instance.moduleCache.get(name);\n if (!container.remoteInfo) return;\n return container.remoteInfo.entry;\n },\n );`,\n 'if(!container) return \"\";',\n 'const cache = container.moduleCache',\n 'const remote = cache.get(name).remoteInfo',\n `const remoteEntry = remote.entry;`,\n `if (remoteEntry) {`,\n Template.indent([\n `const splitted = remoteEntry.split('/_next')`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n `}`,\n `return '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `console.error('failed generating SSR image path', e);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`\n : `${Template.asString([\n 'function getCSRImagePath(){',\n Template.indent([\n 'try {',\n Template.indent([\n `const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `const path = document.currentScript && document.currentScript.src;`,\n `console.error('failed generating CSR image path', e, path);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`;\n\n const constructedObject = Object.entries(content).reduce(\n (acc, [key, value]) => {\n if (key === 'src') {\n if (value && !value.includes('://')) {\n value = path.join(value);\n }\n acc.push(\n `${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`,\n );\n return acc;\n }\n acc.push(`${key}: ${JSON.stringify(value)}`);\n return acc;\n },\n [] as string[],\n );\n\n return Template.asString([\n \"let computedAssetsPrefixReference = '';\",\n 'try {',\n Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),\n '} catch (e) {}',\n 'export default {',\n Template.indent(constructedObject.join(',\\n')),\n '}',\n ]);\n}\n\n/**\n * The pitch function of the loader, which is the same as the fixImageLoader function.\n */\nexport const pitch = fixImageLoader;\n"],"mappings":";;;;;AAEA,MAAM,EAAE,uBACN,qBAAqB,UAAU,CAChC;;;;;;;;;;;;;;;;;AAmBD,eAAsB,eAEpB,WACA;AACA,MAAK,UAAU,KAAK;CAEpB,MAAM,WAAW,KAAK,WAAW,SAAS,SAAS;CACnD,MAAM,aAAa,KAAK,WAAW,SAAS,gBAAgB,cAAc;CAE1E,MAAM,SAAS,MAAM,KAAK,aACxB,GAAG,KAAK,aAAa,8BAA8B,YACpD;CAED,MAAM,UAAW,OAAO,WAAW;CAEnC,MAAM,sBAAsB,WACxB,GAAG,SAAS,SAAS;EACnB;EAEA,mBAAmB,WAAW;EAC9B,SAAS,SAAS;GAChB;GACA,SAAS,OAAO;IACd;IACA;IACA;;;;;;;;;IASA;IACA;IACA;IACA;IACA;IACA,SAAS,OAAO,CACd,gDACA,mDACD,CAAC;IACF;IACA;IACD,CAAC;GACF;GACA,SAAS,OAAO,CACd,yDACA,eACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC,KACF,GAAG,SAAS,SAAS;EACnB;EACA,SAAS,OAAO;GACd;GACA,SAAS,OAAO,CACd,oBAAoB,WAAW,KAAK,WAAW,yBAC/C,mDACD,CAAC;GACF;GACA,SAAS,OAAO;IACd;IACA;IACA;IACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC;CAEN,MAAM,oBAAoB,OAAO,QAAQ,QAAQ,CAAC,QAC/C,KAAK,CAAC,KAAK,WAAW;AACrB,MAAI,QAAQ,OAAO;AACjB,OAAI,SAAS,CAAC,MAAM,SAAS,MAAM,CACjC,SAAQ,KAAK,KAAK,MAAM;AAE1B,OAAI,KACF,GAAG,IAAI,oCAAoC,KAAK,UAAU,MAAM,GACjE;AACD,UAAO;;AAET,MAAI,KAAK,GAAG,IAAI,IAAI,KAAK,UAAU,MAAM,GAAG;AAC5C,SAAO;IAET,EAAE,CACH;AAED,QAAO,SAAS,SAAS;EACvB;EACA;EACA,SAAS,OAAO,mCAAmC,oBAAoB,GAAG;EAC1E;EACA;EACA,SAAS,OAAO,kBAAkB,KAAK,MAAM,CAAC;EAC9C;EACD,CAAC;;;;;AAMJ,MAAa,QAAQ"}
@@ -0,0 +1,16 @@
1
+ //#region src/loaders/fixUrlLoader.d.ts
2
+ /**
3
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
4
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
5
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
6
+ *
7
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
8
+ * For example, it could be: http://localhost:3000/_next
9
+ *
10
+ * @param {string} content - The original output from the url-loader.
11
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
12
+ */
13
+ declare function fixUrlLoader(content: string): string;
14
+ //#endregion
15
+ export { fixUrlLoader as default, fixUrlLoader };
16
+ //# sourceMappingURL=fixUrlLoader.d.mts.map
@@ -0,0 +1,16 @@
1
+ //#region src/loaders/fixUrlLoader.d.ts
2
+ /**
3
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
4
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
5
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
6
+ *
7
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
8
+ * For example, it could be: http://localhost:3000/_next
9
+ *
10
+ * @param {string} content - The original output from the url-loader.
11
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
12
+ */
13
+ declare function fixUrlLoader(content: string): string;
14
+ //#endregion
15
+ export { fixUrlLoader as default, fixUrlLoader };
16
+ //# sourceMappingURL=fixUrlLoader.d.ts.map
@@ -0,0 +1,22 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ //#region src/loaders/fixUrlLoader.ts
4
+ /**
5
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
6
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
7
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
8
+ *
9
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
10
+ * For example, it could be: http://localhost:3000/_next
11
+ *
12
+ * @param {string} content - The original output from the url-loader.
13
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
14
+ */
15
+ function fixUrlLoader(content) {
16
+ return content.replace("export default \"/", `export default __webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '\$1')+"/`);
17
+ }
18
+
19
+ //#endregion
20
+ exports.default = fixUrlLoader;
21
+ exports.fixUrlLoader = fixUrlLoader;
22
+ //# sourceMappingURL=fixUrlLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixUrlLoader.js","names":[],"sources":["../../../src/loaders/fixUrlLoader.ts"],"sourcesContent":["/**\n * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.\n * It injects the PUBLIC_PATH from the webpack runtime into the output.\n * The output format is: `export default __webpack_require__.p + \"/static/media/ssl.e3019f0e.svg\"`\n *\n * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.\n * For example, it could be: http://localhost:3000/_next\n *\n * @param {string} content - The original output from the url-loader.\n * @returns {string} The modified output with the injected PUBLIC_PATH.\n */\nexport function fixUrlLoader(content: string) {\n // This regular expression extracts the hostname from the publicPath.\n // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000\n const currentHostnameCode =\n \"__webpack_require__.p.replace(/(.+\\\\:\\\\/\\\\/[^\\\\/]+){0,1}\\\\/.*/i, '$1')\";\n\n // Replace the default export path in the content with the modified path that includes the hostname.\n return content.replace(\n 'export default \"/',\n `export default ${currentHostnameCode}+\"/`,\n );\n}\n\n// Export the fixUrlLoader function as the default export of this module.\nexport default fixUrlLoader;\n"],"mappings":";;;;;;;;;;;;;;AAWA,SAAgB,aAAa,SAAiB;AAO5C,QAAO,QAAQ,QACb,sBACA,4FACD"}
@@ -0,0 +1,19 @@
1
+ //#region src/loaders/fixUrlLoader.ts
2
+ /**
3
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
4
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
5
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
6
+ *
7
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
8
+ * For example, it could be: http://localhost:3000/_next
9
+ *
10
+ * @param {string} content - The original output from the url-loader.
11
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
12
+ */
13
+ function fixUrlLoader(content) {
14
+ return content.replace("export default \"/", `export default __webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '\$1')+"/`);
15
+ }
16
+
17
+ //#endregion
18
+ export { fixUrlLoader as default, fixUrlLoader };
19
+ //# sourceMappingURL=fixUrlLoader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixUrlLoader.mjs","names":[],"sources":["../../../src/loaders/fixUrlLoader.ts"],"sourcesContent":["/**\n * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.\n * It injects the PUBLIC_PATH from the webpack runtime into the output.\n * The output format is: `export default __webpack_require__.p + \"/static/media/ssl.e3019f0e.svg\"`\n *\n * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.\n * For example, it could be: http://localhost:3000/_next\n *\n * @param {string} content - The original output from the url-loader.\n * @returns {string} The modified output with the injected PUBLIC_PATH.\n */\nexport function fixUrlLoader(content: string) {\n // This regular expression extracts the hostname from the publicPath.\n // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000\n const currentHostnameCode =\n \"__webpack_require__.p.replace(/(.+\\\\:\\\\/\\\\/[^\\\\/]+){0,1}\\\\/.*/i, '$1')\";\n\n // Replace the default export path in the content with the modified path that includes the hostname.\n return content.replace(\n 'export default \"/',\n `export default ${currentHostnameCode}+\"/`,\n );\n}\n\n// Export the fixUrlLoader function as the default export of this module.\nexport default fixUrlLoader;\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,aAAa,SAAiB;AAO5C,QAAO,QAAQ,QACb,sBACA,4FACD"}
@@ -0,0 +1,82 @@
1
+
2
+ //#region src/loaders/helpers.ts
3
+ function injectRuleLoader(rule, loader = {}) {
4
+ if (rule !== "...") {
5
+ const _rule = rule;
6
+ if (_rule.loader) {
7
+ _rule.use = [loader, {
8
+ loader: _rule.loader,
9
+ options: _rule.options
10
+ }];
11
+ delete _rule.loader;
12
+ delete _rule.options;
13
+ } else if (_rule.use) _rule.use = [loader, ..._rule.use];
14
+ }
15
+ }
16
+ /**
17
+ * This function checks if the current module rule has a loader with the provided name.
18
+ *
19
+ * @param {RuleSetRule} rule - The current module rule.
20
+ * @param {string} loaderName - The name of the loader to check.
21
+ * @returns {boolean} Returns true if the current module rule has a loader with the provided name, otherwise false.
22
+ */
23
+ function hasLoader(rule, loaderName) {
24
+ if (rule !== "...") {
25
+ const _rule = rule;
26
+ if (_rule.loader === loaderName) return true;
27
+ else if (_rule.use && Array.isArray(_rule.use)) for (let i = 0; i < _rule.use.length; i++) {
28
+ const loader = _rule.use[i];
29
+ if (typeof loader !== "string" && typeof loader !== "function" && loader.loader && (loader.loader === loaderName || loader.loader.includes(`/${loaderName}/`))) return true;
30
+ else if (typeof loader === "string") {
31
+ if (loader === loaderName || loader.includes(`/${loaderName}/`)) return true;
32
+ }
33
+ }
34
+ }
35
+ return false;
36
+ }
37
+ function matchesCondition(condition, resource, currentPath) {
38
+ if (condition instanceof RegExp) return condition.test(resource.path);
39
+ else if (typeof condition === "string") return resource.path.includes(condition);
40
+ else if (typeof condition === "function") return condition(resource.path);
41
+ else if (typeof condition === "object") {
42
+ if ("test" in condition && condition.test) {
43
+ if (!(Array.isArray(condition.test) ? condition.test : [condition.test]).some((test) => matchesCondition(test, resource, currentPath))) return false;
44
+ }
45
+ if ("include" in condition && condition.include) {
46
+ if (!(Array.isArray(condition.include) ? condition.include : [condition.include]).some((include) => matchesCondition(include, resource, currentPath))) return false;
47
+ }
48
+ if ("exclude" in condition && condition.exclude) {
49
+ if ((Array.isArray(condition.exclude) ? condition.exclude : [condition.exclude]).some((exclude) => matchesCondition(exclude, resource, currentPath))) return false;
50
+ }
51
+ if ("and" in condition && condition.and) return condition.and.every((cond) => matchesCondition(cond, resource, currentPath));
52
+ if ("or" in condition && condition.or) return condition.or.some((cond) => matchesCondition(cond, resource, currentPath));
53
+ if ("not" in condition && condition.not) return !matchesCondition(condition.not, resource, currentPath);
54
+ if ("layer" in condition && condition.layer) {
55
+ if (!resource.layer || !matchesCondition(condition.layer, { path: resource.layer }, currentPath)) return false;
56
+ }
57
+ if ("issuerLayer" in condition && condition.issuerLayer) {
58
+ if (!resource.issuerLayer || !matchesCondition(condition.issuerLayer, { path: resource.issuerLayer }, currentPath)) return false;
59
+ }
60
+ }
61
+ return true;
62
+ }
63
+ function findLoaderForResource(rules, resource, path = []) {
64
+ let lastMatchedRule = null;
65
+ for (let i = 0; i < rules.length; i++) {
66
+ const rule = rules[i];
67
+ const currentPath = [...path, `rules[${i}]`];
68
+ if (rule.oneOf) for (let j = 0; j < rule.oneOf.length; j++) {
69
+ const subRule = rule.oneOf[j];
70
+ const subPath = [...currentPath, `oneOf[${j}]`];
71
+ if (subRule && matchesCondition(subRule, resource, subPath.join("->"))) return subRule;
72
+ }
73
+ else if (rule && matchesCondition(rule, resource, currentPath.join(" -> "))) lastMatchedRule = rule;
74
+ }
75
+ return lastMatchedRule;
76
+ }
77
+
78
+ //#endregion
79
+ exports.findLoaderForResource = findLoaderForResource;
80
+ exports.hasLoader = hasLoader;
81
+ exports.injectRuleLoader = injectRuleLoader;
82
+ //# sourceMappingURL=helpers.js.map