@graphcommerce/next-config 9.0.0-canary.57 → 9.0.0-canary.59
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__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +1 -0
- package/__tests__/interceptors/findPlugins.ts +20 -0
- package/__tests__/interceptors/parseStructure.ts +80 -0
- package/dist/generated/config.js +1 -0
- package/dist/interceptors/findOriginalSource.js +1 -1
- package/dist/interceptors/parseStructure.js +10 -4
- package/dist/withGraphCommerce.js +8 -9
- package/package.json +1 -1
- package/src/generated/config.ts +7 -0
- package/src/interceptors/findOriginalSource.ts +1 -1
- package/src/interceptors/generateInterceptor.ts +1 -1
- package/src/interceptors/parseStructure.ts +11 -4
- package/src/withGraphCommerce.ts +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.0.0-canary.59
|
|
4
|
+
|
|
5
|
+
## 9.0.0-canary.58
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- [#2330](https://github.com/graphcommerce-org/graphcommerce/pull/2330) [`5701e71`](https://github.com/graphcommerce-org/graphcommerce/commit/5701e71454ffb52880cd15c3341826d9502284d0) - Added support for boolean `ifConfig: ['customerXMagentoCacheIdDisable', true]` values in plugin configurations ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
3
11
|
## 9.0.0-canary.57
|
|
4
12
|
|
|
5
13
|
## 9.0.0-canary.56
|
|
@@ -40,6 +40,7 @@ exports[`traverses a schema and returns a list of env variables that match 1`] =
|
|
|
40
40
|
"GC_CUSTOMER_ADDRESS_NOTE_ENABLE",
|
|
41
41
|
"GC_CUSTOMER_COMPANY_FIELDS_ENABLE",
|
|
42
42
|
"GC_CUSTOMER_DELETE_ENABLED",
|
|
43
|
+
"GC_CUSTOMER_X_MAGENTO_CACHE_ID_DISABLE",
|
|
43
44
|
"GC_DATA_LAYER",
|
|
44
45
|
"GC_DATA_LAYER_CORE_WEB_VITALS",
|
|
45
46
|
"GC_DEBUG",
|
|
@@ -187,6 +187,14 @@ it('finds plugins', () => {
|
|
|
187
187
|
"targetModule": "@graphcommerce/ecommerce-ui",
|
|
188
188
|
"type": "component",
|
|
189
189
|
},
|
|
190
|
+
{
|
|
191
|
+
"enabled": true,
|
|
192
|
+
"sourceExport": "meshConfig",
|
|
193
|
+
"sourceModule": "@graphcommerce/graphql-mesh/plugins/meshConfigFake",
|
|
194
|
+
"targetExport": "meshConfig",
|
|
195
|
+
"targetModule": "@graphcommerce/graphql-mesh/meshConfig",
|
|
196
|
+
"type": "function",
|
|
197
|
+
},
|
|
190
198
|
{
|
|
191
199
|
"enabled": true,
|
|
192
200
|
"sourceExport": "plugin",
|
|
@@ -227,6 +235,18 @@ it('finds plugins', () => {
|
|
|
227
235
|
"targetModule": "@graphcommerce/graphql",
|
|
228
236
|
"type": "function",
|
|
229
237
|
},
|
|
238
|
+
{
|
|
239
|
+
"enabled": true,
|
|
240
|
+
"ifConfig": [
|
|
241
|
+
"customerXMagentoCacheIdDisable",
|
|
242
|
+
false,
|
|
243
|
+
],
|
|
244
|
+
"sourceExport": "GraphQLProvider",
|
|
245
|
+
"sourceModule": "@graphcommerce/magento-customer/plugins/XMagentoCacheIdGraphQLProvider",
|
|
246
|
+
"targetExport": "GraphQLProvider",
|
|
247
|
+
"targetModule": "@graphcommerce/graphql",
|
|
248
|
+
"type": "component",
|
|
249
|
+
},
|
|
230
250
|
{
|
|
231
251
|
"enabled": true,
|
|
232
252
|
"sourceExport": "GraphQLProvider",
|
|
@@ -206,3 +206,83 @@ export const Plugin = AddAdyenMethods
|
|
|
206
206
|
`)
|
|
207
207
|
expect(plugins[1]).toMatchInlineSnapshot(`undefined`)
|
|
208
208
|
})
|
|
209
|
+
|
|
210
|
+
it('correctly allows false value in the ifConfig', () => {
|
|
211
|
+
const src = `
|
|
212
|
+
import { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
213
|
+
import { xMagentoCacheIdHeader } from '../link/xMagentoCacheIdHeader'
|
|
214
|
+
import { GraphQLProviderProps } from '@graphcommerce/graphql'
|
|
215
|
+
|
|
216
|
+
export const config: PluginConfig = {
|
|
217
|
+
type: 'component',
|
|
218
|
+
module: '@graphcommerce/graphql',
|
|
219
|
+
ifConfig: ['customerXMagentoCacheIdDisable', false],
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function GraphQLProvider(props: PluginProps<GraphQLProviderProps>) {
|
|
223
|
+
const { Prev, links = [], ...rest } = props
|
|
224
|
+
return <Prev {...rest} links={[...links, xMagentoCacheIdHeader]} />
|
|
225
|
+
}
|
|
226
|
+
`
|
|
227
|
+
const ast = parseSync(src)
|
|
228
|
+
|
|
229
|
+
expect(
|
|
230
|
+
parseStructure(ast, {} as GraphCommerceConfig, './plugins/MyReplace')[0].enabled,
|
|
231
|
+
).toBeTruthy()
|
|
232
|
+
|
|
233
|
+
expect(
|
|
234
|
+
parseStructure(
|
|
235
|
+
ast,
|
|
236
|
+
{ customerXMagentoCacheIdDisable: true } as GraphCommerceConfig,
|
|
237
|
+
'./plugins/MyReplace',
|
|
238
|
+
)[0].enabled,
|
|
239
|
+
).toBeFalsy()
|
|
240
|
+
|
|
241
|
+
expect(
|
|
242
|
+
parseStructure(
|
|
243
|
+
ast,
|
|
244
|
+
{ customerXMagentoCacheIdDisable: false } as GraphCommerceConfig,
|
|
245
|
+
'./plugins/MyReplace',
|
|
246
|
+
)[0].enabled,
|
|
247
|
+
).toBeTruthy()
|
|
248
|
+
})
|
|
249
|
+
|
|
250
|
+
it('correctly allows true value in the ifConfig', () => {
|
|
251
|
+
const src = `
|
|
252
|
+
import { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
253
|
+
import { xMagentoCacheIdHeader } from '../link/xMagentoCacheIdHeader'
|
|
254
|
+
import { GraphQLProviderProps } from '@graphcommerce/graphql'
|
|
255
|
+
|
|
256
|
+
export const config: PluginConfig = {
|
|
257
|
+
type: 'component',
|
|
258
|
+
module: '@graphcommerce/graphql',
|
|
259
|
+
ifConfig: ['customerXMagentoCacheIdDisable', true],
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export function GraphQLProvider(props: PluginProps<GraphQLProviderProps>) {
|
|
263
|
+
const { Prev, links = [], ...rest } = props
|
|
264
|
+
return <Prev {...rest} links={[...links, xMagentoCacheIdHeader]} />
|
|
265
|
+
}
|
|
266
|
+
`
|
|
267
|
+
const ast = parseSync(src)
|
|
268
|
+
|
|
269
|
+
expect(
|
|
270
|
+
parseStructure(ast, {} as GraphCommerceConfig, './plugins/MyReplace')[0].enabled,
|
|
271
|
+
).toBeFalsy()
|
|
272
|
+
|
|
273
|
+
expect(
|
|
274
|
+
parseStructure(
|
|
275
|
+
ast,
|
|
276
|
+
{ customerXMagentoCacheIdDisable: true } as GraphCommerceConfig,
|
|
277
|
+
'./plugins/MyReplace',
|
|
278
|
+
)[0].enabled,
|
|
279
|
+
).toBeTruthy()
|
|
280
|
+
|
|
281
|
+
expect(
|
|
282
|
+
parseStructure(
|
|
283
|
+
ast,
|
|
284
|
+
{ customerXMagentoCacheIdDisable: false } as GraphCommerceConfig,
|
|
285
|
+
'./plugins/MyReplace',
|
|
286
|
+
)[0].enabled,
|
|
287
|
+
).toBeFalsy()
|
|
288
|
+
})
|
package/dist/generated/config.js
CHANGED
|
@@ -36,6 +36,7 @@ function GraphCommerceConfigSchema() {
|
|
|
36
36
|
customerAddressNoteEnable: zod_1.z.boolean().nullish(),
|
|
37
37
|
customerCompanyFieldsEnable: zod_1.z.boolean().nullish(),
|
|
38
38
|
customerDeleteEnabled: zod_1.z.boolean().nullish(),
|
|
39
|
+
customerXMagentoCacheIdDisable: zod_1.z.boolean().nullish(),
|
|
39
40
|
dataLayer: DatalayerConfigSchema().nullish(),
|
|
40
41
|
debug: GraphCommerceDebugConfigSchema().nullish(),
|
|
41
42
|
demoMode: zod_1.z.boolean().default(true).nullish(),
|
|
@@ -81,7 +81,7 @@ function findOriginalSource(plug, resolved, resolve) {
|
|
|
81
81
|
if (!resolved?.source)
|
|
82
82
|
return {
|
|
83
83
|
resolved: undefined,
|
|
84
|
-
error: new Error(`
|
|
84
|
+
error: new Error(`Plugin: Can not find module ${plug.targetModule} for ${plug.sourceModule}`),
|
|
85
85
|
};
|
|
86
86
|
// const cacheKey = `${plug.targetModule}#${plug.targetExport}`
|
|
87
87
|
// if (cachedResults.has(cacheKey)) {
|
|
@@ -11,7 +11,7 @@ const pluginConfigParsed = zod_1.z.object({
|
|
|
11
11
|
type: zod_1.z.enum(['component', 'function', 'replace']),
|
|
12
12
|
module: zod_1.z.string(),
|
|
13
13
|
export: zod_1.z.string(),
|
|
14
|
-
ifConfig: zod_1.z.union([zod_1.z.string(), zod_1.z.tuple([zod_1.z.string(), zod_1.z.
|
|
14
|
+
ifConfig: zod_1.z.union([zod_1.z.string(), zod_1.z.tuple([zod_1.z.string(), zod_1.z.unknown()])]).optional(),
|
|
15
15
|
});
|
|
16
16
|
function nonNullable(value) {
|
|
17
17
|
return value !== null && value !== undefined;
|
|
@@ -51,9 +51,15 @@ function parseStructure(ast, gcConfig, sourceModule) {
|
|
|
51
51
|
}
|
|
52
52
|
let enabled = true;
|
|
53
53
|
if (parsed.data.ifConfig) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
if (Array.isArray(parsed.data.ifConfig)) {
|
|
55
|
+
const isBoolean = typeof parsed.data.ifConfig[1] === 'boolean';
|
|
56
|
+
let confValue = (0, get_1.default)(gcConfig, parsed.data.ifConfig[0]);
|
|
57
|
+
confValue = isBoolean ? Boolean(confValue) : confValue;
|
|
58
|
+
enabled = confValue === parsed.data.ifConfig[1];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
enabled = Boolean((0, get_1.default)(gcConfig, parsed.data.ifConfig));
|
|
62
|
+
}
|
|
57
63
|
}
|
|
58
64
|
const val = {
|
|
59
65
|
targetExport: exports.component || exports.func || parsed.data.export,
|
|
@@ -1,10 +1,7 @@
|
|
|
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.withGraphCommerce = withGraphCommerce;
|
|
7
|
-
|
|
4
|
+
// import CircularDependencyPlugin from 'circular-dependency-plugin'
|
|
8
5
|
const plugin_1 = require("inspectpack/plugin");
|
|
9
6
|
const webpack_1 = require("webpack");
|
|
10
7
|
const loadConfig_1 = require("./config/loadConfig");
|
|
@@ -114,11 +111,13 @@ function withGraphCommerce(nextConfig, cwd) {
|
|
|
114
111
|
// To properly properly treeshake @apollo/client we need to define the __DEV__ property
|
|
115
112
|
config.plugins.push(new webpack_1.DefinePlugin({ 'globalThis.__DEV__': options.dev }));
|
|
116
113
|
if (!options.isServer) {
|
|
117
|
-
if (graphcommerceConfig.debug?.webpackCircularDependencyPlugin) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
114
|
+
// if (graphcommerceConfig.debug?.webpackCircularDependencyPlugin) {
|
|
115
|
+
// config.plugins.push(
|
|
116
|
+
// new CircularDependencyPlugin({
|
|
117
|
+
// exclude: /readable-stream|duplexer2|node_modules\/next/,
|
|
118
|
+
// }),
|
|
119
|
+
// )
|
|
120
|
+
// }
|
|
122
121
|
if (graphcommerceConfig.debug?.webpackDuplicatesPlugin) {
|
|
123
122
|
config.plugins.push(new plugin_1.DuplicatesPlugin({
|
|
124
123
|
ignoredPackages: [
|
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": "9.0.0-canary.
|
|
5
|
+
"version": "9.0.0-canary.59",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
package/src/generated/config.ts
CHANGED
|
@@ -169,6 +169,12 @@ export type GraphCommerceConfig = {
|
|
|
169
169
|
customerCompanyFieldsEnable?: InputMaybe<Scalars['Boolean']['input']>;
|
|
170
170
|
/** Enable customer account deletion through the account section */
|
|
171
171
|
customerDeleteEnabled?: InputMaybe<Scalars['Boolean']['input']>;
|
|
172
|
+
/**
|
|
173
|
+
* X-Magento-Cache-Id allows Varnish to cache requests that are made in the browser while users are logged in. For example the products query can now be cached for logged in users.
|
|
174
|
+
*
|
|
175
|
+
* This can be disabled when Varnish is running out of available memory.
|
|
176
|
+
*/
|
|
177
|
+
customerXMagentoCacheIdDisable?: InputMaybe<Scalars['Boolean']['input']>;
|
|
172
178
|
/** Datalayer config */
|
|
173
179
|
dataLayer?: InputMaybe<DatalayerConfig>;
|
|
174
180
|
/** Debug configuration for GraphCommerce */
|
|
@@ -498,6 +504,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject<Properties<GraphCommerc
|
|
|
498
504
|
customerAddressNoteEnable: z.boolean().nullish(),
|
|
499
505
|
customerCompanyFieldsEnable: z.boolean().nullish(),
|
|
500
506
|
customerDeleteEnabled: z.boolean().nullish(),
|
|
507
|
+
customerXMagentoCacheIdDisable: z.boolean().nullish(),
|
|
501
508
|
dataLayer: DatalayerConfigSchema().nullish(),
|
|
502
509
|
debug: GraphCommerceDebugConfigSchema().nullish(),
|
|
503
510
|
demoMode: z.boolean().default(true).nullish(),
|
|
@@ -93,7 +93,7 @@ export function findOriginalSource(
|
|
|
93
93
|
if (!resolved?.source)
|
|
94
94
|
return {
|
|
95
95
|
resolved: undefined,
|
|
96
|
-
error: new Error(`
|
|
96
|
+
error: new Error(`Plugin: Can not find module ${plug.targetModule} for ${plug.sourceModule}`),
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
// const cacheKey = `${plug.targetModule}#${plug.targetExport}`
|
|
@@ -14,7 +14,7 @@ type PluginBaseConfig = {
|
|
|
14
14
|
sourceModule: string
|
|
15
15
|
targetExport: string
|
|
16
16
|
enabled: boolean
|
|
17
|
-
ifConfig?: string | [string,
|
|
17
|
+
ifConfig?: string | [string, any]
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function isPluginBaseConfig(plugin: Partial<PluginBaseConfig>): plugin is PluginBaseConfig {
|
|
@@ -9,7 +9,7 @@ const pluginConfigParsed = z.object({
|
|
|
9
9
|
type: z.enum(['component', 'function', 'replace']),
|
|
10
10
|
module: z.string(),
|
|
11
11
|
export: z.string(),
|
|
12
|
-
ifConfig: z.union([z.string(), z.tuple([z.string(), z.
|
|
12
|
+
ifConfig: z.union([z.string(), z.tuple([z.string(), z.unknown()])]).optional(),
|
|
13
13
|
})
|
|
14
14
|
|
|
15
15
|
function nonNullable<T>(value: T): value is NonNullable<T> {
|
|
@@ -62,10 +62,17 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
let enabled = true
|
|
65
|
+
|
|
65
66
|
if (parsed.data.ifConfig) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
if (Array.isArray(parsed.data.ifConfig)) {
|
|
68
|
+
const isBoolean = typeof parsed.data.ifConfig[1] === 'boolean'
|
|
69
|
+
let confValue = get(gcConfig, parsed.data.ifConfig[0])
|
|
70
|
+
confValue = isBoolean ? Boolean(confValue) : confValue
|
|
71
|
+
|
|
72
|
+
enabled = confValue === parsed.data.ifConfig[1]
|
|
73
|
+
} else {
|
|
74
|
+
enabled = Boolean(get(gcConfig, parsed.data.ifConfig))
|
|
75
|
+
}
|
|
69
76
|
}
|
|
70
77
|
|
|
71
78
|
const val: PluginConfig = {
|
package/src/withGraphCommerce.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import CircularDependencyPlugin from 'circular-dependency-plugin'
|
|
1
|
+
// import CircularDependencyPlugin from 'circular-dependency-plugin'
|
|
2
2
|
import { DuplicatesPlugin } from 'inspectpack/plugin'
|
|
3
3
|
import type { NextConfig } from 'next'
|
|
4
4
|
import { DomainLocale } from 'next/dist/server/config'
|
|
@@ -135,13 +135,13 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf
|
|
|
135
135
|
config.plugins.push(new DefinePlugin({ 'globalThis.__DEV__': options.dev }))
|
|
136
136
|
|
|
137
137
|
if (!options.isServer) {
|
|
138
|
-
if (graphcommerceConfig.debug?.webpackCircularDependencyPlugin) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
138
|
+
// if (graphcommerceConfig.debug?.webpackCircularDependencyPlugin) {
|
|
139
|
+
// config.plugins.push(
|
|
140
|
+
// new CircularDependencyPlugin({
|
|
141
|
+
// exclude: /readable-stream|duplexer2|node_modules\/next/,
|
|
142
|
+
// }),
|
|
143
|
+
// )
|
|
144
|
+
// }
|
|
145
145
|
if (graphcommerceConfig.debug?.webpackDuplicatesPlugin) {
|
|
146
146
|
config.plugins.push(
|
|
147
147
|
new DuplicatesPlugin({
|