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

v3: use regexparam package #395

Merged
merged 2 commits into from
Dec 9, 2023
Merged
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
19 changes: 8 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/wouter-preact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"dependencies": {
"mitt": "^3.0.1",
"regexparam": "^2.0.1"
"regexparam": "^3.0.0"
},
"devDependencies": {
"wouter": "*"
Expand Down
3 changes: 1 addition & 2 deletions packages/wouter-preact/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default defineConfig([
"wouter/use-hash-location",
"wouter/memory-location",
],
external: ["preact", "preact/hooks", "mitt"],
external: ["preact", "preact/hooks", "regexparam", "mitt"],

output: {
dir: "esm",
Expand All @@ -21,7 +21,6 @@ export default defineConfig([
alias({
entries: {
"./react-deps.js": "./src/preact-deps.js",
regexparam: "wouter/src/regexparam.js",
},
}),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/wouter-preact/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { RouterObject, RouterOptions } from "./router.js";
export { Path, BaseLocationHook, BaseSearchHook } from "./location-hook.js";
export * from "./router.js";

import { RouteParams } from "./regexparam.js";
import { RouteParams } from "regexparam";

/**
* Route patterns and parameters
Expand Down
29 changes: 0 additions & 29 deletions packages/wouter-preact/types/regexparam.d.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/wouter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"dependencies": {
"mitt": "^3.0.1",
"regexparam": "^2.0.1",
"regexparam": "^3.0.0",
"use-sync-external-store": "^1.0.0"
}
}
11 changes: 1 addition & 10 deletions packages/wouter/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { defineConfig } from "rollup";
import alias from "@rollup/plugin-alias";

export default defineConfig([
{
Expand All @@ -21,18 +20,10 @@ export default defineConfig([
"src/use-hash-location.js",
"src/memory-location.js",
],
external: [/react-deps/, "mitt"],
external: [/react-deps/, "regexparam", "mitt"],
output: {
dir: "esm",
format: "esm",
},

plugins: [
alias({
entries: {
regexparam: "./src/regexparam.js",
},
}),
],
},
]);
44 changes: 0 additions & 44 deletions packages/wouter/src/regexparam.js

This file was deleted.

29 changes: 13 additions & 16 deletions packages/wouter/test/use-route.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ it("ignores the trailing slash", () => {
});

it("supports trailing wildcards", () => {
assertRoute("/app/*", "/app/", { wild: "" });
assertRoute("/app/*", "/app/dashboard/intro", { wild: "dashboard/intro" });
assertRoute("/app/*", "/app/charges/1", { wild: "charges/1" });
assertRoute("/app/*", "/app/", { "*": "" });
assertRoute("/app/*", "/app/dashboard/intro", { "*": "dashboard/intro" });
assertRoute("/app/*", "/app/charges/1", { "*": "charges/1" });
});

it("supports wildcards in the middle of the pattern", () => {
assertRoute("/app/*/settings", "/app/users/settings", { wild: "users" });
assertRoute("/app/*/settings", "/app/users/1/settings", { wild: "users/1" });
assertRoute("/app/*/settings", "/app/users/settings", { "*": "users" });
assertRoute("/app/*/settings", "/app/users/1/settings", { "*": "users/1" });

assertRoute("/*/payments/:id", "/home/payments/1", { wild: "home", id: "1" });
assertRoute("/*/payments/:id", "/home/payments/1", { "*": "home", id: "1" });
assertRoute("/*/payments/:id?", "/home/payments", {
wild: "home",
"*": "home",
id: undefined,
});
});
Expand Down Expand Up @@ -75,12 +75,12 @@ it("uses a question mark to define optional segments", () => {
});

it("supports optional wildcards", () => {
assertRoute("/app/*?", "/app/blog/mac", { wild: "blog/mac" });
assertRoute("/app/*?", "/app", { wild: undefined });
assertRoute("/app/*?/dashboard", "/app/v1/dashboard", { wild: "v1" });
assertRoute("/app/*?/dashboard", "/app/dashboard", { wild: undefined });
assertRoute("/app/*?", "/app/blog/mac", { "*": "blog/mac" });
assertRoute("/app/*?", "/app", { "*": undefined });
assertRoute("/app/*?/dashboard", "/app/v1/dashboard", { "*": "v1" });
assertRoute("/app/*?/dashboard", "/app/dashboard", { "*": undefined });
assertRoute("/app/*?/users/:name", "/app/users/karen", {
wild: undefined,
"*": undefined,
name: "karen",
});
});
Expand Down Expand Up @@ -133,10 +133,7 @@ it("reacts to pattern updates", () => {
expect(result.current).toStrictEqual([false, null]);

rerender({ pattern: "/blog/*" });
expect(result.current).toStrictEqual([
true,
{ wild: "products/40/read-all" },
]);
expect(result.current).toStrictEqual([true, { "*": "products/40/read-all" }]);
});

it("reacts to location updates", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/wouter/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { RouterObject, RouterOptions } from "./router.js";
export { Path, BaseLocationHook, BaseSearchHook } from "./location-hook.js";
export * from "./router.js";

import { RouteParams } from "./regexparam.js";
import { RouteParams } from "regexparam";

/**
* Route patterns and parameters
Expand Down
29 changes: 0 additions & 29 deletions packages/wouter/types/regexparam.d.ts

This file was deleted.

Loading