@graphcommerce/next-config 8.1.0-canary.5 → 8.1.0-canary.52
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 +163 -0
- package/Config.graphqls +5 -5
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +48 -2
- package/__tests__/config/utils/configToImportMeta.ts +0 -4
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +15 -2
- package/__tests__/config/utils/rewriteLegancyEnv.ts +1 -1
- package/__tests__/interceptors/findPlugins.ts +144 -194
- package/__tests__/interceptors/generateInterceptors.ts +174 -91
- package/__tests__/interceptors/parseStructure.ts +50 -0
- package/__tests__/utils/resolveDependenciesSync.ts +4 -0
- package/dist/config/commands/exportConfig.js +5 -0
- package/dist/config/commands/generateConfig.js +5 -0
- package/dist/config/commands/generateIntercetors.js +9 -0
- package/dist/config/demoConfig.js +5 -0
- package/dist/config/utils/mergeEnvIntoConfig.js +8 -1
- package/dist/generated/config.js +17 -9
- package/dist/index.js +1 -0
- package/dist/interceptors/commands/codegenInterceptors.js +23 -0
- package/dist/interceptors/commands/generateIntercetors.js +9 -0
- package/dist/interceptors/extractExports.js +21 -18
- package/dist/interceptors/findOriginalSource.js +17 -1
- package/dist/interceptors/findPlugins.js +7 -3
- package/dist/interceptors/generateInterceptor.js +32 -15
- package/dist/interceptors/generateInterceptors.js +6 -5
- package/dist/interceptors/parseStructure.js +9 -1
- package/dist/interceptors/writeInterceptors.js +7 -7
- package/dist/utils/resolveDependenciesSync.js +5 -4
- package/dist/utils/resolveDependency.js +5 -0
- package/dist/withGraphCommerce.js +14 -5
- package/package.json +1 -1
- package/src/config/commands/exportConfig.ts +3 -0
- package/src/config/commands/generateConfig.ts +3 -0
- package/src/config/demoConfig.ts +5 -0
- package/src/config/utils/mergeEnvIntoConfig.ts +9 -1
- package/src/generated/config.ts +57 -19
- package/src/index.ts +1 -0
- package/src/interceptors/commands/codegenInterceptors.ts +27 -0
- package/src/interceptors/extractExports.ts +21 -21
- package/src/interceptors/findOriginalSource.ts +16 -1
- package/src/interceptors/findPlugins.ts +7 -3
- package/src/interceptors/generateInterceptor.ts +39 -15
- package/src/interceptors/generateInterceptors.ts +9 -6
- package/src/interceptors/parseStructure.ts +14 -1
- package/src/interceptors/writeInterceptors.ts +7 -7
- package/src/utils/resolveDependenciesSync.ts +11 -3
- package/src/utils/resolveDependency.ts +7 -0
- package/src/withGraphCommerce.ts +15 -6
|
@@ -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(
|
|
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,33 +74,31 @@ 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
|
|
76
|
-
React.ComponentProps<typeof
|
|
77
|
+
"type PluginAddBraintreeMethodsProps = OmitPrev<
|
|
78
|
+
React.ComponentProps<typeof PluginAddBraintreeMethods>,
|
|
77
79
|
'Prev'
|
|
78
80
|
>
|
|
79
|
-
const PluginAddBraintreeMethodsInterceptor = (props: PluginAddBraintreeMethodsInterceptorProps) => {
|
|
80
|
-
return (
|
|
81
|
-
<PluginAddBraintreeMethodsSource
|
|
82
|
-
{...props}
|
|
83
|
-
Prev={PaymentMethodContextProviderOriginal as React.FC}
|
|
84
|
-
/>
|
|
85
|
-
)
|
|
86
|
-
}
|
|
87
81
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
const PluginAddBraintreeMethodsInterceptor = (props: PluginAddBraintreeMethodsProps) => (
|
|
83
|
+
<PluginAddBraintreeMethods {...props} Prev={PaymentMethodContextProviderOriginal} />
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
type PluginAddMollieMethodsProps = PluginAddBraintreeMethodsProps &
|
|
87
|
+
OmitPrev<React.ComponentProps<typeof PluginAddMollieMethods>, 'Prev'>
|
|
88
|
+
|
|
89
|
+
const PluginAddMollieMethodsInterceptor = (props: PluginAddMollieMethodsProps) => (
|
|
90
|
+
<PluginAddMollieMethods {...props} Prev={PluginAddBraintreeMethodsInterceptor} />
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
95
|
+
*
|
|
96
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
97
|
+
*
|
|
98
|
+
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
99
|
+
* @see {PluginAddBraintreeMethods} for source of applied plugin
|
|
100
|
+
* @see {PluginAddMollieMethods} for source of applied plugin
|
|
101
|
+
*/
|
|
102
102
|
export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
|
|
103
103
|
`)
|
|
104
104
|
})
|
|
@@ -125,9 +125,9 @@ it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
|
125
125
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
126
126
|
?.template,
|
|
127
127
|
).toMatchInlineSnapshot(`
|
|
128
|
-
"import type { DistributedOmit } from 'type-fest'
|
|
128
|
+
"import type { DistributedOmit as OmitPrev } from 'type-fest'
|
|
129
129
|
|
|
130
|
-
import { Plugin as
|
|
130
|
+
import { Plugin as PluginAddPaymentMethodEnhancer } from '../../../plugins/AddPaymentMethodEnhancer'"
|
|
131
131
|
`)
|
|
132
132
|
})
|
|
133
133
|
|
|
@@ -158,39 +158,40 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
158
158
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
159
159
|
?.template
|
|
160
160
|
expectImport(result).toMatchInlineSnapshot(`
|
|
161
|
-
"import type { DistributedOmit } from 'type-fest'
|
|
161
|
+
"import type { DistributedOmit as OmitPrev } from 'type-fest'
|
|
162
162
|
|
|
163
|
-
import { Plugin as
|
|
164
|
-
import { Plugin as
|
|
163
|
+
import { Plugin as PluginAddAdyenMethods } from '@graphcommerce/magento-payment-adyen/plugins/AddAdyenMethods'
|
|
164
|
+
import { Plugin as PluginAddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'"
|
|
165
165
|
`)
|
|
166
166
|
|
|
167
167
|
expectOriginal(result).toContain('PaymentMethodContextProviderOriginal')
|
|
168
168
|
|
|
169
169
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
170
|
-
"type
|
|
171
|
-
React.ComponentProps<typeof
|
|
170
|
+
"type PluginAddAdyenMethodsProps = OmitPrev<
|
|
171
|
+
React.ComponentProps<typeof PluginAddAdyenMethods>,
|
|
172
172
|
'Prev'
|
|
173
173
|
>
|
|
174
|
-
const PluginAddAdyenMethodsInterceptor = (props: PluginAddAdyenMethodsInterceptorProps) => {
|
|
175
|
-
return (
|
|
176
|
-
<PluginAddAdyenMethodsSource
|
|
177
|
-
{...props}
|
|
178
|
-
Prev={PaymentMethodContextProviderOriginal as React.FC}
|
|
179
|
-
/>
|
|
180
|
-
)
|
|
181
|
-
}
|
|
182
174
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
175
|
+
const PluginAddAdyenMethodsInterceptor = (props: PluginAddAdyenMethodsProps) => (
|
|
176
|
+
<PluginAddAdyenMethods {...props} Prev={PaymentMethodContextProviderOriginal} />
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
type PluginAddMollieMethodsProps = PluginAddAdyenMethodsProps &
|
|
180
|
+
OmitPrev<React.ComponentProps<typeof PluginAddMollieMethods>, 'Prev'>
|
|
181
|
+
|
|
182
|
+
const PluginAddMollieMethodsInterceptor = (props: PluginAddMollieMethodsProps) => (
|
|
183
|
+
<PluginAddMollieMethods {...props} Prev={PluginAddAdyenMethodsInterceptor} />
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
188
|
+
*
|
|
189
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
190
|
+
*
|
|
191
|
+
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
192
|
+
* @see {PluginAddAdyenMethods} for source of applied plugin
|
|
193
|
+
* @see {PluginAddMollieMethods} for source of applied plugin
|
|
194
|
+
*/
|
|
194
195
|
export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
|
|
195
196
|
`)
|
|
196
197
|
})
|
|
@@ -223,18 +224,23 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
223
224
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
224
225
|
?.template
|
|
225
226
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
226
|
-
"type
|
|
227
|
-
React.ComponentProps<typeof
|
|
227
|
+
"type PluginAddBraintreeMethodsProps = OmitPrev<
|
|
228
|
+
React.ComponentProps<typeof PluginAddBraintreeMethods>,
|
|
228
229
|
'Prev'
|
|
229
230
|
>
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
231
|
+
|
|
232
|
+
const PluginAddBraintreeMethodsInterceptor = (props: PluginAddBraintreeMethodsProps) => (
|
|
233
|
+
<PluginAddBraintreeMethods {...props} Prev={PaymentMethodContextProviderOriginal} />
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
238
|
+
*
|
|
239
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
240
|
+
*
|
|
241
|
+
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
242
|
+
* @see {PluginAddBraintreeMethods} for source of applied plugin
|
|
243
|
+
*/
|
|
238
244
|
export const PaymentMethodContextProvider = PluginAddBraintreeMethodsInterceptor"
|
|
239
245
|
`)
|
|
240
246
|
})
|
|
@@ -392,28 +398,38 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
392
398
|
)
|
|
393
399
|
|
|
394
400
|
expectImport(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
395
|
-
"import { plugin as
|
|
396
|
-
import { plugin as
|
|
401
|
+
"import { plugin as pluginmagentoInitMemoryCache } from '@graphcommerce/magento-graphql/plugins/magentoInitMemoryCache'
|
|
402
|
+
import { plugin as pluginhygraphInitMemoryCache } from '@graphcommerce/magento-hygraph/plugins/hygraphInitMemoryCache'"
|
|
397
403
|
`)
|
|
398
404
|
|
|
399
405
|
expectOriginal(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
400
406
|
"import { ApolloLink, TypePolicies } from '@apollo/client'
|
|
401
407
|
import type { GraphCommerceStorefrontConfig } from '@graphcommerce/next-config'
|
|
408
|
+
import type { SetRequired } from 'type-fest'
|
|
402
409
|
import { MigrateCache } from './components/GraphQLProvider/migrateCache'
|
|
410
|
+
export interface PreviewData {}
|
|
411
|
+
export type PreviewConfig = {
|
|
412
|
+
preview?: boolean
|
|
413
|
+
previewData?: PreviewData & Record<string, unknown>
|
|
414
|
+
}
|
|
403
415
|
export type ApolloClientConfigInput = {
|
|
404
416
|
storefront: GraphCommerceStorefrontConfig
|
|
405
417
|
links?: ApolloLink[]
|
|
406
418
|
policies?: TypePolicies[]
|
|
407
419
|
migrations?: MigrateCache[]
|
|
408
|
-
}
|
|
409
|
-
export type ApolloClientConfig =
|
|
420
|
+
} & PreviewConfig
|
|
421
|
+
export type ApolloClientConfig = SetRequired<
|
|
422
|
+
ApolloClientConfigInput,
|
|
423
|
+
'links' | 'policies' | 'migrations'
|
|
424
|
+
>
|
|
410
425
|
export function graphqlConfigOriginal(config: ApolloClientConfigInput): ApolloClientConfig {
|
|
411
|
-
const { storefront, links = [], policies = [], migrations = [] } = config
|
|
426
|
+
const { storefront, links = [], policies = [], migrations = [], ...rest } = config
|
|
412
427
|
return {
|
|
413
428
|
storefront,
|
|
414
429
|
links,
|
|
415
430
|
policies,
|
|
416
431
|
migrations,
|
|
432
|
+
...rest,
|
|
417
433
|
}
|
|
418
434
|
}"
|
|
419
435
|
`)
|
|
@@ -430,7 +446,7 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
430
446
|
logOnce(
|
|
431
447
|
\`🔌 Calling graphqlConfig with plugin(s): pluginmagentoInitMemoryCache wrapping pluginhygraphInitMemoryCache wrapping graphqlConfig()\`,
|
|
432
448
|
)
|
|
433
|
-
return
|
|
449
|
+
return pluginhygraphInitMemoryCache(graphqlConfigOriginal, ...args)
|
|
434
450
|
}
|
|
435
451
|
const pluginmagentoInitMemoryCacheInterceptor: typeof pluginhygraphInitMemoryCacheInterceptor = (
|
|
436
452
|
...args
|
|
@@ -438,8 +454,18 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
438
454
|
logOnce(
|
|
439
455
|
\`🔌 Calling graphqlConfig with plugin(s): pluginhygraphInitMemoryCache wrapping pluginmagentoInitMemoryCache wrapping graphqlConfig()\`,
|
|
440
456
|
)
|
|
441
|
-
return
|
|
457
|
+
return pluginmagentoInitMemoryCache(pluginhygraphInitMemoryCacheInterceptor, ...args)
|
|
442
458
|
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
462
|
+
*
|
|
463
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
464
|
+
*
|
|
465
|
+
* @see {@link file://./config.ts} for original source file
|
|
466
|
+
* @see {pluginhygraphInitMemoryCache} for source of applied plugin
|
|
467
|
+
* @see {pluginmagentoInitMemoryCache} for source of applied plugin
|
|
468
|
+
*/
|
|
443
469
|
export const graphqlConfig = pluginmagentoInitMemoryCacheInterceptor"
|
|
444
470
|
`)
|
|
445
471
|
})
|
|
@@ -510,14 +536,12 @@ it('Should apply overrides to the correct file', async () => {
|
|
|
510
536
|
interceptors['packages/magento-product/components/ProductStaticPaths/getProductStaticPaths']
|
|
511
537
|
?.template
|
|
512
538
|
expectImport(result).toMatchInlineSnapshot(
|
|
513
|
-
`"import { getProductStaticPaths as
|
|
539
|
+
`"import { getProductStaticPaths as getProductStaticPathsreplaceGetProductStaticPaths } from '../../../../plugins/replaceGetProductStaticPaths'"`,
|
|
514
540
|
)
|
|
515
541
|
|
|
516
542
|
expectOriginal(result).toContain(`getProductStaticPathsDisabled`)
|
|
517
543
|
})
|
|
518
544
|
|
|
519
|
-
it('Should report an error when multiple files are overriding the same export', () => {})
|
|
520
|
-
|
|
521
545
|
it('correctly reports an error for an incorrect export', async () => {
|
|
522
546
|
const fakeconfig = {
|
|
523
547
|
googleRecaptchaKey: '123',
|
|
@@ -637,10 +661,10 @@ export const Plugin = ConfigurableProductPageName
|
|
|
637
661
|
interceptors['packages/magento-product/components/ProductPageName/ProductPageName']?.template
|
|
638
662
|
|
|
639
663
|
expectImport(result).toMatchInlineSnapshot(`
|
|
640
|
-
"import type { DistributedOmit } from 'type-fest'
|
|
664
|
+
"import type { DistributedOmit as OmitPrev } from 'type-fest'
|
|
641
665
|
|
|
642
|
-
import { Plugin as
|
|
643
|
-
import { ProductPageName as
|
|
666
|
+
import { Plugin as PluginConfigurableProductPageName } from '@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName'
|
|
667
|
+
import { ProductPageName as ProductPageNameMyPlugin } from '../../../../plugins/MyPlugin'"
|
|
644
668
|
`)
|
|
645
669
|
|
|
646
670
|
expectOriginal(result).toMatchInlineSnapshot(`
|
|
@@ -655,25 +679,22 @@ export const Plugin = ConfigurableProductPageName
|
|
|
655
679
|
`)
|
|
656
680
|
|
|
657
681
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
658
|
-
"type
|
|
659
|
-
typeof
|
|
660
|
-
>
|
|
682
|
+
"type PluginConfigurableProductPageNameProps = React.ComponentProps<typeof ProductPageNameMyPlugin> &
|
|
683
|
+
OmitPrev<React.ComponentProps<typeof PluginConfigurableProductPageName>, 'Prev'>
|
|
661
684
|
|
|
662
|
-
type PluginConfigurableProductPageNameInterceptorProps = DistributedOmit<
|
|
663
|
-
React.ComponentProps<typeof PluginConfigurableProductPageNameSource>,
|
|
664
|
-
'Prev'
|
|
665
|
-
>
|
|
666
685
|
const PluginConfigurableProductPageNameInterceptor = (
|
|
667
|
-
props:
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
686
|
+
props: PluginConfigurableProductPageNameProps,
|
|
687
|
+
) => <PluginConfigurableProductPageName {...props} Prev={ProductPageNameMyPlugin} />
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
691
|
+
*
|
|
692
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
693
|
+
*
|
|
694
|
+
* @see {@link file://./ProductPageName.tsx} for original source file
|
|
695
|
+
* @see {ProductPageNameMyPlugin} for replacement of the original source (original source not used)
|
|
696
|
+
* @see {PluginConfigurableProductPageName} for source of applied plugin
|
|
697
|
+
*/
|
|
677
698
|
export const ProductPageName = PluginConfigurableProductPageNameInterceptor"
|
|
678
699
|
`)
|
|
679
700
|
})
|
|
@@ -698,3 +719,65 @@ it('generates to a .ts file when the target file is a .ts as well', async () =>
|
|
|
698
719
|
const interceptor = interceptors['packages/graphql/config']
|
|
699
720
|
expect(interceptor.sourcePath).toBe(`packages/graphql/config.ts`)
|
|
700
721
|
})
|
|
722
|
+
|
|
723
|
+
it.todo('Should report an error when multiple files are overriding the same export')
|
|
724
|
+
|
|
725
|
+
it('Can correctly find exports that are default exports', async () => {
|
|
726
|
+
const pluginSource = `
|
|
727
|
+
import { PluginConfig } from '@graphcommerce/next-config'
|
|
728
|
+
|
|
729
|
+
import accessibilityHuman from '@graphcommerce/next-ui/icons/accessibility-human.svg'
|
|
730
|
+
import alarm from '@graphcommerce/next-ui/icons/alarm.svg'
|
|
731
|
+
|
|
732
|
+
export const config: PluginConfig = {
|
|
733
|
+
type: 'replace',
|
|
734
|
+
module: '@graphcommerce/next-ui',
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
export const iconChevronLeft = accessibilityHuman
|
|
738
|
+
export const iconChevronRight = alarm
|
|
739
|
+
`
|
|
740
|
+
|
|
741
|
+
const config = {
|
|
742
|
+
demoMode: true,
|
|
743
|
+
configurableVariantForSimple: true,
|
|
744
|
+
configurableVariantValues: { content: true, gallery: true, url: true },
|
|
745
|
+
} as GraphCommerceConfig
|
|
746
|
+
|
|
747
|
+
const plugins = parseStructure(parseSync(pluginSource), config, './plugins/MyProjectIcon')
|
|
748
|
+
|
|
749
|
+
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
750
|
+
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(`"packages/next-ui/icons"`)
|
|
751
|
+
|
|
752
|
+
const result = interceptors['packages/next-ui/icons']?.template
|
|
753
|
+
|
|
754
|
+
expectImport(result).toMatchInlineSnapshot(`
|
|
755
|
+
"import { iconChevronLeft as iconChevronLeftMyProjectIcon } from '../../plugins/MyProjectIcon'
|
|
756
|
+
import { iconChevronRight as iconChevronRightMyProjectIcon } from '../../plugins/MyProjectIcon'"
|
|
757
|
+
`)
|
|
758
|
+
|
|
759
|
+
expectOriginal(result).toContain('iconChevronLeftDisabled')
|
|
760
|
+
expectOriginal(result).toContain('iconChevronRightDisabled')
|
|
761
|
+
|
|
762
|
+
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
763
|
+
"/**
|
|
764
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
765
|
+
*
|
|
766
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
767
|
+
*
|
|
768
|
+
* @see {@link file://./icons.ts} for original source file
|
|
769
|
+
* @see {iconChevronLeftMyProjectIcon} for replacement of the original source (original source not used)
|
|
770
|
+
*/
|
|
771
|
+
export const iconChevronLeft = iconChevronLeftMyProjectIcon
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
775
|
+
*
|
|
776
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the original source changes.
|
|
777
|
+
*
|
|
778
|
+
* @see {@link file://./icons.ts} for original source file
|
|
779
|
+
* @see {iconChevronRightMyProjectIcon} for replacement of the original source (original source not used)
|
|
780
|
+
*/
|
|
781
|
+
export const iconChevronRight = iconChevronRightMyProjectIcon"
|
|
782
|
+
`)
|
|
783
|
+
})
|
|
@@ -156,3 +156,53 @@ export const AddProductsToCartForm = EnableCrossselsPlugin
|
|
|
156
156
|
}
|
|
157
157
|
`)
|
|
158
158
|
})
|
|
159
|
+
|
|
160
|
+
it('parses', () => {
|
|
161
|
+
const src = `
|
|
162
|
+
import {
|
|
163
|
+
PaymentMethodContextProviderProps,
|
|
164
|
+
PaymentModule,
|
|
165
|
+
} from '@graphcommerce/magento-cart-payment-method'
|
|
166
|
+
import type { PluginProps } from '@graphcommerce/next-config'
|
|
167
|
+
import { AdyenPaymentActionCard } from '../components/AdyenPaymentActionCard/AdyenPaymentActionCard'
|
|
168
|
+
import { AdyenPaymentHandler } from '../components/AdyenPaymentHandler/AdyenPaymentHandler'
|
|
169
|
+
import { HppOptions } from '../components/AdyenPaymentOptionsAndPlaceOrder/AdyenPaymentOptionsAndPlaceOrder'
|
|
170
|
+
import { adyenHppExpandMethods } from '../hooks/adyenHppExpandMethods'
|
|
171
|
+
|
|
172
|
+
export const adyen_hpp: PaymentModule = {
|
|
173
|
+
PaymentOptions: HppOptions,
|
|
174
|
+
PaymentPlaceOrder: () => null,
|
|
175
|
+
PaymentHandler: AdyenPaymentHandler,
|
|
176
|
+
PaymentActionCard: AdyenPaymentActionCard,
|
|
177
|
+
expandMethods: adyenHppExpandMethods,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const component = 'PaymentMethodContextProvider'
|
|
181
|
+
export const exported = '@graphcommerce/magento-cart-payment-method'
|
|
182
|
+
|
|
183
|
+
function AddAdyenMethods(props: PluginProps<PaymentMethodContextProviderProps>) {
|
|
184
|
+
const { modules, Prev, ...rest } = props
|
|
185
|
+
return <Prev {...rest} modules={{ ...modules, adyen_hpp }} />
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export const Plugin = AddAdyenMethods
|
|
189
|
+
`
|
|
190
|
+
|
|
191
|
+
const plugins = parseStructure(
|
|
192
|
+
parseSync(src),
|
|
193
|
+
fakeconfig,
|
|
194
|
+
'@graphcommerce/magento-payment-adyen/plugins/AddAdyenMethods.tsx',
|
|
195
|
+
)
|
|
196
|
+
expect(plugins).toHaveLength(1)
|
|
197
|
+
expect(plugins[0]).toMatchInlineSnapshot(`
|
|
198
|
+
{
|
|
199
|
+
"enabled": true,
|
|
200
|
+
"sourceExport": "Plugin",
|
|
201
|
+
"sourceModule": "@graphcommerce/magento-payment-adyen/plugins/AddAdyenMethods.tsx",
|
|
202
|
+
"targetExport": "PaymentMethodContextProvider",
|
|
203
|
+
"targetModule": "@graphcommerce/magento-cart-payment-method",
|
|
204
|
+
"type": "component",
|
|
205
|
+
}
|
|
206
|
+
`)
|
|
207
|
+
expect(plugins[1]).toMatchInlineSnapshot(`undefined`)
|
|
208
|
+
})
|
|
@@ -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;
|
|
@@ -5,6 +5,7 @@ exports.demoConfig = {
|
|
|
5
5
|
canonicalBaseUrl: 'https://graphcommerce.vercel.app',
|
|
6
6
|
hygraphEndpoint: 'https://eu-central-1.cdn.hygraph.com/content/ckhx7xadya6xs01yxdujt8i80/master',
|
|
7
7
|
magentoEndpoint: 'https://backend.reachdigital.dev/graphql',
|
|
8
|
+
magentoVersion: 246,
|
|
8
9
|
storefront: [
|
|
9
10
|
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
|
|
10
11
|
{
|
|
@@ -35,6 +36,7 @@ exports.demoConfig = {
|
|
|
35
36
|
],
|
|
36
37
|
productFiltersPro: true,
|
|
37
38
|
productFiltersLayout: 'DEFAULT',
|
|
39
|
+
productListPaginationVariant: 'COMPACT',
|
|
38
40
|
compareVariant: 'ICON',
|
|
39
41
|
robotsAllow: false,
|
|
40
42
|
demoMode: true,
|
|
@@ -44,4 +46,7 @@ exports.demoConfig = {
|
|
|
44
46
|
configurableVariantForSimple: true,
|
|
45
47
|
configurableVariantValues: { url: true, content: true, gallery: true },
|
|
46
48
|
recentlyViewedProducts: { enabled: true, maxCount: 20 },
|
|
49
|
+
breadcrumbs: false,
|
|
50
|
+
customerDeleteEnabled: true,
|
|
51
|
+
previewSecret: 'SECRET',
|
|
47
52
|
};
|
|
@@ -43,6 +43,8 @@ function configToEnvSchema(schema) {
|
|
|
43
43
|
node = node.unwrap();
|
|
44
44
|
if (node instanceof zod_1.ZodNullable)
|
|
45
45
|
node = node.unwrap();
|
|
46
|
+
if (node instanceof zod_1.ZodDefault)
|
|
47
|
+
node = node.removeDefault();
|
|
46
48
|
if (node instanceof zod_1.ZodObject) {
|
|
47
49
|
if (path.length > 0) {
|
|
48
50
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z
|
|
@@ -73,7 +75,12 @@ function configToEnvSchema(schema) {
|
|
|
73
75
|
});
|
|
74
76
|
return;
|
|
75
77
|
}
|
|
76
|
-
if (node instanceof zod_1.
|
|
78
|
+
if (node instanceof zod_1.ZodNumber) {
|
|
79
|
+
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z.coerce.number().optional();
|
|
80
|
+
envToDot[(0, exports.toEnvStr)(path)] = (0, exports.dotNotation)(path);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (node instanceof zod_1.ZodString || node instanceof zod_1.ZodEnum) {
|
|
77
84
|
envSchema[(0, exports.toEnvStr)(path)] = node.optional();
|
|
78
85
|
envToDot[(0, exports.toEnvStr)(path)] = (0, exports.dotNotation)(path);
|
|
79
86
|
return;
|
package/dist/generated/config.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SidebarGalleryConfigSchema = exports.RecentlyViewedProductsConfigSchema = exports.MagentoConfigurableVariantValuesSchema = exports.GraphCommerceStorefrontConfigSchema = exports.GraphCommerceDebugConfigSchema = exports.GraphCommerceConfigSchema = exports.DatalayerConfigSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.CompareVariantSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0;
|
|
3
|
+
exports.SidebarGalleryConfigSchema = exports.RecentlyViewedProductsConfigSchema = exports.MagentoConfigurableVariantValuesSchema = exports.GraphCommerceStorefrontConfigSchema = exports.GraphCommerceDebugConfigSchema = exports.GraphCommerceConfigSchema = exports.DatalayerConfigSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.PaginationVariantSchema = exports.CompareVariantSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0;
|
|
4
4
|
/* eslint-disable */
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const isDefinedNonNullAny = (v) => v !== undefined && v !== null;
|
|
7
7
|
exports.isDefinedNonNullAny = isDefinedNonNullAny;
|
|
8
8
|
exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v));
|
|
9
9
|
exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']);
|
|
10
|
+
exports.PaginationVariantSchema = zod_1.z.enum(['COMPACT', 'EXTENDED']);
|
|
10
11
|
exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']);
|
|
11
12
|
exports.SidebarGalleryPaginationVariantSchema = zod_1.z.enum(['DOTS', 'THUMBNAILS_BOTTOM']);
|
|
12
13
|
function DatalayerConfigSchema() {
|
|
@@ -17,18 +18,21 @@ function DatalayerConfigSchema() {
|
|
|
17
18
|
exports.DatalayerConfigSchema = DatalayerConfigSchema;
|
|
18
19
|
function GraphCommerceConfigSchema() {
|
|
19
20
|
return zod_1.z.object({
|
|
21
|
+
breadcrumbs: zod_1.z.boolean().default(false).nullish(),
|
|
20
22
|
canonicalBaseUrl: zod_1.z.string().min(1),
|
|
21
23
|
cartDisplayPricesInclTax: zod_1.z.boolean().nullish(),
|
|
22
24
|
compare: zod_1.z.boolean().nullish(),
|
|
23
|
-
compareVariant: exports.CompareVariantSchema.nullish(),
|
|
24
|
-
configurableVariantForSimple: zod_1.z.boolean().nullish(),
|
|
25
|
+
compareVariant: exports.CompareVariantSchema.default("ICON").nullish(),
|
|
26
|
+
configurableVariantForSimple: zod_1.z.boolean().default(false).nullish(),
|
|
25
27
|
configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(),
|
|
26
|
-
crossSellsHideCartItems: zod_1.z.boolean().nullish(),
|
|
27
|
-
crossSellsRedirectItems: zod_1.z.boolean().nullish(),
|
|
28
|
-
|
|
28
|
+
crossSellsHideCartItems: zod_1.z.boolean().default(false).nullish(),
|
|
29
|
+
crossSellsRedirectItems: zod_1.z.boolean().default(false).nullish(),
|
|
30
|
+
customerAddressNoteEnable: zod_1.z.boolean().nullish(),
|
|
31
|
+
customerCompanyFieldsEnable: zod_1.z.boolean().nullish(),
|
|
32
|
+
customerDeleteEnabled: zod_1.z.boolean().nullish(),
|
|
29
33
|
dataLayer: DatalayerConfigSchema().nullish(),
|
|
30
34
|
debug: GraphCommerceDebugConfigSchema().nullish(),
|
|
31
|
-
demoMode: zod_1.z.boolean().nullish(),
|
|
35
|
+
demoMode: zod_1.z.boolean().default(true).nullish(),
|
|
32
36
|
enableGuestCheckoutLogin: zod_1.z.boolean().nullish(),
|
|
33
37
|
googleAnalyticsId: zod_1.z.string().nullish(),
|
|
34
38
|
googleRecaptchaKey: zod_1.z.string().nullish(),
|
|
@@ -40,9 +44,11 @@ function GraphCommerceConfigSchema() {
|
|
|
40
44
|
hygraphWriteAccessToken: zod_1.z.string().nullish(),
|
|
41
45
|
limitSsg: zod_1.z.boolean().nullish(),
|
|
42
46
|
magentoEndpoint: zod_1.z.string().min(1),
|
|
47
|
+
magentoVersion: zod_1.z.number(),
|
|
43
48
|
previewSecret: zod_1.z.string().nullish(),
|
|
44
|
-
productFiltersLayout: exports.ProductFiltersLayoutSchema.nullish(),
|
|
49
|
+
productFiltersLayout: exports.ProductFiltersLayoutSchema.default("DEFAULT").nullish(),
|
|
45
50
|
productFiltersPro: zod_1.z.boolean().nullish(),
|
|
51
|
+
productListPaginationVariant: exports.PaginationVariantSchema.default("COMPACT").nullish(),
|
|
46
52
|
productRoute: zod_1.z.string().nullish(),
|
|
47
53
|
recentlyViewedProducts: RecentlyViewedProductsConfigSchema().nullish(),
|
|
48
54
|
robotsAllow: zod_1.z.boolean().nullish(),
|
|
@@ -66,6 +72,7 @@ function GraphCommerceStorefrontConfigSchema() {
|
|
|
66
72
|
return zod_1.z.object({
|
|
67
73
|
canonicalBaseUrl: zod_1.z.string().nullish(),
|
|
68
74
|
cartDisplayPricesInclTax: zod_1.z.boolean().nullish(),
|
|
75
|
+
customerCompanyFieldsEnable: zod_1.z.boolean().nullish(),
|
|
69
76
|
defaultLocale: zod_1.z.boolean().nullish(),
|
|
70
77
|
domain: zod_1.z.string().nullish(),
|
|
71
78
|
googleAnalyticsId: zod_1.z.string().nullish(),
|
|
@@ -74,7 +81,8 @@ function GraphCommerceStorefrontConfigSchema() {
|
|
|
74
81
|
hygraphLocales: zod_1.z.array(zod_1.z.string().min(1)).nullish(),
|
|
75
82
|
linguiLocale: zod_1.z.string().nullish(),
|
|
76
83
|
locale: zod_1.z.string().min(1),
|
|
77
|
-
magentoStoreCode: zod_1.z.string().min(1)
|
|
84
|
+
magentoStoreCode: zod_1.z.string().min(1),
|
|
85
|
+
robotsAllow: zod_1.z.boolean().nullish()
|
|
78
86
|
});
|
|
79
87
|
}
|
|
80
88
|
exports.GraphCommerceStorefrontConfigSchema = GraphCommerceStorefrontConfigSchema;
|
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;
|