@graphcommerce/next-config 8.1.0-canary.8 → 9.0.0-canary.54
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 +138 -0
- package/Config.graphqls +5 -5
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +48 -2
- package/__tests__/config/utils/configToImportMeta.ts +0 -4
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +15 -2
- package/__tests__/config/utils/rewriteLegancyEnv.ts +1 -1
- package/__tests__/interceptors/findPlugins.ts +60 -126
- package/__tests__/interceptors/generateInterceptors.ts +136 -57
- package/__tests__/interceptors/parseStructure.ts +50 -0
- package/dist/config/demoConfig.js +5 -0
- package/dist/config/utils/mergeEnvIntoConfig.js +8 -1
- package/dist/generated/config.js +17 -9
- package/dist/interceptors/extractExports.js +21 -18
- package/dist/interceptors/findOriginalSource.js +17 -1
- package/dist/interceptors/generateInterceptor.js +3 -4
- package/dist/interceptors/parseStructure.js +9 -1
- package/dist/interceptors/writeInterceptors.js +7 -7
- package/dist/withGraphCommerce.js +13 -4
- package/package.json +1 -1
- package/src/config/demoConfig.ts +5 -0
- package/src/config/utils/mergeEnvIntoConfig.ts +9 -1
- package/src/generated/config.ts +56 -14
- package/src/interceptors/extractExports.ts +21 -21
- package/src/interceptors/findOriginalSource.ts +16 -1
- package/src/interceptors/generateInterceptor.ts +3 -5
- package/src/interceptors/parseStructure.ts +14 -1
- package/src/interceptors/writeInterceptors.ts +7 -7
- package/src/withGraphCommerce.ts +13 -5
|
@@ -112,8 +112,8 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
112
112
|
case 'undefined':
|
|
113
113
|
return undefined
|
|
114
114
|
default:
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
return RUNTIME_VALUE
|
|
116
|
+
// throw new UnsupportedValueError(`Unknown identifier "${node.value}"`, path)
|
|
117
117
|
}
|
|
118
118
|
} else if (isArrayExpression(node)) {
|
|
119
119
|
// e.g. [1, 2, 3]
|
|
@@ -123,11 +123,11 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
123
123
|
if (elem) {
|
|
124
124
|
if (elem.spread) {
|
|
125
125
|
// e.g. [ ...a ]
|
|
126
|
-
|
|
127
|
-
throw new UnsupportedValueError(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
)
|
|
126
|
+
return RUNTIME_VALUE
|
|
127
|
+
// throw new UnsupportedValueError(
|
|
128
|
+
// 'Unsupported spread operator in the Array Expression',
|
|
129
|
+
// path,
|
|
130
|
+
// )
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
arr.push(extractValue(elem.expression, path && [...path, `[${i}]`], optional))
|
|
@@ -144,11 +144,11 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
144
144
|
for (const prop of node.properties) {
|
|
145
145
|
if (!isKeyValueProperty(prop)) {
|
|
146
146
|
// e.g. { ...a }
|
|
147
|
-
|
|
148
|
-
throw new UnsupportedValueError(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
)
|
|
147
|
+
return RUNTIME_VALUE
|
|
148
|
+
// throw new UnsupportedValueError(
|
|
149
|
+
// 'Unsupported spread operator in the Object Expression',
|
|
150
|
+
// path,
|
|
151
|
+
// )
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
let key
|
|
@@ -159,11 +159,11 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
159
159
|
// e.g. { "a": 1, "b": 2 }
|
|
160
160
|
key = prop.key.value
|
|
161
161
|
} else {
|
|
162
|
-
|
|
163
|
-
throw new UnsupportedValueError(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
)
|
|
162
|
+
return RUNTIME_VALUE
|
|
163
|
+
// throw new UnsupportedValueError(
|
|
164
|
+
// `Unsupported key type "${prop.key.type}" in the Object Expression`,
|
|
165
|
+
// path,
|
|
166
|
+
// )
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
obj[key] = extractValue(prop.value, path && [...path, key])
|
|
@@ -174,8 +174,8 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
174
174
|
// e.g. `abc`
|
|
175
175
|
if (node.expressions.length !== 0) {
|
|
176
176
|
// TODO: should we add support for `${'e'}d${'g'}'e'`?
|
|
177
|
-
|
|
178
|
-
throw new UnsupportedValueError('Unsupported template literal with expressions', path)
|
|
177
|
+
return RUNTIME_VALUE
|
|
178
|
+
// throw new UnsupportedValueError('Unsupported template literal with expressions', path)
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
// When TemplateLiteral has 0 expressions, the length of quasis is always 1.
|
|
@@ -191,8 +191,8 @@ function extractValue(node: Node, path?: string[], optional: boolean = false): a
|
|
|
191
191
|
|
|
192
192
|
return cooked ?? raw
|
|
193
193
|
} else {
|
|
194
|
-
|
|
195
|
-
throw new UnsupportedValueError(`Unsupported node type "${node.type}"`, path)
|
|
194
|
+
return RUNTIME_VALUE
|
|
195
|
+
// throw new UnsupportedValueError(`Unsupported node type "${node.type}"`, path)
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -32,6 +32,21 @@ function parseAndFindExport(
|
|
|
32
32
|
break
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
+
|
|
36
|
+
if (node.type === 'ExportNamedDeclaration') {
|
|
37
|
+
for (const specifier of node.specifiers) {
|
|
38
|
+
if (specifier.type === 'ExportSpecifier') {
|
|
39
|
+
if (specifier.exported?.value === findExport) return resolved
|
|
40
|
+
} else if (specifier.type === 'ExportDefaultSpecifier') {
|
|
41
|
+
// todo
|
|
42
|
+
} else if (specifier.type === 'ExportNamespaceSpecifier') {
|
|
43
|
+
// todo
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// todo: if (node.type === 'ExportDefaultDeclaration') {}
|
|
49
|
+
// todo: if (node.type === 'ExportDefaultExpression') {}
|
|
35
50
|
}
|
|
36
51
|
|
|
37
52
|
const exports = ast.body
|
|
@@ -95,7 +110,7 @@ export function findOriginalSource(
|
|
|
95
110
|
return {
|
|
96
111
|
resolved: undefined,
|
|
97
112
|
error: new Error(
|
|
98
|
-
`
|
|
113
|
+
`Plugin target not found ${plug.targetModule}#${plug.sourceExport} for plugin ${plug.sourceModule}#${plug.sourceExport}`,
|
|
99
114
|
),
|
|
100
115
|
}
|
|
101
116
|
}
|
|
@@ -74,7 +74,7 @@ const sourceSuffix = 'Plugin'
|
|
|
74
74
|
const interceptorSuffix = 'Interceptor'
|
|
75
75
|
const disabledSuffix = 'Disabled'
|
|
76
76
|
const name = (plugin: PluginConfig) =>
|
|
77
|
-
`${plugin.sourceModule
|
|
77
|
+
`${plugin.sourceExport}${plugin.sourceModule
|
|
78
78
|
.split('/')
|
|
79
79
|
[plugin.sourceModule.split('/').length - 1].replace(/[^a-zA-Z0-9]/g, '')}`
|
|
80
80
|
|
|
@@ -180,9 +180,7 @@ export async function generateInterceptor(
|
|
|
180
180
|
s.replace(originalSuffix, disabledSuffix),
|
|
181
181
|
).visitModule(ast)
|
|
182
182
|
|
|
183
|
-
carryProps.push(
|
|
184
|
-
|
|
185
|
-
result = `type ${interceptorPropsName(name(p))} = React.ComponentProps<typeof ${sourceName(name(p))}>`
|
|
183
|
+
carryProps.push(`React.ComponentProps<typeof ${sourceName(name(p))}>`)
|
|
186
184
|
|
|
187
185
|
pluginSee.push(
|
|
188
186
|
`@see {${sourceName(name(p))}} for replacement of the original source (original source not used)`,
|
|
@@ -225,7 +223,7 @@ export async function generateInterceptor(
|
|
|
225
223
|
.filter((v) => !!v)
|
|
226
224
|
.join('\n')
|
|
227
225
|
|
|
228
|
-
const isComponent = plugins.every((p) =>
|
|
226
|
+
const isComponent = plugins.every((p) => isReactPluginConfig(p))
|
|
229
227
|
if (isComponent && plugins.some((p) => isMethodPluginConfig(p))) {
|
|
230
228
|
throw new Error(`Cannot mix React and Method plugins for ${base} in ${dependency}.`)
|
|
231
229
|
}
|
|
@@ -34,10 +34,11 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
|
|
|
34
34
|
} = exports
|
|
35
35
|
|
|
36
36
|
const exportVals = Object.keys(rest)
|
|
37
|
+
|
|
37
38
|
if (component && !moduleConfig) exportVals.push('Plugin')
|
|
38
39
|
if (func && !moduleConfig) exportVals.push('plugin')
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
const pluginConfigs = exportVals
|
|
41
42
|
.map((exportVal) => {
|
|
42
43
|
let config = isObject(moduleConfig) ? moduleConfig : {}
|
|
43
44
|
|
|
@@ -49,6 +50,7 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
|
|
|
49
50
|
config = { ...moduleConfig, export: exportVal }
|
|
50
51
|
} else {
|
|
51
52
|
console.error(`Plugin configuration invalid! See ${sourceModule}`)
|
|
53
|
+
return null
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const parsed = pluginConfigParsed.safeParse(config)
|
|
@@ -79,4 +81,15 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
|
|
|
79
81
|
return val
|
|
80
82
|
})
|
|
81
83
|
.filter(nonNullable)
|
|
84
|
+
|
|
85
|
+
const newPluginConfigs = pluginConfigs.reduce<PluginConfig[]>((acc, pluginConfig) => {
|
|
86
|
+
if (
|
|
87
|
+
!acc.find((accPluginConfig) => accPluginConfig.sourceExport === pluginConfig.sourceExport)
|
|
88
|
+
) {
|
|
89
|
+
acc.push(pluginConfig)
|
|
90
|
+
}
|
|
91
|
+
return acc
|
|
92
|
+
}, [])
|
|
93
|
+
|
|
94
|
+
return newPluginConfigs
|
|
82
95
|
}
|
|
@@ -17,24 +17,24 @@ export async function writeInterceptors(
|
|
|
17
17
|
cwd: string = process.cwd(),
|
|
18
18
|
) {
|
|
19
19
|
const dependencies = resolveDependenciesSync(cwd)
|
|
20
|
-
const existing
|
|
20
|
+
const existing = new Set<string>()
|
|
21
21
|
dependencies.forEach((dependency) => {
|
|
22
22
|
const files = globSync(
|
|
23
23
|
[`${dependency}/**/*.interceptor.tsx`, `${dependency}/**/*.interceptor.ts`],
|
|
24
24
|
{ cwd },
|
|
25
25
|
)
|
|
26
|
-
existing.
|
|
26
|
+
files.forEach((file) => existing.add(file))
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
const written = Object.entries(interceptors).map(async ([, plugin]) => {
|
|
30
30
|
const extension = plugin.sourcePath.endsWith('.tsx') ? '.tsx' : '.ts'
|
|
31
31
|
const relativeFile = `${plugin.fromRoot}.interceptor${extension}`
|
|
32
32
|
|
|
33
|
-
if (existing.
|
|
34
|
-
|
|
33
|
+
if (existing.has(relativeFile)) {
|
|
34
|
+
existing.delete(relativeFile)
|
|
35
35
|
}
|
|
36
|
-
if (existing.
|
|
37
|
-
|
|
36
|
+
if (existing.has(`./${relativeFile}`)) {
|
|
37
|
+
existing.delete(`./${relativeFile}`)
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const fileToWrite = path.join(cwd, relativeFile)
|
|
@@ -47,7 +47,7 @@ export async function writeInterceptors(
|
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
// Cleanup unused interceptors
|
|
50
|
-
const cleaned = existing.map(
|
|
50
|
+
const cleaned = [...existing].map(
|
|
51
51
|
async (file) => (await checkFileExists(file)) && (await fs.unlink(file)),
|
|
52
52
|
)
|
|
53
53
|
|
package/src/withGraphCommerce.ts
CHANGED
|
@@ -112,8 +112,19 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf
|
|
|
112
112
|
},
|
|
113
113
|
transpilePackages,
|
|
114
114
|
webpack: (config: Configuration, options) => {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
if (!config.module) config.module = { rules: [] }
|
|
116
|
+
|
|
117
|
+
config.module = {
|
|
118
|
+
...config.module,
|
|
119
|
+
rules: [
|
|
120
|
+
...(config.module.rules ?? []),
|
|
121
|
+
// Allow importing yml/yaml files for graphql-mesh
|
|
122
|
+
{ test: /\.ya?ml$/, use: 'js-yaml-loader' },
|
|
123
|
+
// @lingui .po file support
|
|
124
|
+
{ test: /\.po/, use: '@lingui/loader' },
|
|
125
|
+
],
|
|
126
|
+
exprContextCritical: false,
|
|
127
|
+
}
|
|
117
128
|
|
|
118
129
|
if (!config.plugins) config.plugins = []
|
|
119
130
|
|
|
@@ -148,9 +159,6 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf
|
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
|
|
151
|
-
// @lingui .po file support
|
|
152
|
-
config.module?.rules?.push({ test: /\.po/, use: '@lingui/loader' })
|
|
153
|
-
|
|
154
162
|
config.snapshot = {
|
|
155
163
|
...(config.snapshot ?? {}),
|
|
156
164
|
managedPaths: [
|