rsnext/lint-staged.config.js
Kiko Beats fafbea8b74
Use Edge Runtime for running Edge Functions locally (#37024)
This PR introduces [Edge Runtime](https://edge-runtime.vercel.app/) for emulating [Edge Functions](https://vercel.com/features/edge-functions) locally.

Every time you run a [middleware](https://nextjs.org/docs/advanced-features/middleware) locally via `next dev`, an isolated edge runtime context will be created.

These contexts have the same constraints as production servers, plus they don't pollute the global scope; Instead, all the code run in a vm on top of a Node.js process.

Additionally, `@edge-runtime/jest-environment` has been added to make easier testing Edge Functions in a programmatic way.

It dropped the following polyfills from Next.js codebase, since they are now part of Edge Runtime:

- abort-controller
- formdata
- uuid
- web-crypto
- web-streams

Co-authored-by: Gal Schlezinger <2054772+Schniz@users.noreply.github.com>
2022-05-30 12:01:36 +00:00

33 lines
1 KiB
JavaScript

const { quote } = require('shell-quote')
const { ESLint } = require('eslint')
const eslint = new ESLint()
const isWin = process.platform === 'win32'
module.exports = {
'**/*.{js,jsx,ts,tsx}': (filenames) => {
const escapedFileNames = filenames
.map((filename) => `"${isWin ? filename : escape([filename])}"`)
.join(' ')
return [
`prettier --with-node-modules --ignore-path .prettierignore_staged --write ${escapedFileNames}`,
`eslint --no-ignore --max-warnings=0 --fix ${filenames
.filter((file) => !eslint.isPathIgnored(file))
.map((f) => `"${f}"`)
.join(' ')}`,
]
},
'**/*.{json,md,mdx,css,html,yml,yaml,scss}': (filenames) => {
const escapedFileNames = filenames
.map((filename) => `"${isWin ? filename : escape([filename])}"`)
.join(' ')
return [
`prettier --with-node-modules --ignore-path .prettierignore_staged --write ${escapedFileNames}`,
]
},
}
function escape(str) {
const escaped = quote(str)
return escaped.replace(/\\@/g, '@')
}