@graphcommerce/next-config 9.0.4-canary.1 → 9.0.4-canary.11

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +0 -905
  3. package/__tests__/config/utils/mergeEnvIntoConfig.ts +19 -2
  4. package/__tests__/config/utils/replaceConfigInString.ts +0 -1
  5. package/__tests__/interceptors/findPlugins.ts +270 -273
  6. package/__tests__/utils/resolveDependenciesSync.ts +44 -44
  7. package/dist/generated/config.js +109 -119
  8. package/dist/index.js +3359 -26
  9. package/package.json +33 -8
  10. package/src/config/commands/generateConfig.ts +16 -4
  11. package/src/config/demoConfig.ts +0 -1
  12. package/src/config/loadConfig.ts +3 -9
  13. package/src/config/utils/mergeEnvIntoConfig.ts +8 -6
  14. package/src/generated/config.ts +17 -5
  15. package/src/interceptors/generateInterceptor.ts +0 -2
  16. package/src/interceptors/parseStructure.ts +3 -3
  17. package/src/utils/resolveDependenciesSync.ts +43 -6
  18. package/src/withGraphCommerce.ts +30 -42
  19. package/tsconfig.json +1 -1
  20. package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -79
  21. package/dist/commands/codegen.js +0 -18
  22. package/dist/commands/copyFiles.js +0 -297
  23. package/dist/config/commands/exportConfig.js +0 -16
  24. package/dist/config/commands/generateConfig.js +0 -56
  25. package/dist/config/demoConfig.js +0 -52
  26. package/dist/config/index.js +0 -19
  27. package/dist/config/loadConfig.js +0 -62
  28. package/dist/config/utils/configToImportMeta.js +0 -39
  29. package/dist/config/utils/diff.js +0 -33
  30. package/dist/config/utils/exportConfigToEnv.js +0 -31
  31. package/dist/config/utils/mergeEnvIntoConfig.js +0 -182
  32. package/dist/config/utils/replaceConfigInString.js +0 -12
  33. package/dist/config/utils/rewriteLegacyEnv.js +0 -115
  34. package/dist/interceptors/InterceptorPlugin.js +0 -108
  35. package/dist/interceptors/RenameVisitor.js +0 -19
  36. package/dist/interceptors/Visitor.js +0 -1414
  37. package/dist/interceptors/commands/codegenInterceptors.js +0 -22
  38. package/dist/interceptors/extractExports.js +0 -159
  39. package/dist/interceptors/findOriginalSource.js +0 -103
  40. package/dist/interceptors/findPlugins.js +0 -68
  41. package/dist/interceptors/generateInterceptor.js +0 -219
  42. package/dist/interceptors/generateInterceptors.js +0 -56
  43. package/dist/interceptors/parseStructure.js +0 -84
  44. package/dist/interceptors/swc.js +0 -15
  45. package/dist/interceptors/writeInterceptors.js +0 -44
  46. package/dist/utils/PackagesSort.js +0 -7
  47. package/dist/utils/TopologicalSort.js +0 -87
  48. package/dist/utils/isMonorepo.js +0 -47
  49. package/dist/utils/packageRoots.js +0 -31
  50. package/dist/utils/resolveDependenciesSync.js +0 -78
  51. package/dist/utils/resolveDependency.js +0 -70
  52. package/dist/utils/sig.js +0 -34
  53. package/dist/withGraphCommerce.js +0 -162
  54. package/src/config/utils/rewriteLegacyEnv.ts +0 -125
@@ -1,125 +0,0 @@
1
- import cloneDeep from 'lodash/cloneDeep'
2
- import type { GraphCommerceConfig } from '../../generated/config'
3
- import type { ApplyResult, ZodNode } from './mergeEnvIntoConfig'
4
- import { mergeEnvIntoConfig } from './mergeEnvIntoConfig'
5
-
6
- export function rewriteLegacyEnv(
7
- schema: ZodNode,
8
- env: Record<string, string | undefined>,
9
- config: Partial<GraphCommerceConfig> = {},
10
- ) {
11
- const clonedEnv: Record<string, string | undefined> = cloneDeep(env)
12
- const applied: ApplyResult = []
13
-
14
- function renamedTo(to: string) {
15
- return (envVar: string, envValue: string) => {
16
- applied.push({
17
- warning: [`should be renamed to ${to}='${envValue}'`],
18
- envVar,
19
- envValue,
20
- })
21
- clonedEnv[to] = envValue
22
- }
23
- }
24
-
25
- function notUsed() {
26
- return (envVar: string, envValue: string) => {
27
- applied.push({
28
- warning: ['should be removed'],
29
- envVar,
30
- envValue,
31
- })
32
- }
33
- }
34
-
35
- const parsers: Record<string, (key: string, value: string) => void> = {
36
- MAGENTO_ENDPOINT: renamedTo('GC_MAGENTO_ENDPOINT'),
37
- GRAPHCMS_URL: renamedTo('GC_HYGRAPH_ENDPOINT'),
38
- NEXT_PUBLIC_GRAPHQL_ENDPOINT: notUsed(),
39
- IMAGE_DOMAINS: (envVar: string, envValue: string) => {
40
- applied.push({
41
- warning: [
42
- 'should be removed: will automatically add the Magento/Hygraph URL. For more advanced configurations, see: https://nextjs.org/docs/api-reference/next/image#configuration-options',
43
- ],
44
- envVar,
45
- envValue,
46
- })
47
- },
48
- NEXT_PUBLIC_LOCALE_STORES: (envVar: string, envValue: string) => {
49
- const parsed = JSON.parse(envValue) as Record<string, string>
50
-
51
- applied.push({
52
- warning: ['env variable is is modified, rewritten to GC_STOREFRONT.'],
53
- envVar,
54
- envValue,
55
- })
56
-
57
- clonedEnv.GC_STOREFRONT = JSON.stringify(
58
- Object.entries(parsed).map(([locale, magentoStoreCode], index) => {
59
- if (!config.storefront) config.storefront = []
60
- config.storefront[index] = { ...config.storefront[index], locale, magentoStoreCode }
61
- return { locale, magentoStoreCode }
62
- }),
63
- )
64
- },
65
- NEXT_PUBLIC_SITE_URL: renamedTo('GC_CANONICAL_BASE_URL'),
66
- NEXT_PUBLIC_GTM_ID: renamedTo('GC_GOOGLE_TAGMANAGER_ID'),
67
- NEXT_PUBLIC_GOOGLE_ANALYTICS: (envVar: string, envValue: string) => {
68
- if (envValue.startsWith('{')) {
69
- const parsed = JSON.parse(envValue) as Record<string, string>
70
-
71
- clonedEnv.GC_GOOGLE_ANALYTICS_ID = 'enabled'
72
- if (!config.storefront) config.storefront = []
73
- config.storefront.forEach((storefront, index) => {
74
- if (parsed[storefront.locale]) {
75
- clonedEnv[`GC_STOREFRONT_${index}_GOOGLE_ANALYTICS_ID`] = parsed[storefront.locale]
76
- }
77
- })
78
-
79
- applied.push({
80
- warning: ['should be rewritten to GC_STOREFRONT_*_GOOGLE_ANALYTICS_ID'],
81
- envVar,
82
- envValue,
83
- })
84
-
85
- return
86
- }
87
- renamedTo('GC_GOOGLE_ANALYTICS_ID')
88
- },
89
- NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY: renamedTo('GC_GOOGLE_RECAPTCHA_KEY'),
90
- NEXT_PUBLIC_DISPLAY_INCL_TAX: (envVar: string, envValue: string) => {
91
- const inclTax = envValue.split(',').map((i) => i.trim())
92
-
93
- if (!config.storefront) config.storefront = []
94
- config.storefront.forEach((storefront, index) => {
95
- if (!inclTax.includes(storefront.locale)) return
96
- clonedEnv[`GC_STOREFRONT_${index}_CART_DISPLAY_PRICES_INCL_TAX`] = '1'
97
- })
98
-
99
- applied.push({
100
- warning: ['env variable is renamed, move to configuration: cartDisplayPricesInclTax'],
101
- envVar,
102
- envValue,
103
- })
104
- clonedEnv.GC_DISPLAY_PRICES_INCL_TAX = envValue
105
- },
106
- PREVIEW_SECRET: renamedTo('GC_PREVIEW_SECRET'),
107
- DEMO_MAGENTO_GRAPHCOMMERCE: renamedTo('GC_DEMO_MODE'),
108
- }
109
-
110
- if (env.SKIP_MIGRATION === '1' || env.SKIP_MIGRATION === 'true') {
111
- return mergeEnvIntoConfig(schema, config, clonedEnv)
112
- }
113
-
114
- Object.entries(env).forEach(([key, value]) => {
115
- if (value === undefined) return
116
- try {
117
- parsers[key]?.(key, value)
118
- } catch (e) {
119
- console.error(`Error parsing ${key}`, e)
120
- }
121
- })
122
-
123
- const [newConfig, envApplied] = mergeEnvIntoConfig(schema, config, clonedEnv)
124
- return [newConfig, [...applied, ...envApplied] as ApplyResult] as const
125
- }