@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.
- package/CHANGELOG.md +28 -8
- package/__tests__/commands/copyFiles.ts +8 -5
- package/__tests__/config/utils/__snapshots__/mergeEnvIntoConfig.ts.snap +0 -905
- package/__tests__/config/utils/mergeEnvIntoConfig.ts +21 -3
- package/__tests__/config/utils/replaceConfigInString.ts +0 -1
- package/__tests__/interceptors/findPlugins.ts +270 -272
- package/__tests__/interceptors/generateInterceptors.ts +1 -0
- package/__tests__/utils/resolveDependenciesSync.ts +45 -44
- package/dist/generated/config.js +110 -116
- package/dist/index.js +3359 -26
- package/package.json +34 -8
- package/src/commands/codegen.ts +3 -3
- package/src/commands/copyFiles.ts +14 -7
- package/src/config/commands/generateConfig.ts +17 -6
- package/src/config/demoConfig.ts +0 -1
- package/src/config/loadConfig.ts +3 -9
- package/src/config/utils/mergeEnvIntoConfig.ts +9 -9
- package/src/generated/config.ts +305 -245
- package/src/interceptors/Visitor.ts +1 -1
- package/src/interceptors/findOriginalSource.ts +1 -1
- package/src/interceptors/generateInterceptor.ts +0 -2
- package/src/interceptors/parseStructure.ts +3 -3
- package/src/interceptors/writeInterceptors.ts +1 -1
- package/src/utils/resolveDependenciesSync.ts +44 -7
- package/src/withGraphCommerce.ts +30 -42
- package/tsconfig.json +1 -1
- package/__tests__/config/utils/rewriteLegancyEnv.ts +0 -78
- package/dist/commands/codegen.js +0 -18
- package/dist/commands/copyFiles.js +0 -292
- package/dist/config/commands/exportConfig.js +0 -16
- package/dist/config/commands/generateConfig.js +0 -57
- 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 -184
- 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
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.
|
|
6
|
-
"type": "
|
|
7
|
-
"
|
|
8
|
-
"
|
|
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": "
|
|
11
|
-
"build": "
|
|
12
|
-
"prepack": "
|
|
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
|
}
|
package/src/commands/codegen.ts
CHANGED
|
@@ -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.
|
|
8
|
+
console.info('🔄 Copying files from packages to project...')
|
|
9
9
|
await copyFiles()
|
|
10
10
|
|
|
11
11
|
// Generate GraphCommerce config types
|
|
12
|
-
console.
|
|
12
|
+
console.info('⚙️ Generating GraphCommerce config types...')
|
|
13
13
|
await generateConfig()
|
|
14
14
|
|
|
15
15
|
// Generate interceptors
|
|
16
|
-
console.
|
|
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.
|
|
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 (
|
|
54
|
+
if (escapedFiles.length > 0) {
|
|
48
55
|
const newSection = [
|
|
49
56
|
GITIGNORE_SECTION_START,
|
|
50
|
-
...
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
2
|
-
import
|
|
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'
|
|
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: '
|
|
55
|
-
env: { targets: { node: '
|
|
65
|
+
module: { type: 'nodenext' },
|
|
66
|
+
env: { targets: { node: '18' } },
|
|
56
67
|
})
|
|
57
68
|
|
|
58
69
|
writeFileSync(targetJs, result.code)
|
package/src/config/demoConfig.ts
CHANGED
package/src/config/loadConfig.ts
CHANGED
|
@@ -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
|
-
|
|
32
|
-
|
|
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
|
|
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) =>
|
|
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,
|
|
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
|
|