Unverified Commit ffd88aa7 authored by Jackson Hardaker's avatar Jackson Hardaker Committed by GitHub

Fix custom app file regex (#29525)

* Add lodash.escaperegexp

* Add compiled lodash.escaperegexp

* Refactor to escape special characters

* Test for build paths containing a special character

* Replace lodash.escaperegexp with previously compiled dep

* Revert yarn.lock change

* Remove backslash replace
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>

* lint-fix
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent 950ef1a5
...@@ -7,6 +7,7 @@ import semver from 'next/dist/compiled/semver' ...@@ -7,6 +7,7 @@ import semver from 'next/dist/compiled/semver'
import { isWebpack5, webpack } from 'next/dist/compiled/webpack/webpack' import { isWebpack5, webpack } from 'next/dist/compiled/webpack/webpack'
import type webpack5 from 'webpack5' import type webpack5 from 'webpack5'
import path, { join as pathJoin, relative as relativePath } from 'path' import path, { join as pathJoin, relative as relativePath } from 'path'
import escapeRegExp from 'next/dist/compiled/escape-string-regexp'
import { import {
DOT_NEXT_ALIAS, DOT_NEXT_ALIAS,
NEXT_PROJECT_ROOT, NEXT_PROJECT_ROOT,
...@@ -1561,9 +1562,7 @@ export default async function getBaseWebpackConfig( ...@@ -1561,9 +1562,7 @@ export default async function getBaseWebpackConfig(
webpackConfig = await buildConfiguration(webpackConfig, { webpackConfig = await buildConfiguration(webpackConfig, {
rootDirectory: dir, rootDirectory: dir,
customAppFile: new RegExp( customAppFile: new RegExp(escapeRegExp(path.join(pagesDir, `_app`))),
path.join(pagesDir, `_app`).replace(/\\/g, '(/|\\\\)')
),
isDevelopment: dev, isDevelopment: dev,
isServer, isServer,
assetPrefix: config.assetPrefix || '', assetPrefix: config.assetPrefix || '',
......
import React from 'react'
import App from 'next/app'
import '../styles/global.css'
class MyApp extends App {
render() {
const { Component, pageProps } = this.props
return <Component {...pageProps} />
}
}
export default MyApp
export default function Home() {
return <div className="red-text">This text should be red.</div>
}
...@@ -47,6 +47,34 @@ describe('CSS Support', () => { ...@@ -47,6 +47,34 @@ describe('CSS Support', () => {
}) })
}) })
describe('Basic Global Support with special characters in path', () => {
const appDir = join(fixturesDir, 'single-global-special-characters', 'a+b')
beforeAll(async () => {
await remove(join(appDir, '.next'))
})
it('should compile successfully', async () => {
const { code, stdout } = await nextBuild(appDir, [], {
stdout: true,
})
expect(code).toBe(0)
expect(stdout).toMatch(/Compiled successfully/)
})
it(`should've emitted a single CSS file`, async () => {
const cssFolder = join(appDir, '.next/static/css')
const files = await readdir(cssFolder)
const cssFiles = files.filter((f) => /\.css$/.test(f))
expect(cssFiles.length).toBe(1)
expect(await readFile(join(cssFolder, cssFiles[0]), 'utf8')).toContain(
'color:red'
)
})
})
describe('Basic Global Support with src/ dir', () => { describe('Basic Global Support with src/ dir', () => {
const appDir = join(fixturesDir, 'single-global-src') const appDir = join(fixturesDir, 'single-global-src')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment