Skip to content

Commit c8dd715

Browse files
authored
Bump path-to-regexp to v8.2.0 (#218)
* Bump path-to-regexp to 8.2.0 * Update CHANGELOG * Build output
1 parent 327c017 commit c8dd715

23 files changed

+2199
-1243
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [10.0.0] - 2025-05-02
9+
10+
- Update dependency [path-to-regexp](https://www.npmjs.com/package/path-to-regexp) to version 8.2.0 from 6.2.0.
11+
- Primarily inlcluds [major changes from 7.0](https://github.com/pillarjs/path-to-regexp/releases/tag/v7.0.0)
12+
813
## [9.2.1] - 2024-11-22
914

1015
- Enable `noPropertyAccessFromIndexSignature` and `noUncheckedIndexedAccess` checks ([#216](https://github.com/kriasoft/universal-router/pull/216))

dist/universal-router-generate-urls.js

Lines changed: 669 additions & 303 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-generate-urls.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-generate-urls.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-generate-urls.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-sync.js

Lines changed: 724 additions & 437 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-sync.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-sync.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router-sync.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router.js

Lines changed: 727 additions & 440 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/universal-router.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ const urlWithQueryString = generateUrls(router, {
386386
stringifyQueryParams: (params) => new URLSearchParams(params).toString()
387387
})
388388

389-
const params = { username: 'John', busy: 1 }
389+
const params = { username: 'John', busy: '1' }
390390
url('user', params) // => /base/user/John
391391
urlWithQueryString('user', params) // => /base/user/John?busy=1
392392
```

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import UniversalRouter from 'universal-router'
2222
const routes = [
2323
{ path: '/one', action: () => '<h1>Page One</h1>' },
2424
{ path: '/two', action: () => '<h1>Page Two</h1>' },
25-
{ path: '(.*)', action: () => '<h1>Not Found</h1>' }
25+
{ path: '/*all', action: () => '<h1>Not Found</h1>' }
2626
]
2727

2828
const router = new UniversalRouter(routes)
@@ -61,7 +61,7 @@ import UniversalRouter from 'universal-router'
6161
const routes = [
6262
{ path: '/one', action: () => <h1>Page One</h1> },
6363
{ path: '/two', action: () => <h1>Page Two</h1> },
64-
{ path: '(.*)', action: () => <h1>Not Found</h1> }
64+
{ path: '/*all', action: () => <h1>Not Found</h1> }
6565
]
6666

6767
const router = new UniversalRouter(routes)

package-lock.json

Lines changed: 13 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "universal-router",
4-
"version": "9.2.1",
4+
"version": "10.0.0",
55
"description": "Isomorphic router for JavaScript web applications",
66
"homepage": "https://www.kriasoft.com/universal-router/",
77
"repository": "kriasoft/universal-router",
@@ -23,7 +23,7 @@
2323
"module": "module.js",
2424
"types": "src/UniversalRouter.d.ts",
2525
"dependencies": {
26-
"path-to-regexp": "^6.2.0"
26+
"path-to-regexp": "^8.2.0"
2727
},
2828
"devDependencies": {
2929
"@babel/core": "7.14.6",

src/UniversalRouter.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ test('supports next() across multiple routes', async () => {
287287
},
288288
},
289289
{
290-
path: '(.*)',
290+
path: '',
291291
action(): void {
292292
log.push(9)
293293
},
@@ -316,7 +316,7 @@ test('supports next() across multiple routes', async () => {
316316
},
317317
},
318318
{
319-
path: '/*',
319+
path: '/*all',
320320
action(): void {
321321
log.push(13)
322322
},
@@ -622,7 +622,7 @@ test('decodes params correctly', async () => {
622622
})
623623

624624
test('decodes repeated parameters correctly', async () => {
625-
const router = new UniversalRouter({ path: '/:a+', action: (ctx): object => ctx.params })
625+
const router = new UniversalRouter({ path: '/*a', action: (ctx): object => ctx.params })
626626
await expect(router.resolve('/x%2Fy/z/%20/%AF')).resolves.toStrictEqual({
627627
a: ['x/y', 'z', ' ', '%AF'],
628628
})
@@ -672,7 +672,7 @@ test('matches 0 routes (6)', async () => {
672672

673673
test('matches 0 routes (7)', async () => {
674674
const action: jest.Mock = jest.fn(() => true)
675-
const route = { path: '/:a+', action, children: [] }
675+
const route = { path: '/*a', action, children: [] }
676676
await expect(new UniversalRouter(route).resolve('')).rejects.toThrow(/Route not found/)
677677
expect(action.mock.calls.length).toBe(0)
678678
})

src/UniversalRouter.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {
1313
Match,
1414
MatchFunction,
1515
ParseOptions,
16-
TokensToRegexpOptions,
17-
RegexpToFunctionOptions,
16+
MatchOptions,
17+
PathToRegexpOptions,
18+
CompileOptions
1819
} from 'path-to-regexp'
1920

2021
/**
@@ -80,7 +81,7 @@ export interface Route<R = any, C extends RouterContext = RouterContext> {
8081
/**
8182
* A string, array of strings, or a regular expression. Defaults to an empty string.
8283
*/
83-
path?: Path
84+
path?: Path | Path[]
8485
/**
8586
* A unique string that can be used to generate the route URL.
8687
*/
@@ -123,8 +124,9 @@ export type ErrorHandler<R = any> = (error: RouteError, context: ResolveContext)
123124

124125
export interface RouterOptions<R = any, C extends RouterContext = RouterContext>
125126
extends ParseOptions,
126-
TokensToRegexpOptions,
127-
RegexpToFunctionOptions {
127+
MatchOptions,
128+
PathToRegexpOptions,
129+
CompileOptions {
128130
context?: C
129131
baseUrl?: string
130132
resolveRoute?: ResolveRoute<R, C>

src/UniversalRouterSync.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ test('supports next() across multiple routes', () => {
287287
},
288288
},
289289
{
290-
path: '(.*)',
290+
path: '',
291291
action(): void {
292292
log.push(9)
293293
},
@@ -316,7 +316,7 @@ test('supports next() across multiple routes', () => {
316316
},
317317
},
318318
{
319-
path: '/*',
319+
path: '/*all',
320320
action(): void {
321321
log.push(13)
322322
},
@@ -619,7 +619,7 @@ test('decodes params correctly', () => {
619619
})
620620

621621
test('decodes repeated parameters correctly', () => {
622-
const router = new UniversalRouter({ path: '/:a+', action: (ctx): object => ctx.params })
622+
const router = new UniversalRouter({ path: '/*a', action: (ctx): object => ctx.params })
623623
expect(router.resolve('/x%2Fy/z/%20/%AF')).toStrictEqual({
624624
a: ['x/y', 'z', ' ', '%AF'],
625625
})
@@ -669,7 +669,7 @@ test('matches 0 routes (6)', () => {
669669

670670
test('matches 0 routes (7)', () => {
671671
const action: jest.Mock = jest.fn(() => true)
672-
const route = { path: '/:a+', action, children: [] }
672+
const route = { path: '/*a', action, children: [] }
673673
expect(() => new UniversalRouter(route).resolve('')).toThrow(/Route not found/)
674674
expect(action.mock.calls.length).toBe(0)
675675
})

src/UniversalRouterSync.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {
1313
Match,
1414
MatchFunction,
1515
ParseOptions,
16-
TokensToRegexpOptions,
17-
RegexpToFunctionOptions,
16+
MatchOptions,
17+
PathToRegexpOptions,
18+
CompileOptions
1819
} from 'path-to-regexp'
1920

2021
/**
@@ -79,7 +80,7 @@ export interface Route<R = any, C extends RouterContext = RouterContext> {
7980
/**
8081
* A string, array of strings, or a regular expression. Defaults to an empty string.
8182
*/
82-
path?: Path
83+
path?: Path | Path[]
8384
/**
8485
* A unique string that can be used to generate the route URL.
8586
*/
@@ -124,8 +125,9 @@ export type ErrorHandler<R = any> = (
124125

125126
export interface RouterOptions<R = any, C extends RouterContext = RouterContext>
126127
extends ParseOptions,
127-
TokensToRegexpOptions,
128-
RegexpToFunctionOptions {
128+
MatchOptions,
129+
PathToRegexpOptions,
130+
CompileOptions {
129131
context?: C
130132
baseUrl?: string
131133
resolveRoute?: ResolveRoute<R, C>

src/generateUrls.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ test('generates url for named routes', () => {
3838
const router1 = new UniversalRouter({ path: '/:name', name: 'user' })
3939
const url1 = generateUrls(router1)
4040
expect(url1('user', { name: 'koistya' })).toBe('/koistya')
41-
expect(() => url1('user')).toThrow(/Expected "name" to be a string/)
41+
expect(() => url1('user')).toThrow(/Missing parameters: name/)
4242

4343
const router2 = new UniversalRouter({ path: '/user/:id', name: 'user' })
4444
const url2 = generateUrls(router2)
45-
expect(url2('user', { id: 123 })).toBe('/user/123')
46-
expect(() => url2('user')).toThrow(/Expected "id" to be a string/)
45+
expect(url2('user', { id: '123' })).toBe('/user/123')
46+
expect(() => url2('user')).toThrow(/Missing parameters: id/)
4747

4848
const router3 = new UniversalRouter({ path: '/user/:id' })
4949
const url3 = generateUrls(router3)
@@ -55,9 +55,9 @@ test('generates url for routes with array of paths', () => {
5555
const url1 = generateUrls(router1)
5656
expect(url1('user', { name: 'koistya' })).toBe('/koistya')
5757

58-
const router2 = new UniversalRouter({ path: ['/user/:id', /\/user\/(\d+)/i], name: 'user' })
58+
const router2 = new UniversalRouter({ path: ['/user/:id', '/user/(\\d+)'], name: 'user' })
5959
const url2 = generateUrls(router2)
60-
expect(url2('user', { id: 123 })).toBe('/user/123')
60+
expect(url2('user', { id: '123' })).toBe('/user/123')
6161

6262
const router3 = new UniversalRouter({ path: [], name: 'user' })
6363
const url3 = generateUrls(router3)
@@ -85,7 +85,7 @@ test('generates url for nested routes', () => {
8585
})
8686
const url = generateUrls(router)
8787
expect(url('a')).toBe('/')
88-
expect(url('b', { x: 123 })).toBe('/b/123')
88+
expect(url('b', { x: '123' })).toBe('/b/123')
8989
expect(url('c', { x: 'i', y: 'j' })).toBe('/b/i/c/j')
9090

9191
if (Array.isArray(router.root.children)) {
@@ -103,7 +103,7 @@ test('respects baseUrl', () => {
103103

104104
const router2 = new UniversalRouter({ path: '/post/:id', name: 'post' }, options)
105105
const url2 = generateUrls(router2)
106-
expect(url2('post', { id: 12, x: 'y' })).toBe('/base/post/12')
106+
expect(url2('post', { id: '12', x: 'y' })).toBe('/base/post/12')
107107

108108
const router3 = new UniversalRouter(
109109
{
@@ -169,8 +169,7 @@ test('encodes params', () => {
169169

170170
const url = generateUrls(router)
171171
const prettyUrl = generateUrls(router, {
172-
encode(str, token) {
173-
expect(token.name).toBe('user')
172+
encode(str) {
174173
return encodeURI(str).replace(
175174
/[/?#]/g,
176175
(c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`,
@@ -188,9 +187,9 @@ test('stringify query params (1)', () => {
188187

189188
const url = generateUrls(router, { stringifyQueryParams })
190189

191-
expect(url('user', { user: 'tj', busy: 1 })).toBe('/tj?qs')
190+
expect(url('user', { user: 'tj', busy: '1' })).toBe('/tj?qs')
192191
expect(stringifyQueryParams.mock.calls.length).toBe(1)
193-
expect(stringifyQueryParams.mock.calls[0][0]).toEqual({ busy: 1 })
192+
expect(stringifyQueryParams.mock.calls[0][0]).toEqual({ busy: '1' })
194193
})
195194

196195
test('stringify query params (2)', () => {
@@ -199,9 +198,9 @@ test('stringify query params (2)', () => {
199198

200199
const url = generateUrls(router, { stringifyQueryParams })
201200

202-
expect(url('user', { username: 'tj', busy: 1 })).toBe('/user/tj')
201+
expect(url('user', { username: 'tj', busy: '1' })).toBe('/user/tj')
203202
expect(stringifyQueryParams.mock.calls.length).toBe(1)
204-
expect(stringifyQueryParams.mock.calls[0][0]).toEqual({ busy: 1 })
203+
expect(stringifyQueryParams.mock.calls[0][0]).toEqual({ busy: '1' })
205204
})
206205

207206
test('stringify query params (3)', () => {

src/generateUrls.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import {
1111
parse,
1212
ParseOptions,
13-
tokensToFunction,
14-
TokensToFunctionOptions,
13+
compile,
14+
CompileOptions,
1515
PathFunction,
1616
} from 'path-to-regexp'
1717
import UniversalRouter, { Route, Routes } from './UniversalRouter'
1818

1919
export interface UrlParams {
20-
[paramName: string]: string | number | (string | number)[]
20+
[paramName: string]: string | string[]
2121
}
2222

23-
export interface GenerateUrlsOptions extends ParseOptions, TokensToFunctionOptions {
23+
export interface GenerateUrlsOptions extends ParseOptions, CompileOptions {
2424
/**
2525
* Add a query string to generated url based on unknown route params.
2626
*/
@@ -113,12 +113,16 @@ function generateUrls(router: UniversalRouter, options?: GenerateUrlsOptions): G
113113
rt = rt.parent
114114
}
115115
const tokens = parse(fullPath, opts)
116-
const toPath = tokensToFunction(tokens, opts)
116+
const toPath = compile(fullPath, opts)
117117
const keys: Keys = Object.create(null)
118-
for (let i = 0; i < tokens.length; i++) {
119-
const token = tokens[i]
120-
if (token && typeof token !== 'string') {
121-
keys[token.name] = true
118+
for (let i = 0; i < tokens.tokens.length; i++) {
119+
const token = tokens.tokens[i]
120+
if (token && token.type !== 'text') {
121+
if (token.type === 'group') {
122+
keys[String(i)] = true
123+
} else {
124+
keys[token.name] = true
125+
}
122126
}
123127
}
124128
regexp = { toPath, keys }

0 commit comments

Comments
 (0)