@graphcommerce/next-config 8.1.0-canary.7 → 8.1.0-canary.8

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.
@@ -8,8 +8,10 @@ import { resolveDependency } from '../../src/utils/resolveDependency'
8
8
 
9
9
  const projectRoot = `${process.cwd()}/examples/magento-graphcms`
10
10
 
11
+ const startLocation = '/** @see {@link file://'
12
+
11
13
  const expectImport = (value: string | undefined): jest.JestMatchers<string> =>
12
- expect(value?.slice(value.indexOf(`import`) - 1, value.indexOf(SOURCE_START) - 1).trim())
14
+ expect(value?.slice(value.indexOf(`import`) - 1, value.indexOf(startLocation) - 1).trim())
13
15
 
14
16
  const expectInterceptor = (value: string | undefined): jest.JestMatchers<string> => {
15
17
  const val = value?.slice(value.indexOf(SOURCE_END) + SOURCE_END.length).trim()
@@ -72,34 +74,29 @@ it('it generates an interceptor', async () => {
72
74
  interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
73
75
  ?.template
74
76
  expectInterceptor(result).toMatchInlineSnapshot(`
75
- "type PluginAddBraintreeMethodsInterceptorProps = DistributedOmit<
76
- React.ComponentProps<typeof PluginAddBraintreeMethodsSource>,
77
- 'Prev'
78
- >
79
- const PluginAddBraintreeMethodsInterceptor = (props: PluginAddBraintreeMethodsInterceptorProps) => {
80
- return (
81
- <PluginAddBraintreeMethodsSource
82
- {...props}
83
- Prev={PaymentMethodContextProviderOriginal as React.FC}
84
- />
85
- )
86
- }
87
-
88
- type PluginAddMollieMethodsInterceptorProps = DistributedOmit<
89
- React.ComponentProps<typeof PluginAddMollieMethodsSource>,
90
- 'Prev'
91
- >
92
- const PluginAddMollieMethodsInterceptor = (
93
- props: PluginAddBraintreeMethodsInterceptorProps & PluginAddMollieMethodsInterceptorProps,
94
- ) => {
95
- return (
96
- <PluginAddMollieMethodsSource
97
- {...props}
98
- Prev={PluginAddBraintreeMethodsInterceptor as React.FC}
99
- />
100
- )
101
- }
102
- export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
77
+ "type AddBraintreeMethodsProps = OmitPrev<React.ComponentProps<typeof AddBraintreeMethods>, 'Prev'>
78
+
79
+ const AddBraintreeMethodsInterceptor = (props: AddBraintreeMethodsProps) => (
80
+ <AddBraintreeMethods {...props} Prev={PaymentMethodContextProviderOriginal} />
81
+ )
82
+
83
+ type AddMollieMethodsProps = AddBraintreeMethodsProps &
84
+ OmitPrev<React.ComponentProps<typeof AddMollieMethods>, 'Prev'>
85
+
86
+ const AddMollieMethodsInterceptor = (props: AddMollieMethodsProps) => (
87
+ <AddMollieMethods {...props} Prev={AddBraintreeMethodsInterceptor} />
88
+ )
89
+
90
+ /**
91
+ * Here you see the 'interceptor' that is applying all the configured plugins.
92
+ *
93
+ * This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
94
+ *
95
+ * @see {@link file://./PaymentMethodContext.tsx} for original source file
96
+ * @see {AddBraintreeMethods} for source of applied plugin
97
+ * @see {AddMollieMethods} for source of applied plugin
98
+ */
99
+ export const PaymentMethodContextProvider = AddMollieMethodsInterceptor"
103
100
  `)
104
101
  })
105
102
 
@@ -125,9 +122,9 @@ it("resolves a 'root plugin' to be relative to the interceptor", async () => {
125
122
  interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
126
123
  ?.template,
127
124
  ).toMatchInlineSnapshot(`
128
- "import type { DistributedOmit } from 'type-fest'
125
+ "import type { DistributedOmit as OmitPrev } from 'type-fest'
129
126
 
130
- import { Plugin as PluginAddPaymentMethodEnhancerSource } from '../../../plugins/AddPaymentMethodEnhancer'"
127
+ import { Plugin as AddPaymentMethodEnhancer } from '../../../plugins/AddPaymentMethodEnhancer'"
131
128
  `)
132
129
  })
133
130
 
@@ -158,40 +155,38 @@ it('it can apply multiple plugins to a single export', async () => {
158
155
  interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
159
156
  ?.template
160
157
  expectImport(result).toMatchInlineSnapshot(`
161
- "import type { DistributedOmit } from 'type-fest'
158
+ "import type { DistributedOmit as OmitPrev } from 'type-fest'
162
159
 
163
- import { Plugin as PluginAddAdyenMethodsSource } from '@graphcommerce/magento-payment-adyen/plugins/AddAdyenMethods'
164
- import { Plugin as PluginAddMollieMethodsSource } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'"
160
+ import { Plugin as AddAdyenMethods } from '@graphcommerce/magento-payment-adyen/plugins/AddAdyenMethods'
161
+ import { Plugin as AddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'"
165
162
  `)
166
163
 
167
164
  expectOriginal(result).toContain('PaymentMethodContextProviderOriginal')
168
165
 
169
166
  expectInterceptor(result).toMatchInlineSnapshot(`
170
- "type PluginAddAdyenMethodsInterceptorProps = DistributedOmit<
171
- React.ComponentProps<typeof PluginAddAdyenMethodsSource>,
172
- 'Prev'
173
- >
174
- const PluginAddAdyenMethodsInterceptor = (props: PluginAddAdyenMethodsInterceptorProps) => {
175
- return (
176
- <PluginAddAdyenMethodsSource
177
- {...props}
178
- Prev={PaymentMethodContextProviderOriginal as React.FC}
179
- />
180
- )
181
- }
182
-
183
- type PluginAddMollieMethodsInterceptorProps = DistributedOmit<
184
- React.ComponentProps<typeof PluginAddMollieMethodsSource>,
185
- 'Prev'
186
- >
187
- const PluginAddMollieMethodsInterceptor = (
188
- props: PluginAddAdyenMethodsInterceptorProps & PluginAddMollieMethodsInterceptorProps,
189
- ) => {
190
- return (
191
- <PluginAddMollieMethodsSource {...props} Prev={PluginAddAdyenMethodsInterceptor as React.FC} />
192
- )
193
- }
194
- export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
167
+ "type AddAdyenMethodsProps = OmitPrev<React.ComponentProps<typeof AddAdyenMethods>, 'Prev'>
168
+
169
+ const AddAdyenMethodsInterceptor = (props: AddAdyenMethodsProps) => (
170
+ <AddAdyenMethods {...props} Prev={PaymentMethodContextProviderOriginal} />
171
+ )
172
+
173
+ type AddMollieMethodsProps = AddAdyenMethodsProps &
174
+ OmitPrev<React.ComponentProps<typeof AddMollieMethods>, 'Prev'>
175
+
176
+ const AddMollieMethodsInterceptor = (props: AddMollieMethodsProps) => (
177
+ <AddMollieMethods {...props} Prev={AddAdyenMethodsInterceptor} />
178
+ )
179
+
180
+ /**
181
+ * Here you see the 'interceptor' that is applying all the configured plugins.
182
+ *
183
+ * This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
184
+ *
185
+ * @see {@link file://./PaymentMethodContext.tsx} for original source file
186
+ * @see {AddAdyenMethods} for source of applied plugin
187
+ * @see {AddMollieMethods} for source of applied plugin
188
+ */
189
+ export const PaymentMethodContextProvider = AddMollieMethodsInterceptor"
195
190
  `)
196
191
  })
197
192
 
@@ -223,19 +218,21 @@ it('it handles on duplicates gracefully', async () => {
223
218
  interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
224
219
  ?.template
225
220
  expectInterceptor(result).toMatchInlineSnapshot(`
226
- "type PluginAddBraintreeMethodsInterceptorProps = DistributedOmit<
227
- React.ComponentProps<typeof PluginAddBraintreeMethodsSource>,
228
- 'Prev'
229
- >
230
- const PluginAddBraintreeMethodsInterceptor = (props: PluginAddBraintreeMethodsInterceptorProps) => {
231
- return (
232
- <PluginAddBraintreeMethodsSource
233
- {...props}
234
- Prev={PaymentMethodContextProviderOriginal as React.FC}
235
- />
236
- )
237
- }
238
- export const PaymentMethodContextProvider = PluginAddBraintreeMethodsInterceptor"
221
+ "type AddBraintreeMethodsProps = OmitPrev<React.ComponentProps<typeof AddBraintreeMethods>, 'Prev'>
222
+
223
+ const AddBraintreeMethodsInterceptor = (props: AddBraintreeMethodsProps) => (
224
+ <AddBraintreeMethods {...props} Prev={PaymentMethodContextProviderOriginal} />
225
+ )
226
+
227
+ /**
228
+ * Here you see the 'interceptor' that is applying all the configured plugins.
229
+ *
230
+ * This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
231
+ *
232
+ * @see {@link file://./PaymentMethodContext.tsx} for original source file
233
+ * @see {AddBraintreeMethods} for source of applied plugin
234
+ */
235
+ export const PaymentMethodContextProvider = AddBraintreeMethodsInterceptor"
239
236
  `)
240
237
  })
241
238
 
@@ -392,8 +389,8 @@ it('adds debug logging to interceptors for components', async () => {
392
389
  )
393
390
 
394
391
  expectImport(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
395
- "import { plugin as pluginmagentoInitMemoryCacheSource } from '@graphcommerce/magento-graphql/plugins/magentoInitMemoryCache'
396
- import { plugin as pluginhygraphInitMemoryCacheSource } from '@graphcommerce/magento-hygraph/plugins/hygraphInitMemoryCache'"
392
+ "import { plugin as magentoInitMemoryCache } from '@graphcommerce/magento-graphql/plugins/magentoInitMemoryCache'
393
+ import { plugin as hygraphInitMemoryCache } from '@graphcommerce/magento-hygraph/plugins/hygraphInitMemoryCache'"
397
394
  `)
398
395
 
399
396
  expectOriginal(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
@@ -426,21 +423,29 @@ it('adds debug logging to interceptors for components', async () => {
426
423
  console.warn(log, ...additional)
427
424
  }
428
425
 
429
- const pluginhygraphInitMemoryCacheInterceptor: typeof graphqlConfigOriginal = (...args) => {
426
+ const hygraphInitMemoryCacheInterceptor: typeof graphqlConfigOriginal = (...args) => {
430
427
  logOnce(
431
- \`🔌 Calling graphqlConfig with plugin(s): pluginmagentoInitMemoryCache wrapping pluginhygraphInitMemoryCache wrapping graphqlConfig()\`,
428
+ \`🔌 Calling graphqlConfig with plugin(s): magentoInitMemoryCache wrapping hygraphInitMemoryCache wrapping graphqlConfig()\`,
432
429
  )
433
- return pluginhygraphInitMemoryCacheSource(graphqlConfigOriginal, ...args)
430
+ return hygraphInitMemoryCache(graphqlConfigOriginal, ...args)
434
431
  }
435
- const pluginmagentoInitMemoryCacheInterceptor: typeof pluginhygraphInitMemoryCacheInterceptor = (
436
- ...args
437
- ) => {
432
+ const magentoInitMemoryCacheInterceptor: typeof hygraphInitMemoryCacheInterceptor = (...args) => {
438
433
  logOnce(
439
- \`🔌 Calling graphqlConfig with plugin(s): pluginhygraphInitMemoryCache wrapping pluginmagentoInitMemoryCache wrapping graphqlConfig()\`,
434
+ \`🔌 Calling graphqlConfig with plugin(s): hygraphInitMemoryCache wrapping magentoInitMemoryCache wrapping graphqlConfig()\`,
440
435
  )
441
- return pluginmagentoInitMemoryCacheSource(pluginhygraphInitMemoryCacheInterceptor, ...args)
436
+ return magentoInitMemoryCache(hygraphInitMemoryCacheInterceptor, ...args)
442
437
  }
443
- export const graphqlConfig = pluginmagentoInitMemoryCacheInterceptor"
438
+
439
+ /**
440
+ * Here you see the 'interceptor' that is applying all the configured plugins.
441
+ *
442
+ * This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
443
+ *
444
+ * @see {@link file://./config.ts} for original source file
445
+ * @see {hygraphInitMemoryCache} for source of applied plugin
446
+ * @see {magentoInitMemoryCache} for source of applied plugin
447
+ */
448
+ export const graphqlConfig = magentoInitMemoryCacheInterceptor"
444
449
  `)
445
450
  })
446
451
 
@@ -510,7 +515,7 @@ it('Should apply overrides to the correct file', async () => {
510
515
  interceptors['packages/magento-product/components/ProductStaticPaths/getProductStaticPaths']
511
516
  ?.template
512
517
  expectImport(result).toMatchInlineSnapshot(
513
- `"import { getProductStaticPaths as getProductStaticPathsreplaceGetProductStaticPathsSource } from '../../../../plugins/replaceGetProductStaticPaths'"`,
518
+ `"import { getProductStaticPaths as replaceGetProductStaticPaths } from '../../../../plugins/replaceGetProductStaticPaths'"`,
514
519
  )
515
520
 
516
521
  expectOriginal(result).toContain(`getProductStaticPathsDisabled`)
@@ -637,10 +642,10 @@ export const Plugin = ConfigurableProductPageName
637
642
  interceptors['packages/magento-product/components/ProductPageName/ProductPageName']?.template
638
643
 
639
644
  expectImport(result).toMatchInlineSnapshot(`
640
- "import type { DistributedOmit } from 'type-fest'
645
+ "import type { DistributedOmit as OmitPrev } from 'type-fest'
641
646
 
642
- import { Plugin as PluginConfigurableProductPageNameSource } from '@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName'
643
- import { ProductPageName as ProductPageNameMyPluginSource } from '../../../../plugins/MyPlugin'"
647
+ import { Plugin as ConfigurableProductPageName } from '@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName'
648
+ import { ProductPageName as MyPlugin } from '../../../../plugins/MyPlugin'"
644
649
  `)
645
650
 
646
651
  expectOriginal(result).toMatchInlineSnapshot(`
@@ -655,26 +660,25 @@ export const Plugin = ConfigurableProductPageName
655
660
  `)
656
661
 
657
662
  expectInterceptor(result).toMatchInlineSnapshot(`
658
- "type ProductPageNameMyPluginInterceptorProps = React.ComponentProps<
659
- typeof ProductPageNameMyPluginSource
660
- >
661
-
662
- type PluginConfigurableProductPageNameInterceptorProps = DistributedOmit<
663
- React.ComponentProps<typeof PluginConfigurableProductPageNameSource>,
664
- 'Prev'
665
- >
666
- const PluginConfigurableProductPageNameInterceptor = (
667
- props: ProductPageNameMyPluginInterceptorProps &
668
- PluginConfigurableProductPageNameInterceptorProps,
669
- ) => {
670
- return (
671
- <PluginConfigurableProductPageNameSource
672
- {...props}
673
- Prev={ProductPageNameMyPluginSource as React.FC}
674
- />
675
- )
676
- }
677
- export const ProductPageName = PluginConfigurableProductPageNameInterceptor"
663
+ "type MyPluginProps = React.ComponentProps<typeof MyPlugin>
664
+
665
+ type ConfigurableProductPageNameProps = MyPluginProps &
666
+ OmitPrev<React.ComponentProps<typeof ConfigurableProductPageName>, 'Prev'>
667
+
668
+ const ConfigurableProductPageNameInterceptor = (props: ConfigurableProductPageNameProps) => (
669
+ <ConfigurableProductPageName {...props} Prev={MyPlugin} />
670
+ )
671
+
672
+ /**
673
+ * Here you see the 'interceptor' that is applying all the configured plugins.
674
+ *
675
+ * This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
676
+ *
677
+ * @see {@link file://./ProductPageName.tsx} for original source file
678
+ * @see {MyPlugin} for replacement of the original source (original source not used)
679
+ * @see {ConfigurableProductPageName} for source of applied plugin
680
+ */
681
+ export const ProductPageName = ConfigurableProductPageNameInterceptor"
678
682
  `)
679
683
  })
680
684
 
@@ -61,6 +61,10 @@ it('resolves dependences', () => {
61
61
  "@graphcommerce/eslint-config-pwa" => "packagesDev/eslint-config",
62
62
  "@graphcommerce/typescript-config-pwa" => "packagesDev/typescript-config",
63
63
  "@graphcommerce/prettier-config-pwa" => "packagesDev/prettier-config",
64
+ "@graphcommerce/magento-cart-pickup" => "packages/magento-cart-pickup",
65
+ "@graphcommerce/magento-payment-braintree" => "packages/magento-payment-braintree",
66
+ "@graphcommerce/mollie-magento-payment" => "packages/mollie-magento-payment",
67
+ "@graphcommerce/magento-payment-paypal" => "packages/magento-payment-paypal",
64
68
  }
65
69
  `)
66
70
  })
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.exportConfig = void 0;
4
7
  const loadConfig_1 = require("../loadConfig");
5
8
  const exportConfigToEnv_1 = require("../utils/exportConfigToEnv");
9
+ const dotenv_1 = __importDefault(require("dotenv"));
10
+ dotenv_1.default.config();
6
11
  // eslint-disable-next-line @typescript-eslint/require-await
7
12
  async function exportConfig() {
8
13
  const conf = (0, loadConfig_1.loadConfig)(process.cwd());
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.generateConfig = void 0;
4
7
  const fs_1 = require("fs");
5
8
  // eslint-disable-next-line import/no-extraneous-dependencies
6
9
  const cli_1 = require("@graphql-codegen/cli");
7
10
  const core_1 = require("@swc/core");
11
+ const dotenv_1 = __importDefault(require("dotenv"));
8
12
  const isMonorepo_1 = require("../../utils/isMonorepo");
9
13
  const resolveDependenciesSync_1 = require("../../utils/resolveDependenciesSync");
10
14
  const resolveDependency_1 = require("../../utils/resolveDependency");
15
+ dotenv_1.default.config();
11
16
  const packages = [...(0, resolveDependenciesSync_1.resolveDependenciesSync)().values()].filter((p) => p !== '.');
12
17
  const resolve = (0, resolveDependency_1.resolveDependency)();
13
18
  const schemaLocations = packages.map((p) => `${p}/**/Config.graphqls`);
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportConfig = void 0;
4
+ const loadConfig_1 = require("../loadConfig");
5
+ // eslint-disable-next-line @typescript-eslint/require-await
6
+ async function exportConfig() {
7
+ const conf = (0, loadConfig_1.loadConfig)(process.cwd());
8
+ }
9
+ exports.exportConfig = exportConfig;
package/dist/index.js CHANGED
@@ -21,3 +21,4 @@ __exportStar(require("./withGraphCommerce"), exports);
21
21
  __exportStar(require("./generated/config"), exports);
22
22
  __exportStar(require("./config"), exports);
23
23
  __exportStar(require("./runtimeCachingOptimizations"), exports);
24
+ __exportStar(require("./interceptors/commands/codegenInterceptors"), exports);
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.codegenInterceptors = void 0;
7
+ const loadConfig_1 = require("../../config/loadConfig");
8
+ const resolveDependency_1 = require("../../utils/resolveDependency");
9
+ const findPlugins_1 = require("../findPlugins");
10
+ const generateInterceptors_1 = require("../generateInterceptors");
11
+ const writeInterceptors_1 = require("../writeInterceptors");
12
+ const dotenv_1 = __importDefault(require("dotenv"));
13
+ dotenv_1.default.config();
14
+ // eslint-disable-next-line @typescript-eslint/require-await
15
+ async function codegenInterceptors() {
16
+ const conf = (0, loadConfig_1.loadConfig)(process.cwd());
17
+ const [plugins, errors] = (0, findPlugins_1.findPlugins)(conf);
18
+ const generatedInterceptors = await (0, generateInterceptors_1.generateInterceptors)(plugins, (0, resolveDependency_1.resolveDependency)(), conf.debug, true);
19
+ // const generated = Date.now()
20
+ // console.log('Generated interceptors in', generated - found, 'ms')
21
+ await (0, writeInterceptors_1.writeInterceptors)(generatedInterceptors);
22
+ }
23
+ exports.codegenInterceptors = codegenInterceptors;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exportConfig = void 0;
4
+ const loadConfig_1 = require("../../config/loadConfig");
5
+ // eslint-disable-next-line @typescript-eslint/require-await
6
+ async function exportConfig() {
7
+ const conf = (0, loadConfig_1.loadConfig)(process.cwd());
8
+ }
9
+ exports.exportConfig = exportConfig;
@@ -17,10 +17,14 @@ function findPlugins(config, cwd = process.cwd()) {
17
17
  const debug = Boolean(config.debug?.pluginStatus);
18
18
  const errors = [];
19
19
  const plugins = [];
20
- dependencies.forEach((dependency, path) => {
21
- const files = (0, glob_1.sync)(`${dependency}/plugins/**/*.{ts,tsx}`, { dotRelative: true });
20
+ dependencies.forEach((filePath, packageName) => {
21
+ const files = (0, glob_1.sync)(`${filePath}/plugins/**/*.{ts,tsx}`);
22
22
  files.forEach((file) => {
23
- const sourceModule = file.replace(dependency, path).replace('.tsx', '').replace('.ts', '');
23
+ let sourceModule = file.replace('.tsx', '').replace('.ts', '');
24
+ if (file.startsWith(filePath))
25
+ sourceModule = `${packageName}/${sourceModule.slice(filePath.length + 1)}`;
26
+ if (packageName === '.' && !sourceModule.startsWith('.'))
27
+ sourceModule = `./${sourceModule}`;
24
28
  try {
25
29
  const ast = (0, core_1.parseFileSync)(file, { syntax: 'typescript', tsx: true });
26
30
  (0, parseStructure_1.parseStructure)(ast, config, sourceModule).forEach((result) => {
@@ -39,19 +39,19 @@ function isPluginConfig(plugin) {
39
39
  return isPluginBaseConfig(plugin);
40
40
  }
41
41
  exports.isPluginConfig = isPluginConfig;
42
- exports.SOURCE_START = '/** ❗️ Original (modified) source starts here **/';
43
- exports.SOURCE_END = '/** ❗️ Original (modified) source ends here **/';
42
+ exports.SOURCE_START = '/** Original source starts here (do not modify!): **/';
43
+ exports.SOURCE_END = '/** Original source ends here (do not modify!) **/';
44
44
  const originalSuffix = 'Original';
45
- const sourceSuffix = 'Source';
45
+ const sourceSuffix = 'Plugin';
46
46
  const interceptorSuffix = 'Interceptor';
47
47
  const disabledSuffix = 'Disabled';
48
- const name = (plugin) => `${plugin.sourceExport}${plugin.sourceModule
48
+ const name = (plugin) => `${plugin.sourceModule
49
49
  .split('/')[plugin.sourceModule.split('/').length - 1].replace(/[^a-zA-Z0-9]/g, '')}`;
50
50
  const fileName = (plugin) => `${plugin.sourceModule}#${plugin.sourceExport}`;
51
51
  const originalName = (n) => `${n}${originalSuffix}`;
52
- const sourceName = (n) => `${n}${sourceSuffix}`;
52
+ const sourceName = (n) => `${n}`;
53
53
  const interceptorName = (n) => `${n}${interceptorSuffix}`;
54
- const interceptorPropsName = (n) => `${interceptorName(n)}Props`;
54
+ const interceptorPropsName = (n) => `${n}Props`;
55
55
  function moveRelativeDown(plugins) {
56
56
  return [...plugins].sort((a, b) => {
57
57
  if (a.sourceModule.startsWith('.') && !b.sourceModule.startsWith('.'))
@@ -102,7 +102,9 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
102
102
  .map(([base, plugins]) => {
103
103
  const duplicateInterceptors = new Set();
104
104
  let carry = originalName(base);
105
- const carryProps = [];
105
+ let carryProps = [];
106
+ const pluginSee = [];
107
+ pluginSee.push(`@see {@link file://${interceptor.sourcePathRelative}} for original source file`);
106
108
  const pluginStr = plugins
107
109
  .reverse()
108
110
  .filter((p) => {
@@ -121,26 +123,31 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
121
123
  new RenameVisitor_1.RenameVisitor([originalName(p.targetExport)], (s) => s.replace(originalSuffix, disabledSuffix)).visitModule(ast);
122
124
  carryProps.push(interceptorPropsName(name(p)));
123
125
  result = `type ${interceptorPropsName(name(p))} = React.ComponentProps<typeof ${sourceName(name(p))}>`;
126
+ pluginSee.push(`@see {${sourceName(name(p))}} for replacement of the original source (original source not used)`);
124
127
  }
125
128
  if (isReactPluginConfig(p)) {
126
- carryProps.push(interceptorPropsName(name(p)));
129
+ const withBraces = config.pluginStatus || process.env.NODE_ENV === 'development';
127
130
  result = `
128
- type ${interceptorPropsName(name(p))} = DistributedOmit<React.ComponentProps<typeof ${sourceName(name(p))}>, 'Prev'>
129
- const ${interceptorName(name(p))} = (props: ${carryProps.join(' & ')}) => {
131
+ type ${interceptorPropsName(name(p))} = ${carryProps.join(' & ')} & OmitPrev<React.ComponentProps<typeof ${sourceName(name(p))}>, 'Prev'>
132
+
133
+ const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ? `{` : '('}
130
134
  ${config.pluginStatus ? `logOnce(\`🔌 Rendering ${base} with plugin(s): ${wrapChain} wrapping <${base}/>\`)` : ''}
131
135
 
132
136
  ${process.env.NODE_ENV === 'development'
133
137
  ? `if(!props['data-plugin'])
134
138
  logOnce('${fileName(p)} does not spread props to prev: <Prev {...props}/>. This will cause issues if multiple plugins are applied to this component.')`
135
139
  : ''}
136
- return <${sourceName(name(p))} {...props} Prev={${carry} as React.FC} />
137
- }`;
140
+ ${withBraces ? `return` : ''} <${sourceName(name(p))} {...props} Prev={${carry}} />
141
+ ${withBraces ? `}` : ')'}`;
142
+ carryProps = [interceptorPropsName(name(p))];
143
+ pluginSee.push(`@see {${sourceName(name(p))}} for source of applied plugin`);
138
144
  }
139
145
  if (isMethodPluginConfig(p)) {
140
146
  result = `const ${interceptorName(name(p))}: typeof ${carry} = (...args) => {
141
147
  ${config.pluginStatus ? `logOnce(\`🔌 Calling ${base} with plugin(s): ${wrapChain} wrapping ${base}()\`)` : ''}
142
148
  return ${sourceName(name(p))}(${carry}, ...args)
143
149
  }`;
150
+ pluginSee.push(`@see {${sourceName(name(p))}} for source of applied plugin`);
144
151
  }
145
152
  carry = p.type === 'replace' ? sourceName(name(p)) : interceptorName(name(p));
146
153
  return result;
@@ -151,14 +158,24 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
151
158
  if (isComponent && plugins.some((p) => isMethodPluginConfig(p))) {
152
159
  throw new Error(`Cannot mix React and Method plugins for ${base} in ${dependency}.`);
153
160
  }
161
+ const seeString = `
162
+ /**
163
+ * Here you see the 'interceptor' that is applying all the configured plugins.
164
+ *
165
+ * This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
166
+ *
167
+ ${pluginSee.map((s) => `* ${s}`).join('\n')}
168
+ */`;
154
169
  if (process.env.NODE_ENV === 'development' && isComponent) {
155
170
  return `${pluginStr}
171
+ ${seeString}
156
172
  export const ${base}: typeof ${carry} = (props) => {
157
173
  return <${carry} {...props} data-plugin />
158
174
  }`;
159
175
  }
160
176
  return `
161
177
  ${pluginStr}
178
+ ${seeString}
162
179
  export const ${base} = ${carry}
163
180
  `;
164
181
  })
@@ -177,11 +194,12 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
177
194
  /* eslint-disable */
178
195
  /* This file is automatically generated for ${dependency} */
179
196
  ${Object.values(targetExports).some((t) => t.some((p) => p.type === 'component'))
180
- ? `import type { DistributedOmit } from 'type-fest'`
197
+ ? `import type { DistributedOmit as OmitPrev } from 'type-fest'`
181
198
  : ''}
182
199
 
183
200
  ${pluginImports}
184
201
 
202
+ /** @see {@link file://${interceptor.sourcePathRelative}} for source of original */
185
203
  ${exports.SOURCE_START}
186
204
  ${(0, swc_1.printSync)(ast).code}
187
205
  ${exports.SOURCE_END}
@@ -8,7 +8,7 @@ const node_path_1 = __importDefault(require("node:path"));
8
8
  const promises_1 = __importDefault(require("node:fs/promises"));
9
9
  const findOriginalSource_1 = require("./findOriginalSource");
10
10
  const generateInterceptor_1 = require("./generateInterceptor");
11
- async function generateInterceptors(plugins, resolve, config) {
11
+ async function generateInterceptors(plugins, resolve, config, force) {
12
12
  const byTargetModuleAndExport = (0, generateInterceptor_1.moveRelativeDown)(plugins).reduce((acc, plug) => {
13
13
  let { sourceModule: pluginPath } = plug;
14
14
  if (!(0, generateInterceptor_1.isPluginConfig)(plug) || !plug.enabled)
@@ -40,10 +40,11 @@ async function generateInterceptors(plugins, resolve, config) {
40
40
  }, {});
41
41
  return Object.fromEntries(await Promise.all(Object.entries(byTargetModuleAndExport).map(async ([target, interceptor]) => {
42
42
  const file = `${interceptor.fromRoot}.interceptor.tsx`;
43
- const originalSource = (await promises_1.default
44
- .access(file, promises_1.default.constants.F_OK)
45
- .then(() => true)
46
- .catch(() => false))
43
+ const originalSource = !force &&
44
+ (await promises_1.default
45
+ .access(file, promises_1.default.constants.F_OK)
46
+ .then(() => true)
47
+ .catch(() => false))
47
48
  ? (await promises_1.default.readFile(file)).toString()
48
49
  : undefined;
49
50
  return [
@@ -8,7 +8,7 @@ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const PackagesSort_1 = require("./PackagesSort");
10
10
  const resolveCache = new Map();
11
- function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root) {
11
+ function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root, additionalDependencies = []) {
12
12
  const isRoot = dependencyPath === root;
13
13
  const fileName = require.resolve(node_path_1.default.join(dependencyPath, 'package.json'));
14
14
  const packageJsonFile = node_fs_1.default.readFileSync(fileName, 'utf-8').toString();
@@ -22,8 +22,9 @@ function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root)
22
22
  return dependencyStructure;
23
23
  const dependencies = [
24
24
  ...new Set([
25
- ...Object.keys(packageJson.dependencies ?? {}),
26
- ...Object.keys(packageJson.devDependencies ?? {}),
25
+ ...Object.keys(packageJson.dependencies ?? []),
26
+ ...Object.keys(packageJson.devDependencies ?? []),
27
+ ...additionalDependencies,
27
28
  // ...Object.keys(packageJson.peerDependencies ?? {}),
28
29
  ].filter((name) => name.includes('graphcommerce'))),
29
30
  ];
@@ -63,7 +64,7 @@ function resolveDependenciesSync(root = process.cwd()) {
63
64
  const cached = resolveCache.get(root);
64
65
  if (cached)
65
66
  return cached;
66
- const dependencyStructure = resolveRecursivePackageJson(root, {}, root);
67
+ const dependencyStructure = resolveRecursivePackageJson(root, {}, root, process.env.PRIVATE_ADDITIONAL_DEPENDENCIES?.split(',') ?? []);
67
68
  const sorted = sortDependencies(dependencyStructure);
68
69
  resolveCache.set(root, sorted);
69
70
  return sorted;
@@ -14,6 +14,7 @@ const resolveDependency = (cwd = process.cwd()) => {
14
14
  root: '.',
15
15
  source: '',
16
16
  sourcePath: '',
17
+ sourcePathRelative: '',
17
18
  dependency,
18
19
  fromRoot: dependency,
19
20
  fromModule: dependency,
@@ -45,6 +46,9 @@ const resolveDependency = (cwd = process.cwd()) => {
45
46
  let fromModule = !relative
46
47
  ? '.'
47
48
  : `./${relative.split('/')[relative.split('/').length - 1]}`;
49
+ const sourcePathRelative = !sourcePath
50
+ ? '.'
51
+ : `./${sourcePath.split('/')[sourcePath.split('/').length - 1]}`;
48
52
  if (dependency.startsWith('./'))
49
53
  fromModule = `.${relative}`;
50
54
  dependencyPaths = {
@@ -55,6 +59,7 @@ const resolveDependency = (cwd = process.cwd()) => {
55
59
  fromModule,
56
60
  source,
57
61
  sourcePath,
62
+ sourcePathRelative,
58
63
  };
59
64
  }
60
65
  });
@@ -101,8 +101,8 @@ function withGraphCommerce(nextConfig, cwd) {
101
101
  // Make import.meta.graphCommerce available for usage.
102
102
  config.plugins.push(new webpack_1.DefinePlugin(importMetaPaths));
103
103
  // To properly properly treeshake @apollo/client we need to define the __DEV__ property
104
+ config.plugins.push(new webpack_1.DefinePlugin({ 'globalThis.__DEV__': options.dev }));
104
105
  if (!options.isServer) {
105
- config.plugins.push(new webpack_1.DefinePlugin({ __DEV__: options.dev }));
106
106
  if (graphcommerceConfig.debug?.webpackCircularDependencyPlugin) {
107
107
  config.plugins.push(new circular_dependency_plugin_1.default({
108
108
  exclude: /readable-stream|duplexer2|node_modules\/next/,
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": "8.1.0-canary.7",
5
+ "version": "8.1.0-canary.8",
6
6
  "type": "commonjs",
7
7
  "main": "dist/index.js",
8
8
  "types": "src/index.ts",