diff --git a/.changeset/silent-toes-hope.md b/.changeset/silent-toes-hope.md new file mode 100644 index 00000000000..906ccb4f39d --- /dev/null +++ b/.changeset/silent-toes-hope.md @@ -0,0 +1,7 @@ +--- +'@graphcommerce/magento-graphcms': patch +'@graphcommerce/next-config': patch +'@graphcommerce/cli': patch +--- + +Fixes for Windows installation diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 00000000000..5157f9b91cb --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,16 @@ +name: windows-build +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] +jobs: + windows-build: + runs-on: windows-2022 + if: github.event.pull_request.draft == false + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + cache: yarn + node-version: 18 + - run: yarn install && yarn postinstall + - run: yarn --cwd examples\magento-graphcms build diff --git a/examples/magento-graphcms/package.json b/examples/magento-graphcms/package.json index 8e17a855658..c6551c92c75 100644 --- a/examples/magento-graphcms/package.json +++ b/examples/magento-graphcms/package.json @@ -9,14 +9,14 @@ "node": "16.x.x||18.x.x||20.x.x" }, "scripts": { - "dev": "concurrently -k -n codegen,next 'graphql-codegen -w' 'next dev'", + "dev": "concurrently -k -n codegen,next \"graphql-codegen -w\" \"next dev\"", "codegen": "graphcommerce codegen-config && mesh build && graphql-codegen", "build": "graphcommerce codegen-config && mesh build && graphql-codegen && next build && next-sitemap", "start": "next start", "tsc:lint": "tsc --noEmit -p .", "lingui": "cross-env NODE_ENV=development lingui extract --clean", - "postinstall": "is-monorepo '[pkgrun] postinstall' '[pkgrun] patch-package'", - "create-patch": "patch-package --exclude 'package.json$|gql.ts$|interceptor.tsx$'" + "postinstall": "is-monorepo \"[pkgrun] postinstall\" \"[pkgrun] patch-package\"", + "create-patch": "patch-package --exclude \"package.json$|gql.ts$|interceptor.tsx$\"" }, "dependencies": { "@apollo/client": "~3.8.7", diff --git a/packages/cli/dist/bin/codegen.js b/packages/cli/dist/bin/codegen.js index 9ebe7d614f0..16ec787b3c2 100755 --- a/packages/cli/dist/bin/codegen.js +++ b/packages/cli/dist/bin/codegen.js @@ -62,7 +62,7 @@ async function main() { }); const isWatching = process.argv.includes('--watch') || process.argv.includes('-w'); if (!isWatching && extension) - await (0, rimraf_1.rimraf)(node_path_1.default.join(root, `**/*${extension}`)); + await (0, rimraf_1.rimraf)(node_path_1.default.join(root, `**/*${extension}`), { glob: true }); // - Prepend the all targets with ../../ if we're running in a monorepo setup. // - Append all the Graphcommerce packages to the configuration conf.config.generates = Object.fromEntries(generates.map(([generateTarget, generateConf]) => [ diff --git a/packages/cli/dist/bin/mesh.js b/packages/cli/dist/bin/mesh.js index c20dc5761d8..a58daae337f 100755 --- a/packages/cli/dist/bin/mesh.js +++ b/packages/cli/dist/bin/mesh.js @@ -26,7 +26,7 @@ function handleFatalError(e, logger = new utils_1.DefaultLogger('◈')) { exports.handleFatalError = handleFatalError; const root = process.cwd(); const meshDir = node_path_1.default.dirname(require.resolve('@graphcommerce/graphql-mesh')); -const relativePath = node_path_1.default.join(node_path_1.default.relative(meshDir, root), '/'); +const relativePath = node_path_1.default.join(node_path_1.default.relative(meshDir, root), node_path_1.default.sep); const cliParams = { ...cli_1.DEFAULT_CLI_PARAMS, playgroundTitle: 'GraphCommerce® Mesh', @@ -69,11 +69,11 @@ const main = async () => { return additionalTypeDef; }); // Scan the current working directory to also read all graphqls files. - conf.additionalTypeDefs.push('**/*.graphqls'); + conf.additionalTypeDefs.push(node_path_1.default.join('**', '*.graphqls')); const deps = (0, next_config_1.resolveDependenciesSync)(); const packages = [...deps.values()].filter((p) => p !== '.'); (0, next_config_1.packageRoots)(packages).forEach((r) => { - conf.additionalTypeDefs.push(`${r}/**/*.graphqls`); + conf.additionalTypeDefs.push(node_path_1.default.join(r, '**', '*.graphqls')); }); if (!conf.serve) conf.serve = {}; @@ -90,7 +90,7 @@ const main = async () => { const yamlString = (0, next_config_1.replaceConfigInString)(yaml_1.default.stringify(conf), (0, next_config_1.loadConfig)(root)); await node_fs_1.promises.writeFile(tmpMeshLocation, yamlString); // Reexport the mesh to is can be used by packages - await node_fs_1.promises.writeFile(`${meshDir}/.mesh.ts`, `export * from '${relativePath.split(node_path_1.default.sep).join('/')}.mesh'`, { encoding: 'utf8' }); + await node_fs_1.promises.writeFile(node_path_1.default.join(meshDir, '.mesh.ts'), `export * from '${relativePath.split(node_path_1.default.sep).join('/')}.mesh'`, { encoding: 'utf8' }); await (0, cli_1.graphqlMesh)({ ...cliParams, configName: tmpMesh }); await cleanup(); }; diff --git a/packages/cli/src/bin/codegen.ts b/packages/cli/src/bin/codegen.ts index cbbbeb6afe3..2d3d560f612 100755 --- a/packages/cli/src/bin/codegen.ts +++ b/packages/cli/src/bin/codegen.ts @@ -71,7 +71,7 @@ async function main() { }) const isWatching = process.argv.includes('--watch') || process.argv.includes('-w') - if (!isWatching && extension) await rimraf(path.join(root, `**/*${extension}`)) + if (!isWatching && extension) await rimraf(path.join(root, `**/*${extension}`), { glob: true }) // - Prepend the all targets with ../../ if we're running in a monorepo setup. // - Append all the Graphcommerce packages to the configuration diff --git a/packages/cli/src/bin/mesh.ts b/packages/cli/src/bin/mesh.ts index af4d2faf670..f90c8e9ecef 100755 --- a/packages/cli/src/bin/mesh.ts +++ b/packages/cli/src/bin/mesh.ts @@ -28,7 +28,7 @@ export function handleFatalError(e: Error, logger: Logger = new DefaultLogger(' const root = process.cwd() const meshDir = path.dirname(require.resolve('@graphcommerce/graphql-mesh')) -const relativePath = path.join(path.relative(meshDir, root), '/') +const relativePath = path.join(path.relative(meshDir, root), path.sep) const cliParams: GraphQLMeshCLIParams = { ...DEFAULT_CLI_PARAMS, @@ -79,12 +79,12 @@ const main = async () => { }) // Scan the current working directory to also read all graphqls files. - conf.additionalTypeDefs.push('**/*.graphqls') + conf.additionalTypeDefs.push(path.join('**', '*.graphqls')) const deps = resolveDependenciesSync() const packages = [...deps.values()].filter((p) => p !== '.') packageRoots(packages).forEach((r) => { - conf.additionalTypeDefs.push(`${r}/**/*.graphqls`) + conf.additionalTypeDefs.push(path.join(r, '**', '*.graphqls')) }) if (!conf.serve) conf.serve = {} @@ -104,7 +104,7 @@ const main = async () => { // Reexport the mesh to is can be used by packages await fs.writeFile( - `${meshDir}/.mesh.ts`, + path.join(meshDir, '.mesh.ts'), `export * from '${relativePath.split(path.sep).join('/')}.mesh'`, { encoding: 'utf8' }, ) diff --git a/packages/hygraph-cli/dist/migrations/index.js b/packages/hygraph-cli/dist/migrations/index.js index 2ca36a87ca6..359a8699ab2 100644 --- a/packages/hygraph-cli/dist/migrations/index.js +++ b/packages/hygraph-cli/dist/migrations/index.js @@ -16,4 +16,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { Object.defineProperty(exports, "__esModule", { value: true }); __exportStar(require("./graphcommerce5to6"), exports); __exportStar(require("./graphcommerce6to7"), exports); -__exportStar(require("./graphcommerce7to7.1"), exports); diff --git a/packagesDev/next-config/dist/interceptors/findPlugins.js b/packagesDev/next-config/dist/interceptors/findPlugins.js index 279360f7347..ed19bfb8556 100644 --- a/packagesDev/next-config/dist/interceptors/findPlugins.js +++ b/packagesDev/next-config/dist/interceptors/findPlugins.js @@ -48,7 +48,10 @@ function findPlugins(config, cwd = process.cwd()) { if (!result) return; const pluginConfig = { - plugin: file.replace(dependency, path).replace('.tsx', '').replace('.ts', ''), + plugin: file + .replace(dependency.replace(/\\/g, '/'), path) + .replace('.tsx', '') + .replace('.ts', ''), ...result, enabled: !result.ifConfig || Boolean((0, get_1.default)(config, result.ifConfig)), }; diff --git a/packagesDev/next-config/dist/interceptors/generateInterceptors.js b/packagesDev/next-config/dist/interceptors/generateInterceptors.js index 3b406aebd79..87ef6bff46c 100644 --- a/packagesDev/next-config/dist/interceptors/generateInterceptors.js +++ b/packagesDev/next-config/dist/interceptors/generateInterceptors.js @@ -159,7 +159,9 @@ function generateInterceptors(plugins, resolve, config) { let pluginPathFromResolved = plugin; if (plugin.startsWith('.')) { const resolvedPlugin = resolve(plugin); - pluginPathFromResolved = node_path_1.default.relative(resolved.fromRoot.split('/').slice(0, -1).join('/'), resolvedPlugin.fromRoot); + pluginPathFromResolved = node_path_1.default + .relative(resolved.fromRoot.split('/').slice(0, -1).join('/'), resolvedPlugin.fromRoot) + .replace(/\\/g, '/'); } if (!acc[resolved.fromRoot]) acc[resolved.fromRoot] = { diff --git a/packagesDev/next-config/dist/interceptors/writeInterceptors.js b/packagesDev/next-config/dist/interceptors/writeInterceptors.js index d626ff4a642..d5755a33e24 100644 --- a/packagesDev/next-config/dist/interceptors/writeInterceptors.js +++ b/packagesDev/next-config/dist/interceptors/writeInterceptors.js @@ -17,7 +17,7 @@ function writeInterceptors(interceptors, cwd = process.cwd()) { existing.push(...files); }); Object.entries(interceptors).forEach(([, plugin]) => { - const relativeFile = `${plugin.fromRoot}.interceptor.tsx`; + const relativeFile = `${plugin.fromRoot.replace(/\\/g, '/')}.interceptor.tsx`; if (existing.includes(relativeFile)) { delete existing[existing.indexOf(relativeFile)]; } diff --git a/packagesDev/next-config/src/interceptors/findPlugins.ts b/packagesDev/next-config/src/interceptors/findPlugins.ts index eace59cde24..f158ae4432f 100644 --- a/packagesDev/next-config/src/interceptors/findPlugins.ts +++ b/packagesDev/next-config/src/interceptors/findPlugins.ts @@ -64,7 +64,10 @@ export function findPlugins(config: GraphCommerceConfig, cwd: string = process.c if (!result) return const pluginConfig = { - plugin: file.replace(dependency, path).replace('.tsx', '').replace('.ts', ''), + plugin: file + .replace(dependency.replace(/\\/g, '/'), path) + .replace('.tsx', '') + .replace('.ts', ''), ...result, enabled: !result.ifConfig || Boolean(get(config, result.ifConfig)), } @@ -93,16 +96,19 @@ export function findPlugins(config: GraphCommerceConfig, cwd: string = process.c }) if (process.env.NODE_ENV === 'development' && debug) { - const byExported = plugins.reduce((acc, plugin) => { - const componentStr = isReactPluginConfig(plugin) ? plugin.component : '' - const funcStr = isMethodPluginConfig(plugin) ? plugin.func : '' - const key = `🔌 ${chalk.greenBright( - `Plugins loaded for ${plugin.exported}#${componentStr}${funcStr}`, - )}` - if (!acc[key]) acc[key] = [] - acc[key].push(plugin) - return acc - }, {} as Record[]>) + const byExported = plugins.reduce( + (acc, plugin) => { + const componentStr = isReactPluginConfig(plugin) ? plugin.component : '' + const funcStr = isMethodPluginConfig(plugin) ? plugin.func : '' + const key = `🔌 ${chalk.greenBright( + `Plugins loaded for ${plugin.exported}#${componentStr}${funcStr}`, + )}` + if (!acc[key]) acc[key] = [] + acc[key].push(plugin) + return acc + }, + {} as Record[]>, + ) const toLog: string[] = [] Object.entries(byExported).forEach(([key, p]) => { diff --git a/packagesDev/next-config/src/interceptors/generateInterceptors.ts b/packagesDev/next-config/src/interceptors/generateInterceptors.ts index 6100026dd40..ed9459040f3 100644 --- a/packagesDev/next-config/src/interceptors/generateInterceptors.ts +++ b/packagesDev/next-config/src/interceptors/generateInterceptors.ts @@ -200,51 +200,53 @@ export function generateInterceptors( config?: GraphCommerceDebugConfig | null | undefined, ): GenerateInterceptorsReturn { // todo: Do not use reduce as we're passing the accumulator to the next iteration - const byExportedComponent = moveRelativeDown(plugins).reduce((acc, plug) => { - const { exported, plugin } = plug - if (!isPluginConfig(plug) || !plug.enabled) return acc - - const resolved = resolve(exported) - - let pluginPathFromResolved = plugin - if (plugin.startsWith('.')) { - const resolvedPlugin = resolve(plugin) - pluginPathFromResolved = path.relative( - resolved.fromRoot.split('/').slice(0, -1).join('/'), - resolvedPlugin.fromRoot, - ) - } - - if (!acc[resolved.fromRoot]) - acc[resolved.fromRoot] = { - ...resolved, - target: `${resolved.fromRoot}.interceptor`, - components: {}, - funcs: {}, - } as Interceptor - - if (isReactPluginConfig(plug)) { - const { component } = plug - if (!acc[resolved.fromRoot].components[component]) - acc[resolved.fromRoot].components[component] = [] - - acc[resolved.fromRoot].components[component].push({ - ...plug, - plugin: pluginPathFromResolved, - }) - } - if (isMethodPluginConfig(plug)) { - const { func } = plug - if (!acc[resolved.fromRoot].funcs[func]) acc[resolved.fromRoot].funcs[func] = [] - - acc[resolved.fromRoot].funcs[func].push({ - ...plug, - plugin: pluginPathFromResolved, - }) - } - - return acc - }, {} as Record) + const byExportedComponent = moveRelativeDown(plugins).reduce( + (acc, plug) => { + const { exported, plugin } = plug + if (!isPluginConfig(plug) || !plug.enabled) return acc + + const resolved = resolve(exported) + + let pluginPathFromResolved = plugin + if (plugin.startsWith('.')) { + const resolvedPlugin = resolve(plugin) + pluginPathFromResolved = path + .relative(resolved.fromRoot.split('/').slice(0, -1).join('/'), resolvedPlugin.fromRoot) + .replace(/\\/g, '/') + } + + if (!acc[resolved.fromRoot]) + acc[resolved.fromRoot] = { + ...resolved, + target: `${resolved.fromRoot}.interceptor`, + components: {}, + funcs: {}, + } as Interceptor + + if (isReactPluginConfig(plug)) { + const { component } = plug + if (!acc[resolved.fromRoot].components[component]) + acc[resolved.fromRoot].components[component] = [] + + acc[resolved.fromRoot].components[component].push({ + ...plug, + plugin: pluginPathFromResolved, + }) + } + if (isMethodPluginConfig(plug)) { + const { func } = plug + if (!acc[resolved.fromRoot].funcs[func]) acc[resolved.fromRoot].funcs[func] = [] + + acc[resolved.fromRoot].funcs[func].push({ + ...plug, + plugin: pluginPathFromResolved, + }) + } + + return acc + }, + {} as Record, + ) return Object.fromEntries( Object.entries(byExportedComponent).map(([target, interceptor]) => [ diff --git a/packagesDev/next-config/src/interceptors/writeInterceptors.ts b/packagesDev/next-config/src/interceptors/writeInterceptors.ts index 94f488e217c..be616db25ce 100644 --- a/packagesDev/next-config/src/interceptors/writeInterceptors.ts +++ b/packagesDev/next-config/src/interceptors/writeInterceptors.ts @@ -17,7 +17,7 @@ export function writeInterceptors( }) Object.entries(interceptors).forEach(([, plugin]) => { - const relativeFile = `${plugin.fromRoot}.interceptor.tsx` + const relativeFile = `${plugin.fromRoot.replace(/\\/g, '/')}.interceptor.tsx` if (existing.includes(relativeFile)) { delete existing[existing.indexOf(relativeFile)]