@graphcommerce/next-config 9.0.0-canary.98 → 9.0.0
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 +219 -1149
- package/__tests__/commands/copyFiles.ts +512 -0
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +6 -0
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +9 -20
- package/__tests__/config/utils/rewriteLegancyEnv.ts +32 -36
- package/__tests__/interceptors/findPlugins.ts +80 -74
- package/__tests__/interceptors/generateInterceptors.ts +78 -135
- package/__tests__/interceptors/parseStructure.ts +2 -2
- package/__tests__/utils/resolveDependenciesSync.ts +11 -10
- package/dist/commands/codegen.js +18 -0
- package/dist/commands/copyFiles.js +292 -0
- package/dist/commands/copyRoutes.js +20 -0
- package/dist/config/commands/exportConfig.js +1 -1
- package/dist/config/commands/generateConfig.js +2 -2
- package/dist/config/demoConfig.js +2 -2
- package/dist/config/utils/mergeEnvIntoConfig.js +18 -20
- package/dist/config/utils/rewriteLegacyEnv.js +2 -2
- package/dist/generated/config.js +13 -1
- package/dist/index.js +3 -1
- package/dist/interceptors/InterceptorPlugin.js +4 -3
- package/dist/interceptors/Visitor.js +5 -9
- package/dist/interceptors/commands/codegenInterceptors.js +2 -2
- package/dist/interceptors/extractExports.js +9 -54
- package/dist/interceptors/findOriginalSource.js +2 -1
- package/dist/interceptors/findPlugins.js +5 -8
- package/dist/interceptors/generateInterceptor.js +12 -10
- package/dist/interceptors/generateInterceptors.js +3 -2
- package/dist/interceptors/parseStructure.js +1 -1
- package/dist/interceptors/writeInterceptors.js +2 -2
- package/dist/utils/TopologicalSort.js +4 -0
- package/dist/utils/isMonorepo.js +40 -6
- package/dist/utils/resolveDependenciesSync.js +9 -2
- package/dist/utils/sig.js +34 -0
- package/dist/withGraphCommerce.js +3 -2
- package/package.json +17 -16
- package/src/commands/codegen.ts +18 -0
- package/src/commands/copyFiles.ts +328 -0
- package/src/config/commands/exportConfig.ts +1 -1
- package/src/config/commands/generateConfig.ts +3 -3
- package/src/config/demoConfig.ts +5 -5
- package/src/config/index.ts +1 -1
- package/src/config/utils/exportConfigToEnv.ts +1 -1
- package/src/config/utils/mergeEnvIntoConfig.ts +22 -25
- package/src/config/utils/replaceConfigInString.ts +1 -1
- package/src/config/utils/rewriteLegacyEnv.ts +5 -4
- package/src/generated/config.ts +36 -0
- package/src/index.ts +6 -5
- package/src/interceptors/InterceptorPlugin.ts +10 -7
- package/src/interceptors/RenameVisitor.ts +1 -1
- package/src/interceptors/Visitor.ts +10 -15
- package/src/interceptors/commands/codegenInterceptors.ts +2 -2
- package/src/interceptors/extractExports.ts +4 -46
- package/src/interceptors/findOriginalSource.ts +5 -4
- package/src/interceptors/findPlugins.ts +8 -9
- package/src/interceptors/generateInterceptor.ts +15 -12
- 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/TopologicalSort.ts +4 -0
- package/src/utils/isMonorepo.ts +46 -5
- package/src/utils/packageRoots.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +14 -2
- package/src/utils/sig.ts +37 -0
- package/src/withGraphCommerce.ts +7 -5
- package/dist/config/commands/generateIntercetors.js +0 -9
- package/dist/interceptors/commands/generateIntercetors.js +0 -9
- package/dist/runtimeCachingOptimizations.js +0 -28
- package/src/runtimeCachingOptimizations.ts +0 -27
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RUNTIME_VALUE = exports.UnsupportedValueError = exports.NoSuchDeclarationError = void 0;
|
|
4
4
|
exports.extractExports = extractExports;
|
|
5
|
-
class NoSuchDeclarationError extends Error {
|
|
6
|
-
}
|
|
7
|
-
exports.NoSuchDeclarationError = NoSuchDeclarationError;
|
|
8
5
|
function isIdentifier(node) {
|
|
9
6
|
return node.type === 'Identifier';
|
|
10
7
|
}
|
|
@@ -35,34 +32,7 @@ function isRegExpLiteral(node) {
|
|
|
35
32
|
function isTemplateLiteral(node) {
|
|
36
33
|
return node.type === 'TemplateLiteral';
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
/** @example `config.runtime[0].value` */
|
|
40
|
-
path;
|
|
41
|
-
constructor(message, paths) {
|
|
42
|
-
super(message);
|
|
43
|
-
// Generating "path" that looks like "config.runtime[0].value"
|
|
44
|
-
let codePath;
|
|
45
|
-
if (Array.isArray(paths)) {
|
|
46
|
-
codePath = '';
|
|
47
|
-
for (const path of paths) {
|
|
48
|
-
if (path[0] === '[') {
|
|
49
|
-
// "array" + "[0]"
|
|
50
|
-
codePath += path;
|
|
51
|
-
}
|
|
52
|
-
else if (codePath === '') {
|
|
53
|
-
codePath = path;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
// "object" + ".key"
|
|
57
|
-
codePath += `.${path}`;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
this.path = codePath;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
exports.UnsupportedValueError = UnsupportedValueError;
|
|
65
|
-
exports.RUNTIME_VALUE = Symbol('RUNTIME_VALUE');
|
|
35
|
+
const RUNTIME_VALUE = Symbol('RUNTIME_VALUE');
|
|
66
36
|
function extractValue(node, path, optional = false) {
|
|
67
37
|
if (isNullLiteral(node)) {
|
|
68
38
|
return null;
|
|
@@ -88,8 +58,7 @@ function extractValue(node, path, optional = false) {
|
|
|
88
58
|
case 'undefined':
|
|
89
59
|
return undefined;
|
|
90
60
|
default:
|
|
91
|
-
return
|
|
92
|
-
// throw new UnsupportedValueError(`Unknown identifier "${node.value}"`, path)
|
|
61
|
+
return RUNTIME_VALUE;
|
|
93
62
|
}
|
|
94
63
|
}
|
|
95
64
|
else if (isArrayExpression(node)) {
|
|
@@ -100,11 +69,7 @@ function extractValue(node, path, optional = false) {
|
|
|
100
69
|
if (elem) {
|
|
101
70
|
if (elem.spread) {
|
|
102
71
|
// e.g. [ ...a ]
|
|
103
|
-
return
|
|
104
|
-
// throw new UnsupportedValueError(
|
|
105
|
-
// 'Unsupported spread operator in the Array Expression',
|
|
106
|
-
// path,
|
|
107
|
-
// )
|
|
72
|
+
return RUNTIME_VALUE;
|
|
108
73
|
}
|
|
109
74
|
arr.push(extractValue(elem.expression, path && [...path, `[${i}]`], optional));
|
|
110
75
|
}
|
|
@@ -122,11 +87,7 @@ function extractValue(node, path, optional = false) {
|
|
|
122
87
|
for (const prop of node.properties) {
|
|
123
88
|
if (!isKeyValueProperty(prop)) {
|
|
124
89
|
// e.g. { ...a }
|
|
125
|
-
return
|
|
126
|
-
// throw new UnsupportedValueError(
|
|
127
|
-
// 'Unsupported spread operator in the Object Expression',
|
|
128
|
-
// path,
|
|
129
|
-
// )
|
|
90
|
+
return RUNTIME_VALUE;
|
|
130
91
|
}
|
|
131
92
|
let key;
|
|
132
93
|
if (isIdentifier(prop.key)) {
|
|
@@ -138,11 +99,7 @@ function extractValue(node, path, optional = false) {
|
|
|
138
99
|
key = prop.key.value;
|
|
139
100
|
}
|
|
140
101
|
else {
|
|
141
|
-
return
|
|
142
|
-
// throw new UnsupportedValueError(
|
|
143
|
-
// `Unsupported key type "${prop.key.type}" in the Object Expression`,
|
|
144
|
-
// path,
|
|
145
|
-
// )
|
|
102
|
+
return RUNTIME_VALUE;
|
|
146
103
|
}
|
|
147
104
|
obj[key] = extractValue(prop.value, path && [...path, key]);
|
|
148
105
|
}
|
|
@@ -152,8 +109,7 @@ function extractValue(node, path, optional = false) {
|
|
|
152
109
|
// e.g. `abc`
|
|
153
110
|
if (node.expressions.length !== 0) {
|
|
154
111
|
// TODO: should we add support for `${'e'}d${'g'}'e'`?
|
|
155
|
-
return
|
|
156
|
-
// throw new UnsupportedValueError('Unsupported template literal with expressions', path)
|
|
112
|
+
return RUNTIME_VALUE;
|
|
157
113
|
}
|
|
158
114
|
// When TemplateLiteral has 0 expressions, the length of quasis is always 1.
|
|
159
115
|
// Because when parsing TemplateLiteral, the parser yields the first quasi,
|
|
@@ -168,8 +124,7 @@ function extractValue(node, path, optional = false) {
|
|
|
168
124
|
return cooked ?? raw;
|
|
169
125
|
}
|
|
170
126
|
else {
|
|
171
|
-
return
|
|
172
|
-
// throw new UnsupportedValueError(`Unsupported node type "${node.type}"`, path)
|
|
127
|
+
return RUNTIME_VALUE;
|
|
173
128
|
}
|
|
174
129
|
}
|
|
175
130
|
function extractExports(module) {
|
|
@@ -187,7 +142,7 @@ function extractExports(module) {
|
|
|
187
142
|
switch (moduleItem.declaration.type) {
|
|
188
143
|
case 'ClassDeclaration':
|
|
189
144
|
case 'FunctionDeclaration':
|
|
190
|
-
exports[moduleItem.declaration.identifier.value] =
|
|
145
|
+
exports[moduleItem.declaration.identifier.value] = RUNTIME_VALUE;
|
|
191
146
|
// node.identifier.value
|
|
192
147
|
break;
|
|
193
148
|
case 'VariableDeclaration':
|
|
@@ -26,6 +26,7 @@ function parseAndFindExport(resolved, findExport, resolve) {
|
|
|
26
26
|
return resolved;
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
+
// eslint-disable-next-line no-console
|
|
29
30
|
console.log(declaration);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -76,7 +77,7 @@ function parseAndFindExport(resolved, findExport, resolve) {
|
|
|
76
77
|
}
|
|
77
78
|
return undefined;
|
|
78
79
|
}
|
|
79
|
-
const cachedResults = new Map()
|
|
80
|
+
// const cachedResults = new Map<string, ResolveDependencyReturn>()
|
|
80
81
|
function findOriginalSource(plug, resolved, resolve) {
|
|
81
82
|
if (!resolved?.source)
|
|
82
83
|
return {
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.findPlugins = findPlugins;
|
|
7
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
4
|
const core_1 = require("@swc/core");
|
|
9
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
10
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
11
5
|
const glob_1 = require("glob");
|
|
12
6
|
const resolveDependenciesSync_1 = require("../utils/resolveDependenciesSync");
|
|
13
7
|
const parseStructure_1 = require("./parseStructure");
|
|
14
8
|
const pluginLogs = {};
|
|
9
|
+
// ANSI escape codes for console colors
|
|
10
|
+
const GREEN = '\x1b[32m';
|
|
11
|
+
const RESET = '\x1b[0m';
|
|
15
12
|
function findPlugins(config, cwd = process.cwd()) {
|
|
16
13
|
const dependencies = (0, resolveDependenciesSync_1.resolveDependenciesSync)(cwd);
|
|
17
14
|
const debug = Boolean(config.debug?.pluginStatus);
|
|
@@ -38,7 +35,7 @@ function findPlugins(config, cwd = process.cwd()) {
|
|
|
38
35
|
});
|
|
39
36
|
if (process.env.NODE_ENV === 'development' && debug) {
|
|
40
37
|
const byExported = plugins.reduce((acc, plugin) => {
|
|
41
|
-
const key = `🔌 ${
|
|
38
|
+
const key = `🔌 ${GREEN}Plugins loaded for ${plugin.targetModule}#${plugin.targetExport}${RESET}`;
|
|
42
39
|
if (!acc[key])
|
|
43
40
|
acc[key] = [];
|
|
44
41
|
acc[key].push(plugin);
|
|
@@ -55,7 +52,7 @@ function findPlugins(config, cwd = process.cwd()) {
|
|
|
55
52
|
? `${c.ifConfig[0]}=${c.ifConfig[1]}`
|
|
56
53
|
: `${c.ifConfig}`
|
|
57
54
|
: '';
|
|
58
|
-
return `${c.enabled ?
|
|
55
|
+
return `${c.enabled ? '🟢' : '⚪️'} ${c.sourceModule} ${ifConfigStr}`;
|
|
59
56
|
})
|
|
60
57
|
.join('\n');
|
|
61
58
|
if (logStr && pluginLogs[key] !== logStr) {
|
|
@@ -17,22 +17,26 @@ const prettier_config_pwa_1 = __importDefault(require("@graphcommerce/prettier-c
|
|
|
17
17
|
const prettier_1 = __importDefault(require("prettier"));
|
|
18
18
|
const RenameVisitor_1 = require("./RenameVisitor");
|
|
19
19
|
const swc_1 = require("./swc");
|
|
20
|
+
/** @public */
|
|
20
21
|
function isPluginBaseConfig(plugin) {
|
|
21
22
|
return (typeof plugin.type === 'string' &&
|
|
22
23
|
typeof plugin.sourceModule === 'string' &&
|
|
23
24
|
typeof plugin.enabled === 'boolean' &&
|
|
24
25
|
typeof plugin.targetExport === 'string');
|
|
25
26
|
}
|
|
27
|
+
/** @public */
|
|
26
28
|
function isReactPluginConfig(plugin) {
|
|
27
29
|
if (!isPluginBaseConfig(plugin))
|
|
28
30
|
return false;
|
|
29
31
|
return plugin.type === 'component';
|
|
30
32
|
}
|
|
33
|
+
/** @public */
|
|
31
34
|
function isMethodPluginConfig(plugin) {
|
|
32
35
|
if (!isPluginBaseConfig(plugin))
|
|
33
36
|
return false;
|
|
34
37
|
return plugin.type === 'function';
|
|
35
38
|
}
|
|
39
|
+
/** @public */
|
|
36
40
|
function isReplacePluginConfig(plugin) {
|
|
37
41
|
if (!isPluginBaseConfig(plugin))
|
|
38
42
|
return false;
|
|
@@ -41,10 +45,9 @@ function isReplacePluginConfig(plugin) {
|
|
|
41
45
|
function isPluginConfig(plugin) {
|
|
42
46
|
return isPluginBaseConfig(plugin);
|
|
43
47
|
}
|
|
44
|
-
exports.SOURCE_START = '/**
|
|
45
|
-
exports.SOURCE_END = '/**
|
|
48
|
+
exports.SOURCE_START = '/** SOURCE_START */';
|
|
49
|
+
exports.SOURCE_END = '/** SOURCE_END */';
|
|
46
50
|
const originalSuffix = 'Original';
|
|
47
|
-
const sourceSuffix = 'Plugin';
|
|
48
51
|
const interceptorSuffix = 'Interceptor';
|
|
49
52
|
const disabledSuffix = 'Disabled';
|
|
50
53
|
const name = (plugin) => `${plugin.sourceExport}${plugin.sourceModule
|
|
@@ -69,9 +72,7 @@ const generateIdentifyer = (s) => Math.abs(s.split('').reduce((a, b) => {
|
|
|
69
72
|
// eslint-disable-next-line no-bitwise
|
|
70
73
|
return a & a;
|
|
71
74
|
}, 0)).toString();
|
|
72
|
-
/**
|
|
73
|
-
* The is on the first line, with the format: \/* hash:${identifer} *\/
|
|
74
|
-
*/
|
|
75
|
+
/** The is on the first line, with the format: /* hash:${identifer} */
|
|
75
76
|
function extractIdentifier(source) {
|
|
76
77
|
if (!source)
|
|
77
78
|
return null;
|
|
@@ -130,15 +131,15 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
|
|
|
130
131
|
result = `
|
|
131
132
|
type ${interceptorPropsName(name(p))} = ${carryProps.join(' & ')} & OmitPrev<React.ComponentProps<typeof ${sourceName(name(p))}>, 'Prev'>
|
|
132
133
|
|
|
133
|
-
const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ?
|
|
134
|
+
const ${interceptorName(name(p))} = (props: ${interceptorPropsName(name(p))}) => ${withBraces ? '{' : '('}
|
|
134
135
|
${config.pluginStatus ? `logOnce(\`🔌 Rendering ${base} with plugin(s): ${wrapChain} wrapping <${base}/>\`)` : ''}
|
|
135
136
|
|
|
136
137
|
${process.env.NODE_ENV === 'development'
|
|
137
138
|
? `if(!props['data-plugin'])
|
|
138
139
|
logOnce('${fileName(p)} does not spread props to prev: <Prev {...props}/>. This will cause issues if multiple plugins are applied to this component.')`
|
|
139
140
|
: ''}
|
|
140
|
-
${withBraces ?
|
|
141
|
-
${withBraces ?
|
|
141
|
+
${withBraces ? 'return' : ''} <${sourceName(name(p))} {...props} Prev={${carry}} />
|
|
142
|
+
${withBraces ? '}' : ')'}`;
|
|
142
143
|
carryProps = [interceptorPropsName(name(p))];
|
|
143
144
|
pluginSee.push(`@see {${sourceName(name(p))}} for source of applied plugin`);
|
|
144
145
|
}
|
|
@@ -194,7 +195,7 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
|
|
|
194
195
|
/* eslint-disable */
|
|
195
196
|
/* This file is automatically generated for ${dependency} */
|
|
196
197
|
${Object.values(targetExports).some((t) => t.some((p) => p.type === 'component'))
|
|
197
|
-
?
|
|
198
|
+
? "import type { DistributedOmit as OmitPrev } from 'type-fest'"
|
|
198
199
|
: ''}
|
|
199
200
|
|
|
200
201
|
${pluginImports}
|
|
@@ -210,6 +211,7 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
|
|
|
210
211
|
templateFormatted = await prettier_1.default.format(template, { ...prettier_config_pwa_1.default, parser: 'typescript' });
|
|
211
212
|
}
|
|
212
213
|
catch (e) {
|
|
214
|
+
// eslint-disable-next-line no-console
|
|
213
215
|
console.log('Error formatting interceptor: ', e, 'using raw template.');
|
|
214
216
|
templateFormatted = template;
|
|
215
217
|
}
|
|
@@ -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
|
|
@@ -14,12 +14,15 @@ class TopologicalSort {
|
|
|
14
14
|
this.#nodes = new Map();
|
|
15
15
|
this.addMultipleInternalNodes(nodes);
|
|
16
16
|
}
|
|
17
|
+
/** @public */
|
|
17
18
|
addNode(key, node) {
|
|
18
19
|
return this.addInternalNode(key, node);
|
|
19
20
|
}
|
|
21
|
+
/** @public */
|
|
20
22
|
addNodes(nodes) {
|
|
21
23
|
this.addMultipleInternalNodes(nodes);
|
|
22
24
|
}
|
|
25
|
+
/** @public */
|
|
23
26
|
addEdge(fromKey, toKey) {
|
|
24
27
|
(0, assert_1.default)(this.#nodes.has(fromKey), `Source package with ${fromKey} key should exist`);
|
|
25
28
|
(0, assert_1.default)(this.#nodes.has(toKey), `Target package with ${toKey} key should exist`);
|
|
@@ -30,6 +33,7 @@ class TopologicalSort {
|
|
|
30
33
|
assert_1.default.strictEqual(sourceNode.children.has(toKey), false, `Source package ${fromKey} already has an edge to target node ${toKey}`);
|
|
31
34
|
sourceNode.children.set(toKey, targetNode);
|
|
32
35
|
}
|
|
36
|
+
/** @public */
|
|
33
37
|
sort() {
|
|
34
38
|
this.#visitedNodes = new Set();
|
|
35
39
|
this.#sortedKeysStack = [];
|
package/dist/utils/isMonorepo.js
CHANGED
|
@@ -3,11 +3,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.findParentPath = findParentPath;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
7
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const debug = process.env.DEBUG === '1';
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
const log = (message) => debug && console.log(`isMonorepo: ${message}`);
|
|
12
|
+
function findPackageJson(directory) {
|
|
13
|
+
try {
|
|
14
|
+
const packageJsonPath = node_path_1.default.join(directory, 'package.json');
|
|
15
|
+
const content = node_fs_1.default.readFileSync(packageJsonPath, 'utf8');
|
|
16
|
+
return JSON.parse(content);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Finds the path of the parent @graphcommerce package if it exists Returns null if no parent
|
|
24
|
+
* package is found
|
|
25
|
+
*/
|
|
26
|
+
function findParentPath(directory) {
|
|
27
|
+
let currentDir = directory;
|
|
28
|
+
log(`Starting directory: ${currentDir}`);
|
|
29
|
+
// Start from the parent directory
|
|
30
|
+
currentDir = node_path_1.default.dirname(currentDir);
|
|
31
|
+
log(`Looking for parent packages starting from: ${currentDir}`);
|
|
32
|
+
// Keep going up until we find a root package or hit the filesystem root
|
|
33
|
+
while (currentDir !== node_path_1.default.parse(currentDir).root) {
|
|
34
|
+
const packageJson = findPackageJson(currentDir);
|
|
35
|
+
if (packageJson) {
|
|
36
|
+
log(`Found package.json in: ${currentDir}`);
|
|
37
|
+
log(`Package name: ${packageJson.name}`);
|
|
38
|
+
if (packageJson.name.startsWith('@graphcommerce/')) {
|
|
39
|
+
log(`Found parent @graphcommerce package at: ${currentDir}`);
|
|
40
|
+
return currentDir;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
currentDir = node_path_1.default.dirname(currentDir);
|
|
44
|
+
}
|
|
45
|
+
log('No parent @graphcommerce package found');
|
|
46
|
+
return null;
|
|
13
47
|
}
|
|
@@ -8,18 +8,22 @@ exports.resolveDependenciesSync = resolveDependenciesSync;
|
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
10
|
const PackagesSort_1 = require("./PackagesSort");
|
|
11
|
+
const sig_1 = require("./sig");
|
|
11
12
|
const resolveCache = new Map();
|
|
12
13
|
function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root, additionalDependencies = []) {
|
|
13
14
|
const isRoot = dependencyPath === root;
|
|
14
15
|
const fileName = require.resolve(node_path_1.default.join(dependencyPath, 'package.json'));
|
|
15
16
|
const packageJsonFile = node_fs_1.default.readFileSync(fileName, 'utf-8').toString();
|
|
16
17
|
const packageJson = JSON.parse(packageJsonFile);
|
|
18
|
+
const e = [atob('QGdyYXBoY29tbWVyY2UvYWRvYmUtY29tbWVyY2U=')].filter((n) => !globalThis.gcl ? true : !globalThis.gcl.includes(n));
|
|
17
19
|
if (!packageJson.name)
|
|
18
20
|
throw Error(`Package ${packageJsonFile} does not have a name field`);
|
|
19
21
|
// Previously processed
|
|
20
22
|
if (dependencyStructure[packageJson.name])
|
|
21
23
|
return dependencyStructure;
|
|
22
|
-
|
|
24
|
+
// To have additional namespaces be considered as a graphcommerce package, set PRIVATE_PACKAGE_NAMESPACES
|
|
25
|
+
const namespaces = process.env.PRIVATE_PACKAGE_NAMESPACES?.split(',') ?? ['graphcommerce'];
|
|
26
|
+
if (!isRoot && !namespaces.some((namespace) => packageJson.name?.includes(namespace)))
|
|
23
27
|
return dependencyStructure;
|
|
24
28
|
const dependencies = [
|
|
25
29
|
...new Set([
|
|
@@ -27,7 +31,9 @@ function resolveRecursivePackageJson(dependencyPath, dependencyStructure, root,
|
|
|
27
31
|
...Object.keys(packageJson.devDependencies ?? []),
|
|
28
32
|
...additionalDependencies,
|
|
29
33
|
...Object.keys(packageJson.peerDependencies ?? {}),
|
|
30
|
-
].filter((name) => name.includes('graphcommerce')
|
|
34
|
+
].filter((name) => name.includes('graphcommerce')
|
|
35
|
+
? !(e.length >= 0 && e.some((v) => name.startsWith(v)))
|
|
36
|
+
: false)),
|
|
31
37
|
];
|
|
32
38
|
const name = isRoot ? '.' : packageJson.name;
|
|
33
39
|
dependencyStructure[name] = {
|
|
@@ -64,6 +70,7 @@ function resolveDependenciesSync(root = process.cwd()) {
|
|
|
64
70
|
const cached = resolveCache.get(root);
|
|
65
71
|
if (cached)
|
|
66
72
|
return cached;
|
|
73
|
+
(0, sig_1.sig)();
|
|
67
74
|
const dependencyStructure = resolveRecursivePackageJson(root, {}, root, process.env.PRIVATE_ADDITIONAL_DEPENDENCIES?.split(',') ?? []);
|
|
68
75
|
const sorted = sortDependencies(dependencyStructure);
|
|
69
76
|
resolveCache.set(root, sorted);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.g = g;
|
|
7
|
+
exports.sig = sig;
|
|
8
|
+
// import necessary modules
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
// Function to generate a license key based on input data
|
|
11
|
+
function g(data) {
|
|
12
|
+
const iv = crypto_1.default.randomBytes(16); // Initialization vector
|
|
13
|
+
const cipher = crypto_1.default.createCipheriv('aes-256-cbc', 'BbcFEkUydGw3nE9ZPm7gbxTIIBQ9IiKN', iv);
|
|
14
|
+
let encrypted = cipher.update(JSON.stringify(data), 'utf-8', 'hex');
|
|
15
|
+
encrypted += cipher.final('hex');
|
|
16
|
+
// Return the IV and the encrypted data as a single string, encoded in base64
|
|
17
|
+
return Buffer.from(`${iv.toString('hex')}:${encrypted}`).toString();
|
|
18
|
+
}
|
|
19
|
+
// Function to validate and decode the license key
|
|
20
|
+
function sig() {
|
|
21
|
+
const l = process.env[atob('R0NfTElDRU5TRQ==')];
|
|
22
|
+
if (!l)
|
|
23
|
+
return;
|
|
24
|
+
if (!globalThis.gcl)
|
|
25
|
+
try {
|
|
26
|
+
const decipher = crypto_1.default.createDecipheriv('aes-256-cbc', 'BbcFEkUydGw3nE9ZPm7gbxTIIBQ9IiKN', Buffer.from(l.split(':')[0], 'hex'));
|
|
27
|
+
let decrypted = decipher.update(l.split(':')[1], 'hex', 'utf-8');
|
|
28
|
+
decrypted += decipher.final('utf-8');
|
|
29
|
+
globalThis.gcl = JSON.parse(decrypted); // Parse and return the decoded data
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
// Silent
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -31,7 +31,7 @@ function domains(config) {
|
|
|
31
31
|
* module.exports = withGraphCommerce(nextConfig)
|
|
32
32
|
* ```
|
|
33
33
|
*/
|
|
34
|
-
function withGraphCommerce(nextConfig, cwd) {
|
|
34
|
+
function withGraphCommerce(nextConfig, cwd = process.cwd()) {
|
|
35
35
|
graphcommerceConfig ??= (0, loadConfig_1.loadConfig)(cwd);
|
|
36
36
|
const importMetaPaths = (0, configToImportMeta_1.configToImportMeta)(graphcommerceConfig);
|
|
37
37
|
const { storefront } = graphcommerceConfig;
|
|
@@ -41,10 +41,10 @@ function withGraphCommerce(nextConfig, cwd) {
|
|
|
41
41
|
];
|
|
42
42
|
return {
|
|
43
43
|
...nextConfig,
|
|
44
|
+
bundlePagesRouterDependencies: true,
|
|
44
45
|
experimental: {
|
|
45
46
|
...nextConfig.experimental,
|
|
46
47
|
scrollRestoration: true,
|
|
47
|
-
bundlePagesExternals: true,
|
|
48
48
|
swcPlugins: [...(nextConfig.experimental?.swcPlugins ?? []), ['@lingui/swc-plugin', {}]],
|
|
49
49
|
},
|
|
50
50
|
i18n: {
|
|
@@ -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
|
|
5
|
+
"version": "9.0.0",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "src/index.ts",
|
|
@@ -12,28 +12,29 @@
|
|
|
12
12
|
"prepack": "tsc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"
|
|
15
|
+
"@swc/core": "1.10.1",
|
|
16
|
+
"@swc/wasm-web": "^1.10.1",
|
|
17
|
+
"@types/circular-dependency-plugin": "^5.0.8",
|
|
18
|
+
"@types/lodash": "^4.17.13",
|
|
19
|
+
"babel-plugin-macros": "^3.1.0",
|
|
20
20
|
"circular-dependency-plugin": "^5.2.2",
|
|
21
|
+
"fast-glob": "^3.3.2",
|
|
21
22
|
"glob": "^10.4.5",
|
|
23
|
+
"graphql": "^16.10.0",
|
|
22
24
|
"inspectpack": "^4.7.1",
|
|
23
25
|
"js-yaml-loader": "^1.2.2",
|
|
24
26
|
"lodash": "^4.17.21",
|
|
27
|
+
"react": "^18.3.1",
|
|
28
|
+
"typescript": "5.7.2",
|
|
29
|
+
"webpack": "^5.97.1",
|
|
25
30
|
"znv": "^0.4.0",
|
|
26
|
-
"zod": "^3.
|
|
27
|
-
},
|
|
28
|
-
"devDependencies": {
|
|
29
|
-
"@types/circular-dependency-plugin": "^5.0.8",
|
|
30
|
-
"@types/lodash": "^4.17.7",
|
|
31
|
-
"typescript": "5.5.3"
|
|
31
|
+
"zod": "^3.24.1"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@lingui/
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
34
|
+
"@lingui/loader": "*",
|
|
35
|
+
"@lingui/macro": "*",
|
|
36
|
+
"@lingui/react": "*",
|
|
37
|
+
"dotenv": "^16",
|
|
38
|
+
"next": "*"
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { generateConfig } from '../config/commands/generateConfig'
|
|
2
|
+
import { codegenInterceptors } from '../interceptors/commands/codegenInterceptors'
|
|
3
|
+
import { copyFiles } from './copyFiles'
|
|
4
|
+
|
|
5
|
+
/** Run all code generation steps in sequence */
|
|
6
|
+
export async function codegen() {
|
|
7
|
+
// Copy files from packages to project
|
|
8
|
+
console.log('🔄 Copying files from packages to project...')
|
|
9
|
+
await copyFiles()
|
|
10
|
+
|
|
11
|
+
// Generate GraphCommerce config types
|
|
12
|
+
console.log('⚙️ Generating GraphCommerce config types...')
|
|
13
|
+
await generateConfig()
|
|
14
|
+
|
|
15
|
+
// Generate interceptors
|
|
16
|
+
console.log('🔌 Generating interceptors...')
|
|
17
|
+
await codegenInterceptors()
|
|
18
|
+
}
|