@graphcommerce/next-config 10.0.2 → 10.0.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`fdad2b7`](https://github.com/graphcommerce-org/graphcommerce/commit/fdad2b7a14a15c771077f3b836ca1f544f488cdd) - Added support in component props for Generic components. Solves an issue with creating plugins on the AddressFields component. ([@paales](https://github.com/paales))
8
+
9
+ - [`fdad2b7`](https://github.com/graphcommerce-org/graphcommerce/commit/fdad2b7a14a15c771077f3b836ca1f544f488cdd) - Fixed issue where additional props on a plugin did not carry to the final component. Now we can extend the original component's props with additional props from plugins. ([@paales](https://github.com/paales))
10
+
11
+ ## 10.0.3-canary.0
12
+
13
+ ### Patch Changes
14
+
15
+ - [`fdad2b7`](https://github.com/graphcommerce-org/graphcommerce/commit/fdad2b7a14a15c771077f3b836ca1f544f488cdd) - Added support in component props for Generic components. Solves an issue with creating plugins on the AddressFields component. ([@paales](https://github.com/paales))
16
+
17
+ - [`fdad2b7`](https://github.com/graphcommerce-org/graphcommerce/commit/fdad2b7a14a15c771077f3b836ca1f544f488cdd) - Fixed issue where additional props on a plugin did not carry to the final component. Now we can extend the original component's props with additional props from plugins. ([@paales](https://github.com/paales))
18
+
3
19
  ## 10.0.2
4
20
 
5
21
  ## 10.0.2-canary.0
package/dist/index.js CHANGED
@@ -733,15 +733,14 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
733
733
  `@see {@link file://./${targetExport}.original.tsx} for original source file`
734
734
  );
735
735
  }
736
+ let prevPropsName = null;
736
737
  const pluginInterceptors = componentPlugins.reverse().map((plugin) => {
737
738
  const pluginName = sourceName(name(plugin));
738
739
  const interceptorName2 = `${pluginName}${interceptorSuffix}`;
739
740
  const propsName = `${pluginName}Props`;
740
741
  pluginSee.push(`@see {${pluginName}} for source of applied plugin`);
741
- const result = `type ${propsName} = OmitPrev<
742
- React.ComponentProps<typeof ${pluginName}>,
743
- 'Prev'
744
- >
742
+ const propsType = prevPropsName ? `OmitPrev<React.ComponentProps<typeof ${pluginName}>, 'Prev'> & ${prevPropsName}` : `OmitPrev<React.ComponentProps<typeof ${pluginName}>, 'Prev'>`;
743
+ const result = `type ${propsName} = ${propsType}
745
744
 
746
745
  const ${interceptorName2} = (
747
746
  props: ${propsName},
@@ -752,6 +751,7 @@ const ${interceptorName2} = (
752
751
  />
753
752
  )`;
754
753
  carry = interceptorName2;
754
+ prevPropsName = propsName;
755
755
  return result;
756
756
  }).join("\n\n");
757
757
  const seeString = `/**
@@ -762,10 +762,12 @@ const ${interceptorName2} = (
762
762
  *
763
763
  ${pluginSee.map((s) => ` * ${s}`).join("\n")}
764
764
  */`;
765
+ const originalType = replacePlugin ? `typeof ${sourceName(name(replacePlugin))}` : `typeof ${targetExport}${originalSuffix}`;
766
+ const exportType = prevPropsName ? `${originalType} & React.FC<${prevPropsName}>` : originalType;
765
767
  return `${pluginInterceptors}
766
768
 
767
769
  ${seeString}
768
- export const ${targetExport} = ${carry}`;
770
+ export const ${targetExport} = ${carry} as ${exportType}`;
769
771
  } else if (plugins.some((p) => p.type === "function")) {
770
772
  const functionPlugins = plugins.filter((p) => p.type === "function");
771
773
  const replacePlugin = plugins.find((p) => p.type === "replace");
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/next-config",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "10.0.2",
5
+ "version": "10.0.3",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@apollo/client": "*",
66
- "@graphcommerce/prettier-config-pwa": "^10.0.2",
66
+ "@graphcommerce/prettier-config-pwa": "^10.0.3",
67
67
  "@lingui/loader": "*",
68
68
  "@lingui/macro": "*",
69
69
  "@lingui/react": "*",
@@ -204,6 +204,9 @@ export async function generateInterceptor(
204
204
  )
205
205
  }
206
206
 
207
+ // Track the accumulated props type name for chaining
208
+ let prevPropsName: string | null = null
209
+
207
210
  const pluginInterceptors = componentPlugins
208
211
  .reverse() // Start from the last plugin and work backwards
209
212
  .map((plugin) => {
@@ -213,10 +216,13 @@ export async function generateInterceptor(
213
216
 
214
217
  pluginSee.push(`@see {${pluginName}} for source of applied plugin`)
215
218
 
216
- const result = `type ${propsName} = OmitPrev<
217
- React.ComponentProps<typeof ${pluginName}>,
218
- 'Prev'
219
- >
219
+ // For the first plugin, just use OmitPrev
220
+ // For subsequent plugins, intersect with the previous accumulated props
221
+ const propsType = prevPropsName
222
+ ? `OmitPrev<React.ComponentProps<typeof ${pluginName}>, 'Prev'> & ${prevPropsName}`
223
+ : `OmitPrev<React.ComponentProps<typeof ${pluginName}>, 'Prev'>`
224
+
225
+ const result = `type ${propsName} = ${propsType}
220
226
 
221
227
  const ${interceptorName} = (
222
228
  props: ${propsName},
@@ -227,6 +233,7 @@ const ${interceptorName} = (
227
233
  />
228
234
  )`
229
235
  carry = interceptorName
236
+ prevPropsName = propsName
230
237
  return result
231
238
  })
232
239
  .join('\n\n')
@@ -240,10 +247,21 @@ const ${interceptorName} = (
240
247
  ${pluginSee.map((s) => ` * ${s}`).join('\n')}
241
248
  */`
242
249
 
250
+ // Cast to preserve generic signatures while also including accumulated plugin props
251
+ const originalType = replacePlugin
252
+ ? `typeof ${sourceName(name(replacePlugin))}`
253
+ : `typeof ${targetExport}${originalSuffix}`
254
+
255
+ // If we have accumulated props from plugins, include them in the type
256
+ // This creates a type that has both the original's generics AND the plugin's additional props
257
+ const exportType = prevPropsName
258
+ ? `${originalType} & React.FC<${prevPropsName}>`
259
+ : originalType
260
+
243
261
  return `${pluginInterceptors}
244
262
 
245
263
  ${seeString}
246
- export const ${targetExport} = ${carry}`
264
+ export const ${targetExport} = ${carry} as ${exportType}`
247
265
  } else if (plugins.some((p) => p.type === 'function')) {
248
266
  // Function plugins
249
267
  const functionPlugins = plugins.filter((p) => p.type === 'function')