@graphcommerce/next-config 10.1.0-canary.9 → 11.0.0-canary.45

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,117 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.0.0-canary.45
4
+
5
+ ## 10.1.0-canary.44
6
+
7
+ ## 10.1.0-canary.43
8
+
9
+ ## 10.1.0-canary.42
10
+
11
+ ## 10.1.0-canary.41
12
+
13
+ ### Patch Changes
14
+
15
+ - [#2660](https://github.com/graphcommerce-org/graphcommerce/pull/2660) [`84e23e2`](https://github.com/graphcommerce-org/graphcommerce/commit/84e23e2408011fa4a6b0803843f01d96627f148f) - Redirect the Magento frontend account URLs that end up in transactional emails to their GraphCommerce equivalents.
16
+
17
+ Magento renders links from `base_link_url`, which on a headless setup points at the GraphCommerce storefront. Every stock email template contains a `customer/account/` link ("Sign in to your account"), and gated Magento routes 302 to `customer/account/login` — none of which GraphCommerce serves, so customers landed on a 404.
18
+
19
+ `withGraphCommerce` now adds permanent redirects for `/customer/account`, `/customer/account/index`, `/customer/account/login`, `/customer/account/create` and `/sales/order/history`. They are exact matches on purpose: a redirect wins over a filesystem route, and `/customer/account/confirm` and `/customer/account/createPassword` are real pages in the examples — the two that carry Magento's confirmation `key` and reset `rp_token`. A `/customer/account/:path*` catch-all would make both unreachable.
20
+
21
+ This restores the `/customer/account` redirect that was dropped as collateral in "Remove redirects for `/product/$type/[url]` routes". ([@paales](https://github.com/paales))
22
+
23
+ ## 10.1.0-canary.40
24
+
25
+ ## 10.1.0-canary.39
26
+
27
+ ## 10.1.0-canary.38
28
+
29
+ ## 10.1.0-canary.37
30
+
31
+ ## 10.1.0-canary.36
32
+
33
+ ## 10.1.0-canary.35
34
+
35
+ ### Patch Changes
36
+
37
+ - [#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))
38
+
39
+ ## 10.1.0-canary.34
40
+
41
+ ### Patch Changes
42
+
43
+ - [#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.
44
+
45
+ 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))
46
+
47
+ ## 10.1.0-canary.33
48
+
49
+ ## 10.1.0-canary.32
50
+
51
+ ## 10.1.0-canary.31
52
+
53
+ ## 10.1.0-canary.30
54
+
55
+ ## 10.1.0-canary.29
56
+
57
+ ## 10.1.0-canary.28
58
+
59
+ ## 10.1.0-canary.27
60
+
61
+ ## 10.1.0-canary.26
62
+
63
+ ## 10.1.0-canary.25
64
+
65
+ ## 10.1.0-canary.24
66
+
67
+ ### Patch Changes
68
+
69
+ - [#2636](https://github.com/graphcommerce-org/graphcommerce/pull/2636) [`78f9803`](https://github.com/graphcommerce-org/graphcommerce/commit/78f980311d4f8db0d99fe301c62553b4e0bce098) - Fix Turbopack panic ("Cannot find module …graphcommerce.config.cjs") when loading `graphcommerce.config.ts`. cosmiconfig's sync TypeScript loader transpiles the config to a fixed temp `.cjs` path on disk and deletes it again, which races between Next.js worker processes. The `.ts` loader now transpiles via SWC and writes to a per-process unique filename next to the source so concurrent loads never collide. ([@bramvanderholst](https://github.com/bramvanderholst))
70
+
71
+ ## 10.1.0-canary.23
72
+
73
+ ## 10.1.0-canary.22
74
+
75
+ ## 10.1.0-canary.21
76
+
77
+ ## 10.1.0-canary.20
78
+
79
+ ### Patch Changes
80
+
81
+ - [#2632](https://github.com/graphcommerce-org/graphcommerce/pull/2632) [`c25106b`](https://github.com/graphcommerce-org/graphcommerce/commit/c25106bf212974bbfafafabbc650e368576f07d0) - Regenerate the `mergeEnvIntoConfig` snapshot so `yarn test` passes on canary. The test input already feeds `GC_DEMO_MODE` and `GC_STOREFRONT_<i>_HYGRAPH_LOCALES_0` into the env-schema parser, but the snapshot it was compared against still reflected the pre-`demoMode` / pre-flattened-`hygraphLocales` schema, so every CI run since those config fields were added has been failing the `test` job on every PR with a snapshot mismatch unrelated to the PR's own changes. ([@paales](https://github.com/paales))
82
+
83
+ ## 10.1.0-canary.19
84
+
85
+ ## 10.1.0-canary.18
86
+
87
+ ## 10.1.0-canary.17
88
+
89
+ ## 10.1.0-canary.16
90
+
91
+ ## 10.1.0-canary.15
92
+
93
+ ## 10.1.0-canary.14
94
+
95
+ ## 10.1.0-canary.13
96
+
97
+ ### Patch Changes
98
+
99
+ - [#2621](https://github.com/graphcommerce-org/graphcommerce/pull/2621) [`4eccccd`](https://github.com/graphcommerce-org/graphcommerce/commit/4eccccdad9418e713cb6959b20e9cde6ab26d9ae) - `graphcommerce cleanup-interceptors` now actually finds and restores `.original.tsx` / `.original.ts` files when run from a consumer project. Previously `findDotOriginalFiles` walked up looking for a `@graphcommerce/*` parent package; from a consumer project (where there is no such parent) `parentPath` ended up `null` and the glob expanded to literally `null/**/*.original.tsx`, so the command silently restored nothing. Now it falls back to `cwd` and `cwd/node_modules/@graphcommerce` where interceptors actually live for consumers.
100
+
101
+ Also fixes a display bug — the final `X files restored from .original` line printed an always-`0` counter (`restoredCount` was declared but never incremented; the now-removed `removedCount` was the one being incremented). Counter and message are now consistent. ([@paales](https://github.com/paales))
102
+
103
+ ## 10.1.0-canary.12
104
+
105
+ ## 10.1.0-canary.11
106
+
107
+ ### Patch Changes
108
+
109
+ - [#2621](https://github.com/graphcommerce-org/graphcommerce/pull/2621) [`4eccccd`](https://github.com/graphcommerce-org/graphcommerce/commit/4eccccdad9418e713cb6959b20e9cde6ab26d9ae) - `graphcommerce cleanup-interceptors` now actually finds and restores `.original.tsx` / `.original.ts` files when run from a consumer project. Previously `findDotOriginalFiles` walked up looking for a `@graphcommerce/*` parent package; from a consumer project (where there is no such parent) `parentPath` ended up `null` and the glob expanded to literally `null/**/*.original.tsx`, so the command silently restored nothing. Now it falls back to `cwd` and `cwd/node_modules/@graphcommerce` where interceptors actually live for consumers.
110
+
111
+ Also fixes a display bug — the final `X files restored from .original` line printed an always-`0` counter (`restoredCount` was declared but never incremented; the now-removed `removedCount` was the one being incremented). Counter and message are now consistent. ([@paales](https://github.com/paales))
112
+
113
+ ## 10.1.0-canary.10
114
+
3
115
  ## 10.1.0-canary.9
4
116
 
5
117
  ## 10.1.0-canary.8
@@ -2,6 +2,7 @@
2
2
 
3
3
  exports[`parses an env config object 1`] = `
4
4
  {
5
+ "GC_DEMO_MODE": true,
5
6
  "GC_STOREFRONT": [
6
7
  {
7
8
  "defaultLocale": true,
@@ -13,8 +14,10 @@ exports[`parses an env config object 1`] = `
13
14
  },
14
15
  ],
15
16
  "GC_STOREFRONT_0_DEFAULT_LOCALE": true,
17
+ "GC_STOREFRONT_0_HYGRAPH_LOCALES_0": "en",
16
18
  "GC_STOREFRONT_0_LOCALE": "en",
17
19
  "GC_STOREFRONT_0_MAGENTO_STORE_CODE": "en_us",
20
+ "GC_STOREFRONT_1_HYGRAPH_LOCALES_0": "de",
18
21
  "GC_STOREFRONT_1_LOCALE": "de",
19
22
  "GC_STOREFRONT_1_MAGENTO_STORE_CODE": "de_de",
20
23
  }
@@ -75,7 +75,8 @@ it('it generates an interceptor', async () => {
75
75
  type PluginAddMollieMethodsProps = OmitPrev<
76
76
  React.ComponentProps<typeof PluginAddMollieMethods>,
77
77
  'Prev'
78
- >
78
+ > &
79
+ PluginAddBraintreeMethodsProps
79
80
 
80
81
  const PluginAddMollieMethodsInterceptor = (props: PluginAddMollieMethodsProps) => (
81
82
  <PluginAddMollieMethods {...props} Prev={PluginAddBraintreeMethodsInterceptor} />
@@ -91,7 +92,9 @@ it('it generates an interceptor', async () => {
91
92
  * @see {PluginAddBraintreeMethods} for source of applied plugin
92
93
  * @see {PluginAddMollieMethods} for source of applied plugin
93
94
  */
94
- export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor
95
+ export const PaymentMethodContextProvider =
96
+ PluginAddMollieMethodsInterceptor as typeof PaymentMethodContextProviderOriginal &
97
+ React.FC<PluginAddMollieMethodsProps>
95
98
  "
96
99
  `)
97
100
  })
@@ -176,7 +179,8 @@ it('it can apply multiple plugins to a single export', async () => {
176
179
  type PluginAddMollieMethodsProps = OmitPrev<
177
180
  React.ComponentProps<typeof PluginAddMollieMethods>,
178
181
  'Prev'
179
- >
182
+ > &
183
+ PluginAddAdyenMethodsProps
180
184
 
181
185
  const PluginAddMollieMethodsInterceptor = (props: PluginAddMollieMethodsProps) => (
182
186
  <PluginAddMollieMethods {...props} Prev={PluginAddAdyenMethodsInterceptor} />
@@ -192,7 +196,9 @@ it('it can apply multiple plugins to a single export', async () => {
192
196
  * @see {PluginAddAdyenMethods} for source of applied plugin
193
197
  * @see {PluginAddMollieMethods} for source of applied plugin
194
198
  */
195
- export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor
199
+ export const PaymentMethodContextProvider =
200
+ PluginAddMollieMethodsInterceptor as typeof PaymentMethodContextProviderOriginal &
201
+ React.FC<PluginAddMollieMethodsProps>
196
202
  "
197
203
  `)
198
204
  })
@@ -245,7 +251,8 @@ it('it handles on duplicates gracefully', async () => {
245
251
  type PluginAddBraintreeMethodsProps = OmitPrev<
246
252
  React.ComponentProps<typeof PluginAddBraintreeMethods>,
247
253
  'Prev'
248
- >
254
+ > &
255
+ PluginAddBraintreeMethodsProps
249
256
 
250
257
  const PluginAddBraintreeMethodsInterceptor = (props: PluginAddBraintreeMethodsProps) => (
251
258
  <PluginAddBraintreeMethods {...props} Prev={PluginAddBraintreeMethodsInterceptor} />
@@ -261,7 +268,9 @@ it('it handles on duplicates gracefully', async () => {
261
268
  * @see {PluginAddBraintreeMethods} for source of applied plugin
262
269
  * @see {PluginAddBraintreeMethods} for source of applied plugin
263
270
  */
264
- export const PaymentMethodContextProvider = PluginAddBraintreeMethodsInterceptor
271
+ export const PaymentMethodContextProvider =
272
+ PluginAddBraintreeMethodsInterceptor as typeof PaymentMethodContextProviderOriginal &
273
+ React.FC<PluginAddBraintreeMethodsProps>
265
274
  "
266
275
  `)
267
276
  })
@@ -636,7 +645,9 @@ export const Plugin = ConfigurableProductPageName
636
645
  * @see {ProductPageNameMyPlugin} for source of replaced component
637
646
  * @see {PluginConfigurableProductPageName} for source of applied plugin
638
647
  */
639
- export const ProductPageName = PluginConfigurableProductPageNameInterceptor
648
+ export const ProductPageName =
649
+ PluginConfigurableProductPageNameInterceptor as typeof ProductPageNameMyPlugin &
650
+ React.FC<PluginConfigurableProductPageNameProps>
640
651
  "
641
652
  `)
642
653
  })
@@ -709,3 +720,27 @@ it('Can correctly find exports that are default exports', async () => {
709
720
  "export { iconChevronLeft as iconChevronLeft } from '../../plugins/MyProjectIcon'",
710
721
  )
711
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
+ })
@@ -1,6 +1,10 @@
1
+ import '@swc/core';
1
2
  import 'cosmiconfig';
3
+ import 'node:fs';
4
+ import 'node:module';
5
+ import 'node:path';
2
6
  import '../generated/config.js';
3
- export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-DFvwanrZ.js';
7
+ export { l as loadConfig, r as replaceConfigInString } from '../loadConfig-B6AF2Z1i.js';
4
8
  import 'zod';
5
9
  import '@apollo/client/utilities/internal';
6
10
  import 'chalk';
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@ import path from 'path';
4
4
  import { glob, sync } from 'glob';
5
5
  import { findParentPath } from './utils/findParentPath.js';
6
6
  import { spawn } from 'child_process';
7
- import { l as loadConfig, t as toEnvStr } from './loadConfig-DFvwanrZ.js';
8
- export { r as replaceConfigInString } from './loadConfig-DFvwanrZ.js';
7
+ import { l as loadConfig, t as toEnvStr } from './loadConfig-B6AF2Z1i.js';
8
+ export { r as replaceConfigInString } from './loadConfig-B6AF2Z1i.js';
9
9
  import { parseFileSync, parseSync as parseSync$1, transformFileSync } from '@swc/core';
10
10
  import fs$1, { writeFileSync, readFileSync, existsSync, rmSync, mkdirSync } from 'fs';
11
11
  import { resolve as resolve$2 } from 'import-meta-resolve';
@@ -20,6 +20,9 @@ import { generate } from '@graphql-codegen/cli';
20
20
  import { GraphCommerceConfigSchema } from './generated/config.js';
21
21
  export { GraphCommerceDebugConfigSchema, GraphCommerceStorefrontConfigSchema } from './generated/config.js';
22
22
  import 'cosmiconfig';
23
+ import 'node:fs';
24
+ import 'node:module';
25
+ import 'node:path';
23
26
  import '@apollo/client/utilities/internal';
24
27
  import 'chalk';
25
28
 
@@ -52,9 +55,12 @@ async function findDotOriginalFiles(cwd) {
52
55
  if (p) parentPath = p;
53
56
  else break;
54
57
  }
55
- return Promise.all(
56
- (await glob([`${parentPath}/**/*.original.tsx`, `${parentPath}/**/*.original.ts`], { cwd })).map((file) => fs.realpath(file))
57
- );
58
+ const roots = parentPath ? [parentPath] : [cwd, `${cwd}/node_modules/@graphcommerce`];
59
+ const patterns = roots.flatMap((root) => [
60
+ `${root}/**/*.original.tsx`,
61
+ `${root}/**/*.original.ts`
62
+ ]);
63
+ return Promise.all((await glob(patterns, { cwd })).map((file) => fs.realpath(file)));
58
64
  }
59
65
  async function writeInterceptors(interceptors, cwd = process.cwd()) {
60
66
  const processedFiles = [];
@@ -105,13 +111,12 @@ dotenv.config({ quiet: true });
105
111
  async function cleanupInterceptors(cwd = process.cwd()) {
106
112
  console.info("\u{1F9F9} Starting interceptor cleanup...");
107
113
  let restoredCount = 0;
108
- let removedCount = 0;
109
114
  const originalFiles = await findDotOriginalFiles(cwd);
110
115
  console.info(`\u{1F4C2} Found ${originalFiles.length} .original files to restore`);
111
116
  for (const originalFile of originalFiles) {
112
117
  try {
113
118
  await restoreOriginalFile(originalFile);
114
- removedCount++;
119
+ restoredCount++;
115
120
  } catch (error) {
116
121
  console.error(`\u274C Failed to restore ${originalFile}:`, error);
117
122
  }
@@ -618,7 +623,7 @@ function parseAndFindExport(resolved, findExport, resolve) {
618
623
  if (node.type === "ExportNamedDeclaration") {
619
624
  for (const specifier of node.specifiers) {
620
625
  if (specifier.type === "ExportSpecifier") {
621
- if (specifier.exported?.value === findExport) return resolved;
626
+ if ((specifier.exported?.value ?? specifier.orig.value) === findExport) return resolved;
622
627
  } else if (specifier.type === "ExportDefaultSpecifier") ; else if (specifier.type === "ExportNamespaceSpecifier") ;
623
628
  }
624
629
  }
@@ -690,6 +695,22 @@ const stableStringify = (obj) => {
690
695
  const pairs = keys.map((key) => `${JSON.stringify(key)}:${stableStringify(obj[key])}`);
691
696
  return `{${pairs.join(",")}}`;
692
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
+ }
693
714
  async function generateInterceptor(interceptor, config, oldInterceptorSource) {
694
715
  const hashInput = {
695
716
  dependency: interceptor.dependency,
@@ -823,7 +844,10 @@ export const ${targetExport} = ${carry}`;
823
844
 
824
845
  // Re-export everything from the original file except the intercepted exports
825
846
  export * from './${interceptor.target.split("/").pop()}.original'
826
-
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
+ ` : ""}
827
851
  ${logOnce}${pluginExports}
828
852
  `;
829
853
  const formatted = await prettier.format(template, {
@@ -1655,6 +1679,17 @@ function withGraphCommerce(nextConfig, cwd = process.cwd()) {
1655
1679
  ...nextConfig.images?.remotePatterns ?? []
1656
1680
  ].filter((v) => !!v)
1657
1681
  },
1682
+ redirects: async () => {
1683
+ const redirects = await nextConfig.redirects?.() ?? [];
1684
+ redirects.push(
1685
+ { source: "/customer/account", destination: "/account", permanent: true },
1686
+ { source: "/customer/account/index", destination: "/account", permanent: true },
1687
+ { source: "/customer/account/login", destination: "/account/signin", permanent: true },
1688
+ { source: "/customer/account/create", destination: "/account/signin", permanent: true },
1689
+ { source: "/sales/order/history", destination: "/account/orders", permanent: true }
1690
+ );
1691
+ return redirects;
1692
+ },
1658
1693
  rewrites: async () => {
1659
1694
  let rewrites = await nextConfig.rewrites?.() ?? [];
1660
1695
  if (Array.isArray(rewrites)) {
@@ -1,4 +1,8 @@
1
+ import { transformFileSync } from '@swc/core';
1
2
  import { cosmiconfigSync } from 'cosmiconfig';
3
+ import { writeFileSync, existsSync, rmSync } from 'node:fs';
4
+ import { createRequire } from 'node:module';
5
+ import { join, dirname } from 'node:path';
2
6
  import { GraphCommerceConfigSchema } from './generated/config.js';
3
7
  import { cloneDeep, mergeDeep } from '@apollo/client/utilities/internal';
4
8
  import chalk from 'chalk';
@@ -276,7 +280,29 @@ function replaceConfigInString(str, config) {
276
280
  }
277
281
 
278
282
  const moduleName = "graphcommerce";
279
- const loader = cosmiconfigSync(moduleName);
283
+ const requireFromHere = createRequire(import.meta.url);
284
+ let tmpCounter = 0;
285
+ function loadTsConfig(filepath) {
286
+ const { code } = transformFileSync(filepath, {
287
+ jsc: { parser: { syntax: "typescript" }, target: "es2022" },
288
+ module: { type: "commonjs" }
289
+ });
290
+ const tmpFile = join(
291
+ dirname(filepath),
292
+ `.${moduleName}.tmp.${process.pid}-${tmpCounter++}.cjs`
293
+ );
294
+ try {
295
+ writeFileSync(tmpFile, code);
296
+ delete requireFromHere.cache[tmpFile];
297
+ const mod = requireFromHere(tmpFile);
298
+ return mod.default ?? mod;
299
+ } finally {
300
+ if (existsSync(tmpFile)) rmSync(tmpFile, { force: true });
301
+ }
302
+ }
303
+ const loader = cosmiconfigSync(moduleName, {
304
+ loaders: { ".ts": loadTsConfig }
305
+ });
280
306
  function loadConfig(cwd) {
281
307
  const isMainProcess = !process.send;
282
308
  try {
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.9",
5
+ "version": "11.0.0-canary.45",
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.9",
66
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.45",
67
67
  "@lingui/loader": "*",
68
68
  "@lingui/macro": "*",
69
69
  "@lingui/react": "*",
@@ -7,7 +7,6 @@ export async function cleanupInterceptors(cwd: string = process.cwd()) {
7
7
  console.info('🧹 Starting interceptor cleanup...')
8
8
 
9
9
  let restoredCount = 0
10
- let removedCount = 0
11
10
 
12
11
  const originalFiles = await findDotOriginalFiles(cwd)
13
12
  console.info(`📂 Found ${originalFiles.length} .original files to restore`)
@@ -15,7 +14,7 @@ export async function cleanupInterceptors(cwd: string = process.cwd()) {
15
14
  for (const originalFile of originalFiles) {
16
15
  try {
17
16
  await restoreOriginalFile(originalFile)
18
- removedCount++
17
+ restoredCount++
19
18
  } catch (error) {
20
19
  console.error(`❌ Failed to restore ${originalFile}:`, error)
21
20
  }
@@ -1,5 +1,9 @@
1
1
  /* eslint-disable no-console */
2
+ import { transformFileSync } from '@swc/core'
2
3
  import { cosmiconfigSync } from 'cosmiconfig'
4
+ import { existsSync, rmSync, writeFileSync } from 'node:fs'
5
+ import { createRequire } from 'node:module'
6
+ import { dirname, join } from 'node:path'
3
7
  import type { GraphCommerceConfig } from '../generated/config'
4
8
  import { GraphCommerceConfigSchema } from '../generated/config'
5
9
  import { demoConfig } from './demoConfig'
@@ -8,7 +12,42 @@ import { formatAppliedEnv, mergeEnvIntoConfig } from './utils/mergeEnvIntoConfig
8
12
  export * from './utils/replaceConfigInString'
9
13
 
10
14
  const moduleName = 'graphcommerce'
11
- const loader = cosmiconfigSync(moduleName)
15
+ const requireFromHere = createRequire(import.meta.url)
16
+ let tmpCounter = 0
17
+
18
+ // cosmiconfig's built-in sync TypeScript loader transpiles the config to a
19
+ // fixed `.cjs` path on disk and removes it again — that races between
20
+ // Next.js worker processes (especially under Turbopack), producing
21
+ // "Cannot find module" panics. We transpile via SWC and write to a
22
+ // per-process unique filename so concurrent loads never collide. The temp
23
+ // file lives next to the source so relative `require()` calls in the
24
+ // config still resolve.
25
+ function loadTsConfig(filepath: string): Record<string, unknown> {
26
+ const { code } = transformFileSync(filepath, {
27
+ jsc: { parser: { syntax: 'typescript' }, target: 'es2022' },
28
+ module: { type: 'commonjs' },
29
+ })
30
+
31
+ const tmpFile = join(
32
+ dirname(filepath),
33
+ `.${moduleName}.tmp.${process.pid}-${tmpCounter++}.cjs`,
34
+ )
35
+
36
+ try {
37
+ writeFileSync(tmpFile, code)
38
+ delete requireFromHere.cache[tmpFile]
39
+ const mod = requireFromHere(tmpFile) as
40
+ | { default?: Record<string, unknown> }
41
+ | Record<string, unknown>
42
+ return (mod as { default?: Record<string, unknown> }).default ?? mod
43
+ } finally {
44
+ if (existsSync(tmpFile)) rmSync(tmpFile, { force: true })
45
+ }
46
+ }
47
+
48
+ const loader = cosmiconfigSync(moduleName, {
49
+ loaders: { '.ts': loadTsConfig },
50
+ })
12
51
 
13
52
  export function loadConfig(cwd: string): GraphCommerceConfig {
14
53
  const isMainProcess = !process.send
@@ -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
 
@@ -40,11 +40,18 @@ export async function findDotOriginalFiles(cwd: string) {
40
40
  else break
41
41
  }
42
42
 
43
- return Promise.all(
44
- (
45
- await glob([`${parentPath}/**/*.original.tsx`, `${parentPath}/**/*.original.ts`], { cwd })
46
- ).map((file) => fs.realpath(file)),
47
- )
43
+ // Called from inside a @graphcommerce package (upstream dev) → scan from the
44
+ // outermost @graphcommerce parent. Called from a consumer project (no
45
+ // @graphcommerce parent) → scan the project AND node_modules/@graphcommerce,
46
+ // because the interceptor system writes .original files alongside the
47
+ // installed packages there.
48
+ const roots = parentPath ? [parentPath] : [cwd, `${cwd}/node_modules/@graphcommerce`]
49
+ const patterns = roots.flatMap((root) => [
50
+ `${root}/**/*.original.tsx`,
51
+ `${root}/**/*.original.ts`,
52
+ ])
53
+
54
+ return Promise.all((await glob(patterns, { cwd })).map((file) => fs.realpath(file)))
48
55
  }
49
56
 
50
57
  export async function writeInterceptors(
@@ -102,6 +102,31 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
102
102
  ...(nextConfig.images?.remotePatterns ?? []),
103
103
  ].filter((v) => !!v),
104
104
  },
105
+ redirects: async () => {
106
+ const redirects = (await nextConfig.redirects?.()) ?? []
107
+
108
+ // Magento builds its own frontend URLs from `base_link_url`, which on a
109
+ // headless setup points at the GraphCommerce storefront. Those URLs end up
110
+ // in transactional emails ("Sign in to your account" links every stock
111
+ // email template renders) and in the 302 Location of gated Magento routes,
112
+ // but GraphCommerce doesn't serve them, so they 404.
113
+ //
114
+ // A redirect wins over a filesystem route, so every source below must be
115
+ // a path GraphCommerce does *not* serve. Two Magento paths are real pages
116
+ // in the examples — /customer/account/confirm and
117
+ // /customer/account/createPassword, the ones carrying the confirmation
118
+ // `key` and the reset `rp_token` — so these stay exact matches. A
119
+ // `/customer/account/:path*` catch-all would make both unreachable.
120
+ redirects.push(
121
+ { source: '/customer/account', destination: '/account', permanent: true },
122
+ { source: '/customer/account/index', destination: '/account', permanent: true },
123
+ { source: '/customer/account/login', destination: '/account/signin', permanent: true },
124
+ { source: '/customer/account/create', destination: '/account/signin', permanent: true },
125
+ { source: '/sales/order/history', destination: '/account/orders', permanent: true },
126
+ )
127
+
128
+ return redirects
129
+ },
105
130
  rewrites: async () => {
106
131
  let rewrites = (await nextConfig.rewrites?.()) ?? []
107
132