Commit 77c5e36b authored by JJ Kasper's avatar JJ Kasper Committed by Joe Haddad

Escape output names for modern bundles to prevent replacing (#8232)

* Escape output names for modern bundles

* Update escaping for modern bundle
parent 04cf7797
...@@ -37,6 +37,12 @@ import { TerserPlugin } from './webpack/plugins/terser-webpack-plugin/src/index' ...@@ -37,6 +37,12 @@ import { TerserPlugin } from './webpack/plugins/terser-webpack-plugin/src/index'
type ExcludesFalse = <T>(x: T | false) => x is T type ExcludesFalse = <T>(x: T | false) => x is T
const escapePathVariables = (value: any) => {
return typeof value === 'string'
? value.replace(/\[(\\*[\w:]+\\*)\]/gi, '[\\$1\\]')
: value
}
export default async function getBaseWebpackConfig( export default async function getBaseWebpackConfig(
dir: string, dir: string,
{ {
...@@ -689,7 +695,9 @@ export default async function getBaseWebpackConfig( ...@@ -689,7 +695,9 @@ export default async function getBaseWebpackConfig(
return name.includes('.js') return name.includes('.js')
? name.replace(/\.js$/, '.module.js') ? name.replace(/\.js$/, '.module.js')
: args[0].chunk.name.replace(/\.js$/, '.module.js') : escapePathVariables(
args[0].chunk.name.replace(/\.js$/, '.module.js')
)
}, },
chunkFilename: (inputChunkName: string) => chunkFilename: (inputChunkName: string) =>
inputChunkName.replace(/\.js$/, '.module.js'), inputChunkName.replace(/\.js$/, '.module.js'),
......
module.exports = {
experimental: {
modern: true
}
}
...@@ -9,18 +9,17 @@ import { ...@@ -9,18 +9,17 @@ import {
launchApp, launchApp,
killApp, killApp,
waitFor, waitFor,
runNextCommand, nextBuild,
nextServer, nextStart
startApp,
stopApp
} from 'next-test-utils' } from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
let app let app
let appPort let appPort
let server let buildId
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
const buildIdPath = join(appDir, '.next/BUILD_ID')
function runTests (dev) { function runTests (dev) {
it('should render normal route', async () => { it('should render normal route', async () => {
...@@ -209,6 +208,18 @@ function runTests (dev) { ...@@ -209,6 +208,18 @@ function runTests (dev) {
if (browser) await browser.close() if (browser) await browser.close()
} }
}) })
} else {
it('should output modern bundles with dynamic route correctly', async () => {
const bundlePath = join(
appDir,
'.next/static/',
buildId,
'pages/blog/[name]/comment/[id]'
)
await fs.access(bundlePath + '.js', fs.constants.F_OK)
await fs.access(bundlePath + '.module.js', fs.constants.F_OK)
})
} }
} }
...@@ -227,50 +238,50 @@ describe('Dynamic Routing', () => { ...@@ -227,50 +238,50 @@ describe('Dynamic Routing', () => {
describe('production mode', () => { describe('production mode', () => {
beforeAll(async () => { beforeAll(async () => {
await runNextCommand(['build', appDir]) const curConfig = await fs.readFile(nextConfig, 'utf8')
app = nextServer({ if (curConfig.includes('target')) {
dir: appDir, await fs.writeFile(
dev: false, nextConfig,
quiet: true `
}) module.exports = {
experimental: { modern: true }
}
`
)
}
await nextBuild(appDir)
buildId = await fs.readFile(buildIdPath, 'utf8')
server = await startApp(app) appPort = await findPort()
appPort = server.address().port app = await nextStart(appDir, appPort)
}) })
afterAll(() => stopApp(server)) afterAll(() => killApp(app))
runTests() runTests()
}) })
describe('SSR production mode', () => { describe('SSR production mode', () => {
beforeAll(async () => { beforeAll(async () => {
await fs.remove(nextConfig)
await fs.writeFile( await fs.writeFile(
nextConfig, nextConfig,
` `
module.exports = { module.exports = {
target: 'serverless' target: 'serverless',
experimental: {
modern: true
}
} }
` `
) )
await runNextCommand(['build', appDir]) await nextBuild(appDir)
buildId = await fs.readFile(buildIdPath, 'utf8')
app = nextServer({
dir: appDir,
dev: false,
quiet: true
})
server = await startApp(app) appPort = await findPort()
appPort = server.address().port app = await nextStart(appDir, appPort)
})
afterAll(async () => {
await stopApp(server)
await fs.remove(nextConfig)
}) })
afterAll(() => killApp(app))
runTests() runTests()
}) })
}) })
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