Shared Next.js utility functions for ASL19 projects.
npm install @asl-19/next-utilsSee docs/README.md for API documentation.
The hooks import next/router.js. In a project’s Vitest tests, vi.mock("next/router") (or "next/router.js") doesn’t apply to them, since Vitest loads @asl-19/next-utils from node_modules without transforming it. Either:
-
Provide the router through Next’s
RouterContext, as the page would get it at runtime:import { RouterContext } from "next/dist/shared/lib/router-context.shared-runtime"; render( <RouterContext.Provider value={mockRouter}> <IndexPage /> </RouterContext.Provider>, );
-
Or have Vitest transform the package, so module mocks apply to it too:
// vitest.config.ts export default defineConfig({ test: { server: { deps: { inline: ["@asl-19/next-utils"] } }, }, });
useIndexPageLoadingAndQueryLogic only reads the router’s asPath, basePath, defaultLocale, locale and query (and marks the current history.state entry shallow), and useFocusH1OnRouteChangeComplete reads asPath and subscribes to events, so a mock router only needs those.
This package uses mise to manage the Node.js and pinact versions (see mise.toml). With mise activated in your shell:
# Install Node.js and pinact
mise installmise.toml only lists tools, so mise trusts it without mise trust. Keep it that way: adding [env], [hooks] or [tasks] would let it run code when you cd into the folder.
.npmrc and package.json (devEngines, allowScripts) configure npm supply-chain gates: a one-day release-age window, approved install scripts only, and registry-only dependencies. See AGENTS.md for details.
In this folder:
# Run tests in watch mode
npm test
# Build into dist
npm run build
# Install dependencies if needed, then type check, lint, check formatting,
# run tests, and lint package
npm run dev-lint-testIf you add a function or hook, or change the documentation comments or signature of an existing one, regenerate the API documentation (CI will fail if docs is out of date):
# Update docs/* (Markdown documentation generated by TypeDoc)
npm run docsTo check for updates to Node.js (in mise.toml), npm packages, and GitHub Actions (pinned to commit SHAs in .github/workflows):
npm run outdated
# Update GitHub Actions to the latest releases that are at least 7 days old
npm run pinact-updateTo test changes in a project that uses next-utils, use yalc:
# In this folder: build, check, and publish to the local yalc store
npx yalc publish
# In the project: replace the project’s copy of next-utils with the local version
npx yalc add @asl-19/next-utilsAfter making further changes, run npx yalc push in this folder to update the projects using it.
Once you’re finished testing run npx yalc remove @asl-19/next-utils in the project, then run npm install to revert to the published copy of the package.