@graphcommerce/next-config 9.0.0-canary.100 → 9.0.0-canary.103
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 +85 -1195
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +5 -3
- package/__tests__/config/utils/rewriteLegancyEnv.ts +2 -1
- package/__tests__/interceptors/findPlugins.ts +14 -6
- package/__tests__/interceptors/generateInterceptors.ts +29 -29
- package/__tests__/interceptors/parseStructure.ts +2 -2
- package/__tests__/utils/resolveDependenciesSync.ts +1 -1
- package/dist/config/commands/exportConfig.js +1 -1
- package/dist/config/utils/mergeEnvIntoConfig.js +6 -6
- package/dist/config/utils/rewriteLegacyEnv.js +2 -2
- package/dist/interceptors/InterceptorPlugin.js +3 -3
- package/dist/interceptors/Visitor.js +0 -1
- package/dist/interceptors/commands/codegenInterceptors.js +2 -2
- package/dist/interceptors/findOriginalSource.js +2 -1
- package/dist/interceptors/findPlugins.js +5 -8
- package/dist/interceptors/generateInterceptor.js +5 -5
- package/dist/interceptors/generateInterceptors.js +2 -2
- package/dist/interceptors/parseStructure.js +1 -1
- package/dist/utils/resolveDependenciesSync.js +3 -1
- package/package.json +15 -13
- package/src/config/commands/exportConfig.ts +1 -1
- package/src/config/demoConfig.ts +2 -2
- package/src/config/index.ts +1 -1
- package/src/config/utils/exportConfigToEnv.ts +1 -1
- package/src/config/utils/mergeEnvIntoConfig.ts +7 -9
- package/src/config/utils/replaceConfigInString.ts +1 -1
- package/src/config/utils/rewriteLegacyEnv.ts +5 -4
- package/src/generated/config.ts +2 -0
- package/src/index.ts +2 -1
- package/src/interceptors/InterceptorPlugin.ts +9 -7
- package/src/interceptors/RenameVisitor.ts +1 -1
- package/src/interceptors/Visitor.ts +1 -2
- package/src/interceptors/commands/codegenInterceptors.ts +2 -2
- package/src/interceptors/extractExports.ts +1 -0
- package/src/interceptors/findOriginalSource.ts +5 -4
- package/src/interceptors/findPlugins.ts +8 -9
- package/src/interceptors/generateInterceptor.ts +8 -7
- package/src/interceptors/generateInterceptors.ts +6 -12
- package/src/interceptors/parseStructure.ts +4 -4
- package/src/interceptors/swc.ts +2 -1
- package/src/interceptors/writeInterceptors.ts +1 -1
- package/src/utils/packageRoots.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +4 -1
- package/src/withGraphCommerce.ts +4 -3
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.103",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
|
@@ -13,27 +13,29 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@graphql-mesh/cli": "latest",
|
|
16
|
-
"@lingui/loader": "4.11.
|
|
16
|
+
"@lingui/loader": "4.11.4",
|
|
17
|
+
"@lingui/macro": "4.11.4",
|
|
18
|
+
"@lingui/react": "4.11.4",
|
|
17
19
|
"@lingui/swc-plugin": "4.0.8",
|
|
18
|
-
"@swc/core": "1.
|
|
19
|
-
"@swc/wasm-web": "^1.
|
|
20
|
+
"@swc/core": "1.7.26",
|
|
21
|
+
"@swc/wasm-web": "^1.7.28",
|
|
22
|
+
"@types/circular-dependency-plugin": "^5.0.8",
|
|
23
|
+
"@types/lodash": "^4.17.10",
|
|
24
|
+
"babel-plugin-macros": "^3.1.0",
|
|
20
25
|
"circular-dependency-plugin": "^5.2.2",
|
|
21
26
|
"glob": "^10.4.5",
|
|
27
|
+
"graphql": "^16",
|
|
22
28
|
"inspectpack": "^4.7.1",
|
|
23
29
|
"js-yaml-loader": "^1.2.2",
|
|
24
30
|
"lodash": "^4.17.21",
|
|
31
|
+
"react": "^18.3.1",
|
|
32
|
+
"typescript": "5.6.2",
|
|
33
|
+
"webpack": "~5.93.0",
|
|
25
34
|
"znv": "^0.4.0",
|
|
26
35
|
"zod": "^3.23.8"
|
|
27
36
|
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/circular-dependency-plugin": "^5.0.8",
|
|
30
|
-
"@types/lodash": "^4.17.7",
|
|
31
|
-
"typescript": "5.5.3"
|
|
32
|
-
},
|
|
33
37
|
"peerDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"next": "*",
|
|
37
|
-
"webpack": "~5.92.1"
|
|
38
|
+
"dotenv": "^16",
|
|
39
|
+
"next": "*"
|
|
38
40
|
}
|
|
39
41
|
}
|
package/src/config/demoConfig.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
import { PartialDeep } from 'type-fest'
|
|
3
|
-
import { GraphCommerceConfig } from '../generated/config'
|
|
2
|
+
import type { PartialDeep } from 'type-fest'
|
|
3
|
+
import type { GraphCommerceConfig } from '../generated/config'
|
|
4
4
|
|
|
5
5
|
export const demoConfig: PartialDeep<GraphCommerceConfig, { recurseIntoArrays: true }> &
|
|
6
6
|
Record<string, unknown> = {
|
package/src/config/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { mergeDeep, cloneDeep } from '@apollo/client/utilities'
|
|
|
3
3
|
import chalk from 'chalk'
|
|
4
4
|
import { get, set } from 'lodash'
|
|
5
5
|
import snakeCase from 'lodash/snakeCase'
|
|
6
|
+
import type { ZodRawShape, ZodTypeAny, ZodAny } from 'zod'
|
|
6
7
|
import {
|
|
7
8
|
z,
|
|
8
9
|
ZodObject,
|
|
@@ -13,10 +14,7 @@ import {
|
|
|
13
14
|
ZodNullable,
|
|
14
15
|
ZodOptional,
|
|
15
16
|
ZodEffects,
|
|
16
|
-
ZodRawShape,
|
|
17
17
|
ZodEnum,
|
|
18
|
-
ZodTypeAny,
|
|
19
|
-
ZodAny,
|
|
20
18
|
ZodDefault,
|
|
21
19
|
} from 'zod'
|
|
22
20
|
import diff from './diff'
|
|
@@ -69,7 +67,7 @@ export function configToEnvSchema(schema: ZodNode) {
|
|
|
69
67
|
envSchema[toEnvStr(path)] = z
|
|
70
68
|
.string()
|
|
71
69
|
.optional()
|
|
72
|
-
.refine(isJSON, { message:
|
|
70
|
+
.refine(isJSON, { message: 'Invalid JSON' })
|
|
73
71
|
.transform((val) => (val ? JSON.parse(val) : val))
|
|
74
72
|
envToDot[toEnvStr(path)] = dotNotation(path)
|
|
75
73
|
}
|
|
@@ -89,7 +87,7 @@ export function configToEnvSchema(schema: ZodNode) {
|
|
|
89
87
|
envSchema[toEnvStr(path)] = z
|
|
90
88
|
.string()
|
|
91
89
|
.optional()
|
|
92
|
-
.refine(isJSON, { message:
|
|
90
|
+
.refine(isJSON, { message: 'Invalid JSON' })
|
|
93
91
|
.transform((val) => (val ? JSON.parse(val) : val))
|
|
94
92
|
envToDot[toEnvStr(path)] = dotNotation(path)
|
|
95
93
|
}
|
|
@@ -232,11 +230,11 @@ export function formatAppliedEnv(applyResult: ApplyResult) {
|
|
|
232
230
|
return ` ${chalk.yellowBright('~')} ${baseLog}: ${fromFmt} => ${toFmt}`
|
|
233
231
|
})
|
|
234
232
|
|
|
235
|
-
let header = chalk.blueBright(
|
|
236
|
-
if (hasWarning) header = chalk.yellowBright(
|
|
237
|
-
if (hasError) header = chalk.yellowBright(
|
|
233
|
+
let header = chalk.blueBright('info')
|
|
234
|
+
if (hasWarning) header = chalk.yellowBright('warning')
|
|
235
|
+
if (hasError) header = chalk.yellowBright('error')
|
|
238
236
|
|
|
239
|
-
header +=
|
|
237
|
+
header += ' - Loaded GraphCommerce env variables'
|
|
240
238
|
|
|
241
239
|
return [header, ...lines].join('\n')
|
|
242
240
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphCommerceConfig } from '../../generated/config'
|
|
1
|
+
import type { GraphCommerceConfig } from '../../generated/config'
|
|
2
2
|
import { configToImportMeta } from './configToImportMeta'
|
|
3
3
|
|
|
4
4
|
export function replaceConfigInString(str: string, config: Partial<GraphCommerceConfig>) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import cloneDeep from 'lodash/cloneDeep'
|
|
2
|
-
import { GraphCommerceConfig } from '../../generated/config'
|
|
3
|
-
import { ApplyResult,
|
|
2
|
+
import type { GraphCommerceConfig } from '../../generated/config'
|
|
3
|
+
import type { ApplyResult, ZodNode } from './mergeEnvIntoConfig'
|
|
4
|
+
import { mergeEnvIntoConfig } from './mergeEnvIntoConfig'
|
|
4
5
|
|
|
5
6
|
export function rewriteLegacyEnv(
|
|
6
7
|
schema: ZodNode,
|
|
@@ -24,7 +25,7 @@ export function rewriteLegacyEnv(
|
|
|
24
25
|
function notUsed() {
|
|
25
26
|
return (envVar: string, envValue: string) => {
|
|
26
27
|
applied.push({
|
|
27
|
-
warning: [
|
|
28
|
+
warning: ['should be removed'],
|
|
28
29
|
envVar,
|
|
29
30
|
envValue,
|
|
30
31
|
})
|
|
@@ -38,7 +39,7 @@ export function rewriteLegacyEnv(
|
|
|
38
39
|
IMAGE_DOMAINS: (envVar: string, envValue: string) => {
|
|
39
40
|
applied.push({
|
|
40
41
|
warning: [
|
|
41
|
-
|
|
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',
|
|
42
43
|
],
|
|
43
44
|
envVar,
|
|
44
45
|
envValue,
|
package/src/generated/config.ts
CHANGED
|
@@ -369,6 +369,7 @@ export type GraphCommerceDebugConfig = {
|
|
|
369
369
|
webpackDuplicatesPlugin?: InputMaybe<Scalars['Boolean']['input']>;
|
|
370
370
|
};
|
|
371
371
|
|
|
372
|
+
/** Permissions input */
|
|
372
373
|
export type GraphCommercePermissions = {
|
|
373
374
|
/** Changes the availability of the add to cart buttons and the cart page to either customer only or completely disables it. */
|
|
374
375
|
cart?: InputMaybe<CartPermissions>;
|
|
@@ -376,6 +377,7 @@ export type GraphCommercePermissions = {
|
|
|
376
377
|
checkout?: InputMaybe<CartPermissions>;
|
|
377
378
|
/** Enables / disabled the account section of the website. DISABLE_REGISTRATION will only disable the registration page. */
|
|
378
379
|
customerAccount?: InputMaybe<CustomerAccountPermissions>;
|
|
380
|
+
/** Allows the option to require login or completely disable the site. */
|
|
379
381
|
website?: InputMaybe<WebsitePermissions>;
|
|
380
382
|
};
|
|
381
383
|
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
2
|
import type React from 'react'
|
|
3
3
|
import type { Path, PathValue } from 'react-hook-form'
|
|
4
|
-
import { GraphCommerceConfig } from './generated/config'
|
|
4
|
+
import type { GraphCommerceConfig } from './generated/config'
|
|
5
|
+
|
|
5
6
|
export * from './utils/isMonorepo'
|
|
6
7
|
export * from './utils/resolveDependenciesSync'
|
|
7
8
|
export * from './utils/packageRoots'
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import { Compiler } from 'webpack'
|
|
3
|
-
import { GraphCommerceConfig } from '../generated/config'
|
|
4
|
-
import { ResolveDependency
|
|
2
|
+
import type { Compiler } from 'webpack'
|
|
3
|
+
import type { GraphCommerceConfig } from '../generated/config'
|
|
4
|
+
import type { ResolveDependency } from '../utils/resolveDependency'
|
|
5
|
+
import { resolveDependency } from '../utils/resolveDependency'
|
|
5
6
|
import { findPlugins } from './findPlugins'
|
|
6
|
-
import {
|
|
7
|
+
import type { GenerateInterceptorsReturn } from './generateInterceptors'
|
|
8
|
+
import { generateInterceptors } from './generateInterceptors'
|
|
7
9
|
import { writeInterceptors } from './writeInterceptors'
|
|
8
10
|
|
|
9
11
|
let interceptors: GenerateInterceptorsReturn | undefined
|
|
@@ -29,11 +31,11 @@ export class InterceptorPlugin {
|
|
|
29
31
|
#generateInterceptors = async () => {
|
|
30
32
|
if (generating) return {}
|
|
31
33
|
generating = true
|
|
32
|
-
const start = Date.now()
|
|
34
|
+
// const start = Date.now()
|
|
33
35
|
|
|
34
36
|
// console.log('Generating interceptors...')
|
|
35
37
|
|
|
36
|
-
const [plugins
|
|
38
|
+
const [plugins] = findPlugins(this.config)
|
|
37
39
|
|
|
38
40
|
// console.log(errors)
|
|
39
41
|
|
|
@@ -86,7 +88,7 @@ export class InterceptorPlugin {
|
|
|
86
88
|
|
|
87
89
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
88
90
|
this.#generateInterceptors().then((i) => {
|
|
89
|
-
Object.entries(i).forEach(([
|
|
91
|
+
Object.entries(i).forEach(([, { sourcePath }]) => {
|
|
90
92
|
const absoluteFilePath = path.join(process.cwd(), sourcePath)
|
|
91
93
|
compilation.fileDependencies.add(absoluteFilePath)
|
|
92
94
|
})
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
/* eslint-disable class-methods-use-this */
|
|
12
12
|
/* eslint-disable consistent-return */
|
|
13
13
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
14
|
-
import {
|
|
14
|
+
import type {
|
|
15
15
|
Accessibility,
|
|
16
16
|
Argument,
|
|
17
17
|
ArrayExpression,
|
|
@@ -782,7 +782,6 @@ export class Visitor {
|
|
|
782
782
|
}
|
|
783
783
|
|
|
784
784
|
visitTsPropertySignature(n: TsPropertySignature): TsPropertySignature {
|
|
785
|
-
n.params = this.visitTsFnParameters(n.params)
|
|
786
785
|
n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation)
|
|
787
786
|
return n
|
|
788
787
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import dotenv from 'dotenv'
|
|
1
2
|
import { loadConfig } from '../../config/loadConfig'
|
|
2
3
|
import { resolveDependency } from '../../utils/resolveDependency'
|
|
3
4
|
import { findPlugins } from '../findPlugins'
|
|
4
5
|
import { generateInterceptors } from '../generateInterceptors'
|
|
5
6
|
import { writeInterceptors } from '../writeInterceptors'
|
|
6
|
-
import dotenv from 'dotenv'
|
|
7
7
|
|
|
8
8
|
dotenv.config()
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ dotenv.config()
|
|
|
11
11
|
export async function codegenInterceptors() {
|
|
12
12
|
const conf = loadConfig(process.cwd())
|
|
13
13
|
|
|
14
|
-
const [plugins
|
|
14
|
+
const [plugins] = findPlugins(conf)
|
|
15
15
|
|
|
16
16
|
const generatedInterceptors = await generateInterceptors(
|
|
17
17
|
plugins,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { ExportAllDeclaration } from '@swc/core'
|
|
3
|
+
import type { ResolveDependency, ResolveDependencyReturn } from '../utils/resolveDependency'
|
|
4
|
+
import type { PluginConfig } from './generateInterceptor'
|
|
4
5
|
import { parseSync } from './swc'
|
|
5
|
-
import { ExportAllDeclaration } from '@swc/core'
|
|
6
6
|
|
|
7
7
|
function parseAndFindExport(
|
|
8
8
|
resolved: ResolveDependencyReturn,
|
|
@@ -25,6 +25,7 @@ function parseAndFindExport(
|
|
|
25
25
|
if (declaration.id.type === 'Identifier') {
|
|
26
26
|
if (declaration.id.value === findExport) return resolved
|
|
27
27
|
} else {
|
|
28
|
+
// eslint-disable-next-line no-console
|
|
28
29
|
console.log(declaration)
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -81,7 +82,7 @@ function parseAndFindExport(
|
|
|
81
82
|
return undefined
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
const cachedResults = new Map<string, ResolveDependencyReturn>()
|
|
85
|
+
// const cachedResults = new Map<string, ResolveDependencyReturn>()
|
|
85
86
|
|
|
86
87
|
export function findOriginalSource(
|
|
87
88
|
plug: PluginConfig,
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
1
|
import { parseFileSync } from '@swc/core'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
5
2
|
import { sync as globSync } from 'glob'
|
|
6
|
-
import { GraphCommerceConfig } from '../generated/config'
|
|
3
|
+
import type { GraphCommerceConfig } from '../generated/config'
|
|
7
4
|
import { resolveDependenciesSync } from '../utils/resolveDependenciesSync'
|
|
8
|
-
import { PluginConfig } from './generateInterceptor'
|
|
5
|
+
import type { PluginConfig } from './generateInterceptor'
|
|
9
6
|
import { parseStructure } from './parseStructure'
|
|
10
7
|
|
|
11
8
|
const pluginLogs: Record<string, string> = {}
|
|
12
9
|
|
|
10
|
+
// ANSI escape codes for console colors
|
|
11
|
+
const GREEN = '\x1b[32m'
|
|
12
|
+
const RESET = '\x1b[0m'
|
|
13
|
+
|
|
13
14
|
export function findPlugins(config: GraphCommerceConfig, cwd: string = process.cwd()) {
|
|
14
15
|
const dependencies = resolveDependenciesSync(cwd)
|
|
15
16
|
|
|
@@ -40,9 +41,7 @@ export function findPlugins(config: GraphCommerceConfig, cwd: string = process.c
|
|
|
40
41
|
if (process.env.NODE_ENV === 'development' && debug) {
|
|
41
42
|
const byExported = plugins.reduce(
|
|
42
43
|
(acc, plugin) => {
|
|
43
|
-
const key = `🔌 ${
|
|
44
|
-
`Plugins loaded for ${plugin.targetModule}#${plugin.targetExport}`,
|
|
45
|
-
)}`
|
|
44
|
+
const key = `🔌 ${GREEN}Plugins loaded for ${plugin.targetModule}#${plugin.targetExport}${RESET}`
|
|
46
45
|
if (!acc[key]) acc[key] = []
|
|
47
46
|
acc[key].push(plugin)
|
|
48
47
|
return acc
|
|
@@ -65,7 +64,7 @@ export function findPlugins(config: GraphCommerceConfig, cwd: string = process.c
|
|
|
65
64
|
: `${c.ifConfig}`
|
|
66
65
|
: ''
|
|
67
66
|
|
|
68
|
-
return `${c.enabled ?
|
|
67
|
+
return `${c.enabled ? '🟢' : '⚪️'} ${c.sourceModule} ${ifConfigStr}`
|
|
69
68
|
})
|
|
70
69
|
.join('\n')
|
|
71
70
|
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import prettierConf from '@graphcommerce/prettier-config-pwa'
|
|
3
3
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
4
|
import prettier from 'prettier'
|
|
5
|
-
import { GraphCommerceDebugConfig } from '../generated/config'
|
|
6
|
-
import { ResolveDependencyReturn } from '../utils/resolveDependency'
|
|
5
|
+
import type { GraphCommerceDebugConfig } from '../generated/config'
|
|
6
|
+
import type { ResolveDependencyReturn } from '../utils/resolveDependency'
|
|
7
7
|
import { RenameVisitor } from './RenameVisitor'
|
|
8
8
|
import { parseSync, printSync } from './swc'
|
|
9
9
|
|
|
@@ -14,6 +14,7 @@ type PluginBaseConfig = {
|
|
|
14
14
|
sourceModule: string
|
|
15
15
|
targetExport: string
|
|
16
16
|
enabled: boolean
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
18
|
ifConfig?: string | [string, any]
|
|
18
19
|
}
|
|
19
20
|
|
|
@@ -70,7 +71,6 @@ export const SOURCE_START = '/** Original source starts here (do not modify!): *
|
|
|
70
71
|
export const SOURCE_END = '/** Original source ends here (do not modify!) **/'
|
|
71
72
|
|
|
72
73
|
const originalSuffix = 'Original'
|
|
73
|
-
const sourceSuffix = 'Plugin'
|
|
74
74
|
const interceptorSuffix = 'Interceptor'
|
|
75
75
|
const disabledSuffix = 'Disabled'
|
|
76
76
|
const name = (plugin: PluginConfig) =>
|
|
@@ -193,7 +193,7 @@ export async function generateInterceptor(
|
|
|
193
193
|
result = `
|
|
194
194
|
type ${interceptorPropsName(name(p))} = ${carryProps.join(' & ')} & OmitPrev<React.ComponentProps<typeof ${sourceName(name(p))}>, 'Prev'>
|
|
195
195
|
|
|
196
|
-
const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ?
|
|
196
|
+
const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ? '{' : '('}
|
|
197
197
|
${config.pluginStatus ? `logOnce(\`🔌 Rendering ${base} with plugin(s): ${wrapChain} wrapping <${base}/>\`)` : ''}
|
|
198
198
|
|
|
199
199
|
${
|
|
@@ -202,8 +202,8 @@ export async function generateInterceptor(
|
|
|
202
202
|
logOnce('${fileName(p)} does not spread props to prev: <Prev {...props}/>. This will cause issues if multiple plugins are applied to this component.')`
|
|
203
203
|
: ''
|
|
204
204
|
}
|
|
205
|
-
${withBraces ?
|
|
206
|
-
${withBraces ?
|
|
205
|
+
${withBraces ? 'return' : ''} <${sourceName(name(p))} {...props} Prev={${carry}} />
|
|
206
|
+
${withBraces ? '}' : ')'}`
|
|
207
207
|
|
|
208
208
|
carryProps = [interceptorPropsName(name(p))]
|
|
209
209
|
pluginSee.push(`@see {${sourceName(name(p))}} for source of applied plugin`)
|
|
@@ -270,7 +270,7 @@ export async function generateInterceptor(
|
|
|
270
270
|
/* This file is automatically generated for ${dependency} */
|
|
271
271
|
${
|
|
272
272
|
Object.values(targetExports).some((t) => t.some((p) => p.type === 'component'))
|
|
273
|
-
?
|
|
273
|
+
? "import type { DistributedOmit as OmitPrev } from 'type-fest'"
|
|
274
274
|
: ''
|
|
275
275
|
}
|
|
276
276
|
|
|
@@ -287,6 +287,7 @@ export async function generateInterceptor(
|
|
|
287
287
|
try {
|
|
288
288
|
templateFormatted = await prettier.format(template, { ...prettierConf, parser: 'typescript' })
|
|
289
289
|
} catch (e) {
|
|
290
|
+
// eslint-disable-next-line no-console
|
|
290
291
|
console.log('Error formatting interceptor: ', e, 'using raw template.')
|
|
291
292
|
templateFormatted = template
|
|
292
293
|
}
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
1
|
import fs from 'node:fs/promises'
|
|
2
|
+
import path from 'node:path'
|
|
3
3
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
-
import { GraphCommerceDebugConfig } from '../generated/config'
|
|
5
|
-
import { ResolveDependency } from '../utils/resolveDependency'
|
|
4
|
+
import type { GraphCommerceDebugConfig } from '../generated/config'
|
|
5
|
+
import type { ResolveDependency } from '../utils/resolveDependency'
|
|
6
6
|
import { findOriginalSource } from './findOriginalSource'
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
MaterializedPlugin,
|
|
10
|
-
PluginConfig,
|
|
11
|
-
generateInterceptor,
|
|
12
|
-
isPluginConfig,
|
|
13
|
-
moveRelativeDown,
|
|
14
|
-
} from './generateInterceptor'
|
|
7
|
+
import type { Interceptor, MaterializedPlugin, PluginConfig } from './generateInterceptor'
|
|
8
|
+
import { generateInterceptor, isPluginConfig, moveRelativeDown } from './generateInterceptor'
|
|
15
9
|
|
|
16
10
|
export type GenerateInterceptorsReturn = Record<string, MaterializedPlugin>
|
|
17
11
|
|
|
@@ -30,7 +24,7 @@ export async function generateInterceptors(
|
|
|
30
24
|
const { error, resolved } = findOriginalSource(plug, result, resolve)
|
|
31
25
|
|
|
32
26
|
if (error) {
|
|
33
|
-
console.
|
|
27
|
+
console.error(error.message)
|
|
34
28
|
return acc
|
|
35
29
|
}
|
|
36
30
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Module } from '@swc/core'
|
|
1
|
+
import type { Module } from '@swc/core'
|
|
2
2
|
import get from 'lodash/get'
|
|
3
3
|
import { z } from 'zod'
|
|
4
|
-
import { GraphCommerceConfig } from '../generated/config'
|
|
4
|
+
import type { GraphCommerceConfig } from '../generated/config'
|
|
5
5
|
import { extractExports } from './extractExports'
|
|
6
|
-
import { PluginConfig } from './generateInterceptor'
|
|
6
|
+
import type { PluginConfig } from './generateInterceptor'
|
|
7
7
|
|
|
8
8
|
const pluginConfigParsed = z.object({
|
|
9
9
|
type: z.enum(['component', 'function', 'replace']),
|
|
@@ -20,7 +20,7 @@ const isObject = (input: unknown): input is Record<string, unknown> =>
|
|
|
20
20
|
|
|
21
21
|
export function parseStructure(ast: Module, gcConfig: GraphCommerceConfig, sourceModule: string) {
|
|
22
22
|
const [exports, errors] = extractExports(ast)
|
|
23
|
-
if (errors.length) console.error(
|
|
23
|
+
if (errors.length) console.error('Plugin error for', errors.join('\n'))
|
|
24
24
|
|
|
25
25
|
const {
|
|
26
26
|
config: moduleConfig,
|
package/src/interceptors/swc.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Output, Program
|
|
1
|
+
import type { Output, Program } from '@swc/core'
|
|
2
|
+
import { parseSync as parseSyncCore, printSync as printSyncCode } from '@swc/core'
|
|
2
3
|
|
|
3
4
|
export function parseSync(src: string) {
|
|
4
5
|
return parseSyncCore(src, {
|
|
@@ -3,7 +3,7 @@ import path from 'path'
|
|
|
3
3
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
4
|
import { sync as globSync } from 'glob'
|
|
5
5
|
import { resolveDependenciesSync } from '../utils/resolveDependenciesSync'
|
|
6
|
-
import { GenerateInterceptorsReturn } from './generateInterceptors'
|
|
6
|
+
import type { GenerateInterceptorsReturn } from './generateInterceptors'
|
|
7
7
|
|
|
8
8
|
function checkFileExists(file: string) {
|
|
9
9
|
return fs
|
|
@@ -30,6 +30,6 @@ export const packageRoots = (packagePaths: string[]): string[] => {
|
|
|
30
30
|
|
|
31
31
|
// Filter out the sub-paths which are part of another longer sub-path
|
|
32
32
|
return roots.filter(
|
|
33
|
-
(root, index, self) => self.findIndex((r) => r !== root && r.startsWith(`${root
|
|
33
|
+
(root, index, self) => self.findIndex((r) => r !== root && r.startsWith(`${root}/`)) === -1,
|
|
34
34
|
)
|
|
35
35
|
}
|
|
@@ -24,7 +24,10 @@ function resolveRecursivePackageJson(
|
|
|
24
24
|
// Previously processed
|
|
25
25
|
if (dependencyStructure[packageJson.name]) return dependencyStructure
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
// To have additional namespaces be considered as a graphcommerce package, set PRIVATE_PACKAGE_NAMESPACES
|
|
28
|
+
const namespaces = process.env.PRIVATE_PACKAGE_NAMESPACES?.split(',') ?? ['graphcommerce']
|
|
29
|
+
if (!isRoot && !namespaces.some((namespace) => packageJson.name?.includes(namespace)))
|
|
30
|
+
return dependencyStructure
|
|
28
31
|
|
|
29
32
|
const dependencies = [
|
|
30
33
|
...new Set(
|
package/src/withGraphCommerce.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// import CircularDependencyPlugin from 'circular-dependency-plugin'
|
|
2
2
|
import { DuplicatesPlugin } from 'inspectpack/plugin'
|
|
3
3
|
import type { NextConfig } from 'next'
|
|
4
|
-
import { DomainLocale } from 'next/dist/server/config'
|
|
5
|
-
import {
|
|
4
|
+
import type { DomainLocale } from 'next/dist/server/config'
|
|
5
|
+
import type { Configuration } from 'webpack'
|
|
6
|
+
import { DefinePlugin } from 'webpack'
|
|
6
7
|
import { loadConfig } from './config/loadConfig'
|
|
7
8
|
import { configToImportMeta } from './config/utils/configToImportMeta'
|
|
8
|
-
import { GraphCommerceConfig } from './generated/config'
|
|
9
|
+
import type { GraphCommerceConfig } from './generated/config'
|
|
9
10
|
import { InterceptorPlugin } from './interceptors/InterceptorPlugin'
|
|
10
11
|
import { resolveDependenciesSync } from './utils/resolveDependenciesSync'
|
|
11
12
|
|