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'
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(
dir: string,
{
......@@ -689,7 +695,9 @@ export default async function getBaseWebpackConfig(
return name.includes('.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) =>
inputChunkName.replace(/\.js$/, '.module.js'),
......
module.exports = {
experimental: {
modern: true
}
}
......@@ -9,18 +9,17 @@ import {
launchApp,
killApp,
waitFor,
runNextCommand,
nextServer,
startApp,
stopApp
nextBuild,
nextStart
} from 'next-test-utils'
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 5
let app
let appPort
let server
let buildId
const appDir = join(__dirname, '../')
const buildIdPath = join(appDir, '.next/BUILD_ID')
function runTests (dev) {
it('should render normal route', async () => {
......@@ -209,6 +208,18 @@ function runTests (dev) {
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', () => {
describe('production mode', () => {
beforeAll(async () => {
await runNextCommand(['build', appDir])
app = nextServer({
dir: appDir,
dev: false,
quiet: true
})
const curConfig = await fs.readFile(nextConfig, 'utf8')
if (curConfig.includes('target')) {
await fs.writeFile(
nextConfig,
`
module.exports = {
experimental: { modern: true }
}
`
)
}
await nextBuild(appDir)
buildId = await fs.readFile(buildIdPath, 'utf8')
server = await startApp(app)
appPort = server.address().port
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => stopApp(server))
afterAll(() => killApp(app))
runTests()
})
describe('SSR production mode', () => {
beforeAll(async () => {
await fs.remove(nextConfig)
await fs.writeFile(
nextConfig,
`
module.exports = {
target: 'serverless'
target: 'serverless',
experimental: {
modern: true
}
}
`
)
await runNextCommand(['build', appDir])
app = nextServer({
dir: appDir,
dev: false,
quiet: true
})
await nextBuild(appDir)
buildId = await fs.readFile(buildIdPath, 'utf8')
server = await startApp(app)
appPort = server.address().port
})
afterAll(async () => {
await stopApp(server)
await fs.remove(nextConfig)
appPort = await findPort()
app = await nextStart(appDir, appPort)
})
afterAll(() => killApp(app))
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