@graphcommerce/next-config 9.0.4-canary.9 → 9.1.0-canary.15
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 +24 -0
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +12 -1
- package/__tests__/config/utils/replaceConfigInString.ts +0 -1
- package/__tests__/interceptors/findPlugins.ts +301 -254
- package/__tests__/utils/resolveDependenciesSync.ts +44 -44
- package/dist/generated/config.js +109 -120
- package/dist/index.js +3359 -26
- package/package.json +33 -8
- package/src/config/commands/generateConfig.ts +16 -4
- package/src/config/demoConfig.ts +0 -1
- package/src/config/loadConfig.ts +3 -9
- package/src/config/utils/mergeEnvIntoConfig.ts +8 -6
- package/src/generated/config.ts +11 -5
- package/src/interceptors/generateInterceptor.ts +0 -2
- package/src/interceptors/parseStructure.ts +3 -3
- package/src/utils/resolveDependenciesSync.ts +43 -6
- package/src/withGraphCommerce.ts +30 -42
- package/tsconfig.json +1 -1
- package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -79
- package/dist/commands/codegen.js +0 -18
- package/dist/commands/copyFiles.js +0 -297
- package/dist/config/commands/exportConfig.js +0 -16
- package/dist/config/commands/generateConfig.js +0 -56
- package/dist/config/demoConfig.js +0 -52
- package/dist/config/index.js +0 -19
- package/dist/config/loadConfig.js +0 -62
- package/dist/config/utils/configToImportMeta.js +0 -39
- package/dist/config/utils/diff.js +0 -33
- package/dist/config/utils/exportConfigToEnv.js +0 -31
- package/dist/config/utils/mergeEnvIntoConfig.js +0 -182
- package/dist/config/utils/replaceConfigInString.js +0 -12
- package/dist/config/utils/rewriteLegacyEnv.js +0 -115
- package/dist/interceptors/InterceptorPlugin.js +0 -108
- package/dist/interceptors/RenameVisitor.js +0 -19
- package/dist/interceptors/Visitor.js +0 -1414
- package/dist/interceptors/commands/codegenInterceptors.js +0 -22
- package/dist/interceptors/extractExports.js +0 -159
- package/dist/interceptors/findOriginalSource.js +0 -103
- package/dist/interceptors/findPlugins.js +0 -68
- package/dist/interceptors/generateInterceptor.js +0 -219
- package/dist/interceptors/generateInterceptors.js +0 -56
- package/dist/interceptors/parseStructure.js +0 -84
- package/dist/interceptors/swc.js +0 -15
- package/dist/interceptors/writeInterceptors.js +0 -44
- package/dist/utils/PackagesSort.js +0 -7
- package/dist/utils/TopologicalSort.js +0 -87
- package/dist/utils/isMonorepo.js +0 -47
- package/dist/utils/packageRoots.js +0 -31
- package/dist/utils/resolveDependenciesSync.js +0 -78
- package/dist/utils/resolveDependency.js +0 -70
- package/dist/utils/sig.js +0 -34
- package/dist/withGraphCommerce.js +0 -162
- package/src/config/utils/rewriteLegacyEnv.ts +0 -125
|
@@ -1,297 +0,0 @@
|
|
|
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.info('[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 escapedFiles = managedFiles
|
|
32
|
-
.map((file) =>
|
|
33
|
-
// Escape special characters in file names
|
|
34
|
-
file.replace(/[*+?^${}()|[\]\\]/g, '\\$&'))
|
|
35
|
-
.sort();
|
|
36
|
-
const gitignorePath = path_1.default.join(process.cwd(), '.gitignore');
|
|
37
|
-
let content;
|
|
38
|
-
try {
|
|
39
|
-
content = await promises_1.default.readFile(gitignorePath, 'utf-8');
|
|
40
|
-
debug('Reading existing .gitignore');
|
|
41
|
-
}
|
|
42
|
-
catch (err) {
|
|
43
|
-
debug('.gitignore not found, creating new file');
|
|
44
|
-
content = '';
|
|
45
|
-
}
|
|
46
|
-
// Remove existing GraphCommerce section if it exists
|
|
47
|
-
const sectionRegex = new RegExp(`${GITIGNORE_SECTION_START}[\\s\\S]*?${GITIGNORE_SECTION_END}\\n?`, 'g');
|
|
48
|
-
content = content.replace(sectionRegex, '');
|
|
49
|
-
// Only add new section if there are files to manage
|
|
50
|
-
if (escapedFiles.length > 0) {
|
|
51
|
-
const newSection = [
|
|
52
|
-
GITIGNORE_SECTION_START,
|
|
53
|
-
...escapedFiles,
|
|
54
|
-
GITIGNORE_SECTION_END,
|
|
55
|
-
'', // Empty line at the end
|
|
56
|
-
].join('\n');
|
|
57
|
-
// Append the new section
|
|
58
|
-
content = `${content.trim()}\n\n${newSection}`;
|
|
59
|
-
debug(`Updated .gitignore with ${managedFiles.length} managed files`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
content = `${content.trim()}\n`;
|
|
63
|
-
debug('Cleaned up .gitignore managed section');
|
|
64
|
-
}
|
|
65
|
-
await promises_1.default.writeFile(gitignorePath, content);
|
|
66
|
-
}
|
|
67
|
-
/** Determines how a file should be managed based on its content */
|
|
68
|
-
function getFileManagement(content) {
|
|
69
|
-
if (!content)
|
|
70
|
-
return 'graphcommerce';
|
|
71
|
-
const contentStr = content.toString();
|
|
72
|
-
if (contentStr.startsWith(MANAGED_LOCALLY))
|
|
73
|
-
return 'local';
|
|
74
|
-
if (contentStr.startsWith(MANAGED_BY_GC))
|
|
75
|
-
return 'graphcommerce';
|
|
76
|
-
return 'unmanaged';
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* The packages are @graphcommerce/* packages and have special treatment.
|
|
80
|
-
*
|
|
81
|
-
* 1. Glob the `copy/**` directory for each package and generate a list of files that need to be
|
|
82
|
-
* copied. Error if a file with the same path exists in another package.
|
|
83
|
-
* 2. Copy the files to the project directory (cwd).
|
|
84
|
-
*
|
|
85
|
-
* 1. If the file doesn't exist: Create directories and the file with "managed by: graphcommerce"
|
|
86
|
-
* 2. If the file exists and starts with "managed by: local": Skip the file
|
|
87
|
-
* 3. If the file exists but doesn't have a management comment: Suggest adding "managed by: local"
|
|
88
|
-
* 4. If the file is managed by graphcommerce: Update if content differs
|
|
89
|
-
*/
|
|
90
|
-
async function copyFiles() {
|
|
91
|
-
const startTime = performance.now();
|
|
92
|
-
debug('Starting copyFiles');
|
|
93
|
-
const cwd = process.cwd();
|
|
94
|
-
const deps = (0, resolveDependenciesSync_1.resolveDependenciesSync)();
|
|
95
|
-
const packages = [...deps.values()].filter((p) => p !== '.');
|
|
96
|
-
// Track files and their source packages to detect conflicts
|
|
97
|
-
const fileMap = new Map();
|
|
98
|
-
const managedFiles = new Set();
|
|
99
|
-
const existingManagedFiles = new Set();
|
|
100
|
-
// First scan existing files to find GraphCommerce managed ones
|
|
101
|
-
const scanStart = performance.now();
|
|
102
|
-
try {
|
|
103
|
-
// Use only default patterns for testing
|
|
104
|
-
const gitignorePatterns = [
|
|
105
|
-
'**/dist/**',
|
|
106
|
-
'**/build/**',
|
|
107
|
-
'**/.next/**',
|
|
108
|
-
'**/.git/**',
|
|
109
|
-
'**/node_modules/**',
|
|
110
|
-
];
|
|
111
|
-
const allFiles = await (0, fast_glob_1.default)('**/*', {
|
|
112
|
-
cwd,
|
|
113
|
-
dot: true,
|
|
114
|
-
ignore: gitignorePatterns,
|
|
115
|
-
onlyFiles: true,
|
|
116
|
-
});
|
|
117
|
-
debug(`Found ${allFiles.length} project files in ${(performance.now() - scanStart).toFixed(0)}ms`);
|
|
118
|
-
const readStart = performance.now();
|
|
119
|
-
await Promise.all(allFiles.map(async (file) => {
|
|
120
|
-
const filePath = path_1.default.join(cwd, file);
|
|
121
|
-
try {
|
|
122
|
-
const content = await promises_1.default.readFile(filePath);
|
|
123
|
-
if (getFileManagement(content) === 'graphcommerce') {
|
|
124
|
-
existingManagedFiles.add(file);
|
|
125
|
-
debug(`Found existing managed file: ${file}`);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
catch (err) {
|
|
129
|
-
debug(`Error reading file ${file}:`, err);
|
|
130
|
-
}
|
|
131
|
-
}));
|
|
132
|
-
debug(`Read ${existingManagedFiles.size} managed files in ${(performance.now() - readStart).toFixed(0)}ms`);
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
debug('Error scanning project files:', err);
|
|
136
|
-
}
|
|
137
|
-
// First pass: collect all files and check for conflicts
|
|
138
|
-
const collectStart = performance.now();
|
|
139
|
-
await Promise.all(packages.map(async (pkg) => {
|
|
140
|
-
const copyDir = path_1.default.join(pkg, 'copy');
|
|
141
|
-
try {
|
|
142
|
-
const files = await (0, fast_glob_1.default)('**/*', { cwd: copyDir, dot: true, suppressErrors: true });
|
|
143
|
-
if (files.length > 0) {
|
|
144
|
-
debug(`Found files in ${pkg}:`, files);
|
|
145
|
-
for (const file of files) {
|
|
146
|
-
const sourcePath = path_1.default.join(copyDir, file);
|
|
147
|
-
const existing = fileMap.get(file);
|
|
148
|
-
if (existing) {
|
|
149
|
-
console.error(`Error: File conflict detected for '${file}'
|
|
150
|
-
Found in packages:
|
|
151
|
-
- ${existing.packagePath} -> ${existing.sourcePath}
|
|
152
|
-
- ${pkg} -> ${sourcePath}`);
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
fileMap.set(file, { sourcePath, packagePath: pkg });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
catch (err) {
|
|
160
|
-
if (err.code === 'ENOENT')
|
|
161
|
-
return;
|
|
162
|
-
console.error(`Error scanning directory ${copyDir}: ${err.message}\nPath: ${copyDir}`);
|
|
163
|
-
process.exit(1);
|
|
164
|
-
}
|
|
165
|
-
}));
|
|
166
|
-
debug(`Collected ${fileMap.size} files in ${(performance.now() - collectStart).toFixed(0)}ms`);
|
|
167
|
-
// Second pass: copy files and handle removals
|
|
168
|
-
const copyStart = performance.now();
|
|
169
|
-
await Promise.all(Array.from(fileMap.entries()).map(async ([file, { sourcePath }]) => {
|
|
170
|
-
const targetPath = path_1.default.join(cwd, file);
|
|
171
|
-
debug(`Processing file: ${file}`);
|
|
172
|
-
try {
|
|
173
|
-
await promises_1.default.mkdir(path_1.default.dirname(targetPath), { recursive: true });
|
|
174
|
-
const sourceContent = await promises_1.default.readFile(sourcePath);
|
|
175
|
-
const contentWithComment = Buffer.concat([
|
|
176
|
-
Buffer.from(`${MANAGED_BY_GC}\n// to modify this file, change it to managed by: local\n\n`),
|
|
177
|
-
sourceContent,
|
|
178
|
-
]);
|
|
179
|
-
let targetContent;
|
|
180
|
-
try {
|
|
181
|
-
targetContent = await promises_1.default.readFile(targetPath);
|
|
182
|
-
const management = getFileManagement(targetContent);
|
|
183
|
-
if (management === 'local') {
|
|
184
|
-
debug(`File ${file} is managed locally, skipping`);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (management === 'unmanaged') {
|
|
188
|
-
console.info(`Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`);
|
|
189
|
-
debug(`File ${file} doesn't have management comment, skipping`);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
debug(`File ${file} is managed by graphcommerce, will update if needed`);
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
if (err.code !== 'ENOENT') {
|
|
196
|
-
console.error(`Error reading file ${file}: ${err.message}
|
|
197
|
-
Source: ${sourcePath}`);
|
|
198
|
-
process.exit(1);
|
|
199
|
-
}
|
|
200
|
-
console.info(`Creating new file: ${file}\nSource: ${sourcePath}`);
|
|
201
|
-
debug('File does not exist yet');
|
|
202
|
-
}
|
|
203
|
-
// Skip if content is identical (including magic comment)
|
|
204
|
-
if (targetContent && Buffer.compare(contentWithComment, targetContent) === 0) {
|
|
205
|
-
debug(`File ${file} content is identical to source, skipping`);
|
|
206
|
-
managedFiles.add(file);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
// Copy the file with magic comment
|
|
210
|
-
await promises_1.default.writeFile(targetPath, contentWithComment);
|
|
211
|
-
if (targetContent) {
|
|
212
|
-
console.info(`Updated managed file: ${file}`);
|
|
213
|
-
debug(`Overwrote existing file: ${file}`);
|
|
214
|
-
}
|
|
215
|
-
// If the file is managed by GraphCommerce (new or updated), add it to managedFiles
|
|
216
|
-
if (!targetContent || targetContent.toString().startsWith(MANAGED_BY_GC)) {
|
|
217
|
-
managedFiles.add(file);
|
|
218
|
-
debug('Added managed file:', file);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (err) {
|
|
222
|
-
console.error(`Error copying file ${file}: ${err.message}
|
|
223
|
-
Source: ${sourcePath}`);
|
|
224
|
-
process.exit(1);
|
|
225
|
-
}
|
|
226
|
-
}));
|
|
227
|
-
debug(`Copied ${managedFiles.size} files in ${(performance.now() - copyStart).toFixed(0)}ms`);
|
|
228
|
-
// Remove files that are no longer provided
|
|
229
|
-
const removeStart = performance.now();
|
|
230
|
-
const filesToRemove = Array.from(existingManagedFiles).filter((file) => !managedFiles.has(file));
|
|
231
|
-
debug(`Files to remove: ${filesToRemove.length}`);
|
|
232
|
-
// Helper function to recursively clean up empty directories
|
|
233
|
-
async function cleanupEmptyDirs(startPath) {
|
|
234
|
-
let currentDir = startPath;
|
|
235
|
-
while (currentDir !== cwd) {
|
|
236
|
-
try {
|
|
237
|
-
const dirContents = await promises_1.default.readdir(currentDir);
|
|
238
|
-
if (dirContents.length === 0) {
|
|
239
|
-
await promises_1.default.rmdir(currentDir);
|
|
240
|
-
debug(`Removed empty directory: ${currentDir}`);
|
|
241
|
-
currentDir = path_1.default.dirname(currentDir);
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
break; // Stop if directory is not empty
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
catch (err) {
|
|
248
|
-
if (err.code === 'EACCES') {
|
|
249
|
-
console.error(`Error cleaning up directory ${currentDir}: ${err.message}`);
|
|
250
|
-
process.exit(1);
|
|
251
|
-
}
|
|
252
|
-
break; // Stop on other errors (like ENOENT)
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
// Process file removals in parallel
|
|
257
|
-
await Promise.all(filesToRemove.map(async (file) => {
|
|
258
|
-
const filePath = path_1.default.join(cwd, file);
|
|
259
|
-
const dirPath = path_1.default.dirname(filePath);
|
|
260
|
-
try {
|
|
261
|
-
// First check if the directory exists and is accessible
|
|
262
|
-
await promises_1.default.readdir(dirPath);
|
|
263
|
-
// Then try to remove the file
|
|
264
|
-
try {
|
|
265
|
-
await promises_1.default.unlink(filePath);
|
|
266
|
-
console.info(`Removed managed file: ${file}`);
|
|
267
|
-
debug(`Removed file: ${file}`);
|
|
268
|
-
}
|
|
269
|
-
catch (err) {
|
|
270
|
-
if (err.code !== 'ENOENT') {
|
|
271
|
-
console.error(`Error removing file ${file}: ${err.message}`);
|
|
272
|
-
process.exit(1);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
// Finally, try to clean up empty directories
|
|
276
|
-
await cleanupEmptyDirs(dirPath);
|
|
277
|
-
}
|
|
278
|
-
catch (err) {
|
|
279
|
-
if (err.code === 'EACCES') {
|
|
280
|
-
console.error(`Error accessing directory ${dirPath}: ${err.message}`);
|
|
281
|
-
process.exit(1);
|
|
282
|
-
}
|
|
283
|
-
// Ignore ENOENT errors for directories that don't exist
|
|
284
|
-
}
|
|
285
|
-
}));
|
|
286
|
-
debug(`Removed files in ${(performance.now() - removeStart).toFixed(0)}ms`);
|
|
287
|
-
// Update .gitignore with current list of managed files
|
|
288
|
-
if (managedFiles.size > 0) {
|
|
289
|
-
debug('Found managed files:', Array.from(managedFiles));
|
|
290
|
-
await updateGitignore(Array.from(managedFiles));
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
debug('No managed files found, cleaning up .gitignore section');
|
|
294
|
-
await updateGitignore([]);
|
|
295
|
-
}
|
|
296
|
-
debug(`Total execution time: ${(performance.now() - startTime).toFixed(0)}ms`);
|
|
297
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
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.exportConfig = exportConfig;
|
|
7
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
8
|
-
const loadConfig_1 = require("../loadConfig");
|
|
9
|
-
const exportConfigToEnv_1 = require("../utils/exportConfigToEnv");
|
|
10
|
-
dotenv_1.default.config();
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
12
|
-
async function exportConfig() {
|
|
13
|
-
const conf = (0, loadConfig_1.loadConfig)(process.cwd());
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.log((0, exportConfigToEnv_1.exportConfigToEnv)(conf));
|
|
16
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
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.generateConfig = generateConfig;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const cli_1 = require("@graphql-codegen/cli");
|
|
9
|
-
const core_1 = require("@swc/core");
|
|
10
|
-
const dotenv_1 = __importDefault(require("dotenv"));
|
|
11
|
-
const isMonorepo_1 = require("../../utils/isMonorepo");
|
|
12
|
-
const resolveDependenciesSync_1 = require("../../utils/resolveDependenciesSync");
|
|
13
|
-
const resolveDependency_1 = require("../../utils/resolveDependency");
|
|
14
|
-
dotenv_1.default.config();
|
|
15
|
-
const packages = [...(0, resolveDependenciesSync_1.resolveDependenciesSync)().values()].filter((p) => p !== '.');
|
|
16
|
-
const resolve = (0, resolveDependency_1.resolveDependency)();
|
|
17
|
-
const schemaLocations = packages.map((p) => `${p}/**/Config.graphqls`);
|
|
18
|
-
async function generateConfig() {
|
|
19
|
-
const resolved = resolve('@graphcommerce/next-config');
|
|
20
|
-
if (!resolved)
|
|
21
|
-
throw Error('Could not resolve @graphcommerce/next-config');
|
|
22
|
-
const targetTs = `${resolved.root}/src/generated/config.ts`;
|
|
23
|
-
const targetJs = `${resolved.root}/dist/generated/config.js`;
|
|
24
|
-
await (0, cli_1.generate)({
|
|
25
|
-
silent: true,
|
|
26
|
-
schema: ['graphql/**/Config.graphqls', ...schemaLocations],
|
|
27
|
-
generates: {
|
|
28
|
-
[targetTs]: {
|
|
29
|
-
plugins: ['typescript', 'typescript-validation-schema', 'add'],
|
|
30
|
-
config: {
|
|
31
|
-
// enumsAsTypes: true,
|
|
32
|
-
content: '/* eslint-disable */',
|
|
33
|
-
schema: 'zod',
|
|
34
|
-
notAllowEmptyString: true,
|
|
35
|
-
strictScalars: true,
|
|
36
|
-
enumsAsTypes: true,
|
|
37
|
-
scalarSchemas: {
|
|
38
|
-
Domain: 'z.string()',
|
|
39
|
-
DateTime: 'z.date()',
|
|
40
|
-
RichTextAST: 'z.object.json()',
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
...((0, isMonorepo_1.findParentPath)(process.cwd()) && {
|
|
45
|
-
'../../docs/framework/config.md': {
|
|
46
|
-
plugins: ['@graphcommerce/graphql-codegen-markdown-docs'],
|
|
47
|
-
},
|
|
48
|
-
}),
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
const result = (0, core_1.transformFileSync)(targetTs, {
|
|
52
|
-
module: { type: 'commonjs' },
|
|
53
|
-
env: { targets: { node: '18' } },
|
|
54
|
-
});
|
|
55
|
-
(0, fs_1.writeFileSync)(targetJs, result.code);
|
|
56
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.demoConfig = void 0;
|
|
4
|
-
exports.demoConfig = {
|
|
5
|
-
canonicalBaseUrl: 'https://graphcommerce.vercel.app',
|
|
6
|
-
hygraphEndpoint: 'https://eu-central-1.cdn.hygraph.com/content/ckhx7xadya6xs01yxdujt8i80/master',
|
|
7
|
-
magentoEndpoint: 'https://configurator.reachdigital.dev/graphql',
|
|
8
|
-
magentoVersion: 247,
|
|
9
|
-
storefront: [
|
|
10
|
-
{ locale: 'en', magentoStoreCode: 'en_US', defaultLocale: true },
|
|
11
|
-
{
|
|
12
|
-
locale: 'nl',
|
|
13
|
-
magentoStoreCode: 'nl_NL',
|
|
14
|
-
hygraphLocales: ['nl', 'en_us'],
|
|
15
|
-
cartDisplayPricesInclTax: true,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
locale: 'fr-be',
|
|
19
|
-
magentoStoreCode: 'fr_BE',
|
|
20
|
-
cartDisplayPricesInclTax: true,
|
|
21
|
-
linguiLocale: 'fr',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
locale: 'nl-be',
|
|
25
|
-
magentoStoreCode: 'nl_BE',
|
|
26
|
-
cartDisplayPricesInclTax: true,
|
|
27
|
-
linguiLocale: 'nl',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
locale: 'en-gb',
|
|
31
|
-
magentoStoreCode: 'en_GB',
|
|
32
|
-
cartDisplayPricesInclTax: true,
|
|
33
|
-
linguiLocale: 'en',
|
|
34
|
-
},
|
|
35
|
-
{ locale: 'en-ca', magentoStoreCode: 'en_CA', linguiLocale: 'en' },
|
|
36
|
-
],
|
|
37
|
-
productFiltersPro: true,
|
|
38
|
-
productFiltersLayout: 'DEFAULT',
|
|
39
|
-
productListPaginationVariant: 'COMPACT',
|
|
40
|
-
compareVariant: 'ICON',
|
|
41
|
-
robotsAllow: false,
|
|
42
|
-
demoMode: true,
|
|
43
|
-
limitSsg: true,
|
|
44
|
-
compare: true,
|
|
45
|
-
sidebarGallery: { paginationVariant: 'DOTS' },
|
|
46
|
-
configurableVariantForSimple: true,
|
|
47
|
-
configurableVariantValues: { url: true, content: true, gallery: true },
|
|
48
|
-
recentlyViewedProducts: { enabled: true, maxCount: 20 },
|
|
49
|
-
breadcrumbs: false,
|
|
50
|
-
customerDeleteEnabled: true,
|
|
51
|
-
previewSecret: 'SECRET',
|
|
52
|
-
};
|
package/dist/config/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./commands/generateConfig"), exports);
|
|
18
|
-
__exportStar(require("./commands/exportConfig"), exports);
|
|
19
|
-
__exportStar(require("./loadConfig"), exports);
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.loadConfig = loadConfig;
|
|
18
|
-
/* eslint-disable no-console */
|
|
19
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
20
|
-
const cosmiconfig_1 = require("cosmiconfig");
|
|
21
|
-
const config_1 = require("../generated/config");
|
|
22
|
-
const demoConfig_1 = require("./demoConfig");
|
|
23
|
-
const mergeEnvIntoConfig_1 = require("./utils/mergeEnvIntoConfig");
|
|
24
|
-
const rewriteLegacyEnv_1 = require("./utils/rewriteLegacyEnv");
|
|
25
|
-
__exportStar(require("./utils/configToImportMeta"), exports);
|
|
26
|
-
__exportStar(require("./utils/replaceConfigInString"), exports);
|
|
27
|
-
const moduleName = 'graphcommerce';
|
|
28
|
-
const loader = (0, cosmiconfig_1.cosmiconfigSync)(moduleName);
|
|
29
|
-
function loadConfig(cwd) {
|
|
30
|
-
const isMainProcess = !process.send;
|
|
31
|
-
try {
|
|
32
|
-
const result = loader.search(cwd);
|
|
33
|
-
let confFile = result?.config;
|
|
34
|
-
if (!confFile) {
|
|
35
|
-
if (isMainProcess)
|
|
36
|
-
console.warn('No graphcommerce.config.js found in the project, using demo config');
|
|
37
|
-
confFile = demoConfig_1.demoConfig;
|
|
38
|
-
}
|
|
39
|
-
confFile ||= {};
|
|
40
|
-
const schema = (0, config_1.GraphCommerceConfigSchema)();
|
|
41
|
-
const [mergedConfig, applyResult] = (0, rewriteLegacyEnv_1.rewriteLegacyEnv)(schema, process.env,
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
43
|
-
confFile);
|
|
44
|
-
if (applyResult.length > 0 && isMainProcess)
|
|
45
|
-
console.log((0, mergeEnvIntoConfig_1.formatAppliedEnv)(applyResult));
|
|
46
|
-
const finalParse = schema.parse(mergedConfig);
|
|
47
|
-
if (process.env.DEBUG && isMainProcess) {
|
|
48
|
-
console.log('Parsed configuration');
|
|
49
|
-
console.log(finalParse);
|
|
50
|
-
}
|
|
51
|
-
return finalParse;
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
if (error instanceof Error) {
|
|
55
|
-
if (isMainProcess) {
|
|
56
|
-
console.log('Error while parsing graphcommerce.config.js', error.message);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.configToImportMeta = configToImportMeta;
|
|
4
|
-
function flattenKeys(value, initialPathPrefix, stringify) {
|
|
5
|
-
// Is a scalar:
|
|
6
|
-
if (value === null || value === undefined || typeof value === 'number') {
|
|
7
|
-
return { [initialPathPrefix]: value };
|
|
8
|
-
}
|
|
9
|
-
if (typeof value === 'string') {
|
|
10
|
-
return { [initialPathPrefix]: stringify ? JSON.stringify(value) : value };
|
|
11
|
-
}
|
|
12
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
13
|
-
return {
|
|
14
|
-
[initialPathPrefix]: stringify || Array.isArray(value) ? JSON.stringify(value) : value,
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
if (typeof value === 'object') {
|
|
18
|
-
let outputValue = value;
|
|
19
|
-
if (stringify)
|
|
20
|
-
outputValue =
|
|
21
|
-
process.env.NODE_ENV !== 'production'
|
|
22
|
-
? `{ __debug: "'${initialPathPrefix}' can not be destructured, please access deeper properties directly" }`
|
|
23
|
-
: '{}';
|
|
24
|
-
return {
|
|
25
|
-
[initialPathPrefix]: outputValue,
|
|
26
|
-
...Object.keys(value)
|
|
27
|
-
.map((key) => {
|
|
28
|
-
const deep = value[key];
|
|
29
|
-
return flattenKeys(deep, `${initialPathPrefix}.${key}`, stringify);
|
|
30
|
-
})
|
|
31
|
-
.reduce((acc, path) => ({ ...acc, ...path }), {}),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
throw Error(`Unexpected value: ${value}`);
|
|
35
|
-
}
|
|
36
|
-
/** The result of this function is passed to the webpack DefinePlugin as import.meta.graphCommerce.* */
|
|
37
|
-
function configToImportMeta(config, path = 'import.meta.graphCommerce', stringify = true) {
|
|
38
|
-
return flattenKeys(config, path, stringify);
|
|
39
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = diff;
|
|
4
|
-
function isObject(val) {
|
|
5
|
-
return typeof val === 'object' && val !== null;
|
|
6
|
-
}
|
|
7
|
-
function isArray(val) {
|
|
8
|
-
return Array.isArray(val);
|
|
9
|
-
}
|
|
10
|
-
/** Simple diff function, retuns the values of the second object. */
|
|
11
|
-
function diff(item1, item2) {
|
|
12
|
-
const item1Type = typeof item2;
|
|
13
|
-
const item2Type = typeof item2;
|
|
14
|
-
const isSame = item1Type === item2Type;
|
|
15
|
-
// If the types aren't the same we always have a diff
|
|
16
|
-
if (!isSame)
|
|
17
|
-
return item2;
|
|
18
|
-
if (isArray(item1) && isArray(item2)) {
|
|
19
|
-
const res = item1.map((val, idx) => diff(val, item2[idx])).filter((val) => !!val);
|
|
20
|
-
return res.length ? res : undefined;
|
|
21
|
-
}
|
|
22
|
-
if (isObject(item1) && isObject(item2)) {
|
|
23
|
-
const entriesRight = Object.fromEntries(Object.entries(item1)
|
|
24
|
-
.map(([key, val]) => [key, diff(val, item2[key])])
|
|
25
|
-
.filter((entry) => !!entry[1]));
|
|
26
|
-
const entriesLeft = Object.fromEntries(Object.entries(item2)
|
|
27
|
-
.map(([key, val]) => [key, diff(item1[key], val)])
|
|
28
|
-
.filter((entry) => !!entry[1]));
|
|
29
|
-
const entries = { ...entriesRight, ...entriesLeft };
|
|
30
|
-
return Object.keys(entries).length ? entries : undefined;
|
|
31
|
-
}
|
|
32
|
-
return item2 === item1 ? undefined : item2;
|
|
33
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.exportConfigToEnv = exportConfigToEnv;
|
|
4
|
-
const mergeEnvIntoConfig_1 = require("./mergeEnvIntoConfig");
|
|
5
|
-
const fmt = (value) => {
|
|
6
|
-
let formattedValue = value;
|
|
7
|
-
if (typeof formattedValue === 'boolean') {
|
|
8
|
-
formattedValue = formattedValue ? '1' : '0';
|
|
9
|
-
}
|
|
10
|
-
if (typeof formattedValue === 'object') {
|
|
11
|
-
formattedValue = JSON.stringify(formattedValue);
|
|
12
|
-
}
|
|
13
|
-
if (typeof formattedValue === 'number') {
|
|
14
|
-
formattedValue = String(formattedValue);
|
|
15
|
-
}
|
|
16
|
-
return formattedValue;
|
|
17
|
-
};
|
|
18
|
-
function exportConfigToEnv(config) {
|
|
19
|
-
let env = '';
|
|
20
|
-
Object.entries(config).forEach(([key, value]) => {
|
|
21
|
-
if (Array.isArray(value)) {
|
|
22
|
-
value.forEach((val, idx) => {
|
|
23
|
-
env += `${(0, mergeEnvIntoConfig_1.toEnvStr)([key, `${idx}`])}='${fmt(val)}'\n`;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
env += `${(0, mergeEnvIntoConfig_1.toEnvStr)([key])}='${fmt(value)}'\n`;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
return env;
|
|
31
|
-
}
|