@graphcommerce/next-config 9.0.0-canary.100 → 9.0.0-canary.103
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 +85 -1195
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +5 -3
- package/__tests__/config/utils/rewriteLegancyEnv.ts +2 -1
- package/__tests__/interceptors/findPlugins.ts +14 -6
- package/__tests__/interceptors/generateInterceptors.ts +29 -29
- package/__tests__/interceptors/parseStructure.ts +2 -2
- package/__tests__/utils/resolveDependenciesSync.ts +1 -1
- package/dist/config/commands/exportConfig.js +1 -1
- package/dist/config/utils/mergeEnvIntoConfig.js +6 -6
- package/dist/config/utils/rewriteLegacyEnv.js +2 -2
- package/dist/interceptors/InterceptorPlugin.js +3 -3
- package/dist/interceptors/Visitor.js +0 -1
- package/dist/interceptors/commands/codegenInterceptors.js +2 -2
- package/dist/interceptors/findOriginalSource.js +2 -1
- package/dist/interceptors/findPlugins.js +5 -8
- package/dist/interceptors/generateInterceptor.js +5 -5
- package/dist/interceptors/generateInterceptors.js +2 -2
- package/dist/interceptors/parseStructure.js +1 -1
- package/dist/utils/resolveDependenciesSync.js +3 -1
- package/package.json +15 -13
- package/src/config/commands/exportConfig.ts +1 -1
- package/src/config/demoConfig.ts +2 -2
- package/src/config/index.ts +1 -1
- package/src/config/utils/exportConfigToEnv.ts +1 -1
- package/src/config/utils/mergeEnvIntoConfig.ts +7 -9
- package/src/config/utils/replaceConfigInString.ts +1 -1
- package/src/config/utils/rewriteLegacyEnv.ts +5 -4
- package/src/generated/config.ts +2 -0
- package/src/index.ts +2 -1
- package/src/interceptors/InterceptorPlugin.ts +9 -7
- package/src/interceptors/RenameVisitor.ts +1 -1
- package/src/interceptors/Visitor.ts +1 -2
- package/src/interceptors/commands/codegenInterceptors.ts +2 -2
- package/src/interceptors/extractExports.ts +1 -0
- package/src/interceptors/findOriginalSource.ts +5 -4
- package/src/interceptors/findPlugins.ts +8 -9
- package/src/interceptors/generateInterceptor.ts +8 -7
- package/src/interceptors/generateInterceptors.ts +6 -12
- package/src/interceptors/parseStructure.ts +4 -4
- package/src/interceptors/swc.ts +2 -1
- package/src/interceptors/writeInterceptors.ts +1 -1
- package/src/utils/packageRoots.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +4 -1
- package/src/withGraphCommerce.ts +4 -3
|
@@ -3,7 +3,8 @@ import {
|
|
|
3
3
|
formatAppliedEnv,
|
|
4
4
|
mergeEnvIntoConfig,
|
|
5
5
|
} from '../../../src/config/utils/mergeEnvIntoConfig'
|
|
6
|
-
import { GraphCommerceConfig
|
|
6
|
+
import type { GraphCommerceConfig } from '../../../src/generated/config'
|
|
7
|
+
import { GraphCommerceConfigSchema } from '../../../src/generated/config'
|
|
7
8
|
import { removeColor } from './rewriteLegancyEnv'
|
|
8
9
|
|
|
9
10
|
const env = {
|
|
@@ -17,7 +18,8 @@ const env = {
|
|
|
17
18
|
GC_STOREFRONT_1_LOCALE: 'de',
|
|
18
19
|
GC_STOREFRONT_1_HYGRAPH_LOCALES_0: 'de',
|
|
19
20
|
GC_STOREFRONT_1_MAGENTO_STORE_CODE: 'de_de',
|
|
20
|
-
GC_STOREFRONT:
|
|
21
|
+
GC_STOREFRONT:
|
|
22
|
+
'[{"locale": "en", "defaultLocale": true, "hygraphLocales": ["en"], "magentoStoreCode": "en_us"}]',
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
it('traverses a schema and returns a list of env variables that match', () => {
|
|
@@ -93,7 +95,7 @@ it('converts an env schema to a config schema', () => {
|
|
|
93
95
|
|
|
94
96
|
const environmentVariables = {
|
|
95
97
|
GC_PRODUCT_FILTERS_PRO: '1',
|
|
96
|
-
GC_STOREFRONT:
|
|
98
|
+
GC_STOREFRONT: '[{"defaultLocale": true }]',
|
|
97
99
|
GC_STOREFRONT_0_LOCALE: 'de',
|
|
98
100
|
}
|
|
99
101
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { formatAppliedEnv } from '../../../src/config/utils/mergeEnvIntoConfig'
|
|
2
2
|
import { rewriteLegacyEnv } from '../../../src/config/utils/rewriteLegacyEnv'
|
|
3
|
-
import { GraphCommerceConfig
|
|
3
|
+
import type { GraphCommerceConfig } from '../../../src/generated/config'
|
|
4
|
+
import { GraphCommerceConfigSchema } from '../../../src/generated/config'
|
|
4
5
|
|
|
5
6
|
export const removeColor = (str: string) =>
|
|
6
7
|
str.replace(
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphCommerceConfig } from '../../src/generated/config'
|
|
1
|
+
import type { GraphCommerceConfig } from '../../src/generated/config'
|
|
2
2
|
import { findPlugins } from '../../src/interceptors/findPlugins'
|
|
3
3
|
|
|
4
4
|
const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
@@ -17,7 +17,7 @@ it('finds plugins', () => {
|
|
|
17
17
|
const disabled = plugins.filter((p) => !p.enabled)
|
|
18
18
|
const enabled = plugins.filter((p) => p.enabled)
|
|
19
19
|
|
|
20
|
-
expect(errors).toMatchInlineSnapshot(
|
|
20
|
+
expect(errors).toMatchInlineSnapshot('[]')
|
|
21
21
|
|
|
22
22
|
expect(enabled).toMatchInlineSnapshot(`
|
|
23
23
|
[
|
|
@@ -80,13 +80,13 @@ it('finds plugins', () => {
|
|
|
80
80
|
"sourceExport": "hygraphPageContent",
|
|
81
81
|
"sourceModule": "@graphcommerce/hygraph-dynamic-rows/plugins/hygraphDynamicRowsPageContent",
|
|
82
82
|
"targetExport": "hygraphPageContent",
|
|
83
|
-
"targetModule": "@graphcommerce/
|
|
83
|
+
"targetModule": "@graphcommerce/hygraph-ui",
|
|
84
84
|
"type": "function",
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
87
|
"enabled": true,
|
|
88
88
|
"sourceExport": "previewModeDefaults",
|
|
89
|
-
"sourceModule": "@graphcommerce/
|
|
89
|
+
"sourceModule": "@graphcommerce/hygraph-ui/plugins/hygraphPreviewModeDefaults",
|
|
90
90
|
"targetExport": "previewModeDefaults",
|
|
91
91
|
"targetModule": "@graphcommerce/ecommerce-ui",
|
|
92
92
|
"type": "function",
|
|
@@ -94,7 +94,7 @@ it('finds plugins', () => {
|
|
|
94
94
|
{
|
|
95
95
|
"enabled": true,
|
|
96
96
|
"sourceExport": "graphqlConfig",
|
|
97
|
-
"sourceModule": "@graphcommerce/
|
|
97
|
+
"sourceModule": "@graphcommerce/hygraph-ui/plugins/hygraphGraphqlConfig",
|
|
98
98
|
"targetExport": "graphqlConfig",
|
|
99
99
|
"targetModule": "@graphcommerce/graphql",
|
|
100
100
|
"type": "function",
|
|
@@ -102,7 +102,7 @@ it('finds plugins', () => {
|
|
|
102
102
|
{
|
|
103
103
|
"enabled": true,
|
|
104
104
|
"sourceExport": "PreviewModeToolbar",
|
|
105
|
-
"sourceModule": "@graphcommerce/
|
|
105
|
+
"sourceModule": "@graphcommerce/hygraph-ui/plugins/HygraphPreviewModeToolbar",
|
|
106
106
|
"targetExport": "PreviewModeToolbar",
|
|
107
107
|
"targetModule": "@graphcommerce/ecommerce-ui",
|
|
108
108
|
"type": "component",
|
|
@@ -459,6 +459,14 @@ it('finds plugins', () => {
|
|
|
459
459
|
"targetModule": "@graphcommerce/graphql",
|
|
460
460
|
"type": "component",
|
|
461
461
|
},
|
|
462
|
+
{
|
|
463
|
+
"enabled": true,
|
|
464
|
+
"sourceExport": "graphqlConfig",
|
|
465
|
+
"sourceModule": "@graphcommerce/magento-customer/plugins/magentoCustomerRemoveInContextDirective",
|
|
466
|
+
"targetExport": "graphqlConfig",
|
|
467
|
+
"targetModule": "@graphcommerce/graphql",
|
|
468
|
+
"type": "function",
|
|
469
|
+
},
|
|
462
470
|
{
|
|
463
471
|
"enabled": true,
|
|
464
472
|
"sourceExport": "getInContextInput",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphCommerceConfig } from '../../src/generated/config'
|
|
1
|
+
import type { GraphCommerceConfig } from '../../src/generated/config'
|
|
2
2
|
import { findOriginalSource } from '../../src/interceptors/findOriginalSource'
|
|
3
3
|
import { SOURCE_START, SOURCE_END } from '../../src/interceptors/generateInterceptor'
|
|
4
4
|
import { generateInterceptors } from '../../src/interceptors/generateInterceptors'
|
|
@@ -11,7 +11,7 @@ const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
|
11
11
|
const startLocation = '/** @see {@link file://'
|
|
12
12
|
|
|
13
13
|
const expectImport = (value: string | undefined): jest.JestMatchers<string> =>
|
|
14
|
-
expect(value?.slice(value.indexOf(
|
|
14
|
+
expect(value?.slice(value.indexOf('import') - 1, value.indexOf(startLocation) - 1).trim())
|
|
15
15
|
|
|
16
16
|
const expectInterceptor = (value: string | undefined): jest.JestMatchers<string> => {
|
|
17
17
|
const val = value?.slice(value.indexOf(SOURCE_END) + SOURCE_END.length).trim()
|
|
@@ -28,7 +28,7 @@ const expectOriginal = (value: string | undefined): jest.JestMatchers<string> =>
|
|
|
28
28
|
it('it replaces paths and creates a relative path', () => {
|
|
29
29
|
const resolver = resolveDependency(projectRoot)
|
|
30
30
|
const resolved = resolver('@graphcommerce/magento-cart-payment-method')
|
|
31
|
-
expect(resolved?.fromRoot).toMatchInlineSnapshot(
|
|
31
|
+
expect(resolved?.fromRoot).toMatchInlineSnapshot('"packages/magento-cart-payment-method/index"')
|
|
32
32
|
expect(resolved?.fromModule).toBe('.')
|
|
33
33
|
expect(resolved?.root).toBe('packages/magento-cart-payment-method')
|
|
34
34
|
|
|
@@ -36,7 +36,7 @@ it('it replaces paths and creates a relative path', () => {
|
|
|
36
36
|
'@graphcommerce/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext',
|
|
37
37
|
)
|
|
38
38
|
expect(resolved2?.fromRoot).toMatchInlineSnapshot(
|
|
39
|
-
|
|
39
|
+
'"packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext"',
|
|
40
40
|
)
|
|
41
41
|
expect(resolved2?.fromModule).toBe('./PaymentMethodContext')
|
|
42
42
|
expect(resolved2?.root).toBe('packages/magento-cart-payment-method')
|
|
@@ -119,7 +119,7 @@ it("resolves a 'root plugin' to be relative to the interceptor", async () => {
|
|
|
119
119
|
)
|
|
120
120
|
|
|
121
121
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
122
|
-
|
|
122
|
+
'"packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext"',
|
|
123
123
|
)
|
|
124
124
|
expectImport(
|
|
125
125
|
interceptors['packages/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext']
|
|
@@ -262,7 +262,7 @@ it('correctly renames all variable usages', async () => {
|
|
|
262
262
|
)
|
|
263
263
|
|
|
264
264
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
265
|
-
|
|
265
|
+
'"packages/magento-product/components/ProductListItem/ProductListItem"',
|
|
266
266
|
)
|
|
267
267
|
|
|
268
268
|
const template =
|
|
@@ -288,7 +288,7 @@ it('it handles root plugins', async () => {
|
|
|
288
288
|
)
|
|
289
289
|
|
|
290
290
|
expect(interceptors['packages/magento-product/index']?.template).toMatchInlineSnapshot(
|
|
291
|
-
|
|
291
|
+
'undefined',
|
|
292
292
|
)
|
|
293
293
|
})
|
|
294
294
|
|
|
@@ -310,13 +310,13 @@ it('it handles root plugins and creates a relative path', async () => {
|
|
|
310
310
|
)
|
|
311
311
|
|
|
312
312
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
313
|
-
|
|
313
|
+
'"packages/next-ui/Overlay/components/OverlayBase"',
|
|
314
314
|
)
|
|
315
315
|
|
|
316
316
|
expect(
|
|
317
317
|
interceptors['packages/next-ui/Overlay/components/OverlayBase'].targetExports.OverlayBase[0]
|
|
318
318
|
.sourceModule,
|
|
319
|
-
).toMatchInlineSnapshot(
|
|
319
|
+
).toMatchInlineSnapshot('"../../../../examples/magento-graphcms/plugins/EnableCrosssellsPlugin"')
|
|
320
320
|
})
|
|
321
321
|
|
|
322
322
|
it('generates method interceptors alognside component interceptors', async () => {
|
|
@@ -345,7 +345,7 @@ it('generates method interceptors alognside component interceptors', async () =>
|
|
|
345
345
|
enabled: true,
|
|
346
346
|
sourceExport: 'Plugin',
|
|
347
347
|
targetModule: '@graphcommerce/graphql',
|
|
348
|
-
sourceModule: '@graphcommerce/magento-
|
|
348
|
+
sourceModule: '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache',
|
|
349
349
|
},
|
|
350
350
|
],
|
|
351
351
|
resolve,
|
|
@@ -390,7 +390,7 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
390
390
|
enabled: true,
|
|
391
391
|
sourceExport: 'plugin',
|
|
392
392
|
targetModule: '@graphcommerce/graphql',
|
|
393
|
-
sourceModule: '@graphcommerce/magento-
|
|
393
|
+
sourceModule: '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache',
|
|
394
394
|
},
|
|
395
395
|
],
|
|
396
396
|
resolve,
|
|
@@ -398,15 +398,15 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
398
398
|
)
|
|
399
399
|
|
|
400
400
|
expectImport(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
401
|
-
"import { plugin as
|
|
402
|
-
import { plugin as
|
|
401
|
+
"import { plugin as pluginhygraphInitMemoryCache } from '@graphcommerce/magento-graphcms/plugins/hygraphInitMemoryCache'
|
|
402
|
+
import { plugin as pluginmagentoInitMemoryCache } from '@graphcommerce/magento-graphql/plugins/magentoInitMemoryCache'"
|
|
403
403
|
`)
|
|
404
404
|
|
|
405
405
|
expectOriginal(interceptors['packages/graphql/config']?.template).toMatchInlineSnapshot(`
|
|
406
|
-
"import { ApolloLink, TypePolicies } from '@apollo/client'
|
|
406
|
+
"import type { ApolloLink, TypePolicies } from '@apollo/client'
|
|
407
407
|
import type { GraphCommerceStorefrontConfig } from '@graphcommerce/next-config'
|
|
408
408
|
import type { SetRequired } from 'type-fest'
|
|
409
|
-
import { MigrateCache } from './components/GraphQLProvider/migrateCache'
|
|
409
|
+
import type { MigrateCache } from './components/GraphQLProvider/migrateCache'
|
|
410
410
|
export interface PreviewData {}
|
|
411
411
|
export type PreviewConfig = {
|
|
412
412
|
preview?: boolean
|
|
@@ -488,7 +488,7 @@ it('correctly resolves when a source can not be parsed', async () => {
|
|
|
488
488
|
)
|
|
489
489
|
|
|
490
490
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
491
|
-
|
|
491
|
+
'"packages/next-ui/Row/RowLinks/RowLinks"',
|
|
492
492
|
)
|
|
493
493
|
})
|
|
494
494
|
|
|
@@ -508,7 +508,7 @@ it('can correctly find the source for deeper chained exports', () => {
|
|
|
508
508
|
)
|
|
509
509
|
expect(originalSource.error).toBeUndefined()
|
|
510
510
|
expect(originalSource.resolved?.dependency).toMatchInlineSnapshot(
|
|
511
|
-
|
|
511
|
+
'"@graphcommerce/next-ui/Blog/BlogTags/BlogTag"',
|
|
512
512
|
)
|
|
513
513
|
})
|
|
514
514
|
|
|
@@ -529,17 +529,17 @@ it('Should apply overrides to the correct file', async () => {
|
|
|
529
529
|
)
|
|
530
530
|
|
|
531
531
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
532
|
-
|
|
532
|
+
'"packages/magento-product/components/ProductStaticPaths/getProductStaticPaths"',
|
|
533
533
|
)
|
|
534
534
|
|
|
535
535
|
const result =
|
|
536
536
|
interceptors['packages/magento-product/components/ProductStaticPaths/getProductStaticPaths']
|
|
537
537
|
?.template
|
|
538
538
|
expectImport(result).toMatchInlineSnapshot(
|
|
539
|
-
|
|
539
|
+
'"import { getProductStaticPaths as getProductStaticPathsreplaceGetProductStaticPaths } from \'../../../../plugins/replaceGetProductStaticPaths\'"',
|
|
540
540
|
)
|
|
541
541
|
|
|
542
|
-
expectOriginal(result).toContain(
|
|
542
|
+
expectOriginal(result).toContain('getProductStaticPathsDisabled')
|
|
543
543
|
})
|
|
544
544
|
|
|
545
545
|
it('correctly reports an error for an incorrect export', async () => {
|
|
@@ -568,13 +568,13 @@ export const plugin: FunctionPlugin<typeof getSitemapPathsType> = (prev, ...args
|
|
|
568
568
|
|
|
569
569
|
// @ts-expect-error mock not typed
|
|
570
570
|
expect(console.error.mock.calls[0][0]).toMatchInlineSnapshot(
|
|
571
|
-
|
|
571
|
+
'"Plugin configuration invalid! See ./plugins/MyPlugin.tsx"',
|
|
572
572
|
)
|
|
573
573
|
|
|
574
|
-
expect(plugins).toMatchInlineSnapshot(
|
|
574
|
+
expect(plugins).toMatchInlineSnapshot('[]')
|
|
575
575
|
const result = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
576
576
|
|
|
577
|
-
expect(Object.keys(result)).toMatchInlineSnapshot(
|
|
577
|
+
expect(Object.keys(result)).toMatchInlineSnapshot('[]')
|
|
578
578
|
})
|
|
579
579
|
|
|
580
580
|
it('generated a correct file if a replacement and a plugin is applied to the same export', async () => {
|
|
@@ -654,7 +654,7 @@ export const Plugin = ConfigurableProductPageName
|
|
|
654
654
|
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
655
655
|
|
|
656
656
|
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
657
|
-
|
|
657
|
+
'"packages/magento-product/components/ProductPageName/ProductPageName"',
|
|
658
658
|
)
|
|
659
659
|
|
|
660
660
|
const result =
|
|
@@ -668,11 +668,11 @@ export const Plugin = ConfigurableProductPageName
|
|
|
668
668
|
`)
|
|
669
669
|
|
|
670
670
|
expectOriginal(result).toMatchInlineSnapshot(`
|
|
671
|
-
"import { ProductPageNameFragment } from './ProductPageName.gql'
|
|
671
|
+
"import type { ProductPageNameFragment } from './ProductPageName.gql'
|
|
672
672
|
export type ProductPageNameProps = {
|
|
673
673
|
product: ProductPageNameFragment
|
|
674
674
|
}
|
|
675
|
-
export
|
|
675
|
+
export function ProductPageNameDisabled(props: ProductPageNameProps) {
|
|
676
676
|
const { product } = props
|
|
677
677
|
return <>{product.name}</>
|
|
678
678
|
}"
|
|
@@ -715,9 +715,9 @@ it('generates to a .ts file when the target file is a .ts as well', async () =>
|
|
|
715
715
|
resolve,
|
|
716
716
|
)
|
|
717
717
|
|
|
718
|
-
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
718
|
+
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot('"packages/graphql/config"')
|
|
719
719
|
const interceptor = interceptors['packages/graphql/config']
|
|
720
|
-
expect(interceptor.sourcePath).toBe(
|
|
720
|
+
expect(interceptor.sourcePath).toBe('packages/graphql/config.ts')
|
|
721
721
|
})
|
|
722
722
|
|
|
723
723
|
it.todo('Should report an error when multiple files are overriding the same export')
|
|
@@ -747,7 +747,7 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
747
747
|
const plugins = parseStructure(parseSync(pluginSource), config, './plugins/MyProjectIcon')
|
|
748
748
|
|
|
749
749
|
const interceptors = await generateInterceptors(plugins, resolveDependency(projectRoot))
|
|
750
|
-
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot(
|
|
750
|
+
expect(Object.keys(interceptors)[0]).toMatchInlineSnapshot('"packages/next-ui/icons"')
|
|
751
751
|
|
|
752
752
|
const result = interceptors['packages/next-ui/icons']?.template
|
|
753
753
|
|
|
@@ -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', () => {
|
|
@@ -16,7 +16,7 @@ it('resolves dependences', () => {
|
|
|
16
16
|
"@graphcommerce/googlerecaptcha" => "packages/googlerecaptcha",
|
|
17
17
|
"@graphcommerce/googletagmanager" => "packages/googletagmanager",
|
|
18
18
|
"@graphcommerce/hygraph-dynamic-rows" => "packages/hygraph-dynamic-rows",
|
|
19
|
-
"@graphcommerce/
|
|
19
|
+
"@graphcommerce/hygraph-ui" => "packages/hygraph-ui",
|
|
20
20
|
"@graphcommerce/magento-cart-billing-address" => "packages/magento-cart-billing-address",
|
|
21
21
|
"@graphcommerce/magento-cart-checkout" => "packages/magento-cart-checkout",
|
|
22
22
|
"@graphcommerce/magento-cart-coupon" => "packages/magento-cart-coupon",
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.exportConfig = exportConfig;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
8
|
const loadConfig_1 = require("../loadConfig");
|
|
8
9
|
const exportConfigToEnv_1 = require("../utils/exportConfigToEnv");
|
|
9
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
10
|
dotenv_1.default.config();
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
12
12
|
async function exportConfig() {
|
|
@@ -53,7 +53,7 @@ function configToEnvSchema(schema) {
|
|
|
53
53
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z
|
|
54
54
|
.string()
|
|
55
55
|
.optional()
|
|
56
|
-
.refine(isJSON, { message:
|
|
56
|
+
.refine(isJSON, { message: 'Invalid JSON' })
|
|
57
57
|
.transform((val) => (val ? JSON.parse(val) : val));
|
|
58
58
|
envToDot[(0, exports.toEnvStr)(path)] = (0, exports.dotNotation)(path);
|
|
59
59
|
}
|
|
@@ -69,7 +69,7 @@ function configToEnvSchema(schema) {
|
|
|
69
69
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z
|
|
70
70
|
.string()
|
|
71
71
|
.optional()
|
|
72
|
-
.refine(isJSON, { message:
|
|
72
|
+
.refine(isJSON, { message: 'Invalid JSON' })
|
|
73
73
|
.transform((val) => (val ? JSON.parse(val) : val));
|
|
74
74
|
envToDot[(0, exports.toEnvStr)(path)] = (0, exports.dotNotation)(path);
|
|
75
75
|
}
|
|
@@ -176,11 +176,11 @@ function formatAppliedEnv(applyResult) {
|
|
|
176
176
|
return ` ${chalk_1.default.red('-')} ${baseLog}: ${fromFmt}`;
|
|
177
177
|
return ` ${chalk_1.default.yellowBright('~')} ${baseLog}: ${fromFmt} => ${toFmt}`;
|
|
178
178
|
});
|
|
179
|
-
let header = chalk_1.default.blueBright(
|
|
179
|
+
let header = chalk_1.default.blueBright('info');
|
|
180
180
|
if (hasWarning)
|
|
181
|
-
header = chalk_1.default.yellowBright(
|
|
181
|
+
header = chalk_1.default.yellowBright('warning');
|
|
182
182
|
if (hasError)
|
|
183
|
-
header = chalk_1.default.yellowBright(
|
|
184
|
-
header +=
|
|
183
|
+
header = chalk_1.default.yellowBright('error');
|
|
184
|
+
header += ' - Loaded GraphCommerce env variables';
|
|
185
185
|
return [header, ...lines].join('\n');
|
|
186
186
|
}
|
|
@@ -22,7 +22,7 @@ function rewriteLegacyEnv(schema, env, config = {}) {
|
|
|
22
22
|
function notUsed() {
|
|
23
23
|
return (envVar, envValue) => {
|
|
24
24
|
applied.push({
|
|
25
|
-
warning: [
|
|
25
|
+
warning: ['should be removed'],
|
|
26
26
|
envVar,
|
|
27
27
|
envValue,
|
|
28
28
|
});
|
|
@@ -35,7 +35,7 @@ function rewriteLegacyEnv(schema, env, config = {}) {
|
|
|
35
35
|
IMAGE_DOMAINS: (envVar, envValue) => {
|
|
36
36
|
applied.push({
|
|
37
37
|
warning: [
|
|
38
|
-
|
|
38
|
+
'should be removed: will automatically add the Magento/Hygraph URL. For more advanced configurations, see: https://nextjs.org/docs/api-reference/next/image#configuration-options',
|
|
39
39
|
],
|
|
40
40
|
envVar,
|
|
41
41
|
envValue,
|
|
@@ -29,9 +29,9 @@ class InterceptorPlugin {
|
|
|
29
29
|
if (generating)
|
|
30
30
|
return {};
|
|
31
31
|
generating = true;
|
|
32
|
-
const start = Date.now()
|
|
32
|
+
// const start = Date.now()
|
|
33
33
|
// console.log('Generating interceptors...')
|
|
34
|
-
const [plugins
|
|
34
|
+
const [plugins] = (0, findPlugins_1.findPlugins)(this.config);
|
|
35
35
|
// console.log(errors)
|
|
36
36
|
// const found = Date.now()
|
|
37
37
|
// console.log('Found plugins in', found - start, 'ms')
|
|
@@ -64,7 +64,7 @@ class InterceptorPlugin {
|
|
|
64
64
|
});
|
|
65
65
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
66
66
|
this.#generateInterceptors().then((i) => {
|
|
67
|
-
Object.entries(i).forEach(([
|
|
67
|
+
Object.entries(i).forEach(([, { sourcePath }]) => {
|
|
68
68
|
const absoluteFilePath = path_1.default.join(process.cwd(), sourcePath);
|
|
69
69
|
compilation.fileDependencies.add(absoluteFilePath);
|
|
70
70
|
});
|
|
@@ -4,17 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.codegenInterceptors = codegenInterceptors;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
8
|
const loadConfig_1 = require("../../config/loadConfig");
|
|
8
9
|
const resolveDependency_1 = require("../../utils/resolveDependency");
|
|
9
10
|
const findPlugins_1 = require("../findPlugins");
|
|
10
11
|
const generateInterceptors_1 = require("../generateInterceptors");
|
|
11
12
|
const writeInterceptors_1 = require("../writeInterceptors");
|
|
12
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
13
13
|
dotenv_1.default.config();
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
15
15
|
async function codegenInterceptors() {
|
|
16
16
|
const conf = (0, loadConfig_1.loadConfig)(process.cwd());
|
|
17
|
-
const [plugins
|
|
17
|
+
const [plugins] = (0, findPlugins_1.findPlugins)(conf);
|
|
18
18
|
const generatedInterceptors = await (0, generateInterceptors_1.generateInterceptors)(plugins, (0, resolveDependency_1.resolveDependency)(), conf.debug, true);
|
|
19
19
|
// const generated = Date.now()
|
|
20
20
|
// console.log('Generated interceptors in', generated - found, 'ms')
|
|
@@ -26,6 +26,7 @@ function parseAndFindExport(resolved, findExport, resolve) {
|
|
|
26
26
|
return resolved;
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
29
30
|
console.log(declaration);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -76,7 +77,7 @@ function parseAndFindExport(resolved, findExport, resolve) {
|
|
|
76
77
|
}
|
|
77
78
|
return undefined;
|
|
78
79
|
}
|
|
79
|
-
const cachedResults = new Map()
|
|
80
|
+
// const cachedResults = new Map<string, ResolveDependencyReturn>()
|
|
80
81
|
function findOriginalSource(plug, resolved, resolve) {
|
|
81
82
|
if (!resolved?.source)
|
|
82
83
|
return {
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.findPlugins = findPlugins;
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
4
|
const core_1 = require("@swc/core");
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
5
|
const glob_1 = require("glob");
|
|
12
6
|
const resolveDependenciesSync_1 = require("../utils/resolveDependenciesSync");
|
|
13
7
|
const parseStructure_1 = require("./parseStructure");
|
|
14
8
|
const pluginLogs = {};
|
|
9
|
+
// ANSI escape codes for console colors
|
|
10
|
+
const GREEN = '\x1b[32m';
|
|
11
|
+
const RESET = '\x1b[0m';
|
|
15
12
|
function findPlugins(config, cwd = process.cwd()) {
|
|
16
13
|
const dependencies = (0, resolveDependenciesSync_1.resolveDependenciesSync)(cwd);
|
|
17
14
|
const debug = Boolean(config.debug?.pluginStatus);
|
|
@@ -38,7 +35,7 @@ function findPlugins(config, cwd = process.cwd()) {
|
|
|
38
35
|
});
|
|
39
36
|
if (process.env.NODE_ENV === 'development' && debug) {
|
|
40
37
|
const byExported = plugins.reduce((acc, plugin) => {
|
|
41
|
-
const key = `🔌 ${
|
|
38
|
+
const key = `🔌 ${GREEN}Plugins loaded for ${plugin.targetModule}#${plugin.targetExport}${RESET}`;
|
|
42
39
|
if (!acc[key])
|
|
43
40
|
acc[key] = [];
|
|
44
41
|
acc[key].push(plugin);
|
|
@@ -55,7 +52,7 @@ function findPlugins(config, cwd = process.cwd()) {
|
|
|
55
52
|
? `${c.ifConfig[0]}=${c.ifConfig[1]}`
|
|
56
53
|
: `${c.ifConfig}`
|
|
57
54
|
: '';
|
|
58
|
-
return `${c.enabled ?
|
|
55
|
+
return `${c.enabled ? '🟢' : '⚪️'} ${c.sourceModule} ${ifConfigStr}`;
|
|
59
56
|
})
|
|
60
57
|
.join('\n');
|
|
61
58
|
if (logStr && pluginLogs[key] !== logStr) {
|
|
@@ -44,7 +44,6 @@ function isPluginConfig(plugin) {
|
|
|
44
44
|
exports.SOURCE_START = '/** Original source starts here (do not modify!): **/';
|
|
45
45
|
exports.SOURCE_END = '/** Original source ends here (do not modify!) **/';
|
|
46
46
|
const originalSuffix = 'Original';
|
|
47
|
-
const sourceSuffix = 'Plugin';
|
|
48
47
|
const interceptorSuffix = 'Interceptor';
|
|
49
48
|
const disabledSuffix = 'Disabled';
|
|
50
49
|
const name = (plugin) => `${plugin.sourceExport}${plugin.sourceModule
|
|
@@ -130,15 +129,15 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
|
|
|
130
129
|
result = `
|
|
131
130
|
type ${interceptorPropsName(name(p))} = ${carryProps.join(' & ')} & OmitPrev<React.ComponentProps<typeof ${sourceName(name(p))}>, 'Prev'>
|
|
132
131
|
|
|
133
|
-
const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ?
|
|
132
|
+
const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ? '{' : '('}
|
|
134
133
|
${config.pluginStatus ? `logOnce(\`🔌 Rendering ${base} with plugin(s): ${wrapChain} wrapping <${base}/>\`)` : ''}
|
|
135
134
|
|
|
136
135
|
${process.env.NODE_ENV === 'development'
|
|
137
136
|
? `if(!props['data-plugin'])
|
|
138
137
|
logOnce('${fileName(p)} does not spread props to prev: <Prev {...props}/>. This will cause issues if multiple plugins are applied to this component.')`
|
|
139
138
|
: ''}
|
|
140
|
-
${withBraces ?
|
|
141
|
-
${withBraces ?
|
|
139
|
+
${withBraces ? 'return' : ''} <${sourceName(name(p))} {...props} Prev={${carry}} />
|
|
140
|
+
${withBraces ? '}' : ')'}`;
|
|
142
141
|
carryProps = [interceptorPropsName(name(p))];
|
|
143
142
|
pluginSee.push(`@see {${sourceName(name(p))}} for source of applied plugin`);
|
|
144
143
|
}
|
|
@@ -194,7 +193,7 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
|
|
|
194
193
|
/* eslint-disable */
|
|
195
194
|
/* This file is automatically generated for ${dependency} */
|
|
196
195
|
${Object.values(targetExports).some((t) => t.some((p) => p.type === 'component'))
|
|
197
|
-
?
|
|
196
|
+
? "import type { DistributedOmit as OmitPrev } from 'type-fest'"
|
|
198
197
|
: ''}
|
|
199
198
|
|
|
200
199
|
${pluginImports}
|
|
@@ -210,6 +209,7 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
|
|
|
210
209
|
templateFormatted = await prettier_1.default.format(template, { ...prettier_config_pwa_1.default, parser: 'typescript' });
|
|
211
210
|
}
|
|
212
211
|
catch (e) {
|
|
212
|
+
// eslint-disable-next-line no-console
|
|
213
213
|
console.log('Error formatting interceptor: ', e, 'using raw template.');
|
|
214
214
|
templateFormatted = template;
|
|
215
215
|
}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateInterceptors = generateInterceptors;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
7
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const findOriginalSource_1 = require("./findOriginalSource");
|
|
10
10
|
const generateInterceptor_1 = require("./generateInterceptor");
|
|
11
11
|
async function generateInterceptors(plugins, resolve, config, force) {
|
|
@@ -16,7 +16,7 @@ async function generateInterceptors(plugins, resolve, config, force) {
|
|
|
16
16
|
const result = resolve(plug.targetModule, { includeSources: true });
|
|
17
17
|
const { error, resolved } = (0, findOriginalSource_1.findOriginalSource)(plug, result, resolve);
|
|
18
18
|
if (error) {
|
|
19
|
-
console.
|
|
19
|
+
console.error(error.message);
|
|
20
20
|
return acc;
|
|
21
21
|
}
|
|
22
22
|
const { fromRoot } = resolved;
|
|
@@ -20,7 +20,7 @@ const isObject = (input) => typeof input === 'object' && input !== null && !Arra
|
|
|
20
20
|
function parseStructure(ast, gcConfig, sourceModule) {
|
|
21
21
|
const [exports, errors] = (0, extractExports_1.extractExports)(ast);
|
|
22
22
|
if (errors.length)
|
|
23
|
-
console.error(
|
|
23
|
+
console.error('Plugin error for', errors.join('\n'));
|
|
24
24
|
const { config: moduleConfig, component, func, exported, ifConfig, plugin, Plugin, ...rest } = exports;
|
|
25
25
|
const exportVals = Object.keys(rest);
|
|
26
26
|
if (component && !moduleConfig)
|
|
@@ -19,7 +19,9 @@ function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root,
|
|
|
19
19
|
// Previously processed
|
|
20
20
|
if (dependencyStructure[packageJson.name])
|
|
21
21
|
return dependencyStructure;
|
|
22
|
-
|
|
22
|
+
// To have additional namespaces be considered as a graphcommerce package, set PRIVATE_PACKAGE_NAMESPACES
|
|
23
|
+
const namespaces = process.env.PRIVATE_PACKAGE_NAMESPACES?.split(',') ?? ['graphcommerce'];
|
|
24
|
+
if (!isRoot && !namespaces.some((namespace) => packageJson.name?.includes(namespace)))
|
|
23
25
|
return dependencyStructure;
|
|
24
26
|
const dependencies = [
|
|
25
27
|
...new Set([
|