@graphcommerce/cli 9.0.0-canary.99 → 9.0.1-canary.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/package.json CHANGED
@@ -2,49 +2,42 @@
2
2
  "name": "@graphcommerce/cli",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "9.0.0-canary.99",
5
+ "version": "9.0.1-canary.0",
6
6
  "scripts": {
7
- "dev": "tsc --preserveWatchOutput --watch",
8
- "build": "tsc",
9
- "prepack": "tsc"
7
+ "dev": "pkgroll --watch",
8
+ "build": "pkgroll",
9
+ "prepack": "pkgroll"
10
10
  },
11
- "type": "commonjs",
12
- "main": "dist/index.js",
13
- "types": "src/index.ts",
11
+ "type": "module",
14
12
  "bin": {
15
- "gql-gen": "dist/bin/codegen.js",
16
- "gql-mesh": "dist/bin/mesh.js",
13
+ "gc-gql-codegen": "dist/bin/codegen.js",
14
+ "gc-mesh": "dist/bin/mesh.js",
17
15
  "graphcommerce": "dist/bin/graphcommerce.js",
18
- "graphql-code-generator": "dist/bin/codegen.js",
19
- "graphql-codegen": "dist/bin/codegen.js",
20
- "graphql-mesh": "dist/bin/mesh.js",
21
- "is-monorepo": "dist/bin/is-monorepo.js",
22
- "mesh": "dist/bin/mesh.js"
16
+ "is-monorepo": "dist/bin/is-monorepo.js"
23
17
  },
24
18
  "dependencies": {
25
- "@graphql-codegen/cli": "5.0.2",
26
- "@graphql-mesh/cli": "latest",
27
- "@graphql-mesh/cross-helpers": "latest",
28
- "@graphql-mesh/runtime": "latest",
29
- "@graphql-mesh/store": "latest",
30
- "@graphql-mesh/types": "latest",
31
- "@graphql-mesh/utils": "latest",
32
- "@graphql-tools/utils": "^10.3.2",
19
+ "@graphql-codegen/cli": "5.0.3",
33
20
  "cosmiconfig": "^8.3.6",
34
21
  "detect-package-manager": "^3.0.2",
35
- "graphql-codegen-typescript-validation-schema": "^0.15.0",
22
+ "dotenv": "16.4.7",
23
+ "graphql": "^16.10.0",
24
+ "graphql-codegen-typescript-validation-schema": "^0.17.0",
36
25
  "graphql-tag": "^2.12.6",
37
- "rimraf": "^5.0.9",
38
- "tslib": "^2.6.3",
39
- "tsx": "^4.16.2"
26
+ "rimraf": "^5.0.10",
27
+ "tslib": "^2.8.1",
28
+ "tsx": "^4.19.2",
29
+ "yaml": "2.6.1"
40
30
  },
41
31
  "peerDependencies": {
42
- "@graphcommerce/eslint-config-pwa": "^9.0.0-canary.99",
43
- "@graphcommerce/hygraph-cli": "^9.0.0-canary.99",
44
- "@graphcommerce/next-config": "^9.0.0-canary.99",
45
- "@graphcommerce/prettier-config-pwa": "^9.0.0-canary.99",
46
- "@graphcommerce/typescript-config-pwa": "^9.0.0-canary.99",
47
- "graphql": "^16.7.1",
32
+ "@graphcommerce/eslint-config-pwa": "^9.0.1-canary.0",
33
+ "@graphcommerce/graphql-mesh": "^9.0.1-canary.0",
34
+ "@graphcommerce/hygraph-cli": "^9.0.1-canary.0",
35
+ "@graphcommerce/next-config": "^9.0.1-canary.0",
36
+ "@graphcommerce/prettier-config-pwa": "^9.0.1-canary.0",
37
+ "@graphcommerce/typescript-config-pwa": "^9.0.1-canary.0",
38
+ "@graphql-mesh/cli": "*",
39
+ "@graphql-mesh/types": "*",
40
+ "@graphql-mesh/utils": "*",
48
41
  "react": "^18.2.0"
49
42
  },
50
43
  "sideEffects": false,
@@ -57,5 +50,8 @@
57
50
  "parserOptions": {
58
51
  "project": "./tsconfig.json"
59
52
  }
53
+ },
54
+ "devDependencies": {
55
+ "pkgroll": "^2.5.1"
60
56
  }
61
57
  }
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
+
2
3
  /* eslint-disable import/no-extraneous-dependencies */
3
- import fs from 'node:fs/promises'
4
- import path from 'node:path'
5
4
  import { packageRoots, resolveDependenciesSync } from '@graphcommerce/next-config'
6
- import { runCli, cliError, loadCodegenConfig } from '@graphql-codegen/cli'
7
- import { Types } from '@graphql-codegen/plugin-helpers'
5
+ import { cliError, loadCodegenConfig, runCli } from '@graphql-codegen/cli'
6
+ import type { Types } from '@graphql-codegen/plugin-helpers'
8
7
  import dotenv from 'dotenv'
8
+ import fs from 'node:fs/promises'
9
+ import path from 'node:path'
9
10
  import { rimraf } from 'rimraf'
10
11
  import yaml from 'yaml'
11
12
 
@@ -14,7 +15,7 @@ const [, , cmd] = process.argv
14
15
  dotenv.config()
15
16
 
16
17
  const root = process.cwd()
17
- const configLocation = path.join(root, `._tmp_codegen.yml`)
18
+ const configLocation = path.join(root, '._tmp_codegen.yml')
18
19
 
19
20
  async function cleanup() {
20
21
  try {
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const commands = {
4
+ codegen: () => import('@graphcommerce/next-config').then((m) => m.codegen),
4
5
  'codegen-config': () => import('@graphcommerce/next-config').then((m) => m.generateConfig),
6
+ 'copy-files': () => import('@graphcommerce/next-config').then((m) => m.copyFiles),
5
7
  'codegen-interceptors': () =>
6
8
  import('@graphcommerce/next-config').then((m) => m.codegenInterceptors),
7
9
  'export-config': () => import('@graphcommerce/next-config').then((m) => m.exportConfig),
@@ -1,44 +1,64 @@
1
1
  #!/usr/bin/env node
2
-
3
- import { ChildProcess, spawn } from 'node:child_process'
4
- import { isMonorepo } from '@graphcommerce/next-config'
2
+ import type { ChildProcess } from 'node:child_process'
3
+ import { spawn } from 'node:child_process'
4
+ import path from 'node:path'
5
+ import { findParentPath } from '@graphcommerce/next-config'
5
6
  import { detect } from 'detect-package-manager'
6
7
 
8
+ const debug = process.env.DEBUG === '1'
9
+ // eslint-disable-next-line no-console
10
+ const log = (message: string) => debug && console.log(`is-monorepo: ${message}`)
11
+ const logError = (message: string) => console.error(`is-monorepo: ${message}`)
12
+
7
13
  /**
8
- * Executes a command dependening if we're running in a monorepo or not Usage:
14
+ * Executes a command depending if we're running in a monorepo or not. Usage: is-monorepo '[pkgrun]
15
+ * run my-script' '[pkgrun] run my-other-script'
9
16
  *
10
- * is-monorepo '[pkgrun] run my-script' '[pkgrun] run my-other-script'
17
+ * The [pkgrun] placeholder will be replaced with the detected package manager:
11
18
  *
12
- * We're using the `[pkgrun]` placeholder to replace it with the package manager we're using. For
13
- * example, if we're using `yarn` it will replace `[pkgrun]` with `yarn`. If we're using `npm` it
14
- * will replace `[pkgrun]` with `npm run`.
19
+ * - Yarn -> 'yarn'
20
+ * - Npm -> 'npm run'
15
21
  */
16
22
  async function main() {
17
- const isMono = isMonorepo()
18
- const command = isMono ? process.argv.slice(2)[0] : process.argv.slice(2)[1]
23
+ const parentPath = findParentPath(process.cwd())
24
+
25
+ const command = parentPath ? process.argv.slice(2)[0] : process.argv.slice(2)[1]
26
+
27
+ if (!command) {
28
+ logError('No command provided')
29
+ process.exit(1)
30
+ }
19
31
 
20
32
  let packageManager = 'yarn'
21
33
  try {
22
- packageManager = await detect({ cwd: isMono ? `../..` : `.` })
34
+ packageManager = await detect({ cwd: '.' })
23
35
  } catch {
24
- console.error('Could not detect package manager, defaulting to yarn')
36
+ log('Could not detect package manager, defaulting to yarn')
25
37
  }
26
38
 
39
+ const relativePath = parentPath ? `cd ${path.relative(process.cwd(), parentPath)}/` : 'cd .'
27
40
  const commandArray = command
28
41
  .split(' ')
29
- .map((arg) => arg.replace('[pkgrun]', `${packageManager} run`))
42
+ .map((arg) =>
43
+ arg.replace('[pkgrun]', `${packageManager}${packageManager === 'npm' ? ' run' : ''}`),
44
+ )
45
+ log(`Command: ${commandArray.join(' ')}`)
30
46
 
31
- if (isMono) commandArray.unshift('cd', '../..', '&&')
47
+ const finalCommand = `${relativePath} && ${commandArray.join(' ')}`
48
+ log(`Executing: ${finalCommand}`)
32
49
 
33
- const [cmd, ...args] = commandArray
34
- const childProcess: ChildProcess = spawn(cmd, args, { shell: true, stdio: 'inherit' })
50
+ const childProcess: ChildProcess = spawn(finalCommand, [], { shell: true, stdio: 'inherit' })
35
51
 
36
52
  childProcess.on('exit', (code) => {
37
53
  process.exit(code ?? 0)
38
54
  })
39
55
  }
40
56
 
41
- main().catch((error) => {
42
- console.error(error)
57
+ main().catch((err: unknown) => {
58
+ if (err instanceof Error) {
59
+ logError(err.message)
60
+ } else {
61
+ logError('An unknown error occurred')
62
+ }
43
63
  process.exit(1)
44
64
  })
package/src/bin/mesh.ts CHANGED
@@ -1,30 +1,32 @@
1
- #!/usr/bin/env node
2
1
  /* eslint-disable import/no-extraneous-dependencies */
3
2
  import { promises as fs } from 'node:fs'
4
3
  import path from 'node:path'
5
4
  import { exit } from 'node:process'
5
+ import type { meshConfig as meshConfigBase } from '@graphcommerce/graphql-mesh/meshConfig'
6
6
  import {
7
7
  loadConfig,
8
8
  packageRoots,
9
9
  replaceConfigInString,
10
10
  resolveDependenciesSync,
11
+ sig,
11
12
  } from '@graphcommerce/next-config'
12
- import { graphqlMesh, DEFAULT_CLI_PARAMS, GraphQLMeshCLIParams } from '@graphql-mesh/cli'
13
- import { Logger, YamlConfig } from '@graphql-mesh/types'
14
- import { Handler } from '@graphql-mesh/types/typings/config'
15
- import { DefaultLogger } from '@graphql-mesh/utils'
13
+ import type { GraphQLMeshCLIParams } from '@graphql-mesh/cli'
14
+ import { DEFAULT_CLI_PARAMS, graphqlMesh } from '@graphql-mesh/cli'
15
+ import type { Logger, YamlConfig } from '@graphql-mesh/types'
16
+ import { DefaultLogger, fileURLToPath } from '@graphql-mesh/utils'
16
17
  import dotenv from 'dotenv'
17
- import type { OmitIndexSignature, Entries } from 'type-fest'
18
+ import 'tsx/cjs'
19
+ import 'tsx/esm'
20
+ import type { Entries, OmitIndexSignature } from 'type-fest'
18
21
  import yaml from 'yaml'
19
22
  import { findConfig } from '../utils/findConfig'
20
- import type { meshConfig as meshConfigBase } from '@graphcommerce/graphql-mesh/meshConfig'
21
- // eslint-disable-next-line import/no-unresolved
22
- import 'tsx/cjs' // support importing typescript configs in CommonJS
23
- // eslint-disable-next-line import/no-unresolved
24
- import 'tsx/esm' // support importing typescript configs in ESM
25
23
 
26
24
  dotenv.config()
27
25
 
26
+ function resolvePath(pathStr: string) {
27
+ return fileURLToPath(import.meta.resolve(pathStr))
28
+ }
29
+
28
30
  export function handleFatalError(e: Error, logger: Logger = new DefaultLogger('◈')) {
29
31
  logger.error(e.stack || e.message)
30
32
  // eslint-disable-next-line no-console
@@ -33,7 +35,7 @@ export function handleFatalError(e: Error, logger: Logger = new DefaultLogger('
33
35
  }
34
36
 
35
37
  const root = process.cwd()
36
- const meshDir = path.dirname(require.resolve('@graphcommerce/graphql-mesh'))
38
+ const meshDir = path.dirname(resolvePath('@graphcommerce/graphql-mesh'))
37
39
  const relativePath = path.join(path.relative(meshDir, root), '/')
38
40
 
39
41
  const cliParams: GraphQLMeshCLIParams = {
@@ -41,7 +43,7 @@ const cliParams: GraphQLMeshCLIParams = {
41
43
  playgroundTitle: 'GraphCommerce® Mesh',
42
44
  }
43
45
 
44
- const tmpMesh = `_tmp_mesh`
46
+ const tmpMesh = '_tmp_mesh'
45
47
  const tmpMeshLocation = path.join(root, `.${tmpMesh}rc.yml`)
46
48
 
47
49
  async function cleanup() {
@@ -60,12 +62,14 @@ const main = async () => {
60
62
  const baseConf = (await findConfig({})) as YamlConfig.Config
61
63
  const graphCommerce = loadConfig(root)
62
64
 
63
- // eslint-disable-next-line global-require
64
- // @ts-ignore Might not exist
65
- const { meshConfig } = (await import('@graphcommerce/graphql-mesh/meshConfig.interceptor')) as {
66
- meshConfig: typeof meshConfigBase
65
+ const meshConfigf = (await import(
66
+ '@graphcommerce/graphql-mesh/meshConfig.interceptor'
67
+ )) as unknown as {
68
+ default: {
69
+ meshConfig: typeof meshConfigBase
70
+ }
67
71
  }
68
- const conf = meshConfig(baseConf, graphCommerce)
72
+ const conf = meshConfigf.default.meshConfig(baseConf, graphCommerce)
69
73
 
70
74
  // We're configuring a custom fetch function
71
75
  conf.customFetch = '@graphcommerce/graphql-mesh/customFetch'
@@ -76,12 +80,12 @@ const main = async () => {
76
80
  conf.additionalResolvers = conf.additionalResolvers?.map((additionalResolver) => {
77
81
  if (typeof additionalResolver !== 'string') return additionalResolver
78
82
  if (additionalResolver.startsWith('@'))
79
- return path.relative(root, require.resolve(additionalResolver))
83
+ return path.relative(root, resolvePath(additionalResolver))
80
84
 
81
85
  return additionalResolver
82
86
  })
83
87
 
84
- type DefinedHandler = OmitIndexSignature<Handler>
88
+ type DefinedHandler = OmitIndexSignature<YamlConfig.Handler>
85
89
 
86
90
  conf.sources = conf.sources.map((source) => {
87
91
  const definedHandlers = Object.entries(source.handler) as Entries<DefinedHandler>
@@ -92,10 +96,7 @@ const main = async () => {
92
96
  if (key === 'openapi' && value) {
93
97
  const openapi = value as NonNullable<DefinedHandler['openapi']>
94
98
  if (openapi.source.startsWith('@')) {
95
- return [
96
- key,
97
- { ...openapi, source: path.relative(root, require.resolve(openapi.source)) },
98
- ]
99
+ return [key, { ...openapi, source: path.relative(root, resolvePath(openapi.source)) }]
99
100
  }
100
101
  }
101
102
 
@@ -111,7 +112,7 @@ const main = async () => {
111
112
  Array.isArray(conf.additionalTypeDefs) ? conf.additionalTypeDefs : [conf.additionalTypeDefs]
112
113
  ).map((additionalTypeDef) => {
113
114
  if (typeof additionalTypeDef === 'string' && additionalTypeDef.startsWith('@'))
114
- return path.relative(root, require.resolve(additionalTypeDef))
115
+ return path.relative(root, resolvePath(additionalTypeDef))
115
116
 
116
117
  return additionalTypeDef
117
118
  })
@@ -126,13 +127,24 @@ const main = async () => {
126
127
  const packages = [...deps.values()].filter((p) => p !== '.')
127
128
 
128
129
  const mV = graphCommerce.magentoVersion ?? 246
130
+ sig()
131
+
129
132
  packageRoots(packages).forEach((r) => {
130
- const alsoScan = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254]
133
+ conf.additionalTypeDefs.push(`${r}/*/schema/**/*.graphqls`)
134
+
135
+ const scanVersions = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254]
131
136
  .filter((v) => v > mV)
132
137
  .map((v) => `${r}/*/schema-${v}/**/*.graphqls`)
133
138
 
134
- conf.additionalTypeDefs.push(`${r}/*/schema/**/*.graphqls`)
135
- conf.additionalTypeDefs.push(...alsoScan)
139
+ conf.additionalTypeDefs.push(...scanVersions)
140
+
141
+ if (globalThis.gcl?.includes(atob('QGdyYXBoY29tbWVyY2UvYWRvYmUtY29tbWVyY2U='))) {
142
+ conf.additionalTypeDefs.push(`${r}/*/schema-ac/**/*.graphqls`)
143
+ const scanVersionAC = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254]
144
+ .filter((v) => v > mV)
145
+ .map((v) => `${r}/*/schema-ac-${v}/**/*.graphqls`)
146
+ conf.additionalTypeDefs.push(...scanVersionAC)
147
+ }
136
148
  })
137
149
 
138
150
  if (!conf.serve) conf.serve = {}
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
- import path from 'path'
3
- import { ConfigProcessOptions } from '@graphql-mesh/config'
4
- import { defaultImportFn, loadYaml, DefaultLogger } from '@graphql-mesh/utils'
2
+ import type { ConfigProcessOptions } from '@graphql-mesh/config'
3
+ import { DefaultLogger, defaultImportFn, loadYaml } from '@graphql-mesh/utils'
5
4
  import { cosmiconfig, defaultLoaders } from 'cosmiconfig'
5
+ import path from 'path'
6
6
 
7
7
  function customLoader(
8
8
  ext: 'json' | 'yaml' | 'js',
package/tsconfig.json CHANGED
@@ -15,6 +15,8 @@
15
15
  "outDir": "dist",
16
16
  "sourceMap": false,
17
17
  "noLib": false,
18
- "strict": true
18
+ "strict": true,
19
+ "moduleResolution": "Bundler",
20
+ "module": "ESNext"
19
21
  }
20
22
  }
package/dist/index.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,71 +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.findConfig = findConfig;
7
- /* eslint-disable import/no-extraneous-dependencies */
8
- const path_1 = __importDefault(require("path"));
9
- const utils_1 = require("@graphql-mesh/utils");
10
- const cosmiconfig_1 = require("cosmiconfig");
11
- function customLoader(ext, importFn = utils_1.defaultImportFn, initialLoggerPrefix = '🕸️ Mesh') {
12
- const logger = new utils_1.DefaultLogger(initialLoggerPrefix).child('config');
13
- // eslint-disable-next-line consistent-return
14
- function loader(filepath, content) {
15
- if (process.env) {
16
- // eslint-disable-next-line no-param-reassign
17
- content = content.replace(/\$\{(.*?)\}/g, (_, variable) => {
18
- let varName = variable;
19
- let defaultValue = '';
20
- if (variable.includes(':')) {
21
- const spl = variable.split(':');
22
- varName = spl.shift();
23
- defaultValue = spl.join(':');
24
- }
25
- return process.env[varName] || defaultValue;
26
- });
27
- }
28
- if (ext === 'json') {
29
- return cosmiconfig_1.defaultLoaders['.json'](filepath, content);
30
- }
31
- if (ext === 'yaml') {
32
- return (0, utils_1.loadYaml)(filepath, content, logger);
33
- }
34
- if (ext === 'js') {
35
- return importFn(filepath);
36
- }
37
- }
38
- return loader;
39
- }
40
- async function findConfig(options) {
41
- const { configName = 'mesh', dir: configDir = '', initialLoggerPrefix } = options || {};
42
- const dir = path_1.default.isAbsolute(configDir) ? configDir : path_1.default.join(process.cwd(), configDir);
43
- const explorer = (0, cosmiconfig_1.cosmiconfig)(configName, {
44
- searchPlaces: [
45
- 'package.json',
46
- `.${configName}rc`,
47
- `.${configName}rc.json`,
48
- `.${configName}rc.yaml`,
49
- `.${configName}rc.yml`,
50
- `.${configName}rc.js`,
51
- `.${configName}rc.ts`,
52
- `.${configName}rc.cjs`,
53
- `${configName}.config.js`,
54
- `${configName}.config.cjs`,
55
- ],
56
- loaders: {
57
- '.json': customLoader('json', options?.importFn, initialLoggerPrefix),
58
- '.yaml': customLoader('yaml', options?.importFn, initialLoggerPrefix),
59
- '.yml': customLoader('yaml', options?.importFn, initialLoggerPrefix),
60
- '.js': customLoader('js', options?.importFn, initialLoggerPrefix),
61
- '.ts': customLoader('js', options?.importFn, initialLoggerPrefix),
62
- noExt: customLoader('yaml', options?.importFn, initialLoggerPrefix),
63
- },
64
- });
65
- const results = await explorer.search(dir);
66
- if (!results) {
67
- throw new Error(`No ${configName} config file found in "${dir}"!`);
68
- }
69
- const { config } = results;
70
- return config;
71
- }