Skip to content

Commit

Permalink
Fix issue with escape-string-regexp in IE11 (vercel#32708)
Browse files Browse the repository at this point in the history
* Fix issue with escape-string-regexp in IE11

* remove escape-string-regexp dep

* Update compiled

* Link to original repo
  • Loading branch information
ijjk committed Jan 3, 2022
1 parent c9c3183 commit 4d30771
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 37 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isMatch } from 'next/dist/compiled/micromatch'
import { promises, writeFileSync } from 'fs'
import { Worker } from '../lib/worker'
import devalue from 'next/dist/compiled/devalue'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import findUp from 'next/dist/compiled/find-up'
import { nanoid } from 'next/dist/compiled/nanoid/index.cjs'
import { pathToRegexp } from 'next/dist/compiled/path-to-regexp'
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import semver from 'next/dist/compiled/semver'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import path, { join as pathJoin, relative as relativePath } from 'path'
import escapeRegExp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import {
DOT_NEXT_ALIAS,
NEXT_PROJECT_ROOT,
Expand Down Expand Up @@ -1694,7 +1694,7 @@ export default async function getBaseWebpackConfig(
webpackConfig = await buildConfiguration(webpackConfig, {
supportedBrowsers,
rootDirectory: dir,
customAppFile: new RegExp(escapeRegExp(path.join(pagesDir, `_app`))),
customAppFile: new RegExp(escapeStringRegexp(path.join(pagesDir, `_app`))),
isDevelopment: dev,
isServer,
webServerRuntime,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import devalue from 'next/dist/compiled/devalue'
import escapeRegexp from 'next/dist/compiled/escape-string-regexp'
import { join } from 'path'
import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { API_ROUTE } from '../../../../lib/constants'
import { isDynamicRoute } from '../../../../shared/lib/router/utils'
import { escapeStringRegexp } from '../../../../shared/lib/escape-regexp'
import { __ApiPreviewProps } from '../../../../server/api-utils'
import {
BUILD_MANIFEST,
Expand Down Expand Up @@ -62,7 +62,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
)
const routesManifest = join(distDir, ROUTES_MANIFEST).replace(/\\/g, '/')

const escapedBuildId = escapeRegexp(buildId)
const escapedBuildId = escapeStringRegexp(buildId)
const pageIsDynamicRoute = isDynamicRoute(page)

const encodedPreviewProps = devalue(
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/chalk/index.js

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions packages/next/compiled/escape-string-regexp/LICENSE

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/compiled/escape-string-regexp/index.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next/compiled/escape-string-regexp/package.json

This file was deleted.

2 changes: 1 addition & 1 deletion packages/next/lib/load-custom-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chalk from 'next/dist/compiled/chalk'
import { parse as parseUrl } from 'url'
import { NextConfig } from '../server/config'
import * as pathToRegexp from 'next/dist/compiled/path-to-regexp'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../shared/lib/escape-regexp'
import {
PERMANENT_REDIRECT_STATUS,
TEMPORARY_REDIRECT_STATUS,
Expand Down
1 change: 0 additions & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
"debug": "4.1.1",
"devalue": "2.0.1",
"domain-browser": "4.19.0",
"escape-string-regexp": "2.0.0",
"etag": "1.8.1",
"events": "3.3.0",
"find-cache-dir": "3.3.1",
Expand Down
4 changes: 4 additions & 0 deletions packages/next/shared/lib/escape-regexp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// regexp from https://github.com/sindresorhus/escape-string-regexp
export function escapeStringRegexp(str: string) {
return str.replace(/[|\\{}()[\]^$+*?.-]/g, '\\$&')
}
4 changes: 2 additions & 2 deletions packages/next/shared/lib/post-process.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import escapeRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from './escape-regexp'
import { parse, HTMLElement } from 'next/dist/compiled/node-html-parser'
import { OPTIMIZED_FONT_PROVIDERS } from './constants'

Expand Down Expand Up @@ -216,7 +216,7 @@ function isImgEligible(imgElement: HTMLElement): boolean {
}

function preloadTagAlreadyExists(html: string, href: string) {
const escapedHref = escapeRegexp(href)
const escapedHref = escapeStringRegexp(href)
const regex = new RegExp(`<link[^>]*href[^>]*${escapedHref}`)
return html.match(regex)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { NextParsedUrlQuery } from '../../../../server/request-meta'
import type { Params } from '../../../../server/router'
import type { RouteHas } from '../../../../lib/load-custom-routes'
import { compile, pathToRegexp } from 'next/dist/compiled/path-to-regexp'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { escapeStringRegexp } from '../../escape-regexp'
import { parseUrl } from './parse-url'

export function matchHas(
Expand Down
11 changes: 0 additions & 11 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,16 +741,6 @@ export async function ncc_devalue(task, opts) {
.ncc({ packageName: 'devalue', externals })
.target('compiled/devalue')
}
externals['escape-string-regexp'] = 'next/dist/compiled/escape-string-regexp'
// eslint-disable-next-line camelcase
export async function ncc_escape_string_regexp(task, opts) {
await task
.source(
opts.src || relative(__dirname, require.resolve('escape-string-regexp'))
)
.ncc({ packageName: 'escape-string-regexp', externals, target: 'es5' })
.target('compiled/escape-string-regexp')
}

// eslint-disable-next-line camelcase
externals['find-cache-dir'] = 'next/dist/compiled/find-cache-dir'
Expand Down Expand Up @@ -1469,7 +1459,6 @@ export async function ncc(task, opts) {
'ncc_cross_spawn',
'ncc_debug',
'ncc_devalue',
'ncc_escape_string_regexp',
'ncc_find_cache_dir',
'ncc_find_up',
'ncc_fresh',
Expand Down
4 changes: 0 additions & 4 deletions packages/next/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,6 @@ declare module 'next/dist/compiled/devalue' {
import m from 'devalue'
export = m
}
declare module 'next/dist/compiled/escape-string-regexp' {
import m from 'escape-string-regexp'
export = m
}
declare module 'next/dist/compiled/find-up' {
import m from 'find-up'
export = m
Expand Down

0 comments on commit 4d30771

Please sign in to comment.