Skip to content

Commit 73d6b8e

Browse files
authored
feat: improve messaging on middleware detection (#1575)
* feat: improve messaging on middleware detection * refactor: don't use execa if there's no middleware to bundle
1 parent 5b98fed commit 73d6b8e

File tree

1 file changed

+10
-10
lines changed
  • packages/runtime/src/helpers

1 file changed

+10
-10
lines changed

packages/runtime/src/helpers/dev.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ export const onPreDev: OnPreBuild = async ({ constants, netlifyConfig }) => {
1919
// Ignore if it doesn't exist
2020
})
2121
await writeDevEdgeFunction(constants)
22+
2223
if (!existsSync(resolve(base, 'middleware.ts')) && !existsSync(resolve(base, 'middleware.js'))) {
2324
console.log(
24-
"No middleware found. Create a 'middleware.ts' or 'middleware.js' file in your project root to add custom middleware.",
25+
"No middleware found. If you did intend to use middleware, create a 'middleware.ts' or 'middleware.js' file in your project root to add custom middleware.",
2526
)
2627
} else {
2728
console.log('Watching for changes in Next.js middleware...')
28-
}
29-
// Eventually we might want to do this via esbuild's API, but for now the CLI works fine
3029

31-
const common = [`--bundle`, `--outdir=${resolve('.netlify')}`, `--format=esm`, `--target=esnext`, '--watch']
30+
// Eventually we might want to do this via esbuild's API, but for now the CLI works fine
31+
const common = [`--bundle`, `--outdir=${resolve('.netlify')}`, `--format=esm`, `--target=esnext`, '--watch']
3232

33-
// TypeScript
34-
execa(`esbuild`, [...common, resolve(base, 'middleware.ts')], { all: true }).all.pipe(process.stdout)
33+
// TypeScript
34+
execa(`esbuild`, [...common, resolve(base, 'middleware.ts')], { all: true }).all.pipe(process.stdout)
3535

36-
// JavaScript
37-
execa(`esbuild`, [...common, resolve(base, 'middleware.js')], { all: true }).all.pipe(process.stdout)
38-
39-
// Don't return the promise because we don't want to wait for the child process to finish
36+
// JavaScript
37+
execa(`esbuild`, [...common, resolve(base, 'middleware.js')], { all: true }).all.pipe(process.stdout)
38+
// Don't return the promise because we don't want to wait for the child process to finish
39+
}
4040
}

0 commit comments

Comments
 (0)