@graphcommerce/next-config 9.0.4-canary.0 → 9.0.4-canary.10

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.
Files changed (61) hide show
  1. package/CHANGELOG.md +28 -8
  2. package/__tests__/commands/copyFiles.ts +8 -5
  3. package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +0 -905
  4. package/__tests__/config/utils/mergeEnvIntoConfig.ts +21 -3
  5. package/__tests__/config/utils/replaceConfigInString.ts +0 -1
  6. package/__tests__/interceptors/findPlugins.ts +270 -272
  7. package/__tests__/interceptors/generateInterceptors.ts +1 -0
  8. package/__tests__/utils/resolveDependenciesSync.ts +45 -44
  9. package/dist/generated/config.js +110 -116
  10. package/dist/index.js +3359 -26
  11. package/package.json +34 -8
  12. package/src/commands/codegen.ts +3 -3
  13. package/src/commands/copyFiles.ts +14 -7
  14. package/src/config/commands/generateConfig.ts +17 -6
  15. package/src/config/demoConfig.ts +0 -1
  16. package/src/config/loadConfig.ts +3 -9
  17. package/src/config/utils/mergeEnvIntoConfig.ts +9 -9
  18. package/src/generated/config.ts +305 -245
  19. package/src/interceptors/Visitor.ts +1 -1
  20. package/src/interceptors/findOriginalSource.ts +1 -1
  21. package/src/interceptors/generateInterceptor.ts +0 -2
  22. package/src/interceptors/parseStructure.ts +3 -3
  23. package/src/interceptors/writeInterceptors.ts +1 -1
  24. package/src/utils/resolveDependenciesSync.ts +44 -7
  25. package/src/withGraphCommerce.ts +30 -42
  26. package/tsconfig.json +1 -1
  27. package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -78
  28. package/dist/commands/codegen.js +0 -18
  29. package/dist/commands/copyFiles.js +0 -292
  30. package/dist/config/commands/exportConfig.js +0 -16
  31. package/dist/config/commands/generateConfig.js +0 -57
  32. package/dist/config/demoConfig.js +0 -52
  33. package/dist/config/index.js +0 -19
  34. package/dist/config/loadConfig.js +0 -62
  35. package/dist/config/utils/configToImportMeta.js +0 -39
  36. package/dist/config/utils/diff.js +0 -33
  37. package/dist/config/utils/exportConfigToEnv.js +0 -31
  38. package/dist/config/utils/mergeEnvIntoConfig.js +0 -184
  39. package/dist/config/utils/replaceConfigInString.js +0 -12
  40. package/dist/config/utils/rewriteLegacyEnv.js +0 -115
  41. package/dist/interceptors/InterceptorPlugin.js +0 -108
  42. package/dist/interceptors/RenameVisitor.js +0 -19
  43. package/dist/interceptors/Visitor.js +0 -1414
  44. package/dist/interceptors/commands/codegenInterceptors.js +0 -22
  45. package/dist/interceptors/extractExports.js +0 -159
  46. package/dist/interceptors/findOriginalSource.js +0 -103
  47. package/dist/interceptors/findPlugins.js +0 -68
  48. package/dist/interceptors/generateInterceptor.js +0 -219
  49. package/dist/interceptors/generateInterceptors.js +0 -56
  50. package/dist/interceptors/parseStructure.js +0 -84
  51. package/dist/interceptors/swc.js +0 -15
  52. package/dist/interceptors/writeInterceptors.js +0 -44
  53. package/dist/utils/PackagesSort.js +0 -7
  54. package/dist/utils/TopologicalSort.js +0 -87
  55. package/dist/utils/isMonorepo.js +0 -47
  56. package/dist/utils/packageRoots.js +0 -31
  57. package/dist/utils/resolveDependenciesSync.js +0 -78
  58. package/dist/utils/resolveDependency.js +0 -70
  59. package/dist/utils/sig.js +0 -34
  60. package/dist/withGraphCommerce.js +0 -162
  61. package/src/config/utils/rewriteLegacyEnv.ts +0 -125
package/package.json CHANGED
@@ -2,27 +2,38 @@
2
2
  "name": "@graphcommerce/next-config",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.0.4-canary.0",
6
- "type": "commonjs",
7
- "main": "dist/index.js",
8
- "types": "src/index.ts",
5
+ "version": "9.0.4-canary.10",
6
+ "type": "module",
7
+ "types": "./src/index.ts",
8
+ "exports": {
9
+ ".": {
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./config": {
13
+ "default": "./dist/generated/config.js"
14
+ }
15
+ },
9
16
  "scripts": {
10
- "dev": "tsc -W --preserveWatchOutput",
11
- "build": "tsc",
12
- "prepack": "tsc"
17
+ "dev": "pkgroll --clean-dist --watch",
18
+ "build": "pkgroll --clean-dist",
19
+ "prepack": "pkgroll --clean-dist"
13
20
  },
14
21
  "dependencies": {
22
+ "@graphql-codegen/cli": "5.0.3",
15
23
  "@swc/core": "1.10.1",
16
24
  "@swc/wasm-web": "^1.10.1",
17
25
  "@types/circular-dependency-plugin": "^5.0.8",
26
+ "@types/js-yaml": "^4",
18
27
  "@types/lodash": "^4.17.13",
19
28
  "babel-plugin-macros": "^3.1.0",
20
29
  "chalk": "^4",
21
30
  "circular-dependency-plugin": "^5.2.2",
31
+ "cosmiconfig": "^8.3.6",
22
32
  "fast-glob": "^3.3.2",
23
33
  "glob": "^10.4.5",
24
34
  "graphql": "^16.10.0",
25
35
  "inspectpack": "^4.7.1",
36
+ "js-yaml": "^4.1.0",
26
37
  "js-yaml-loader": "^1.2.2",
27
38
  "lodash": "^4.17.21",
28
39
  "react": "^18.3.1",
@@ -32,10 +43,25 @@
32
43
  "zod": "^3.24.1"
33
44
  },
34
45
  "peerDependencies": {
46
+ "@graphcommerce/prettier-config-pwa": "^9.0.4-canary.10",
35
47
  "@lingui/loader": "*",
36
48
  "@lingui/macro": "*",
37
49
  "@lingui/react": "*",
38
50
  "dotenv": "^16",
39
- "next": "*"
51
+ "next": "*",
52
+ "prettier": "^3"
53
+ },
54
+ "prettier": "@graphcommerce/prettier-config-pwa",
55
+ "eslint": {
56
+ "extends": "@graphcommerce/eslint-config-pwa"
57
+ },
58
+ "eslintConfig": {
59
+ "extends": "@graphcommerce/eslint-config-pwa",
60
+ "parserOptions": {
61
+ "project": "./tsconfig.json"
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "pkgroll": "^2.5.1"
40
66
  }
41
67
  }
@@ -5,14 +5,14 @@ import { copyFiles } from './copyFiles'
5
5
  /** Run all code generation steps in sequence */
6
6
  export async function codegen() {
7
7
  // Copy files from packages to project
8
- console.log('🔄 Copying files from packages to project...')
8
+ console.info('🔄 Copying files from packages to project...')
9
9
  await copyFiles()
10
10
 
11
11
  // Generate GraphCommerce config types
12
- console.log('⚙️ Generating GraphCommerce config types...')
12
+ console.info('⚙️ Generating GraphCommerce config types...')
13
13
  await generateConfig()
14
14
 
15
15
  // Generate interceptors
16
- console.log('🔌 Generating interceptors...')
16
+ console.info('🔌 Generating interceptors...')
17
17
  await codegenInterceptors()
18
18
  }
@@ -6,7 +6,7 @@ import { resolveDependenciesSync } from '../utils/resolveDependenciesSync'
6
6
 
7
7
  // Add debug logging helper
8
8
  const debug = (...args: unknown[]) => {
9
- if (process.env.DEBUG) console.log('[copy-files]', ...args)
9
+ if (process.env.DEBUG) console.info('[copy-files]', ...args)
10
10
  }
11
11
 
12
12
  // Add constants for the magic comments
@@ -25,6 +25,13 @@ const GITIGNORE_SECTION_END = '# end managed by: graphcommerce'
25
25
  * - Ensures the file ends with a newline
26
26
  */
27
27
  async function updateGitignore(managedFiles: string[]) {
28
+ const escapedFiles = managedFiles
29
+ .map((file) =>
30
+ // Escape special characters in file names
31
+ file.replace(/[*+?^${}()|[\]\\]/g, '\\$&'),
32
+ )
33
+ .sort()
34
+
28
35
  const gitignorePath = path.join(process.cwd(), '.gitignore')
29
36
  let content: string
30
37
 
@@ -44,10 +51,10 @@ async function updateGitignore(managedFiles: string[]) {
44
51
  content = content.replace(sectionRegex, '')
45
52
 
46
53
  // Only add new section if there are files to manage
47
- if (managedFiles.length > 0) {
54
+ if (escapedFiles.length > 0) {
48
55
  const newSection = [
49
56
  GITIGNORE_SECTION_START,
50
- ...managedFiles.sort(),
57
+ ...escapedFiles,
51
58
  GITIGNORE_SECTION_END,
52
59
  '', // Empty line at the end
53
60
  ].join('\n')
@@ -206,7 +213,7 @@ Found in packages:
206
213
  return
207
214
  }
208
215
  if (management === 'unmanaged') {
209
- console.log(
216
+ console.info(
210
217
  `Note: File ${file} has been modified. Add '${MANAGED_LOCALLY.trim()}' at the top to manage it locally.`,
211
218
  )
212
219
  debug(`File ${file} doesn't have management comment, skipping`)
@@ -220,7 +227,7 @@ Found in packages:
220
227
  Source: ${sourcePath}`)
221
228
  process.exit(1)
222
229
  }
223
- console.log(`Creating new file: ${file}\nSource: ${sourcePath}`)
230
+ console.info(`Creating new file: ${file}\nSource: ${sourcePath}`)
224
231
  debug('File does not exist yet')
225
232
  }
226
233
 
@@ -234,7 +241,7 @@ Source: ${sourcePath}`)
234
241
  // Copy the file with magic comment
235
242
  await fs.writeFile(targetPath, contentWithComment)
236
243
  if (targetContent) {
237
- console.log(`Updated managed file: ${file}`)
244
+ console.info(`Updated managed file: ${file}`)
238
245
  debug(`Overwrote existing file: ${file}`)
239
246
  }
240
247
 
@@ -293,7 +300,7 @@ Source: ${sourcePath}`)
293
300
  // Then try to remove the file
294
301
  try {
295
302
  await fs.unlink(filePath)
296
- console.log(`Removed managed file: ${file}`)
303
+ console.info(`Removed managed file: ${file}`)
297
304
  debug(`Removed file: ${file}`)
298
305
  } catch (err) {
299
306
  if ((err as { code?: string }).code !== 'ENOENT') {
@@ -1,8 +1,9 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
- import { writeFileSync } from 'fs'
1
+ import { readFileSync, writeFileSync } from 'fs'
2
+ import prettierConf from '@graphcommerce/prettier-config-pwa'
3
3
  import { generate } from '@graphql-codegen/cli'
4
4
  import { transformFileSync } from '@swc/core'
5
5
  import dotenv from 'dotenv'
6
+ import prettier from 'prettier'
6
7
  import { findParentPath } from '../../utils/isMonorepo'
7
8
  import { resolveDependenciesSync } from '../../utils/resolveDependenciesSync'
8
9
  import { resolveDependency } from '../../utils/resolveDependency'
@@ -27,10 +28,9 @@ export async function generateConfig() {
27
28
  schema: ['graphql/**/Config.graphqls', ...schemaLocations],
28
29
  generates: {
29
30
  [targetTs]: {
30
- plugins: ['typescript', 'typescript-validation-schema', 'add'],
31
+ plugins: ['typescript', 'typescript-validation-schema'],
31
32
  config: {
32
33
  // enumsAsTypes: true,
33
- content: '/* eslint-disable */',
34
34
  schema: 'zod',
35
35
  notAllowEmptyString: true,
36
36
  strictScalars: true,
@@ -50,9 +50,20 @@ export async function generateConfig() {
50
50
  },
51
51
  })
52
52
 
53
+ writeFileSync(
54
+ targetTs,
55
+ await prettier.format(readFileSync(targetTs, 'utf-8'), {
56
+ ...prettierConf,
57
+ parser: 'typescript',
58
+ plugins: prettierConf.plugins?.filter(
59
+ (p) => typeof p === 'string' && !p.includes('prettier-plugin-sort-imports'),
60
+ ),
61
+ }),
62
+ )
63
+
53
64
  const result = transformFileSync(targetTs, {
54
- module: { type: 'commonjs' },
55
- env: { targets: { node: '16' } },
65
+ module: { type: 'nodenext' },
66
+ env: { targets: { node: '18' } },
56
67
  })
57
68
 
58
69
  writeFileSync(targetJs, result.code)
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
1
  import type { PartialDeep } from 'type-fest'
3
2
  import type { GraphCommerceConfig, GraphCommerceStorefrontConfig } from '../generated/config'
4
3
 
@@ -1,11 +1,9 @@
1
1
  /* eslint-disable no-console */
2
- // eslint-disable-next-line import/no-extraneous-dependencies
3
2
  import { cosmiconfigSync } from 'cosmiconfig'
4
3
  import type { GraphCommerceConfig } from '../generated/config'
5
4
  import { GraphCommerceConfigSchema } from '../generated/config'
6
5
  import { demoConfig } from './demoConfig'
7
- import { formatAppliedEnv } from './utils/mergeEnvIntoConfig'
8
- import { rewriteLegacyEnv } from './utils/rewriteLegacyEnv'
6
+ import { formatAppliedEnv, mergeEnvIntoConfig } from './utils/mergeEnvIntoConfig'
9
7
 
10
8
  export * from './utils/configToImportMeta'
11
9
  export * from './utils/replaceConfigInString'
@@ -28,12 +26,8 @@ export function loadConfig(cwd: string): GraphCommerceConfig {
28
26
  confFile ||= {}
29
27
 
30
28
  const schema = GraphCommerceConfigSchema()
31
- const [mergedConfig, applyResult] = rewriteLegacyEnv(
32
- schema,
33
- process.env,
34
- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
35
- confFile,
36
- )
29
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
30
+ const [mergedConfig, applyResult] = mergeEnvIntoConfig(schema, confFile, process.env)
37
31
 
38
32
  if (applyResult.length > 0 && isMainProcess) console.log(formatAppliedEnv(applyResult))
39
33
 
@@ -1,8 +1,6 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
1
  import { cloneDeep, mergeDeep } from '@apollo/client/utilities'
3
2
  import chalk from 'chalk'
4
- import { get, set } from 'lodash'
5
- import snakeCase from 'lodash/snakeCase'
3
+ import lodash from 'lodash'
6
4
  import type { ZodAny, ZodRawShape, ZodTypeAny } from 'zod'
7
5
  import {
8
6
  z,
@@ -19,7 +17,11 @@ import {
19
17
  } from 'zod'
20
18
  import diff from './diff'
21
19
 
22
- const fmt = (s: string) => s.split(/(\d+)/).map(snakeCase).join('')
20
+ const fmt = (s: string) =>
21
+ s
22
+ .split(/(\d+)/)
23
+ .map((v) => lodash.snakeCase(v))
24
+ .join('')
23
25
  export const toEnvStr = (path: string[]) => ['GC', ...path].map(fmt).join('_').toUpperCase()
24
26
  const dotNotation = (pathParts: string[]) =>
25
27
  pathParts
@@ -178,14 +180,14 @@ export function mergeEnvIntoConfig(
178
180
  return
179
181
  }
180
182
 
181
- const dotValue = get(newConfig, dotVar)
183
+ const dotValue = lodash.get(newConfig, dotVar)
182
184
  const merged = mergeDeep(dotValue, value)
183
185
 
184
186
  const from = diff(merged, dotValue)
185
187
  const to = diff(dotValue, merged)
186
188
 
187
189
  applyResult.push({ envVar, envValue, dotVar, from, to })
188
- set(newConfig, dotVar, merged)
190
+ lodash.set(newConfig, dotVar, merged)
189
191
  })
190
192
 
191
193
  return [newConfig, applyResult] as const
@@ -204,9 +206,7 @@ export function mergeEnvIntoConfig(
204
206
  export function formatAppliedEnv(applyResult: ApplyResult) {
205
207
  let hasError = false
206
208
  let hasWarning = false
207
- const lines = applyResult.map(({ from, to, envValue, envVar, dotVar, error, warning }) => {
208
- const fromFmt = chalk.red(JSON.stringify(from))
209
- const toFmt = chalk.green(JSON.stringify(to))
209
+ const lines = applyResult.map(({ from, to, envVar, dotVar, error, warning }) => {
210
210
  const envVariableFmt = `${envVar}`
211
211
  const dotVariableFmt = chalk.bold.underline(`${dotVar}`)
212
212