@graphcommerce/next-config 10.1.0-canary.32 → 10.1.0-canary.36

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,23 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.1.0-canary.36
4
+
5
+ ## 10.1.0-canary.35
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2649](https://github.com/graphcommerce-org/graphcommerce/pull/2649) [`d81ac44`](https://github.com/graphcommerce-org/graphcommerce/commit/d81ac44f7749961aa518ee517b7e4699c19bb189) - Interceptors now forward the original module's default export. `export * from './X.original'` does not re-export `default` (ES semantics), so intercepting a module with a default export silently dropped it. This broke `gc-mesh build` when a plugin targeted `@graphcommerce/graphql-mesh/customFetch`: GraphQL Mesh resolves the fetch function via `exported.default || exported` and received the module namespace instead of the function, failing schema introspection with `Cannot read properties of undefined (reading '__schema')`. ([@paales](https://github.com/paales))
10
+
11
+ ## 10.1.0-canary.34
12
+
13
+ ### Patch Changes
14
+
15
+ - [#2647](https://github.com/graphcommerce-org/graphcommerce/pull/2647) [`789e69c`](https://github.com/graphcommerce-org/graphcommerce/commit/789e69c87ed260ee87f62e64c1bc830c0cf7f58d) - Fix plugin interceptor resolution for components exported via a non-aliased re-export.
16
+
17
+ The interceptor scanner (`findOriginalSource`) only inspected an export specifier's `exported` field, which SWC leaves `null` for a non-aliased re-export such as `export { Image }` (the name lives in `orig`; `exported` is only populated by an aliased `export { Foo as Image }`). As a result, any component re-exported without an alias — e.g. `Image` from `@graphcommerce/image` — could not be targeted by a plugin and failed with "Plugin target not found". The scanner now falls back to `orig` when `exported` is absent. ([@paales](https://github.com/paales))
18
+
19
+ ## 10.1.0-canary.33
20
+
3
21
  ## 10.1.0-canary.32
4
22
 
5
23
  ## 10.1.0-canary.31
@@ -720,3 +720,27 @@ it('Can correctly find exports that are default exports', async () => {
720
720
  "export { iconChevronLeft as iconChevronLeft } from '../../plugins/MyProjectIcon'",
721
721
  )
722
722
  })
723
+
724
+ it('forwards the default export of the original module', async () => {
725
+ const resolve = resolveDependency(projectRoot)
726
+ const interceptors = await generateInterceptors(
727
+ [
728
+ {
729
+ type: 'function',
730
+ targetExport: 'fetch',
731
+ sourceExport: 'fetch',
732
+ enabled: true,
733
+ targetModule: '@graphcommerce/graphql-mesh/customFetch',
734
+ sourceModule: './plugins/MyCustomFetch',
735
+ },
736
+ ],
737
+ resolve,
738
+ )
739
+ const result = interceptors['packages/graphql-mesh/customFetch']?.template
740
+
741
+ // `export *` does not include the default export; without an explicit forward, consumers that
742
+ // import the default (e.g. GraphQL Mesh resolving customFetch via `exported.default ||
743
+ // exported`) would receive the module namespace instead of the function.
744
+ expect(result).toContain("export * from './customFetch.original'")
745
+ expect(result).toContain("export { default } from './customFetch.original'")
746
+ })
package/dist/index.js CHANGED
@@ -623,7 +623,7 @@ function parseAndFindExport(resolved, findExport, resolve) {
623
623
  if (node.type === "ExportNamedDeclaration") {
624
624
  for (const specifier of node.specifiers) {
625
625
  if (specifier.type === "ExportSpecifier") {
626
- if (specifier.exported?.value === findExport) return resolved;
626
+ if ((specifier.exported?.value ?? specifier.orig.value) === findExport) return resolved;
627
627
  } else if (specifier.type === "ExportDefaultSpecifier") ; else if (specifier.type === "ExportNamespaceSpecifier") ;
628
628
  }
629
629
  }
@@ -695,6 +695,22 @@ const stableStringify = (obj) => {
695
695
  const pairs = keys.map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`);
696
696
  return `{${pairs.join(",")}}`;
697
697
  };
698
+ function hasDefaultExport(source) {
699
+ try {
700
+ return parseSync(source).body.some((node) => {
701
+ if (node.type === "ExportDefaultDeclaration" || node.type === "ExportDefaultExpression")
702
+ return true;
703
+ if (node.type === "ExportNamedDeclaration") {
704
+ return node.specifiers.some(
705
+ (s) => s.type === "ExportSpecifier" && (s.exported ?? s.orig).value === "default"
706
+ );
707
+ }
708
+ return false;
709
+ });
710
+ } catch {
711
+ return false;
712
+ }
713
+ }
698
714
  async function generateInterceptor(interceptor, config, oldInterceptorSource) {
699
715
  const hashInput = {
700
716
  dependency: interceptor.dependency,
@@ -828,7 +844,10 @@ export const ${targetExport} = ${carry}`;
828
844
 
829
845
  // Re-export everything from the original file except the intercepted exports
830
846
  export * from './${interceptor.target.split("/").pop()}.original'
831
-
847
+ ${hasDefaultExport(interceptor.source) ? `
848
+ // Forward the original module's default export: \`export *\` does not include it.
849
+ export { default } from './${interceptor.target.split("/").pop()}.original'
850
+ ` : ""}
832
851
  ${logOnce}${pluginExports}
833
852
  `;
834
853
  const formatted = await prettier.format(template, {
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.1.0-canary.32",
5
+ "version": "10.1.0-canary.36",
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.1.0-canary.32",
66
+ "@graphcommerce/prettier-config-pwa": "^10.1.0-canary.36",
67
67
  "@lingui/loader": "*",
68
68
  "@lingui/macro": "*",
69
69
  "@lingui/react": "*",
@@ -37,7 +37,11 @@ function parseAndFindExport(
37
37
  if (node.type === 'ExportNamedDeclaration') {
38
38
  for (const specifier of node.specifiers) {
39
39
  if (specifier.type === 'ExportSpecifier') {
40
- if (specifier.exported?.value === findExport) return resolved
40
+ // A non-aliased re-export (`export { Image }`) carries the name in
41
+ // `orig`, with `exported` left null; only an aliased re-export
42
+ // (`export { Foo as Image }`) populates `exported`. Fall back to
43
+ // `orig` so components exported without an alias remain interceptable.
44
+ if ((specifier.exported?.value ?? specifier.orig.value) === findExport) return resolved
41
45
  } else if (specifier.type === 'ExportDefaultSpecifier') {
42
46
  // todo
43
47
  } else if (specifier.type === 'ExportNamespaceSpecifier') {
@@ -2,6 +2,7 @@ import prettierConf from '@graphcommerce/prettier-config-pwa'
2
2
  import prettier from 'prettier'
3
3
  import type { GraphCommerceDebugConfig } from '../generated/config'
4
4
  import type { ResolveDependencyReturn } from '../utils/resolveDependency'
5
+ import { parseSync } from './swc'
5
6
 
6
7
  type PluginBaseConfig = {
7
8
  type: 'component' | 'function' | 'replace'
@@ -109,6 +110,34 @@ const stableStringify = (obj: any): string => {
109
110
  return `{${pairs.join(',')}}`
110
111
  }
111
112
 
113
+ /**
114
+ * `export * from './X.original'` does not re-export the original module's default export (ES
115
+ * semantics), so an intercepted module would silently lose it. Consumers that prefer the default
116
+ * export (e.g. GraphQL Mesh's getPackage does `exported.default || exported` to resolve
117
+ * `customFetch`) then receive the whole module namespace instead of the function, which breaks at
118
+ * runtime. Detect a default export so the interceptor can forward it explicitly.
119
+ *
120
+ * On regeneration the resolved source may be a previously generated interceptor; its emitted
121
+ * `export { default } from './X.original'` is an ExportNamedDeclaration with a `default` specifier
122
+ * and is detected the same way, keeping the output stable.
123
+ */
124
+ function hasDefaultExport(source: string): boolean {
125
+ try {
126
+ return parseSync(source).body.some((node) => {
127
+ if (node.type === 'ExportDefaultDeclaration' || node.type === 'ExportDefaultExpression')
128
+ return true
129
+ if (node.type === 'ExportNamedDeclaration') {
130
+ return node.specifiers.some(
131
+ (s) => s.type === 'ExportSpecifier' && (s.exported ?? s.orig).value === 'default',
132
+ )
133
+ }
134
+ return false
135
+ })
136
+ } catch {
137
+ return false
138
+ }
139
+ }
140
+
112
141
  /**
113
142
  * Extract the identifier from the first line of the source file. The identifier is in the format:
114
143
  * slash-star hash:${identifer} star-slash
@@ -340,7 +369,12 @@ export const ${targetExport} = ${carry}`
340
369
 
341
370
  // Re-export everything from the original file except the intercepted exports
342
371
  export * from './${interceptor.target.split('/').pop()}.original'
343
-
372
+ ${
373
+ hasDefaultExport(interceptor.source)
374
+ ? `\n // Forward the original module's default export: \`export *\` does not include it.
375
+ export { default } from './${interceptor.target.split('/').pop()}.original'\n`
376
+ : ''
377
+ }
344
378
  ${logOnce}${pluginExports}
345
379
  `
346
380