@graphcommerce/next-config 9.0.0-canary.101 → 9.0.0-canary.104
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 +89 -1204
- 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 +34 -35
- 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/commands/generateConfig.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 +4 -7
- package/dist/interceptors/commands/codegenInterceptors.js +2 -2
- package/dist/interceptors/extractExports.js +1 -0
- 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 +3 -2
- package/dist/interceptors/parseStructure.js +1 -1
- package/dist/interceptors/writeInterceptors.js +2 -2
- package/dist/utils/resolveDependenciesSync.js +3 -1
- package/dist/withGraphCommerce.js +1 -0
- package/package.json +12 -10
- package/src/config/commands/exportConfig.ts +1 -1
- package/src/config/commands/generateConfig.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 +16 -18
- package/src/config/utils/replaceConfigInString.ts +1 -1
- package/src/config/utils/rewriteLegacyEnv.ts +5 -4
- 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 +7 -10
- package/src/interceptors/commands/codegenInterceptors.ts +2 -2
- package/src/interceptors/extractExports.ts +3 -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 +7 -13
- package/src/interceptors/parseStructure.ts +4 -4
- package/src/interceptors/swc.ts +2 -1
- package/src/interceptors/writeInterceptors.ts +3 -3
- package/src/utils/packageRoots.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +4 -1
- package/src/withGraphCommerce.ts +5 -3
|
@@ -4,8 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateInterceptors = generateInterceptors;
|
|
7
|
-
|
|
7
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
8
|
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const findOriginalSource_1 = require("./findOriginalSource");
|
|
10
11
|
const generateInterceptor_1 = require("./generateInterceptor");
|
|
11
12
|
async function generateInterceptors(plugins, resolve, config, force) {
|
|
@@ -16,7 +17,7 @@ async function generateInterceptors(plugins, resolve, config, force) {
|
|
|
16
17
|
const result = resolve(plug.targetModule, { includeSources: true });
|
|
17
18
|
const { error, resolved } = (0, findOriginalSource_1.findOriginalSource)(plug, result, resolve);
|
|
18
19
|
if (error) {
|
|
19
|
-
console.
|
|
20
|
+
console.error(error.message);
|
|
20
21
|
return acc;
|
|
21
22
|
}
|
|
22
23
|
const { fromRoot } = resolved;
|
|
@@ -20,7 +20,7 @@ const isObject = (input) => typeof input === 'object' && input !== null && !Arra
|
|
|
20
20
|
function parseStructure(ast, gcConfig, sourceModule) {
|
|
21
21
|
const [exports, errors] = (0, extractExports_1.extractExports)(ast);
|
|
22
22
|
if (errors.length)
|
|
23
|
-
console.error(
|
|
23
|
+
console.error('Plugin error for', errors.join('\n'));
|
|
24
24
|
const { config: moduleConfig, component, func, exported, ifConfig, plugin, Plugin, ...rest } = exports;
|
|
25
25
|
const exportVals = Object.keys(rest);
|
|
26
26
|
if (component && !moduleConfig)
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.writeInterceptors = writeInterceptors;
|
|
7
|
-
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
7
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
10
8
|
const glob_1 = require("glob");
|
|
9
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
11
|
const resolveDependenciesSync_1 = require("../utils/resolveDependenciesSync");
|
|
12
12
|
function checkFileExists(file) {
|
|
13
13
|
return promises_1.default
|
|
@@ -19,7 +19,9 @@ function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root,
|
|
|
19
19
|
// Previously processed
|
|
20
20
|
if (dependencyStructure[packageJson.name])
|
|
21
21
|
return dependencyStructure;
|
|
22
|
-
|
|
22
|
+
// To have additional namespaces be considered as a graphcommerce package, set PRIVATE_PACKAGE_NAMESPACES
|
|
23
|
+
const namespaces = process.env.PRIVATE_PACKAGE_NAMESPACES?.split(',') ?? ['graphcommerce'];
|
|
24
|
+
if (!isRoot && !namespaces.some((namespace) => packageJson.name?.includes(namespace)))
|
|
23
25
|
return dependencyStructure;
|
|
24
26
|
const dependencies = [
|
|
25
27
|
...new Set([
|
|
@@ -58,6 +58,7 @@ function withGraphCommerce(nextConfig, cwd) {
|
|
|
58
58
|
remotePatterns: [
|
|
59
59
|
{ hostname: new URL(graphcommerceConfig.magentoEndpoint).hostname },
|
|
60
60
|
{ hostname: 'media.graphassets.com' },
|
|
61
|
+
{ hostname: '*.graphcommerce.org' },
|
|
61
62
|
...(nextConfig.images?.remotePatterns ?? []),
|
|
62
63
|
],
|
|
63
64
|
},
|
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.104",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
|
@@ -14,26 +14,28 @@
|
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@graphql-mesh/cli": "latest",
|
|
16
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
20
|
"@swc/core": "1.7.26",
|
|
19
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.10",
|
|
31
|
-
"typescript": "5.6.2"
|
|
32
|
-
},
|
|
33
37
|
"peerDependencies": {
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"next": "*",
|
|
37
|
-
"webpack": "~5.92.1"
|
|
38
|
+
"dotenv": "^16",
|
|
39
|
+
"next": "*"
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { writeFileSync } from 'fs'
|
|
2
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
3
2
|
import { generate } from '@graphql-codegen/cli'
|
|
4
3
|
import { transformFileSync } from '@swc/core'
|
|
5
4
|
import dotenv from 'dotenv'
|
|
5
|
+
import { writeFileSync } from 'fs'
|
|
6
6
|
import { isMonorepo } from '../../utils/isMonorepo'
|
|
7
7
|
import { resolveDependenciesSync } from '../../utils/resolveDependenciesSync'
|
|
8
8
|
import { resolveDependency } from '../../utils/resolveDependency'
|
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
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
-
import {
|
|
2
|
+
import { cloneDeep, mergeDeep } 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 { ZodAny, ZodRawShape, ZodTypeAny } from 'zod'
|
|
6
7
|
import {
|
|
7
|
-
z,
|
|
8
|
-
ZodObject,
|
|
9
|
-
ZodBoolean,
|
|
10
8
|
ZodArray,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
ZodNullable,
|
|
14
|
-
ZodOptional,
|
|
9
|
+
ZodBoolean,
|
|
10
|
+
ZodDefault,
|
|
15
11
|
ZodEffects,
|
|
16
|
-
ZodRawShape,
|
|
17
12
|
ZodEnum,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
ZodNullable,
|
|
14
|
+
ZodNumber,
|
|
15
|
+
ZodObject,
|
|
16
|
+
ZodOptional,
|
|
17
|
+
ZodString,
|
|
18
|
+
z,
|
|
21
19
|
} from 'zod'
|
|
22
20
|
import diff from './diff'
|
|
23
21
|
|
|
@@ -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/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
|
})
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This is an implementation of
|
|
3
|
-
* https://github.com/swc-project/swc/blob/main/
|
|
3
|
+
* https://github.com/swc-project/swc/blob/main/packages/core/src/Visitor.ts
|
|
4
4
|
*
|
|
5
5
|
* The JS API is deprecated, but there doesn't seem to be a valid alternative at this point.
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
9
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
10
|
-
/* eslint-disable no-param-reassign */
|
|
11
|
-
/* eslint-disable class-methods-use-this */
|
|
12
|
-
/* eslint-disable consistent-return */
|
|
13
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
14
|
-
import {
|
|
7
|
+
import type {
|
|
15
8
|
Accessibility,
|
|
16
9
|
Argument,
|
|
17
10
|
ArrayExpression,
|
|
@@ -188,6 +181,10 @@ import {
|
|
|
188
181
|
YieldExpression,
|
|
189
182
|
} from '@swc/types'
|
|
190
183
|
|
|
184
|
+
/* eslint-disable no-param-reassign */
|
|
185
|
+
/* eslint-disable class-methods-use-this */
|
|
186
|
+
/* eslint-disable consistent-return */
|
|
187
|
+
|
|
191
188
|
/**
|
|
192
189
|
* @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
|
|
193
190
|
*/
|
|
@@ -872,7 +869,7 @@ export class Visitor {
|
|
|
872
869
|
}
|
|
873
870
|
|
|
874
871
|
visitTsFnParameters(params: TsFnParameter[]): TsFnParameter[] {
|
|
875
|
-
return params
|
|
872
|
+
return params.map(this.visitTsFnParameter.bind(this))
|
|
876
873
|
}
|
|
877
874
|
|
|
878
875
|
visitTsFnParameter(n: TsFnParameter): TsFnParameter {
|
|
@@ -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
|
+
import type { ExportAllDeclaration } from '@swc/core'
|
|
1
2
|
import path from 'path'
|
|
2
|
-
import { ResolveDependency, ResolveDependencyReturn } from '../utils/resolveDependency'
|
|
3
|
-
import { PluginConfig } from './generateInterceptor'
|
|
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
|
-
import fs from 'node:fs/promises'
|
|
3
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
|
-
import
|
|
5
|
-
import
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
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, {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import fs from 'node:fs/promises'
|
|
2
|
-
import path from 'path'
|
|
3
1
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
4
2
|
import { sync as globSync } from 'glob'
|
|
3
|
+
import fs from 'node:fs/promises'
|
|
4
|
+
import path from 'path'
|
|
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(
|