Skip to content

Commit

Permalink
Fix routes manifest location when using pnpm (#2963)
Browse files Browse the repository at this point in the history
(patch)
  • Loading branch information
beerose authored Nov 17, 2021
1 parent 522da1a commit 4f868ad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 31 deletions.
3 changes: 3 additions & 0 deletions nextjs/packages/next/build/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ async function findNodeModulesRoot(src: string) {
)
}
root = join(nextPkgLocation, '../')
if (root.endsWith('@blitzjs/')) {
root = join(nextPkgLocation, '../../')
}
}
manifestDebug('root ' + root)
return root
Expand Down
43 changes: 42 additions & 1 deletion packages/blitz/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {promisify} = require("util")
const fs = require("fs")
const path = require("path")
const resolveFrom = require("resolve-from")
const findUp = require("find-up")

const copyFile = promisify(fs.copyFile)
const mkdir = promisify(fs.mkdir)
Expand All @@ -21,6 +22,46 @@ try {
// noop
}

// todo: we should reuse `findNodeModulesRoot` from /nextjs/packages/next/build/routes.ts
async function findNodeModulesRoot(src) {
let root
if (process.env.NEXT_PNPM_TEST) {
const nextPkgLocation = path.dirname(
(await findUp("package.json", {
cwd: resolveFrom(src, "next"),
})) ?? "",
)
if (!nextPkgLocation) {
throw new Error("Internal Blitz Error: unable to find 'next' package location")
}
root = path.join(nextPkgLocation, "../")
} else if (isInBlitzMonorepo) {
root = path.join(src, "node_modules")
} else {
const blitzPkgLocation = path.dirname(
(await findUp("package.json", {
cwd: resolveFrom(src, "blitz"),
})) ?? "",
)
if (!blitzPkgLocation) {
throw new Error("Internal Blitz Error: unable to find 'blitz' package location")
}
const nextPkgLocation = path.dirname(
(await findUp("package.json", {
cwd: resolveFrom(blitzPkgLocation, "next"),
})) ?? "",
)
if (!nextPkgLocation) {
throw new Error("Internal Blitz Error: unable to find 'next' package location")
}
root = path.join(nextPkgLocation, "../")
if (root.endsWith("@blitzjs/")) {
root = path.join(nextPkgLocation, "../../")
}
}
return path.join(root, ".blitz")
}

const isUsingNpm =
process.env.npm_config_user_agent && process.env.npm_config_user_agent.startsWith("npm")

Expand Down Expand Up @@ -193,7 +234,7 @@ function codegen() {
try {
const dotBlitzDir = isInBlitzMonorepo
? path.join(process.cwd(), "node_modules/.blitz")
: path.join(__dirname, "../../.blitz")
: await findNodeModulesRoot(__dirname)

await makeDir(dotBlitzDir)
const defaultIndexJsPath = path.join(dotBlitzDir, "index.js")
Expand Down
31 changes: 1 addition & 30 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,6 @@
dependencies:
"@babel/types" "^7.12.13"

"@babel/helper-module-imports@^7.13.12":
version "7.13.12"
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.13.12.tgz#c6a369a6f3621cb25da014078684da9196b61977"
integrity sha512-4cVvR2/1B693IuOvSI20xqqa/+bl7lqAMR59R4iu39R9aOX8/JoYY1sFaNvUMyMBGnHdwvJgUrzNLoUZxXypxA==
dependencies:
"@babel/types" "^7.13.12"

"@babel/helper-module-imports@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/helper-module-imports/-/helper-module-imports-7.14.5.tgz#6d1a44df6a38c957aa7c312da076429f11b422f3"
Expand Down Expand Up @@ -562,11 +555,6 @@
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.12.11.tgz#c9a1f021917dcb5ccf0d4e453e399022981fc9ed"
integrity sha512-np/lG3uARFybkoHokJUmf1QfEvRVCPbmQeUQpKow5cQ3xWrV9i3rUHodKDJPQfTVX61qKi+UdYk8kik84n7XOw==

"@babel/helper-validator-identifier@^7.14.0":
version "7.14.0"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.0.tgz#d26cad8a47c65286b15df1547319a5d0bcf27288"
integrity sha512-V3ts7zMSu5lfiwWDVWzRDGIN+lnCEUdaXgtVHJgLb1rGaA6jMrtB9EmE7L18foXJIE8Un/A/h6NJfGQp/e1J4A==

"@babel/helper-validator-identifier@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.14.5.tgz#d0f0e277c512e0c938277faa85a3968c9a44c0e8"
Expand Down Expand Up @@ -1683,14 +1671,6 @@
"@babel/helper-validator-identifier" "^7.14.5"
to-fast-properties "^2.0.0"

"@babel/types@^7.13.12", "@babel/types@^7.13.17":
version "7.14.1"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.14.1.tgz#095bd12f1c08ab63eff6e8f7745fa7c9cc15a9db"
integrity sha512-S13Qe85fzLs3gYRUnrpyeIrBJIMYv33qSTg1qoBwiG6nPKwUWAD9odSzWhEedpwOIzSEI6gbdQIWEMiCI42iBA==
dependencies:
"@babel/helper-validator-identifier" "^7.14.0"
to-fast-properties "^2.0.0"

"@babel/types@^7.13.13":
version "7.13.14"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.13.14.tgz#c35a4abb15c7cd45a2746d78ab328e362cbace0d"
Expand Down Expand Up @@ -6795,15 +6775,6 @@ [email protected]:
babel-plugin-syntax-jsx "^6.18.0"
lodash "^4.17.11"

[email protected]:
version "0.3.0"
resolved "https://registry.yarnpkg.com/babel-plugin-superjson-next/-/babel-plugin-superjson-next-0.3.0.tgz#86620a2d134a1b0a515d903512cf7f766b394cc1"
integrity sha512-fTE8uWUy9OJG7PkRNP094XDdieoBsZR2iatxurbNqLyd4INXpwuuQ246iLu4+dAeQHtGhOJZxsPR8KdbNvdnlQ==
dependencies:
"@babel/helper-module-imports" "^7.13.12"
"@babel/types" "^7.13.17"
hoist-non-react-statics "^3.3.2"

babel-plugin-syntax-jsx@^6.18.0:
version "6.18.0"
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-jsx/-/babel-plugin-syntax-jsx-6.18.0.tgz#0af32a9a6e13ca7a3fd5069e62d7b0f58d0d8946"
Expand Down Expand Up @@ -12729,7 +12700,7 @@ hmac-drbg@^1.0.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.1"

hoist-non-react-statics@^3.0.0, hoist-non-react-statics@^3.3.2:
hoist-non-react-statics@^3.0.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==
Expand Down

0 comments on commit 4f868ad

Please sign in to comment.