From efc7bbb699fada93979b0d75aa5f6d2a54acb2ad Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Wed, 25 Aug 2021 15:59:13 -0400 Subject: [PATCH 01/13] add deps to cli package --- packages/cli/package.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/cli/package.json b/packages/cli/package.json index c6cb48cae8..9a62700ae8 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -24,6 +24,8 @@ "dependencies": { "@blitzjs/display": "0.40.0-canary.5", "@blitzjs/repl": "0.40.0-canary.5", + "@blitzjs/generator": "0.40.0-canary.5", + "@blitzjs/server": "0.40.0-canary.5", "@oclif/command": "1.8.0", "@oclif/config": "1.17.0", "@oclif/plugin-autocomplete": "0.3.0", From dd1377355924ccfb35b4685bd553baf093456b80 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Wed, 25 Aug 2021 16:37:15 -0400 Subject: [PATCH 02/13] some tests --- nextjs/packages/next/build/routes.ts | 2 +- nextjs/packages/next/package.json | 6 +++++- packages/blitz/src/index.ts | 1 + packages/cli/package.json | 6 ++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index 1e60c4ba42..7a2d596381 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -224,7 +224,7 @@ export function generateManifest( '\n}', declaration: ` import type { ParsedUrlQueryInput } from "querystring" -import type { RouteUrlObject } from "next/types" +import type { RouteUrlObject } from "blitz" export const Routes: { ${declarationLines.map((line) => ' ' + line).join(';\n') + declarationEnding} diff --git a/nextjs/packages/next/package.json b/nextjs/packages/next/package.json index 31108e135a..d67bc753e0 100644 --- a/nextjs/packages/next/package.json +++ b/nextjs/packages/next/package.json @@ -138,7 +138,8 @@ "peerDependencies": { "fibers": ">= 3.1.0", "node-sass": "^4.0.0 || ^5.0.0", - "sass": "^1.3.0" + "sass": "^1.3.0", + "secure-password": "*" }, "peerDependenciesMeta": { "node-sass": { @@ -147,6 +148,9 @@ "sass": { "optional": true }, + "secure-password": { + "optional": true + }, "fibers": { "optional": true } diff --git a/packages/blitz/src/index.ts b/packages/blitz/src/index.ts index f684d7e0d6..b748f3f67e 100644 --- a/packages/blitz/src/index.ts +++ b/packages/blitz/src/index.ts @@ -72,4 +72,5 @@ export type { RedirectAuthenticatedTo, RedirectAuthenticatedToFnCtx, RedirectAuthenticatedToFn, + RouteUrlObject, } from "next/types" diff --git a/packages/cli/package.json b/packages/cli/package.json index 9a62700ae8..41efa788a0 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -23,8 +23,9 @@ ], "dependencies": { "@blitzjs/display": "0.40.0-canary.5", - "@blitzjs/repl": "0.40.0-canary.5", "@blitzjs/generator": "0.40.0-canary.5", + "@blitzjs/installer": "0.40.0-canary.5", + "@blitzjs/repl": "0.40.0-canary.5", "@blitzjs/server": "0.40.0-canary.5", "@oclif/command": "1.8.0", "@oclif/config": "1.17.0", @@ -58,9 +59,6 @@ "v8-compile-cache": "2.2.0" }, "devDependencies": { - "@blitzjs/generator": "0.40.0-canary.5", - "@blitzjs/installer": "0.40.0-canary.5", - "@blitzjs/server": "0.40.0-canary.5", "@oclif/dev-cli": "1.26.0", "@oclif/test": "1.2.8", "nock": "13.0.6", From 477e38912e431588d62d37b970fced7045dfe617 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Wed, 25 Aug 2021 16:41:46 -0400 Subject: [PATCH 03/13] bump From 5752111bef8b2bb122a6f4814c5c83a40b2b0c37 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Wed, 25 Aug 2021 18:37:24 -0400 Subject: [PATCH 04/13] try to fix prisma and .blitz --- nextjs/packages/next/build/routes.ts | 52 ++++++++++++++++---------- nextjs/packages/next/package.json | 7 +--- packages/cli/package.json | 1 - packages/cli/src/commands/prisma.ts | 7 +--- packages/generator/templates/app/npmrc | 3 ++ yarn.lock | 24 +++--------- 6 files changed, 44 insertions(+), 50 deletions(-) diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index 7a2d596381..c2c0fb455a 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -4,9 +4,12 @@ import { createPagesMapping } from './entries' import { collectPages, getIsRpcFile } from './utils' import { isInternalDevelopment } from '../server/utils' import { join } from 'path' -import { existsSync, outputFile } from 'fs-extra' -import { baseLogger } from '../server/lib/logging' +// import { existsSync, outputFile } from 'fs-extra' +import { outputFile } from 'fs-extra' +// import { baseLogger } from '../server/lib/logging' +import resolveFrom from 'resolve-from' const readFile = promises.readFile +const manifestDebug = require('debug')('blitz:manifest') export type RouteType = 'page' | 'rpc' | 'api' export type RouteVerb = 'get' | 'post' | 'patch' | 'head' | 'delete' | '*' @@ -130,24 +133,33 @@ export async function saveRouteManifest( } function findNodeModulesRoot(src: string) { - const log = baseLogger() - let nodeModules = join(src, 'node_modules') - let includesBlitzPackage = existsSync(join(nodeModules, 'blitz')) - let count = 0 - while (!includesBlitzPackage) { - // Check for node_modules at the next level up - nodeModules = join(nodeModules, '../../node_modules') - includesBlitzPackage = existsSync(join(nodeModules, 'blitz')) - count++ - if (count > 5) { - log.warn( - "We couldn't determine your actual node_modules location, so defaulting to normal location" - ) - nodeModules = join(src, 'node_modules') - break - } - } - return nodeModules + manifestDebug('src ' + src) + const blitzPkgLocation = resolveFrom(src, 'blitz') + manifestDebug('blitzPkgLocation ' + blitzPkgLocation) + const blitzCorePkgLocation = resolveFrom(blitzPkgLocation, '@blitzjs/core') + manifestDebug('blitzCorePkgLocation ' + blitzCorePkgLocation) + const root = join(blitzCorePkgLocation, '../../') + manifestDebug('root ' + root) + return root + + // const log = baseLogger() + // let nodeModules = join(src, 'node_modules') + // let includesBlitzPackage = existsSync(join(nodeModules, 'blitz')) + // let count = 0 + // while (!includesBlitzPackage) { + // // Check for node_modules at the next level up + // nodeModules = join(nodeModules, '../../node_modules') + // includesBlitzPackage = existsSync(join(nodeModules, 'blitz')) + // count++ + // if (count > 5) { + // log.warn( + // "We couldn't determine your actual node_modules location, so defaulting to normal location" + // ) + // nodeModules = join(src, 'node_modules') + // break + // } + // } + // return nodeModules } export function parseDefaultExportName(contents: string): string | null { diff --git a/nextjs/packages/next/package.json b/nextjs/packages/next/package.json index d67bc753e0..f3b5838b0e 100644 --- a/nextjs/packages/next/package.json +++ b/nextjs/packages/next/package.json @@ -121,6 +121,7 @@ "react-is": "17.0.2", "react-query": "3.16.0", "react-refresh": "0.8.3", + "resolve-from": "5.0.0", "secure-password": "4.0.0", "stream-browserify": "3.0.0", "stream-http": "3.1.1", @@ -138,8 +139,7 @@ "peerDependencies": { "fibers": ">= 3.1.0", "node-sass": "^4.0.0 || ^5.0.0", - "sass": "^1.3.0", - "secure-password": "*" + "sass": "^1.3.0" }, "peerDependenciesMeta": { "node-sass": { @@ -148,9 +148,6 @@ "sass": { "optional": true }, - "secure-password": { - "optional": true - }, "fibers": { "optional": true } diff --git a/packages/cli/package.json b/packages/cli/package.json index 41efa788a0..7ee3a6f709 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -46,7 +46,6 @@ "got": "^11.8.1", "has-yarn": "2.1.0", "hasbin": "1.2.3", - "import-cwd": "3.0.0", "minimist": "1.2.5", "p-event": "4.2.0", "pkg-dir": "^5.0.0", diff --git a/packages/cli/src/commands/prisma.ts b/packages/cli/src/commands/prisma.ts index 84a7869535..69f52ad6ce 100644 --- a/packages/cli/src/commands/prisma.ts +++ b/packages/cli/src/commands/prisma.ts @@ -1,15 +1,12 @@ import {Command} from "@oclif/command" -// @blitzjs/server imports react, so we must import the @blitzjs/server version of the -// local app instead of the global. -// import-cwd is required so this works correctly during new app generation const getPrismaBin = async () => { let bin: any try { - bin = require("import-cwd")("@blitzjs/server").resolveBinAsync("prisma", "prisma") + bin = require("@blitzjs/server").resolveBinAsync("prisma", "prisma") } catch { // legacy compatability - bin = require("import-cwd")("@blitzjs/server").resolveBinAsync("@prisma/cli", "prisma") + bin = require("@blitzjs/server").resolveBinAsync("@prisma/cli", "prisma") } return bin } diff --git a/packages/generator/templates/app/npmrc b/packages/generator/templates/app/npmrc index 1b78f1c6f2..5e9b201649 100644 --- a/packages/generator/templates/app/npmrc +++ b/packages/generator/templates/app/npmrc @@ -1,2 +1,5 @@ save-exact=true legacy-peer-deps=true + +public-hoist-pattern[]=next +public-hoist-pattern[]=secure-password diff --git a/yarn.lock b/yarn.lock index 1a56c27115..d05333d78f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12625,13 +12625,6 @@ immediate@~3.0.5: resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b" integrity sha1-nbHb0Pr43m++D13V5Wu2BigN5ps= -import-cwd@3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-3.0.0.tgz#20845547718015126ea9b3676b7592fb8bd4cf92" - integrity sha512-4pnzH16plW+hgvRECbDWpQl3cqtvSofHWh44met7ESfZ8UZOWWddm8hEyDTqREJ9RbYHY8gi8DqmaelApoOGMg== - dependencies: - import-from "^3.0.0" - import-cwd@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9" @@ -12662,13 +12655,6 @@ import-from@^2.1.0: dependencies: resolve-from "^3.0.0" -import-from@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/import-from/-/import-from-3.0.0.tgz#055cfec38cd5a27d8057ca51376d7d3bf0891966" - integrity sha512-CiuXOFFSzkU5x/CR0+z7T91Iht4CXgfCxVOFRhh2Zyhg5wOpWvvDLQUsWl+gcN+QscYBjez8hDCt85O7RLDttQ== - dependencies: - resolve-from "^5.0.0" - import-lazy@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43" @@ -20340,6 +20326,11 @@ resolve-dir@^1.0.0, resolve-dir@^1.0.1: expand-tilde "^2.0.0" global-modules "^1.0.0" +resolve-from@5.0.0, resolve-from@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" + integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== + resolve-from@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748" @@ -20350,11 +20341,6 @@ resolve-from@^4.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== -resolve-from@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" - integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== - resolve-pkg@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/resolve-pkg/-/resolve-pkg-2.0.0.tgz#ac06991418a7623edc119084edc98b0e6bf05a41" From 29e3ec74419b6827c3f54dcebffc888b87b83891 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Wed, 25 Aug 2021 18:56:35 -0400 Subject: [PATCH 05/13] another try for .blitz --- nextjs/packages/next/build/routes.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index c2c0fb455a..99b9bd229c 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -7,6 +7,7 @@ import { join } from 'path' // import { existsSync, outputFile } from 'fs-extra' import { outputFile } from 'fs-extra' // import { baseLogger } from '../server/lib/logging' +import findUp from 'next/dist/compiled/find-up' import resolveFrom from 'resolve-from' const readFile = promises.readFile const manifestDebug = require('debug')('blitz:manifest') @@ -119,7 +120,7 @@ export async function saveRouteManifest( const { declaration, implementation } = generateManifest(routes) - const dotBlitz = join(findNodeModulesRoot(directory), '.blitz') + const dotBlitz = join(await findNodeModulesRoot(directory), '.blitz') await outputFile(join(dotBlitz, 'index.js'), implementation, { encoding: 'utf-8', @@ -132,12 +133,26 @@ export async function saveRouteManifest( }) } -function findNodeModulesRoot(src: string) { +async function findNodeModulesRoot(src: string) { manifestDebug('src ' + src) - const blitzPkgLocation = resolveFrom(src, 'blitz') + const blitzPkgLocation = await findUp('package.json', { + cwd: resolveFrom(src, 'blitz'), + }) manifestDebug('blitzPkgLocation ' + blitzPkgLocation) - const blitzCorePkgLocation = resolveFrom(blitzPkgLocation, '@blitzjs/core') + if (!blitzPkgLocation) { + throw new Error( + "Internal Blitz Error: unable to find 'blitz' package location" + ) + } + const blitzCorePkgLocation = await findUp('package.json', { + cwd: resolveFrom(blitzPkgLocation, '@blitzjs/core'), + }) manifestDebug('blitzCorePkgLocation ' + blitzCorePkgLocation) + if (!blitzCorePkgLocation) { + throw new Error( + "Internal Blitz Error: unable to find '@blitzjs/core' package location" + ) + } const root = join(blitzCorePkgLocation, '../../') manifestDebug('root ' + root) return root From 938f70881b79c14f89c5146bbc906022ba7fa973 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 26 Aug 2021 16:07:01 -0400 Subject: [PATCH 06/13] more fix --- nextjs/packages/next/build/routes.ts | 18 +++++++++++------- .../app/auth/mutations/forgotPassword.test.ts | 2 +- packages/generator/templates/app/npmrc | 2 ++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index 99b9bd229c..3244568b40 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -3,7 +3,7 @@ import { NextConfigComplete } from '../server/config-shared' import { createPagesMapping } from './entries' import { collectPages, getIsRpcFile } from './utils' import { isInternalDevelopment } from '../server/utils' -import { join } from 'path' +import { join, dirname } from 'path' // import { existsSync, outputFile } from 'fs-extra' import { outputFile } from 'fs-extra' // import { baseLogger } from '../server/lib/logging' @@ -135,18 +135,22 @@ export async function saveRouteManifest( async function findNodeModulesRoot(src: string) { manifestDebug('src ' + src) - const blitzPkgLocation = await findUp('package.json', { - cwd: resolveFrom(src, 'blitz'), - }) + const blitzPkgLocation = dirname( + (await findUp('package.json', { + cwd: resolveFrom(src, 'blitz'), + })) ?? '' + ) manifestDebug('blitzPkgLocation ' + blitzPkgLocation) if (!blitzPkgLocation) { throw new Error( "Internal Blitz Error: unable to find 'blitz' package location" ) } - const blitzCorePkgLocation = await findUp('package.json', { - cwd: resolveFrom(blitzPkgLocation, '@blitzjs/core'), - }) + const blitzCorePkgLocation = dirname( + (await findUp('package.json', { + cwd: resolveFrom(blitzPkgLocation, '@blitzjs/core'), + })) ?? '' + ) manifestDebug('blitzCorePkgLocation ' + blitzCorePkgLocation) if (!blitzCorePkgLocation) { throw new Error( diff --git a/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts b/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts index 4d1e4f2e27..20cc73e98e 100644 --- a/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts +++ b/packages/generator/templates/app/app/auth/mutations/forgotPassword.test.ts @@ -9,7 +9,7 @@ beforeEach(async () => { const generatedToken = "plain-token" jest.mock("blitz", () => ({ - ...jest.requireActual("blitz")!, + ...jest.requireActual>("blitz")!, generateToken: () => generatedToken, })) jest.mock("preview-email", () => jest.fn()) diff --git a/packages/generator/templates/app/npmrc b/packages/generator/templates/app/npmrc index 5e9b201649..f7777f0b8c 100644 --- a/packages/generator/templates/app/npmrc +++ b/packages/generator/templates/app/npmrc @@ -3,3 +3,5 @@ legacy-peer-deps=true public-hoist-pattern[]=next public-hoist-pattern[]=secure-password +public-hoist-pattern[]=*jest* +public-hoist-pattern[]=@testing-library/* From f7dc866f46a467ea011102434ea0fb3be1027225 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 26 Aug 2021 16:11:37 -0400 Subject: [PATCH 07/13] bump From 0a8df2b8a470d3193eb27bf2b84be0d6f542ae2a Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 26 Aug 2021 18:01:53 -0400 Subject: [PATCH 08/13] debug logging --- packages/server/src/next-utils.ts | 4 ++++ packages/server/src/resolve-bin-async.ts | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/server/src/next-utils.ts b/packages/server/src/next-utils.ts index add400b40b..132f587e8f 100644 --- a/packages/server/src/next-utils.ts +++ b/packages/server/src/next-utils.ts @@ -9,6 +9,7 @@ import {newline} from "next/dist/server/lib/logging" import path from "path" import pkgDir from "pkg-dir" import {ServerConfig} from "./config" +const debug = require("debug")("blitz:utils") function getSpawnEnv(config: ServerConfig) { let spawnEnv: NodeJS.ProcessEnv = process.env @@ -49,6 +50,9 @@ export async function nextStartDev( process.env.BLITZ_DEV_SERVER_ORIGIN = `http://localhost:${availablePort}` + debug("cwd ", cwd) + debug("spawn ", nextBin, spawnCommand) + return new Promise((res, rej) => { if (config.port && availablePort !== config.port) { log.error(`Couldn't start server on port ${config.port} because it's already in use`) diff --git a/packages/server/src/resolve-bin-async.ts b/packages/server/src/resolve-bin-async.ts index 56af62971b..ce7bd9dfb6 100644 --- a/packages/server/src/resolve-bin-async.ts +++ b/packages/server/src/resolve-bin-async.ts @@ -2,6 +2,7 @@ import {readJSON} from "fs-extra" import path from "path" import pkgDir from "pkg-dir" import resolveCwd from "resolve-cwd" +const debug = require("debug")("blitz:utils") export async function resolveBinAsync(pkg: string, executable = pkg) { const packageDir = await pkgDir(resolveCwd(pkg)) @@ -11,6 +12,10 @@ export async function resolveBinAsync(pkg: string, executable = pkg) { const binPath = typeof bin === "object" ? bin[executable] : bin if (!binPath) throw new Error(`No bin '${executable}' in module '${pkg}'`) + debug("binPath: " + binPath) - return path.join(packageDir, binPath) + const fullPath = path.join(packageDir, binPath) + debug("fullPath: " + fullPath) + + return fullPath } From 9744386a1f22bb5c92b2614d8768265aef7c7c9f Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 26 Aug 2021 18:11:32 -0400 Subject: [PATCH 09/13] cleanup --- nextjs/packages/next/build/routes.ts | 29 ++++++++-------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index 3244568b40..a121d0e803 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -4,9 +4,7 @@ import { createPagesMapping } from './entries' import { collectPages, getIsRpcFile } from './utils' import { isInternalDevelopment } from '../server/utils' import { join, dirname } from 'path' -// import { existsSync, outputFile } from 'fs-extra' import { outputFile } from 'fs-extra' -// import { baseLogger } from '../server/lib/logging' import findUp from 'next/dist/compiled/find-up' import resolveFrom from 'resolve-from' const readFile = promises.readFile @@ -134,6 +132,14 @@ export async function saveRouteManifest( } async function findNodeModulesRoot(src: string) { + /* + * Because of our package structure, and because of how things like pnpm link modules, + * we must first find blitz package, and then find @blitzjs/core and then + * the root of @blitzjs/core + * + * This is because we import from `.blitz` inside @blitzjs/core. + * If that changes, then this logic here will need to change + */ manifestDebug('src ' + src) const blitzPkgLocation = dirname( (await findUp('package.json', { @@ -160,25 +166,6 @@ async function findNodeModulesRoot(src: string) { const root = join(blitzCorePkgLocation, '../../') manifestDebug('root ' + root) return root - - // const log = baseLogger() - // let nodeModules = join(src, 'node_modules') - // let includesBlitzPackage = existsSync(join(nodeModules, 'blitz')) - // let count = 0 - // while (!includesBlitzPackage) { - // // Check for node_modules at the next level up - // nodeModules = join(nodeModules, '../../node_modules') - // includesBlitzPackage = existsSync(join(nodeModules, 'blitz')) - // count++ - // if (count > 5) { - // log.warn( - // "We couldn't determine your actual node_modules location, so defaulting to normal location" - // ) - // nodeModules = join(src, 'node_modules') - // break - // } - // } - // return nodeModules } export function parseDefaultExportName(contents: string): string | null { From 6e5194eb08460cd3999b52d2ec14dee259d273e6 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 26 Aug 2021 18:16:12 -0400 Subject: [PATCH 10/13] fix lint --- nextjs/packages/next/package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nextjs/packages/next/package.json b/nextjs/packages/next/package.json index f3b5838b0e..e0cafc75b9 100644 --- a/nextjs/packages/next/package.json +++ b/nextjs/packages/next/package.json @@ -121,7 +121,7 @@ "react-is": "17.0.2", "react-query": "3.16.0", "react-refresh": "0.8.3", - "resolve-from": "5.0.0", + "resolve-from": "^5.0.0", "secure-password": "4.0.0", "stream-browserify": "3.0.0", "stream-http": "3.1.1", diff --git a/yarn.lock b/yarn.lock index d05333d78f..692a75de45 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20326,11 +20326,6 @@ resolve-dir@^1.0.0, resolve-dir@^1.0.1: expand-tilde "^2.0.0" global-modules "^1.0.0" -resolve-from@5.0.0, resolve-from@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" - integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== - resolve-from@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748" @@ -20341,6 +20336,11 @@ resolve-from@^4.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== +resolve-from@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" + integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== + resolve-pkg@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/resolve-pkg/-/resolve-pkg-2.0.0.tgz#ac06991418a7623edc119084edc98b0e6bf05a41" From 8eb8e5c3d6acc51eccdde5efd96caf8639625518 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Thu, 26 Aug 2021 18:23:50 -0400 Subject: [PATCH 11/13] fix test --- nextjs/test/unit/route-import-manifest.unit.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nextjs/test/unit/route-import-manifest.unit.test.ts b/nextjs/test/unit/route-import-manifest.unit.test.ts index c37384c40c..c67b02ab00 100644 --- a/nextjs/test/unit/route-import-manifest.unit.test.ts +++ b/nextjs/test/unit/route-import-manifest.unit.test.ts @@ -63,7 +63,7 @@ exports.Routes = { `.trim(), declaration: ` import type { ParsedUrlQueryInput } from "querystring" -import type { RouteUrlObject } from "next/types" +import type { RouteUrlObject } from "blitz" export const Routes: { @@ -121,7 +121,7 @@ exports.Routes = { `.trim(), declaration: ` import type { ParsedUrlQueryInput } from "querystring" -import type { RouteUrlObject } from "next/types" +import type { RouteUrlObject } from "blitz" export const Routes: { Home(query?: ParsedUrlQueryInput): RouteUrlObject; From ee462365fbd176a47015beb1187f09b4609b6b12 Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Fri, 27 Aug 2021 11:13:02 -0400 Subject: [PATCH 12/13] fix pnpm test --- nextjs/packages/next/build/routes.ts | 60 ++++++++++++++-------- nextjs/test/package-managers/pnpm/app/.env | 1 + 2 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 nextjs/test/package-managers/pnpm/app/.env diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index a121d0e803..20fb9ec089 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -141,29 +141,45 @@ async function findNodeModulesRoot(src: string) { * If that changes, then this logic here will need to change */ manifestDebug('src ' + src) - const blitzPkgLocation = dirname( - (await findUp('package.json', { - cwd: resolveFrom(src, 'blitz'), - })) ?? '' - ) - manifestDebug('blitzPkgLocation ' + blitzPkgLocation) - if (!blitzPkgLocation) { - throw new Error( - "Internal Blitz Error: unable to find 'blitz' package location" + let root: string + if (process.env.NEXT_PNPM_TEST) { + const nextPkgLocation = dirname( + (await findUp('package.json', { + cwd: resolveFrom(src, 'next'), + })) ?? '' ) - } - const blitzCorePkgLocation = dirname( - (await findUp('package.json', { - cwd: resolveFrom(blitzPkgLocation, '@blitzjs/core'), - })) ?? '' - ) - manifestDebug('blitzCorePkgLocation ' + blitzCorePkgLocation) - if (!blitzCorePkgLocation) { - throw new Error( - "Internal Blitz Error: unable to find '@blitzjs/core' package location" + manifestDebug('nextPkgLocation ' + nextPkgLocation) + if (!nextPkgLocation) { + throw new Error( + "Internal Blitz Error: unable to find 'next' package location" + ) + } + root = join(nextPkgLocation, '../') + } else { + const blitzPkgLocation = dirname( + (await findUp('package.json', { + cwd: resolveFrom(src, 'blitz'), + })) ?? '' ) + manifestDebug('blitzPkgLocation ' + blitzPkgLocation) + if (!blitzPkgLocation) { + throw new Error( + "Internal Blitz Error: unable to find 'blitz' package location" + ) + } + const blitzCorePkgLocation = dirname( + (await findUp('package.json', { + cwd: resolveFrom(blitzPkgLocation, '@blitzjs/core'), + })) ?? '' + ) + manifestDebug('blitzCorePkgLocation ' + blitzCorePkgLocation) + if (!blitzCorePkgLocation) { + throw new Error( + "Internal Blitz Error: unable to find '@blitzjs/core' package location" + ) + } + root = join(blitzCorePkgLocation, '../../') } - const root = join(blitzCorePkgLocation, '../../') manifestDebug('root ' + root) return root } @@ -235,6 +251,8 @@ export function generateManifest( const declarationEnding = declarationLines.length > 0 ? ';' : '' + const moduleName = process.env.NEXT_PNPM_TEST ? 'next/types' : 'blitz' + return { implementation: 'exports.Routes = {\n' + @@ -242,7 +260,7 @@ export function generateManifest( '\n}', declaration: ` import type { ParsedUrlQueryInput } from "querystring" -import type { RouteUrlObject } from "blitz" +import type { RouteUrlObject } from "${moduleName}" export const Routes: { ${declarationLines.map((line) => ' ' + line).join(';\n') + declarationEnding} diff --git a/nextjs/test/package-managers/pnpm/app/.env b/nextjs/test/package-managers/pnpm/app/.env new file mode 100644 index 0000000000..fc0b91609a --- /dev/null +++ b/nextjs/test/package-managers/pnpm/app/.env @@ -0,0 +1 @@ +NEXT_PNPM_TEST="true" From 5a999ed7af0b8536ece0616e461cd65e5609d87a Mon Sep 17 00:00:00 2001 From: Brandon Bayer Date: Fri, 27 Aug 2021 11:20:03 -0400 Subject: [PATCH 13/13] fix example test --- nextjs/packages/next/build/routes.ts | 2 ++ packages/cli/src/commands/codegen.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/nextjs/packages/next/build/routes.ts b/nextjs/packages/next/build/routes.ts index 20fb9ec089..d0270f7704 100644 --- a/nextjs/packages/next/build/routes.ts +++ b/nextjs/packages/next/build/routes.ts @@ -155,6 +155,8 @@ async function findNodeModulesRoot(src: string) { ) } root = join(nextPkgLocation, '../') + } else if (isInternalDevelopment) { + root = join(src, 'node_modules') } else { const blitzPkgLocation = dirname( (await findUp('package.json', { diff --git a/packages/cli/src/commands/codegen.ts b/packages/cli/src/commands/codegen.ts index 99169e2717..f55f681ecc 100644 --- a/packages/cli/src/commands/codegen.ts +++ b/packages/cli/src/commands/codegen.ts @@ -1,3 +1,4 @@ +import {log} from "@blitzjs/display" import {Command, flags} from "@oclif/command" export class CodeGen extends Command { @@ -12,10 +13,12 @@ export class CodeGen extends Command { this.parse(CodeGen) try { + let spinner = log.spinner(`Generating route manifest`).start() const {loadConfigProduction} = await import("next/dist/server/config-shared") const {saveRouteManifest} = await import("next/dist/build/routes") const config = loadConfigProduction(process.cwd()) await saveRouteManifest(process.cwd(), config) + spinner.succeed() } catch (err) { console.error(err) process.exit(1)