diff --git a/.changeset/sweet-kiwis-cross.md b/.changeset/sweet-kiwis-cross.md new file mode 100644 index 0000000000..a17ff30daf --- /dev/null +++ b/.changeset/sweet-kiwis-cross.md @@ -0,0 +1,5 @@ +--- +"@blitzjs/rpc": patch +--- + +Fix queries/mutations lookup on Windows diff --git a/apps/toolkit-app/package.json b/apps/toolkit-app/package.json index 759eb5ccf8..713abc5ef3 100644 --- a/apps/toolkit-app/package.json +++ b/apps/toolkit-app/package.json @@ -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", diff --git a/packages/blitz-rpc/src/index-server.ts b/packages/blitz-rpc/src/index-server.ts index 37192b7130..81f80eea16 100644 --- a/packages/blitz-rpc/src/index-server.ts +++ b/packages/blitz-rpc/src/index-server.ts @@ -80,7 +80,7 @@ export function installWebpackConfig({ webpackRuleOptions, }: InstallWebpackConfigOptions) { webpackConfig.module.rules.push({ - test: /\/\[\[\.\.\.blitz]]\.[jt]s$/, + test: /[\\/]\[\[\.\.\.blitz]]\.[jt]sx?$/, use: [ { loader: loaderServer, @@ -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) } diff --git a/packages/blitz-rpc/src/loader-server.ts b/packages/blitz-rpc/src/loader-server.ts index 7637aab862..4a38735ad2 100644 --- a/packages/blitz-rpc/src/loader-server.ts +++ b/packages/blitz-rpc/src/loader-server.ts @@ -1,4 +1,4 @@ -import {dirname, join, posix} from "path" +import {dirname, join, posix, relative} from "path" import {promises} from "fs" import { assertPosixPath, @@ -37,6 +37,10 @@ export async function loader(this: Loader, input: string): Promise { module.exports = loader +function slash(str: string) { + return str.replace(/\\/g, "/") +} + export async function transformBlitzRpcServer( src: string, id: string, @@ -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" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 669fe21dd5..0bd5468ad3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,7 +49,7 @@ importers: "@types/preview-email": 2.0.1 "@types/react": 18.0.1 "@typescript-eslint/eslint-plugin": 5.9.1 - blitz: workspace:2.0.0-alpha.55 + blitz: workspace:2.0.0-alpha.56 eslint: 7.32.0 eslint-config-next: 12.2.0 eslint-config-prettier: 8.5.0 @@ -324,7 +324,7 @@ importers: "@vitejs/plugin-react": 1.3.0 delay: 5.0.0 eslint: 7.32.0 - eslint-config-next: 12.2.2_hrkuebk64jiu2ut2d2sm4oylnu + eslint-config-next: 12.2.3_hrkuebk64jiu2ut2d2sm4oylnu eslint-plugin-testing-library: 5.0.1_hrkuebk64jiu2ut2d2sm4oylnu jsdom: 19.0.0 typescript: 4.6.3 @@ -475,8 +475,8 @@ importers: packages/blitz: specifiers: - "@blitzjs/config": workspace:2.0.0-alpha.55 - "@blitzjs/generator": 2.0.0-alpha.55 + "@blitzjs/config": workspace:2.0.0-alpha.56 + "@blitzjs/generator": 2.0.0-alpha.56 "@types/cookie": 0.4.1 "@types/cross-spawn": 6.0.2 "@types/debug": 4.1.7 @@ -584,7 +584,7 @@ importers: packages/blitz-auth: specifiers: - "@blitzjs/config": workspace:2.0.0-alpha.55 + "@blitzjs/config": workspace:2.0.0-alpha.56 "@testing-library/react": 13.0.0 "@testing-library/react-hooks": 7.0.2 "@types/b64-lite": 1.3.0 @@ -598,7 +598,7 @@ importers: "@types/secure-password": 3.1.1 b64-lite: 1.4.0 bad-behavior: 1.0.1 - blitz: 2.0.0-alpha.55 + blitz: 2.0.0-alpha.56 cookie: 0.4.1 cookie-session: 2.0.0 debug: 4.3.3 @@ -649,8 +649,8 @@ importers: packages/blitz-next: specifiers: - "@blitzjs/config": workspace:2.0.0-alpha.55 - "@blitzjs/rpc": 2.0.0-alpha.55 + "@blitzjs/config": workspace:2.0.0-alpha.56 + "@blitzjs/rpc": 2.0.0-alpha.56 "@testing-library/dom": 8.13.0 "@testing-library/jest-dom": 5.16.3 "@testing-library/react": 13.0.0 @@ -661,7 +661,7 @@ importers: "@types/react": 18.0.1 "@types/react-dom": 17.0.14 "@types/testing-library__react-hooks": 4.0.0 - blitz: 2.0.0-alpha.55 + blitz: 2.0.0-alpha.56 cross-spawn: 7.0.3 debug: 4.3.3 find-up: 4.1.0 @@ -710,14 +710,14 @@ importers: packages/blitz-rpc: specifiers: - "@blitzjs/auth": 2.0.0-alpha.55 - "@blitzjs/config": workspace:2.0.0-alpha.55 + "@blitzjs/auth": 2.0.0-alpha.56 + "@blitzjs/config": workspace:2.0.0-alpha.56 "@types/debug": 4.1.7 "@types/react": 18.0.1 "@types/react-dom": 17.0.14 b64-lite: 1.4.0 bad-behavior: 1.0.1 - blitz: 2.0.0-alpha.55 + blitz: 2.0.0-alpha.56 chalk: ^4.1.0 debug: 4.3.3 next: 12.2.0 @@ -759,12 +759,12 @@ importers: "@babel/plugin-syntax-typescript": 7.17.12 "@babel/preset-env": 7.12.10 "@blitzjs/config": workspace:* - "@blitzjs/generator": 2.0.0-alpha.55 + "@blitzjs/generator": 2.0.0-alpha.56 "@types/jscodeshift": 0.11.2 "@types/node": 17.0.16 arg: 5.0.1 ast-types: 0.14.2 - blitz: 2.0.0-alpha.55 + blitz: 2.0.0-alpha.56 chalk: ^4.1.0 cross-spawn: 7.0.3 debug: 4.3.3 @@ -819,7 +819,7 @@ importers: "@babel/plugin-transform-typescript": 7.12.1 "@babel/preset-env": 7.12.10 "@babel/types": 7.12.10 - "@blitzjs/config": 2.0.0-alpha.55 + "@blitzjs/config": 2.0.0-alpha.56 "@juanm04/cpx": 2.0.1 "@mrleebo/prisma-ast": 0.2.6 "@types/babel__core": 7.1.19 @@ -910,7 +910,7 @@ importers: packages/pkg-template: specifiers: - "@blitzjs/config": 2.0.0-alpha.55 + "@blitzjs/config": 2.0.0-alpha.56 "@types/react": 18.0.1 "@types/react-dom": 17.0.14 "@typescript-eslint/eslint-plugin": 5.9.1 @@ -3451,10 +3451,10 @@ packages: dependencies: glob: 7.1.7 - /@next/eslint-plugin-next/12.2.2: + /@next/eslint-plugin-next/12.2.3: resolution: { - integrity: sha512-XOi0WzJhGH3Lk51SkSu9eZxF+IY1ZZhWcJTIGBycAbWU877IQa6+6KxMATWCOs7c+bmp6Sd8KywXJaDRxzu0JA==, + integrity: sha512-B2e8Yg1MpuLsGxhCx4rU8/Tcnr5wFmCx1O2eyLXBPnaCcsFXfGCo067ujagtDLtWASL3GNgzg78U1SB0dbc38A==, } dependencies: glob: 7.1.7 @@ -8444,10 +8444,10 @@ packages: - supports-color dev: false - /eslint-config-next/12.2.2_hrkuebk64jiu2ut2d2sm4oylnu: + /eslint-config-next/12.2.3_hrkuebk64jiu2ut2d2sm4oylnu: resolution: { - integrity: sha512-oJhWBLC4wDYYUFv/5APbjHUFd0QRFCojMdj/QnMoOEktmeTvwnnoA8F8uaXs0fQgsaTK0tbUxBRv9/Y4/rpxOA==, + integrity: sha512-xAQqAqwa2bu9ZMRypz58ym4tNCo22Wc6LuoLpbpf3yW5c4ZkVib9934AgGDDvh2zKrP56Z6X0Pp6gNnuuZzcRw==, } peerDependencies: eslint: ^7.23.0 || ^8.0.0 @@ -8456,7 +8456,7 @@ packages: typescript: optional: true dependencies: - "@next/eslint-plugin-next": 12.2.2 + "@next/eslint-plugin-next": 12.2.3 "@rushstack/eslint-patch": 1.1.3 "@typescript-eslint/parser": 5.28.0_hrkuebk64jiu2ut2d2sm4oylnu eslint: 7.32.0