@graphcommerce/next-config 9.0.4-canary.1 → 9.0.4-canary.10
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 +30 -0
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +0 -905
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +19 -2
- package/__tests__/config/utils/replaceConfigInString.ts +0 -1
- package/__tests__/interceptors/findPlugins.ts +270 -273
- package/__tests__/utils/resolveDependenciesSync.ts +44 -44
- package/dist/generated/config.js +109 -119
- package/dist/index.js +3359 -26
- package/package.json +33 -8
- package/src/config/commands/generateConfig.ts +16 -4
- package/src/config/demoConfig.ts +0 -1
- package/src/config/loadConfig.ts +3 -9
- package/src/config/utils/mergeEnvIntoConfig.ts +8 -6
- package/src/generated/config.ts +17 -5
- package/src/interceptors/generateInterceptor.ts +0 -2
- package/src/interceptors/parseStructure.ts +3 -3
- package/src/utils/resolveDependenciesSync.ts +43 -6
- package/src/withGraphCommerce.ts +30 -42
- package/tsconfig.json +1 -1
- package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -79
- package/dist/commands/codegen.js +0 -18
- package/dist/commands/copyFiles.js +0 -297
- package/dist/config/commands/exportConfig.js +0 -16
- package/dist/config/commands/generateConfig.js +0 -56
- package/dist/config/demoConfig.js +0 -52
- package/dist/config/index.js +0 -19
- package/dist/config/loadConfig.js +0 -62
- package/dist/config/utils/configToImportMeta.js +0 -39
- package/dist/config/utils/diff.js +0 -33
- package/dist/config/utils/exportConfigToEnv.js +0 -31
- package/dist/config/utils/mergeEnvIntoConfig.js +0 -182
- package/dist/config/utils/replaceConfigInString.js +0 -12
- package/dist/config/utils/rewriteLegacyEnv.js +0 -115
- package/dist/interceptors/InterceptorPlugin.js +0 -108
- package/dist/interceptors/RenameVisitor.js +0 -19
- package/dist/interceptors/Visitor.js +0 -1414
- package/dist/interceptors/commands/codegenInterceptors.js +0 -22
- package/dist/interceptors/extractExports.js +0 -159
- package/dist/interceptors/findOriginalSource.js +0 -103
- package/dist/interceptors/findPlugins.js +0 -68
- package/dist/interceptors/generateInterceptor.js +0 -219
- package/dist/interceptors/generateInterceptors.js +0 -56
- package/dist/interceptors/parseStructure.js +0 -84
- package/dist/interceptors/swc.js +0 -15
- package/dist/interceptors/writeInterceptors.js +0 -44
- package/dist/utils/PackagesSort.js +0 -7
- package/dist/utils/TopologicalSort.js +0 -87
- package/dist/utils/isMonorepo.js +0 -47
- package/dist/utils/packageRoots.js +0 -31
- package/dist/utils/resolveDependenciesSync.js +0 -78
- package/dist/utils/resolveDependency.js +0 -70
- package/dist/utils/sig.js +0 -34
- package/dist/withGraphCommerce.js +0 -162
- package/src/config/utils/rewriteLegacyEnv.ts +0 -125
package/package.json
CHANGED
|
@@ -2,28 +2,38 @@
|
|
|
2
2
|
"name": "@graphcommerce/next-config",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "9.0.4-canary.
|
|
6
|
-
"type": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"version": "9.0.4-canary.10",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"types": "./src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./config": {
|
|
13
|
+
"default": "./dist/generated/config.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
"scripts": {
|
|
10
|
-
"dev": "
|
|
11
|
-
"build": "
|
|
12
|
-
"prepack": "
|
|
17
|
+
"dev": "pkgroll --clean-dist --watch",
|
|
18
|
+
"build": "pkgroll --clean-dist",
|
|
19
|
+
"prepack": "pkgroll --clean-dist"
|
|
13
20
|
},
|
|
14
21
|
"dependencies": {
|
|
15
22
|
"@graphql-codegen/cli": "5.0.3",
|
|
16
23
|
"@swc/core": "1.10.1",
|
|
17
24
|
"@swc/wasm-web": "^1.10.1",
|
|
18
25
|
"@types/circular-dependency-plugin": "^5.0.8",
|
|
26
|
+
"@types/js-yaml": "^4",
|
|
19
27
|
"@types/lodash": "^4.17.13",
|
|
20
28
|
"babel-plugin-macros": "^3.1.0",
|
|
21
29
|
"chalk": "^4",
|
|
22
30
|
"circular-dependency-plugin": "^5.2.2",
|
|
31
|
+
"cosmiconfig": "^8.3.6",
|
|
23
32
|
"fast-glob": "^3.3.2",
|
|
24
33
|
"glob": "^10.4.5",
|
|
25
34
|
"graphql": "^16.10.0",
|
|
26
35
|
"inspectpack": "^4.7.1",
|
|
36
|
+
"js-yaml": "^4.1.0",
|
|
27
37
|
"js-yaml-loader": "^1.2.2",
|
|
28
38
|
"lodash": "^4.17.21",
|
|
29
39
|
"react": "^18.3.1",
|
|
@@ -33,10 +43,25 @@
|
|
|
33
43
|
"zod": "^3.24.1"
|
|
34
44
|
},
|
|
35
45
|
"peerDependencies": {
|
|
46
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.4-canary.10",
|
|
36
47
|
"@lingui/loader": "*",
|
|
37
48
|
"@lingui/macro": "*",
|
|
38
49
|
"@lingui/react": "*",
|
|
39
50
|
"dotenv": "^16",
|
|
40
|
-
"next": "*"
|
|
51
|
+
"next": "*",
|
|
52
|
+
"prettier": "^3"
|
|
53
|
+
},
|
|
54
|
+
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
55
|
+
"eslint": {
|
|
56
|
+
"extends": "@graphcommerce/eslint-config-pwa"
|
|
57
|
+
},
|
|
58
|
+
"eslintConfig": {
|
|
59
|
+
"extends": "@graphcommerce/eslint-config-pwa",
|
|
60
|
+
"parserOptions": {
|
|
61
|
+
"project": "./tsconfig.json"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"pkgroll": "^2.5.1"
|
|
41
66
|
}
|
|
42
67
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { writeFileSync } from 'fs'
|
|
1
|
+
import { readFileSync, writeFileSync } from 'fs'
|
|
2
|
+
import prettierConf from '@graphcommerce/prettier-config-pwa'
|
|
2
3
|
import { generate } from '@graphql-codegen/cli'
|
|
3
4
|
import { transformFileSync } from '@swc/core'
|
|
4
5
|
import dotenv from 'dotenv'
|
|
6
|
+
import prettier from 'prettier'
|
|
5
7
|
import { findParentPath } from '../../utils/isMonorepo'
|
|
6
8
|
import { resolveDependenciesSync } from '../../utils/resolveDependenciesSync'
|
|
7
9
|
import { resolveDependency } from '../../utils/resolveDependency'
|
|
@@ -26,10 +28,9 @@ export async function generateConfig() {
|
|
|
26
28
|
schema: ['graphql/**/Config.graphqls', ...schemaLocations],
|
|
27
29
|
generates: {
|
|
28
30
|
[targetTs]: {
|
|
29
|
-
plugins: ['typescript', 'typescript-validation-schema'
|
|
31
|
+
plugins: ['typescript', 'typescript-validation-schema'],
|
|
30
32
|
config: {
|
|
31
33
|
// enumsAsTypes: true,
|
|
32
|
-
content: '/* eslint-disable */',
|
|
33
34
|
schema: 'zod',
|
|
34
35
|
notAllowEmptyString: true,
|
|
35
36
|
strictScalars: true,
|
|
@@ -49,8 +50,19 @@ export async function generateConfig() {
|
|
|
49
50
|
},
|
|
50
51
|
})
|
|
51
52
|
|
|
53
|
+
writeFileSync(
|
|
54
|
+
targetTs,
|
|
55
|
+
await prettier.format(readFileSync(targetTs, 'utf-8'), {
|
|
56
|
+
...prettierConf,
|
|
57
|
+
parser: 'typescript',
|
|
58
|
+
plugins: prettierConf.plugins?.filter(
|
|
59
|
+
(p) => typeof p === 'string' && !p.includes('prettier-plugin-sort-imports'),
|
|
60
|
+
),
|
|
61
|
+
}),
|
|
62
|
+
)
|
|
63
|
+
|
|
52
64
|
const result = transformFileSync(targetTs, {
|
|
53
|
-
module: { type: '
|
|
65
|
+
module: { type: 'nodenext' },
|
|
54
66
|
env: { targets: { node: '18' } },
|
|
55
67
|
})
|
|
56
68
|
|
package/src/config/demoConfig.ts
CHANGED
package/src/config/loadConfig.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
2
|
import { cosmiconfigSync } from 'cosmiconfig'
|
|
4
3
|
import type { GraphCommerceConfig } from '../generated/config'
|
|
5
4
|
import { GraphCommerceConfigSchema } from '../generated/config'
|
|
6
5
|
import { demoConfig } from './demoConfig'
|
|
7
|
-
import { formatAppliedEnv } from './utils/mergeEnvIntoConfig'
|
|
8
|
-
import { rewriteLegacyEnv } from './utils/rewriteLegacyEnv'
|
|
6
|
+
import { formatAppliedEnv, mergeEnvIntoConfig } from './utils/mergeEnvIntoConfig'
|
|
9
7
|
|
|
10
8
|
export * from './utils/configToImportMeta'
|
|
11
9
|
export * from './utils/replaceConfigInString'
|
|
@@ -28,12 +26,8 @@ export function loadConfig(cwd: string): GraphCommerceConfig {
|
|
|
28
26
|
confFile ||= {}
|
|
29
27
|
|
|
30
28
|
const schema = GraphCommerceConfigSchema()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
process.env,
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
35
|
-
confFile,
|
|
36
|
-
)
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
30
|
+
const [mergedConfig, applyResult] = mergeEnvIntoConfig(schema, confFile, process.env)
|
|
37
31
|
|
|
38
32
|
if (applyResult.length > 0 && isMainProcess) console.log(formatAppliedEnv(applyResult))
|
|
39
33
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
1
|
import { cloneDeep, mergeDeep } from '@apollo/client/utilities'
|
|
3
2
|
import chalk from 'chalk'
|
|
4
|
-
import
|
|
5
|
-
import snakeCase from 'lodash/snakeCase'
|
|
3
|
+
import lodash from 'lodash'
|
|
6
4
|
import type { ZodAny, ZodRawShape, ZodTypeAny } from 'zod'
|
|
7
5
|
import {
|
|
8
6
|
z,
|
|
@@ -19,7 +17,11 @@ import {
|
|
|
19
17
|
} from 'zod'
|
|
20
18
|
import diff from './diff'
|
|
21
19
|
|
|
22
|
-
const fmt = (s: string) =>
|
|
20
|
+
const fmt = (s: string) =>
|
|
21
|
+
s
|
|
22
|
+
.split(/(\d+)/)
|
|
23
|
+
.map((v) => lodash.snakeCase(v))
|
|
24
|
+
.join('')
|
|
23
25
|
export const toEnvStr = (path: string[]) => ['GC', ...path].map(fmt).join('_').toUpperCase()
|
|
24
26
|
const dotNotation = (pathParts: string[]) =>
|
|
25
27
|
pathParts
|
|
@@ -178,14 +180,14 @@ export function mergeEnvIntoConfig(
|
|
|
178
180
|
return
|
|
179
181
|
}
|
|
180
182
|
|
|
181
|
-
const dotValue = get(newConfig, dotVar)
|
|
183
|
+
const dotValue = lodash.get(newConfig, dotVar)
|
|
182
184
|
const merged = mergeDeep(dotValue, value)
|
|
183
185
|
|
|
184
186
|
const from = diff(merged, dotValue)
|
|
185
187
|
const to = diff(dotValue, merged)
|
|
186
188
|
|
|
187
189
|
applyResult.push({ envVar, envValue, dotVar, from, to })
|
|
188
|
-
set(newConfig, dotVar, merged)
|
|
190
|
+
lodash.set(newConfig, dotVar, merged)
|
|
189
191
|
})
|
|
190
192
|
|
|
191
193
|
return [newConfig, applyResult] as const
|
package/src/generated/config.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
1
|
import { z } from 'zod'
|
|
3
|
-
|
|
4
2
|
export type Maybe<T> = T | null
|
|
5
3
|
export type InputMaybe<T> = Maybe<T>
|
|
6
4
|
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }
|
|
@@ -55,7 +53,12 @@ export type DatalayerConfig = {
|
|
|
55
53
|
* Configuration can be accessed in your project with the `import.meta.graphCommerce` object.
|
|
56
54
|
*
|
|
57
55
|
* ```tsx
|
|
58
|
-
* import {
|
|
56
|
+
* import {
|
|
57
|
+
* storefrontAll,
|
|
58
|
+
* storefrontConfig,
|
|
59
|
+
* storefrontConfigDefault,
|
|
60
|
+
* useStorefrontConfig,
|
|
61
|
+
* } from '@graphcommerce/next-ui'
|
|
59
62
|
*
|
|
60
63
|
* // Accessing a global value
|
|
61
64
|
* const globalConf = import.meta.graphCommerce.cartDisplayPricesInclTax
|
|
@@ -69,7 +72,8 @@ export type DatalayerConfig = {
|
|
|
69
72
|
*
|
|
70
73
|
* // Or as single line
|
|
71
74
|
* const scopedConfigWithFallback2 =
|
|
72
|
-
* useStorefrontConfig().cartDisplayPricesInclTax ??
|
|
75
|
+
* useStorefrontConfig().cartDisplayPricesInclTax ??
|
|
76
|
+
* import.meta.graphCommerce.cartDisplayPricesInclTax
|
|
73
77
|
*
|
|
74
78
|
* return <div>{googleRecaptchaKey}</div>
|
|
75
79
|
* }
|
|
@@ -254,7 +258,14 @@ export type GraphCommerceConfig = {
|
|
|
254
258
|
*/
|
|
255
259
|
googleTagmanagerId?: InputMaybe<Scalars['String']['input']>
|
|
256
260
|
/**
|
|
257
|
-
* The
|
|
261
|
+
* The GraphQL Mesh will be loaded once and any modifications to resolvers will be ignored. When
|
|
262
|
+
* developing new resolvers this should be set to true.
|
|
263
|
+
*/
|
|
264
|
+
graphqlMeshEditMode?: InputMaybe<Scalars['Boolean']['input']>
|
|
265
|
+
/**
|
|
266
|
+
* The HyGraph endpoint.
|
|
267
|
+
*
|
|
268
|
+
* > Read-only endpoint that allows low latency and high read-throughput content delivery.
|
|
258
269
|
*
|
|
259
270
|
* Project settings -> API Access -> High Performance Read-only Content API
|
|
260
271
|
*/
|
|
@@ -610,6 +621,7 @@ export function GraphCommerceConfigSchema(): z.ZodObject<Properties<GraphCommerc
|
|
|
610
621
|
googlePlaystore: GraphCommerceGooglePlaystoreConfigSchema().nullish(),
|
|
611
622
|
googleRecaptchaKey: z.string().nullish(),
|
|
612
623
|
googleTagmanagerId: z.string().nullish(),
|
|
624
|
+
graphqlMeshEditMode: z.boolean().default(false).nullish(),
|
|
613
625
|
hygraphEndpoint: z.string().min(1),
|
|
614
626
|
hygraphManagementApi: z.string().nullish(),
|
|
615
627
|
hygraphProjectId: z.string().nullish(),
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
1
|
import prettierConf from '@graphcommerce/prettier-config-pwa'
|
|
3
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
2
|
import prettier from 'prettier'
|
|
5
3
|
import type { GraphCommerceDebugConfig } from '../generated/config'
|
|
6
4
|
import type { ResolveDependencyReturn } from '../utils/resolveDependency'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Module } from '@swc/core'
|
|
2
|
-
import
|
|
2
|
+
import lodash from 'lodash'
|
|
3
3
|
import { z } from 'zod'
|
|
4
4
|
import type { GraphCommerceConfig } from '../generated/config'
|
|
5
5
|
import { extractExports } from './extractExports'
|
|
@@ -66,12 +66,12 @@ export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourc
|
|
|
66
66
|
if (parsed.data.ifConfig) {
|
|
67
67
|
if (Array.isArray(parsed.data.ifConfig)) {
|
|
68
68
|
const isBoolean = typeof parsed.data.ifConfig[1] === 'boolean'
|
|
69
|
-
let confValue = get(gcConfig, parsed.data.ifConfig[0])
|
|
69
|
+
let confValue = lodash.get(gcConfig, parsed.data.ifConfig[0])
|
|
70
70
|
confValue = isBoolean ? Boolean(confValue) : confValue
|
|
71
71
|
|
|
72
72
|
enabled = confValue === parsed.data.ifConfig[1]
|
|
73
73
|
} else {
|
|
74
|
-
enabled = Boolean(get(gcConfig, parsed.data.ifConfig))
|
|
74
|
+
enabled = Boolean(lodash.get(gcConfig, parsed.data.ifConfig))
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -9,6 +9,17 @@ type DependencyStructure = Record<string, { dirName: string; dependencies: strin
|
|
|
9
9
|
|
|
10
10
|
const resolveCache: Map<string, PackageNames> = new Map<string, PackageNames>()
|
|
11
11
|
|
|
12
|
+
function findPackageJson(id: string, root: string) {
|
|
13
|
+
let dir = id.startsWith('/') ? id : require.resolve(id)
|
|
14
|
+
let packageJsonLocation = path.join(dir, 'package.json')
|
|
15
|
+
while (!fs.existsSync(packageJsonLocation)) {
|
|
16
|
+
dir = path.dirname(dir)
|
|
17
|
+
if (dir === root) throw Error(`Can't find package.json for ${id}`)
|
|
18
|
+
packageJsonLocation = path.join(dir, 'package.json')
|
|
19
|
+
}
|
|
20
|
+
return packageJsonLocation
|
|
21
|
+
}
|
|
22
|
+
|
|
12
23
|
function resolveRecursivePackageJson(
|
|
13
24
|
dependencyPath: string,
|
|
14
25
|
dependencyStructure: DependencyStructure,
|
|
@@ -16,7 +27,15 @@ function resolveRecursivePackageJson(
|
|
|
16
27
|
additionalDependencies: string[] = [],
|
|
17
28
|
) {
|
|
18
29
|
const isRoot = dependencyPath === root
|
|
19
|
-
|
|
30
|
+
|
|
31
|
+
let fileName: string
|
|
32
|
+
try {
|
|
33
|
+
fileName = require.resolve(path.join(dependencyPath, 'package.json'))
|
|
34
|
+
} catch (e) {
|
|
35
|
+
fileName = findPackageJson(dependencyPath, root)
|
|
36
|
+
}
|
|
37
|
+
if (!fileName) throw Error(`Can't find package.json for ${dependencyPath}`)
|
|
38
|
+
|
|
20
39
|
const packageJsonFile = fs.readFileSync(fileName, 'utf-8').toString()
|
|
21
40
|
const packageJson = JSON.parse(packageJsonFile) as PackageJson
|
|
22
41
|
const e = [atob('QGdyYXBoY29tbWVyY2UvYWRvYmUtY29tbWVyY2U=')].filter((n) =>
|
|
@@ -48,16 +67,34 @@ function resolveRecursivePackageJson(
|
|
|
48
67
|
),
|
|
49
68
|
]
|
|
50
69
|
|
|
70
|
+
const optionalPeerDependencies = Object.entries(packageJson.peerDependenciesMeta ?? {})
|
|
71
|
+
.filter(([_, v]) => v?.optional)
|
|
72
|
+
.map(([key]) => key)
|
|
73
|
+
|
|
74
|
+
const optionalDependencies = Object.keys(packageJson.optionalDependencies ?? {})
|
|
75
|
+
const optional = new Set([...optionalPeerDependencies, ...optionalDependencies])
|
|
76
|
+
|
|
77
|
+
const availableDependencies = dependencies.filter((dep) => {
|
|
78
|
+
if (optional.has(dep)) {
|
|
79
|
+
try {
|
|
80
|
+
resolveRecursivePackageJson(dep, dependencyStructure, root)
|
|
81
|
+
return true
|
|
82
|
+
} catch (resolveError) {
|
|
83
|
+
// Dependency is optional, so we don't care if it is not found.
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
resolveRecursivePackageJson(dep, dependencyStructure, root)
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
|
|
51
92
|
const name = isRoot ? '.' : packageJson.name
|
|
52
93
|
dependencyStructure[name] = {
|
|
53
94
|
dirName: path.dirname(path.relative(process.cwd(), fileName)),
|
|
54
|
-
dependencies,
|
|
95
|
+
dependencies: availableDependencies,
|
|
55
96
|
}
|
|
56
97
|
|
|
57
|
-
dependencies.forEach((dep) => {
|
|
58
|
-
resolveRecursivePackageJson(dep, dependencyStructure, root)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
98
|
return dependencyStructure
|
|
62
99
|
}
|
|
63
100
|
|
package/src/withGraphCommerce.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// import CircularDependencyPlugin from 'circular-dependency-plugin'
|
|
2
|
-
import { DuplicatesPlugin } from 'inspectpack/plugin'
|
|
2
|
+
// import { DuplicatesPlugin } from 'inspectpack/plugin'
|
|
3
3
|
import type { NextConfig } from 'next'
|
|
4
4
|
import type { DomainLocale } from 'next/dist/server/config'
|
|
5
5
|
import type { Configuration } from 'webpack'
|
|
6
|
-
import
|
|
6
|
+
import webpack from 'webpack'
|
|
7
7
|
import { loadConfig } from './config/loadConfig'
|
|
8
8
|
import { configToImportMeta } from './config/utils/configToImportMeta'
|
|
9
9
|
import type { GraphCommerceConfig } from './generated/config'
|
|
@@ -70,31 +70,15 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
|
|
|
70
70
|
images: {
|
|
71
71
|
...nextConfig.images,
|
|
72
72
|
remotePatterns: [
|
|
73
|
-
|
|
73
|
+
'magentoEndpoint' in graphcommerceConfig
|
|
74
|
+
? {
|
|
75
|
+
hostname: new URL(graphcommerceConfig.magentoEndpoint).hostname,
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
74
78
|
{ hostname: '**.graphassets.com' },
|
|
75
79
|
{ hostname: '*.graphcommerce.org' },
|
|
76
80
|
...(nextConfig.images?.remotePatterns ?? []),
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
redirects: async () => {
|
|
80
|
-
const redirects = (await nextConfig.redirects?.()) ?? []
|
|
81
|
-
|
|
82
|
-
const destination = `${graphcommerceConfig.productRoute ?? '/p/'}:url*`
|
|
83
|
-
|
|
84
|
-
redirects.push(
|
|
85
|
-
...[
|
|
86
|
-
{ source: '/product/bundle/:url*', destination, permanent: true },
|
|
87
|
-
{ source: '/product/configurable/:url*', destination, permanent: true },
|
|
88
|
-
{ source: '/product/downloadable/:url*', destination, permanent: true },
|
|
89
|
-
{ source: '/product/grouped/:url*', destination, permanent: true },
|
|
90
|
-
{ source: '/product/virtual/:url*', destination, permanent: true },
|
|
91
|
-
{ source: '/customer/account', destination: '/account', permanent: true },
|
|
92
|
-
],
|
|
93
|
-
)
|
|
94
|
-
if (destination !== '/product/:url*')
|
|
95
|
-
redirects.push({ source: '/product/:url*', destination, permanent: true })
|
|
96
|
-
|
|
97
|
-
return redirects
|
|
81
|
+
].filter((v) => !!v),
|
|
98
82
|
},
|
|
99
83
|
rewrites: async () => {
|
|
100
84
|
let rewrites = (await nextConfig.rewrites?.()) ?? []
|
|
@@ -103,7 +87,11 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
|
|
|
103
87
|
rewrites = { beforeFiles: rewrites, afterFiles: [], fallback: [] }
|
|
104
88
|
}
|
|
105
89
|
|
|
106
|
-
if (
|
|
90
|
+
if (
|
|
91
|
+
'productRoute' in graphcommerceConfig &&
|
|
92
|
+
typeof graphcommerceConfig.productRoute === 'string' &&
|
|
93
|
+
graphcommerceConfig.productRoute !== '/p/'
|
|
94
|
+
) {
|
|
107
95
|
rewrites.beforeFiles.push({
|
|
108
96
|
source: `${graphcommerceConfig.productRoute ?? '/p/'}:path*`,
|
|
109
97
|
destination: '/p/:path*',
|
|
@@ -131,10 +119,10 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
|
|
|
131
119
|
if (!config.plugins) config.plugins = []
|
|
132
120
|
|
|
133
121
|
// Make import.meta.graphCommerce available for usage.
|
|
134
|
-
config.plugins.push(new DefinePlugin(importMetaPaths))
|
|
122
|
+
config.plugins.push(new webpack.DefinePlugin(importMetaPaths))
|
|
135
123
|
|
|
136
124
|
// To properly properly treeshake @apollo/client we need to define the __DEV__ property
|
|
137
|
-
config.plugins.push(new DefinePlugin({ 'globalThis.__DEV__': options.dev }))
|
|
125
|
+
config.plugins.push(new webpack.DefinePlugin({ 'globalThis.__DEV__': options.dev }))
|
|
138
126
|
|
|
139
127
|
if (!options.isServer) {
|
|
140
128
|
// if (graphcommerceConfig.debug?.webpackCircularDependencyPlugin) {
|
|
@@ -144,21 +132,21 @@ export function withGraphCommerce(nextConfig: NextConfig, cwd: string = process.
|
|
|
144
132
|
// }),
|
|
145
133
|
// )
|
|
146
134
|
// }
|
|
147
|
-
if (graphcommerceConfig.debug?.webpackDuplicatesPlugin) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
135
|
+
// if (graphcommerceConfig.debug?.webpackDuplicatesPlugin) {
|
|
136
|
+
// config.plugins.push(
|
|
137
|
+
// new DuplicatesPlugin({
|
|
138
|
+
// ignoredPackages: [
|
|
139
|
+
// // very small
|
|
140
|
+
// 'react-is',
|
|
141
|
+
// // build issue
|
|
142
|
+
// 'tslib',
|
|
143
|
+
// // server
|
|
144
|
+
// 'isarray',
|
|
145
|
+
// 'readable-stream',
|
|
146
|
+
// ],
|
|
147
|
+
// }),
|
|
148
|
+
// )
|
|
149
|
+
// }
|
|
162
150
|
}
|
|
163
151
|
|
|
164
152
|
config.snapshot = {
|
package/tsconfig.json
CHANGED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { formatAppliedEnv } from '../../../src/config/utils/mergeEnvIntoConfig'
|
|
2
|
-
import { rewriteLegacyEnv } from '../../../src/config/utils/rewriteLegacyEnv'
|
|
3
|
-
import type { GraphCommerceConfig } from '../../../src/generated/config'
|
|
4
|
-
import { GraphCommerceConfigSchema } from '../../../src/generated/config'
|
|
5
|
-
|
|
6
|
-
export const removeColor = (str: string) =>
|
|
7
|
-
str.replace(
|
|
8
|
-
new RegExp(
|
|
9
|
-
[
|
|
10
|
-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
11
|
-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
|
|
12
|
-
].join('|'),
|
|
13
|
-
'g',
|
|
14
|
-
),
|
|
15
|
-
'',
|
|
16
|
-
)
|
|
17
|
-
it('rewrites legacy env', () => {
|
|
18
|
-
const configFile: GraphCommerceConfig = {
|
|
19
|
-
storefront: [{ locale: 'en', hygraphLocales: ['en'], magentoStoreCode: 'en_us' }],
|
|
20
|
-
productFiltersPro: false,
|
|
21
|
-
canonicalBaseUrl: 'https://example.com',
|
|
22
|
-
hygraphEndpoint: 'https://example.com',
|
|
23
|
-
magentoEndpoint: 'https://example.com',
|
|
24
|
-
previewSecret: 'secret',
|
|
25
|
-
robotsAllow: true,
|
|
26
|
-
magentoVersion: 246,
|
|
27
|
-
}
|
|
28
|
-
const legacyEnv = {
|
|
29
|
-
GRAPHCMS_URL: 'https://api-eu-central-1.graphcms.com/v2/ckhx7xadya6xs01yxdujt8i80/master',
|
|
30
|
-
MAGENTO_ENDPOINT: 'https://backend.reachdigital.dev/graphql',
|
|
31
|
-
NEXT_PUBLIC_GRAPHQL_ENDPOINT: 'http://localhost:3000/api/graphql',
|
|
32
|
-
IMAGE_DOMAINS: 'backend.reachdigital.dev,media.graphcms.com,media.graphassets.com',
|
|
33
|
-
NEXT_PUBLIC_LOCALE_STORES:
|
|
34
|
-
'{"en-us": "en_US", "nl-nl": "nl_NL", "fr-be": "fr_BE", "nl-be": "nl_BE", "en-gb": "en_GB", "en-ca": "en_CA"}',
|
|
35
|
-
NEXT_PUBLIC_SITE_URL: 'https://graphcommerce.vercel.app/',
|
|
36
|
-
NEXT_PUBLIC_GTM_ID: '123',
|
|
37
|
-
NEXT_PUBLIC_GOOGLE_ANALYTICS:
|
|
38
|
-
'{"en-us": "G-111", "nl-nl": "G-222", "fr-be": "G-333", "nl-be": "G-444", "en-gb":"G-555", "en-ca": "G-666"}',
|
|
39
|
-
NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY: '',
|
|
40
|
-
NEXT_PUBLIC_DISPLAY_INCL_TAX: 'nl,fr-be,nl-be,en-gb,eu',
|
|
41
|
-
PREVIEW_SECRET: 'dya6xs01y',
|
|
42
|
-
DEMO_MAGENTO_GRAPHCOMMERCE: '1',
|
|
43
|
-
SOME_KEY: 'bla',
|
|
44
|
-
}
|
|
45
|
-
const [, appliedRewrite] = rewriteLegacyEnv(GraphCommerceConfigSchema(), legacyEnv, configFile)
|
|
46
|
-
expect(removeColor(formatAppliedEnv(appliedRewrite))).toMatchInlineSnapshot(`
|
|
47
|
-
"warning - Loaded GraphCommerce env variables
|
|
48
|
-
‼ GRAPHCMS_URL => should be renamed to GC_HYGRAPH_ENDPOINT='https://api-eu-central-1.graphcms.com/v2/ckhx7xadya6xs01yxdujt8i80/master'
|
|
49
|
-
‼ MAGENTO_ENDPOINT => should be renamed to GC_MAGENTO_ENDPOINT='https://backend.reachdigital.dev/graphql'
|
|
50
|
-
‼ NEXT_PUBLIC_GRAPHQL_ENDPOINT => should be removed
|
|
51
|
-
‼ IMAGE_DOMAINS => 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
|
|
52
|
-
‼ NEXT_PUBLIC_LOCALE_STORES => env variable is is modified, rewritten to GC_STOREFRONT.
|
|
53
|
-
‼ NEXT_PUBLIC_SITE_URL => should be renamed to GC_CANONICAL_BASE_URL='https://graphcommerce.vercel.app/'
|
|
54
|
-
‼ NEXT_PUBLIC_GTM_ID => should be renamed to GC_GOOGLE_TAGMANAGER_ID='123'
|
|
55
|
-
‼ NEXT_PUBLIC_GOOGLE_ANALYTICS => should be rewritten to GC_STOREFRONT_*_GOOGLE_ANALYTICS_ID
|
|
56
|
-
‼ NEXT_PUBLIC_GOOGLE_RECAPTCHA_V3_SITE_KEY => should be renamed to GC_GOOGLE_RECAPTCHA_KEY=''
|
|
57
|
-
‼ NEXT_PUBLIC_DISPLAY_INCL_TAX => env variable is renamed, move to configuration: cartDisplayPricesInclTax
|
|
58
|
-
‼ PREVIEW_SECRET => should be renamed to GC_PREVIEW_SECRET='dya6xs01y'
|
|
59
|
-
‼ DEMO_MAGENTO_GRAPHCOMMERCE => should be renamed to GC_DEMO_MODE='1'
|
|
60
|
-
~ GC_CANONICAL_BASE_URL => canonicalBaseUrl
|
|
61
|
-
+ GC_DEMO_MODE => demoMode
|
|
62
|
-
+ GC_GOOGLE_ANALYTICS_ID => googleAnalyticsId
|
|
63
|
-
+ GC_GOOGLE_RECAPTCHA_KEY => googleRecaptchaKey
|
|
64
|
-
+ GC_GOOGLE_TAGMANAGER_ID => googleTagmanagerId
|
|
65
|
-
~ GC_HYGRAPH_ENDPOINT => hygraphEndpoint
|
|
66
|
-
~ GC_MAGENTO_ENDPOINT => magentoEndpoint
|
|
67
|
-
~ GC_PREVIEW_SECRET => previewSecret
|
|
68
|
-
= GC_STOREFRONT => storefront: (ignored)
|
|
69
|
-
+ GC_STOREFRONT_0_GOOGLE_ANALYTICS_ID => storefront.[0].googleAnalyticsId
|
|
70
|
-
+ GC_STOREFRONT_1_GOOGLE_ANALYTICS_ID => storefront.[1].googleAnalyticsId
|
|
71
|
-
+ GC_STOREFRONT_2_CART_DISPLAY_PRICES_INCL_TAX => storefront.[2].cartDisplayPricesInclTax
|
|
72
|
-
+ GC_STOREFRONT_2_GOOGLE_ANALYTICS_ID => storefront.[2].googleAnalyticsId
|
|
73
|
-
+ GC_STOREFRONT_3_CART_DISPLAY_PRICES_INCL_TAX => storefront.[3].cartDisplayPricesInclTax
|
|
74
|
-
+ GC_STOREFRONT_3_GOOGLE_ANALYTICS_ID => storefront.[3].googleAnalyticsId
|
|
75
|
-
+ GC_STOREFRONT_4_CART_DISPLAY_PRICES_INCL_TAX => storefront.[4].cartDisplayPricesInclTax
|
|
76
|
-
+ GC_STOREFRONT_4_GOOGLE_ANALYTICS_ID => storefront.[4].googleAnalyticsId
|
|
77
|
-
+ GC_STOREFRONT_5_GOOGLE_ANALYTICS_ID => storefront.[5].googleAnalyticsId"
|
|
78
|
-
`)
|
|
79
|
-
})
|
package/dist/commands/codegen.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.codegen = codegen;
|
|
4
|
-
const generateConfig_1 = require("../config/commands/generateConfig");
|
|
5
|
-
const codegenInterceptors_1 = require("../interceptors/commands/codegenInterceptors");
|
|
6
|
-
const copyFiles_1 = require("./copyFiles");
|
|
7
|
-
/** Run all code generation steps in sequence */
|
|
8
|
-
async function codegen() {
|
|
9
|
-
// Copy files from packages to project
|
|
10
|
-
console.info('🔄 Copying files from packages to project...');
|
|
11
|
-
await (0, copyFiles_1.copyFiles)();
|
|
12
|
-
// Generate GraphCommerce config types
|
|
13
|
-
console.info('⚙️ Generating GraphCommerce config types...');
|
|
14
|
-
await (0, generateConfig_1.generateConfig)();
|
|
15
|
-
// Generate interceptors
|
|
16
|
-
console.info('🔌 Generating interceptors...');
|
|
17
|
-
await (0, codegenInterceptors_1.codegenInterceptors)();
|
|
18
|
-
}
|