Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/silent-toes-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphcommerce/magento-graphcms': patch
'@graphcommerce/next-config': patch
'@graphcommerce/cli': patch
---

Fixes for Windows installation
16 changes: 16 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions examples/magento-graphcms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/dist/bin/codegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => [
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/dist/bin/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 = {};
Expand All @@ -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();
};
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/bin/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/bin/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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' },
)
Expand Down
1 change: 0 additions & 1 deletion packages/hygraph-cli/dist/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 4 additions & 1 deletion packagesDev/next-config/dist/interceptors/findPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}
Expand Down
28 changes: 17 additions & 11 deletions packagesDev/next-config/src/interceptors/findPlugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
}
Expand Down Expand Up @@ -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<string, Pick<PluginConfig, 'plugin' | 'ifConfig' | 'enabled'>[]>)
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<string, Pick<PluginConfig, 'plugin' | 'ifConfig' | 'enabled'>[]>,
)

const toLog: string[] = []
Object.entries(byExported).forEach(([key, p]) => {
Expand Down
92 changes: 47 additions & 45 deletions packagesDev/next-config/src/interceptors/generateInterceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Interceptor>)
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<string, Interceptor>,
)

return Object.fromEntries(
Object.entries(byExportedComponent).map(([target, interceptor]) => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down