@graphcommerce/next-config 9.0.0-canary.105 → 9.0.0-canary.107
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 +8 -0
- package/__tests__/commands/copyFiles.ts +512 -0
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +3 -0
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +4 -17
- package/__tests__/config/utils/rewriteLegancyEnv.ts +30 -35
- package/__tests__/interceptors/findPlugins.ts +38 -53
- package/__tests__/interceptors/generateInterceptors.ts +23 -74
- package/__tests__/utils/resolveDependenciesSync.ts +9 -9
- package/dist/commands/codegen.js +18 -0
- package/dist/commands/copyFiles.js +293 -0
- package/dist/commands/copyRoutes.js +20 -0
- package/dist/config/utils/mergeEnvIntoConfig.js +5 -5
- package/dist/generated/config.js +8 -0
- package/dist/index.js +3 -0
- package/dist/interceptors/generateInterceptor.js +3 -5
- package/dist/utils/resolveDependenciesSync.js +6 -1
- package/dist/utils/sig.js +34 -0
- package/dist/withGraphCommerce.js +1 -1
- package/package.json +10 -9
- package/src/commands/codegen.ts +18 -0
- package/src/commands/copyFiles.ts +329 -0
- package/src/config/utils/mergeEnvIntoConfig.ts +6 -7
- package/src/generated/config.ts +18 -0
- package/src/index.ts +4 -3
- package/src/interceptors/generateInterceptor.ts +3 -5
- package/src/utils/resolveDependenciesSync.ts +10 -1
- package/src/utils/sig.ts +37 -0
- package/src/withGraphCommerce.ts +1 -1
- package/dist/config/commands/generateIntercetors.js +0 -9
- package/dist/interceptors/commands/generateIntercetors.js +0 -9
|
@@ -5,33 +5,31 @@ import { generateInterceptors } from '../../src/interceptors/generateInterceptor
|
|
|
5
5
|
import { parseStructure } from '../../src/interceptors/parseStructure'
|
|
6
6
|
import { parseSync } from '../../src/interceptors/swc'
|
|
7
7
|
import { resolveDependency } from '../../src/utils/resolveDependency'
|
|
8
|
-
|
|
9
8
|
const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
10
|
-
|
|
11
9
|
const startLocation = '/** @see {@link file://'
|
|
12
|
-
|
|
13
10
|
const expectImport = (value: string | undefined): jest.JestMatchers<string> =>
|
|
14
|
-
expect(
|
|
11
|
+
expect(
|
|
12
|
+
value
|
|
13
|
+
?.slice(value.indexOf('import') - 1, value.indexOf(startLocation) - 1)
|
|
15
14
|
|
|
15
|
+
.trim(),
|
|
16
|
+
)
|
|
16
17
|
const expectInterceptor = (value: string | undefined): jest.JestMatchers<string> => {
|
|
17
18
|
const val = value?.slice(value.indexOf(SOURCE_END) + SOURCE_END.length).trim()
|
|
18
19
|
return expect(val?.trim())
|
|
19
20
|
}
|
|
20
|
-
|
|
21
21
|
const expectOriginal = (value: string | undefined): jest.JestMatchers<string> =>
|
|
22
22
|
expect(
|
|
23
23
|
value
|
|
24
24
|
?.slice(value.indexOf(SOURCE_START) + SOURCE_START.length, value.indexOf(SOURCE_END))
|
|
25
25
|
.trim(),
|
|
26
26
|
)
|
|
27
|
-
|
|
28
27
|
it('it replaces paths and creates a relative path', () => {
|
|
29
28
|
const resolver = resolveDependency(projectRoot)
|
|
30
29
|
const resolved = resolver('@graphcommerce/magento-cart-payment-method')
|
|
31
30
|
expect(resolved?.fromRoot).toMatchInlineSnapshot('"packages/magento-cart-payment-method/index"')
|
|
32
31
|
expect(resolved?.fromModule).toBe('.')
|
|
33
32
|
expect(resolved?.root).toBe('packages/magento-cart-payment-method')
|
|
34
|
-
|
|
35
33
|
const resolved2 = resolver(
|
|
36
34
|
'@graphcommerce/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext',
|
|
37
35
|
)
|
|
@@ -41,7 +39,6 @@ it('it replaces paths and creates a relative path', () => {
|
|
|
41
39
|
expect(resolved2?.fromModule).toBe('./PaymentMethodContext')
|
|
42
40
|
expect(resolved2?.root).toBe('packages/magento-cart-payment-method')
|
|
43
41
|
})
|
|
44
|
-
|
|
45
42
|
it('it generates an interceptor', async () => {
|
|
46
43
|
const resolve = resolveDependency(projectRoot)
|
|
47
44
|
const interceptors = await generateInterceptors(
|
|
@@ -65,11 +62,9 @@ it('it generates an interceptor', async () => {
|
|
|
65
62
|
],
|
|
66
63
|
resolve,
|
|
67
64
|
)
|
|
68
|
-
|
|
69
65
|
expect(Object.keys(interceptors)[0]).toBe(
|
|
70
66
|
'packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext',
|
|
71
67
|
)
|
|
72
|
-
|
|
73
68
|
const result =
|
|
74
69
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
75
70
|
?.template
|
|
@@ -93,7 +88,8 @@ it('it generates an interceptor', async () => {
|
|
|
93
88
|
/**
|
|
94
89
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
95
90
|
*
|
|
96
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
91
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
92
|
+
* original source changes.
|
|
97
93
|
*
|
|
98
94
|
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
99
95
|
* @see {PluginAddBraintreeMethods} for source of applied plugin
|
|
@@ -102,7 +98,6 @@ it('it generates an interceptor', async () => {
|
|
|
102
98
|
export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
|
|
103
99
|
`)
|
|
104
100
|
})
|
|
105
|
-
|
|
106
101
|
it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
107
102
|
const interceptors = await generateInterceptors(
|
|
108
103
|
[
|
|
@@ -117,7 +112,6 @@ it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
|
117
112
|
],
|
|
118
113
|
resolveDependency(projectRoot),
|
|
119
114
|
)
|
|
120
|
-
|
|
121
115
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
122
116
|
'"packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext"',
|
|
123
117
|
)
|
|
@@ -128,7 +122,6 @@ it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
|
128
122
|
"import { Plugin as PluginAddPaymentMethodEnhancer } from '../../../plugins/AddPaymentMethodEnhancer'",
|
|
129
123
|
)
|
|
130
124
|
})
|
|
131
|
-
|
|
132
125
|
it('it can apply multiple plugins to a single export', async () => {
|
|
133
126
|
const resolve = resolveDependency(projectRoot)
|
|
134
127
|
const interceptors = await generateInterceptors(
|
|
@@ -162,7 +155,6 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
162
155
|
"import { Plugin as PluginAddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'",
|
|
163
156
|
)
|
|
164
157
|
expectOriginal(result).toContain('PaymentMethodContextProviderOriginal')
|
|
165
|
-
|
|
166
158
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
167
159
|
"type PluginAddAdyenMethodsProps = OmitPrev<
|
|
168
160
|
React.ComponentProps<typeof PluginAddAdyenMethods>,
|
|
@@ -183,7 +175,8 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
183
175
|
/**
|
|
184
176
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
185
177
|
*
|
|
186
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
178
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
179
|
+
* original source changes.
|
|
187
180
|
*
|
|
188
181
|
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
189
182
|
* @see {PluginAddAdyenMethods} for source of applied plugin
|
|
@@ -192,7 +185,6 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
192
185
|
export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
|
|
193
186
|
`)
|
|
194
187
|
})
|
|
195
|
-
|
|
196
188
|
it('it handles on duplicates gracefully', async () => {
|
|
197
189
|
const resolve = resolveDependency(projectRoot)
|
|
198
190
|
const interceptors = await generateInterceptors(
|
|
@@ -216,7 +208,6 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
216
208
|
],
|
|
217
209
|
resolve,
|
|
218
210
|
)
|
|
219
|
-
|
|
220
211
|
const result =
|
|
221
212
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
222
213
|
?.template
|
|
@@ -233,7 +224,8 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
233
224
|
/**
|
|
234
225
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
235
226
|
*
|
|
236
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
227
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
228
|
+
* original source changes.
|
|
237
229
|
*
|
|
238
230
|
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
239
231
|
* @see {PluginAddBraintreeMethods} for source of applied plugin
|
|
@@ -241,7 +233,6 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
241
233
|
export const PaymentMethodContextProvider = PluginAddBraintreeMethodsInterceptor"
|
|
242
234
|
`)
|
|
243
235
|
})
|
|
244
|
-
|
|
245
236
|
it('correctly renames all variable usages', async () => {
|
|
246
237
|
const resolve = resolveDependency(projectRoot)
|
|
247
238
|
const interceptors = await generateInterceptors(
|
|
@@ -257,17 +248,14 @@ it('correctly renames all variable usages', async () => {
|
|
|
257
248
|
],
|
|
258
249
|
resolve,
|
|
259
250
|
)
|
|
260
|
-
|
|
261
251
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
262
252
|
'"packages/magento-product/components/ProductListItem/ProductListItem"',
|
|
263
253
|
)
|
|
264
|
-
|
|
265
254
|
const template =
|
|
266
255
|
interceptors['packages/magento-product/components/ProductListItem/ProductListItem']?.template
|
|
267
256
|
expectOriginal(template).not.toContain('ProductListItem.selectors')
|
|
268
257
|
expectOriginal(template).toContain('ProductListItemOriginal.selectors')
|
|
269
258
|
})
|
|
270
|
-
|
|
271
259
|
it('it handles root plugins', async () => {
|
|
272
260
|
const resolve = resolveDependency(projectRoot)
|
|
273
261
|
const interceptors = await generateInterceptors(
|
|
@@ -283,15 +271,12 @@ it('it handles root plugins', async () => {
|
|
|
283
271
|
],
|
|
284
272
|
resolve,
|
|
285
273
|
)
|
|
286
|
-
|
|
287
274
|
expect(interceptors['packages/magento-product/index']?.template).toMatchInlineSnapshot(
|
|
288
275
|
'undefined',
|
|
289
276
|
)
|
|
290
277
|
})
|
|
291
|
-
|
|
292
278
|
it('it handles root plugins and creates a relative path', async () => {
|
|
293
279
|
const resolve = resolveDependency(projectRoot)
|
|
294
|
-
|
|
295
280
|
const interceptors = await generateInterceptors(
|
|
296
281
|
[
|
|
297
282
|
{
|
|
@@ -305,17 +290,14 @@ it('it handles root plugins and creates a relative path', async () => {
|
|
|
305
290
|
],
|
|
306
291
|
resolve,
|
|
307
292
|
)
|
|
308
|
-
|
|
309
293
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
310
294
|
'"packages/next-ui/Overlay/components/OverlayBase"',
|
|
311
295
|
)
|
|
312
|
-
|
|
313
296
|
expect(
|
|
314
297
|
interceptors['packages/next-ui/Overlay/components/OverlayBase'].targetExports.OverlayBase[0]
|
|
315
298
|
.sourceModule,
|
|
316
299
|
).toMatchInlineSnapshot('"../../../../examples/magento-graphcms/plugins/EnableCrosssellsPlugin"')
|
|
317
300
|
})
|
|
318
|
-
|
|
319
301
|
it('generates method interceptors alognside component interceptors', async () => {
|
|
320
302
|
const resolve = resolveDependency(projectRoot)
|
|
321
303
|
const interceptors = await generateInterceptors(
|
|
@@ -347,7 +329,6 @@ it('generates method interceptors alognside component interceptors', async () =>
|
|
|
347
329
|
],
|
|
348
330
|
resolve,
|
|
349
331
|
)
|
|
350
|
-
|
|
351
332
|
expect(Object.keys(interceptors)).toMatchInlineSnapshot(
|
|
352
333
|
`
|
|
353
334
|
[
|
|
@@ -356,14 +337,12 @@ it('generates method interceptors alognside component interceptors', async () =>
|
|
|
356
337
|
]
|
|
357
338
|
`,
|
|
358
339
|
)
|
|
359
|
-
|
|
360
340
|
expect(
|
|
361
341
|
interceptors['packages/graphql/components/GraphQLProvider/GraphQLProvider']?.template,
|
|
362
342
|
).toContain('MagentoGraphqlGraphqlProvider')
|
|
363
343
|
expect(interceptors['packages/graphql/config']?.template).toContain('magentoInitMemoryCache')
|
|
364
344
|
expect(interceptors['packages/graphql/config']?.template).toContain('hygraphInitMemoryCache')
|
|
365
345
|
})
|
|
366
|
-
|
|
367
346
|
it('adds debug logging to interceptors for components', async () => {
|
|
368
347
|
const resolve = resolveDependency(projectRoot)
|
|
369
348
|
const interceptors = await generateInterceptors(
|
|
@@ -396,12 +375,10 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
396
375
|
resolve,
|
|
397
376
|
{ pluginStatus: true },
|
|
398
377
|
)
|
|
399
|
-
|
|
400
378
|
expectImport(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
401
379
|
"import { plugin as pluginhygraphInitMemoryCache } from '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache'
|
|
402
380
|
import { plugin as pluginmagentoInitMemoryCache } from '@graphcommerce/magento-graphql/plugins/magentoInitMemoryCache'"
|
|
403
381
|
`)
|
|
404
|
-
|
|
405
382
|
expectOriginal(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
406
383
|
"import type { GraphCommerceStorefrontConfig } from '@graphcommerce/next-config'
|
|
407
384
|
import type { ApolloLink, TypePolicies } from '@apollo/client'
|
|
@@ -460,7 +437,8 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
460
437
|
/**
|
|
461
438
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
462
439
|
*
|
|
463
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
440
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
441
|
+
* original source changes.
|
|
464
442
|
*
|
|
465
443
|
* @see {@link file://./config.ts} for original source file
|
|
466
444
|
* @see {pluginhygraphInitMemoryCache} for source of applied plugin
|
|
@@ -469,7 +447,6 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
469
447
|
export const graphqlConfig = pluginmagentoInitMemoryCacheInterceptor"
|
|
470
448
|
`)
|
|
471
449
|
})
|
|
472
|
-
|
|
473
450
|
it('correctly resolves when a source can not be parsed', async () => {
|
|
474
451
|
const resolve = resolveDependency(projectRoot)
|
|
475
452
|
const interceptors = await generateInterceptors(
|
|
@@ -486,12 +463,10 @@ it('correctly resolves when a source can not be parsed', async () => {
|
|
|
486
463
|
resolve,
|
|
487
464
|
{ pluginStatus: true },
|
|
488
465
|
)
|
|
489
|
-
|
|
490
466
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
491
467
|
'"packages/next-ui/Row/RowLinks/RowLinks"',
|
|
492
468
|
)
|
|
493
469
|
})
|
|
494
|
-
|
|
495
470
|
it('can correctly find the source for deeper chained exports', () => {
|
|
496
471
|
const resolve = resolveDependency(projectRoot)
|
|
497
472
|
const originalSource = findOriginalSource(
|
|
@@ -511,7 +486,6 @@ it('can correctly find the source for deeper chained exports', () => {
|
|
|
511
486
|
'"@graphcommerce/next-ui/Blog/BlogTags/BlogTag"',
|
|
512
487
|
)
|
|
513
488
|
})
|
|
514
|
-
|
|
515
489
|
it('Should apply overrides to the correct file', async () => {
|
|
516
490
|
const resolve = resolveDependency(projectRoot)
|
|
517
491
|
const interceptors = await generateInterceptors(
|
|
@@ -527,28 +501,23 @@ it('Should apply overrides to the correct file', async () => {
|
|
|
527
501
|
],
|
|
528
502
|
resolve,
|
|
529
503
|
)
|
|
530
|
-
|
|
531
504
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
532
505
|
'"packages/magento-product/components/ProductStaticPaths/getProductStaticPaths"',
|
|
533
506
|
)
|
|
534
|
-
|
|
535
507
|
const result =
|
|
536
508
|
interceptors['packages/magento-product/components/ProductStaticPaths/getProductStaticPaths']
|
|
537
509
|
?.template
|
|
538
510
|
expect(result).toContain(
|
|
539
511
|
"import { getProductStaticPaths as getProductStaticPathsreplaceGetProductStaticPaths } from '../../../../plugins/replaceGetProductStaticPaths'",
|
|
540
512
|
)
|
|
541
|
-
|
|
542
513
|
expectOriginal(result).toContain('getProductStaticPathsDisabled')
|
|
543
514
|
})
|
|
544
|
-
|
|
545
515
|
it('correctly reports an error for an incorrect export', async () => {
|
|
546
516
|
const fakeconfig = {
|
|
547
517
|
googleRecaptchaKey: '123',
|
|
548
518
|
googleAnalyticsId: '123',
|
|
549
519
|
demoMode: true,
|
|
550
520
|
} as unknown as GraphCommerceConfig
|
|
551
|
-
|
|
552
521
|
const src = `
|
|
553
522
|
import { getSitemapPaths as getSitemapPathsType } from '@graphcommerce/magento-product'
|
|
554
523
|
import { IfConfig, FunctionPlugin } from '@graphcommerce/next-config'
|
|
@@ -562,20 +531,15 @@ export const plugin: FunctionPlugin<typeof getSitemapPathsType> = (prev, ...args
|
|
|
562
531
|
return prev(...args)
|
|
563
532
|
}
|
|
564
533
|
`
|
|
565
|
-
|
|
566
534
|
console.error = jest.fn()
|
|
567
535
|
const plugins = parseStructure(parseSync(src), fakeconfig, './plugins/MyPlugin.tsx')
|
|
568
|
-
|
|
569
536
|
expect((console.error as jest.Mock).mock.calls[0][0]).toMatchInlineSnapshot(
|
|
570
537
|
'"Plugin configuration invalid! See ./plugins/MyPlugin.tsx"',
|
|
571
538
|
)
|
|
572
|
-
|
|
573
539
|
expect(plugins).toMatchInlineSnapshot('[]')
|
|
574
540
|
const result = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
575
|
-
|
|
576
541
|
expect(Object.keys(result)).toMatchInlineSnapshot('[]')
|
|
577
542
|
})
|
|
578
|
-
|
|
579
543
|
it('generated a correct file if a replacement and a plugin is applied to the same export', async () => {
|
|
580
544
|
const src1 = `import { ProductPageNameProps } from '@graphcommerce/magento-product'
|
|
581
545
|
import { PluginConfig } from '@graphcommerce/next-config'
|
|
@@ -591,7 +555,6 @@ export function ProductPageName(props: ProductPageNameProps) {
|
|
|
591
555
|
return <div>Complete overrides {product.url_key}</div>
|
|
592
556
|
}
|
|
593
557
|
`
|
|
594
|
-
|
|
595
558
|
const src2 = `import type { AddToCartItemSelector, ProductPageNameProps } from '@graphcommerce/magento-product'
|
|
596
559
|
import type { IfConfig, PluginProps } from '@graphcommerce/next-config'
|
|
597
560
|
import { useConfigurableSelectedVariant } from '../../hooks'
|
|
@@ -610,21 +573,17 @@ const ConfigurableProductPageName = (
|
|
|
610
573
|
|
|
611
574
|
export const Plugin = ConfigurableProductPageName
|
|
612
575
|
`
|
|
613
|
-
|
|
614
576
|
const config = {
|
|
615
577
|
demoMode: true,
|
|
616
578
|
configurableVariantForSimple: true,
|
|
617
579
|
configurableVariantValues: { content: true, gallery: true, url: true },
|
|
618
580
|
} as unknown as GraphCommerceConfig
|
|
619
|
-
|
|
620
581
|
const firstFile = parseStructure(parseSync(src1), config, './plugins/MyPlugin')
|
|
621
|
-
|
|
622
582
|
const secondFile = parseStructure(
|
|
623
583
|
parseSync(src2),
|
|
624
584
|
config,
|
|
625
585
|
'@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName',
|
|
626
586
|
)
|
|
627
|
-
|
|
628
587
|
const plugins = [...firstFile, ...secondFile]
|
|
629
588
|
expect(plugins).toMatchInlineSnapshot(
|
|
630
589
|
`
|
|
@@ -651,20 +610,16 @@ export const Plugin = ConfigurableProductPageName
|
|
|
651
610
|
`,
|
|
652
611
|
)
|
|
653
612
|
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
654
|
-
|
|
655
613
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
656
614
|
'"packages/magento-product/components/ProductPageName/ProductPageName"',
|
|
657
615
|
)
|
|
658
|
-
|
|
659
616
|
const result =
|
|
660
617
|
interceptors['packages/magento-product/components/ProductPageName/ProductPageName']?.template
|
|
661
|
-
|
|
662
618
|
expectImport(result).toMatchInlineSnapshot(`
|
|
663
619
|
"import { Plugin as PluginConfigurableProductPageName } from '@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName'
|
|
664
620
|
import type { DistributedOmit as OmitPrev } from 'type-fest'
|
|
665
621
|
import { ProductPageName as ProductPageNameMyPlugin } from '../../../../plugins/MyPlugin'"
|
|
666
622
|
`)
|
|
667
|
-
|
|
668
623
|
expectOriginal(result).toMatchInlineSnapshot(`
|
|
669
624
|
"import type { ProductPageNameFragment } from './ProductPageName.gql'
|
|
670
625
|
|
|
@@ -676,7 +631,6 @@ export const Plugin = ConfigurableProductPageName
|
|
|
676
631
|
return <>{product.name}</>
|
|
677
632
|
}"
|
|
678
633
|
`)
|
|
679
|
-
|
|
680
634
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
681
635
|
"type PluginConfigurableProductPageNameProps = React.ComponentProps<typeof ProductPageNameMyPlugin> &
|
|
682
636
|
OmitPrev<React.ComponentProps<typeof PluginConfigurableProductPageName>, 'Prev'>
|
|
@@ -688,7 +642,8 @@ export const Plugin = ConfigurableProductPageName
|
|
|
688
642
|
/**
|
|
689
643
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
690
644
|
*
|
|
691
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
645
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
646
|
+
* original source changes.
|
|
692
647
|
*
|
|
693
648
|
* @see {@link file://./ProductPageName.tsx} for original source file
|
|
694
649
|
* @see {ProductPageNameMyPlugin} for replacement of the original source (original source not used)
|
|
@@ -697,7 +652,6 @@ export const Plugin = ConfigurableProductPageName
|
|
|
697
652
|
export const ProductPageName = PluginConfigurableProductPageNameInterceptor"
|
|
698
653
|
`)
|
|
699
654
|
})
|
|
700
|
-
|
|
701
655
|
it('generates to a .ts file when the target file is a .ts as well', async () => {
|
|
702
656
|
const resolve = resolveDependency(projectRoot)
|
|
703
657
|
const interceptors = await generateInterceptors(
|
|
@@ -713,14 +667,11 @@ it('generates to a .ts file when the target file is a .ts as well', async () =>
|
|
|
713
667
|
],
|
|
714
668
|
resolve,
|
|
715
669
|
)
|
|
716
|
-
|
|
717
670
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot('"packages/graphql/config"')
|
|
718
671
|
const interceptor = interceptors['packages/graphql/config']
|
|
719
672
|
expect(interceptor.sourcePath).toBe('packages/graphql/config.ts')
|
|
720
673
|
})
|
|
721
|
-
|
|
722
674
|
it.todo('Should report an error when multiple files are overriding the same export')
|
|
723
|
-
|
|
724
675
|
it('Can correctly find exports that are default exports', async () => {
|
|
725
676
|
const pluginSource = `
|
|
726
677
|
import { PluginConfig } from '@graphcommerce/next-config'
|
|
@@ -741,29 +692,25 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
741
692
|
configurableVariantForSimple: true,
|
|
742
693
|
configurableVariantValues: { content: true, gallery: true, url: true },
|
|
743
694
|
} as unknown as GraphCommerceConfig
|
|
744
|
-
|
|
745
695
|
const plugins = parseStructure(parseSync(pluginSource), config, './plugins/MyProjectIcon')
|
|
746
|
-
|
|
747
696
|
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
748
697
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot('"packages/next-ui/icons"')
|
|
749
|
-
|
|
750
698
|
const result = interceptors['packages/next-ui/icons']?.template
|
|
751
|
-
|
|
752
699
|
expectImport(result).toMatchInlineSnapshot(`
|
|
753
700
|
"import {
|
|
754
701
|
iconChevronLeft as iconChevronLeftMyProjectIcon,
|
|
755
702
|
iconChevronRight as iconChevronRightMyProjectIcon,
|
|
756
703
|
} from '../../plugins/MyProjectIcon'"
|
|
757
704
|
`)
|
|
758
|
-
|
|
759
705
|
expectOriginal(result).toContain('iconChevronLeftDisabled')
|
|
760
706
|
expectOriginal(result).toContain('iconChevronRightDisabled')
|
|
761
|
-
|
|
762
|
-
|
|
707
|
+
expectInterceptor(result).toMatchInlineSnapshot(
|
|
708
|
+
`
|
|
763
709
|
"/**
|
|
764
710
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
765
711
|
*
|
|
766
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
712
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
713
|
+
* original source changes.
|
|
767
714
|
*
|
|
768
715
|
* @see {@link file://./icons.ts} for original source file
|
|
769
716
|
* @see {iconChevronLeftMyProjectIcon} for replacement of the original source (original source not used)
|
|
@@ -773,11 +720,13 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
773
720
|
/**
|
|
774
721
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
775
722
|
*
|
|
776
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
723
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
724
|
+
* original source changes.
|
|
777
725
|
*
|
|
778
726
|
* @see {@link file://./icons.ts} for original source file
|
|
779
727
|
* @see {iconChevronRightMyProjectIcon} for replacement of the original source (original source not used)
|
|
780
728
|
*/
|
|
781
729
|
export const iconChevronRight = iconChevronRightMyProjectIcon"
|
|
782
|
-
|
|
730
|
+
`,
|
|
731
|
+
)
|
|
783
732
|
})
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { resolveDependenciesSync, sortDependencies } from '../../src/utils/resolveDependenciesSync'
|
|
2
|
-
|
|
3
2
|
const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
4
|
-
|
|
5
3
|
it('resolves dependences', () => {
|
|
6
4
|
const dependencies = resolveDependenciesSync(projectRoot)
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
expect(dependencies).toMatchInlineSnapshot(
|
|
6
|
+
`
|
|
9
7
|
Map {
|
|
10
8
|
"." => "examples/magento-graphcms",
|
|
11
9
|
"@graphcommerce/cli" => "packages/cli",
|
|
12
10
|
"@graphcommerce/hygraph-cli" => "packages/hygraph-cli",
|
|
13
11
|
"@graphcommerce/demo-magento-graphcommerce" => "packages/demo-magento-graphcommerce",
|
|
14
12
|
"@graphcommerce/magento-recently-viewed-products" => "packages/magento-recently-viewed-products",
|
|
13
|
+
"@graphcommerce/google-playstore" => "packages/google-playstore",
|
|
15
14
|
"@graphcommerce/googleanalytics" => "packages/googleanalytics",
|
|
16
15
|
"@graphcommerce/googlerecaptcha" => "packages/googlerecaptcha",
|
|
17
16
|
"@graphcommerce/googletagmanager" => "packages/googletagmanager",
|
|
@@ -72,9 +71,9 @@ it('resolves dependences', () => {
|
|
|
72
71
|
"@graphcommerce/eslint-config-pwa" => "packagesDev/eslint-config",
|
|
73
72
|
"@graphcommerce/typescript-config-pwa" => "packagesDev/typescript-config",
|
|
74
73
|
}
|
|
75
|
-
|
|
74
|
+
`,
|
|
75
|
+
)
|
|
76
76
|
})
|
|
77
|
-
|
|
78
77
|
it('sorts dependencies', () => {
|
|
79
78
|
const sorted = sortDependencies({
|
|
80
79
|
'@graphcommerce/magento-graphcms': {
|
|
@@ -94,13 +93,14 @@ it('sorts dependencies', () => {
|
|
|
94
93
|
dependencies: ['@graphcommerce/magento-product'],
|
|
95
94
|
},
|
|
96
95
|
})
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
expect(sorted).toMatchInlineSnapshot(
|
|
97
|
+
`
|
|
99
98
|
Map {
|
|
100
99
|
"@graphcommerce/magento-graphcms" => "examples/magento-graphcms",
|
|
101
100
|
"@graphcommerce/magento-cart" => "packages/magento-cart",
|
|
102
101
|
"@graphcommerce/magento-product" => "packages/magento-product",
|
|
103
102
|
"@graphcommerce/magento-product-simple" => "packages/magento-product-simple",
|
|
104
103
|
}
|
|
105
|
-
|
|
104
|
+
`,
|
|
105
|
+
)
|
|
106
106
|
})
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codegen = codegen;
|
|
4
|
+
const generateConfig_1 = require("../config/commands/generateConfig");
|
|
5
|
+
const codegenInterceptors_1 = require("../interceptors/commands/codegenInterceptors");
|
|
6
|
+
const copyFiles_1 = require("./copyFiles");
|
|
7
|
+
/** Run all code generation steps in sequence */
|
|
8
|
+
async function codegen() {
|
|
9
|
+
// Copy files from packages to project
|
|
10
|
+
console.log('🔄 Copying files from packages to project...');
|
|
11
|
+
await (0, copyFiles_1.copyFiles)();
|
|
12
|
+
// Generate GraphCommerce config types
|
|
13
|
+
console.log('⚙️ Generating GraphCommerce config types...');
|
|
14
|
+
await (0, generateConfig_1.generateConfig)();
|
|
15
|
+
// Generate interceptors
|
|
16
|
+
console.log('🔌 Generating interceptors...');
|
|
17
|
+
await (0, codegenInterceptors_1.codegenInterceptors)();
|
|
18
|
+
}
|