@graphcommerce/next-config 9.0.0-canary.99 → 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 -1151
- 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 +76 -78
- 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
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codegen = codegen;
|
|
4
|
+
const generateConfig_1 = require("../config/commands/generateConfig");
|
|
5
|
+
const codegenInterceptors_1 = require("../interceptors/commands/codegenInterceptors");
|
|
6
|
+
const copyFiles_1 = require("./copyFiles");
|
|
7
|
+
/** Run all code generation steps in sequence */
|
|
8
|
+
async function codegen() {
|
|
9
|
+
// Copy files from packages to project
|
|
10
|
+
console.log('🔄 Copying files from packages to project...');
|
|
11
|
+
await (0, copyFiles_1.copyFiles)();
|
|
12
|
+
// Generate GraphCommerce config types
|
|
13
|
+
console.log('⚙️ Generating GraphCommerce config types...');
|
|
14
|
+
await (0, generateConfig_1.generateConfig)();
|
|
15
|
+
// Generate interceptors
|
|
16
|
+
console.log('🔌 Generating interceptors...');
|
|
17
|
+
await (0, codegenInterceptors_1.codegenInterceptors)();
|
|
18
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
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.copyFiles = copyFiles;
|
|
7
|
+
/* eslint-disable no-await-in-loop */
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
11
|
+
const resolveDependenciesSync_1 = require("../utils/resolveDependenciesSync");
|
|
12
|
+
// Add debug logging helper
|
|
13
|
+
const debug = (...args) => {
|
|
14
|
+
if (process.env.DEBUG)
|
|
15
|
+
console.log('[copy-files]', ...args);
|
|
16
|
+
};
|
|
17
|
+
// Add constants for the magic comments
|
|
18
|
+
const MANAGED_BY_GC = '// managed by: graphcommerce';
|
|
19
|
+
const MANAGED_LOCALLY = '// managed by: local';
|
|
20
|
+
const GITIGNORE_SECTION_START = '# managed by: graphcommerce';
|
|
21
|
+
const GITIGNORE_SECTION_END = '# end managed by: graphcommerce';
|
|
22
|
+
/**
|
|
23
|
+
* Updates the .gitignore file with a list of GraphCommerce managed files
|
|
24
|
+
*
|
|
25
|
+
* - Removes any existing GraphCommerce managed files section
|
|
26
|
+
* - If managedFiles is not empty, adds a new section with the files
|
|
27
|
+
* - If managedFiles is empty, just cleans up the existing section
|
|
28
|
+
* - Ensures the file ends with a newline
|
|
29
|
+
*/
|
|
30
|
+
async function updateGitignore(managedFiles) {
|
|
31
|
+
const gitignorePath = path_1.default.join(process.cwd(), '.gitignore');
|
|
32
|
+
let content;
|
|
33
|
+
try {
|
|
34
|
+
content = await promises_1.default.readFile(gitignorePath, 'utf-8');
|
|
35
|
+
debug('Reading existing .gitignore');
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
debug('.gitignore not found, creating new file');
|
|
39
|
+
content = '';
|
|
40
|
+
}
|
|
41
|
+
// Remove existing GraphCommerce section if it exists
|
|
42
|
+
const sectionRegex = new RegExp(`${GITIGNORE_SECTION_START}[\\s\\S]*?${GITIGNORE_SECTION_END}\\n?`, 'g');
|
|
43
|
+
content = content.replace(sectionRegex, '');
|
|
44
|
+
// Only add new section if there are files to manage
|
|
45
|
+
if (managedFiles.length > 0) {
|
|
46
|
+
const newSection = [
|
|
47
|
+
GITIGNORE_SECTION_START,
|
|
48
|
+
...managedFiles.sort(),
|
|
49
|
+
GITIGNORE_SECTION_END,
|
|
50
|
+
'', // Empty line at the end
|
|
51
|
+
].join('\n');
|
|
52
|
+
// Append the new section
|
|
53
|
+
content = `${content.trim()}\n\n${newSection}`;
|
|
54
|
+
debug(`Updated .gitignore with ${managedFiles.length} managed files`);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
content = `${content.trim()}\n`;
|
|
58
|
+
debug('Cleaned up .gitignore managed section');
|
|
59
|
+
}
|
|
60
|
+
await promises_1.default.writeFile(gitignorePath, content);
|
|
61
|
+
}
|
|
62
|
+
/** Determines how a file should be managed based on its content */
|
|
63
|
+
function getFileManagement(content) {
|
|
64
|
+
if (!content)
|
|
65
|
+
return 'graphcommerce';
|
|
66
|
+
const contentStr = content.toString();
|
|
67
|
+
if (contentStr.startsWith(MANAGED_LOCALLY))
|
|
68
|
+
return 'local';
|
|
69
|
+
if (contentStr.startsWith(MANAGED_BY_GC))
|
|
70
|
+
return 'graphcommerce';
|
|
71
|
+
return 'unmanaged';
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The packages are @graphcommerce/* packages and have special treatment.
|
|
75
|
+
*
|
|
76
|
+
* 1. Glob the `copy/**` directory for each package and generate a list of files that need to be
|
|
77
|
+
* copied. Error if a file with the same path exists in another package.
|
|
78
|
+
* 2. Copy the files to the project directory (cwd).
|
|
79
|
+
*
|
|
80
|
+
* 1. If the file doesn't exist: Create directories and the file with "managed by: graphcommerce"
|
|
81
|
+
* 2. If the file exists and starts with "managed by: local": Skip the file
|
|
82
|
+
* 3. If the file exists but doesn't have a management comment: Suggest adding "managed by: local"
|
|
83
|
+
* 4. If the file is managed by graphcommerce: Update if content differs
|
|
84
|
+
*/
|
|
85
|
+
async function copyFiles() {
|
|
86
|
+
const startTime = performance.now();
|
|
87
|
+
debug('Starting copyFiles');
|
|
88
|
+
const cwd = process.cwd();
|
|
89
|
+
const deps = (0, resolveDependenciesSync_1.resolveDependenciesSync)();
|
|
90
|
+
const packages = [...deps.values()].filter((p) => p !== '.');
|
|
91
|
+
// Track files and their source packages to detect conflicts
|
|
92
|
+
const fileMap = new Map();
|
|
93
|
+
const managedFiles = new Set();
|
|
94
|
+
const existingManagedFiles = new Set();
|
|
95
|
+
// First scan existing files to find GraphCommerce managed ones
|
|
96
|
+
const scanStart = performance.now();
|
|
97
|
+
try {
|
|
98
|
+
// Use only default patterns for testing
|
|
99
|
+
const gitignorePatterns = [
|
|
100
|
+
'**/dist/**',
|
|
101
|
+
'**/build/**',
|
|
102
|
+
'**/.next/**',
|
|
103
|
+
'**/.git/**',
|
|
104
|
+
'**/node_modules/**',
|
|
105
|
+
];
|
|
106
|
+
const allFiles = await (0, fast_glob_1.default)('**/*', {
|
|
107
|
+
cwd,
|
|
108
|
+
dot: true,
|
|
109
|
+
ignore: gitignorePatterns,
|
|
110
|
+
onlyFiles: true,
|
|
111
|
+
});
|
|
112
|
+
debug(`Found ${allFiles.length} project files in ${(performance.now() - scanStart).toFixed(0)}ms`);
|
|
113
|
+
const readStart = performance.now();
|
|
114
|
+
await Promise.all(allFiles.map(async (file) => {
|
|
115
|
+
const filePath = path_1.default.join(cwd, file);
|
|
116
|
+
try {
|
|
117
|
+
const content = await promises_1.default.readFile(filePath);
|
|
118
|
+
if (getFileManagement(content) === 'graphcommerce') {
|
|
119
|
+
existingManagedFiles.add(file);
|
|
120
|
+
debug(`Found existing managed file: ${file}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
debug(`Error reading file ${file}:`, err);
|
|
125
|
+
}
|
|
126
|
+
}));
|
|
127
|
+
debug(`Read ${existingManagedFiles.size} managed files in ${(performance.now() - readStart).toFixed(0)}ms`);
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
debug('Error scanning project files:', err);
|
|
131
|
+
}
|
|
132
|
+
// First pass: collect all files and check for conflicts
|
|
133
|
+
const collectStart = performance.now();
|
|
134
|
+
await Promise.all(packages.map(async (pkg) => {
|
|
135
|
+
const copyDir = path_1.default.join(pkg, 'copy');
|
|
136
|
+
try {
|
|
137
|
+
const files = await (0, fast_glob_1.default)('**/*', { cwd: copyDir, dot: true, suppressErrors: true });
|
|
138
|
+
if (files.length > 0) {
|
|
139
|
+
debug(`Found files in ${pkg}:`, files);
|
|
140
|
+
for (const file of files) {
|
|
141
|
+
const sourcePath = path_1.default.join(copyDir, file);
|
|
142
|
+
const existing = fileMap.get(file);
|
|
143
|
+
if (existing) {
|
|
144
|
+
console.error(`Error: File conflict detected for '${file}'
|
|
145
|
+
Found in packages:
|
|
146
|
+
- ${existing.packagePath} -> ${existing.sourcePath}
|
|
147
|
+
- ${pkg} -> ${sourcePath}`);
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
fileMap.set(file, { sourcePath, packagePath: pkg });
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (err.code === 'ENOENT')
|
|
156
|
+
return;
|
|
157
|
+
console.error(`Error scanning directory ${copyDir}: ${err.message}\nPath: ${copyDir}`);
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
}));
|
|
161
|
+
debug(`Collected ${fileMap.size} files in ${(performance.now() - collectStart).toFixed(0)}ms`);
|
|
162
|
+
// Second pass: copy files and handle removals
|
|
163
|
+
const copyStart = performance.now();
|
|
164
|
+
await Promise.all(Array.from(fileMap.entries()).map(async ([file, { sourcePath }]) => {
|
|
165
|
+
const targetPath = path_1.default.join(cwd, file);
|
|
166
|
+
debug(`Processing file: ${file}`);
|
|
167
|
+
try {
|
|
168
|
+
await promises_1.default.mkdir(path_1.default.dirname(targetPath), { recursive: true });
|
|
169
|
+
const sourceContent = await promises_1.default.readFile(sourcePath);
|
|
170
|
+
const contentWithComment = Buffer.concat([
|
|
171
|
+
Buffer.from(`${MANAGED_BY_GC}\n// to modify this file, change it to managed by: local\n\n`),
|
|
172
|
+
sourceContent,
|
|
173
|
+
]);
|
|
174
|
+
let targetContent;
|
|
175
|
+
try {
|
|
176
|
+
targetContent = await promises_1.default.readFile(targetPath);
|
|
177
|
+
const management = getFileManagement(targetContent);
|
|
178
|
+
if (management === 'local') {
|
|
179
|
+
debug(`File ${file} is managed locally, skipping`);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (management === 'unmanaged') {
|
|
183
|
+
console.log(`Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`);
|
|
184
|
+
debug(`File ${file} doesn't have management comment, skipping`);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
debug(`File ${file} is managed by graphcommerce, will update if needed`);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
if (err.code !== 'ENOENT') {
|
|
191
|
+
console.error(`Error reading file ${file}: ${err.message}
|
|
192
|
+
Source: ${sourcePath}`);
|
|
193
|
+
process.exit(1);
|
|
194
|
+
}
|
|
195
|
+
console.log(`Creating new file: ${file}\nSource: ${sourcePath}`);
|
|
196
|
+
debug('File does not exist yet');
|
|
197
|
+
}
|
|
198
|
+
// Skip if content is identical (including magic comment)
|
|
199
|
+
if (targetContent && Buffer.compare(contentWithComment, targetContent) === 0) {
|
|
200
|
+
debug(`File ${file} content is identical to source, skipping`);
|
|
201
|
+
managedFiles.add(file);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
// Copy the file with magic comment
|
|
205
|
+
await promises_1.default.writeFile(targetPath, contentWithComment);
|
|
206
|
+
if (targetContent) {
|
|
207
|
+
console.log(`Updated managed file: ${file}`);
|
|
208
|
+
debug(`Overwrote existing file: ${file}`);
|
|
209
|
+
}
|
|
210
|
+
// If the file is managed by GraphCommerce (new or updated), add it to managedFiles
|
|
211
|
+
if (!targetContent || targetContent.toString().startsWith(MANAGED_BY_GC)) {
|
|
212
|
+
managedFiles.add(file);
|
|
213
|
+
debug('Added managed file:', file);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
catch (err) {
|
|
217
|
+
console.error(`Error copying file ${file}: ${err.message}
|
|
218
|
+
Source: ${sourcePath}`);
|
|
219
|
+
process.exit(1);
|
|
220
|
+
}
|
|
221
|
+
}));
|
|
222
|
+
debug(`Copied ${managedFiles.size} files in ${(performance.now() - copyStart).toFixed(0)}ms`);
|
|
223
|
+
// Remove files that are no longer provided
|
|
224
|
+
const removeStart = performance.now();
|
|
225
|
+
const filesToRemove = Array.from(existingManagedFiles).filter((file) => !managedFiles.has(file));
|
|
226
|
+
debug(`Files to remove: ${filesToRemove.length}`);
|
|
227
|
+
// Helper function to recursively clean up empty directories
|
|
228
|
+
async function cleanupEmptyDirs(startPath) {
|
|
229
|
+
let currentDir = startPath;
|
|
230
|
+
while (currentDir !== cwd) {
|
|
231
|
+
try {
|
|
232
|
+
const dirContents = await promises_1.default.readdir(currentDir);
|
|
233
|
+
if (dirContents.length === 0) {
|
|
234
|
+
await promises_1.default.rmdir(currentDir);
|
|
235
|
+
debug(`Removed empty directory: ${currentDir}`);
|
|
236
|
+
currentDir = path_1.default.dirname(currentDir);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
break; // Stop if directory is not empty
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
catch (err) {
|
|
243
|
+
if (err.code === 'EACCES') {
|
|
244
|
+
console.error(`Error cleaning up directory ${currentDir}: ${err.message}`);
|
|
245
|
+
process.exit(1);
|
|
246
|
+
}
|
|
247
|
+
break; // Stop on other errors (like ENOENT)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Process file removals in parallel
|
|
252
|
+
await Promise.all(filesToRemove.map(async (file) => {
|
|
253
|
+
const filePath = path_1.default.join(cwd, file);
|
|
254
|
+
const dirPath = path_1.default.dirname(filePath);
|
|
255
|
+
try {
|
|
256
|
+
// First check if the directory exists and is accessible
|
|
257
|
+
await promises_1.default.readdir(dirPath);
|
|
258
|
+
// Then try to remove the file
|
|
259
|
+
try {
|
|
260
|
+
await promises_1.default.unlink(filePath);
|
|
261
|
+
console.log(`Removed managed file: ${file}`);
|
|
262
|
+
debug(`Removed file: ${file}`);
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
if (err.code !== 'ENOENT') {
|
|
266
|
+
console.error(`Error removing file ${file}: ${err.message}`);
|
|
267
|
+
process.exit(1);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
// Finally, try to clean up empty directories
|
|
271
|
+
await cleanupEmptyDirs(dirPath);
|
|
272
|
+
}
|
|
273
|
+
catch (err) {
|
|
274
|
+
if (err.code === 'EACCES') {
|
|
275
|
+
console.error(`Error accessing directory ${dirPath}: ${err.message}`);
|
|
276
|
+
process.exit(1);
|
|
277
|
+
}
|
|
278
|
+
// Ignore ENOENT errors for directories that don't exist
|
|
279
|
+
}
|
|
280
|
+
}));
|
|
281
|
+
debug(`Removed files in ${(performance.now() - removeStart).toFixed(0)}ms`);
|
|
282
|
+
// Update .gitignore with current list of managed files
|
|
283
|
+
if (managedFiles.size > 0) {
|
|
284
|
+
debug('Found managed files:', Array.from(managedFiles));
|
|
285
|
+
await updateGitignore(Array.from(managedFiles));
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
debug('No managed files found, cleaning up .gitignore section');
|
|
289
|
+
await updateGitignore([]);
|
|
290
|
+
}
|
|
291
|
+
debug(`Total execution time: ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
292
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
7
|
+
// ... earlier code remains the same ...
|
|
8
|
+
try {
|
|
9
|
+
targetContent = await promises_1.default.readFile(targetPath);
|
|
10
|
+
}
|
|
11
|
+
catch (err) {
|
|
12
|
+
if (err.code !== 'ENOENT')
|
|
13
|
+
throw err;
|
|
14
|
+
// File doesn't exist, log that we're creating it
|
|
15
|
+
console.log(`Creating new file: ${file}`);
|
|
16
|
+
}
|
|
17
|
+
// Skip if content is identical
|
|
18
|
+
if (targetContent && Buffer.compare(sourceContent, targetContent) === 0)
|
|
19
|
+
return;
|
|
20
|
+
// ... rest of the code remains the same ...
|
|
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.exportConfig = exportConfig;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
8
|
const loadConfig_1 = require("../loadConfig");
|
|
8
9
|
const exportConfigToEnv_1 = require("../utils/exportConfigToEnv");
|
|
9
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
10
10
|
dotenv_1.default.config();
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
12
12
|
async function exportConfig() {
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateConfig = generateConfig;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
7
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
9
|
const cli_1 = require("@graphql-codegen/cli");
|
|
10
10
|
const core_1 = require("@swc/core");
|
|
11
11
|
const dotenv_1 = __importDefault(require("dotenv"));
|
|
@@ -42,7 +42,7 @@ async function generateConfig() {
|
|
|
42
42
|
},
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
-
...((0, isMonorepo_1.
|
|
45
|
+
...((0, isMonorepo_1.findParentPath)(process.cwd()) && {
|
|
46
46
|
'../../docs/framework/config.md': {
|
|
47
47
|
plugins: ['@graphcommerce/graphql-codegen-markdown-docs'],
|
|
48
48
|
},
|
|
@@ -4,8 +4,8 @@ exports.demoConfig = void 0;
|
|
|
4
4
|
exports.demoConfig = {
|
|
5
5
|
canonicalBaseUrl: 'https://graphcommerce.vercel.app',
|
|
6
6
|
hygraphEndpoint: 'https://eu-central-1.cdn.hygraph.com/content/ckhx7xadya6xs01yxdujt8i80/master',
|
|
7
|
-
magentoEndpoint: 'https://
|
|
8
|
-
magentoVersion:
|
|
7
|
+
magentoEndpoint: 'https://configurator.reachdigital.dev/graphql',
|
|
8
|
+
magentoVersion: 247,
|
|
9
9
|
storefront: [
|
|
10
10
|
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
|
|
11
11
|
{
|
|
@@ -3,7 +3,7 @@ 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.toEnvStr = void 0;
|
|
7
7
|
exports.configToEnvSchema = configToEnvSchema;
|
|
8
8
|
exports.mergeEnvIntoConfig = mergeEnvIntoConfig;
|
|
9
9
|
exports.formatAppliedEnv = formatAppliedEnv;
|
|
@@ -23,7 +23,6 @@ const dotNotation = (pathParts) => pathParts
|
|
|
23
23
|
return !Number.isNaN(idx) ? `[${idx}]` : v;
|
|
24
24
|
})
|
|
25
25
|
.join('.');
|
|
26
|
-
exports.dotNotation = dotNotation;
|
|
27
26
|
function isJSON(str) {
|
|
28
27
|
if (!str)
|
|
29
28
|
return true;
|
|
@@ -53,9 +52,9 @@ function configToEnvSchema(schema) {
|
|
|
53
52
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z
|
|
54
53
|
.string()
|
|
55
54
|
.optional()
|
|
56
|
-
.refine(isJSON, { message:
|
|
55
|
+
.refine(isJSON, { message: 'Invalid JSON' })
|
|
57
56
|
.transform((val) => (val ? JSON.parse(val) : val));
|
|
58
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
57
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
59
58
|
}
|
|
60
59
|
const typeNode = node;
|
|
61
60
|
Object.keys(typeNode.shape).forEach((key) => {
|
|
@@ -69,9 +68,9 @@ function configToEnvSchema(schema) {
|
|
|
69
68
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z
|
|
70
69
|
.string()
|
|
71
70
|
.optional()
|
|
72
|
-
.refine(isJSON, { message:
|
|
71
|
+
.refine(isJSON, { message: 'Invalid JSON' })
|
|
73
72
|
.transform((val) => (val ? JSON.parse(val) : val));
|
|
74
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
73
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
75
74
|
}
|
|
76
75
|
arr.forEach((key) => {
|
|
77
76
|
walk(node.element, [...path, String(key)]);
|
|
@@ -80,12 +79,12 @@ function configToEnvSchema(schema) {
|
|
|
80
79
|
}
|
|
81
80
|
if (node instanceof zod_1.ZodNumber) {
|
|
82
81
|
envSchema[(0, exports.toEnvStr)(path)] = zod_1.z.coerce.number().optional();
|
|
83
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
82
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
84
83
|
return;
|
|
85
84
|
}
|
|
86
85
|
if (node instanceof zod_1.ZodString || node instanceof zod_1.ZodEnum) {
|
|
87
86
|
envSchema[(0, exports.toEnvStr)(path)] = node.optional();
|
|
88
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
87
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
89
88
|
return;
|
|
90
89
|
}
|
|
91
90
|
if (node instanceof zod_1.ZodBoolean) {
|
|
@@ -99,7 +98,7 @@ function configToEnvSchema(schema) {
|
|
|
99
98
|
return false;
|
|
100
99
|
return v;
|
|
101
100
|
});
|
|
102
|
-
envToDot[(0, exports.toEnvStr)(path)] =
|
|
101
|
+
envToDot[(0, exports.toEnvStr)(path)] = dotNotation(path);
|
|
103
102
|
return;
|
|
104
103
|
}
|
|
105
104
|
throw Error(`[@graphcommerce/next-config] Unknown type in schema ${node.constructor.name}. This is probably a bug please create an issue.`);
|
|
@@ -108,9 +107,8 @@ function configToEnvSchema(schema) {
|
|
|
108
107
|
return [zod_1.z.object(envSchema), envToDot];
|
|
109
108
|
}
|
|
110
109
|
const filterEnv = (env) => Object.fromEntries(Object.entries(env).filter(([key]) => key.startsWith('GC_')));
|
|
111
|
-
exports.filterEnv = filterEnv;
|
|
112
110
|
function mergeEnvIntoConfig(schema, config, env) {
|
|
113
|
-
const filteredEnv =
|
|
111
|
+
const filteredEnv = filterEnv(env);
|
|
114
112
|
const newConfig = (0, utilities_1.cloneDeep)(config);
|
|
115
113
|
const [envSchema, envToDot] = configToEnvSchema(schema);
|
|
116
114
|
const result = envSchema.safeParse(filteredEnv);
|
|
@@ -155,7 +153,7 @@ function formatAppliedEnv(applyResult) {
|
|
|
155
153
|
const lines = applyResult.map(({ from, to, envValue, envVar, dotVar, error, warning }) => {
|
|
156
154
|
const fromFmt = chalk_1.default.red(JSON.stringify(from));
|
|
157
155
|
const toFmt = chalk_1.default.green(JSON.stringify(to));
|
|
158
|
-
const envVariableFmt = `${envVar}
|
|
156
|
+
const envVariableFmt = `${envVar}`;
|
|
159
157
|
const dotVariableFmt = chalk_1.default.bold.underline(`${dotVar}`);
|
|
160
158
|
const baseLog = `${envVariableFmt} => ${dotVariableFmt}`;
|
|
161
159
|
if (error) {
|
|
@@ -169,18 +167,18 @@ function formatAppliedEnv(applyResult) {
|
|
|
169
167
|
if (!dotVar)
|
|
170
168
|
return chalk_1.default.red(`${envVariableFmt} => ignored (no matching config)`);
|
|
171
169
|
if (from === undefined && to === undefined)
|
|
172
|
-
return ` = ${baseLog}: (ignored
|
|
170
|
+
return ` = ${baseLog}: (ignored)`;
|
|
173
171
|
if (from === undefined && to !== undefined)
|
|
174
|
-
return ` ${chalk_1.default.green('+')} ${baseLog}
|
|
172
|
+
return ` ${chalk_1.default.green('+')} ${baseLog}`;
|
|
175
173
|
if (from !== undefined && to === undefined)
|
|
176
|
-
return ` ${chalk_1.default.red('-')} ${baseLog}
|
|
177
|
-
return ` ${chalk_1.default.yellowBright('~')} ${baseLog}
|
|
174
|
+
return ` ${chalk_1.default.red('-')} ${baseLog}`;
|
|
175
|
+
return ` ${chalk_1.default.yellowBright('~')} ${baseLog}`;
|
|
178
176
|
});
|
|
179
|
-
let header = chalk_1.default.blueBright(
|
|
177
|
+
let header = chalk_1.default.blueBright('info');
|
|
180
178
|
if (hasWarning)
|
|
181
|
-
header = chalk_1.default.yellowBright(
|
|
179
|
+
header = chalk_1.default.yellowBright('warning');
|
|
182
180
|
if (hasError)
|
|
183
|
-
header = chalk_1.default.yellowBright(
|
|
184
|
-
header +=
|
|
181
|
+
header = chalk_1.default.yellowBright('error');
|
|
182
|
+
header += ' - Loaded GraphCommerce env variables';
|
|
185
183
|
return [header, ...lines].join('\n');
|
|
186
184
|
}
|
|
@@ -22,7 +22,7 @@ function rewriteLegacyEnv(schema, env, config = {}) {
|
|
|
22
22
|
function notUsed() {
|
|
23
23
|
return (envVar, envValue) => {
|
|
24
24
|
applied.push({
|
|
25
|
-
warning: [
|
|
25
|
+
warning: ['should be removed'],
|
|
26
26
|
envVar,
|
|
27
27
|
envValue,
|
|
28
28
|
});
|
|
@@ -35,7 +35,7 @@ function rewriteLegacyEnv(schema, env, config = {}) {
|
|
|
35
35
|
IMAGE_DOMAINS: (envVar, envValue) => {
|
|
36
36
|
applied.push({
|
|
37
37
|
warning: [
|
|
38
|
-
|
|
38
|
+
'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',
|
|
39
39
|
],
|
|
40
40
|
envVar,
|
|
41
41
|
envValue,
|
package/dist/generated/config.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WebsitePermissionsSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.PaginationVariantSchema = exports.CustomerAccountPermissionsSchema = exports.CompareVariantSchema = exports.CartPermissionsSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0;
|
|
3
|
+
exports.WebsitePermissionsSchema = exports.SidebarGalleryPaginationVariantSchema = exports.ProductFiltersLayoutSchema = exports.PaginationVariantSchema = exports.CustomerAccountPermissionsSchema = exports.ContainerSizingSchema = exports.CompareVariantSchema = exports.CartPermissionsSchema = exports.definedNonNullAnySchema = exports.isDefinedNonNullAny = void 0;
|
|
4
4
|
exports.DatalayerConfigSchema = DatalayerConfigSchema;
|
|
5
5
|
exports.GraphCommerceConfigSchema = GraphCommerceConfigSchema;
|
|
6
6
|
exports.GraphCommerceDebugConfigSchema = GraphCommerceDebugConfigSchema;
|
|
7
|
+
exports.GraphCommerceGooglePlaystoreConfigSchema = GraphCommerceGooglePlaystoreConfigSchema;
|
|
7
8
|
exports.GraphCommercePermissionsSchema = GraphCommercePermissionsSchema;
|
|
8
9
|
exports.GraphCommerceStorefrontConfigSchema = GraphCommerceStorefrontConfigSchema;
|
|
9
10
|
exports.MagentoConfigurableVariantValuesSchema = MagentoConfigurableVariantValuesSchema;
|
|
@@ -16,6 +17,7 @@ exports.isDefinedNonNullAny = isDefinedNonNullAny;
|
|
|
16
17
|
exports.definedNonNullAnySchema = zod_1.z.any().refine((v) => (0, exports.isDefinedNonNullAny)(v));
|
|
17
18
|
exports.CartPermissionsSchema = zod_1.z.enum(['CUSTOMER_ONLY', 'DISABLED', 'ENABLED']);
|
|
18
19
|
exports.CompareVariantSchema = zod_1.z.enum(['CHECKBOX', 'ICON']);
|
|
20
|
+
exports.ContainerSizingSchema = zod_1.z.enum(['BREAKPOINT', 'FULL_WIDTH']);
|
|
19
21
|
exports.CustomerAccountPermissionsSchema = zod_1.z.enum(['DISABLED', 'DISABLE_REGISTRATION', 'ENABLED']);
|
|
20
22
|
exports.PaginationVariantSchema = zod_1.z.enum(['COMPACT', 'EXTENDED']);
|
|
21
23
|
exports.ProductFiltersLayoutSchema = zod_1.z.enum(['DEFAULT', 'SIDEBAR']);
|
|
@@ -35,6 +37,8 @@ function GraphCommerceConfigSchema() {
|
|
|
35
37
|
compareVariant: exports.CompareVariantSchema.default("ICON").nullish(),
|
|
36
38
|
configurableVariantForSimple: zod_1.z.boolean().default(false).nullish(),
|
|
37
39
|
configurableVariantValues: MagentoConfigurableVariantValuesSchema().nullish(),
|
|
40
|
+
containerSizingContent: exports.ContainerSizingSchema.default("FULL_WIDTH").nullish(),
|
|
41
|
+
containerSizingShell: exports.ContainerSizingSchema.default("FULL_WIDTH").nullish(),
|
|
38
42
|
crossSellsHideCartItems: zod_1.z.boolean().default(false).nullish(),
|
|
39
43
|
crossSellsRedirectItems: zod_1.z.boolean().default(false).nullish(),
|
|
40
44
|
customerAddressNoteEnable: zod_1.z.boolean().nullish(),
|
|
@@ -46,6 +50,7 @@ function GraphCommerceConfigSchema() {
|
|
|
46
50
|
demoMode: zod_1.z.boolean().default(true).nullish(),
|
|
47
51
|
enableGuestCheckoutLogin: zod_1.z.boolean().nullish(),
|
|
48
52
|
googleAnalyticsId: zod_1.z.string().nullish(),
|
|
53
|
+
googlePlaystore: GraphCommerceGooglePlaystoreConfigSchema().nullish(),
|
|
49
54
|
googleRecaptchaKey: zod_1.z.string().nullish(),
|
|
50
55
|
googleTagmanagerId: zod_1.z.string().nullish(),
|
|
51
56
|
hygraphEndpoint: zod_1.z.string().min(1),
|
|
@@ -71,12 +76,19 @@ function GraphCommerceConfigSchema() {
|
|
|
71
76
|
}
|
|
72
77
|
function GraphCommerceDebugConfigSchema() {
|
|
73
78
|
return zod_1.z.object({
|
|
79
|
+
cart: zod_1.z.boolean().nullish(),
|
|
74
80
|
pluginStatus: zod_1.z.boolean().nullish(),
|
|
75
81
|
sessions: zod_1.z.boolean().nullish(),
|
|
76
82
|
webpackCircularDependencyPlugin: zod_1.z.boolean().nullish(),
|
|
77
83
|
webpackDuplicatesPlugin: zod_1.z.boolean().nullish()
|
|
78
84
|
});
|
|
79
85
|
}
|
|
86
|
+
function GraphCommerceGooglePlaystoreConfigSchema() {
|
|
87
|
+
return zod_1.z.object({
|
|
88
|
+
packageName: zod_1.z.string().min(1),
|
|
89
|
+
sha256CertificateFingerprint: zod_1.z.string().min(1)
|
|
90
|
+
});
|
|
91
|
+
}
|
|
80
92
|
function GraphCommercePermissionsSchema() {
|
|
81
93
|
return zod_1.z.object({
|
|
82
94
|
cart: exports.CartPermissionsSchema.nullish(),
|
package/dist/index.js
CHANGED
|
@@ -17,8 +17,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./utils/isMonorepo"), exports);
|
|
18
18
|
__exportStar(require("./utils/resolveDependenciesSync"), exports);
|
|
19
19
|
__exportStar(require("./utils/packageRoots"), exports);
|
|
20
|
+
__exportStar(require("./utils/sig"), exports);
|
|
20
21
|
__exportStar(require("./withGraphCommerce"), exports);
|
|
21
22
|
__exportStar(require("./generated/config"), exports);
|
|
22
23
|
__exportStar(require("./config"), exports);
|
|
23
|
-
__exportStar(require("./runtimeCachingOptimizations"), exports);
|
|
24
24
|
__exportStar(require("./interceptors/commands/codegenInterceptors"), exports);
|
|
25
|
+
__exportStar(require("./commands/copyFiles"), exports);
|
|
26
|
+
__exportStar(require("./commands/codegen"), exports);
|
|
@@ -29,9 +29,9 @@ class InterceptorPlugin {
|
|
|
29
29
|
if (generating)
|
|
30
30
|
return {};
|
|
31
31
|
generating = true;
|
|
32
|
-
const start = Date.now()
|
|
32
|
+
// const start = Date.now()
|
|
33
33
|
// console.log('Generating interceptors...')
|
|
34
|
-
const [plugins
|
|
34
|
+
const [plugins] = (0, findPlugins_1.findPlugins)(this.config);
|
|
35
35
|
// console.log(errors)
|
|
36
36
|
// const found = Date.now()
|
|
37
37
|
// console.log('Found plugins in', found - start, 'ms')
|
|
@@ -47,6 +47,7 @@ class InterceptorPlugin {
|
|
|
47
47
|
generating = false;
|
|
48
48
|
return generatedInterceptors;
|
|
49
49
|
};
|
|
50
|
+
/** @public */
|
|
50
51
|
apply(compiler) {
|
|
51
52
|
const logger = compiler.getInfrastructureLogger('InterceptorPlugin');
|
|
52
53
|
// After the compilation has succeeded we watch all possible plugin locations.
|
|
@@ -64,7 +65,7 @@ class InterceptorPlugin {
|
|
|
64
65
|
});
|
|
65
66
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
66
67
|
this.#generateInterceptors().then((i) => {
|
|
67
|
-
Object.entries(i).forEach(([
|
|
68
|
+
Object.entries(i).forEach(([, { sourcePath }]) => {
|
|
68
69
|
const absoluteFilePath = path_1.default.join(process.cwd(), sourcePath);
|
|
69
70
|
compilation.fileDependencies.add(absoluteFilePath);
|
|
70
71
|
});
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* This is an implementation of
|
|
4
|
-
* https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts
|
|
5
|
-
*
|
|
6
|
-
* The JS API is deprecated, but there doesn't seem to be a valid alternative at this point.
|
|
7
|
-
*/
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.Visitor = void 0;
|
|
4
|
+
/* eslint-disable no-param-reassign */
|
|
5
|
+
/* eslint-disable class-methods-use-this */
|
|
6
|
+
/* eslint-disable consistent-return */
|
|
10
7
|
/**
|
|
11
8
|
* @deprecated JavaScript API is deprecated. Please use Wasm plugin instead.
|
|
9
|
+
* @public
|
|
12
10
|
*/
|
|
13
11
|
class Visitor {
|
|
14
12
|
visitProgram(n) {
|
|
@@ -517,7 +515,6 @@ class Visitor {
|
|
|
517
515
|
return n;
|
|
518
516
|
}
|
|
519
517
|
visitTsPropertySignature(n) {
|
|
520
|
-
n.params = this.visitTsFnParameters(n.params);
|
|
521
518
|
n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
|
|
522
519
|
return n;
|
|
523
520
|
}
|
|
@@ -595,7 +592,7 @@ class Visitor {
|
|
|
595
592
|
return n;
|
|
596
593
|
}
|
|
597
594
|
visitTsFnParameters(params) {
|
|
598
|
-
return params
|
|
595
|
+
return params.map(this.visitTsFnParameter.bind(this));
|
|
599
596
|
}
|
|
600
597
|
visitTsFnParameter(n) {
|
|
601
598
|
n.typeAnnotation = this.visitTsTypeAnnotation(n.typeAnnotation);
|
|
@@ -1415,4 +1412,3 @@ class Visitor {
|
|
|
1415
1412
|
}
|
|
1416
1413
|
}
|
|
1417
1414
|
exports.Visitor = Visitor;
|
|
1418
|
-
exports.default = Visitor;
|
|
@@ -4,17 +4,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.codegenInterceptors = codegenInterceptors;
|
|
7
|
+
const dotenv_1 = __importDefault(require("dotenv"));
|
|
7
8
|
const loadConfig_1 = require("../../config/loadConfig");
|
|
8
9
|
const resolveDependency_1 = require("../../utils/resolveDependency");
|
|
9
10
|
const findPlugins_1 = require("../findPlugins");
|
|
10
11
|
const generateInterceptors_1 = require("../generateInterceptors");
|
|
11
12
|
const writeInterceptors_1 = require("../writeInterceptors");
|
|
12
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
13
13
|
dotenv_1.default.config();
|
|
14
14
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
15
15
|
async function codegenInterceptors() {
|
|
16
16
|
const conf = (0, loadConfig_1.loadConfig)(process.cwd());
|
|
17
|
-
const [plugins
|
|
17
|
+
const [plugins] = (0, findPlugins_1.findPlugins)(conf);
|
|
18
18
|
const generatedInterceptors = await (0, generateInterceptors_1.generateInterceptors)(plugins, (0, resolveDependency_1.resolveDependency)(), conf.debug, true);
|
|
19
19
|
// const generated = Date.now()
|
|
20
20
|
// console.log('Generated interceptors in', generated - found, 'ms')
|