@graphcommerce/next-config 6.0.0-canary.40 → 6.0.0-canary.41
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/Config.graphqls +7 -0
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +1 -0
- package/__tests__/config/utils/configToImportMeta.ts +11 -43
- package/__tests__/config/utils/replaceConfigInString.ts +4 -6
- package/__tests__/interceptors/findPlugins.ts +1 -7
- package/dist/config/loadConfig.js +4 -4
- package/dist/config/utils/configToImportMeta.js +2 -2
- package/dist/config/utils/replaceConfigInString.js +1 -1
- package/dist/config/utils/rewriteLegacyEnv.js +1 -1
- package/package.json +1 -1
- package/src/config/loadConfig.ts +5 -6
- package/src/config/utils/configToImportMeta.ts +6 -2
- package/src/config/utils/replaceConfigInString.ts +1 -1
- package/src/config/utils/rewriteLegacyEnv.ts +1 -1
- package/src/generated/config.ts +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 6.0.0-canary.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1839](https://github.com/graphcommerce-org/graphcommerce/pull/1839) [`e4a3f5e98`](https://github.com/graphcommerce-org/graphcommerce/commit/e4a3f5e986287b78c3e048d8a33611c61070b79e) - Make sure the configuration is validated before executing ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
- [#1839](https://github.com/graphcommerce-org/graphcommerce/pull/1839) [`8eb310409`](https://github.com/graphcommerce-org/graphcommerce/commit/8eb3104098749a6b08d2affb6cdc8a7e6698866f) - Use graphCommerce._ instead of import.meta.graphCommerce._ in .meshrc.yml ([@paales](https://github.com/paales))
|
|
10
|
+
|
|
3
11
|
## 6.0.0-canary.40
|
|
4
12
|
|
|
5
13
|
## 6.0.0-canary.39
|
package/Config.graphqls
CHANGED
|
@@ -33,6 +33,13 @@ function MyComponent() {
|
|
|
33
33
|
}
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
You can also use the configuration in your `.meshrc.yml` by accessing
|
|
37
|
+
`{graphCommerce.myField}`
|
|
38
|
+
|
|
39
|
+
```yml
|
|
40
|
+
endpoint: '{graphCommerce.magentoEndpoint}'
|
|
41
|
+
```
|
|
42
|
+
|
|
36
43
|
## Environment variables to override configuration
|
|
37
44
|
|
|
38
45
|
Configuration values can be overwriten by environment variables, with the following rules:
|
|
@@ -737,6 +737,7 @@ exports[`traverses a schema and returns a list of env variables that match 1`] =
|
|
|
737
737
|
"GC_MAGENTO_ENDPOINT",
|
|
738
738
|
"GC_PREVIEW_SECRET",
|
|
739
739
|
"GC_PRODUCT_FILTERS_PRO",
|
|
740
|
+
"GC_PRODUCT_ROUTE",
|
|
740
741
|
"GC_ROBOTS_ALLOW",
|
|
741
742
|
"GC_WISHLIST_HIDE_FOR_GUESTS",
|
|
742
743
|
"GC_WISHLIST_IGNORE_PRODUCT_WISHLIST_STATUS",
|
|
@@ -36,49 +36,17 @@ it('flattens a config object', () => {
|
|
|
36
36
|
it('creates keys but does not stringify values', () => {
|
|
37
37
|
expect(configToImportMeta(configFile, false)).toMatchInlineSnapshot(`
|
|
38
38
|
{
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"googleTagmanagerKey": "GTM-XXXXXXX",
|
|
51
|
-
"i18n": [
|
|
52
|
-
{
|
|
53
|
-
"hygraphLocales": [
|
|
54
|
-
"en",
|
|
55
|
-
],
|
|
56
|
-
"locale": "en",
|
|
57
|
-
"magentoStoreCode": "en_us",
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
"legacyProductRoute": true,
|
|
61
|
-
"productFiltersPro": false,
|
|
62
|
-
},
|
|
63
|
-
"import.meta.graphCommerce.customerRequireEmailConfirmation": false,
|
|
64
|
-
"import.meta.graphCommerce.deeper": {
|
|
65
|
-
"arrayvalue": [
|
|
66
|
-
"test",
|
|
67
|
-
],
|
|
68
|
-
"nested": {
|
|
69
|
-
"value": "test",
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
"import.meta.graphCommerce.deeper.arrayvalue": "["test"]",
|
|
73
|
-
"import.meta.graphCommerce.deeper.nested": {
|
|
74
|
-
"value": "test",
|
|
75
|
-
},
|
|
76
|
-
"import.meta.graphCommerce.deeper.nested.value": "test",
|
|
77
|
-
"import.meta.graphCommerce.demoMode": true,
|
|
78
|
-
"import.meta.graphCommerce.googleTagmanagerKey": "GTM-XXXXXXX",
|
|
79
|
-
"import.meta.graphCommerce.i18n": "[{"locale":"en","hygraphLocales":["en"],"magentoStoreCode":"en_us"}]",
|
|
80
|
-
"import.meta.graphCommerce.legacyProductRoute": true,
|
|
81
|
-
"import.meta.graphCommerce.productFiltersPro": false,
|
|
39
|
+
"false": "{ __debug: "'false' can not be destructured, please access deeper properties directly" }",
|
|
40
|
+
"false.customerRequireEmailConfirmation": "false",
|
|
41
|
+
"false.deeper": "{ __debug: "'false.deeper' can not be destructured, please access deeper properties directly" }",
|
|
42
|
+
"false.deeper.arrayvalue": "["test"]",
|
|
43
|
+
"false.deeper.nested": "{ __debug: "'false.deeper.nested' can not be destructured, please access deeper properties directly" }",
|
|
44
|
+
"false.deeper.nested.value": ""test"",
|
|
45
|
+
"false.demoMode": "true",
|
|
46
|
+
"false.googleTagmanagerKey": ""GTM-XXXXXXX"",
|
|
47
|
+
"false.i18n": "[{"locale":"en","hygraphLocales":["en"],"magentoStoreCode":"en_us"}]",
|
|
48
|
+
"false.legacyProductRoute": "true",
|
|
49
|
+
"false.productFiltersPro": "false",
|
|
82
50
|
}
|
|
83
51
|
`)
|
|
84
52
|
})
|
|
@@ -6,19 +6,17 @@ import { replaceConfigInString } from '../../../src/config/utils/replaceConfigIn
|
|
|
6
6
|
it('replaces config in string', () => {
|
|
7
7
|
const config = { ...demoConfig, replaceMe: '1234', do: { replaceMe: 'CHECK' } }
|
|
8
8
|
|
|
9
|
-
const meshrc = `
|
|
10
|
-
|
|
11
|
-
sources:
|
|
9
|
+
const meshrc = `sources:
|
|
12
10
|
- name: hygraph
|
|
13
11
|
handler:
|
|
14
12
|
graphql:
|
|
15
13
|
useGETForQueries: true
|
|
16
|
-
endpoint: '{
|
|
14
|
+
endpoint: '{graphCommerce.hygraphEndpoint}'
|
|
17
15
|
batch: false
|
|
18
|
-
i18nConfig: {
|
|
16
|
+
i18nConfig: {graphCommerce.i18n}
|
|
19
17
|
operationHeaders:
|
|
20
18
|
gcms-locales: "{context.headers['gcms-locales']}"
|
|
21
|
-
path: /nl/v3/json/getAddress/index.php?postcode={args.postcode}&huisnummer={args.housenumber}&secure_code={
|
|
19
|
+
path: /nl/v3/json/getAddress/index.php?postcode={args.postcode}&huisnummer={args.housenumber}&secure_code={graphCommerce.replaceMe}&public_key={graphCommerce.do.replaceMe}
|
|
22
20
|
transforms:
|
|
23
21
|
- filterSchema:
|
|
24
22
|
filters:
|
|
@@ -15,12 +15,6 @@ it('finds plugins', () => {
|
|
|
15
15
|
|
|
16
16
|
expect(enabled).toMatchInlineSnapshot(`
|
|
17
17
|
[
|
|
18
|
-
{
|
|
19
|
-
"component": "AddProductsToCartForm",
|
|
20
|
-
"enabled": true,
|
|
21
|
-
"exported": "@graphcommerce/magento-product",
|
|
22
|
-
"plugin": "./plugins/MyPlugin",
|
|
23
|
-
},
|
|
24
18
|
{
|
|
25
19
|
"component": "AddProductsToCartForm",
|
|
26
20
|
"enabled": true,
|
|
@@ -170,7 +164,7 @@ it('finds plugins', () => {
|
|
|
170
164
|
"enabled": false,
|
|
171
165
|
"exported": "@graphcommerce/magento-product",
|
|
172
166
|
"ifConfig": "demoMode",
|
|
173
|
-
"plugin": "
|
|
167
|
+
"plugin": "./plugins/EnableCrosssellsPlugin",
|
|
174
168
|
},
|
|
175
169
|
{
|
|
176
170
|
"component": "ProductListItem",
|
|
@@ -30,7 +30,6 @@ function loadConfig(cwd) {
|
|
|
30
30
|
try {
|
|
31
31
|
const result = loader.search(cwd);
|
|
32
32
|
let confFile = result?.config;
|
|
33
|
-
const hasEnv = Object.keys((0, mergeEnvIntoConfig_1.filterEnv)(process.env)).length > 0;
|
|
34
33
|
if (!confFile) {
|
|
35
34
|
if (isMainProcess)
|
|
36
35
|
console.warn('No graphcommerce.config.js found in the project, using demo config');
|
|
@@ -38,8 +37,9 @@ function loadConfig(cwd) {
|
|
|
38
37
|
}
|
|
39
38
|
confFile ||= {};
|
|
40
39
|
const schema = (0, config_1.GraphCommerceConfigSchema)();
|
|
41
|
-
const
|
|
42
|
-
|
|
40
|
+
const [mergedConfig, applyResult] = (0, rewriteLegacyEnv_1.rewriteLegacyEnv)(schema, process.env,
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
42
|
+
confFile);
|
|
43
43
|
if (applyResult.length > 0 && isMainProcess)
|
|
44
44
|
console.log((0, mergeEnvIntoConfig_1.formatAppliedEnv)(applyResult));
|
|
45
45
|
const finalParse = schema.parse(mergedConfig);
|
|
@@ -52,7 +52,7 @@ function loadConfig(cwd) {
|
|
|
52
52
|
catch (error) {
|
|
53
53
|
if (error instanceof Error) {
|
|
54
54
|
if (isMainProcess) {
|
|
55
|
-
console.log(error.message);
|
|
55
|
+
console.log('Error while parsing graphcommerce.config.js', error.message);
|
|
56
56
|
process.exit(1);
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -30,7 +30,7 @@ function flattenKeys(value, initialPathPrefix, stringify) {
|
|
|
30
30
|
throw Error(`Unexpected value: ${value}`);
|
|
31
31
|
}
|
|
32
32
|
/** The result of this function is passed to the webpack DefinePlugin as import.meta.graphCommerce.* */
|
|
33
|
-
function configToImportMeta(config, stringify = true) {
|
|
34
|
-
return flattenKeys(config,
|
|
33
|
+
function configToImportMeta(config, path = 'import.meta.graphCommerce', stringify = true) {
|
|
34
|
+
return flattenKeys(config, path, stringify);
|
|
35
35
|
}
|
|
36
36
|
exports.configToImportMeta = configToImportMeta;
|
|
@@ -4,7 +4,7 @@ exports.replaceConfigInString = void 0;
|
|
|
4
4
|
const configToImportMeta_1 = require("./configToImportMeta");
|
|
5
5
|
function replaceConfigInString(str, config) {
|
|
6
6
|
let result = str;
|
|
7
|
-
const replacers = (0, configToImportMeta_1.configToImportMeta)(config, false);
|
|
7
|
+
const replacers = (0, configToImportMeta_1.configToImportMeta)(config, 'graphCommerce', false);
|
|
8
8
|
Object.entries(replacers).forEach(([from, to]) => {
|
|
9
9
|
result = result.replace(new RegExp(`{${from}}`, 'g'), to);
|
|
10
10
|
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.rewriteLegacyEnv = void 0;
|
|
7
7
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
8
8
|
const mergeEnvIntoConfig_1 = require("./mergeEnvIntoConfig");
|
|
9
|
-
function rewriteLegacyEnv(schema,
|
|
9
|
+
function rewriteLegacyEnv(schema, env, config = {}) {
|
|
10
10
|
const clonedEnv = (0, cloneDeep_1.default)(env);
|
|
11
11
|
const applied = [];
|
|
12
12
|
function renamedTo(to) {
|
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.41",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
package/src/config/loadConfig.ts
CHANGED
|
@@ -19,7 +19,6 @@ export function loadConfig(cwd: string): GraphCommerceConfig {
|
|
|
19
19
|
const result = loader.search(cwd)
|
|
20
20
|
|
|
21
21
|
let confFile = result?.config
|
|
22
|
-
const hasEnv = Object.keys(filterEnv(process.env)).length > 0
|
|
23
22
|
if (!confFile) {
|
|
24
23
|
if (isMainProcess)
|
|
25
24
|
console.warn('No graphcommerce.config.js found in the project, using demo config')
|
|
@@ -28,17 +27,17 @@ export function loadConfig(cwd: string): GraphCommerceConfig {
|
|
|
28
27
|
confFile ||= {}
|
|
29
28
|
|
|
30
29
|
const schema = GraphCommerceConfigSchema()
|
|
31
|
-
const parsed = schema.safeParse(confFile)
|
|
32
|
-
|
|
33
30
|
const [mergedConfig, applyResult] = rewriteLegacyEnv(
|
|
34
|
-
|
|
35
|
-
parsed.success ? parsed.data : {},
|
|
31
|
+
schema,
|
|
36
32
|
process.env,
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
34
|
+
confFile,
|
|
37
35
|
)
|
|
38
36
|
|
|
39
37
|
if (applyResult.length > 0 && isMainProcess) console.log(formatAppliedEnv(applyResult))
|
|
40
38
|
|
|
41
39
|
const finalParse = schema.parse(mergedConfig)
|
|
40
|
+
|
|
42
41
|
if (process.env.DEBUG && isMainProcess) {
|
|
43
42
|
console.log('Parsed configuration')
|
|
44
43
|
console.log(finalParse)
|
|
@@ -47,7 +46,7 @@ export function loadConfig(cwd: string): GraphCommerceConfig {
|
|
|
47
46
|
} catch (error) {
|
|
48
47
|
if (error instanceof Error) {
|
|
49
48
|
if (isMainProcess) {
|
|
50
|
-
console.log(error.message)
|
|
49
|
+
console.log('Error while parsing graphcommerce.config.js', error.message)
|
|
51
50
|
process.exit(1)
|
|
52
51
|
}
|
|
53
52
|
}
|
|
@@ -38,6 +38,10 @@ function flattenKeys(
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/** The result of this function is passed to the webpack DefinePlugin as import.meta.graphCommerce.* */
|
|
41
|
-
export function configToImportMeta(
|
|
42
|
-
|
|
41
|
+
export function configToImportMeta(
|
|
42
|
+
config: unknown,
|
|
43
|
+
path = 'import.meta.graphCommerce',
|
|
44
|
+
stringify = true,
|
|
45
|
+
) {
|
|
46
|
+
return flattenKeys(config, path, stringify) as Record<string, string>
|
|
43
47
|
}
|
|
@@ -3,7 +3,7 @@ import { configToImportMeta } from './configToImportMeta'
|
|
|
3
3
|
|
|
4
4
|
export function replaceConfigInString(str: string, config: Partial<GraphCommerceConfig>) {
|
|
5
5
|
let result = str
|
|
6
|
-
const replacers = configToImportMeta(config, false)
|
|
6
|
+
const replacers = configToImportMeta(config, 'graphCommerce', false)
|
|
7
7
|
|
|
8
8
|
Object.entries(replacers).forEach(([from, to]) => {
|
|
9
9
|
result = result.replace(new RegExp(`{${from}}`, 'g'), to)
|
|
@@ -4,8 +4,8 @@ import { ApplyResult, mergeEnvIntoConfig, ZodNode } from './mergeEnvIntoConfig'
|
|
|
4
4
|
|
|
5
5
|
export function rewriteLegacyEnv(
|
|
6
6
|
schema: ZodNode,
|
|
7
|
-
config: Partial<GraphCommerceConfig>,
|
|
8
7
|
env: Record<string, string | undefined>,
|
|
8
|
+
config: Partial<GraphCommerceConfig> = {},
|
|
9
9
|
) {
|
|
10
10
|
const clonedEnv: Record<string, string | undefined> = cloneDeep(env)
|
|
11
11
|
const applied: ApplyResult = []
|
package/src/generated/config.ts
CHANGED
|
@@ -49,6 +49,13 @@ export type Scalars = {
|
|
|
49
49
|
* }
|
|
50
50
|
* ```
|
|
51
51
|
*
|
|
52
|
+
* You can also use the configuration in your `.meshrc.yml` by accessing
|
|
53
|
+
* `{graphCommerce.myField}`
|
|
54
|
+
*
|
|
55
|
+
* ```yml
|
|
56
|
+
* endpoint: '{graphCommerce.magentoEndpoint}'
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
52
59
|
* ## Environment variables to override configuration
|
|
53
60
|
*
|
|
54
61
|
* Configuration values can be overwriten by environment variables, with the following rules:
|
|
@@ -130,7 +137,7 @@ export type GraphCommerceConfig = {
|
|
|
130
137
|
*
|
|
131
138
|
* Provide a value to enable Google Analytics for your store.
|
|
132
139
|
*
|
|
133
|
-
* To
|
|
140
|
+
* To override the value for a specific locale, configure in i18n config.
|
|
134
141
|
*/
|
|
135
142
|
googleAnalyticsId?: InputMaybe<Scalars['String']>;
|
|
136
143
|
/**
|