Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

cli: sort generated paths #12

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ["14.x", "16.x"]
node-version: ["18.x", "20.x"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- uses: pnpm/[email protected].1
- uses: pnpm/[email protected].4
with:
version: 6.31.0
version: 8.6.2
- name: Cache pnpm modules
uses: actions/cache@v2
with:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
uses: actions/checkout@v3

- uses: pnpm/[email protected].1
- uses: pnpm/[email protected].4
with:
version: 6.31.0
version: 8.6.2

- name: Setup Node.js 16.x
uses: actions/setup-node@v2
- name: Setup Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 20.x
cache: pnpm

- name: Install Dependencies
Expand Down
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# This feature is supported natively in [Next.js 13.2](https://nextjs.org/13-2)
This is a fork of [next-static-paths](https://github.com/Schniz/next-static-paths)
that supports next.js 13 app router.

upgrade and have fun!
Although [Next.js 13.2](https://nextjs.org/blog/next-13-2#statically-typed-links) added experimental `typeRoutes` feature for statically typed links -
we cannot easily search them as plain text.
See https://github.com/vercel/next.js/discussions/50118

---
# `@nirtamir2/next-static-paths`

# `next-static-paths`
[![npm version](https://badge.fury.io/js/@nirtamir2%2Fnext-static-paths.svg)](https://badge.fury.io/js/@nirtamir2%2Fnext-static-paths)

Statically prevent HTTP 404 Not Found in your Next.js applications using TypeScript and code generation.

Expand All @@ -19,24 +22,24 @@ Statically prevent HTTP 404 Not Found in your Next.js applications using TypeScr
## Usage

```sh-session
$ pnpm add next-static-paths
$ pnpm add @nirtamir2/next-static-paths
# or
$ yarn add next-static-paths
$ yarn add @nirtamir2/next-static-paths
# or
$ npm install next-static-paths
$ npm install @nirtamir2/next-static-paths
```

Then, from within your Next.js application root, run the following command:

```sh-session
# For pnpm users
$ pnpx next-static-paths
$ pnpx @nirtamir2/next-static-paths

# For yarn users
$ yarn next-static-paths
$ yarn @nirtamir2/next-static-paths

# For npm users
$ npx next-static-paths
$ npx @nirtamir2/next-static-paths
```

## Usage screenshots
Expand Down
Binary file modified docs/autocomplete-paths.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/error-in-variadic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"changeset:publish": "pnpm run build && changeset publish"
},
"devDependencies": {
"@changesets/cli": "^2.22.0",
"turbo": "^1.2.9"
"@changesets/cli": "^2.26.2",
"turbo": "^1.10.16"
}
}
3 changes: 3 additions & 0 deletions packages/example-app/app/app-directory/_ignored/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function IgnoredPage() {
return <div>Ignored</div>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function RestPropsPage({
params,
}: {
params: { userId: string };
}) {
return <div>user id: {params.userId}</div>;
}
16 changes: 16 additions & 0 deletions packages/example-app/app/app-directory/group/(auth)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ReactNode } from "react";

interface Props {
children: ReactNode;
}

export default function AuthLayout(props: Props) {
const { children } = props;

return (
<div>
<div>Auth</div>
<div>{children}</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function SignInPage() {
return <div>Sign in</div>;
}
9 changes: 9 additions & 0 deletions packages/example-app/app/app-directory/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TypedLink } from "@nirtamir2/next-static-paths";

export default function Home() {
return (
<div>
Hello, world. <TypedLink as="/">Hello</TypedLink>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Splat({ params }: { params: Record<string, unknown> }) {
return <div>rest: {JSON.stringify(params)}</div>;
}
12 changes: 12 additions & 0 deletions packages/example-app/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ReactNode } from "react";

export default function Layout(props: { children: ReactNode }) {
const { children } = props;

return (
<div>
<div>App directory</div>
<div>{children}</div>
</div>
);
}
4 changes: 4 additions & 0 deletions packages/example-app/generated/static-paths.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
declare module "@@@next-static-paths" {
interface Paths {
"/": Record<never, never>,
"/app-directory": Record<never, never>,
"/app-directory/dynamic/[userId]": {"userId": string},
"/app-directory/group/sign-in": Record<never, never>,
"/app-directory/splat/[...rest]": {"rest": string[]},
"/dynamic/[userId]": {"userId": string},
"/splat/[...rest]": {"rest": string[]}
}
Expand Down
1 change: 1 addition & 0 deletions packages/example-app/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
18 changes: 9 additions & 9 deletions packages/example-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@types/react": "^17.0.42",
"@types/react-dom": "^18.0.4",
"next": "^12.1.0",
"next-static-paths": "workspace:^0.0.6",
"prettier": "^2.6.0",
"typescript": "^4.6.2",
"vitest": "^0.5.9"
"@nirtamir2/next-static-paths": "workspace:*",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"next": "^14.0.3",
"prettier": "^3.1.0",
"typescript": "^5.2.2",
"vitest": "^0.34.6"
},
"dependencies": {
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}
4 changes: 2 additions & 2 deletions packages/example-app/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { TypedLink } from "next-static-paths";
import { TypedLink } from "@nirtamir2/next-static-paths";

export default function Home() {
return (
<div>
Hello, world.{" "}
<TypedLink as="/">
<a>Hello</a>
Hello
</TypedLink>
</div>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/example-app/tests/TypedLink.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TypedLink } from "next-static-paths";
import { TypedLink } from "@nirtamir2/next-static-paths";
import { test, expect, describe } from "vitest";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
Expand All @@ -16,7 +16,7 @@ test("/", () => {
expect(
renderToStaticMarkup(
<TypedLink as="/">
<a>Hello</a>
Hello
</TypedLink>
)
).toEqual(`<a href="/">Hello</a>`);
Expand All @@ -33,7 +33,7 @@ describe("/dynamic/[userId]", () => {
expect(
renderToStaticMarkup(
<TypedLink as="/dynamic/[userId]" userId="my-user-id">
<a>Hello</a>
Hello
</TypedLink>
)
).toEqual(`<a href="/dynamic/my-user-id">Hello</a>`);
Expand All @@ -51,7 +51,7 @@ describe("/splat/[...rest]", () => {
expect(
renderToStaticMarkup(
<TypedLink as="/splat/[...rest]" rest={["my-rest", "wel/come"]}>
<a>Hello</a>
Hello
</TypedLink>
)
).toEqual(`<a href="/splat/my-rest/wel%2Fcome">Hello</a>`);
Expand Down
4 changes: 2 additions & 2 deletions packages/example-app/tests/pathFor.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test, expect } from "vitest";
import { pathFor } from "next-static-paths";
import { pathFor } from "@nirtamir2/next-static-paths";

test("/", () => {
expect(pathFor("/")).toEqual("/");
Expand Down Expand Up @@ -38,6 +38,6 @@ test("/splat/[...rest]", () => {

pathFor("/splat/[...rest]", { rest: [] });
expect(pathFor("/splat/[...rest]", { rest: ["hello", "wor/ld"] })).toEqual(
"/splat/hello/wor%2Fld"
"/[[...rest]]/hello/wor%2Fld"
);
});
24 changes: 20 additions & 4 deletions packages/example-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
Expand All @@ -13,8 +17,20 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"allowJs": true
"allowJs": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
".next/types/**/*.ts"
],
"exclude": [
"node_modules"
]
}
38 changes: 25 additions & 13 deletions packages/next-static-paths/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
# next-static-paths
# @nirtami2/next-static-paths

## 0.0.6
## 0.6.0

### Patch Changes
### Minor Changes

- d81f4ff: add a readme to the npm package
- 8c88464: Upgrade dependencies and drop Node.js 16

## 0.0.5
## 0.5.0

### Patch Changes
### Minor Changes

- 477976c: Add repository to package.json
- 2cb6122: Support next.js 14

## 0.0.4
## 0.4.0

### Patch Changes
### Minor Changes

- 238a159: Allow TypedLink to receive children in the types
- 1d4e754: Support parallel routes

## 0.0.3
## 0.3.0

### Patch Changes
### Minor Changes

- 3013374: Remove the `as` prop from the link
- 9a41b3c: support prettier v3

## 0.2.0

### Minor Changes

- b0efbde: Fix variadic argument type

## 0.1.0

### Minor Changes

- 14d3fa6: Support next 13 app router pages
16 changes: 13 additions & 3 deletions packages/next-static-paths/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,24 @@ $ yarn next-static-paths
$ npx next-static-paths
```

It's recommended to configure scripts in your `package.json` too

```json
{
"dev": "next-static-paths --pages-dir ./src --output . && next dev",
"generate-routes": "next-static-paths --pages-dir ./src --output . && :"
}
```


### `TypedLink` component

```tsx
import { TypedLink } from "next-static-paths";
import { TypedLink } from "@nirtamir2/next-static-paths";
function MyComponent() {
return (
<TypedLink as="/some/[myArgument]" myArgument="hello world">
<a>Hello world</a>
Hello world
</TypedLink>
);
}
Expand All @@ -41,7 +51,7 @@ function MyComponent() {
### `pathFor` helper

```tsx
import { pathFor } from "next-static-paths";
import { pathFor } from "@nirtamir2/next-static-paths";

function getPath() {
return pathFor("/some/[myArgument]", { myArgument: "hello world" });
Expand Down
Loading