@graphcommerce/next-config 9.0.0-canary.115 → 9.0.0-canary.116
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 +6 -0
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +1 -0
- package/__tests__/interceptors/findPlugins.ts +24 -20
- package/__tests__/interceptors/generateInterceptors.ts +5 -11
- package/dist/config/demoConfig.js +2 -2
- package/dist/config/utils/mergeEnvIntoConfig.js +7 -9
- package/dist/generated/config.js +1 -0
- package/dist/interceptors/InterceptorPlugin.js +1 -0
- package/dist/interceptors/Visitor.js +1 -1
- package/dist/interceptors/extractExports.js +8 -54
- package/dist/interceptors/generateInterceptor.js +4 -0
- package/dist/utils/TopologicalSort.js +4 -0
- package/package.json +1 -1
- package/src/config/demoConfig.ts +2 -2
- package/src/config/utils/mergeEnvIntoConfig.ts +2 -2
- package/src/generated/config.ts +3 -0
- package/src/interceptors/InterceptorPlugin.ts +1 -0
- package/src/interceptors/Visitor.ts +3 -4
- package/src/interceptors/extractExports.ts +1 -46
- package/src/interceptors/generateInterceptor.ts +4 -0
- package/src/utils/TopologicalSort.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 9.0.0-canary.116
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#2452](https://github.com/graphcommerce-org/graphcommerce/pull/2452) [`aab290f`](https://github.com/graphcommerce-org/graphcommerce/commit/aab290f9c905be06e742cd8ad50d7d415930828a) - Migrated to next.config.ts ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
3
9
|
## 9.0.0-canary.115
|
|
4
10
|
|
|
5
11
|
## 9.0.0-canary.114
|
|
@@ -46,6 +46,7 @@ exports[`traverses a schema and returns a list of env variables that match 1`] =
|
|
|
46
46
|
"GC_DATA_LAYER",
|
|
47
47
|
"GC_DATA_LAYER_CORE_WEB_VITALS",
|
|
48
48
|
"GC_DEBUG",
|
|
49
|
+
"GC_DEBUG_CART",
|
|
49
50
|
"GC_DEBUG_PLUGIN_STATUS",
|
|
50
51
|
"GC_DEBUG_SESSIONS",
|
|
51
52
|
"GC_DEBUG_WEBPACK_CIRCULAR_DEPENDENCY_PLUGIN",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GraphCommerceConfig } from '../../src/generated/config'
|
|
2
2
|
import { findPlugins } from '../../src/interceptors/findPlugins'
|
|
3
|
+
|
|
3
4
|
const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
4
5
|
it('finds plugins', () => {
|
|
5
6
|
const fakeconfig = {
|
|
@@ -12,7 +13,8 @@ it('finds plugins', () => {
|
|
|
12
13
|
const disabled = plugins.filter((p) => !p.enabled)
|
|
13
14
|
const enabled = plugins.filter((p) => p.enabled)
|
|
14
15
|
expect(errors).toMatchInlineSnapshot('[]')
|
|
15
|
-
expect(enabled).toMatchInlineSnapshot(
|
|
16
|
+
expect(enabled).toMatchInlineSnapshot(
|
|
17
|
+
`
|
|
16
18
|
[
|
|
17
19
|
{
|
|
18
20
|
"enabled": true,
|
|
@@ -282,17 +284,17 @@ it('finds plugins', () => {
|
|
|
282
284
|
},
|
|
283
285
|
{
|
|
284
286
|
"enabled": true,
|
|
285
|
-
"sourceExport": "
|
|
287
|
+
"sourceExport": "getPrivateQueryContext",
|
|
286
288
|
"sourceModule": "@graphcommerce/algolia-personalization/plugins/InContextInputAlgoliaUserToken",
|
|
287
|
-
"targetExport": "
|
|
289
|
+
"targetExport": "getPrivateQueryContext",
|
|
288
290
|
"targetModule": "@graphcommerce/graphql",
|
|
289
291
|
"type": "function",
|
|
290
292
|
},
|
|
291
293
|
{
|
|
292
294
|
"enabled": true,
|
|
293
|
-
"sourceExport": "
|
|
295
|
+
"sourceExport": "usePrivateQueryContext",
|
|
294
296
|
"sourceModule": "@graphcommerce/algolia-personalization/plugins/InContextInputAlgoliaUserToken",
|
|
295
|
-
"targetExport": "
|
|
297
|
+
"targetExport": "usePrivateQueryContext",
|
|
296
298
|
"targetModule": "@graphcommerce/graphql",
|
|
297
299
|
"type": "function",
|
|
298
300
|
},
|
|
@@ -482,25 +484,17 @@ it('finds plugins', () => {
|
|
|
482
484
|
},
|
|
483
485
|
{
|
|
484
486
|
"enabled": true,
|
|
485
|
-
"sourceExport": "
|
|
486
|
-
"sourceModule": "@graphcommerce/magento-customer/plugins/
|
|
487
|
-
"targetExport": "
|
|
488
|
-
"targetModule": "@graphcommerce/graphql",
|
|
489
|
-
"type": "function",
|
|
490
|
-
},
|
|
491
|
-
{
|
|
492
|
-
"enabled": true,
|
|
493
|
-
"sourceExport": "getInContextInput",
|
|
494
|
-
"sourceModule": "@graphcommerce/magento-customer/plugins/magentoCustomerGetInContext",
|
|
495
|
-
"targetExport": "getInContextInput",
|
|
487
|
+
"sourceExport": "getPrivateQueryContext",
|
|
488
|
+
"sourceModule": "@graphcommerce/magento-customer/plugins/magentoCustomerPrivateQueryContext",
|
|
489
|
+
"targetExport": "getPrivateQueryContext",
|
|
496
490
|
"targetModule": "@graphcommerce/graphql",
|
|
497
491
|
"type": "function",
|
|
498
492
|
},
|
|
499
493
|
{
|
|
500
494
|
"enabled": true,
|
|
501
|
-
"sourceExport": "
|
|
502
|
-
"sourceModule": "@graphcommerce/magento-customer/plugins/
|
|
503
|
-
"targetExport": "
|
|
495
|
+
"sourceExport": "usePrivateQueryContext",
|
|
496
|
+
"sourceModule": "@graphcommerce/magento-customer/plugins/magentoCustomerPrivateQueryContext",
|
|
497
|
+
"targetExport": "usePrivateQueryContext",
|
|
504
498
|
"targetModule": "@graphcommerce/graphql",
|
|
505
499
|
"type": "function",
|
|
506
500
|
},
|
|
@@ -549,7 +543,8 @@ it('finds plugins', () => {
|
|
|
549
543
|
"type": "function",
|
|
550
544
|
},
|
|
551
545
|
]
|
|
552
|
-
|
|
546
|
+
`,
|
|
547
|
+
)
|
|
553
548
|
expect(disabled).toMatchInlineSnapshot(`
|
|
554
549
|
[
|
|
555
550
|
{
|
|
@@ -723,6 +718,15 @@ it('finds plugins', () => {
|
|
|
723
718
|
"targetModule": "@graphcommerce/framer-next-pages",
|
|
724
719
|
"type": "component",
|
|
725
720
|
},
|
|
721
|
+
{
|
|
722
|
+
"enabled": false,
|
|
723
|
+
"ifConfig": "debug.cart",
|
|
724
|
+
"sourceExport": "FramerNextPages",
|
|
725
|
+
"sourceModule": "@graphcommerce/magento-cart/plugins/CartDebuggerPlugin",
|
|
726
|
+
"targetExport": "FramerNextPages",
|
|
727
|
+
"targetModule": "@graphcommerce/framer-next-pages",
|
|
728
|
+
"type": "component",
|
|
729
|
+
},
|
|
726
730
|
{
|
|
727
731
|
"enabled": false,
|
|
728
732
|
"ifConfig": "debug.sessions",
|
|
@@ -8,12 +8,7 @@ import { resolveDependency } from '../../src/utils/resolveDependency'
|
|
|
8
8
|
const projectRoot = `${process.cwd()}/examples/magento-graphcms`
|
|
9
9
|
const startLocation = '/** @see {@link file://'
|
|
10
10
|
const expectImport = (value: string | undefined): jest.JestMatchers<string> =>
|
|
11
|
-
expect(
|
|
12
|
-
value
|
|
13
|
-
?.slice(value.indexOf('import') - 1, value.indexOf(startLocation) - 1)
|
|
14
|
-
|
|
15
|
-
.trim(),
|
|
16
|
-
)
|
|
11
|
+
expect(value?.slice(value.indexOf('import') - 1, value.indexOf(startLocation) - 1).trim())
|
|
17
12
|
const expectInterceptor = (value: string | undefined): jest.JestMatchers<string> => {
|
|
18
13
|
const val = value?.slice(value.indexOf(SOURCE_END) + SOURCE_END.length).trim()
|
|
19
14
|
return expect(val?.trim())
|
|
@@ -384,6 +379,7 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
384
379
|
import type { ApolloLink, TypePolicies } from '@apollo/client'
|
|
385
380
|
import type { SetRequired } from 'type-fest'
|
|
386
381
|
import type { MigrateCache } from './components/GraphQLProvider/migrateCache'
|
|
382
|
+
import { RemovePrivateContextDirectivesLink } from './link/RemovePrivateContextDirectivesLink'
|
|
387
383
|
|
|
388
384
|
export interface PreviewData {}
|
|
389
385
|
export type PreviewConfig = {
|
|
@@ -404,7 +400,7 @@ it('adds debug logging to interceptors for components', async () => {
|
|
|
404
400
|
const { storefront, links = [], policies = [], migrations = [], ...rest } = config
|
|
405
401
|
return {
|
|
406
402
|
storefront,
|
|
407
|
-
links,
|
|
403
|
+
links: [...links, new RemovePrivateContextDirectivesLink()],
|
|
408
404
|
policies,
|
|
409
405
|
migrations,
|
|
410
406
|
...rest,
|
|
@@ -704,8 +700,7 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
704
700
|
`)
|
|
705
701
|
expectOriginal(result).toContain('iconChevronLeftDisabled')
|
|
706
702
|
expectOriginal(result).toContain('iconChevronRightDisabled')
|
|
707
|
-
expectInterceptor(result).toMatchInlineSnapshot(
|
|
708
|
-
`
|
|
703
|
+
expectInterceptor(result).toMatchInlineSnapshot(`
|
|
709
704
|
"/**
|
|
710
705
|
* Here you see the 'interceptor' that is applying all the configured plugins.
|
|
711
706
|
*
|
|
@@ -727,6 +722,5 @@ it('Can correctly find exports that are default exports', async () => {
|
|
|
727
722
|
* @see {iconChevronRightMyProjectIcon} for replacement of the original source (original source not used)
|
|
728
723
|
*/
|
|
729
724
|
export const iconChevronRight = iconChevronRightMyProjectIcon"
|
|
730
|
-
|
|
731
|
-
)
|
|
725
|
+
`)
|
|
732
726
|
})
|
|
@@ -4,8 +4,8 @@ exports.demoConfig = void 0;
|
|
|
4
4
|
exports.demoConfig = {
|
|
5
5
|
canonicalBaseUrl: 'https://graphcommerce.vercel.app',
|
|
6
6
|
hygraphEndpoint: 'https://eu-central-1.cdn.hygraph.com/content/ckhx7xadya6xs01yxdujt8i80/master',
|
|
7
|
-
magentoEndpoint: 'https://
|
|
8
|
-
magentoVersion:
|
|
7
|
+
magentoEndpoint: 'https://configurator.reachdigital.dev/graphql',
|
|
8
|
+
magentoVersion: 247,
|
|
9
9
|
storefront: [
|
|
10
10
|
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
|
|
11
11
|
{
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.toEnvStr = void 0;
|
|
7
7
|
exports.configToEnvSchema = configToEnvSchema;
|
|
8
8
|
exports.mergeEnvIntoConfig = mergeEnvIntoConfig;
|
|
9
9
|
exports.formatAppliedEnv = formatAppliedEnv;
|
|
@@ -23,7 +23,6 @@ const dotNotation = (pathParts) => pathParts
|
|
|
23
23
|
return !Number.isNaN(idx) ? `[${idx}]` : v;
|
|
24
24
|
})
|
|
25
25
|
.join('.');
|
|
26
|
-
exports.dotNotation = dotNotation;
|
|
27
26
|
function isJSON(str) {
|
|
28
27
|
if (!str)
|
|
29
28
|
return true;
|
|
@@ -55,7 +54,7 @@ function configToEnvSchema(schema) {
|
|
|
55
54
|
.optional()
|
|
56
55
|
.refine(isJSON, { message: 'Invalid JSON' })
|
|
57
56
|
.transform((val) => (val ? JSON.parse(val) : val));
|
|
58
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
57
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
59
58
|
}
|
|
60
59
|
const typeNode = node;
|
|
61
60
|
Object.keys(typeNode.shape).forEach((key) => {
|
|
@@ -71,7 +70,7 @@ function configToEnvSchema(schema) {
|
|
|
71
70
|
.optional()
|
|
72
71
|
.refine(isJSON, { message: 'Invalid JSON' })
|
|
73
72
|
.transform((val) => (val ? JSON.parse(val) : val));
|
|
74
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
73
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
75
74
|
}
|
|
76
75
|
arr.forEach((key) => {
|
|
77
76
|
walk(node.element, [...path, String(key)]);
|
|
@@ -80,12 +79,12 @@ function configToEnvSchema(schema) {
|
|
|
80
79
|
}
|
|
81
80
|
if (node instanceof zod_1.ZodNumber) {
|
|
82
81
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z.coerce.number().optional();
|
|
83
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
82
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
84
83
|
return;
|
|
85
84
|
}
|
|
86
85
|
if (node instanceof zod_1.ZodString || node instanceof zod_1.ZodEnum) {
|
|
87
86
|
envSchema[(0, exports.toEnvStr)(path)] = node.optional();
|
|
88
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
87
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
89
88
|
return;
|
|
90
89
|
}
|
|
91
90
|
if (node instanceof zod_1.ZodBoolean) {
|
|
@@ -99,7 +98,7 @@ function configToEnvSchema(schema) {
|
|
|
99
98
|
return false;
|
|
100
99
|
return v;
|
|
101
100
|
});
|
|
102
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
101
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
103
102
|
return;
|
|
104
103
|
}
|
|
105
104
|
throw Error(`[@graphcommerce/next-config] Unknown type in schema ${node.constructor.name}. This is probably a bug please create an issue.`);
|
|
@@ -108,9 +107,8 @@ function configToEnvSchema(schema) {
|
|
|
108
107
|
return [zod_1.z.object(envSchema), envToDot];
|
|
109
108
|
}
|
|
110
109
|
const filterEnv = (env) => Object.fromEntries(Object.entries(env).filter(([key]) => key.startsWith('GC_')));
|
|
111
|
-
exports.filterEnv = filterEnv;
|
|
112
110
|
function mergeEnvIntoConfig(schema, config, env) {
|
|
113
|
-
const filteredEnv =
|
|
111
|
+
const filteredEnv = filterEnv(env);
|
|
114
112
|
const newConfig = (0, utilities_1.cloneDeep)(config);
|
|
115
113
|
const [envSchema, envToDot] = configToEnvSchema(schema);
|
|
116
114
|
const result = envSchema.safeParse(filteredEnv);
|
package/dist/generated/config.js
CHANGED
|
@@ -76,6 +76,7 @@ function GraphCommerceConfigSchema() {
|
|
|
76
76
|
}
|
|
77
77
|
function GraphCommerceDebugConfigSchema() {
|
|
78
78
|
return zod_1.z.object({
|
|
79
|
+
cart: zod_1.z.boolean().nullish(),
|
|
79
80
|
pluginStatus: zod_1.z.boolean().nullish(),
|
|
80
81
|
sessions: zod_1.z.boolean().nullish(),
|
|
81
82
|
webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(),
|
|
@@ -47,6 +47,7 @@ class InterceptorPlugin {
|
|
|
47
47
|
generating = false;
|
|
48
48
|
return generatedInterceptors;
|
|
49
49
|
};
|
|
50
|
+
/** @public */
|
|
50
51
|
apply(compiler) {
|
|
51
52
|
const logger = compiler.getInfrastructureLogger('InterceptorPlugin');
|
|
52
53
|
// After the compilation has succeeded we watch all possible plugin locations.
|
|
@@ -6,6 +6,7 @@ exports.Visitor = void 0;
|
|
|
6
6
|
/* eslint-disable consistent-return */
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
|
|
9
|
+
* @public
|
|
9
10
|
*/
|
|
10
11
|
class Visitor {
|
|
11
12
|
visitProgram(n) {
|
|
@@ -1411,4 +1412,3 @@ class Visitor {
|
|
|
1411
1412
|
}
|
|
1412
1413
|
}
|
|
1413
1414
|
exports.Visitor = Visitor;
|
|
1414
|
-
exports.default = Visitor;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.RUNTIME_VALUE = exports.UnsupportedValueError = exports.NoSuchDeclarationError = void 0;
|
|
5
4
|
exports.extractExports = extractExports;
|
|
6
|
-
class NoSuchDeclarationError extends Error {
|
|
7
|
-
}
|
|
8
|
-
exports.NoSuchDeclarationError = NoSuchDeclarationError;
|
|
9
5
|
function isIdentifier(node) {
|
|
10
6
|
return node.type === 'Identifier';
|
|
11
7
|
}
|
|
@@ -36,34 +32,7 @@ function isRegExpLiteral(node) {
|
|
|
36
32
|
function isTemplateLiteral(node) {
|
|
37
33
|
return node.type === 'TemplateLiteral';
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
/** @example `config.runtime[0].value` */
|
|
41
|
-
path;
|
|
42
|
-
constructor(message, paths) {
|
|
43
|
-
super(message);
|
|
44
|
-
// Generating "path" that looks like "config.runtime[0].value"
|
|
45
|
-
let codePath;
|
|
46
|
-
if (Array.isArray(paths)) {
|
|
47
|
-
codePath = '';
|
|
48
|
-
for (const path of paths) {
|
|
49
|
-
if (path[0] === '[') {
|
|
50
|
-
// "array" + "[0]"
|
|
51
|
-
codePath += path;
|
|
52
|
-
}
|
|
53
|
-
else if (codePath === '') {
|
|
54
|
-
codePath = path;
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
// "object" + ".key"
|
|
58
|
-
codePath += `.${path}`;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
this.path = codePath;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.UnsupportedValueError = UnsupportedValueError;
|
|
66
|
-
exports.RUNTIME_VALUE = Symbol('RUNTIME_VALUE');
|
|
35
|
+
const RUNTIME_VALUE = Symbol('RUNTIME_VALUE');
|
|
67
36
|
function extractValue(node, path, optional = false) {
|
|
68
37
|
if (isNullLiteral(node)) {
|
|
69
38
|
return null;
|
|
@@ -89,8 +58,7 @@ function extractValue(node, path, optional = false) {
|
|
|
89
58
|
case 'undefined':
|
|
90
59
|
return undefined;
|
|
91
60
|
default:
|
|
92
|
-
return
|
|
93
|
-
// throw new UnsupportedValueError(`Unknown identifier "${node.value}"`, path)
|
|
61
|
+
return RUNTIME_VALUE;
|
|
94
62
|
}
|
|
95
63
|
}
|
|
96
64
|
else if (isArrayExpression(node)) {
|
|
@@ -101,11 +69,7 @@ function extractValue(node, path, optional = false) {
|
|
|
101
69
|
if (elem) {
|
|
102
70
|
if (elem.spread) {
|
|
103
71
|
// e.g. [ ...a ]
|
|
104
|
-
return
|
|
105
|
-
// throw new UnsupportedValueError(
|
|
106
|
-
// 'Unsupported spread operator in the Array Expression',
|
|
107
|
-
// path,
|
|
108
|
-
// )
|
|
72
|
+
return RUNTIME_VALUE;
|
|
109
73
|
}
|
|
110
74
|
arr.push(extractValue(elem.expression, path && [...path, `[${i}]`], optional));
|
|
111
75
|
}
|
|
@@ -123,11 +87,7 @@ function extractValue(node, path, optional = false) {
|
|
|
123
87
|
for (const prop of node.properties) {
|
|
124
88
|
if (!isKeyValueProperty(prop)) {
|
|
125
89
|
// e.g. { ...a }
|
|
126
|
-
return
|
|
127
|
-
// throw new UnsupportedValueError(
|
|
128
|
-
// 'Unsupported spread operator in the Object Expression',
|
|
129
|
-
// path,
|
|
130
|
-
// )
|
|
90
|
+
return RUNTIME_VALUE;
|
|
131
91
|
}
|
|
132
92
|
let key;
|
|
133
93
|
if (isIdentifier(prop.key)) {
|
|
@@ -139,11 +99,7 @@ function extractValue(node, path, optional = false) {
|
|
|
139
99
|
key = prop.key.value;
|
|
140
100
|
}
|
|
141
101
|
else {
|
|
142
|
-
return
|
|
143
|
-
// throw new UnsupportedValueError(
|
|
144
|
-
// `Unsupported key type "${prop.key.type}" in the Object Expression`,
|
|
145
|
-
// path,
|
|
146
|
-
// )
|
|
102
|
+
return RUNTIME_VALUE;
|
|
147
103
|
}
|
|
148
104
|
obj[key] = extractValue(prop.value, path && [...path, key]);
|
|
149
105
|
}
|
|
@@ -153,8 +109,7 @@ function extractValue(node, path, optional = false) {
|
|
|
153
109
|
// e.g. `abc`
|
|
154
110
|
if (node.expressions.length !== 0) {
|
|
155
111
|
// TODO: should we add support for `${'e'}d${'g'}'e'`?
|
|
156
|
-
return
|
|
157
|
-
// throw new UnsupportedValueError('Unsupported template literal with expressions', path)
|
|
112
|
+
return RUNTIME_VALUE;
|
|
158
113
|
}
|
|
159
114
|
// When TemplateLiteral has 0 expressions, the length of quasis is always 1.
|
|
160
115
|
// Because when parsing TemplateLiteral, the parser yields the first quasi,
|
|
@@ -169,8 +124,7 @@ function extractValue(node, path, optional = false) {
|
|
|
169
124
|
return cooked ?? raw;
|
|
170
125
|
}
|
|
171
126
|
else {
|
|
172
|
-
return
|
|
173
|
-
// throw new UnsupportedValueError(`Unsupported node type "${node.type}"`, path)
|
|
127
|
+
return RUNTIME_VALUE;
|
|
174
128
|
}
|
|
175
129
|
}
|
|
176
130
|
function extractExports(module) {
|
|
@@ -188,7 +142,7 @@ function extractExports(module) {
|
|
|
188
142
|
switch (moduleItem.declaration.type) {
|
|
189
143
|
case 'ClassDeclaration':
|
|
190
144
|
case 'FunctionDeclaration':
|
|
191
|
-
exports[moduleItem.declaration.identifier.value] =
|
|
145
|
+
exports[moduleItem.declaration.identifier.value] = RUNTIME_VALUE;
|
|
192
146
|
// node.identifier.value
|
|
193
147
|
break;
|
|
194
148
|
case 'VariableDeclaration':
|
|
@@ -17,22 +17,26 @@ const prettier_config_pwa_1 = __importDefault(require("@graphcommerce/prettier-c
|
|
|
17
17
|
const prettier_1 = __importDefault(require("prettier"));
|
|
18
18
|
const RenameVisitor_1 = require("./RenameVisitor");
|
|
19
19
|
const swc_1 = require("./swc");
|
|
20
|
+
/** @public */
|
|
20
21
|
function isPluginBaseConfig(plugin) {
|
|
21
22
|
return (typeof plugin.type === 'string' &&
|
|
22
23
|
typeof plugin.sourceModule === 'string' &&
|
|
23
24
|
typeof plugin.enabled === 'boolean' &&
|
|
24
25
|
typeof plugin.targetExport === 'string');
|
|
25
26
|
}
|
|
27
|
+
/** @public */
|
|
26
28
|
function isReactPluginConfig(plugin) {
|
|
27
29
|
if (!isPluginBaseConfig(plugin))
|
|
28
30
|
return false;
|
|
29
31
|
return plugin.type === 'component';
|
|
30
32
|
}
|
|
33
|
+
/** @public */
|
|
31
34
|
function isMethodPluginConfig(plugin) {
|
|
32
35
|
if (!isPluginBaseConfig(plugin))
|
|
33
36
|
return false;
|
|
34
37
|
return plugin.type === 'function';
|
|
35
38
|
}
|
|
39
|
+
/** @public */
|
|
36
40
|
function isReplacePluginConfig(plugin) {
|
|
37
41
|
if (!isPluginBaseConfig(plugin))
|
|
38
42
|
return false;
|
|
@@ -14,12 +14,15 @@ class TopologicalSort {
|
|
|
14
14
|
this.#nodes = new Map();
|
|
15
15
|
this.addMultipleInternalNodes(nodes);
|
|
16
16
|
}
|
|
17
|
+
/** @public */
|
|
17
18
|
addNode(key, node) {
|
|
18
19
|
return this.addInternalNode(key, node);
|
|
19
20
|
}
|
|
21
|
+
/** @public */
|
|
20
22
|
addNodes(nodes) {
|
|
21
23
|
this.addMultipleInternalNodes(nodes);
|
|
22
24
|
}
|
|
25
|
+
/** @public */
|
|
23
26
|
addEdge(fromKey, toKey) {
|
|
24
27
|
(0, assert_1.default)(this.#nodes.has(fromKey), `Source package with ${fromKey} key should exist`);
|
|
25
28
|
(0, assert_1.default)(this.#nodes.has(toKey), `Target package with ${toKey} key should exist`);
|
|
@@ -30,6 +33,7 @@ class TopologicalSort {
|
|
|
30
33
|
assert_1.default.strictEqual(sourceNode.children.has(toKey), false, `Source package ${fromKey} already has an edge to target node ${toKey}`);
|
|
31
34
|
sourceNode.children.set(toKey, targetNode);
|
|
32
35
|
}
|
|
36
|
+
/** @public */
|
|
33
37
|
sort() {
|
|
34
38
|
this.#visitedNodes = new Set();
|
|
35
39
|
this.#sortedKeysStack = [];
|
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.116",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
package/src/config/demoConfig.ts
CHANGED
|
@@ -6,8 +6,8 @@ export const demoConfig: PartialDeep<GraphCommerceConfig, { recurseIntoArrays: t
|
|
|
6
6
|
Record<string, unknown> & { storefront: PartialDeep<GraphCommerceStorefrontConfig>[] } = {
|
|
7
7
|
canonicalBaseUrl: 'https://graphcommerce.vercel.app',
|
|
8
8
|
hygraphEndpoint: 'https://eu-central-1.cdn.hygraph.com/content/ckhx7xadya6xs01yxdujt8i80/master',
|
|
9
|
-
magentoEndpoint: 'https://
|
|
10
|
-
magentoVersion:
|
|
9
|
+
magentoEndpoint: 'https://configurator.reachdigital.dev/graphql',
|
|
10
|
+
magentoVersion: 247,
|
|
11
11
|
storefront: [
|
|
12
12
|
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
|
|
13
13
|
{
|
|
@@ -21,7 +21,7 @@ import diff from './diff'
|
|
|
21
21
|
|
|
22
22
|
const fmt = (s: string) => s.split(/(\d+)/).map(snakeCase).join('')
|
|
23
23
|
export const toEnvStr = (path: string[]) => ['GC', ...path].map(fmt).join('_').toUpperCase()
|
|
24
|
-
|
|
24
|
+
const dotNotation = (pathParts: string[]) =>
|
|
25
25
|
pathParts
|
|
26
26
|
.map((v) => {
|
|
27
27
|
const idx = Number(v)
|
|
@@ -144,7 +144,7 @@ export type ApplyResultItem = {
|
|
|
144
144
|
}
|
|
145
145
|
export type ApplyResult = ApplyResultItem[]
|
|
146
146
|
|
|
147
|
-
|
|
147
|
+
const filterEnv = (env: Record<string, string | undefined>) =>
|
|
148
148
|
Object.fromEntries(Object.entries(env).filter(([key]) => key.startsWith('GC_')))
|
|
149
149
|
|
|
150
150
|
export function mergeEnvIntoConfig(
|
package/src/generated/config.ts
CHANGED
|
@@ -359,6 +359,8 @@ export type GraphCommerceConfig = {
|
|
|
359
359
|
|
|
360
360
|
/** Debug configuration for GraphCommerce */
|
|
361
361
|
export type GraphCommerceDebugConfig = {
|
|
362
|
+
/** Enable debugging interface to debug sessions */
|
|
363
|
+
cart?: InputMaybe<Scalars['Boolean']['input']>;
|
|
362
364
|
/** Reports which plugins are enabled or disabled. */
|
|
363
365
|
pluginStatus?: InputMaybe<Scalars['Boolean']['input']>;
|
|
364
366
|
/** Enable debugging interface to debug sessions */
|
|
@@ -596,6 +598,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject<Properties<GraphCommerc
|
|
|
596
598
|
|
|
597
599
|
export function GraphCommerceDebugConfigSchema(): z.ZodObject<Properties<GraphCommerceDebugConfig>> {
|
|
598
600
|
return z.object({
|
|
601
|
+
cart: z.boolean().nullish(),
|
|
599
602
|
pluginStatus: z.boolean().nullish(),
|
|
600
603
|
sessions: z.boolean().nullish(),
|
|
601
604
|
webpackCircularDependencyPlugin: z.boolean().nullish(),
|
|
@@ -47,9 +47,9 @@ import type {
|
|
|
47
47
|
ExportNamedDeclaration,
|
|
48
48
|
ExportNamespaceSpecifier,
|
|
49
49
|
ExportSpecifier,
|
|
50
|
-
ExprOrSpread,
|
|
51
50
|
Expression,
|
|
52
51
|
ExpressionStatement,
|
|
52
|
+
ExprOrSpread,
|
|
53
53
|
Fn,
|
|
54
54
|
ForInStatement,
|
|
55
55
|
ForOfStatement,
|
|
@@ -64,10 +64,10 @@ import type {
|
|
|
64
64
|
ImportDefaultSpecifier,
|
|
65
65
|
ImportNamespaceSpecifier,
|
|
66
66
|
ImportSpecifier,
|
|
67
|
-
JSXAttrValue,
|
|
68
67
|
JSXAttribute,
|
|
69
68
|
JSXAttributeName,
|
|
70
69
|
JSXAttributeOrSpread,
|
|
70
|
+
JSXAttrValue,
|
|
71
71
|
JSXClosingElement,
|
|
72
72
|
JSXClosingFragment,
|
|
73
73
|
JSXElement,
|
|
@@ -187,6 +187,7 @@ import type {
|
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
189
|
* @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
|
|
190
|
+
* @public
|
|
190
191
|
*/
|
|
191
192
|
export class Visitor {
|
|
192
193
|
visitProgram(n: Program): Program {
|
|
@@ -1839,5 +1840,3 @@ export class Visitor {
|
|
|
1839
1840
|
return n
|
|
1840
1841
|
}
|
|
1841
1842
|
}
|
|
1842
|
-
|
|
1843
|
-
export default Visitor
|
|
@@ -18,8 +18,6 @@ import type {
|
|
|
18
18
|
TemplateLiteral,
|
|
19
19
|
} from '@swc/core'
|
|
20
20
|
|
|
21
|
-
export class NoSuchDeclarationError extends Error {}
|
|
22
|
-
|
|
23
21
|
function isIdentifier(node: Node): node is Identifier {
|
|
24
22
|
return node.type === 'Identifier'
|
|
25
23
|
}
|
|
@@ -60,35 +58,7 @@ function isTemplateLiteral(node: Node): node is TemplateLiteral {
|
|
|
60
58
|
return node.type === 'TemplateLiteral'
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
/** @example `config.runtime[0].value` */
|
|
65
|
-
path?: string
|
|
66
|
-
|
|
67
|
-
constructor(message: string, paths?: string[]) {
|
|
68
|
-
super(message)
|
|
69
|
-
|
|
70
|
-
// Generating "path" that looks like "config.runtime[0].value"
|
|
71
|
-
let codePath: string | undefined
|
|
72
|
-
if (Array.isArray(paths)) {
|
|
73
|
-
codePath = ''
|
|
74
|
-
for (const path of paths) {
|
|
75
|
-
if (path[0] === '[') {
|
|
76
|
-
// "array" + "[0]"
|
|
77
|
-
codePath += path
|
|
78
|
-
} else if (codePath === '') {
|
|
79
|
-
codePath = path
|
|
80
|
-
} else {
|
|
81
|
-
// "object" + ".key"
|
|
82
|
-
codePath += `.${path}`
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.path = codePath
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export const RUNTIME_VALUE = Symbol('RUNTIME_VALUE')
|
|
61
|
+
const RUNTIME_VALUE = Symbol('RUNTIME_VALUE')
|
|
92
62
|
|
|
93
63
|
function extractValue(node: Node, path?: string[], optional: boolean = false): any {
|
|
94
64
|
if (isNullLiteral(node)) {
|
|
@@ -116,7 +86,6 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
116
86
|
return undefined
|
|
117
87
|
default:
|
|
118
88
|
return RUNTIME_VALUE
|
|
119
|
-
// throw new UnsupportedValueError(`Unknown identifier "${node.value}"`, path)
|
|
120
89
|
}
|
|
121
90
|
} else if (isArrayExpression(node)) {
|
|
122
91
|
// e.g. [1, 2, 3]
|
|
@@ -127,10 +96,6 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
127
96
|
if (elem.spread) {
|
|
128
97
|
// e.g. [ ...a ]
|
|
129
98
|
return RUNTIME_VALUE
|
|
130
|
-
// throw new UnsupportedValueError(
|
|
131
|
-
// 'Unsupported spread operator in the Array Expression',
|
|
132
|
-
// path,
|
|
133
|
-
// )
|
|
134
99
|
}
|
|
135
100
|
|
|
136
101
|
arr.push(extractValue(elem.expression, path && [...path, `[${i}]`], optional))
|
|
@@ -148,10 +113,6 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
148
113
|
if (!isKeyValueProperty(prop)) {
|
|
149
114
|
// e.g. { ...a }
|
|
150
115
|
return RUNTIME_VALUE
|
|
151
|
-
// throw new UnsupportedValueError(
|
|
152
|
-
// 'Unsupported spread operator in the Object Expression',
|
|
153
|
-
// path,
|
|
154
|
-
// )
|
|
155
116
|
}
|
|
156
117
|
|
|
157
118
|
let key
|
|
@@ -163,10 +124,6 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
163
124
|
key = prop.key.value
|
|
164
125
|
} else {
|
|
165
126
|
return RUNTIME_VALUE
|
|
166
|
-
// throw new UnsupportedValueError(
|
|
167
|
-
// `Unsupported key type "${prop.key.type}" in the Object Expression`,
|
|
168
|
-
// path,
|
|
169
|
-
// )
|
|
170
127
|
}
|
|
171
128
|
|
|
172
129
|
obj[key] = extractValue(prop.value, path && [...path, key])
|
|
@@ -178,7 +135,6 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
178
135
|
if (node.expressions.length !== 0) {
|
|
179
136
|
// TODO: should we add support for `${'e'}d${'g'}'e'`?
|
|
180
137
|
return RUNTIME_VALUE
|
|
181
|
-
// throw new UnsupportedValueError('Unsupported template literal with expressions', path)
|
|
182
138
|
}
|
|
183
139
|
|
|
184
140
|
// When TemplateLiteral has 0 expressions, the length of quasis is always 1.
|
|
@@ -195,7 +151,6 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
195
151
|
return cooked ?? raw
|
|
196
152
|
} else {
|
|
197
153
|
return RUNTIME_VALUE
|
|
198
|
-
// throw new UnsupportedValueError(`Unsupported node type "${node.type}"`, path)
|
|
199
154
|
}
|
|
200
155
|
}
|
|
201
156
|
|
|
@@ -18,6 +18,7 @@ type PluginBaseConfig = {
|
|
|
18
18
|
ifConfig?: string | [string, any]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/** @public */
|
|
21
22
|
export function isPluginBaseConfig(plugin: Partial<PluginBaseConfig>): plugin is PluginBaseConfig {
|
|
22
23
|
return (
|
|
23
24
|
typeof plugin.type === 'string' &&
|
|
@@ -31,6 +32,7 @@ type ReactPluginConfig = PluginBaseConfig & { type: 'component' }
|
|
|
31
32
|
type MethodPluginConfig = PluginBaseConfig & { type: 'function' }
|
|
32
33
|
type ReplacePluginConfig = PluginBaseConfig & { type: 'replace' }
|
|
33
34
|
|
|
35
|
+
/** @public */
|
|
34
36
|
export function isReactPluginConfig(
|
|
35
37
|
plugin: Partial<PluginBaseConfig>,
|
|
36
38
|
): plugin is ReactPluginConfig {
|
|
@@ -38,6 +40,7 @@ export function isReactPluginConfig(
|
|
|
38
40
|
return plugin.type === 'component'
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
/** @public */
|
|
41
44
|
export function isMethodPluginConfig(
|
|
42
45
|
plugin: Partial<PluginBaseConfig>,
|
|
43
46
|
): plugin is MethodPluginConfig {
|
|
@@ -45,6 +48,7 @@ export function isMethodPluginConfig(
|
|
|
45
48
|
return plugin.type === 'function'
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
/** @public */
|
|
48
52
|
export function isReplacePluginConfig(
|
|
49
53
|
plugin: Partial<PluginBaseConfig>,
|
|
50
54
|
): plugin is ReactPluginConfig {
|
|
@@ -23,14 +23,17 @@ export class TopologicalSort<KeyType, ValueType> {
|
|
|
23
23
|
this.addMultipleInternalNodes(nodes)
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** @public */
|
|
26
27
|
addNode(key: KeyType, node: ValueType) {
|
|
27
28
|
return this.addInternalNode(key, node)
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
/** @public */
|
|
30
32
|
addNodes(nodes: Map<KeyType, ValueType>) {
|
|
31
33
|
this.addMultipleInternalNodes(nodes)
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
/** @public */
|
|
34
37
|
addEdge(fromKey: KeyType, toKey: KeyType) {
|
|
35
38
|
assert(this.#nodes.has(fromKey), `Source package with ${fromKey} key should exist`)
|
|
36
39
|
assert(this.#nodes.has(toKey), `Target package with ${toKey} key should exist`)
|
|
@@ -58,6 +61,7 @@ export class TopologicalSort<KeyType, ValueType> {
|
|
|
58
61
|
sourceNode!.children.set(toKey, targetNode!)
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/** @public */
|
|
61
65
|
sort(): Map<KeyType, INodeWithChildren<KeyType, ValueType>> {
|
|
62
66
|
this.#visitedNodes = new Set()
|
|
63
67
|
this.#sortedKeysStack = []
|