@graphcommerce/next-config 9.0.0-canary.99 → 9.0.0
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 +219 -1151
- package/__tests__/commands/copyFiles.ts +512 -0
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +6 -0
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +9 -20
- package/__tests__/config/utils/rewriteLegancyEnv.ts +32 -36
- package/__tests__/interceptors/findPlugins.ts +76 -78
- package/__tests__/interceptors/generateInterceptors.ts +78 -135
- package/__tests__/interceptors/parseStructure.ts +2 -2
- package/__tests__/utils/resolveDependenciesSync.ts +11 -10
- package/dist/commands/codegen.js +18 -0
- package/dist/commands/copyFiles.js +292 -0
- package/dist/commands/copyRoutes.js +20 -0
- package/dist/config/commands/exportConfig.js +1 -1
- package/dist/config/commands/generateConfig.js +2 -2
- package/dist/config/demoConfig.js +2 -2
- package/dist/config/utils/mergeEnvIntoConfig.js +18 -20
- package/dist/config/utils/rewriteLegacyEnv.js +2 -2
- package/dist/generated/config.js +13 -1
- package/dist/index.js +3 -1
- package/dist/interceptors/InterceptorPlugin.js +4 -3
- package/dist/interceptors/Visitor.js +5 -9
- package/dist/interceptors/commands/codegenInterceptors.js +2 -2
- package/dist/interceptors/extractExports.js +9 -54
- package/dist/interceptors/findOriginalSource.js +2 -1
- package/dist/interceptors/findPlugins.js +5 -8
- package/dist/interceptors/generateInterceptor.js +12 -10
- package/dist/interceptors/generateInterceptors.js +3 -2
- package/dist/interceptors/parseStructure.js +1 -1
- package/dist/interceptors/writeInterceptors.js +2 -2
- package/dist/utils/TopologicalSort.js +4 -0
- package/dist/utils/isMonorepo.js +40 -6
- package/dist/utils/resolveDependenciesSync.js +9 -2
- package/dist/utils/sig.js +34 -0
- package/dist/withGraphCommerce.js +3 -2
- package/package.json +17 -16
- package/src/commands/codegen.ts +18 -0
- package/src/commands/copyFiles.ts +328 -0
- package/src/config/commands/exportConfig.ts +1 -1
- package/src/config/commands/generateConfig.ts +3 -3
- package/src/config/demoConfig.ts +5 -5
- package/src/config/index.ts +1 -1
- package/src/config/utils/exportConfigToEnv.ts +1 -1
- package/src/config/utils/mergeEnvIntoConfig.ts +22 -25
- package/src/config/utils/replaceConfigInString.ts +1 -1
- package/src/config/utils/rewriteLegacyEnv.ts +5 -4
- package/src/generated/config.ts +36 -0
- package/src/index.ts +6 -5
- package/src/interceptors/InterceptorPlugin.ts +10 -7
- package/src/interceptors/RenameVisitor.ts +1 -1
- package/src/interceptors/Visitor.ts +10 -15
- package/src/interceptors/commands/codegenInterceptors.ts +2 -2
- package/src/interceptors/extractExports.ts +4 -46
- package/src/interceptors/findOriginalSource.ts +5 -4
- package/src/interceptors/findPlugins.ts +8 -9
- package/src/interceptors/generateInterceptor.ts +15 -12
- package/src/interceptors/generateInterceptors.ts +7 -13
- package/src/interceptors/parseStructure.ts +4 -4
- package/src/interceptors/swc.ts +2 -1
- package/src/interceptors/writeInterceptors.ts +3 -3
- package/src/utils/TopologicalSort.ts +4 -0
- package/src/utils/isMonorepo.ts +46 -5
- package/src/utils/packageRoots.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +14 -2
- package/src/utils/sig.ts +37 -0
- package/src/withGraphCommerce.ts +7 -5
- package/dist/config/commands/generateIntercetors.js +0 -9
- package/dist/interceptors/commands/generateIntercetors.js +0 -9
- package/dist/runtimeCachingOptimizations.js +0 -28
- package/src/runtimeCachingOptimizations.ts +0 -27
|
@@ -1,47 +1,39 @@
|
|
|
1
|
-
import { GraphCommerceConfig } from '../../src/generated/config'
|
|
1
|
+
import type { GraphCommerceConfig } from '../../src/generated/config'
|
|
2
2
|
import { findOriginalSource } from '../../src/interceptors/findOriginalSource'
|
|
3
|
-
import {
|
|
3
|
+
import { SOURCE_END, SOURCE_START } from '../../src/interceptors/generateInterceptor'
|
|
4
4
|
import { generateInterceptors } from '../../src/interceptors/generateInterceptors'
|
|
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(value?.slice(value.indexOf(
|
|
15
|
-
|
|
11
|
+
expect(value?.slice(value.indexOf('import') - 1, value.indexOf(startLocation) - 1).trim())
|
|
16
12
|
const expectInterceptor = (value: string | undefined): jest.JestMatchers<string> => {
|
|
17
13
|
const val = value?.slice(value.indexOf(SOURCE_END) + SOURCE_END.length).trim()
|
|
18
14
|
return expect(val?.trim())
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
const expectOriginal = (value: string | undefined): jest.JestMatchers<string> =>
|
|
22
17
|
expect(
|
|
23
18
|
value
|
|
24
19
|
?.slice(value.indexOf(SOURCE_START) + SOURCE_START.length, value.indexOf(SOURCE_END))
|
|
25
20
|
.trim(),
|
|
26
21
|
)
|
|
27
|
-
|
|
28
22
|
it('it replaces paths and creates a relative path', () => {
|
|
29
23
|
const resolver = resolveDependency(projectRoot)
|
|
30
24
|
const resolved = resolver('@graphcommerce/magento-cart-payment-method')
|
|
31
|
-
expect(resolved?.fromRoot).toMatchInlineSnapshot(
|
|
25
|
+
expect(resolved?.fromRoot).toMatchInlineSnapshot('"packages/magento-cart-payment-method/index"')
|
|
32
26
|
expect(resolved?.fromModule).toBe('.')
|
|
33
27
|
expect(resolved?.root).toBe('packages/magento-cart-payment-method')
|
|
34
|
-
|
|
35
28
|
const resolved2 = resolver(
|
|
36
29
|
'@graphcommerce/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext',
|
|
37
30
|
)
|
|
38
31
|
expect(resolved2?.fromRoot).toMatchInlineSnapshot(
|
|
39
|
-
|
|
32
|
+
'"packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext"',
|
|
40
33
|
)
|
|
41
34
|
expect(resolved2?.fromModule).toBe('./PaymentMethodContext')
|
|
42
35
|
expect(resolved2?.root).toBe('packages/magento-cart-payment-method')
|
|
43
36
|
})
|
|
44
|
-
|
|
45
37
|
it('it generates an interceptor', async () => {
|
|
46
38
|
const resolve = resolveDependency(projectRoot)
|
|
47
39
|
const interceptors = await generateInterceptors(
|
|
@@ -65,11 +57,9 @@ it('it generates an interceptor', async () => {
|
|
|
65
57
|
],
|
|
66
58
|
resolve,
|
|
67
59
|
)
|
|
68
|
-
|
|
69
60
|
expect(Object.keys(interceptors)[0]).toBe(
|
|
70
61
|
'packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext',
|
|
71
62
|
)
|
|
72
|
-
|
|
73
63
|
const result =
|
|
74
64
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
75
65
|
?.template
|
|
@@ -93,7 +83,8 @@ it('it generates an interceptor', async () => {
|
|
|
93
83
|
/**
|
|
94
84
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
95
85
|
*
|
|
96
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
86
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
87
|
+
* original source changes.
|
|
97
88
|
*
|
|
98
89
|
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
99
90
|
* @see {PluginAddBraintreeMethods} for source of applied plugin
|
|
@@ -102,7 +93,6 @@ it('it generates an interceptor', async () => {
|
|
|
102
93
|
export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
|
|
103
94
|
`)
|
|
104
95
|
})
|
|
105
|
-
|
|
106
96
|
it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
107
97
|
const interceptors = await generateInterceptors(
|
|
108
98
|
[
|
|
@@ -117,20 +107,16 @@ it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
|
117
107
|
],
|
|
118
108
|
resolveDependency(projectRoot),
|
|
119
109
|
)
|
|
120
|
-
|
|
121
110
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
122
|
-
|
|
111
|
+
'"packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext"',
|
|
123
112
|
)
|
|
124
|
-
|
|
113
|
+
expect(
|
|
125
114
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
126
115
|
?.template,
|
|
127
|
-
).
|
|
128
|
-
"import
|
|
129
|
-
|
|
130
|
-
import { Plugin as PluginAddPaymentMethodEnhancer } from '../../../plugins/AddPaymentMethodEnhancer'"
|
|
131
|
-
`)
|
|
116
|
+
).toContain(
|
|
117
|
+
"import { Plugin as PluginAddPaymentMethodEnhancer } from '../../../plugins/AddPaymentMethodEnhancer'",
|
|
118
|
+
)
|
|
132
119
|
})
|
|
133
|
-
|
|
134
120
|
it('it can apply multiple plugins to a single export', async () => {
|
|
135
121
|
const resolve = resolveDependency(projectRoot)
|
|
136
122
|
const interceptors = await generateInterceptors(
|
|
@@ -157,15 +143,13 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
157
143
|
const result =
|
|
158
144
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
159
145
|
?.template
|
|
160
|
-
|
|
161
|
-
"import
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
import { Plugin as PluginAddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'"
|
|
165
|
-
|
|
166
|
-
|
|
146
|
+
expect(result).toContain(
|
|
147
|
+
"import { Plugin as PluginAddAdyenMethods } from '@graphcommerce/magento-payment-adyen/plugins/AddAdyenMethods'",
|
|
148
|
+
)
|
|
149
|
+
expect(result).toContain(
|
|
150
|
+
"import { Plugin as PluginAddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'",
|
|
151
|
+
)
|
|
167
152
|
expectOriginal(result).toContain('PaymentMethodContextProviderOriginal')
|
|
168
|
-
|
|
169
153
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
170
154
|
"type PluginAddAdyenMethodsProps = OmitPrev<
|
|
171
155
|
React.ComponentProps<typeof PluginAddAdyenMethods>,
|
|
@@ -186,7 +170,8 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
186
170
|
/**
|
|
187
171
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
188
172
|
*
|
|
189
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
173
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
174
|
+
* original source changes.
|
|
190
175
|
*
|
|
191
176
|
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
192
177
|
* @see {PluginAddAdyenMethods} for source of applied plugin
|
|
@@ -195,7 +180,6 @@ it('it can apply multiple plugins to a single export', async () => {
|
|
|
195
180
|
export const PaymentMethodContextProvider = PluginAddMollieMethodsInterceptor"
|
|
196
181
|
`)
|
|
197
182
|
})
|
|
198
|
-
|
|
199
183
|
it('it handles on duplicates gracefully', async () => {
|
|
200
184
|
const resolve = resolveDependency(projectRoot)
|
|
201
185
|
const interceptors = await generateInterceptors(
|
|
@@ -219,7 +203,6 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
219
203
|
],
|
|
220
204
|
resolve,
|
|
221
205
|
)
|
|
222
|
-
|
|
223
206
|
const result =
|
|
224
207
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
225
208
|
?.template
|
|
@@ -236,7 +219,8 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
236
219
|
/**
|
|
237
220
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
238
221
|
*
|
|
239
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
222
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
223
|
+
* original source changes.
|
|
240
224
|
*
|
|
241
225
|
* @see {@link file://./PaymentMethodContext.tsx} for original source file
|
|
242
226
|
* @see {PluginAddBraintreeMethods} for source of applied plugin
|
|
@@ -244,7 +228,6 @@ it('it handles on duplicates gracefully', async () => {
|
|
|
244
228
|
export const PaymentMethodContextProvider = PluginAddBraintreeMethodsInterceptor"
|
|
245
229
|
`)
|
|
246
230
|
})
|
|
247
|
-
|
|
248
231
|
it('correctly renames all variable usages', async () => {
|
|
249
232
|
const resolve = resolveDependency(projectRoot)
|
|
250
233
|
const interceptors = await generateInterceptors(
|
|
@@ -260,17 +243,14 @@ it('correctly renames all variable usages', async () => {
|
|
|
260
243
|
],
|
|
261
244
|
resolve,
|
|
262
245
|
)
|
|
263
|
-
|
|
264
246
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
265
|
-
|
|
247
|
+
'"packages/magento-product/components/ProductListItem/ProductListItem"',
|
|
266
248
|
)
|
|
267
|
-
|
|
268
249
|
const template =
|
|
269
250
|
interceptors['packages/magento-product/components/ProductListItem/ProductListItem']?.template
|
|
270
251
|
expectOriginal(template).not.toContain('ProductListItem.selectors')
|
|
271
252
|
expectOriginal(template).toContain('ProductListItemOriginal.selectors')
|
|
272
253
|
})
|
|
273
|
-
|
|
274
254
|
it('it handles root plugins', async () => {
|
|
275
255
|
const resolve = resolveDependency(projectRoot)
|
|
276
256
|
const interceptors = await generateInterceptors(
|
|
@@ -286,15 +266,12 @@ it('it handles root plugins', async () => {
|
|
|
286
266
|
],
|
|
287
267
|
resolve,
|
|
288
268
|
)
|
|
289
|
-
|
|
290
269
|
expect(interceptors['packages/magento-product/index']?.template).toMatchInlineSnapshot(
|
|
291
|
-
|
|
270
|
+
'undefined',
|
|
292
271
|
)
|
|
293
272
|
})
|
|
294
|
-
|
|
295
273
|
it('it handles root plugins and creates a relative path', async () => {
|
|
296
274
|
const resolve = resolveDependency(projectRoot)
|
|
297
|
-
|
|
298
275
|
const interceptors = await generateInterceptors(
|
|
299
276
|
[
|
|
300
277
|
{
|
|
@@ -308,17 +285,14 @@ it('it handles root plugins and creates a relative path', async () => {
|
|
|
308
285
|
],
|
|
309
286
|
resolve,
|
|
310
287
|
)
|
|
311
|
-
|
|
312
288
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
313
|
-
|
|
289
|
+
'"packages/next-ui/Overlay/components/OverlayBase"',
|
|
314
290
|
)
|
|
315
|
-
|
|
316
291
|
expect(
|
|
317
292
|
interceptors['packages/next-ui/Overlay/components/OverlayBase'].targetExports.OverlayBase[0]
|
|
318
293
|
.sourceModule,
|
|
319
|
-
).toMatchInlineSnapshot(
|
|
294
|
+
).toMatchInlineSnapshot('"../../../../examples/magento-graphcms/plugins/EnableCrosssellsPlugin"')
|
|
320
295
|
})
|
|
321
|
-
|
|
322
296
|
it('generates method interceptors alognside component interceptors', async () => {
|
|
323
297
|
const resolve = resolveDependency(projectRoot)
|
|
324
298
|
const interceptors = await generateInterceptors(
|
|
@@ -345,25 +319,25 @@ it('generates method interceptors alognside component interceptors', async () =>
|
|
|
345
319
|
enabled: true,
|
|
346
320
|
sourceExport: 'Plugin',
|
|
347
321
|
targetModule: '@graphcommerce/graphql',
|
|
348
|
-
sourceModule: '@graphcommerce/magento-
|
|
322
|
+
sourceModule: '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache',
|
|
349
323
|
},
|
|
350
324
|
],
|
|
351
325
|
resolve,
|
|
352
326
|
)
|
|
353
|
-
|
|
354
|
-
|
|
327
|
+
expect(Object.keys(interceptors)).toMatchInlineSnapshot(
|
|
328
|
+
`
|
|
355
329
|
[
|
|
356
330
|
"packages/graphql/components/GraphQLProvider/GraphQLProvider",
|
|
357
331
|
"packages/graphql/config",
|
|
358
332
|
]
|
|
359
|
-
|
|
333
|
+
`,
|
|
334
|
+
)
|
|
360
335
|
expect(
|
|
361
336
|
interceptors['packages/graphql/components/GraphQLProvider/GraphQLProvider']?.template,
|
|
362
337
|
).toContain('MagentoGraphqlGraphqlProvider')
|
|
363
338
|
expect(interceptors['packages/graphql/config']?.template).toContain('magentoInitMemoryCache')
|
|
364
339
|
expect(interceptors['packages/graphql/config']?.template).toContain('hygraphInitMemoryCache')
|
|
365
340
|
})
|
|
366
|
-
|
|
367
341
|
it('adds debug logging to interceptors for components', async () => {
|
|
368
342
|
const resolve = resolveDependency(projectRoot)
|
|
369
343
|
const interceptors = await generateInterceptors(
|
|
@@ -390,23 +364,23 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
390
364
|
enabled: true,
|
|
391
365
|
sourceExport: 'plugin',
|
|
392
366
|
targetModule: '@graphcommerce/graphql',
|
|
393
|
-
sourceModule: '@graphcommerce/magento-
|
|
367
|
+
sourceModule: '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache',
|
|
394
368
|
},
|
|
395
369
|
],
|
|
396
370
|
resolve,
|
|
397
371
|
{ pluginStatus: true },
|
|
398
372
|
)
|
|
399
|
-
|
|
400
373
|
expectImport(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
401
|
-
"import { plugin as
|
|
402
|
-
import { plugin as
|
|
374
|
+
"import { plugin as pluginhygraphInitMemoryCache } from '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache'
|
|
375
|
+
import { plugin as pluginmagentoInitMemoryCache } from '@graphcommerce/magento-graphql/plugins/magentoInitMemoryCache'"
|
|
403
376
|
`)
|
|
404
|
-
|
|
405
377
|
expectOriginal(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
406
|
-
"import {
|
|
407
|
-
import type {
|
|
378
|
+
"import type { GraphCommerceStorefrontConfig } from '@graphcommerce/next-config'
|
|
379
|
+
import type { ApolloLink, TypePolicies } from '@apollo/client'
|
|
408
380
|
import type { SetRequired } from 'type-fest'
|
|
409
|
-
import { MigrateCache } from './components/GraphQLProvider/migrateCache'
|
|
381
|
+
import type { MigrateCache } from './components/GraphQLProvider/migrateCache'
|
|
382
|
+
import { RemovePrivateContextDirectivesLink } from './link/RemovePrivateContextDirectivesLink'
|
|
383
|
+
|
|
410
384
|
export interface PreviewData {}
|
|
411
385
|
export type PreviewConfig = {
|
|
412
386
|
preview?: boolean
|
|
@@ -426,14 +400,13 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
426
400
|
const { storefront, links = [], policies = [], migrations = [], ...rest } = config
|
|
427
401
|
return {
|
|
428
402
|
storefront,
|
|
429
|
-
links,
|
|
403
|
+
links: [...links, new RemovePrivateContextDirectivesLink()],
|
|
430
404
|
policies,
|
|
431
405
|
migrations,
|
|
432
406
|
...rest,
|
|
433
407
|
}
|
|
434
408
|
}"
|
|
435
409
|
`)
|
|
436
|
-
|
|
437
410
|
expectInterceptor(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
438
411
|
"const logged: Set<string> = new Set()
|
|
439
412
|
const logOnce = (log: string, ...additional: unknown[]) => {
|
|
@@ -460,7 +433,8 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
460
433
|
/**
|
|
461
434
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
462
435
|
*
|
|
463
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
436
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
437
|
+
* original source changes.
|
|
464
438
|
*
|
|
465
439
|
* @see {@link file://./config.ts} for original source file
|
|
466
440
|
* @see {pluginhygraphInitMemoryCache} for source of applied plugin
|
|
@@ -469,7 +443,6 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
469
443
|
export const graphqlConfig = pluginmagentoInitMemoryCacheInterceptor"
|
|
470
444
|
`)
|
|
471
445
|
})
|
|
472
|
-
|
|
473
446
|
it('correctly resolves when a source can not be parsed', async () => {
|
|
474
447
|
const resolve = resolveDependency(projectRoot)
|
|
475
448
|
const interceptors = await generateInterceptors(
|
|
@@ -486,12 +459,10 @@ it('correctly resolves when a source can not be parsed', async () => {
|
|
|
486
459
|
resolve,
|
|
487
460
|
{ pluginStatus: true },
|
|
488
461
|
)
|
|
489
|
-
|
|
490
462
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
491
|
-
|
|
463
|
+
'"packages/next-ui/Row/RowLinks/RowLinks"',
|
|
492
464
|
)
|
|
493
465
|
})
|
|
494
|
-
|
|
495
466
|
it('can correctly find the source for deeper chained exports', () => {
|
|
496
467
|
const resolve = resolveDependency(projectRoot)
|
|
497
468
|
const originalSource = findOriginalSource(
|
|
@@ -508,10 +479,9 @@ it('can correctly find the source for deeper chained exports', () => {
|
|
|
508
479
|
)
|
|
509
480
|
expect(originalSource.error).toBeUndefined()
|
|
510
481
|
expect(originalSource.resolved?.dependency).toMatchInlineSnapshot(
|
|
511
|
-
|
|
482
|
+
'"@graphcommerce/next-ui/Blog/BlogTags/BlogTag"',
|
|
512
483
|
)
|
|
513
484
|
})
|
|
514
|
-
|
|
515
485
|
it('Should apply overrides to the correct file', async () => {
|
|
516
486
|
const resolve = resolveDependency(projectRoot)
|
|
517
487
|
const interceptors = await generateInterceptors(
|
|
@@ -527,28 +497,23 @@ it('Should apply overrides to the correct file', async () => {
|
|
|
527
497
|
],
|
|
528
498
|
resolve,
|
|
529
499
|
)
|
|
530
|
-
|
|
531
500
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
532
|
-
|
|
501
|
+
'"packages/magento-product/components/ProductStaticPaths/getProductStaticPaths"',
|
|
533
502
|
)
|
|
534
|
-
|
|
535
503
|
const result =
|
|
536
504
|
interceptors['packages/magento-product/components/ProductStaticPaths/getProductStaticPaths']
|
|
537
505
|
?.template
|
|
538
|
-
|
|
539
|
-
|
|
506
|
+
expect(result).toContain(
|
|
507
|
+
"import { getProductStaticPaths as getProductStaticPathsreplaceGetProductStaticPaths } from '../../../../plugins/replaceGetProductStaticPaths'",
|
|
540
508
|
)
|
|
541
|
-
|
|
542
|
-
expectOriginal(result).toContain(`getProductStaticPathsDisabled`)
|
|
509
|
+
expectOriginal(result).toContain('getProductStaticPathsDisabled')
|
|
543
510
|
})
|
|
544
|
-
|
|
545
511
|
it('correctly reports an error for an incorrect export', async () => {
|
|
546
512
|
const fakeconfig = {
|
|
547
513
|
googleRecaptchaKey: '123',
|
|
548
514
|
googleAnalyticsId: '123',
|
|
549
515
|
demoMode: true,
|
|
550
|
-
} as GraphCommerceConfig
|
|
551
|
-
|
|
516
|
+
} as unknown as GraphCommerceConfig
|
|
552
517
|
const src = `
|
|
553
518
|
import { getSitemapPaths as getSitemapPathsType } from '@graphcommerce/magento-product'
|
|
554
519
|
import { IfConfig, FunctionPlugin } from '@graphcommerce/next-config'
|
|
@@ -562,21 +527,15 @@ export const plugin: FunctionPlugin<typeof getSitemapPathsType> = (prev, ...args
|
|
|
562
527
|
return prev(...args)
|
|
563
528
|
}
|
|
564
529
|
`
|
|
565
|
-
|
|
566
530
|
console.error = jest.fn()
|
|
567
531
|
const plugins = parseStructure(parseSync(src), fakeconfig, './plugins/MyPlugin.tsx')
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
expect(console.error.mock.calls[0][0]).toMatchInlineSnapshot(
|
|
571
|
-
`"Plugin configuration invalid! See ./plugins/MyPlugin.tsx"`,
|
|
532
|
+
expect((console.error as jest.Mock).mock.calls[0][0]).toMatchInlineSnapshot(
|
|
533
|
+
'"Plugin configuration invalid! See ./plugins/MyPlugin.tsx"',
|
|
572
534
|
)
|
|
573
|
-
|
|
574
|
-
expect(plugins).toMatchInlineSnapshot(`[]`)
|
|
535
|
+
expect(plugins).toMatchInlineSnapshot('[]')
|
|
575
536
|
const result = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
576
|
-
|
|
577
|
-
expect(Object.keys(result)).toMatchInlineSnapshot(`[]`)
|
|
537
|
+
expect(Object.keys(result)).toMatchInlineSnapshot('[]')
|
|
578
538
|
})
|
|
579
|
-
|
|
580
539
|
it('generated a correct file if a replacement and a plugin is applied to the same export', async () => {
|
|
581
540
|
const src1 = `import { ProductPageNameProps } from '@graphcommerce/magento-product'
|
|
582
541
|
import { PluginConfig } from '@graphcommerce/next-config'
|
|
@@ -592,7 +551,6 @@ export function ProductPageName(props: ProductPageNameProps) {
|
|
|
592
551
|
return <div>Complete overrides {product.url_key}</div>
|
|
593
552
|
}
|
|
594
553
|
`
|
|
595
|
-
|
|
596
554
|
const src2 = `import type { AddToCartItemSelector, ProductPageNameProps } from '@graphcommerce/magento-product'
|
|
597
555
|
import type { IfConfig, PluginProps } from '@graphcommerce/next-config'
|
|
598
556
|
import { useConfigurableSelectedVariant } from '../../hooks'
|
|
@@ -611,24 +569,20 @@ const ConfigurableProductPageName = (
|
|
|
611
569
|
|
|
612
570
|
export const Plugin = ConfigurableProductPageName
|
|
613
571
|
`
|
|
614
|
-
|
|
615
572
|
const config = {
|
|
616
573
|
demoMode: true,
|
|
617
574
|
configurableVariantForSimple: true,
|
|
618
575
|
configurableVariantValues: { content: true, gallery: true, url: true },
|
|
619
|
-
} as GraphCommerceConfig
|
|
620
|
-
|
|
576
|
+
} as unknown as GraphCommerceConfig
|
|
621
577
|
const firstFile = parseStructure(parseSync(src1), config, './plugins/MyPlugin')
|
|
622
|
-
|
|
623
578
|
const secondFile = parseStructure(
|
|
624
579
|
parseSync(src2),
|
|
625
580
|
config,
|
|
626
581
|
'@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName',
|
|
627
582
|
)
|
|
628
|
-
|
|
629
583
|
const plugins = [...firstFile, ...secondFile]
|
|
630
|
-
|
|
631
|
-
|
|
584
|
+
expect(plugins).toMatchInlineSnapshot(
|
|
585
|
+
`
|
|
632
586
|
[
|
|
633
587
|
{
|
|
634
588
|
"enabled": true,
|
|
@@ -649,35 +603,30 @@ export const Plugin = ConfigurableProductPageName
|
|
|
649
603
|
"type": "component",
|
|
650
604
|
},
|
|
651
605
|
]
|
|
652
|
-
|
|
653
|
-
|
|
606
|
+
`,
|
|
607
|
+
)
|
|
654
608
|
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
655
|
-
|
|
656
609
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
657
|
-
|
|
610
|
+
'"packages/magento-product/components/ProductPageName/ProductPageName"',
|
|
658
611
|
)
|
|
659
|
-
|
|
660
612
|
const result =
|
|
661
613
|
interceptors['packages/magento-product/components/ProductPageName/ProductPageName']?.template
|
|
662
|
-
|
|
663
614
|
expectImport(result).toMatchInlineSnapshot(`
|
|
664
|
-
"import
|
|
665
|
-
|
|
666
|
-
import { Plugin as PluginConfigurableProductPageName } from '@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName'
|
|
615
|
+
"import { Plugin as PluginConfigurableProductPageName } from '@graphcommerce/magento-product-configurable/plugins/ConfigurableProductPage/ConfigurableProductPageName'
|
|
616
|
+
import type { DistributedOmit as OmitPrev } from 'type-fest'
|
|
667
617
|
import { ProductPageName as ProductPageNameMyPlugin } from '../../../../plugins/MyPlugin'"
|
|
668
618
|
`)
|
|
669
|
-
|
|
670
619
|
expectOriginal(result).toMatchInlineSnapshot(`
|
|
671
|
-
"import { ProductPageNameFragment } from './ProductPageName.gql'
|
|
620
|
+
"import type { ProductPageNameFragment } from './ProductPageName.gql'
|
|
621
|
+
|
|
672
622
|
export type ProductPageNameProps = {
|
|
673
623
|
product: ProductPageNameFragment
|
|
674
624
|
}
|
|
675
|
-
export
|
|
625
|
+
export function ProductPageNameDisabled(props: ProductPageNameProps) {
|
|
676
626
|
const { product } = props
|
|
677
627
|
return <>{product.name}</>
|
|
678
628
|
}"
|
|
679
629
|
`)
|
|
680
|
-
|
|
681
630
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
682
631
|
"type PluginConfigurableProductPageNameProps = React.ComponentProps<typeof ProductPageNameMyPlugin> &
|
|
683
632
|
OmitPrev<React.ComponentProps<typeof PluginConfigurableProductPageName>, 'Prev'>
|
|
@@ -689,7 +638,8 @@ export const Plugin = ConfigurableProductPageName
|
|
|
689
638
|
/**
|
|
690
639
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
691
640
|
*
|
|
692
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
641
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
642
|
+
* original source changes.
|
|
693
643
|
*
|
|
694
644
|
* @see {@link file://./ProductPageName.tsx} for original source file
|
|
695
645
|
* @see {ProductPageNameMyPlugin} for replacement of the original source (original source not used)
|
|
@@ -698,7 +648,6 @@ export const Plugin = ConfigurableProductPageName
|
|
|
698
648
|
export const ProductPageName = PluginConfigurableProductPageNameInterceptor"
|
|
699
649
|
`)
|
|
700
650
|
})
|
|
701
|
-
|
|
702
651
|
it('generates to a .ts file when the target file is a .ts as well', async () => {
|
|
703
652
|
const resolve = resolveDependency(projectRoot)
|
|
704
653
|
const interceptors = await generateInterceptors(
|
|
@@ -714,14 +663,11 @@ it('generates to a .ts file when the target file is a .ts as well', async () =>
|
|
|
714
663
|
],
|
|
715
664
|
resolve,
|
|
716
665
|
)
|
|
717
|
-
|
|
718
|
-
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(`"packages/graphql/config"`)
|
|
666
|
+
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot('"packages/graphql/config"')
|
|
719
667
|
const interceptor = interceptors['packages/graphql/config']
|
|
720
|
-
expect(interceptor.sourcePath).toBe(
|
|
668
|
+
expect(interceptor.sourcePath).toBe('packages/graphql/config.ts')
|
|
721
669
|
})
|
|
722
|
-
|
|
723
670
|
it.todo('Should report an error when multiple files are overriding the same export')
|
|
724
|
-
|
|
725
671
|
it('Can correctly find exports that are default exports', async () => {
|
|
726
672
|
const pluginSource = `
|
|
727
673
|
import { PluginConfig } from '@graphcommerce/next-config'
|
|
@@ -737,33 +683,29 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
737
683
|
export const iconChevronLeft = accessibilityHuman
|
|
738
684
|
export const iconChevronRight = alarm
|
|
739
685
|
`
|
|
740
|
-
|
|
741
686
|
const config = {
|
|
742
687
|
demoMode: true,
|
|
743
688
|
configurableVariantForSimple: true,
|
|
744
689
|
configurableVariantValues: { content: true, gallery: true, url: true },
|
|
745
|
-
} as GraphCommerceConfig
|
|
746
|
-
|
|
690
|
+
} as unknown as GraphCommerceConfig
|
|
747
691
|
const plugins = parseStructure(parseSync(pluginSource), config, './plugins/MyProjectIcon')
|
|
748
|
-
|
|
749
692
|
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
750
|
-
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
751
|
-
|
|
693
|
+
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot('"packages/next-ui/icons"')
|
|
752
694
|
const result = interceptors['packages/next-ui/icons']?.template
|
|
753
|
-
|
|
754
695
|
expectImport(result).toMatchInlineSnapshot(`
|
|
755
|
-
"import {
|
|
756
|
-
|
|
696
|
+
"import {
|
|
697
|
+
iconChevronLeft as iconChevronLeftMyProjectIcon,
|
|
698
|
+
iconChevronRight as iconChevronRightMyProjectIcon,
|
|
699
|
+
} from '../../plugins/MyProjectIcon'"
|
|
757
700
|
`)
|
|
758
|
-
|
|
759
701
|
expectOriginal(result).toContain('iconChevronLeftDisabled')
|
|
760
702
|
expectOriginal(result).toContain('iconChevronRightDisabled')
|
|
761
|
-
|
|
762
703
|
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
763
704
|
"/**
|
|
764
705
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
765
706
|
*
|
|
766
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
707
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
708
|
+
* original source changes.
|
|
767
709
|
*
|
|
768
710
|
* @see {@link file://./icons.ts} for original source file
|
|
769
711
|
* @see {iconChevronLeftMyProjectIcon} for replacement of the original source (original source not used)
|
|
@@ -773,7 +715,8 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
773
715
|
/**
|
|
774
716
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
775
717
|
*
|
|
776
|
-
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
718
|
+
* This file is NOT meant to be modified directly and is auto-generated if the plugins or the
|
|
719
|
+
* original source changes.
|
|
777
720
|
*
|
|
778
721
|
* @see {@link file://./icons.ts} for original source file
|
|
779
722
|
* @see {iconChevronRightMyProjectIcon} for replacement of the original source (original source not used)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphCommerceConfig } from '../../src/generated/config'
|
|
1
|
+
import type { GraphCommerceConfig } from '../../src/generated/config'
|
|
2
2
|
import { parseStructure } from '../../src/interceptors/parseStructure'
|
|
3
3
|
import { parseSync } from '../../src/interceptors/swc'
|
|
4
4
|
|
|
@@ -204,7 +204,7 @@ export const Plugin = AddAdyenMethods
|
|
|
204
204
|
"type": "component",
|
|
205
205
|
}
|
|
206
206
|
`)
|
|
207
|
-
expect(plugins[1]).toMatchInlineSnapshot(
|
|
207
|
+
expect(plugins[1]).toMatchInlineSnapshot('undefined')
|
|
208
208
|
})
|
|
209
209
|
|
|
210
210
|
it('correctly allows false value in the ifConfig', () => {
|
|
@@ -1,22 +1,21 @@
|
|
|
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",
|
|
18
17
|
"@graphcommerce/hygraph-dynamic-rows" => "packages/hygraph-dynamic-rows",
|
|
19
|
-
"@graphcommerce/
|
|
18
|
+
"@graphcommerce/hygraph-ui" => "packages/hygraph-ui",
|
|
20
19
|
"@graphcommerce/magento-cart-billing-address" => "packages/magento-cart-billing-address",
|
|
21
20
|
"@graphcommerce/magento-cart-checkout" => "packages/magento-cart-checkout",
|
|
22
21
|
"@graphcommerce/magento-cart-coupon" => "packages/magento-cart-coupon",
|
|
@@ -32,6 +31,7 @@ it('resolves dependences', () => {
|
|
|
32
31
|
"@graphcommerce/magento-product-virtual" => "packages/magento-product-virtual",
|
|
33
32
|
"@graphcommerce/magento-review" => "packages/magento-review",
|
|
34
33
|
"@graphcommerce/magento-wishlist" => "packages/magento-wishlist",
|
|
34
|
+
"@graphcommerce/service-worker" => "packages/service-worker",
|
|
35
35
|
"@graphcommerce/magento-cart-pickup" => "packages/magento-cart-pickup",
|
|
36
36
|
"@graphcommerce/magento-payment-braintree" => "packages/magento-payment-braintree",
|
|
37
37
|
"@graphcommerce/mollie-magento-payment" => "packages/mollie-magento-payment",
|
|
@@ -72,9 +72,9 @@ it('resolves dependences', () => {
|
|
|
72
72
|
"@graphcommerce/eslint-config-pwa" => "packagesDev/eslint-config",
|
|
73
73
|
"@graphcommerce/typescript-config-pwa" => "packagesDev/typescript-config",
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
`,
|
|
76
|
+
)
|
|
76
77
|
})
|
|
77
|
-
|
|
78
78
|
it('sorts dependencies', () => {
|
|
79
79
|
const sorted = sortDependencies({
|
|
80
80
|
'@graphcommerce/magento-graphcms': {
|
|
@@ -94,13 +94,14 @@ it('sorts dependencies', () => {
|
|
|
94
94
|
dependencies: ['@graphcommerce/magento-product'],
|
|
95
95
|
},
|
|
96
96
|
})
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
expect(sorted).toMatchInlineSnapshot(
|
|
98
|
+
`
|
|
99
99
|
Map {
|
|
100
100
|
"@graphcommerce/magento-graphcms" => "examples/magento-graphcms",
|
|
101
101
|
"@graphcommerce/magento-cart" => "packages/magento-cart",
|
|
102
102
|
"@graphcommerce/magento-product" => "packages/magento-product",
|
|
103
103
|
"@graphcommerce/magento-product-simple" => "packages/magento-product-simple",
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
`,
|
|
106
|
+
)
|
|
106
107
|
})
|