Skip to content

Commit

Permalink
Fix queries/mutations lookup on Windows (#3581)
Browse files Browse the repository at this point in the history
  • Loading branch information
beerose authored Jul 22, 2022
1 parent 57a53fa commit 716e188
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .changeset/sweet-kiwis-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/rpc": patch
---

Fix queries/mutations lookup on Windows
2 changes: 1 addition & 1 deletion apps/toolkit-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "toolkit-app",
"version": "1.0.1-alpha.16",
"scripts": {
"start:dev": "pnpm run prisma:start && next dev",
"start:dev": "pnpm run prisma:start && blitz dev",
"buildapp": "NODE_ENV=production pnpm blitz codegen && pnpm prisma generate && next build",
"start": "next start",
"lint": "next lint",
Expand Down
6 changes: 3 additions & 3 deletions packages/blitz-rpc/src/index-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function installWebpackConfig({
webpackRuleOptions,
}: InstallWebpackConfigOptions) {
webpackConfig.module.rules.push({
test: /\/\[\[\.\.\.blitz]]\.[jt]s$/,
test: /[\\/]\[\[\.\.\.blitz]]\.[jt]sx?$/,
use: [
{
loader: loaderServer,
Expand Down Expand Up @@ -146,10 +146,10 @@ export function rpcHandler(config: RpcConfig) {
"It seems your Blitz RPC endpoint file is not named [[...blitz]].(jt)s. Please ensure it is",
)

const relativeRoutePath = req.query.blitz.join("/")
const relativeRoutePath = (req.query.blitz as string[])?.join("/")
const routePath = "/" + relativeRoutePath

const loadableResolver = resolverMap[routePath]
const loadableResolver = resolverMap?.[routePath]
if (!loadableResolver) {
throw new Error("No resolver for path: " + routePath)
}
Expand Down
8 changes: 6 additions & 2 deletions packages/blitz-rpc/src/loader-server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {dirname, join, posix} from "path"
import {dirname, join, posix, relative} from "path"
import {promises} from "fs"
import {
assertPosixPath,
Expand Down Expand Up @@ -37,6 +37,10 @@ export async function loader(this: Loader, input: string): Promise<string> {

module.exports = loader

function slash(str: string) {
return str.replace(/\\/g, "/")
}

export async function transformBlitzRpcServer(
src: string,
id: string,
Expand All @@ -54,7 +58,7 @@ export async function transformBlitzRpcServer(
code += "\n\n"

for (let resolverFilePath of resolvers) {
const relativeResolverPath = posix.relative(dirname(id), join(root, resolverFilePath))
const relativeResolverPath = slash(relative(dirname(id), join(root, resolverFilePath)))
const routePath = convertPageFilePathToRoutePath(resolverFilePath, options?.resolverPath)
code += `__internal_addBlitzRpcResolver('${routePath}', () => import('${relativeResolverPath}'));`
code += "\n"
Expand Down
42 changes: 21 additions & 21 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 716e188

Please sign in to comment.