Skip to content

Commit

Permalink
chore: improves validation message
Browse files Browse the repository at this point in the history
  • Loading branch information
feugy committed Sep 12, 2022
1 parent eb2c584 commit db81016
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 5 additions & 2 deletions packages/next/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as Log from '../output/log'
import { SERVER_RUNTIME } from '../../lib/constants'
import { ServerRuntime } from 'next/types'
import { checkCustomRoutes } from '../../lib/load-custom-routes'
import { matcher } from 'next/dist/compiled/micromatch'

export interface MiddlewareConfig {
matchers: MiddlewareMatcher[]
Expand Down Expand Up @@ -177,9 +178,11 @@ function getMiddlewareConfig(
? config.allowDynamic
: [config.allowDynamic]
for (const glob of result.allowDynamicGlobs ?? []) {
if (typeof glob !== 'string') {
try {
matcher(glob)
} catch (err) {
throw new Error(
`A middleware/edge exported 'config.allowDynamic' must be a string or an array of strings`
`A middleware/edge exported 'config.allowDynamic' is not a valid pattern: ${err.message}`
)
}
}
Expand Down
7 changes: 1 addition & 6 deletions packages/next/build/webpack/plugins/middleware-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,7 @@ function isDynamicCodeEvaluationAllowed(
rootDir?: string
) {
const name = fileName.replace(rootDir ?? '', '')
for (const glob of edgeFunctionConfig?.allowDynamicGlobs ?? []) {
if (isMatch(name, glob)) {
return true
}
}
return false
return isMatch(name, edgeFunctionConfig?.allowDynamicGlobs ?? [])
}

function buildUnsupportedApiError({
Expand Down
2 changes: 1 addition & 1 deletion test/production/edge-config-validations/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('Edge config validations', () => {
})
await expect(next.start()).rejects.toThrow('next build failed')
expect(next.cliOutput).toMatch(
`exported 'config.allowDynamic' must be a string or an array of strings`
`exported 'config.allowDynamic' is not a valid pattern: Expected pattern to be a non-empty string`
)
})
})

0 comments on commit db81016

Please sign in to comment.