diff --git a/.eslintrc.js b/.eslintrc.js index f1025ae52c4..ecedee734d6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -26,6 +26,7 @@ module.exports = { 'default-case': 2, 'default-case-last': 2, 'func-name-matching': [2, { considerPropertyDescriptor: true }], + 'func-names': [2, 'as-needed'], 'max-classes-per-file': 2, 'max-params': [2, { max: 4 }], 'multiline-comment-style': [2, 'separate-lines'], diff --git a/site/watch.js b/site/watch.js index b735918958e..54477e18b05 100644 --- a/site/watch.js +++ b/site/watch.js @@ -9,21 +9,21 @@ const { ensureFilePathAsync, removeRecursiveAsync } = require('./fs') const watcher = sane(config.docs.srcPath, { glob: ['**/*.md'] }) /* Watch Files */ -watcher.on('ready', function () { +watcher.on('ready', function onReady() { console.log(`Watching ${config.docs.srcPath} files for changes`) }) -watcher.on('change', async function (filepath) { +watcher.on('change', async function onChange(filepath) { console.log('file changed', filepath) await syncFile(filepath) }) -watcher.on('add', async function (filepath) { +watcher.on('add', async function onAdd(filepath) { console.log('file added') await syncFile(filepath) }) -watcher.on('delete', async function (filepath) { +watcher.on('delete', async function onDelete(filepath) { console.log('file deleted', filepath) await deleteFile(filepath) console.log('File deletion complete') diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index b224eb96aa2..93399965a20 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -30,7 +30,7 @@ async function startFrameworkServer({ settings, log, exit }) { }) await new Promise((resolve) => { - server.start(function () { + server.start(function onListening() { log(`\n${NETLIFYDEVLOG} Server listening to`, settings.frameworkPort) resolve() }) diff --git a/src/detectors/README.md b/src/detectors/README.md index 0d64bf3b5d5..39d0788d10a 100644 --- a/src/detectors/README.md +++ b/src/detectors/README.md @@ -35,7 +35,7 @@ requires a global install: https://github.com/GitbookIO/gitbook/blob/master/docs ```js const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['README.md', 'SUMMARY.md'])) return false // // REQUIRED DEPS diff --git a/src/detectors/angular.js b/src/detectors/angular.js index b1f8804aafe..48e5b4964a8 100644 --- a/src/detectors/angular.js +++ b/src/detectors/angular.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false if (!hasRequiredFiles(['angular.json'])) return false diff --git a/src/detectors/brunch.js b/src/detectors/brunch.js index 51419511779..9371df7e50f 100644 --- a/src/detectors/brunch.js +++ b/src/detectors/brunch.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', 'brunch-config.js'])) return false // REQUIRED DEPS diff --git a/src/detectors/create-react-app.js b/src/detectors/create-react-app.js index fe12a6dc9df..34399d95f37 100644 --- a/src/detectors/create-react-app.js +++ b/src/detectors/create-react-app.js @@ -3,7 +3,7 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = // // detection logic - artificial intelligence! // -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/docusaurus.js b/src/detectors/docusaurus.js index f51b1092c6e..1a6b3c6956e 100644 --- a/src/detectors/docusaurus.js +++ b/src/detectors/docusaurus.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false diff --git a/src/detectors/eleventy.js b/src/detectors/eleventy.js index d064548b0cb..955fc1322a7 100644 --- a/src/detectors/eleventy.js +++ b/src/detectors/eleventy.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if ( !hasRequiredFiles(['package.json', '.eleventy.js']) && diff --git a/src/detectors/ember.js b/src/detectors/ember.js index fe18a428135..e75b686f601 100644 --- a/src/detectors/ember.js +++ b/src/detectors/ember.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false if (!hasRequiredFiles(['ember-cli-build.js'])) return false diff --git a/src/detectors/expo.js b/src/detectors/expo.js index 73ba99eef24..e2758412e57 100644 --- a/src/detectors/expo.js +++ b/src/detectors/expo.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', 'app.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/gatsby.js b/src/detectors/gatsby.js index 4f013f7a9e1..56e9a00d9b6 100644 --- a/src/detectors/gatsby.js +++ b/src/detectors/gatsby.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', 'gatsby-config.js'])) return false // REQUIRED DEPS diff --git a/src/detectors/gridsome.js b/src/detectors/gridsome.js index b997610b6f0..03bad0a9a0b 100644 --- a/src/detectors/gridsome.js +++ b/src/detectors/gridsome.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', 'gridsome.config.js'])) return false // REQUIRED DEPS diff --git a/src/detectors/hexo.js b/src/detectors/hexo.js index ce59f78ee5a..fbb81dab3cb 100644 --- a/src/detectors/hexo.js +++ b/src/detectors/hexo.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', '_config.yml'])) return false // REQUIRED DEPS diff --git a/src/detectors/hugo.js b/src/detectors/hugo.js index e1c29799367..ad93cd14234 100644 --- a/src/detectors/hugo.js +++ b/src/detectors/hugo.js @@ -1,6 +1,6 @@ const { existsSync } = require('fs') -module.exports = function () { +module.exports = function detector() { if (!existsSync('config.toml') && !existsSync('config.yaml')) { return false } diff --git a/src/detectors/jekyll.js b/src/detectors/jekyll.js index 1b095e52205..78b278e2fea 100644 --- a/src/detectors/jekyll.js +++ b/src/detectors/jekyll.js @@ -1,6 +1,6 @@ const { existsSync } = require('fs') -module.exports = function () { +module.exports = function detector() { if (!existsSync('_config.yml')) { return false } diff --git a/src/detectors/middleman.js b/src/detectors/middleman.js index f1dca2843b6..cdad26c4bd1 100644 --- a/src/detectors/middleman.js +++ b/src/detectors/middleman.js @@ -1,6 +1,6 @@ const { existsSync } = require('fs') -module.exports = function () { +module.exports = function detector() { if (!existsSync('config.rb')) { return false } diff --git a/src/detectors/next.js b/src/detectors/next.js index ceea5af65a0..2c264c7a124 100644 --- a/src/detectors/next.js +++ b/src/detectors/next.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/nuxt.js b/src/detectors/nuxt.js index 63f5ffde122..4852f74a140 100644 --- a/src/detectors/nuxt.js +++ b/src/detectors/nuxt.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/parcel.js b/src/detectors/parcel.js index a46dfd7eda1..b51a4105bc9 100644 --- a/src/detectors/parcel.js +++ b/src/detectors/parcel.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { /* REQUIRED FILES */ if (!hasRequiredFiles(['package.json'])) return false diff --git a/src/detectors/phenomic.js b/src/detectors/phenomic.js index b0af9b4888f..c6a6bf98f43 100644 --- a/src/detectors/phenomic.js +++ b/src/detectors/phenomic.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/quasar-v0.17.js b/src/detectors/quasar-v0.17.js index f5d9405d601..bef951e733b 100644 --- a/src/detectors/quasar-v0.17.js +++ b/src/detectors/quasar-v0.17.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/quasar.js b/src/detectors/quasar.js index 8a5087fe2f9..1df857459b2 100644 --- a/src/detectors/quasar.js +++ b/src/detectors/quasar.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/react-static.js b/src/detectors/react-static.js index aad85902dc9..329d35cb887 100644 --- a/src/detectors/react-static.js +++ b/src/detectors/react-static.js @@ -1,5 +1,5 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', 'static.config.js'])) return false // REQUIRED DEPS diff --git a/src/detectors/sapper.js b/src/detectors/sapper.js index e77e9a5548c..3c8281898a7 100644 --- a/src/detectors/sapper.js +++ b/src/detectors/sapper.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/stencil.js b/src/detectors/stencil.js index ca2371f2c12..754257f915d 100644 --- a/src/detectors/stencil.js +++ b/src/detectors/stencil.js @@ -3,7 +3,7 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = // // detection logic - artificial intelligence! // -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json', 'stencil.config.ts'])) return false // REQUIRED DEPS diff --git a/src/detectors/svelte.js b/src/detectors/svelte.js index 9541ae132f0..dfba3fbecca 100644 --- a/src/detectors/svelte.js +++ b/src/detectors/svelte.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/vue.js b/src/detectors/vue.js index 7fd35367d1f..002743df0ae 100644 --- a/src/detectors/vue.js +++ b/src/detectors/vue.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/detectors/vuepress.js b/src/detectors/vuepress.js index eaad7340a60..7ad6671a1ee 100644 --- a/src/detectors/vuepress.js +++ b/src/detectors/vuepress.js @@ -1,6 +1,6 @@ const { hasRequiredDeps, hasRequiredFiles, getYarnOrNPMCommand, scanScripts } = require('./utils/jsdetect') -module.exports = function () { +module.exports = function detector() { // REQUIRED FILES if (!hasRequiredFiles(['package.json'])) return false // REQUIRED DEPS diff --git a/src/function-builder-detectors/netlify-lambda.js b/src/function-builder-detectors/netlify-lambda.js index 3ab1c1d9212..2546d42c7be 100644 --- a/src/function-builder-detectors/netlify-lambda.js +++ b/src/function-builder-detectors/netlify-lambda.js @@ -1,7 +1,7 @@ const { existsSync, readFileSync } = require('fs') const execa = require('execa') -module.exports = function () { +module.exports = function handler() { if (!existsSync('package.json')) { return false } diff --git a/src/functions-templates/js/apollo-graphql-rest/apollo-graphql-rest.js b/src/functions-templates/js/apollo-graphql-rest/apollo-graphql-rest.js index f97487230fb..b9e10c8baed 100644 --- a/src/functions-templates/js/apollo-graphql-rest/apollo-graphql-rest.js +++ b/src/functions-templates/js/apollo-graphql-rest/apollo-graphql-rest.js @@ -62,4 +62,6 @@ const server = new ApolloServer({ }), }) -exports.handler = server.createHandler() +const handler = server.createHandler() + +module.exports = { handler } diff --git a/src/functions-templates/js/apollo-graphql/apollo-graphql.js b/src/functions-templates/js/apollo-graphql/apollo-graphql.js index 2b6b8dc1816..75b9faa6b04 100644 --- a/src/functions-templates/js/apollo-graphql/apollo-graphql.js +++ b/src/functions-templates/js/apollo-graphql/apollo-graphql.js @@ -41,4 +41,6 @@ const server = new ApolloServer({ resolvers, }) -exports.handler = server.createHandler() +const handler = server.createHandler() + +module.exports = { handler } diff --git a/src/functions-templates/js/auth-fetch/auth-fetch.js b/src/functions-templates/js/auth-fetch/auth-fetch.js index 3b3dad3e476..5e296242304 100644 --- a/src/functions-templates/js/auth-fetch/auth-fetch.js +++ b/src/functions-templates/js/auth-fetch/auth-fetch.js @@ -1,7 +1,7 @@ // for a full working demo of Netlify Identity + Functions, see https://netlify-gotrue-in-react.netlify.com/ const fetch = require('node-fetch') -exports.handler = async function (event, context) { +const handler = async function (event, context) { if (!context.clientContext && !context.clientContext.identity) { return { statusCode: 500, @@ -31,3 +31,5 @@ exports.handler = async function (event, context) { } } } + +module.exports = { handler } diff --git a/src/functions-templates/js/create-user/create-user.js b/src/functions-templates/js/create-user/create-user.js index a31aa26c7de..26d4fff9429 100644 --- a/src/functions-templates/js/create-user/create-user.js +++ b/src/functions-templates/js/create-user/create-user.js @@ -1,6 +1,6 @@ const fetch = require('node-fetch') -exports.handler = async (event, context) => { +const handler = async (event, context) => { if (event.httpMethod !== 'POST') return { statusCode: 400, body: 'Must POST to this function' } // send account information along with the POST @@ -32,3 +32,5 @@ exports.handler = async (event, context) => { body: 'success!', } } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-crud/create.js b/src/functions-templates/js/fauna-crud/create.js index 31036b9c171..4a642c9e8c9 100644 --- a/src/functions-templates/js/fauna-crud/create.js +++ b/src/functions-templates/js/fauna-crud/create.js @@ -7,7 +7,7 @@ const client = new faunadb.Client({ }) /* export our lambda function as named "handler" export */ -exports.handler = async (event) => { +const handler = async (event) => { /* parse the string body into a useable JS object */ const data = JSON.parse(event.body) console.log('Function `create` invoked', data) @@ -34,3 +34,5 @@ exports.handler = async (event) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-crud/delete.js b/src/functions-templates/js/fauna-crud/delete.js index 65b11695752..38d82cc54d4 100644 --- a/src/functions-templates/js/fauna-crud/delete.js +++ b/src/functions-templates/js/fauna-crud/delete.js @@ -6,7 +6,7 @@ const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET, }) -exports.handler = async (event) => { +const handler = async (event) => { const { id } = event console.log(`Function 'delete' invoked. delete id: ${id}`) return client @@ -26,3 +26,5 @@ exports.handler = async (event) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-crud/fauna-crud.js b/src/functions-templates/js/fauna-crud/fauna-crud.js index 42ade1aaccf..a1fa4ce669b 100644 --- a/src/functions-templates/js/fauna-crud/fauna-crud.js +++ b/src/functions-templates/js/fauna-crud/fauna-crud.js @@ -1,4 +1,4 @@ -exports.handler = async (event, context) => { +const handler = async (event, context) => { const path = event.path.replace(/\.netlify\/functions\/[^/]+/, '') const segments = path.split('/').filter((e) => e) @@ -53,3 +53,5 @@ exports.handler = async (event, context) => { } } } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-crud/read-all.js b/src/functions-templates/js/fauna-crud/read-all.js index 03efcd29a9d..bb5818efabf 100644 --- a/src/functions-templates/js/fauna-crud/read-all.js +++ b/src/functions-templates/js/fauna-crud/read-all.js @@ -6,7 +6,7 @@ const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET, }) -exports.handler = async () => { +const handler = async () => { console.log('Function `read-all` invoked') return client .query(q.Paginate(q.Match(q.Ref('indexes/all_items')))) @@ -32,3 +32,5 @@ exports.handler = async () => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-crud/read.js b/src/functions-templates/js/fauna-crud/read.js index 9297ee5beeb..b37c4fe5bfd 100644 --- a/src/functions-templates/js/fauna-crud/read.js +++ b/src/functions-templates/js/fauna-crud/read.js @@ -6,7 +6,7 @@ const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET, }) -exports.handler = async (event) => { +const handler = async (event) => { const { id } = event console.log(`Function 'read' invoked. Read id: ${id}`) return client @@ -26,3 +26,5 @@ exports.handler = async (event) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-crud/update.js b/src/functions-templates/js/fauna-crud/update.js index e66ba2c3ffb..c979a61eee3 100644 --- a/src/functions-templates/js/fauna-crud/update.js +++ b/src/functions-templates/js/fauna-crud/update.js @@ -6,7 +6,7 @@ const client = new faunadb.Client({ secret: process.env.FAUNADB_SERVER_SECRET, }) -exports.handler = async (event) => { +const handler = async (event) => { const data = JSON.parse(event.body) const { id } = event console.log(`Function 'update' invoked. update id: ${id}`) @@ -27,3 +27,5 @@ exports.handler = async (event) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/fauna-graphql/fauna-graphql.js b/src/functions-templates/js/fauna-graphql/fauna-graphql.js index e2163d672af..ab3192bc34c 100644 --- a/src/functions-templates/js/fauna-graphql/fauna-graphql.js +++ b/src/functions-templates/js/fauna-graphql/fauna-graphql.js @@ -3,11 +3,11 @@ const { createHttpLink } = require('apollo-link-http') const fetch = require('node-fetch') const { introspectSchema, makeRemoteExecutableSchema } = require('graphql-tools') -exports.handler = async function (event, context) { +const handler = async function (event, context) { /** required for Fauna GraphQL auth */ if (!process.env.FAUNADB_SERVER_SECRET) { const msg = ` - FAUNADB_SERVER_SECRET missing. + FAUNADB_SERVER_SECRET missing. Did you forget to install the fauna addon or forgot to run inside Netlify Dev? ` console.error(msg) @@ -40,3 +40,5 @@ exports.handler = async function (event, context) { server.createHandler()(event, context, cb) }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/google-analytics/google-analytics.js b/src/functions-templates/js/google-analytics/google-analytics.js index e858ea1b454..ce923348076 100644 --- a/src/functions-templates/js/google-analytics/google-analytics.js +++ b/src/functions-templates/js/google-analytics/google-analytics.js @@ -54,7 +54,7 @@ function proxyToGoogleAnalytics(event, done) { done() } -exports.handler = function (event, context, callback) { +const handler = function (event, context, callback) { const origin = event.headers.origin || event.headers.Origin || '' console.log(`Received ${event.httpMethod} request from, origin: ${origin}`) @@ -89,6 +89,8 @@ exports.handler = function (event, context, callback) { } } +module.exports = { handler } + // // Docs on GA endpoint and example params // diff --git a/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js b/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js index 99132cf493d..b047299ca7a 100644 --- a/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js +++ b/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-1.js @@ -43,4 +43,6 @@ const server = new ApolloServer({ resolvers, }) -exports.handler = server.createHandler() +const handler = server.createHandler() + +module.exports = { handler } diff --git a/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-2.js b/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-2.js index 806609e57ed..5a2880b52cf 100644 --- a/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-2.js +++ b/src/functions-templates/js/graphql-gateway/example-sibling-function-graphql-2.js @@ -81,4 +81,6 @@ const server = new ApolloServer({ resolvers, }) -exports.handler = server.createHandler() +const handler = server.createHandler() + +module.exports = { handler } diff --git a/src/functions-templates/js/graphql-gateway/graphql-gateway.js b/src/functions-templates/js/graphql-gateway/graphql-gateway.js index 4790c4d135a..49d82d435a7 100644 --- a/src/functions-templates/js/graphql-gateway/graphql-gateway.js +++ b/src/functions-templates/js/graphql-gateway/graphql-gateway.js @@ -10,7 +10,7 @@ const { createHttpLink } = require('apollo-link-http') const fetch = require('node-fetch') const { ApolloServer } = require('apollo-server-lambda') -exports.handler = async function (event, context) { +const handler = async function (event, context) { const schema1 = await getSchema('graphql-1') // other Netlify functions which are graphql lambdas const schema2 = await getSchema('graphql-2') // other Netlify functions which are graphql lambdas const schemas = [schema1, schema2] @@ -68,3 +68,5 @@ async function getSchema(endpoint) { const executableSchema = makeRemoteExecutableSchema({ schema, link }) return executableSchema } + +module.exports = { handler } diff --git a/src/functions-templates/js/hasura-event-triggered/hasura-event-triggered.js b/src/functions-templates/js/hasura-event-triggered/hasura-event-triggered.js index f7c097a91f4..e73f37f5bea 100644 --- a/src/functions-templates/js/hasura-event-triggered/hasura-event-triggered.js +++ b/src/functions-templates/js/hasura-event-triggered/hasura-event-triggered.js @@ -15,7 +15,7 @@ mutation verifiedp($id: uuid!, $title: String!, $content: String!) { } ` -exports.handler = async (event) => { +const handler = async (event) => { let request try { request = JSON.parse(event.body) @@ -35,3 +35,5 @@ exports.handler = async (event) => { return { statusCode: 500, body: error.toString() } } } + +module.exports = { handler } diff --git a/src/functions-templates/js/hello-world/hello-world.js b/src/functions-templates/js/hello-world/hello-world.js index 17015e6d15d..27d6c4ced84 100644 --- a/src/functions-templates/js/hello-world/hello-world.js +++ b/src/functions-templates/js/hello-world/hello-world.js @@ -1,5 +1,5 @@ // Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method -exports.handler = async (event) => { +const handler = async (event) => { try { const subject = event.queryStringParameters.name || 'World' return { @@ -13,3 +13,5 @@ exports.handler = async (event) => { return { statusCode: 500, body: error.toString() } } } + +module.exports = { handler } diff --git a/src/functions-templates/js/identity-signup/identity-signup.js b/src/functions-templates/js/identity-signup/identity-signup.js index 6de3c9c5e95..c5c451eb02a 100644 --- a/src/functions-templates/js/identity-signup/identity-signup.js +++ b/src/functions-templates/js/identity-signup/identity-signup.js @@ -5,7 +5,7 @@ // https://www.netlify.com/blog/2019/02/21/the-role-of-roles-and-how-to-set-them-in-netlify-identity/ // https://www.netlify.com/docs/functions/#identity-and-functions -exports.handler = async function (event) { +const handler = async function (event) { const data = JSON.parse(event.body) const { user } = data @@ -24,3 +24,5 @@ exports.handler = async function (event) { body: JSON.stringify(responseBody), } } + +module.exports = { handler } diff --git a/src/functions-templates/js/node-fetch/node-fetch.js b/src/functions-templates/js/node-fetch/node-fetch.js index ffaea890b77..263bb525831 100644 --- a/src/functions-templates/js/node-fetch/node-fetch.js +++ b/src/functions-templates/js/node-fetch/node-fetch.js @@ -1,5 +1,5 @@ const fetch = require('node-fetch') -exports.handler = async function () { +const handler = async function () { try { const response = await fetch('https://icanhazdadjoke.com', { headers: { Accept: 'application/json' }, @@ -22,3 +22,5 @@ exports.handler = async function () { } } } + +module.exports = { handler } diff --git a/src/functions-templates/js/oauth-passport/oauth-passport.js b/src/functions-templates/js/oauth-passport/oauth-passport.js index c3aac26183c..8171a77a0e8 100644 --- a/src/functions-templates/js/oauth-passport/oauth-passport.js +++ b/src/functions-templates/js/oauth-passport/oauth-passport.js @@ -32,4 +32,6 @@ app.get(`${ENDPOINT}/auth/status`, passport.authenticate('jwt', { session: false res.json({ email: req.user.email }) ) -module.exports.handler = serverless(app) +const handler = serverless(app) + +module.exports = { handler } diff --git a/src/functions-templates/js/oauth-passport/utils/config.js b/src/functions-templates/js/oauth-passport/utils/config.js index 81c401ad7d8..eeda8bc6cf4 100644 --- a/src/functions-templates/js/oauth-passport/utils/config.js +++ b/src/functions-templates/js/oauth-passport/utils/config.js @@ -1,13 +1,22 @@ // lambda/utils/config.js // Circumvent problem with Netlify CLI. // https://github.com/netlify/netlify-dev-plugin/issues/147 -exports.BASE_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8888' : process.env.BASE_URL +const BASE_URL = process.env.NODE_ENV === 'development' ? 'http://localhost:8888' : process.env.BASE_URL -exports.COOKIE_SECURE = process.env.NODE_ENV !== 'development' +const COOKIE_SECURE = process.env.NODE_ENV !== 'development' -exports.ENDPOINT = process.env.NODE_ENV === 'development' ? '/.netlify/functions' : '/api' +const ENDPOINT = process.env.NODE_ENV === 'development' ? '/.netlify/functions' : '/api' -exports.GITHUB_CLIENT_ID = process.env.GITHUB_CLIENT_ID -exports.GITHUB_CLIENT_SECRET = process.env.GITHUB_CLIENT_SECRET +const { GITHUB_CLIENT_ID } = process.env +const { GITHUB_CLIENT_SECRET } = process.env -exports.SECRET = process.env.SECRET || 'SUPERSECRET' +const SECRET = process.env.SECRET || 'SUPERSECRET' + +module.exports = { + BASE_URL, + COOKIE_SECURE, + ENDPOINT, + GITHUB_CLIENT_ID, + GITHUB_CLIENT_SECRET, + SECRET, +} diff --git a/src/functions-templates/js/protected-function/protected-function.js b/src/functions-templates/js/protected-function/protected-function.js index 1150b04cd2d..2c36ffeba31 100644 --- a/src/functions-templates/js/protected-function/protected-function.js +++ b/src/functions-templates/js/protected-function/protected-function.js @@ -1,4 +1,4 @@ -exports.handler = async (event, context) => { +const handler = async (event, context) => { console.log('protected function!') // Reading the context.clientContext will give us the current user const claims = context.clientContext && context.clientContext.user @@ -21,3 +21,5 @@ exports.handler = async (event, context) => { }), } } + +module.exports = { handler } diff --git a/src/functions-templates/js/sanity-create/sanity-create.js b/src/functions-templates/js/sanity-create/sanity-create.js index ddb4944b7cc..73ab1492de2 100644 --- a/src/functions-templates/js/sanity-create/sanity-create.js +++ b/src/functions-templates/js/sanity-create/sanity-create.js @@ -30,7 +30,7 @@ const client = sanityClient({ // // Then we construct an object to save in Sanity.io and return the full saved // object back to our caller -exports.handler = async (event) => { +const handler = async (event) => { if (!event.httpMethod === 'POST') { return { statusCode: 400, @@ -67,3 +67,5 @@ exports.handler = async (event) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/sanity-groq/sanity-groq.js b/src/functions-templates/js/sanity-groq/sanity-groq.js index 295a93e92ff..813c9f1babf 100644 --- a/src/functions-templates/js/sanity-groq/sanity-groq.js +++ b/src/functions-templates/js/sanity-groq/sanity-groq.js @@ -29,7 +29,7 @@ const client = sanityClient({ // // Read more about restricting access to your Netlify functions at // https://www.netlify.com/blog/2018/03/29/jamstack-architecture-on-netlify-how-identity-and-functions-work-together/#restricting-access -exports.handler = async (event) => { +const handler = async (event) => { const { query = '' } = event.queryStringParameters // The rest of the query params are handled as parameters to the query const params = { ...event.queryStringParameters, query: null } @@ -51,3 +51,5 @@ exports.handler = async (event) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/send-email/send-email.js b/src/functions-templates/js/send-email/send-email.js index 98a2b1becde..9c41a0dc2fd 100644 --- a/src/functions-templates/js/send-email/send-email.js +++ b/src/functions-templates/js/send-email/send-email.js @@ -2,7 +2,7 @@ const sendMail = require('sendmail')() const { validateEmail, validateLength } = require('./validations') -exports.handler = (event, context, callback) => { +const handler = (event, context, callback) => { if (!process.env.CONTACT_EMAIL) { return callback(null, { statusCode: 500, @@ -60,3 +60,5 @@ exports.handler = (event, context, callback) => { } }) } + +module.exports = { handler } diff --git a/src/functions-templates/js/send-email/validations.js b/src/functions-templates/js/send-email/validations.js index cdc21393d70..052bb8a34c5 100644 --- a/src/functions-templates/js/send-email/validations.js +++ b/src/functions-templates/js/send-email/validations.js @@ -1,16 +1,16 @@ -exports.validateEmail = (ctx, str) => { +const validateEmail = (ctx, str) => { if (typeof str !== 'string' && !(str instanceof String)) { throw new TypeError(`${ctx} must be a string`) } - exports.validateLength(ctx, str, 5, 30) + validateLength(ctx, str, 5, 30) if (!/^[\w.-]+@[\w.-]+\.\w+$/.test(str)) { throw new TypeError(`${ctx} is not an email address`) } } -exports.validateLength = (ctx, str, min, max) => { +const validateLength = (ctx, str, min, max) => { if (max === undefined) { max = min min = 0 @@ -28,3 +28,8 @@ exports.validateLength = (ctx, str, min, max) => { throw new TypeError(`${ctx} must contain ${max} chars at most`) } } + +module.exports = { + validateEmail, + validateLength, +} diff --git a/src/functions-templates/js/serverless-ssr/app/index.js b/src/functions-templates/js/serverless-ssr/app/index.js index b78dcd7aabf..2d4f39e9bd1 100644 --- a/src/functions-templates/js/serverless-ssr/app/index.js +++ b/src/functions-templates/js/serverless-ssr/app/index.js @@ -17,7 +17,7 @@ module.exports = function expressApp(functionName) { const routerBasePath = process.env.NODE_ENV === 'dev' ? `/${functionName}` : `/.netlify/functions/${functionName}/` /* define routes */ - router.get('/', (req, res) => { + router.get('/', function onRequest(req, res) { const html = ` @@ -65,7 +65,7 @@ module.exports = function expressApp(functionName) { res.send(html) }) - router.get('/users', (req, res) => { + router.get('/users', function onRequest(req, res) { res.json({ users: [ { @@ -78,7 +78,7 @@ module.exports = function expressApp(functionName) { }) }) - router.get('/hello/', function (req, res) { + router.get('/hello/', function onRequest(req, res) { res.send('hello world') }) diff --git a/src/functions-templates/js/serverless-ssr/serverless-http.js b/src/functions-templates/js/serverless-ssr/serverless-http.js index bff11100f5d..836383379f9 100644 --- a/src/functions-templates/js/serverless-ssr/serverless-http.js +++ b/src/functions-templates/js/serverless-ssr/serverless-http.js @@ -9,4 +9,6 @@ const functionName = 'serverless-http' const app = expressApp(functionName) // Export lambda handler -exports.handler = serverless(app) +const handler = serverless(app) + +module.exports = { handler } diff --git a/src/functions-templates/js/serverless-ssr/serverless-ssr.js b/src/functions-templates/js/serverless-ssr/serverless-ssr.js index bff11100f5d..836383379f9 100644 --- a/src/functions-templates/js/serverless-ssr/serverless-ssr.js +++ b/src/functions-templates/js/serverless-ssr/serverless-ssr.js @@ -9,4 +9,6 @@ const functionName = 'serverless-http' const app = expressApp(functionName) // Export lambda handler -exports.handler = serverless(app) +const handler = serverless(app) + +module.exports = { handler } diff --git a/src/functions-templates/js/set-cookie/set-cookie.js b/src/functions-templates/js/set-cookie/set-cookie.js index 033b5f9621c..00d42a845e5 100644 --- a/src/functions-templates/js/set-cookie/set-cookie.js +++ b/src/functions-templates/js/set-cookie/set-cookie.js @@ -1,6 +1,6 @@ const cookie = require('cookie') -exports.handler = async () => { +const handler = async () => { const hour = 3600000 const twoWeeks = 14 * 24 * hour const myCookie = cookie.serialize('my_cookie', 'lolHi', { @@ -39,3 +39,5 @@ exports.handler = async () => { body: html, } } + +module.exports = { handler } diff --git a/src/functions-templates/js/stripe-charge/stripe-charge.js b/src/functions-templates/js/stripe-charge/stripe-charge.js index aac41af831e..5fa49767bbd 100644 --- a/src/functions-templates/js/stripe-charge/stripe-charge.js +++ b/src/functions-templates/js/stripe-charge/stripe-charge.js @@ -8,7 +8,7 @@ const headers = { 'Access-Control-Allow-Headers': 'Content-Type', } -exports.handler = function (event, context, callback) { +const handler = function (event, context, callback) { // -- We only care to do anything if this is our POST request. if (event.httpMethod !== 'POST' || !event.body) { callback(null, { @@ -60,3 +60,5 @@ exports.handler = function (event, context, callback) { } ) } + +module.exports = { handler } diff --git a/src/functions-templates/js/stripe-subscription/stripe-subscription.js b/src/functions-templates/js/stripe-subscription/stripe-subscription.js index 36242216b7b..959f4746e7d 100644 --- a/src/functions-templates/js/stripe-subscription/stripe-subscription.js +++ b/src/functions-templates/js/stripe-subscription/stripe-subscription.js @@ -14,7 +14,7 @@ const respond = (fulfillmentText) => { } } -exports.handler = async function (event) { +const handler = async function (event) { let incoming try { incoming = JSON.parse(event.body) @@ -49,3 +49,5 @@ async function createCustomerAndSubscribeToPlan(stripeToken, email, productPlan) }) return subscription } + +module.exports = { handler } diff --git a/src/functions-templates/js/submission-created/submission-created.js b/src/functions-templates/js/submission-created/submission-created.js index 3694961107b..6e99280a3ea 100644 --- a/src/functions-templates/js/submission-created/submission-created.js +++ b/src/functions-templates/js/submission-created/submission-created.js @@ -4,7 +4,7 @@ // // details in https://css-tricks.com/using-netlify-forms-and-netlify-functions-to-build-an-email-sign-up-widget const fetch = require('node-fetch') const { EMAIL_TOKEN } = process.env -exports.handler = async (event) => { +const handler = async (event) => { const { email } = JSON.parse(event.body).payload console.log(`Recieved a submission: ${email}`) return fetch('https://api.buttondown.email/v1/subscribers', { @@ -21,3 +21,5 @@ exports.handler = async (event) => { }) .catch((error) => ({ statusCode: 422, body: String(error) })) } + +module.exports = { handler } diff --git a/src/functions-templates/js/token-hider/token-hider.js b/src/functions-templates/js/token-hider/token-hider.js index 2909fa40411..11afb266403 100644 --- a/src/functions-templates/js/token-hider/token-hider.js +++ b/src/functions-templates/js/token-hider/token-hider.js @@ -1,7 +1,7 @@ const axios = require('axios') const qs = require('qs') -exports.handler = async function (event) { +const handler = async function (event) { // apply our function to the queryStringParameters and assign it to a variable const API_PARAMS = qs.stringify(event.queryStringParameters) console.log('API_PARAMS', API_PARAMS) @@ -31,3 +31,5 @@ exports.handler = async function (event) { } } } + +module.exports = { handler } diff --git a/src/functions-templates/js/url-shortener/generate-route.js b/src/functions-templates/js/url-shortener/generate-route.js index ddf78e62849..faafc9bd120 100644 --- a/src/functions-templates/js/url-shortener/generate-route.js +++ b/src/functions-templates/js/url-shortener/generate-route.js @@ -29,7 +29,7 @@ module.exports = function handler(event, context, callback) { } // post the new route to the Routes form - request.post({ url: rootURL, formData: payload }, function (err) { + request.post({ url: rootURL, formData: payload }, function onResponse(err) { const msg = err ? `Post to Routes stash failed: ${err}` : `Route registered. Site deploying to include it. ${rootURL}${code}` diff --git a/src/functions-templates/js/url-shortener/get-route.js b/src/functions-templates/js/url-shortener/get-route.js index 5903afd54ad..7553efeb9b2 100644 --- a/src/functions-templates/js/url-shortener/get-route.js +++ b/src/functions-templates/js/url-shortener/get-route.js @@ -13,7 +13,7 @@ module.exports = function handler(event, context, callback) { '/submissions/?access_token=' + process.env.API_AUTH - request(url, function (err, response, body) { + request(url, function onResponse(err, response, body) { // look for this code in our stash if (!err && response.statusCode === 200) { const routes = JSON.parse(body) diff --git a/src/functions-templates/js/url-shortener/url-shortener.js b/src/functions-templates/js/url-shortener/url-shortener.js index 8db3c093e11..aa8e85fd93d 100644 --- a/src/functions-templates/js/url-shortener/url-shortener.js +++ b/src/functions-templates/js/url-shortener/url-shortener.js @@ -1,4 +1,4 @@ -exports.handler = (event, context, callback) => { +const handler = (event, context, callback) => { const path = event.path.replace(/\.netlify\/functions\/[^/]+/, '') const segments = path.split('/').filter((e) => e) console.log('segments', segments) @@ -20,3 +20,5 @@ exports.handler = (event, context, callback) => { return callback(new Error('unrecognized HTTP Method, must be one of GET/POST/PUT/DELETE')) } } + +module.exports = { handler } diff --git a/src/functions-templates/js/using-middleware/using-middleware.js b/src/functions-templates/js/using-middleware/using-middleware.js index e48938f2374..52d1827bd63 100644 --- a/src/functions-templates/js/using-middleware/using-middleware.js +++ b/src/functions-templates/js/using-middleware/using-middleware.js @@ -14,7 +14,7 @@ const businessLogic = (event, context, callback) => { }) } -/* Input & Output Schema */ +/* Export inputSchema & outputSchema for automatic documentation */ const schema = { input: { type: 'object', @@ -45,10 +45,7 @@ const schema = { }, } -/* Export inputSchema & outputSchema for automatic documentation */ -exports.schema = schema - -exports.handler = middy(businessLogic) +const handler = middy(businessLogic) .use(httpHeaderNormalizer()) // parses the request body when it's a JSON and converts it to an object .use(jsonBodyParser()) @@ -56,3 +53,8 @@ exports.handler = middy(businessLogic) .use(validator({ inputSchema: schema.input })) // handles common http errors and returns proper responses .use(httpErrorHandler()) + +module.exports = { + schema, + handler, +} diff --git a/src/hooks/init.js b/src/hooks/init.js index 9db921bac41..f2f3c7228f7 100644 --- a/src/hooks/init.js +++ b/src/hooks/init.js @@ -3,7 +3,7 @@ const header = require('../utils/header') const globalConfig = require('../utils/global-config') const { track } = require('../utils/telemetry') -module.exports = async (context) => { +module.exports = async function initHooks(context) { // Enable/disable telemetry Global flags. TODO refactor where these fire if (context.id === '--telemetry-disable') { globalConfig.set('telemetryDisabled', true) diff --git a/src/lib/http-agent.test.js b/src/lib/http-agent.test.js index 145f9640e50..82dad9a785f 100644 --- a/src/lib/http-agent.test.js +++ b/src/lib/http-agent.test.js @@ -48,7 +48,7 @@ test(`should exit with error when proxy is no available`, async (t) => { test(`should return agent for a valid proxy`, async (t) => { const proxy = httpProxy.createProxyServer() - const server = http.createServer(function (req, res) { + const server = http.createServer(function onRequest(req, res) { proxy.web(req, res, { target: 'http://localhost:5555' }) }) diff --git a/src/utils/addons/diffs/options.js b/src/utils/addons/diffs/options.js index 9b9200d46f0..6b97897f5d2 100644 --- a/src/utils/addons/diffs/options.js +++ b/src/utils/addons/diffs/options.js @@ -105,5 +105,10 @@ const colorTheme = { const plugins = [] const theme = colorTheme -module.exports.concordanceOptions = { maxDepth: 3, plugins, theme } -module.exports.concordanceDiffOptions = { maxDepth: 1, plugins, theme } +const concordanceOptions = { maxDepth: 3, plugins, theme } +const concordanceDiffOptions = { maxDepth: 1, plugins, theme } + +module.exports = { + concordanceOptions, + concordanceDiffOptions, +} diff --git a/src/utils/addons/prompts.js b/src/utils/addons/prompts.js index cee2543fa5b..f5dd9475405 100644 --- a/src/utils/addons/prompts.js +++ b/src/utils/addons/prompts.js @@ -82,7 +82,7 @@ function noValidate() { // } function validate(pattern) { - return function (value) { + return function validateValue(value) { const regex = new RegExp(pattern) if (value.match(regex)) { return true diff --git a/src/utils/addons/validation.js b/src/utils/addons/validation.js index 23b38ef0c41..30eee81dc85 100644 --- a/src/utils/addons/validation.js +++ b/src/utils/addons/validation.js @@ -1,16 +1,16 @@ -module.exports.requiredConfigValues = function requiredConfigValues(config) { +const requiredConfigValues = function (config) { return Object.keys(config).filter((key) => { return config[key].required }) } -module.exports.missingConfigValues = function missingConfigValues(requiredConfig, providedConfig) { +const missingConfigValues = function (requiredConfig, providedConfig) { return requiredConfig.filter((key) => { return !providedConfig[key] }) } -module.exports.updateConfigValues = function updateConfigValues(allowedConfig, currentConfig, newConfig) { +const updateConfigValues = function (allowedConfig, currentConfig, newConfig) { return Object.keys(allowedConfig).reduce((acc, key) => { if (newConfig[key]) { acc[key] = newConfig[key] @@ -20,3 +20,9 @@ module.exports.updateConfigValues = function updateConfigValues(allowedConfig, c return acc }, {}) } + +module.exports = { + requiredConfigValues, + missingConfigValues, + updateConfigValues, +} diff --git a/src/utils/create-stream-promise.js b/src/utils/create-stream-promise.js index 110aae152f2..a1c740e1f6b 100644 --- a/src/utils/create-stream-promise.js +++ b/src/utils/create-stream-promise.js @@ -1,5 +1,5 @@ function createStreamPromise(stream, timeoutSeconds, bytesLimit = 1024 * 1024 * 6) { - return new Promise(function (resolve, reject) { + return new Promise(function streamPromiseFunc(resolve, reject) { let data = [] let dataLength = 0 @@ -11,7 +11,7 @@ function createStreamPromise(stream, timeoutSeconds, bytesLimit = 1024 * 1024 * }, timeoutSeconds * 1000) } - stream.on('data', function (chunk) { + stream.on('data', function onData(chunk) { if (!Array.isArray(data)) { // Stream harvesting closed return @@ -25,12 +25,12 @@ function createStreamPromise(stream, timeoutSeconds, bytesLimit = 1024 * 1024 * } }) - stream.on('error', function (error) { + stream.on('error', function onError(error) { data = null reject(error) clearTimeout(timeoutId) }) - stream.on('end', function () { + stream.on('end', function onEnd() { clearTimeout(timeoutId) if (data) { resolve(Buffer.concat(data)) diff --git a/src/utils/detect-functions-builder.js b/src/utils/detect-functions-builder.js index a555a52d351..0aa96ac5055 100644 --- a/src/utils/detect-functions-builder.js +++ b/src/utils/detect-functions-builder.js @@ -1,6 +1,6 @@ const path = require('path') -module.exports.detectFunctionsBuilder = async function (projectDir) { +const detectFunctionsBuilder = async function (projectDir) { const detectors = require('fs') .readdirSync(path.join(__dirname, '..', 'function-builder-detectors')) .filter((x) => x.endsWith('.js')) // only accept .js detector files @@ -13,3 +13,5 @@ module.exports.detectFunctionsBuilder = async function (projectDir) { } } } + +module.exports = { detectFunctionsBuilder } diff --git a/src/utils/detect-server.js b/src/utils/detect-server.js index c29b24117eb..e3363faeab6 100644 --- a/src/utils/detect-server.js +++ b/src/utils/detect-server.js @@ -6,7 +6,7 @@ const inquirer = require('inquirer') const fuzzy = require('fuzzy') const fs = require('fs') -module.exports.serverSettings = async (devConfig, flags, projectDir, log) => { +const serverSettings = async (devConfig, flags, projectDir, log) => { let settings = {} const detectorsFiles = fs.readdirSync(path.join(__dirname, '..', 'detectors')).filter((x) => x.endsWith('.js')) // only accept .js detector files @@ -208,7 +208,6 @@ function loadDetector(detectorName) { ) } } -module.exports.loadDetector = loadDetector function chooseDefaultArgs(possibleArgsArrs) { // vast majority of projects will only have one matching detector @@ -225,7 +224,6 @@ function chooseDefaultArgs(possibleArgsArrs) { return args } -module.exports.chooseDefaultArgs = chooseDefaultArgs /** utilities for the inquirer section above */ function filterSettings(scriptInquirerOptions, input) { @@ -249,3 +247,9 @@ function formatSettingsArrForInquirer(settingsArr) { ) ) } + +module.exports = { + serverSettings, + loadDetector, + chooseDefaultArgs, +} diff --git a/src/utils/env.js b/src/utils/env.js index 194ec1ae6f2..6748fb751a2 100644 --- a/src/utils/env.js +++ b/src/utils/env.js @@ -33,4 +33,4 @@ async function getEnvSettings({ projectDir, warn }) { return { files, vars } } -module.exports.getEnvSettings = getEnvSettings +module.exports = { getEnvSettings } diff --git a/src/utils/gh-auth.js b/src/utils/gh-auth.js index ce8530c482e..d4c6d20debd 100644 --- a/src/utils/gh-auth.js +++ b/src/utils/gh-auth.js @@ -50,12 +50,12 @@ async function getGitHubToken({ opts, log }) { const port = await getPort({ port: 3000 }) let deferredResolve let deferredReject - const deferredPromise = new Promise(function (resolve, reject) { + const deferredPromise = new Promise(function deferred(resolve, reject) { deferredResolve = resolve deferredReject = reject }) - const server = http.createServer(function (req, res) { + const server = http.createServer(function onRequest(req, res) { const parameters = querystring.parse(req.url.slice(req.url.indexOf('?') + 1)) if (parameters.token) { deferredResolve(parameters) @@ -73,7 +73,7 @@ async function getGitHubToken({ opts, log }) { deferredReject(new Error('Got invalid parameters for CLI login')) }) - await new Promise(function (resolve, reject) { + await new Promise(function waitForListening(resolve, reject) { server.on('error', reject) server.listen(port, resolve) }) diff --git a/src/utils/parse-raw-flags.js b/src/utils/parse-raw-flags.js index 7e1d5e9b586..da242a7014f 100644 --- a/src/utils/parse-raw-flags.js +++ b/src/utils/parse-raw-flags.js @@ -10,7 +10,6 @@ // // rawFlags = {stuff: yay!} // -exports.parseRawFlags = parseRawFlags function parseRawFlags(raw) { const rawFlags = raw.reduce((acc, curr, index, array) => { if (curr.input.match(/^-{1,2}/)) { @@ -29,7 +28,6 @@ function parseRawFlags(raw) { return rawFlags } -exports.aggressiveJSONParse = aggressiveJSONParse function aggressiveJSONParse(value) { if (value === 'true') { return true @@ -49,3 +47,8 @@ function aggressiveJSONParse(value) { } return parsed } + +module.exports = { + parseRawFlags, + aggressiveJSONParse, +} diff --git a/src/utils/proxy.js b/src/utils/proxy.js index 46897199fd3..0156c5bd16d 100644 --- a/src/utils/proxy.js +++ b/src/utils/proxy.js @@ -273,10 +273,10 @@ function initializeProxy(port, distDir, projectDir) { }) } res.writeHead(req.proxyOptions.status || proxyRes.statusCode, proxyRes.headers) - proxyRes.on('data', function (data) { + proxyRes.on('data', function onData(data) { res.write(data) }) - proxyRes.on('end', function () { + proxyRes.on('end', function onEnd() { res.end() }) }) @@ -308,7 +308,7 @@ async function startProxy(settings = {}, addonUrls, configPath, projectDir) { projectDir, }) - const server = http.createServer(async function (req, res) { + const server = http.createServer(async function onRequest(req, res) { req.originalBody = ['GET', 'OPTIONS', 'HEAD'].includes(req.method) ? null : await createStreamPromise(req, 30) if (isFunction(settings.functionsPort, req.url)) { @@ -346,7 +346,7 @@ async function startProxy(settings = {}, addonUrls, configPath, projectDir) { }) }) - server.on('upgrade', function (req, socket, head) { + server.on('upgrade', function onUpgrade(req, socket, head) { proxy.ws(req, socket, head) }) diff --git a/src/utils/rules-proxy.js b/src/utils/rules-proxy.js index b7e16398a59..50a98dcb698 100644 --- a/src/utils/rules-proxy.js +++ b/src/utils/rules-proxy.js @@ -24,15 +24,11 @@ async function parseFile(filePath) { return success } -module.exports.parseFile = parseFile - async function parseRules(configFiles) { const results = await Promise.all(configFiles.map(parseFile)) return [].concat(...results) } -module.exports.parseRules = parseRules - function onChanges(files, cb) { files.forEach((file) => { const watcher = chokidar.watch(file) @@ -41,8 +37,6 @@ function onChanges(files, cb) { }) } -module.exports.onChanges = onChanges - function getLanguage(headers) { if (headers['accept-language']) { return headers['accept-language'].split(',')[0].slice(0, 2) @@ -50,13 +44,11 @@ function getLanguage(headers) { return 'en' } -module.exports.getLanguage = getLanguage - function getCountry() { return 'us' } -module.exports.createRewriter = async function createRewriter({ distDir, projectDir, jwtSecret, jwtRole, configPath }) { +const createRewriter = async function ({ distDir, projectDir, jwtSecret, jwtRole, configPath }) { let matcher = null const configFiles = [ ...new Set( @@ -92,7 +84,7 @@ module.exports.createRewriter = async function createRewriter({ distDir, project } } - return function (req, res, next) { + return function rewriter(req, res, next) { getMatcher().then((matcher) => { const reqUrl = new url.URL( req.url, @@ -125,3 +117,11 @@ module.exports.createRewriter = async function createRewriter({ distDir, project }) } } + +module.exports = { + parseFile, + parseRules, + onChanges, + getLanguage, + createRewriter, +} diff --git a/src/utils/serve-functions.js b/src/utils/serve-functions.js index a6e40f44ca6..80994d7451c 100644 --- a/src/utils/serve-functions.js +++ b/src/utils/serve-functions.js @@ -30,7 +30,7 @@ function capitalize(t) { /** need to keep createCallback in scope so we can know if cb was called AND handler is async */ function createCallback(response) { - return function (err, lambdaResponse) { + return function callbackHandler(err, lambdaResponse) { if (err) { return handleErr(err, response) } @@ -117,13 +117,11 @@ function createHandler(dir) { }) lambdaLocal.setLogger(logger) - return function (request, response) { + return function handler(request, response) { // handle proxies without path re-writes (http-servr) const cleanPath = request.path.replace(/^\/.netlify\/functions/, '') - const func = cleanPath.split('/').find(function (e) { - return e - }) + const func = cleanPath.split('/').find(Boolean) if (!functions[func]) { response.statusCode = 404 response.end('Function not found...') @@ -179,7 +177,7 @@ function createHandler(dir) { } function createFormSubmissionHandler(siteInfo) { - return async function (req, res, next) { + return async function formSubmissionHandler(req, res, next) { if (req.url.startsWith('/.netlify/') || req.method !== 'POST') return next() const fakeRequest = new Readable({ @@ -307,7 +305,7 @@ function serveFunctions(dir, siteInfo = {}) { }) ) - app.get('/favicon.ico', function (req, res) { + app.get('/favicon.ico', function onRequest(req, res) { res.status(204).end() }) diff --git a/tests/rules-proxy.test.js b/tests/rules-proxy.test.js index 6a13688f19d..8234577e0a1 100644 --- a/tests/rules-proxy.test.js +++ b/tests/rules-proxy.test.js @@ -21,7 +21,7 @@ test.before(async (t) => { configPath: path.join(builder.directory, 'netlify.toml'), }) const port = await getPort({ port: 8888 }) - const server = http.createServer(function (req, res) { + const server = http.createServer(function onRequest(req, res) { rewriter(req, res, (match) => res.end(JSON.stringify(match))) }) diff --git a/tests/site-cra/functions/echo.js b/tests/site-cra/functions/echo.js index f2ca9e72805..5cc99520cc7 100644 --- a/tests/site-cra/functions/echo.js +++ b/tests/site-cra/functions/echo.js @@ -1,6 +1,8 @@ -exports.handler = async (event, context) => { +const handler = async (event, context) => { return { statusCode: 200, body: JSON.stringify(event), } } + +module.exports = { handler } diff --git a/tests/utils/external-server.js b/tests/utils/external-server.js index eedf82f3f3e..96ea677bdb5 100644 --- a/tests/utils/external-server.js +++ b/tests/utils/external-server.js @@ -4,7 +4,7 @@ const bodyParser = require('body-parser') const startExternalServer = () => { const app = express() app.use(bodyParser.urlencoded({ extended: true })) - app.all('*', function (req, res) { + app.all('*', function onRequest(req, res) { res.json({ url: req.url, body: req.body, method: req.method }) })