@graphcommerce/next-config 10.0.1-canary.0 → 10.0.1-canary.2

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 10.0.1-canary.2
4
+
5
+ ## 10.0.1-canary.1
6
+
7
+ ### Patch Changes
8
+
9
+ - [#2571](https://github.com/graphcommerce-org/graphcommerce/pull/2571) [`a16bed1`](https://github.com/graphcommerce-org/graphcommerce/commit/a16bed1b8670932e273d5ea7114bf01fda40f2f8) - Always copy the file if the original file is a core file, allowing overrides. ([@paales](https://github.com/paales))
10
+
3
11
  ## 10.0.1-canary.0
4
12
 
5
13
  ### Patch Changes
@@ -16,6 +16,7 @@ vi.mock('fs/promises', () => ({
16
16
  stat: vi.fn(),
17
17
  unlink: vi.fn(),
18
18
  rmdir: vi.fn(),
19
+ rename: vi.fn(),
19
20
  },
20
21
  readFile: vi.fn(),
21
22
  writeFile: vi.fn(),
@@ -24,6 +25,7 @@ vi.mock('fs/promises', () => ({
24
25
  stat: vi.fn(),
25
26
  unlink: vi.fn(),
26
27
  rmdir: vi.fn(),
28
+ rename: vi.fn(),
27
29
  }))
28
30
 
29
31
  // Mock fast-glob
@@ -425,11 +427,17 @@ describe('copyFiles', () => {
425
427
  }
426
428
  return Promise.reject(new Error(`ENOENT: no such file or directory, open '${filePath}'`))
427
429
  })
430
+ mockFs.rename.mockResolvedValue(undefined)
428
431
 
429
432
  await copyFiles()
430
433
 
434
+ // Unmanaged files should be renamed to .original and a new managed file created
435
+ expect(mockFs.rename).toHaveBeenCalledWith(
436
+ path.join(mockCwd, 'file.ts'),
437
+ path.join(mockCwd, 'file.original.ts'),
438
+ )
431
439
  expect(consoleInfo).toHaveBeenCalledWith(
432
- expect.stringContaining('Note: File file.ts has been modified'),
440
+ expect.stringContaining('Renamed existing file to: file.original.ts'),
433
441
  )
434
442
  })
435
443
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  exports[`parses an env config object 1`] = `
4
4
  {
5
- "GC_DEMO_MODE": true,
6
5
  "GC_STOREFRONT": [
7
6
  {
8
7
  "defaultLocale": true,
@@ -14,10 +13,8 @@ exports[`parses an env config object 1`] = `
14
13
  },
15
14
  ],
16
15
  "GC_STOREFRONT_0_DEFAULT_LOCALE": true,
17
- "GC_STOREFRONT_0_HYGRAPH_LOCALES_0": "en",
18
16
  "GC_STOREFRONT_0_LOCALE": "en",
19
17
  "GC_STOREFRONT_0_MAGENTO_STORE_CODE": "en_us",
20
- "GC_STOREFRONT_1_HYGRAPH_LOCALES_0": "de",
21
18
  "GC_STOREFRONT_1_LOCALE": "de",
22
19
  "GC_STOREFRONT_1_MAGENTO_STORE_CODE": "de_de",
23
20
  }
@@ -557,6 +557,14 @@ it('finds plugins', () => {
557
557
  "targetModule": "@graphcommerce/magento-product-configurable",
558
558
  "type": "component",
559
559
  },
560
+ {
561
+ "enabled": true,
562
+ "sourceExport": "GraphQLProvider",
563
+ "sourceModule": "@graphcommerce/magento-recently-viewed-products/plugins/AddRecentlyViewedProductsTypePolicies",
564
+ "targetExport": "GraphQLProvider",
565
+ "targetModule": "@graphcommerce/graphql",
566
+ "type": "component",
567
+ },
560
568
  {
561
569
  "enabled": true,
562
570
  "sourceExport": "cartItemToCartItemInput",
@@ -87,7 +87,7 @@ it('it generates an interceptor', async () => {
87
87
  * This file is NOT meant to be modified directly and is auto-generated if the plugins or the
88
88
  * original source changes.
89
89
  *
90
- * @see {@link file://./PaymentMethodContextProvider.tsx} for original source file
90
+ * @see {@link file://./PaymentMethodContextProvider.original.tsx} for original source file
91
91
  * @see {PluginAddBraintreeMethods} for source of applied plugin
92
92
  * @see {PluginAddMollieMethods} for source of applied plugin
93
93
  */
@@ -188,7 +188,7 @@ it('it can apply multiple plugins to a single export', async () => {
188
188
  * This file is NOT meant to be modified directly and is auto-generated if the plugins or the
189
189
  * original source changes.
190
190
  *
191
- * @see {@link file://./PaymentMethodContextProvider.tsx} for original source file
191
+ * @see {@link file://./PaymentMethodContextProvider.original.tsx} for original source file
192
192
  * @see {PluginAddAdyenMethods} for source of applied plugin
193
193
  * @see {PluginAddMollieMethods} for source of applied plugin
194
194
  */
@@ -257,7 +257,7 @@ it('it handles on duplicates gracefully', async () => {
257
257
  * This file is NOT meant to be modified directly and is auto-generated if the plugins or the
258
258
  * original source changes.
259
259
  *
260
- * @see {@link file://./PaymentMethodContextProvider.tsx} for original source file
260
+ * @see {@link file://./PaymentMethodContextProvider.original.tsx} for original source file
261
261
  * @see {PluginAddBraintreeMethods} for source of applied plugin
262
262
  * @see {PluginAddBraintreeMethods} for source of applied plugin
263
263
  */
@@ -434,7 +434,7 @@ it('adds debug logging to interceptors for components', async () => {
434
434
  * This file is NOT meant to be modified directly and is auto-generated if the plugins or the
435
435
  * original source changes.
436
436
  *
437
- * @see {@link file://./graphqlConfig.ts} for original source file
437
+ * @see {@link file://./graphqlConfig.original.ts} for original source file
438
438
  * @see {pluginhygraphInitMemoryCache} for source of applied plugin
439
439
  * @see {pluginmagentoInitMemoryCache} for source of applied plugin
440
440
  */
package/dist/index.js CHANGED
@@ -729,7 +729,9 @@ async function generateInterceptor(interceptor, config, oldInterceptorSource) {
729
729
  `@see {${sourceName(name(replacePlugin))}} for source of replaced component`
730
730
  );
731
731
  } else {
732
- pluginSee.push(`@see {@link file://./${targetExport}.tsx} for original source file`);
732
+ pluginSee.push(
733
+ `@see {@link file://./${targetExport}.original.tsx} for original source file`
734
+ );
733
735
  }
734
736
  const pluginInterceptors = componentPlugins.reverse().map((plugin) => {
735
737
  const pluginName = sourceName(name(plugin));
@@ -774,7 +776,9 @@ export const ${targetExport} = ${carry}`;
774
776
  `@see {${sourceName(name(replacePlugin))}} for source of replaced function`
775
777
  );
776
778
  } else {
777
- pluginSee.push(`@see {@link file://./${targetExport}.ts} for original source file`);
779
+ pluginSee.push(
780
+ `@see {@link file://./${targetExport}.original.ts} for original source file`
781
+ );
778
782
  }
779
783
  const pluginInterceptors = functionPlugins.reverse().map((plugin) => {
780
784
  const pluginName = sourceName(name(plugin));
@@ -1079,7 +1083,7 @@ async function updateGitignore(managedFiles) {
1079
1083
  try {
1080
1084
  content = await fs.readFile(gitignorePath, "utf-8");
1081
1085
  debug("Reading existing .gitignore");
1082
- } catch (err) {
1086
+ } catch {
1083
1087
  debug(".gitignore not found, creating new file");
1084
1088
  content = "";
1085
1089
  }
@@ -1114,6 +1118,11 @@ function getFileManagement(content) {
1114
1118
  if (contentStr.startsWith(MANAGED_BY_GC)) return "graphcommerce";
1115
1119
  return "unmanaged";
1116
1120
  }
1121
+ function getOriginalFilename(filePath) {
1122
+ const ext = path.extname(filePath);
1123
+ const base = filePath.slice(0, -ext.length);
1124
+ return `${base}.original${ext}`;
1125
+ }
1117
1126
  async function copyFiles() {
1118
1127
  const startTime = performance.now();
1119
1128
  debug("Starting copyFiles");
@@ -1220,11 +1229,15 @@ Path: ${copyDir}`
1220
1229
  return;
1221
1230
  }
1222
1231
  if (management === "unmanaged") {
1232
+ const originalPath = getOriginalFilename(targetPath);
1233
+ await fs.rename(targetPath, originalPath);
1234
+ const originalRelative = getOriginalFilename(file);
1223
1235
  console.info(
1224
- `Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`
1236
+ `Renamed existing file to: ${originalRelative}
1237
+ Creating managed file: ${file}`
1225
1238
  );
1226
- debug(`File ${file} doesn't have management comment, skipping`);
1227
- return;
1239
+ debug(`Renamed ${file} to ${originalRelative}`);
1240
+ targetContent = void 0;
1228
1241
  }
1229
1242
  debug(`File ${file} is managed by graphcommerce, will update if needed`);
1230
1243
  } catch (err) {
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": "10.0.1-canary.0",
5
+ "version": "10.0.1-canary.2",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
@@ -63,7 +63,7 @@
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@apollo/client": "*",
66
- "@graphcommerce/prettier-config-pwa": "^10.0.1-canary.0",
66
+ "@graphcommerce/prettier-config-pwa": "^10.0.1-canary.2",
67
67
  "@lingui/loader": "*",
68
68
  "@lingui/macro": "*",
69
69
  "@lingui/react": "*",
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-await-in-loop */
2
1
  import fs from 'fs/promises'
3
2
  import path from 'path'
4
3
  import fg from 'fast-glob'
@@ -38,7 +37,7 @@ async function updateGitignore(managedFiles: string[]) {
38
37
  try {
39
38
  content = await fs.readFile(gitignorePath, 'utf-8')
40
39
  debug('Reading existing .gitignore')
41
- } catch (err) {
40
+ } catch {
42
41
  debug('.gitignore not found, creating new file')
43
42
  content = ''
44
43
  }
@@ -79,6 +78,13 @@ function getFileManagement(content: Buffer | undefined): 'local' | 'graphcommerc
79
78
  return 'unmanaged'
80
79
  }
81
80
 
81
+ /** Generates the .original filename for a given file path (e.g., file.tsx -> file.original.tsx) */
82
+ function getOriginalFilename(filePath: string): string {
83
+ const ext = path.extname(filePath)
84
+ const base = filePath.slice(0, -ext.length)
85
+ return `${base}.original${ext}`
86
+ }
87
+
82
88
  /**
83
89
  * The packages are @graphcommerce/* packages and have special treatment.
84
90
  *
@@ -88,7 +94,8 @@ function getFileManagement(content: Buffer | undefined): 'local' | 'graphcommerc
88
94
  *
89
95
  * 1. If the file doesn't exist: Create directories and the file with "managed by: graphcommerce"
90
96
  * 2. If the file exists and starts with "managed by: local": Skip the file
91
- * 3. If the file exists but doesn't have a management comment: Suggest adding "managed by: local"
97
+ * 3. If the file exists but doesn't have a management comment: Rename to filename.original.ext and
98
+ * create the new managed file
92
99
  * 4. If the file is managed by graphcommerce: Update if content differs
93
100
  */
94
101
  export async function copyFiles() {
@@ -213,11 +220,15 @@ Found in packages:
213
220
  return
214
221
  }
215
222
  if (management === 'unmanaged') {
223
+ // Rename existing file to .original and create new managed file
224
+ const originalPath = getOriginalFilename(targetPath)
225
+ await fs.rename(targetPath, originalPath)
226
+ const originalRelative = getOriginalFilename(file)
216
227
  console.info(
217
- `Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`,
228
+ `Renamed existing file to: ${originalRelative}\nCreating managed file: ${file}`,
218
229
  )
219
- debug(`File ${file} doesn't have management comment, skipping`)
220
- return
230
+ debug(`Renamed ${file} to ${originalRelative}`)
231
+ targetContent = undefined // Treat as new file from here
221
232
  }
222
233
 
223
234
  debug(`File ${file} is managed by graphcommerce, will update if needed`)
@@ -199,7 +199,9 @@ export async function generateInterceptor(
199
199
  `@see {${sourceName(name(replacePlugin))}} for source of replaced component`,
200
200
  )
201
201
  } else {
202
- pluginSee.push(`@see {@link file://./${targetExport}.tsx} for original source file`)
202
+ pluginSee.push(
203
+ `@see {@link file://./${targetExport}.original.tsx} for original source file`,
204
+ )
203
205
  }
204
206
 
205
207
  const pluginInterceptors = componentPlugins
@@ -259,7 +261,9 @@ export const ${targetExport} = ${carry}`
259
261
  `@see {${sourceName(name(replacePlugin))}} for source of replaced function`,
260
262
  )
261
263
  } else {
262
- pluginSee.push(`@see {@link file://./${targetExport}.ts} for original source file`)
264
+ pluginSee.push(
265
+ `@see {@link file://./${targetExport}.original.ts} for original source file`,
266
+ )
263
267
  }
264
268
 
265
269
  const pluginInterceptors = functionPlugins