@sitecore-content-sdk/nextjs 2.1.0 → 2.1.1-canary.20260507131755

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/LICENSE.txt CHANGED
@@ -1,202 +1,202 @@
1
-
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
5
-
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
-
8
- 1. Definitions.
9
-
10
- "License" shall mean the terms and conditions for use, reproduction,
11
- and distribution as defined by Sections 1 through 9 of this document.
12
-
13
- "Licensor" shall mean the copyright owner or entity authorized by
14
- the copyright owner that is granting the License.
15
-
16
- "Legal Entity" shall mean the union of the acting entity and all
17
- other entities that control, are controlled by, or are under common
18
- control with that entity. For the purposes of this definition,
19
- "control" means (i) the power, direct or indirect, to cause the
20
- direction or management of such entity, whether by contract or
21
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
- outstanding shares, or (iii) beneficial ownership of such entity.
23
-
24
- "You" (or "Your") shall mean an individual or Legal Entity
25
- exercising permissions granted by this License.
26
-
27
- "Source" form shall mean the preferred form for making modifications,
28
- including but not limited to software source code, documentation
29
- source, and configuration files.
30
-
31
- "Object" form shall mean any form resulting from mechanical
32
- transformation or translation of a Source form, including but
33
- not limited to compiled object code, generated documentation,
34
- and conversions to other media types.
35
-
36
- "Work" shall mean the work of authorship, whether in Source or
37
- Object form, made available under the License, as indicated by a
38
- copyright notice that is included in or attached to the work
39
- (an example is provided in the Appendix below).
40
-
41
- "Derivative Works" shall mean any work, whether in Source or Object
42
- form, that is based on (or derived from) the Work and for which the
43
- editorial revisions, annotations, elaborations, or other modifications
44
- represent, as a whole, an original work of authorship. For the purposes
45
- of this License, Derivative Works shall not include works that remain
46
- separable from, or merely link (or bind by name) to the interfaces of,
47
- the Work and Derivative Works thereof.
48
-
49
- "Contribution" shall mean any work of authorship, including
50
- the original version of the Work and any modifications or additions
51
- to that Work or Derivative Works thereof, that is intentionally
52
- submitted to Licensor for inclusion in the Work by the copyright owner
53
- or by an individual or Legal Entity authorized to submit on behalf of
54
- the copyright owner. For the purposes of this definition, "submitted"
55
- means any form of electronic, verbal, or written communication sent
56
- to the Licensor or its representatives, including but not limited to
57
- communication on electronic mailing lists, source code control systems,
58
- and issue tracking systems that are managed by, or on behalf of, the
59
- Licensor for the purpose of discussing and improving the Work, but
60
- excluding communication that is conspicuously marked or otherwise
61
- designated in writing by the copyright owner as "Not a Contribution."
62
-
63
- "Contributor" shall mean Licensor and any individual or Legal Entity
64
- on behalf of whom a Contribution has been received by Licensor and
65
- subsequently incorporated within the Work.
66
-
67
- 2. Grant of Copyright License. Subject to the terms and conditions of
68
- this License, each Contributor hereby grants to You a perpetual,
69
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
- copyright license to reproduce, prepare Derivative Works of,
71
- publicly display, publicly perform, sublicense, and distribute the
72
- Work and such Derivative Works in Source or Object form.
73
-
74
- 3. Grant of Patent License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- (except as stated in this section) patent license to make, have made,
78
- use, offer to sell, sell, import, and otherwise transfer the Work,
79
- where such license applies only to those patent claims licensable
80
- by such Contributor that are necessarily infringed by their
81
- Contribution(s) alone or by combination of their Contribution(s)
82
- with the Work to which such Contribution(s) was submitted. If You
83
- institute patent litigation against any entity (including a
84
- cross-claim or counterclaim in a lawsuit) alleging that the Work
85
- or a Contribution incorporated within the Work constitutes direct
86
- or contributory patent infringement, then any patent licenses
87
- granted to You under this License for that Work shall terminate
88
- as of the date such litigation is filed.
89
-
90
- 4. Redistribution. You may reproduce and distribute copies of the
91
- Work or Derivative Works thereof in any medium, with or without
92
- modifications, and in Source or Object form, provided that You
93
- meet the following conditions:
94
-
95
- (a) You must give any other recipients of the Work or
96
- Derivative Works a copy of this License; and
97
-
98
- (b) You must cause any modified files to carry prominent notices
99
- stating that You changed the files; and
100
-
101
- (c) You must retain, in the Source form of any Derivative Works
102
- that You distribute, all copyright, patent, trademark, and
103
- attribution notices from the Source form of the Work,
104
- excluding those notices that do not pertain to any part of
105
- the Derivative Works; and
106
-
107
- (d) If the Work includes a "NOTICE" text file as part of its
108
- distribution, then any Derivative Works that You distribute must
109
- include a readable copy of the attribution notices contained
110
- within such NOTICE file, excluding those notices that do not
111
- pertain to any part of the Derivative Works, in at least one
112
- of the following places: within a NOTICE text file distributed
113
- as part of the Derivative Works; within the Source form or
114
- documentation, if provided along with the Derivative Works; or,
115
- within a display generated by the Derivative Works, if and
116
- wherever such third-party notices normally appear. The contents
117
- of the NOTICE file are for informational purposes only and
118
- do not modify the License. You may add Your own attribution
119
- notices within Derivative Works that You distribute, alongside
120
- or as an addendum to the NOTICE text from the Work, provided
121
- that such additional attribution notices cannot be construed
122
- as modifying the License.
123
-
124
- You may add Your own copyright statement to Your modifications and
125
- may provide additional or different license terms and conditions
126
- for use, reproduction, or distribution of Your modifications, or
127
- for any such Derivative Works as a whole, provided Your use,
128
- reproduction, and distribution of the Work otherwise complies with
129
- the conditions stated in this License.
130
-
131
- 5. Submission of Contributions. Unless You explicitly state otherwise,
132
- any Contribution intentionally submitted for inclusion in the Work
133
- by You to the Licensor shall be under the terms and conditions of
134
- this License, without any additional terms or conditions.
135
- Notwithstanding the above, nothing herein shall supersede or modify
136
- the terms of any separate license agreement you may have executed
137
- with Licensor regarding such Contributions.
138
-
139
- 6. Trademarks. This License does not grant permission to use the trade
140
- names, trademarks, service marks, or product names of the Licensor,
141
- except as required for reasonable and customary use in describing the
142
- origin of the Work and reproducing the content of the NOTICE file.
143
-
144
- 7. Disclaimer of Warranty. Unless required by applicable law or
145
- agreed to in writing, Licensor provides the Work (and each
146
- Contributor provides its Contributions) on an "AS IS" BASIS,
147
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
- implied, including, without limitation, any warranties or conditions
149
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
- PARTICULAR PURPOSE. You are solely responsible for determining the
151
- appropriateness of using or redistributing the Work and assume any
152
- risks associated with Your exercise of permissions under this License.
153
-
154
- 8. Limitation of Liability. In no event and under no legal theory,
155
- whether in tort (including negligence), contract, or otherwise,
156
- unless required by applicable law (such as deliberate and grossly
157
- negligent acts) or agreed to in writing, shall any Contributor be
158
- liable to You for damages, including any direct, indirect, special,
159
- incidental, or consequential damages of any character arising as a
160
- result of this License or out of the use or inability to use the
161
- Work (including but not limited to damages for loss of goodwill,
162
- work stoppage, computer failure or malfunction, or any and all
163
- other commercial damages or losses), even if such Contributor
164
- has been advised of the possibility of such damages.
165
-
166
- 9. Accepting Warranty or Additional Liability. While redistributing
167
- the Work or Derivative Works thereof, You may choose to offer,
168
- and charge a fee for, acceptance of support, warranty, indemnity,
169
- or other liability obligations and/or rights consistent with this
170
- License. However, in accepting such obligations, You may act only
171
- on Your own behalf and on Your sole responsibility, not on behalf
172
- of any other Contributor, and only if You agree to indemnify,
173
- defend, and hold each Contributor harmless for any liability
174
- incurred by, or claims asserted against, such Contributor by reason
175
- of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -33,11 +33,39 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.generateMap = exports.defaultClientMapTemplate = void 0;
36
+ exports.generateMap = exports.defaultClientMapTemplate = exports.defaultServerMapTemplate = void 0;
37
37
  const tools_1 = require("@sitecore-content-sdk/content/tools");
38
38
  const path = __importStar(require("path"));
39
39
  const fs = __importStar(require("fs"));
40
40
  const utils_1 = require("./templating/utils");
41
+ const DEFAULT_HEADER_COMMENT = "Below are built-in components that are available in the app, it's recommended to keep them as is";
42
+ const APP_ROUTER_BUILTIN_IMPORTS = `
43
+ import { BYOCServerWrapper, NextjsContentSdkComponent, FEaaSServerWrapper } from '@sitecore-content-sdk/nextjs';
44
+ import { Form } from '@sitecore-content-sdk/nextjs';
45
+ `;
46
+ const APP_ROUTER_BUILTIN_ENTRIES = [
47
+ `['BYOCWrapper', BYOCServerWrapper]`,
48
+ `['FEaaSWrapper', FEaaSServerWrapper]`,
49
+ `['Form', { ...Form, componentType: 'client' }]`,
50
+ ];
51
+ const PAGES_ROUTER_BUILTIN_IMPORTS = `
52
+ import { BYOCWrapper, NextjsContentSdkComponent, FEaaSWrapper } from '@sitecore-content-sdk/nextjs';
53
+ import { Form } from '@sitecore-content-sdk/nextjs';
54
+ `;
55
+ const PAGES_ROUTER_BUILTIN_ENTRIES = [
56
+ `['BYOCWrapper', BYOCWrapper]`,
57
+ `['FEaaSWrapper', FEaaSWrapper]`,
58
+ `['Form', Form]`,
59
+ ];
60
+ const CLIENT_MAP_BUILTIN_IMPORTS = `
61
+ import { BYOCClientWrapper, NextjsContentSdkComponent, FEaaSClientWrapper } from '@sitecore-content-sdk/nextjs';
62
+ import { Form } from '@sitecore-content-sdk/nextjs';
63
+ `;
64
+ const CLIENT_MAP_BUILTIN_ENTRIES = [
65
+ `['BYOCWrapper', BYOCClientWrapper]`,
66
+ `['FEaaSWrapper', FEaaSClientWrapper]`,
67
+ `['Form', Form]`,
68
+ ];
41
69
  // Common builder for Next.js component map content
42
70
  const prepareComponentsForMap = (components, opts) => {
43
71
  const groups = new Map();
@@ -113,21 +141,16 @@ const prepareComponentsForMap = (components, opts) => {
113
141
  }
114
142
  return entries;
115
143
  };
116
- const buildNextjsMapContent = (entries, componentImports, options = {}) => {
117
- const isAppRouter = (0, utils_1.detectRouterType)() === 'app';
118
- const { headerComment = "Below are built-in components that are available in the app, it's recommended to keep them as is", isClientMap = false, } = options;
144
+ /**
145
+ * Distinguishes the simple 2-arity ComponentMapTemplate from the 3-arity EnhancedComponentMapTemplate.
146
+ * @param {ComponentMapTemplate | EnhancedComponentMapTemplate} fn The template function to check.
147
+ * @internal
148
+ */
149
+ const isComponentMapTemplate = (fn) => fn.length === 2;
150
+ const buildNextjsMapContent = (entries, componentImports, options) => {
151
+ const { headerComment = DEFAULT_HEADER_COMMENT, isClientMap = false, builtInImports, builtInMapEntries, } = options;
119
152
  const wildcardImports = [];
120
153
  const namedImports = [];
121
- const builtInImports = options.builtInImports ||
122
- `
123
- import { BYOCWrapper, NextjsContentSdkComponent, FEaaSWrapper } from '@sitecore-content-sdk/nextjs';
124
- import { Form } from '@sitecore-content-sdk/nextjs';
125
- `;
126
- const builtInMapEntries = options.builtInMapEntries || [
127
- `['BYOCWrapper', BYOCWrapper]`,
128
- `['FEaaSWrapper', FEaaSWrapper]`,
129
- `['Form', ${isAppRouter ? '{ ...Form, componentType: \'client\' }' : 'Form'}]`,
130
- ];
131
154
  // Add per-entry imports
132
155
  entries.forEach((e) => wildcardImports.push(...e.imports));
133
156
  // Handle package imports
@@ -145,8 +168,8 @@ import { Form } from '@sitecore-content-sdk/nextjs';
145
168
  ...namedImports,
146
169
  ].filter(Boolean);
147
170
  const importsSection = importLines.length ? `\n${importLines.join('\n')}` : '';
148
- // Build entry lines (package named imports are appended below)
149
- const componentMapEntries = builtInMapEntries;
171
+ // Clone to avoid mutating the caller's array
172
+ const componentMapEntries = structuredClone(builtInMapEntries);
150
173
  for (const e of entries) {
151
174
  const value = !isClientMap && e.annotateClient
152
175
  ? `{ ${e.valueExpr}, componentType: 'client' }`
@@ -179,26 +202,31 @@ ${componentMapEntries
179
202
  export default componentMap;
180
203
  `;
181
204
  };
182
- // default client template
205
+ // Default App Router (server) component map template
206
+ const defaultServerMapTemplate = (components, componentImports, ctx) => {
207
+ var _a, _b;
208
+ const entries = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.entries) !== null && _a !== void 0 ? _a : prepareComponentsForMap(components, {
209
+ includeVariants: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.includeVariants) !== null && _b !== void 0 ? _b : true,
210
+ });
211
+ return buildNextjsMapContent(entries, componentImports, {
212
+ headerComment: DEFAULT_HEADER_COMMENT,
213
+ isClientMap: false,
214
+ builtInImports: APP_ROUTER_BUILTIN_IMPORTS,
215
+ builtInMapEntries: APP_ROUTER_BUILTIN_ENTRIES,
216
+ });
217
+ };
218
+ exports.defaultServerMapTemplate = defaultServerMapTemplate;
219
+ // Default client-safe component map template for App Router
183
220
  const defaultClientMapTemplate = (components, componentImports, ctx) => {
184
221
  var _a, _b;
185
- const builtInImports = `
186
- import { BYOCClientWrapper, NextjsContentSdkComponent, FEaaSClientWrapper } from '@sitecore-content-sdk/nextjs';
187
- import { Form } from '@sitecore-content-sdk/nextjs';
188
- `;
189
- const builtInMapEntries = [
190
- `['BYOCWrapper', BYOCClientWrapper]`,
191
- `['FEaaSWrapper', FEaaSClientWrapper]`,
192
- `['Form', Form]`,
193
- ];
194
222
  const entries = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.entries) !== null && _a !== void 0 ? _a : prepareComponentsForMap(components, {
195
223
  includeVariants: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.includeVariants) !== null && _b !== void 0 ? _b : true,
196
224
  });
197
225
  return buildNextjsMapContent(entries, componentImports, {
198
226
  headerComment: 'Client-safe component map for App Router',
199
227
  isClientMap: true,
200
- builtInImports,
201
- builtInMapEntries,
228
+ builtInImports: CLIENT_MAP_BUILTIN_IMPORTS,
229
+ builtInMapEntries: CLIENT_MAP_BUILTIN_ENTRIES,
202
230
  });
203
231
  };
204
232
  exports.defaultClientMapTemplate = defaultClientMapTemplate;
@@ -219,116 +247,91 @@ const collectComponents = (opts) => {
219
247
  /**
220
248
  * Generate and write componentMap.ts files based on provided params.
221
249
  *
222
- * When clientComponentMap is true, generates:
250
+ * Pages Router:
251
+ * - component-map.ts : Single component map with Pages Router wrappers
252
+ *
253
+ * App Router (clientComponentMap=true):
223
254
  * - component-map.ts : Full component map with all components (server, client, universal)
224
- * - component-map.client.ts : Client-safe map with only client + universal components
255
+ * - component-map.client.ts : Client-safe map with client + universal components
225
256
  *
226
- * When clientComponentMap is false, generates:
227
- * - component-map.ts : Single component map (traditional behavior)
257
+ * App Router (clientComponentMap=false or undefined):
258
+ * - component-map.ts : Full component map with all components (server, client, universal)
259
+ * - component-map.client.ts : Client-safe map with built-in components only (no user components)
228
260
  *
229
- * When includeVariants is true (in either mode):
261
+ * When includeVariants is true:
230
262
  * - Includes component **variants** in the generated map(s) alongside base components
231
263
  * - Preserves the same client/server filtering rules (variants obey clientComponentMap filtering)
232
264
  * - Variant entries are emitted using the same naming/keys convention as their base components
233
265
  *
234
266
  * Template Customization:
235
267
  * - mapTemplate: Custom template for main component map (works for both single and dual map modes)
236
- * - clientMapTemplate: Custom template for client component map (only used when clientComponentMap is true)
268
+ * - clientMapTemplate: Custom template for client component map (App Router only)
237
269
  * @param {GenerateMapArgs} params - The parameters for the generateMap function.
238
270
  * @public
239
271
  */
240
272
  const generateMap = ({ paths, destination = '.sitecore', exclude, componentImports, mapTemplate, clientMapTemplate, clientComponentMap, includeVariants = true, }) => {
241
- const isAppRouter = (0, utils_1.detectRouterType)() === 'app';
242
- const shouldGenerateClientMap = clientComponentMap !== null && clientComponentMap !== void 0 ? clientComponentMap : isAppRouter;
243
- if (shouldGenerateClientMap) {
244
- // App Router case, main map
245
- const getComponents = collectComponents({ paths, exclude, includeVariants, filter: 'all' });
246
- let mainContent;
247
- if (mapTemplate) {
248
- mainContent = mapTemplate(getComponents.raw, componentImports, {
249
- entries: getComponents.entries,
273
+ const routerType = (0, utils_1.detectRouterType)();
274
+ const allComponents = collectComponents({ paths, exclude, includeVariants, filter: 'all' });
275
+ if (routerType === utils_1.ROUTER_TYPE.PAGES) {
276
+ const content = mapTemplate
277
+ ? mapTemplate(allComponents.raw, componentImports, {
278
+ entries: allComponents.entries,
250
279
  includeVariants,
251
280
  isClientMap: false,
252
- });
253
- }
254
- else {
255
- // default app router server map
256
- const builtInImports = `
257
- import { BYOCServerWrapper, NextjsContentSdkComponent, FEaaSServerWrapper } from '@sitecore-content-sdk/nextjs';
258
- import { Form } from '@sitecore-content-sdk/nextjs';
259
- `;
260
- const builtInMapEntries = [
261
- `['BYOCWrapper', BYOCServerWrapper]`,
262
- `['FEaaSWrapper', FEaaSServerWrapper]`,
263
- `['Form', { ...Form, componentType: 'client' }]`,
264
- ];
265
- mainContent = buildNextjsMapContent(getComponents.entries, componentImports, {
266
- headerComment: "Below are built-in components that are available in the app, it's recommended to keep them as is",
281
+ })
282
+ : buildNextjsMapContent(allComponents.entries, componentImports, {
267
283
  isClientMap: false,
268
- builtInImports,
269
- builtInMapEntries,
284
+ builtInImports: PAGES_ROUTER_BUILTIN_IMPORTS,
285
+ builtInMapEntries: PAGES_ROUTER_BUILTIN_ENTRIES,
270
286
  });
287
+ try {
288
+ fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), content, 'utf8');
271
289
  }
272
- fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), mainContent, 'utf8');
273
- // App Router, client map
274
- const clientComponents = collectComponents({
275
- paths,
276
- exclude,
277
- includeVariants,
278
- filter: 'client',
279
- });
280
- const clientTemplate = clientMapTemplate || exports.defaultClientMapTemplate;
281
- let clientContent;
282
- if (clientTemplate.length >= 2) {
283
- clientContent = clientTemplate(clientComponents.raw, componentImports);
284
- }
285
- else {
286
- clientContent = clientTemplate(clientComponents.raw, componentImports, {
287
- entries: clientComponents.entries,
288
- includeVariants,
289
- isClientMap: true,
290
- });
290
+ catch (error) {
291
+ console.error(`Component Map generation failed. Error writing to file ${destination}:`, error);
292
+ throw error;
291
293
  }
292
- fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.client.ts'), clientContent, 'utf8');
294
+ return;
293
295
  }
294
- else {
295
- // Either in pages/app router or clientComponentMap = false
296
- const components = collectComponents({
297
- paths,
298
- exclude,
296
+ const mainContent = mapTemplate
297
+ ? mapTemplate(allComponents.raw, componentImports, {
298
+ entries: allComponents.entries,
299
+ includeVariants,
300
+ isClientMap: false,
301
+ })
302
+ : (0, exports.defaultServerMapTemplate)(allComponents.raw, componentImports, {
303
+ entries: allComponents.entries,
299
304
  includeVariants,
300
- filter: 'all',
301
- }).entries;
302
- const content = buildNextjsMapContent(components, componentImports, {
303
- headerComment: "Below are built-in components that are available in the app, it's recommended to keep them as is",
304
305
  isClientMap: false,
305
306
  });
306
- fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), content, 'utf8');
307
- // For App Router compatibility, always generate client map file even when clientComponentMap is false
308
- // When clientComponentMap is false, only include built-in components (no custom client components)
309
- if (shouldGenerateClientMap || isAppRouter) {
310
- const clientMapTemplateToUse = clientMapTemplate || exports.defaultClientMapTemplate;
311
- const components = collectComponents({ paths: [], includeVariants, filter: 'all' });
312
- let clientMapContent;
313
- if (clientMapTemplateToUse.length >= 2) {
314
- clientMapContent = clientMapTemplateToUse([], componentImports);
315
- }
316
- else {
317
- clientMapContent = clientMapTemplateToUse([], componentImports, {
318
- entries: components.entries,
319
- includeVariants,
320
- isClientMap: true,
321
- });
322
- }
323
- const clientMapFile = path.join(process.cwd(), destination, 'component-map.client.ts');
324
- try {
325
- fs.writeFileSync(clientMapFile, clientMapContent, { encoding: 'utf8' });
326
- }
327
- catch (error) {
328
- console.error(`Client Component Map generation failed. Error writing to file ${destination}:`, error);
329
- throw error;
330
- }
331
- }
307
+ try {
308
+ fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), mainContent, 'utf8');
309
+ }
310
+ catch (error) {
311
+ console.error(`Main Component Map generation failed. Error writing to file ${destination}:`, error);
312
+ throw error;
313
+ }
314
+ // clientComponentMap=true -> include user client+universal components
315
+ // clientComponentMap=false -> built-ins only
316
+ const clientComponents = clientComponentMap
317
+ ? collectComponents({ paths, exclude, includeVariants, filter: 'client' })
318
+ : { raw: [], entries: [] };
319
+ const clientTemplate = clientMapTemplate || exports.defaultClientMapTemplate;
320
+ let clientContent;
321
+ if (isComponentMapTemplate(clientTemplate))
322
+ clientContent = clientTemplate(clientComponents.raw, componentImports);
323
+ else
324
+ clientContent = clientTemplate(clientComponents.raw, componentImports, {
325
+ entries: clientComponents.entries,
326
+ includeVariants,
327
+ isClientMap: true,
328
+ });
329
+ try {
330
+ fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.client.ts'), clientContent, 'utf8');
331
+ }
332
+ catch (error) {
333
+ console.error(`Client Component Map generation failed. Error writing to file ${destination}:`, error);
334
+ throw error;
332
335
  }
333
336
  };
334
337
  exports.generateMap = generateMap;
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ROUTER_TYPE = void 0;
6
7
  exports.detectRouterType = detectRouterType;
7
8
  exports.detectComponentType = detectComponentType;
8
9
  exports.getComponentListWithTypes = getComponentListWithTypes;
@@ -12,6 +13,17 @@ exports.nextjsDefaultMapTemplate = nextjsDefaultMapTemplate;
12
13
  const node_tools_1 = require("@sitecore-content-sdk/content/node-tools");
13
14
  const typescript_1 = __importDefault(require("typescript"));
14
15
  const fs_1 = __importDefault(require("fs"));
16
+ /**
17
+ * Constants for Next.js router types. Used for consistent detection and comparison throughout the codebase.
18
+ * Values are based on Next.js conventions:
19
+ * - 'app' for App Router (src/app or app directory)
20
+ * - 'pages' for Pages Router (src/pages or pages directory)
21
+ * @internal
22
+ */
23
+ exports.ROUTER_TYPE = {
24
+ APP: 'app',
25
+ PAGES: 'pages',
26
+ };
15
27
  /**
16
28
  * Detects the Next.js router type (App Router or Pages Router) based on directory structure.
17
29
  * @param {string} projectRoot - The project root directory. Defaults to current working directory.
@@ -19,15 +31,15 @@ const fs_1 = __importDefault(require("fs"));
19
31
  * @internal
20
32
  */
21
33
  function detectRouterType(projectRoot = process.cwd()) {
22
- const appDirExists = fs_1.default.existsSync(`${projectRoot}/src/app`) || fs_1.default.existsSync(`${projectRoot}/app`);
23
- const pagesDirExists = fs_1.default.existsSync(`${projectRoot}/src/pages`) || fs_1.default.existsSync(`${projectRoot}/pages`);
24
- if (appDirExists) {
25
- return 'app';
26
- }
27
- if (pagesDirExists) {
28
- return 'pages';
29
- }
30
- return 'pages';
34
+ const appDirExists = fs_1.default.existsSync(`${projectRoot}/src/${exports.ROUTER_TYPE.APP}`) ||
35
+ fs_1.default.existsSync(`${projectRoot}/${exports.ROUTER_TYPE.APP}`);
36
+ const pagesDirExists = fs_1.default.existsSync(`${projectRoot}/src/${exports.ROUTER_TYPE.PAGES}`) ||
37
+ fs_1.default.existsSync(`${projectRoot}/${exports.ROUTER_TYPE.PAGES}`);
38
+ if (appDirExists)
39
+ return exports.ROUTER_TYPE.APP;
40
+ if (pagesDirExists)
41
+ return exports.ROUTER_TYPE.PAGES;
42
+ return exports.ROUTER_TYPE.PAGES;
31
43
  }
32
44
  /**
33
45
  * Detects the component type based on directives, imports, and router context.
@@ -155,7 +167,7 @@ function detectComponentType(filePath, routerType) {
155
167
  // Router-aware defaults:
156
168
  // - App Router: defaults to server (RSC by default)
157
169
  // - Pages Router: defaults to universal (isomorphic by default)
158
- if (detectedRouterType === 'app') {
170
+ if (detectedRouterType === exports.ROUTER_TYPE.APP) {
159
171
  return 'server';
160
172
  }
161
173
  else {
@@ -1,7 +1,35 @@
1
1
  import { filterComponentsByType, } from '@sitecore-content-sdk/content/tools';
2
2
  import * as path from 'path';
3
3
  import * as fs from 'fs';
4
- import { detectRouterType, getComponentListWithTypes } from './templating/utils';
4
+ import { detectRouterType, getComponentListWithTypes, ROUTER_TYPE } from './templating/utils';
5
+ const DEFAULT_HEADER_COMMENT = "Below are built-in components that are available in the app, it's recommended to keep them as is";
6
+ const APP_ROUTER_BUILTIN_IMPORTS = `
7
+ import { BYOCServerWrapper, NextjsContentSdkComponent, FEaaSServerWrapper } from '@sitecore-content-sdk/nextjs';
8
+ import { Form } from '@sitecore-content-sdk/nextjs';
9
+ `;
10
+ const APP_ROUTER_BUILTIN_ENTRIES = [
11
+ `['BYOCWrapper', BYOCServerWrapper]`,
12
+ `['FEaaSWrapper', FEaaSServerWrapper]`,
13
+ `['Form', { ...Form, componentType: 'client' }]`,
14
+ ];
15
+ const PAGES_ROUTER_BUILTIN_IMPORTS = `
16
+ import { BYOCWrapper, NextjsContentSdkComponent, FEaaSWrapper } from '@sitecore-content-sdk/nextjs';
17
+ import { Form } from '@sitecore-content-sdk/nextjs';
18
+ `;
19
+ const PAGES_ROUTER_BUILTIN_ENTRIES = [
20
+ `['BYOCWrapper', BYOCWrapper]`,
21
+ `['FEaaSWrapper', FEaaSWrapper]`,
22
+ `['Form', Form]`,
23
+ ];
24
+ const CLIENT_MAP_BUILTIN_IMPORTS = `
25
+ import { BYOCClientWrapper, NextjsContentSdkComponent, FEaaSClientWrapper } from '@sitecore-content-sdk/nextjs';
26
+ import { Form } from '@sitecore-content-sdk/nextjs';
27
+ `;
28
+ const CLIENT_MAP_BUILTIN_ENTRIES = [
29
+ `['BYOCWrapper', BYOCClientWrapper]`,
30
+ `['FEaaSWrapper', FEaaSClientWrapper]`,
31
+ `['Form', Form]`,
32
+ ];
5
33
  // Common builder for Next.js component map content
6
34
  const prepareComponentsForMap = (components, opts) => {
7
35
  const groups = new Map();
@@ -77,21 +105,16 @@ const prepareComponentsForMap = (components, opts) => {
77
105
  }
78
106
  return entries;
79
107
  };
80
- const buildNextjsMapContent = (entries, componentImports, options = {}) => {
81
- const isAppRouter = detectRouterType() === 'app';
82
- const { headerComment = "Below are built-in components that are available in the app, it's recommended to keep them as is", isClientMap = false, } = options;
108
+ /**
109
+ * Distinguishes the simple 2-arity ComponentMapTemplate from the 3-arity EnhancedComponentMapTemplate.
110
+ * @param {ComponentMapTemplate | EnhancedComponentMapTemplate} fn The template function to check.
111
+ * @internal
112
+ */
113
+ const isComponentMapTemplate = (fn) => fn.length === 2;
114
+ const buildNextjsMapContent = (entries, componentImports, options) => {
115
+ const { headerComment = DEFAULT_HEADER_COMMENT, isClientMap = false, builtInImports, builtInMapEntries, } = options;
83
116
  const wildcardImports = [];
84
117
  const namedImports = [];
85
- const builtInImports = options.builtInImports ||
86
- `
87
- import { BYOCWrapper, NextjsContentSdkComponent, FEaaSWrapper } from '@sitecore-content-sdk/nextjs';
88
- import { Form } from '@sitecore-content-sdk/nextjs';
89
- `;
90
- const builtInMapEntries = options.builtInMapEntries || [
91
- `['BYOCWrapper', BYOCWrapper]`,
92
- `['FEaaSWrapper', FEaaSWrapper]`,
93
- `['Form', ${isAppRouter ? '{ ...Form, componentType: \'client\' }' : 'Form'}]`,
94
- ];
95
118
  // Add per-entry imports
96
119
  entries.forEach((e) => wildcardImports.push(...e.imports));
97
120
  // Handle package imports
@@ -109,8 +132,8 @@ import { Form } from '@sitecore-content-sdk/nextjs';
109
132
  ...namedImports,
110
133
  ].filter(Boolean);
111
134
  const importsSection = importLines.length ? `\n${importLines.join('\n')}` : '';
112
- // Build entry lines (package named imports are appended below)
113
- const componentMapEntries = builtInMapEntries;
135
+ // Clone to avoid mutating the caller's array
136
+ const componentMapEntries = structuredClone(builtInMapEntries);
114
137
  for (const e of entries) {
115
138
  const value = !isClientMap && e.annotateClient
116
139
  ? `{ ${e.valueExpr}, componentType: 'client' }`
@@ -143,26 +166,30 @@ ${componentMapEntries
143
166
  export default componentMap;
144
167
  `;
145
168
  };
146
- // default client template
169
+ // Default App Router (server) component map template
170
+ export const defaultServerMapTemplate = (components, componentImports, ctx) => {
171
+ var _a, _b;
172
+ const entries = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.entries) !== null && _a !== void 0 ? _a : prepareComponentsForMap(components, {
173
+ includeVariants: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.includeVariants) !== null && _b !== void 0 ? _b : true,
174
+ });
175
+ return buildNextjsMapContent(entries, componentImports, {
176
+ headerComment: DEFAULT_HEADER_COMMENT,
177
+ isClientMap: false,
178
+ builtInImports: APP_ROUTER_BUILTIN_IMPORTS,
179
+ builtInMapEntries: APP_ROUTER_BUILTIN_ENTRIES,
180
+ });
181
+ };
182
+ // Default client-safe component map template for App Router
147
183
  export const defaultClientMapTemplate = (components, componentImports, ctx) => {
148
184
  var _a, _b;
149
- const builtInImports = `
150
- import { BYOCClientWrapper, NextjsContentSdkComponent, FEaaSClientWrapper } from '@sitecore-content-sdk/nextjs';
151
- import { Form } from '@sitecore-content-sdk/nextjs';
152
- `;
153
- const builtInMapEntries = [
154
- `['BYOCWrapper', BYOCClientWrapper]`,
155
- `['FEaaSWrapper', FEaaSClientWrapper]`,
156
- `['Form', Form]`,
157
- ];
158
185
  const entries = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.entries) !== null && _a !== void 0 ? _a : prepareComponentsForMap(components, {
159
186
  includeVariants: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.includeVariants) !== null && _b !== void 0 ? _b : true,
160
187
  });
161
188
  return buildNextjsMapContent(entries, componentImports, {
162
189
  headerComment: 'Client-safe component map for App Router',
163
190
  isClientMap: true,
164
- builtInImports,
165
- builtInMapEntries,
191
+ builtInImports: CLIENT_MAP_BUILTIN_IMPORTS,
192
+ builtInMapEntries: CLIENT_MAP_BUILTIN_ENTRIES,
166
193
  });
167
194
  };
168
195
  // Collect components from specified paths, apply exclude and type filter, and prepare map entries.
@@ -182,115 +209,90 @@ const collectComponents = (opts) => {
182
209
  /**
183
210
  * Generate and write componentMap.ts files based on provided params.
184
211
  *
185
- * When clientComponentMap is true, generates:
212
+ * Pages Router:
213
+ * - component-map.ts : Single component map with Pages Router wrappers
214
+ *
215
+ * App Router (clientComponentMap=true):
186
216
  * - component-map.ts : Full component map with all components (server, client, universal)
187
- * - component-map.client.ts : Client-safe map with only client + universal components
217
+ * - component-map.client.ts : Client-safe map with client + universal components
188
218
  *
189
- * When clientComponentMap is false, generates:
190
- * - component-map.ts : Single component map (traditional behavior)
219
+ * App Router (clientComponentMap=false or undefined):
220
+ * - component-map.ts : Full component map with all components (server, client, universal)
221
+ * - component-map.client.ts : Client-safe map with built-in components only (no user components)
191
222
  *
192
- * When includeVariants is true (in either mode):
223
+ * When includeVariants is true:
193
224
  * - Includes component **variants** in the generated map(s) alongside base components
194
225
  * - Preserves the same client/server filtering rules (variants obey clientComponentMap filtering)
195
226
  * - Variant entries are emitted using the same naming/keys convention as their base components
196
227
  *
197
228
  * Template Customization:
198
229
  * - mapTemplate: Custom template for main component map (works for both single and dual map modes)
199
- * - clientMapTemplate: Custom template for client component map (only used when clientComponentMap is true)
230
+ * - clientMapTemplate: Custom template for client component map (App Router only)
200
231
  * @param {GenerateMapArgs} params - The parameters for the generateMap function.
201
232
  * @public
202
233
  */
203
234
  export const generateMap = ({ paths, destination = '.sitecore', exclude, componentImports, mapTemplate, clientMapTemplate, clientComponentMap, includeVariants = true, }) => {
204
- const isAppRouter = detectRouterType() === 'app';
205
- const shouldGenerateClientMap = clientComponentMap !== null && clientComponentMap !== void 0 ? clientComponentMap : isAppRouter;
206
- if (shouldGenerateClientMap) {
207
- // App Router case, main map
208
- const getComponents = collectComponents({ paths, exclude, includeVariants, filter: 'all' });
209
- let mainContent;
210
- if (mapTemplate) {
211
- mainContent = mapTemplate(getComponents.raw, componentImports, {
212
- entries: getComponents.entries,
235
+ const routerType = detectRouterType();
236
+ const allComponents = collectComponents({ paths, exclude, includeVariants, filter: 'all' });
237
+ if (routerType === ROUTER_TYPE.PAGES) {
238
+ const content = mapTemplate
239
+ ? mapTemplate(allComponents.raw, componentImports, {
240
+ entries: allComponents.entries,
213
241
  includeVariants,
214
242
  isClientMap: false,
215
- });
216
- }
217
- else {
218
- // default app router server map
219
- const builtInImports = `
220
- import { BYOCServerWrapper, NextjsContentSdkComponent, FEaaSServerWrapper } from '@sitecore-content-sdk/nextjs';
221
- import { Form } from '@sitecore-content-sdk/nextjs';
222
- `;
223
- const builtInMapEntries = [
224
- `['BYOCWrapper', BYOCServerWrapper]`,
225
- `['FEaaSWrapper', FEaaSServerWrapper]`,
226
- `['Form', { ...Form, componentType: 'client' }]`,
227
- ];
228
- mainContent = buildNextjsMapContent(getComponents.entries, componentImports, {
229
- headerComment: "Below are built-in components that are available in the app, it's recommended to keep them as is",
243
+ })
244
+ : buildNextjsMapContent(allComponents.entries, componentImports, {
230
245
  isClientMap: false,
231
- builtInImports,
232
- builtInMapEntries,
246
+ builtInImports: PAGES_ROUTER_BUILTIN_IMPORTS,
247
+ builtInMapEntries: PAGES_ROUTER_BUILTIN_ENTRIES,
233
248
  });
249
+ try {
250
+ fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), content, 'utf8');
234
251
  }
235
- fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), mainContent, 'utf8');
236
- // App Router, client map
237
- const clientComponents = collectComponents({
238
- paths,
239
- exclude,
240
- includeVariants,
241
- filter: 'client',
242
- });
243
- const clientTemplate = clientMapTemplate || defaultClientMapTemplate;
244
- let clientContent;
245
- if (clientTemplate.length >= 2) {
246
- clientContent = clientTemplate(clientComponents.raw, componentImports);
247
- }
248
- else {
249
- clientContent = clientTemplate(clientComponents.raw, componentImports, {
250
- entries: clientComponents.entries,
251
- includeVariants,
252
- isClientMap: true,
253
- });
252
+ catch (error) {
253
+ console.error(`Component Map generation failed. Error writing to file ${destination}:`, error);
254
+ throw error;
254
255
  }
255
- fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.client.ts'), clientContent, 'utf8');
256
+ return;
256
257
  }
257
- else {
258
- // Either in pages/app router or clientComponentMap = false
259
- const components = collectComponents({
260
- paths,
261
- exclude,
258
+ const mainContent = mapTemplate
259
+ ? mapTemplate(allComponents.raw, componentImports, {
260
+ entries: allComponents.entries,
261
+ includeVariants,
262
+ isClientMap: false,
263
+ })
264
+ : defaultServerMapTemplate(allComponents.raw, componentImports, {
265
+ entries: allComponents.entries,
262
266
  includeVariants,
263
- filter: 'all',
264
- }).entries;
265
- const content = buildNextjsMapContent(components, componentImports, {
266
- headerComment: "Below are built-in components that are available in the app, it's recommended to keep them as is",
267
267
  isClientMap: false,
268
268
  });
269
- fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), content, 'utf8');
270
- // For App Router compatibility, always generate client map file even when clientComponentMap is false
271
- // When clientComponentMap is false, only include built-in components (no custom client components)
272
- if (shouldGenerateClientMap || isAppRouter) {
273
- const clientMapTemplateToUse = clientMapTemplate || defaultClientMapTemplate;
274
- const components = collectComponents({ paths: [], includeVariants, filter: 'all' });
275
- let clientMapContent;
276
- if (clientMapTemplateToUse.length >= 2) {
277
- clientMapContent = clientMapTemplateToUse([], componentImports);
278
- }
279
- else {
280
- clientMapContent = clientMapTemplateToUse([], componentImports, {
281
- entries: components.entries,
282
- includeVariants,
283
- isClientMap: true,
284
- });
285
- }
286
- const clientMapFile = path.join(process.cwd(), destination, 'component-map.client.ts');
287
- try {
288
- fs.writeFileSync(clientMapFile, clientMapContent, { encoding: 'utf8' });
289
- }
290
- catch (error) {
291
- console.error(`Client Component Map generation failed. Error writing to file ${destination}:`, error);
292
- throw error;
293
- }
294
- }
269
+ try {
270
+ fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.ts'), mainContent, 'utf8');
271
+ }
272
+ catch (error) {
273
+ console.error(`Main Component Map generation failed. Error writing to file ${destination}:`, error);
274
+ throw error;
275
+ }
276
+ // clientComponentMap=true -> include user client+universal components
277
+ // clientComponentMap=false -> built-ins only
278
+ const clientComponents = clientComponentMap
279
+ ? collectComponents({ paths, exclude, includeVariants, filter: 'client' })
280
+ : { raw: [], entries: [] };
281
+ const clientTemplate = clientMapTemplate || defaultClientMapTemplate;
282
+ let clientContent;
283
+ if (isComponentMapTemplate(clientTemplate))
284
+ clientContent = clientTemplate(clientComponents.raw, componentImports);
285
+ else
286
+ clientContent = clientTemplate(clientComponents.raw, componentImports, {
287
+ entries: clientComponents.entries,
288
+ includeVariants,
289
+ isClientMap: true,
290
+ });
291
+ try {
292
+ fs.writeFileSync(path.join(process.cwd(), destination, 'component-map.client.ts'), clientContent, 'utf8');
293
+ }
294
+ catch (error) {
295
+ console.error(`Client Component Map generation failed. Error writing to file ${destination}:`, error);
296
+ throw error;
295
297
  }
296
298
  };
@@ -1,6 +1,17 @@
1
1
  import { getComponentList, defaultImportMapTemplate, } from '@sitecore-content-sdk/content/node-tools';
2
2
  import ts from 'typescript';
3
3
  import fs from 'fs';
4
+ /**
5
+ * Constants for Next.js router types. Used for consistent detection and comparison throughout the codebase.
6
+ * Values are based on Next.js conventions:
7
+ * - 'app' for App Router (src/app or app directory)
8
+ * - 'pages' for Pages Router (src/pages or pages directory)
9
+ * @internal
10
+ */
11
+ export const ROUTER_TYPE = {
12
+ APP: 'app',
13
+ PAGES: 'pages',
14
+ };
4
15
  /**
5
16
  * Detects the Next.js router type (App Router or Pages Router) based on directory structure.
6
17
  * @param {string} projectRoot - The project root directory. Defaults to current working directory.
@@ -8,15 +19,15 @@ import fs from 'fs';
8
19
  * @internal
9
20
  */
10
21
  export function detectRouterType(projectRoot = process.cwd()) {
11
- const appDirExists = fs.existsSync(`${projectRoot}/src/app`) || fs.existsSync(`${projectRoot}/app`);
12
- const pagesDirExists = fs.existsSync(`${projectRoot}/src/pages`) || fs.existsSync(`${projectRoot}/pages`);
13
- if (appDirExists) {
14
- return 'app';
15
- }
16
- if (pagesDirExists) {
17
- return 'pages';
18
- }
19
- return 'pages';
22
+ const appDirExists = fs.existsSync(`${projectRoot}/src/${ROUTER_TYPE.APP}`) ||
23
+ fs.existsSync(`${projectRoot}/${ROUTER_TYPE.APP}`);
24
+ const pagesDirExists = fs.existsSync(`${projectRoot}/src/${ROUTER_TYPE.PAGES}`) ||
25
+ fs.existsSync(`${projectRoot}/${ROUTER_TYPE.PAGES}`);
26
+ if (appDirExists)
27
+ return ROUTER_TYPE.APP;
28
+ if (pagesDirExists)
29
+ return ROUTER_TYPE.PAGES;
30
+ return ROUTER_TYPE.PAGES;
20
31
  }
21
32
  /**
22
33
  * Detects the component type based on directives, imports, and router context.
@@ -144,7 +155,7 @@ export function detectComponentType(filePath, routerType) {
144
155
  // Router-aware defaults:
145
156
  // - App Router: defaults to server (RSC by default)
146
157
  // - Pages Router: defaults to universal (isomorphic by default)
147
- if (detectedRouterType === 'app') {
158
+ if (detectedRouterType === ROUTER_TYPE.APP) {
148
159
  return 'server';
149
160
  }
150
161
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/nextjs",
3
- "version": "2.1.0",
3
+ "version": "2.1.1-canary.20260507131755",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -178,7 +178,7 @@
178
178
  },
179
179
  "description": "",
180
180
  "types": "types/index.d.ts",
181
- "gitHead": "c505c331a61f4ebf65f1bd5fe514cb0ab9192c56",
181
+ "gitHead": "2f4820efddf4454eeee58ed1b2cc251969efdf5b",
182
182
  "files": [
183
183
  "dist",
184
184
  "types",
@@ -1,24 +1,29 @@
1
1
  import { GenerateMapFunction, EnhancedComponentMapTemplate } from '@sitecore-content-sdk/content/tools';
2
+ export declare const defaultServerMapTemplate: EnhancedComponentMapTemplate;
2
3
  export declare const defaultClientMapTemplate: EnhancedComponentMapTemplate;
3
4
  export type CollectFilter = 'all' | 'client' | 'server' | 'universal';
4
5
  /**
5
6
  * Generate and write componentMap.ts files based on provided params.
6
7
  *
7
- * When clientComponentMap is true, generates:
8
+ * Pages Router:
9
+ * - component-map.ts : Single component map with Pages Router wrappers
10
+ *
11
+ * App Router (clientComponentMap=true):
8
12
  * - component-map.ts : Full component map with all components (server, client, universal)
9
- * - component-map.client.ts : Client-safe map with only client + universal components
13
+ * - component-map.client.ts : Client-safe map with client + universal components
10
14
  *
11
- * When clientComponentMap is false, generates:
12
- * - component-map.ts : Single component map (traditional behavior)
15
+ * App Router (clientComponentMap=false or undefined):
16
+ * - component-map.ts : Full component map with all components (server, client, universal)
17
+ * - component-map.client.ts : Client-safe map with built-in components only (no user components)
13
18
  *
14
- * When includeVariants is true (in either mode):
19
+ * When includeVariants is true:
15
20
  * - Includes component **variants** in the generated map(s) alongside base components
16
21
  * - Preserves the same client/server filtering rules (variants obey clientComponentMap filtering)
17
22
  * - Variant entries are emitted using the same naming/keys convention as their base components
18
23
  *
19
24
  * Template Customization:
20
25
  * - mapTemplate: Custom template for main component map (works for both single and dual map modes)
21
- * - clientMapTemplate: Custom template for client component map (only used when clientComponentMap is true)
26
+ * - clientMapTemplate: Custom template for client component map (App Router only)
22
27
  * @param {GenerateMapArgs} params - The parameters for the generateMap function.
23
28
  * @public
24
29
  */
@@ -1 +1 @@
1
- {"version":3,"file":"generate-map.d.ts","sourceRoot":"","sources":["../../src/tools/generate-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EAInB,4BAA4B,EAG7B,MAAM,qCAAqC,CAAC;AAuM7C,eAAO,MAAM,wBAAwB,EAAE,4BA4BtC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AA6BtE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,WAAW,EAAE,mBAkIzB,CAAC"}
1
+ {"version":3,"file":"generate-map.d.ts","sourceRoot":"","sources":["../../src/tools/generate-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,mBAAmB,EAInB,4BAA4B,EAG7B,MAAM,qCAAqC,CAAC;AAyO7C,eAAO,MAAM,wBAAwB,EAAE,4BAiBtC,CAAC;AAGF,eAAO,MAAM,wBAAwB,EAAE,4BAiBtC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AA6BtE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,WAAW,EAAE,mBA+FzB,CAAC"}
@@ -1,5 +1,16 @@
1
1
  import { ComponentFileWithType, ComponentType, RouterType } from '@sitecore-content-sdk/content/tools';
2
2
  import { ModuleExports } from '@sitecore-content-sdk/content/node-tools';
3
+ /**
4
+ * Constants for Next.js router types. Used for consistent detection and comparison throughout the codebase.
5
+ * Values are based on Next.js conventions:
6
+ * - 'app' for App Router (src/app or app directory)
7
+ * - 'pages' for Pages Router (src/pages or pages directory)
8
+ * @internal
9
+ */
10
+ export declare const ROUTER_TYPE: {
11
+ readonly APP: "app";
12
+ readonly PAGES: "pages";
13
+ };
3
14
  /**
4
15
  * Detects the Next.js router type (App Router or Pages Router) based on directory structure.
5
16
  * @param {string} projectRoot - The project root directory. Defaults to current working directory.
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tools/templating/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,UAAU,EACX,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAGL,aAAa,EACd,MAAM,0CAA0C,CAAC;AAIlD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,GAAE,MAAsB,GAAG,UAAU,CAehF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,aAAa,CA0J5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,eAAe,CAAC,EAAE,OAAO,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,qBAAqB,EAAE,CAQzB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,UAGnF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,UAEpF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,UAEpF"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tools/templating/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,UAAU,EACX,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAGL,aAAa,EACd,MAAM,0CAA0C,CAAC;AAIlD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,GAAE,MAAsB,GAAG,UAAU,CAahF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,aAAa,CA0J5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,CAAC,EAAE,MAAM,EAAE,EAClB,eAAe,CAAC,EAAE,OAAO,EACzB,UAAU,CAAC,EAAE,UAAU,GACtB,qBAAqB,EAAE,CAQzB;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,UAGnF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,UAEpF;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,UAEpF"}