Compare commits

...

2 Commits

Author SHA1 Message Date
Steven
4ff8ab2435 Publish Canary
- @now/routing-utils@1.3.4-canary.5
2019-11-26 19:00:34 -05:00
Steven
d2cccbfce6 [now-routing-utils] Update path-to-regexp to v6.1.0 (#3361)
This bumps `path-to-regexp` to the latest version 6.1.0 which fixes optional capture groups like the test I added for `/next.js`.
2019-11-26 23:41:35 +00:00
4 changed files with 21 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@now/routing-utils",
"version": "1.3.4-canary.4",
"version": "1.3.4-canary.5",
"description": "ZEIT Now routing utilities",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
@@ -20,7 +20,7 @@
"test-unit": "jest --env node --verbose --runInBand"
},
"dependencies": {
"path-to-regexp": "3.1.0"
"path-to-regexp": "6.1.0"
},
"devDependencies": {
"ajv": "^6.0.0",

View File

@@ -3,7 +3,7 @@
* See https://github.com/firebase/superstatic#configuration
*/
import pathToRegexp from 'path-to-regexp';
import { pathToRegexp, Key } from 'path-to-regexp';
import { Route, NowRedirect, NowRewrite, NowHeader } from './types';
export function getCleanUrls(
@@ -97,7 +97,7 @@ export function convertTrailingSlash(enable: boolean): Route[] {
}
function sourceToRegex(source: string): { src: string; segments: string[] } {
const keys: pathToRegexp.Key[] = [];
const keys: Key[] = [];
const r = pathToRegexp(source, keys, { strict: true });
const segments = keys.map(k => k.name).filter(isString);
return { src: r.source, segments };

View File

@@ -148,6 +148,7 @@ test('convertCleanUrls false', () => {
test('convertRedirects', () => {
const actual = convertRedirects([
{ source: '/some/old/path', destination: '/some/new/path' },
{ source: '/next(\\.js)?', destination: 'https://nextjs.org' },
{
source: '/firebase/(.*)',
destination: 'https://www.firebase.com',
@@ -167,17 +168,22 @@ test('convertRedirects', () => {
status: 307,
},
{
src: '^\\/firebase\\/(.*)$',
src: '^\\/next(\\.js)?$',
headers: { Location: 'https://nextjs.org' },
status: 307,
},
{
src: '^\\/firebase(?:\\/(.*))$',
headers: { Location: 'https://www.firebase.com' },
status: 302,
},
{
src: '^\\/projects\\/([^\\/]+?)\\/([^\\/]+?)$',
src: '^\\/projects(?:\\/([^\\/#\\?]+?))(?:\\/([^\\/#\\?]+?))$',
headers: { Location: '/projects.html?id=$1&action=$2' },
status: 307,
},
{
src: '^\\/old\\/([^\\/]+?)\\/path$',
src: '^\\/old(?:\\/([^\\/#\\?]+?))\\/path$',
headers: { Location: '/new/path/$1' },
status: 307,
},
@@ -187,6 +193,7 @@ test('convertRedirects', () => {
const mustMatch = [
['/some/old/path'],
['/next', '/next.js'],
['/firebase/one', '/firebase/2', '/firebase/-', '/firebase/dir/sub'],
['/projects/one/edit', '/projects/two/edit'],
['/old/one/path', '/old/two/path'],
@@ -194,6 +201,7 @@ test('convertRedirects', () => {
const mustNotMatch = [
['/nope'],
['/nextAjs', '/nextjs'],
['/fire', '/firebasejumper/two'],
['/projects/edit', '/projects/two/three/delete', '/projects'],
['/old/path', '/old/two/foo', '/old'],
@@ -212,12 +220,12 @@ test('convertRewrites', () => {
const expected = [
{ src: '^\\/some\\/old\\/path$', dest: '/some/new/path', check: true },
{
src: '^\\/firebase\\/(.*)$',
src: '^\\/firebase(?:\\/(.*))$',
dest: 'https://www.firebase.com',
check: true,
},
{
src: '^\\/projects\\/([^\\/]+?)\\/edit$',
src: '^\\/projects(?:\\/([^\\/#\\?]+?))\\/edit$',
dest: '/projects.html?id=$1',
check: true,
},

View File

@@ -8610,10 +8610,10 @@ path-to-regexp@2.2.1:
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-2.2.1.tgz#90b617025a16381a879bc82a38d4e8bdeb2bcf45"
integrity sha512-gu9bD6Ta5bwGrrU8muHzVOBFFREpp2iRkVfhBJahwJ6p6Xw20SjT0MxLnwkjOibQmGSYhiUnf2FLe7k+jcFmGQ==
path-to-regexp@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-3.1.0.tgz#f45a9cc4dc6331ae8f131e0ce4fde8607f802367"
integrity sha512-PtHLisEvUOepjc+sStXxJ/pDV/s5UBTOKWJY2SOz3e6E/iN/jLknY9WL72kTwRrwXDUbZTEAtSnJbz2fF127DA==
path-to-regexp@6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-6.1.0.tgz#0b18f88b7a0ce0bfae6a25990c909ab86f512427"
integrity sha512-h9DqehX3zZZDCEm+xbfU0ZmwCGFCAAraPJWMXJ4+v32NjZJilVg3k1TcKsRgIb8IQ/izZSaydDc1OhJCZvs2Dw==
path-to-regexp@^1.0.0, path-to-regexp@^1.7.0:
version "1.7.0"