@graphcommerce/next-config 4.31.0-canary.2 → 4.31.0-canary.3
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/dist/index.d.ts +2 -2
- package/dist/interceptors/InterceptorPlugin.js +2 -2
- package/dist/interceptors/generateInterceptors.js +20 -15
- package/package.json +2 -2
- package/src/index.ts +2 -2
- package/src/interceptors/InterceptorPlugin.ts +2 -2
- package/src/interceptors/generateInterceptors.ts +23 -15
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { NextConfig } from 'next/dist/server/config-shared';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import type React from 'react';
|
|
3
3
|
export * from './utils/isMonorepo';
|
|
4
4
|
export * from './utils/resolveDependenciesSync';
|
|
5
5
|
export * from './withGraphCommerce';
|
|
6
6
|
export declare function withYarn1Workspaces(packages?: string[]): (config: NextConfig) => NextConfig;
|
|
7
7
|
export declare function withYarn1Scopes(packages?: string[]): (config: NextConfig) => NextConfig;
|
|
8
8
|
export declare type PluginProps<P extends Record<string, unknown> = Record<string, unknown>> = P & {
|
|
9
|
-
|
|
9
|
+
Prev: React.FC<P>;
|
|
10
10
|
};
|
|
@@ -55,12 +55,12 @@ class InterceptorPlugin {
|
|
|
55
55
|
}
|
|
56
56
|
const interceptorForRequest = this.interceptorByDepependency[resource.request];
|
|
57
57
|
if (interceptorForRequest) {
|
|
58
|
-
logger.log(`Intercepting... ${interceptorForRequest.dependency}`);
|
|
58
|
+
logger.log(`Intercepting dep... ${interceptorForRequest.dependency}`);
|
|
59
59
|
resource.request = `${interceptorForRequest.denormalized}.interceptor.tsx`;
|
|
60
60
|
}
|
|
61
61
|
const interceptorForPath = this.interceptors[requestPath];
|
|
62
62
|
if (interceptorForPath) {
|
|
63
|
-
logger.log(`Intercepting... ${interceptorForPath.fromRoot}`);
|
|
63
|
+
logger.log(`Intercepting fromRoot... ${interceptorForPath.fromRoot}`);
|
|
64
64
|
resource.request = `${resource.request}.interceptor.tsx`;
|
|
65
65
|
}
|
|
66
66
|
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateInterceptors = exports.generateInterceptor = void 0;
|
|
4
4
|
function generateInterceptor(plugin) {
|
|
5
|
-
const { fromModule, components } = plugin;
|
|
5
|
+
const { fromModule, dependency, components } = plugin;
|
|
6
6
|
const pluginImports = Object.entries(components)
|
|
7
7
|
.map(([_, plugins]) => {
|
|
8
8
|
const duplicateImports = new Set();
|
|
@@ -19,9 +19,12 @@ function generateInterceptor(plugin) {
|
|
|
19
19
|
.join('\n');
|
|
20
20
|
})
|
|
21
21
|
.join('\n');
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
const imports = Object.entries(components).map(([component]) => `${component} as ${component}Base`);
|
|
23
|
+
const importInjectables = imports.length > 1
|
|
24
|
+
? `import {
|
|
25
|
+
${imports.join(',\n ')},
|
|
26
|
+
} from '${fromModule}'`
|
|
27
|
+
: `import { ${imports[0]} } from '${fromModule}'`;
|
|
25
28
|
const pluginExports = Object.entries(components)
|
|
26
29
|
.map(([component, plugins]) => {
|
|
27
30
|
const duplicateImports = new Set();
|
|
@@ -37,30 +40,32 @@ function generateInterceptor(plugin) {
|
|
|
37
40
|
return true;
|
|
38
41
|
})
|
|
39
42
|
.map((name) => {
|
|
40
|
-
const result = `
|
|
41
|
-
<${name} {...props}
|
|
42
|
-
|
|
43
|
+
const result = `function ${name}Interceptor(props: ${component}Props) {
|
|
44
|
+
return <${name} {...props} Prev={${carry}} />
|
|
45
|
+
}`;
|
|
43
46
|
carry = `${name}Interceptor`;
|
|
44
47
|
return result;
|
|
45
48
|
})
|
|
46
49
|
.join('\n');
|
|
47
|
-
return `
|
|
50
|
+
return `
|
|
51
|
+
/**
|
|
52
|
+
* Interceptor for \`<${component}/>\` with these plugins:
|
|
53
|
+
*
|
|
54
|
+
${plugins.map((p) => ` * - \`${p.plugin}\``).join('\n')}
|
|
55
|
+
*/
|
|
56
|
+
type ${component}Props = ComponentProps<typeof ${component}Base>
|
|
48
57
|
|
|
49
58
|
${pluginStr}
|
|
50
59
|
export const ${component} = ${carry}`;
|
|
51
60
|
})
|
|
52
61
|
.join('\n');
|
|
53
62
|
const componentExports = `export * from '${fromModule}'`;
|
|
54
|
-
const template = `/* This file is automatically generated
|
|
55
|
-
|
|
56
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
57
|
-
/* eslint-disable import/export */
|
|
63
|
+
const template = `/* This file is automatically generated for ${dependency} */
|
|
58
64
|
|
|
65
|
+
${componentExports}
|
|
59
66
|
${pluginImports}
|
|
67
|
+
import { ComponentProps } from 'react'
|
|
60
68
|
${importInjectables}
|
|
61
|
-
|
|
62
|
-
${componentExports}
|
|
63
|
-
|
|
64
69
|
${pluginExports}
|
|
65
70
|
`;
|
|
66
71
|
return { ...plugin, template };
|
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": "4.31.0-canary.
|
|
5
|
+
"version": "4.31.0-canary.3",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"typings": "dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"prepack": "yarn build"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@graphcommerce/cli": "4.31.0-canary.
|
|
16
|
+
"@graphcommerce/cli": "4.31.0-canary.3",
|
|
17
17
|
"@lingui/loader": "^3.14.0",
|
|
18
18
|
"@swc/core": "^1.3.10",
|
|
19
19
|
"js-yaml-loader": "^1.2.2",
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextConfig } from 'next/dist/server/config-shared'
|
|
2
|
-
import React from 'react'
|
|
2
|
+
import type React from 'react'
|
|
3
3
|
import { withGraphCommerce } from './withGraphCommerce'
|
|
4
4
|
|
|
5
5
|
export * from './utils/isMonorepo'
|
|
@@ -15,5 +15,5 @@ export function withYarn1Scopes(packages?: string[]): (config: NextConfig) => Ne
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export type PluginProps<P extends Record<string, unknown> = Record<string, unknown>> = P & {
|
|
18
|
-
|
|
18
|
+
Prev: React.FC<P>
|
|
19
19
|
}
|
|
@@ -77,13 +77,13 @@ export class InterceptorPlugin {
|
|
|
77
77
|
|
|
78
78
|
const interceptorForRequest = this.interceptorByDepependency[resource.request]
|
|
79
79
|
if (interceptorForRequest) {
|
|
80
|
-
logger.log(`Intercepting... ${interceptorForRequest.dependency}`)
|
|
80
|
+
logger.log(`Intercepting dep... ${interceptorForRequest.dependency}`)
|
|
81
81
|
resource.request = `${interceptorForRequest.denormalized}.interceptor.tsx`
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
const interceptorForPath = this.interceptors[requestPath]
|
|
85
85
|
if (interceptorForPath) {
|
|
86
|
-
logger.log(`Intercepting... ${interceptorForPath.fromRoot}`)
|
|
86
|
+
logger.log(`Intercepting fromRoot... ${interceptorForPath.fromRoot}`)
|
|
87
87
|
resource.request = `${resource.request}.interceptor.tsx`
|
|
88
88
|
}
|
|
89
89
|
})
|
|
@@ -15,7 +15,7 @@ type Plugin = ResolveDependencyReturn & {
|
|
|
15
15
|
export type MaterializedPlugin = Plugin & { template: string }
|
|
16
16
|
|
|
17
17
|
export function generateInterceptor(plugin: Plugin): MaterializedPlugin {
|
|
18
|
-
const { fromModule, components } = plugin
|
|
18
|
+
const { fromModule, dependency, components } = plugin
|
|
19
19
|
|
|
20
20
|
const pluginImports = Object.entries(components)
|
|
21
21
|
.map(([_, plugins]) => {
|
|
@@ -39,9 +39,15 @@ export function generateInterceptor(plugin: Plugin): MaterializedPlugin {
|
|
|
39
39
|
})
|
|
40
40
|
.join('\n')
|
|
41
41
|
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const imports = Object.entries(components).map(
|
|
43
|
+
([component]) => `${component} as ${component}Base`,
|
|
44
|
+
)
|
|
45
|
+
const importInjectables =
|
|
46
|
+
imports.length > 1
|
|
47
|
+
? `import {
|
|
48
|
+
${imports.join(',\n ')},
|
|
49
|
+
} from '${fromModule}'`
|
|
50
|
+
: `import { ${imports[0]} } from '${fromModule}'`
|
|
45
51
|
|
|
46
52
|
const pluginExports = Object.entries(components)
|
|
47
53
|
.map(([component, plugins]) => {
|
|
@@ -59,15 +65,21 @@ export function generateInterceptor(plugin: Plugin): MaterializedPlugin {
|
|
|
59
65
|
return true
|
|
60
66
|
})
|
|
61
67
|
.map((name) => {
|
|
62
|
-
const result = `
|
|
63
|
-
<${name} {...props}
|
|
64
|
-
|
|
68
|
+
const result = `function ${name}Interceptor(props: ${component}Props) {
|
|
69
|
+
return <${name} {...props} Prev={${carry}} />
|
|
70
|
+
}`
|
|
65
71
|
carry = `${name}Interceptor`
|
|
66
72
|
return result
|
|
67
73
|
})
|
|
68
74
|
.join('\n')
|
|
69
75
|
|
|
70
|
-
return `
|
|
76
|
+
return `
|
|
77
|
+
/**
|
|
78
|
+
* Interceptor for \`<${component}/>\` with these plugins:
|
|
79
|
+
*
|
|
80
|
+
${plugins.map((p) => ` * - \`${p.plugin}\``).join('\n')}
|
|
81
|
+
*/
|
|
82
|
+
type ${component}Props = ComponentProps<typeof ${component}Base>
|
|
71
83
|
|
|
72
84
|
${pluginStr}
|
|
73
85
|
export const ${component} = ${carry}`
|
|
@@ -76,16 +88,12 @@ export const ${component} = ${carry}`
|
|
|
76
88
|
|
|
77
89
|
const componentExports = `export * from '${fromModule}'`
|
|
78
90
|
|
|
79
|
-
const template = `/* This file is automatically generated
|
|
80
|
-
|
|
81
|
-
/* eslint-disable import/no-extraneous-dependencies */
|
|
82
|
-
/* eslint-disable import/export */
|
|
91
|
+
const template = `/* This file is automatically generated for ${dependency} */
|
|
83
92
|
|
|
93
|
+
${componentExports}
|
|
84
94
|
${pluginImports}
|
|
95
|
+
import { ComponentProps } from 'react'
|
|
85
96
|
${importInjectables}
|
|
86
|
-
|
|
87
|
-
${componentExports}
|
|
88
|
-
|
|
89
97
|
${pluginExports}
|
|
90
98
|
`
|
|
91
99
|
|