@graphcommerce/next-config 6.0.0-canary.44 → 6.0.0-canary.46
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__/interceptors/generateInterceptors.ts +7 -7
- package/dist/interceptors/generateInterceptors.js +32 -22
- package/dist/withGraphCommerce.js +1 -0
- package/package.json +1 -1
- package/src/interceptors/generateInterceptors.ts +39 -33
- package/src/withGraphCommerce.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 6.0.0-canary.46
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1844](https://github.com/graphcommerce-org/graphcommerce/pull/1844) [`929cffafb`](https://github.com/graphcommerce-org/graphcommerce/commit/929cffafbc8b2e57433b6448c95234fb057880b1) - Plugins were incorrectly sorted and local plugins didn't get preference ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
## 6.0.0-canary.45
|
|
10
|
+
|
|
3
11
|
## 6.0.0-canary.44
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -55,18 +55,18 @@ it('it generates an interceptor', () => {
|
|
|
55
55
|
/**
|
|
56
56
|
* Interceptor for \`<PaymentMethodContextProvider/>\` with these plugins:
|
|
57
57
|
*
|
|
58
|
-
* - \`@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods\`
|
|
59
58
|
* - \`@graphcommerce/magento-payment-braintree/plugins/AddBraintreeMethods\`
|
|
59
|
+
* - \`@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods\`
|
|
60
60
|
*/
|
|
61
61
|
type PaymentMethodContextProviderProps = ComponentProps<typeof PaymentMethodContextProviderBase>
|
|
62
62
|
|
|
63
|
-
function AddMollieMethodsInterceptor(props: PaymentMethodContextProviderProps) {
|
|
64
|
-
return <AddMollieMethods {...props} Prev={PaymentMethodContextProviderBase} />
|
|
65
|
-
}
|
|
66
63
|
function AddBraintreeMethodsInterceptor(props: PaymentMethodContextProviderProps) {
|
|
67
|
-
return <AddBraintreeMethods {...props} Prev={
|
|
64
|
+
return <AddBraintreeMethods {...props} Prev={PaymentMethodContextProviderBase} />
|
|
68
65
|
}
|
|
69
|
-
|
|
66
|
+
function AddMollieMethodsInterceptor(props: PaymentMethodContextProviderProps) {
|
|
67
|
+
return <AddMollieMethods {...props} Prev={AddBraintreeMethodsInterceptor} />
|
|
68
|
+
}
|
|
69
|
+
export const PaymentMethodContextProvider = AddMollieMethodsInterceptor
|
|
70
70
|
"
|
|
71
71
|
`)
|
|
72
72
|
})
|
|
@@ -134,8 +134,8 @@ it('it can apply multiple plugins to a single export', () => {
|
|
|
134
134
|
"/* This file is automatically generated for @graphcommerce/magento-cart-payment-method/PaymentMethodContext/PaymentMethodContext */
|
|
135
135
|
|
|
136
136
|
export * from './PaymentMethodContext'
|
|
137
|
-
import { Plugin as AddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'
|
|
138
137
|
import { Plugin as AddOneMore } from '@graphcommerce/magento-payment-braintree/plugins/AddOneMore'
|
|
138
|
+
import { Plugin as AddMollieMethods } from '@graphcommerce/mollie-magento-payment/plugins/AddMollieMethods'
|
|
139
139
|
import { ComponentProps } from 'react'
|
|
140
140
|
import {
|
|
141
141
|
PaymentMethodContextProvider as PaymentMethodContextProviderBase,
|
|
@@ -5,22 +5,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateInterceptors = exports.generateInterceptor = void 0;
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
function moveRelativeDown(plugins) {
|
|
9
|
+
return [...plugins].sort((a, b) => {
|
|
10
|
+
if (a.plugin.startsWith('.') && !b.plugin.startsWith('.'))
|
|
11
|
+
return 1;
|
|
12
|
+
if (!a.plugin.startsWith('.') && b.plugin.startsWith('.'))
|
|
13
|
+
return -1;
|
|
14
|
+
return 0;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function generateInterceptor(interceptor) {
|
|
18
|
+
const { fromModule, dependency, components } = interceptor;
|
|
19
|
+
const flattended = Object.entries(components)
|
|
20
|
+
.map(([, plugins]) => plugins)
|
|
21
|
+
.flat();
|
|
22
|
+
const duplicateImports = new Set();
|
|
23
|
+
const pluginImports = moveRelativeDown([...flattended].sort((a, b) => a.plugin.localeCompare(b.plugin)))
|
|
24
|
+
.map((p) => p.plugin)
|
|
25
|
+
.map((p) => `import { Plugin as ${p.split('/')[p.split('/').length - 1]} } from '${p}'`)
|
|
26
|
+
.filter((str) => {
|
|
27
|
+
if (duplicateImports.has(str))
|
|
28
|
+
return false;
|
|
29
|
+
duplicateImports.add(str);
|
|
30
|
+
return true;
|
|
24
31
|
})
|
|
25
32
|
.join('\n');
|
|
26
33
|
const imports = Object.entries(components).map(([component]) => `${component} as ${component}Base`);
|
|
@@ -31,16 +38,16 @@ function generateInterceptor(plugin) {
|
|
|
31
38
|
: `import { ${imports[0]} } from '${fromModule}'`;
|
|
32
39
|
const pluginExports = Object.entries(components)
|
|
33
40
|
.map(([component, plugins]) => {
|
|
34
|
-
const
|
|
41
|
+
const duplicateInterceptors = new Set();
|
|
35
42
|
let carry = `${component}Base`;
|
|
36
43
|
const pluginStr = plugins
|
|
37
44
|
.reverse()
|
|
38
45
|
.map((p) => p.plugin.split('/')[p.plugin.split('/').length - 1])
|
|
39
46
|
.filter((importStr) => {
|
|
40
|
-
if (
|
|
47
|
+
if (duplicateInterceptors.has(importStr)) {
|
|
41
48
|
return false;
|
|
42
49
|
}
|
|
43
|
-
|
|
50
|
+
duplicateInterceptors.add(importStr);
|
|
44
51
|
return true;
|
|
45
52
|
})
|
|
46
53
|
.map((name) => {
|
|
@@ -72,12 +79,12 @@ import { ComponentProps } from 'react'
|
|
|
72
79
|
${importInjectables}
|
|
73
80
|
${pluginExports}
|
|
74
81
|
`;
|
|
75
|
-
return { ...
|
|
82
|
+
return { ...interceptor, template };
|
|
76
83
|
}
|
|
77
84
|
exports.generateInterceptor = generateInterceptor;
|
|
78
85
|
function generateInterceptors(plugins, resolve) {
|
|
79
86
|
// todo: Do not use reduce as we're passing the accumulator to the next iteration
|
|
80
|
-
const byExportedComponent = plugins.reduce((acc, plug) => {
|
|
87
|
+
const byExportedComponent = moveRelativeDown(plugins).reduce((acc, plug) => {
|
|
81
88
|
const { exported, component, enabled, plugin } = plug;
|
|
82
89
|
if (!exported || !component || !enabled)
|
|
83
90
|
return acc;
|
|
@@ -101,6 +108,9 @@ function generateInterceptors(plugins, resolve) {
|
|
|
101
108
|
});
|
|
102
109
|
return acc;
|
|
103
110
|
}, {});
|
|
104
|
-
return Object.fromEntries(Object.entries(byExportedComponent).map(([target,
|
|
111
|
+
return Object.fromEntries(Object.entries(byExportedComponent).map(([target, interceptor]) => [
|
|
112
|
+
target,
|
|
113
|
+
generateInterceptor(interceptor),
|
|
114
|
+
]));
|
|
105
115
|
}
|
|
106
116
|
exports.generateInterceptors = generateInterceptors;
|
|
@@ -58,6 +58,7 @@ function withGraphCommerce(nextConfig, cwd) {
|
|
|
58
58
|
domains: [...domains(graphcommerceConfig), ...(nextConfig.i18n?.domains ?? [])],
|
|
59
59
|
},
|
|
60
60
|
images: {
|
|
61
|
+
...nextConfig.images,
|
|
61
62
|
domains: [
|
|
62
63
|
new URL(graphcommerceConfig.magentoEndpoint).hostname,
|
|
63
64
|
'media.graphassets.com',
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/next-config",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "6.0.0-canary.
|
|
5
|
+
"version": "6.0.0-canary.46",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
|
@@ -9,36 +9,39 @@ export type PluginConfig = {
|
|
|
9
9
|
enabled: boolean
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
type
|
|
12
|
+
type Interceptor = ResolveDependencyReturn & {
|
|
13
13
|
components: Record<string, PluginConfig[]>
|
|
14
14
|
target: string
|
|
15
15
|
template?: string
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export type MaterializedPlugin =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
18
|
+
export type MaterializedPlugin = Interceptor & { template: string }
|
|
19
|
+
|
|
20
|
+
function moveRelativeDown(plugins: PluginConfig[]) {
|
|
21
|
+
return [...plugins].sort((a, b) => {
|
|
22
|
+
if (a.plugin.startsWith('.') && !b.plugin.startsWith('.')) return 1
|
|
23
|
+
if (!a.plugin.startsWith('.') && b.plugin.startsWith('.')) return -1
|
|
24
|
+
return 0
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function generateInterceptor(interceptor: Interceptor): MaterializedPlugin {
|
|
29
|
+
const { fromModule, dependency, components } = interceptor
|
|
30
|
+
|
|
31
|
+
const flattended = Object.entries(components)
|
|
32
|
+
.map(([, plugins]) => plugins)
|
|
33
|
+
.flat()
|
|
34
|
+
const duplicateImports = new Set()
|
|
35
|
+
|
|
36
|
+
const pluginImports = moveRelativeDown(
|
|
37
|
+
[...flattended].sort((a, b) => a.plugin.localeCompare(b.plugin)),
|
|
38
|
+
)
|
|
39
|
+
.map((p) => p.plugin)
|
|
40
|
+
.map((p) => `import { Plugin as ${p.split('/')[p.split('/').length - 1]} } from '${p}'`)
|
|
41
|
+
.filter((str) => {
|
|
42
|
+
if (duplicateImports.has(str)) return false
|
|
43
|
+
duplicateImports.add(str)
|
|
44
|
+
return true
|
|
42
45
|
})
|
|
43
46
|
.join('\n')
|
|
44
47
|
|
|
@@ -54,17 +57,17 @@ export function generateInterceptor(plugin: Plugin): MaterializedPlugin {
|
|
|
54
57
|
|
|
55
58
|
const pluginExports = Object.entries(components)
|
|
56
59
|
.map(([component, plugins]) => {
|
|
57
|
-
const
|
|
60
|
+
const duplicateInterceptors = new Set()
|
|
58
61
|
|
|
59
62
|
let carry = `${component}Base`
|
|
60
63
|
const pluginStr = plugins
|
|
61
64
|
.reverse()
|
|
62
65
|
.map((p) => p.plugin.split('/')[p.plugin.split('/').length - 1])
|
|
63
66
|
.filter((importStr) => {
|
|
64
|
-
if (
|
|
67
|
+
if (duplicateInterceptors.has(importStr)) {
|
|
65
68
|
return false
|
|
66
69
|
}
|
|
67
|
-
|
|
70
|
+
duplicateInterceptors.add(importStr)
|
|
68
71
|
return true
|
|
69
72
|
})
|
|
70
73
|
.map((name) => {
|
|
@@ -100,7 +103,7 @@ ${importInjectables}
|
|
|
100
103
|
${pluginExports}
|
|
101
104
|
`
|
|
102
105
|
|
|
103
|
-
return { ...
|
|
106
|
+
return { ...interceptor, template }
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
export type GenerateInterceptorsReturn = Record<string, MaterializedPlugin>
|
|
@@ -110,7 +113,7 @@ export function generateInterceptors(
|
|
|
110
113
|
resolve: ResolveDependency,
|
|
111
114
|
): GenerateInterceptorsReturn {
|
|
112
115
|
// todo: Do not use reduce as we're passing the accumulator to the next iteration
|
|
113
|
-
const byExportedComponent = plugins.reduce((acc, plug) => {
|
|
116
|
+
const byExportedComponent = moveRelativeDown(plugins).reduce((acc, plug) => {
|
|
114
117
|
const { exported, component, enabled, plugin } = plug
|
|
115
118
|
if (!exported || !component || !enabled) return acc
|
|
116
119
|
|
|
@@ -127,7 +130,7 @@ export function generateInterceptors(
|
|
|
127
130
|
...resolved,
|
|
128
131
|
target: `${resolved.fromRoot}.interceptor`,
|
|
129
132
|
components: {},
|
|
130
|
-
} as
|
|
133
|
+
} as Interceptor
|
|
131
134
|
|
|
132
135
|
if (!acc[resolved.fromRoot].components[component])
|
|
133
136
|
acc[resolved.fromRoot].components[component] = []
|
|
@@ -138,9 +141,12 @@ export function generateInterceptors(
|
|
|
138
141
|
})
|
|
139
142
|
|
|
140
143
|
return acc
|
|
141
|
-
}, {} as Record<string,
|
|
144
|
+
}, {} as Record<string, Interceptor>)
|
|
142
145
|
|
|
143
146
|
return Object.fromEntries(
|
|
144
|
-
Object.entries(byExportedComponent).map(([target,
|
|
147
|
+
Object.entries(byExportedComponent).map(([target, interceptor]) => [
|
|
148
|
+
target,
|
|
149
|
+
generateInterceptor(interceptor),
|
|
150
|
+
]),
|
|
145
151
|
)
|
|
146
152
|
}
|
package/src/withGraphCommerce.ts
CHANGED
|
@@ -68,6 +68,7 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf
|
|
|
68
68
|
domains: [...domains(graphcommerceConfig), ...(nextConfig.i18n?.domains ?? [])],
|
|
69
69
|
},
|
|
70
70
|
images: {
|
|
71
|
+
...nextConfig.images,
|
|
71
72
|
domains: [
|
|
72
73
|
new URL(graphcommerceConfig.magentoEndpoint).hostname,
|
|
73
74
|
'media.graphassets.com',
|