Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add navigation entry point compatible with Next.js App Router #583

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion packages/next-drupal-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"deepmerge": "^4.3.1",
"drupal-jsonapi-params": "^2.3.1",
"next": "^12.2.3 || ^13",
"next": "^12.2.3 || ^13 || ^14",
"type-fest": "^2.19.0"
}
}
1 change: 1 addition & 0 deletions packages/next-drupal/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/coverage
/CHANGELOG.md
/postBuild.js
/tests
/tsconfig.json
30 changes: 28 additions & 2 deletions packages/next-drupal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,35 @@
"description": "Helpers for Next.js + Drupal.",
"version": "1.6.0",
"sideEffects": false,
"source": "src/index.ts",
"source": [
"src/index.ts",
"src/navigation.ts"
],
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.modern.js",
"exports": {
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.modern.js"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./navigation": {
"import": {
"types": "./dist/navigation.d.ts",
"default": "./dist/navigation.modern.js"
},
"require": {
"types": "./dist/navigation.d.cts",
"default": "./dist/navigation.cjs"
}
}
},
"types": "dist/index.d.ts",
"license": "MIT",
"publishConfig": {
Expand All @@ -18,6 +43,7 @@
},
"scripts": {
"prepare": "microbundle --no-compress --jsx React.createElement --format modern,cjs",
"postprepare": "node postBuild.js",
"dev": "microbundle watch --no-compress --jsx React.createElement --format modern,cjs",
"test": "jest"
},
Expand All @@ -42,7 +68,7 @@
},
"dependencies": {
"jsona": "^1.12.1",
"next": "^12.2.0 || ^13",
"next": "^12.2.0 || ^13 || ^14",
"node-cache": "^5.1.2",
"qs": "^6.11.2",
"react": "^17.0.2 || ^18",
Expand Down
22 changes: 22 additions & 0 deletions packages/next-drupal/postBuild.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { readdir, copyFile } from "node:fs/promises"

const files = await readdir("./dist")
const tasks = []
for (const file of files) {
if (file.endsWith(".modern.js")) {
const base = file.replace(/\.modern\.js$/, "")

// Make a duplicate of the type definitions.
//
// From the TypeScript docs:
//
// "It’s important to note that the CommonJS entrypoint and the ES module
// entrypoint each needs its own declaration file, even if the contents are
// the same between them."
//
// @see https://www.typescriptlang.org/docs/handbook/esm-node.html#packagejson-exports-imports-and-self-referencing
tasks.push(copyFile(`./dist/${base}.d.ts`, `./dist/${base}.d.cts`))
}
}
await Promise.all(tasks)
console.log(`Created unique *.d.cts files for CommonJS build.`)
2 changes: 1 addition & 1 deletion packages/next-drupal/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Jsona from "jsona"
import { Jsona } from "jsona"
import { stringify } from "qs"
import { JsonApiErrors } from "./jsonapi-errors"
import { logger as defaultLogger } from "./logger"
Expand Down
1 change: 0 additions & 1 deletion packages/next-drupal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from "./get-resource"
export * from "./get-search-index"
export * from "./get-view"
export * from "./types"
export * from "./use-menu"
export * from "./translate-path"
export {
deserialize,
Expand Down
1 change: 1 addition & 0 deletions packages/next-drupal/src/navigation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { useMenu } from "./navigation/use-menu"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useRouter } from "next/router"
import { useEffect, useState } from "react"
import { getMenu } from "./get-menu"
import type { DrupalMenuLinkContent } from "./types"
import { getMenu } from "../get-menu"
import type { DrupalMenuLinkContent } from "../types"

export function useMenu<T extends DrupalMenuLinkContent>(
name: string
Expand Down
2 changes: 1 addition & 1 deletion packages/next-drupal/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Jsona from "jsona"
import { Jsona } from "jsona"
import { stringify } from "qs"
import { getAccessToken } from "./get-access-token"
import type { GetStaticPropsContext } from "next"
Expand Down
2 changes: 1 addition & 1 deletion starters/basic-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@tailwindcss/typography": "^0.5.8",
"next": "^13",
"next": "^13 || ^14",
"next-drupal": "^1.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion starters/graphql-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@tailwindcss/typography": "^0.5.8",
"next": "^13",
"next": "^13 || ^14",
"next-drupal": "^1.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
108 changes: 54 additions & 54 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2548,10 +2548,10 @@
resolved "https://registry.yarnpkg.com/@next/env/-/env-12.3.4.tgz#c787837d36fcad75d72ff8df6b57482027d64a47"
integrity sha512-H/69Lc5Q02dq3o+dxxy5O/oNxFsZpdL6WREtOOtOM1B/weonIwDXkekr1KV5DPVPr12IHFPrMrcJQ6bgPMfn7A==

"@next/env@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/env/-/env-13.5.6.tgz#c1148e2e1aa166614f05161ee8f77ded467062bc"
integrity sha512-Yac/bV5sBGkkEXmAX5FWPS9Mmo2rthrOPRQQNfycJPkjUAUclomCPH7QFVCDQ4Mp2k2K1SSM6m0zrxYrOwtFQw==
"@next/env@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/env/-/env-14.0.3.tgz#9a58b296e7ae04ffebce8a4e5bd0f87f71de86bd"
integrity sha512-7xRqh9nMvP5xrW4/+L0jgRRX+HoNRGnfJpD+5Wq6/13j3dsdzxO3BCXn7D3hMqsDb+vjZnJq+vI7+EtgrYZTeA==

"@next/[email protected]", "@next/eslint-plugin-next@^12.3.4":
version "12.3.4"
Expand Down Expand Up @@ -2582,20 +2582,20 @@
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-12.3.4.tgz#14ac8357010c95e67327f47082af9c9d75d5be79"
integrity sha512-DqsSTd3FRjQUR6ao0E1e2OlOcrF5br+uegcEGPVonKYJpcr0MJrtYmPxd4v5T6UCJZ+XzydF7eQo5wdGvSZAyA==

"@next/swc-darwin-arm64@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.5.6.tgz#b15d139d8971360fca29be3bdd703c108c9a45fb"
integrity sha512-5nvXMzKtZfvcu4BhtV0KH1oGv4XEW+B+jOfmBdpFI3C7FrB/MfujRpWYSBBO64+qbW8pkZiSyQv9eiwnn5VIQA==
"@next/swc-darwin-arm64@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.0.3.tgz#b1a0440ffbf69056451947c4aea5b6d887e9fbbc"
integrity sha512-64JbSvi3nbbcEtyitNn2LEDS/hcleAFpHdykpcnrstITFlzFgB/bW0ER5/SJJwUPj+ZPY+z3e+1jAfcczRLVGw==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-12.3.4.tgz#e7dc63cd2ac26d15fb84d4d2997207fb9ba7da0f"
integrity sha512-PPF7tbWD4k0dJ2EcUSnOsaOJ5rhT3rlEt/3LhZUGiYNL8KvoqczFrETlUx0cUYaXe11dRA3F80Hpt727QIwByQ==

"@next/swc-darwin-x64@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.5.6.tgz#9c72ee31cc356cb65ce6860b658d807ff39f1578"
integrity sha512-6cgBfxg98oOCSr4BckWjLLgiVwlL3vlLj8hXg2b+nDgm4bC/qVXXLfpLB9FHdoDu4057hzywbxKvmYGmi7yUzA==
"@next/swc-darwin-x64@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-14.0.3.tgz#48b527ef7eb5dbdcaf62fd107bc3a78371f36f09"
integrity sha512-RkTf+KbAD0SgYdVn1XzqE/+sIxYGB7NLMZRn9I4Z24afrhUpVJx6L8hsRnIwxz3ERE2NFURNliPjJ2QNfnWicQ==

"@next/[email protected]":
version "12.3.4"
Expand All @@ -2612,70 +2612,70 @@
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-12.3.4.tgz#43a7bc409b03487bff5beb99479cacdc7bd29af5"
integrity sha512-kiX0vgJGMZVv+oo1QuObaYulXNvdH/IINmvdZnVzMO/jic/B8EEIGlZ8Bgvw8LCjH3zNVPO3mGrdMvnEEPEhKA==

"@next/swc-linux-arm64-gnu@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.5.6.tgz#59f5f66155e85380ffa26ee3d95b687a770cfeab"
integrity sha512-txagBbj1e1w47YQjcKgSU4rRVQ7uF29YpnlHV5xuVUsgCUf2FmyfJ3CPjZUvpIeXCJAoMCFAoGnbtX86BK7+sg==
"@next/swc-linux-arm64-gnu@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.0.3.tgz#0a36475a38b2855ab8ea0fe8b56899bc90184c0f"
integrity sha512-3tBWGgz7M9RKLO6sPWC6c4pAw4geujSwQ7q7Si4d6bo0l6cLs4tmO+lnSwFp1Tm3lxwfMk0SgkJT7EdwYSJvcg==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-12.3.4.tgz#4d1db6de6dc982b974cd1c52937111e3e4a34bd3"
integrity sha512-EETZPa1juczrKLWk5okoW2hv7D7WvonU+Cf2CgsSoxgsYbUCZ1voOpL4JZTOb6IbKMDo6ja+SbY0vzXZBUMvkQ==

"@next/swc-linux-arm64-musl@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.5.6.tgz#f012518228017052736a87d69bae73e587c76ce2"
integrity sha512-cGd+H8amifT86ZldVJtAKDxUqeFyLWW+v2NlBULnLAdWsiuuN8TuhVBt8ZNpCqcAuoruoSWynvMWixTFcroq+Q==
"@next/swc-linux-arm64-musl@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.0.3.tgz#25328a9f55baa09fde6364e7e47ade65c655034f"
integrity sha512-v0v8Kb8j8T23jvVUWZeA2D8+izWspeyeDGNaT2/mTHWp7+37fiNfL8bmBWiOmeumXkacM/AB0XOUQvEbncSnHA==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-12.3.4.tgz#c3b414d77bab08b35f7dd8943d5586f0adb15e38"
integrity sha512-4csPbRbfZbuWOk3ATyWcvVFdD9/Rsdq5YHKvRuEni68OCLkfy4f+4I9OBpyK1SKJ00Cih16NJbHE+k+ljPPpag==

"@next/swc-linux-x64-gnu@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.5.6.tgz#339b867a7e9e7ee727a700b496b269033d820df4"
integrity sha512-Mc2b4xiIWKXIhBy2NBTwOxGD3nHLmq4keFk+d4/WL5fMsB8XdJRdtUlL87SqVCTSaf1BRuQQf1HvXZcy+rq3Nw==
"@next/swc-linux-x64-gnu@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.0.3.tgz#594b747e3c8896b2da67bba54fcf8a6b5a410e5e"
integrity sha512-VM1aE1tJKLBwMGtyBR21yy+STfl0MapMQnNrXkxeyLs0GFv/kZqXS5Jw/TQ3TSUnbv0QPDf/X8sDXuMtSgG6eg==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-12.3.4.tgz#187a883ec09eb2442a5ebf126826e19037313c61"
integrity sha512-YeBmI+63Ro75SUiL/QXEVXQ19T++58aI/IINOyhpsRL1LKdyfK/35iilraZEFz9bLQrwy1LYAR5lK200A9Gjbg==

"@next/swc-linux-x64-musl@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.5.6.tgz#ae0ae84d058df758675830bcf70ca1846f1028f2"
integrity sha512-CFHvP9Qz98NruJiUnCe61O6GveKKHpJLloXbDSWRhqhkJdZD2zU5hG+gtVJR//tyW897izuHpM6Gtf6+sNgJPQ==
"@next/swc-linux-x64-musl@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.0.3.tgz#a02da58fc6ecad8cf5c5a2a96a7f6030ec7f6215"
integrity sha512-64EnmKy18MYFL5CzLaSuUn561hbO1Gk16jM/KHznYP3iCIfF9e3yULtHaMy0D8zbHfxset9LTOv6cuYKJgcOxg==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-12.3.4.tgz#89befa84e453ed2ef9a888f375eba565a0fde80b"
integrity sha512-Sd0qFUJv8Tj0PukAYbCCDbmXcMkbIuhnTeHm9m4ZGjCf6kt7E/RMs55Pd3R5ePjOkN7dJEuxYBehawTR/aPDSQ==

"@next/swc-win32-arm64-msvc@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.5.6.tgz#a5cc0c16920485a929a17495064671374fdbc661"
integrity sha512-aFv1ejfkbS7PUa1qVPwzDHjQWQtknzAZWGTKYIAaS4NMtBlk3VyA6AYn593pqNanlicewqyl2jUhQAaFV/qXsg==
"@next/swc-win32-arm64-msvc@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.0.3.tgz#bf2be23d3ba2ebd0d4a9376a31f783efdb677b48"
integrity sha512-WRDp8QrmsL1bbGtsh5GqQ/KWulmrnMBgbnb+59qNTW1kVi1nG/2ndZLkcbs2GX7NpFLlToLRMWSQXmPzQm4tog==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-12.3.4.tgz#cb50c08f0e40ead63642a7f269f0c8254261f17c"
integrity sha512-rt/vv/vg/ZGGkrkKcuJ0LyliRdbskQU+91bje+PgoYmxTZf/tYs6IfbmgudBJk6gH3QnjHWbkphDdRQrseRefQ==

"@next/swc-win32-ia32-msvc@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.5.6.tgz#6a2409b84a2cbf34bf92fe714896455efb4191e4"
integrity sha512-XqqpHgEIlBHvzwG8sp/JXMFkLAfGLqkbVsyN+/Ih1mR8INb6YCc2x/Mbwi6hsAgUnqQztz8cvEbHJUbSl7RHDg==
"@next/swc-win32-ia32-msvc@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.0.3.tgz#839f8de85a4bf2c3c69242483ab87cb916427551"
integrity sha512-EKffQeqCrj+t6qFFhIFTRoqb2QwX1mU7iTOvMyLbYw3QtqTw9sMwjykyiMlZlrfm2a4fA84+/aeW+PMg1MjuTg==

"@next/[email protected]":
version "12.3.4"
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.3.4.tgz#d28ea15a72cdcf96201c60a43e9630cd7fda168f"
integrity sha512-DQ20JEfTBZAgF8QCjYfJhv2/279M6onxFjdG/+5B0Cyj00/EdBxiWb2eGGFgQhrBbNv/lsvzFbbi0Ptf8Vw/bg==

"@next/swc-win32-x64-msvc@13.5.6":
version "13.5.6"
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.5.6.tgz#4a3e2a206251abc729339ba85f60bc0433c2865d"
integrity sha512-Cqfe1YmOS7k+5mGu92nl5ULkzpKuxJrP3+4AEuPmrpFZ3BHxTY3TnHmU1On3bFmFFs6FbTcdF58CCUProGpIGQ==
"@next/swc-win32-x64-msvc@14.0.3":
version "14.0.3"
resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.0.3.tgz#27b623612b1d0cea6efe0a0d31aa1a335fc99647"
integrity sha512-ERhKPSJ1vQrPiwrs15Pjz/rvDHZmkmvbf/BjPN/UCOI++ODftT0GtasDPi0j+y6PPJi5HsXw+dpRaXUaw4vjuQ==

"@nicolo-ribaudo/[email protected]":
version "5.1.1-v1"
Expand Down Expand Up @@ -10413,28 +10413,28 @@ next-seo@^4.23.0:
resolved "https://registry.yarnpkg.com/next-seo/-/next-seo-4.29.0.tgz#d281e95ba47914117cc99e9e468599f0547d9b9b"
integrity sha512-xmwzcz4uHaYJ8glbuhs6FSBQ7z3irmdPYdJJ5saWm72Uy3o+mPKGaPCXQetTCE6/xxVnpoDV4yFtFlEjUcljSg==

"next@^12.2.0 || ^13", "next@^12.2.3 || ^13", next@^13:
version "13.5.6"
resolved "https://registry.yarnpkg.com/next/-/next-13.5.6.tgz#e964b5853272236c37ce0dd2c68302973cf010b1"
integrity sha512-Y2wTcTbO4WwEsVb4A8VSnOsG1I9ok+h74q0ZdxkwM3EODqrs4pasq7O0iUxbcS9VtWMicG7f3+HAj0r1+NtKSw==
"next@^12.2.0 || ^13 || ^14", "next@^12.2.3 || ^13 || ^14", "next@^13 || ^14":
version "14.0.3"
resolved "https://registry.yarnpkg.com/next/-/next-14.0.3.tgz#8d801a08eaefe5974203d71092fccc463103a03f"
integrity sha512-AbYdRNfImBr3XGtvnwOxq8ekVCwbFTv/UJoLwmaX89nk9i051AEY4/HAWzU0YpaTDw8IofUpmuIlvzWF13jxIw==
dependencies:
"@next/env" "13.5.6"
"@next/env" "14.0.3"
"@swc/helpers" "0.5.2"
busboy "1.6.0"
caniuse-lite "^1.0.30001406"
postcss "8.4.31"
styled-jsx "5.1.1"
watchpack "2.4.0"
optionalDependencies:
"@next/swc-darwin-arm64" "13.5.6"
"@next/swc-darwin-x64" "13.5.6"
"@next/swc-linux-arm64-gnu" "13.5.6"
"@next/swc-linux-arm64-musl" "13.5.6"
"@next/swc-linux-x64-gnu" "13.5.6"
"@next/swc-linux-x64-musl" "13.5.6"
"@next/swc-win32-arm64-msvc" "13.5.6"
"@next/swc-win32-ia32-msvc" "13.5.6"
"@next/swc-win32-x64-msvc" "13.5.6"
"@next/swc-darwin-arm64" "14.0.3"
"@next/swc-darwin-x64" "14.0.3"
"@next/swc-linux-arm64-gnu" "14.0.3"
"@next/swc-linux-arm64-musl" "14.0.3"
"@next/swc-linux-x64-gnu" "14.0.3"
"@next/swc-linux-x64-musl" "14.0.3"
"@next/swc-win32-arm64-msvc" "14.0.3"
"@next/swc-win32-ia32-msvc" "14.0.3"
"@next/swc-win32-x64-msvc" "14.0.3"

next@^12.2.3:
version "12.3.4"
Expand Down