@graphcommerce/next-config 8.1.0-canary.9 → 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.
@@ -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
- if (optional) return RUNTIME_VALUE
116
- throw new UnsupportedValueError(`Unknown identifier "${node.value}"`, path)
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
- if (optional) return RUNTIME_VALUE
127
- throw new UnsupportedValueError(
128
- 'Unsupported spread operator in the Array Expression',
129
- path,
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
- if (optional) return RUNTIME_VALUE
148
- throw new UnsupportedValueError(
149
- 'Unsupported spread operator in the Object Expression',
150
- path,
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
- if (optional) return RUNTIME_VALUE
163
- throw new UnsupportedValueError(
164
- `Unsupported key type "${prop.key.type}" in the Object Expression`,
165
- path,
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
- if (optional) return RUNTIME_VALUE
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
- if (optional) return RUNTIME_VALUE
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
- `Can not find ${plug.targetModule}#${plug.sourceExport} for plugin ${plug.sourceModule}`,
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(interceptorPropsName(name(p)))
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) => isReplacePluginConfig(p) || isReactPluginConfig(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
- return exportVals
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: string[] = []
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.push(...files)
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.includes(relativeFile)) {
34
- delete existing[existing.indexOf(relativeFile)]
33
+ if (existing.has(relativeFile)) {
34
+ existing.delete(relativeFile)
35
35
  }
36
- if (existing.includes(`./${relativeFile}`)) {
37
- delete existing[existing.indexOf(`./${relativeFile}`)]
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
 
@@ -112,8 +112,19 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string): NextConf
112
112
  },
113
113
  transpilePackages,
114
114
  webpack: (config: Configuration, options) => {
115
- // Allow importing yml/yaml files for graphql-mesh
116
- config.module?.rules?.push({ test: /\.ya?ml$/, use: 'js-yaml-loader' })
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: [