Skip to content
This repository was archived by the owner on Oct 10, 2022. It is now read-only.

Commit 325f9d7

Browse files
committed
Enable several ESLint rules
1 parent 7cba651 commit 325f9d7

File tree

11 files changed

+78
-66
lines changed

11 files changed

+78
-66
lines changed

.eslintrc.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ module.exports = {
77
'array-callback-return': 0,
88
complexity: 0,
99
'consistent-this': 0,
10-
'func-names': 0,
11-
'func-style': 0,
1210
'id-length': 0,
1311
'line-comment-position': 0,
1412
'max-nested-callbacks': 0,
@@ -17,7 +15,6 @@ module.exports = {
1715
'no-inline-comments': 0,
1816
'no-magic-numbers': 0,
1917
'no-param-reassign': 0,
20-
'no-promise-executor-return': 0,
2118
'no-shadow': 0,
2219
'fp/no-class': 0,
2320
'fp/no-delete': 0,
@@ -27,7 +24,6 @@ module.exports = {
2724
'fp/no-mutating-methods': 0,
2825
'fp/no-mutation': 0,
2926
'fp/no-this': 0,
30-
'node/exports-style': 0,
3127
'node/global-require': 0,
3228
'node/prefer-global/process': 0,
3329
'promise/no-callback-in-promise': 0,

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const opts = {
124124
All operations are conveniently consumed with async/await:
125125

126126
```js
127-
async function getSomeData() {
127+
const getSomeData = async () => {
128128
// Calls may fail!
129129
try {
130130
return await client.getSiteDeploy({
@@ -163,7 +163,7 @@ See the [authenticating](https://www.netlify.com/docs/api/#authenticating) docs
163163

164164
```js
165165
// example:
166-
async function login() {
166+
const login = async () => {
167167
const ticket = await api.createTicket({
168168
clientId: CLIENT_ID,
169169
})

src/addons.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
const fetch = require('node-fetch')
55

6-
async function createAddon(settings, netlifyApiToken) {
6+
const createAddon = async (settings, netlifyApiToken) => {
77
const { siteId, addon, config } = settings
88
const url = `https://api.netlify.com/api/v1/sites/${siteId}/services/${addon}/instances`
99
const response = await fetch(url, {
@@ -26,7 +26,7 @@ async function createAddon(settings, netlifyApiToken) {
2626
return data
2727
}
2828

29-
async function getAddons(siteId, netlifyApiToken) {
29+
const getAddons = async (siteId, netlifyApiToken) => {
3030
const url = `https://api.netlify.com/api/v1/sites/${siteId}/service-instances`
3131
const response = await fetch(url, {
3232
method: 'GET',
@@ -45,7 +45,7 @@ async function getAddons(siteId, netlifyApiToken) {
4545
return data
4646
}
4747

48-
async function deleteAddon(settings, netlifyApiToken) {
48+
const deleteAddon = async (settings, netlifyApiToken) => {
4949
const { siteId, addon, instanceId } = settings
5050
const url = `https://api.netlify.com/api/v1/sites/${siteId}/services/${addon}/instances/${instanceId}`
5151
const response = await fetch(url, {
@@ -64,7 +64,7 @@ async function deleteAddon(settings, netlifyApiToken) {
6464
return response
6565
}
6666

67-
async function updateAddon(settings, netlifyApiToken) {
67+
const updateAddon = async (settings, netlifyApiToken) => {
6868
const { siteId, addon, config, instanceId } = settings
6969
const url = `https://api.netlify.com/api/v1/sites/${siteId}/services/${addon}/instances/${instanceId}`
7070

src/deploy/hash-files.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ const pump = promisify(require('pump'))
55

66
const { hasherCtor, manifestCollectorCtor, fileFilterCtor, fileNormalizerCtor } = require('./hasher-segments')
77

8-
module.exports = hashFiles
9-
async function hashFiles(dir, configPath, opts) {
8+
const hashFiles = async (dir, configPath, opts) => {
109
opts = {
1110
concurrentHash: 100,
1211
assetType: 'file',
@@ -29,3 +28,5 @@ async function hashFiles(dir, configPath, opts) {
2928

3029
return { files, filesShaMap }
3130
}
31+
32+
module.exports = hashFiles

src/deploy/hash-fns.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ const pump = promisify(require('pump'))
77

88
const { hasherCtor, manifestCollectorCtor } = require('./hasher-segments')
99

10-
module.exports = hashFns
11-
async function hashFns(dir, opts) {
10+
const hashFns = async (dir, opts) => {
1211
opts = {
1312
concurrentHash: 100,
1413
assetType: 'function',
@@ -48,3 +47,5 @@ async function hashFns(dir, opts) {
4847

4948
return { functions, fnShaMap }
5049
}
50+
51+
module.exports = hashFns

src/deploy/hasher-segments.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const map = require('through2-map').obj
77
const { normalizePath } = require('./util')
88

99
// a parallel transform stream segment ctor that hashes fileObj's created by folder-walker
10-
exports.hasherCtor = ({ concurrentHash, hashAlgorithm = 'sha1' }) => {
10+
const hasherCtor = ({ concurrentHash, hashAlgorithm = 'sha1' }) => {
1111
const hashaOpts = { algorithm: hashAlgorithm }
1212
if (!concurrentHash) throw new Error('Missing required opts')
1313
return transform(concurrentHash, { objectMode: true }, (fileObj, cb) => {
@@ -20,13 +20,11 @@ exports.hasherCtor = ({ concurrentHash, hashAlgorithm = 'sha1' }) => {
2020
}
2121

2222
// Inject normalized file names into normalizedPath and assetType
23-
exports.fileNormalizerCtor = fileNormalizerCtor
24-
function fileNormalizerCtor({ assetType = 'file' }) {
25-
return map((fileObj) => ({ ...fileObj, assetType, normalizedPath: normalizePath(fileObj.relname) }))
26-
}
23+
const fileNormalizerCtor = ({ assetType = 'file' }) =>
24+
map((fileObj) => ({ ...fileObj, assetType, normalizedPath: normalizePath(fileObj.relname) }))
2725

2826
// A writable stream segment ctor that normalizes file paths, and writes shaMap's
29-
exports.manifestCollectorCtor = (filesObj, shaMap, { statusCb, assetType }) => {
27+
const manifestCollectorCtor = (filesObj, shaMap, { statusCb, assetType }) => {
3028
if (!statusCb || !assetType) throw new Error('Missing required options')
3129
return objWriter((fileObj, _, cb) => {
3230
filesObj[fileObj.normalizedPath] = fileObj.hash
@@ -49,4 +47,11 @@ exports.manifestCollectorCtor = (filesObj, shaMap, { statusCb, assetType }) => {
4947
}
5048

5149
// transform stream ctor that filters folder-walker results for only files
52-
exports.fileFilterCtor = objFilterCtor((fileObj) => fileObj.type === 'file')
50+
const fileFilterCtor = objFilterCtor((fileObj) => fileObj.type === 'file')
51+
52+
module.exports = {
53+
hasherCtor,
54+
fileNormalizerCtor,
55+
manifestCollectorCtor,
56+
fileFilterCtor,
57+
}

src/deploy/index.browser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module.exports = browserDeploy
2-
3-
function browserDeploy() {
1+
const browserDeploy = function () {
42
throw new Error('Deploys not supported in the browser')
53
}
4+
5+
module.exports = browserDeploy

src/deploy/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const uploadFiles = require('./upload-files')
1010
const { waitForDiff } = require('./util')
1111
const { waitForDeploy, getUploadList, defaultFilter } = require('./util')
1212

13-
module.exports = async (api, siteId, dir, opts) => {
13+
const deploySite = async (api, siteId, dir, opts) => {
1414
opts = {
1515
fnDir: null,
1616
configPath: null,
@@ -128,3 +128,5 @@ module.exports = async (api, siteId, dir, opts) => {
128128
}
129129
return deployManifest
130130
}
131+
132+
module.exports = deploySite

src/deploy/upload-files.js

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ const fs = require('fs')
33
const backoff = require('backoff')
44
const pMap = require('p-map')
55

6-
module.exports = uploadFiles
7-
async function uploadFiles(api, deployId, uploadList, { concurrentUpload, statusCb, maxRetry }) {
6+
const uploadFiles = async (api, deployId, uploadList, { concurrentUpload, statusCb, maxRetry }) => {
87
if (!concurrentUpload || !statusCb || !maxRetry) throw new Error('Missing required option concurrentUpload')
98
statusCb({
109
type: 'upload',
@@ -67,28 +66,16 @@ async function uploadFiles(api, deployId, uploadList, { concurrentUpload, status
6766
return results
6867
}
6968

70-
function retryUpload(uploadFn, maxRetry) {
71-
return new Promise((resolve, reject) => {
69+
const retryUpload = (uploadFn, maxRetry) =>
70+
new Promise((resolve, reject) => {
7271
let lastError
7372
const fibonacciBackoff = backoff.fibonacci({
7473
randomisationFactor: 0.5,
7574
initialDelay: 5000,
7675
maxDelay: 90000,
7776
})
78-
fibonacciBackoff.failAfter(maxRetry)
79-
80-
fibonacciBackoff.on('backoff', () => {
81-
// Do something when backoff starts, e.g. show to the
82-
// user the delay before next reconnection attempt.
83-
})
84-
85-
fibonacciBackoff.on('ready', tryUpload)
8677

87-
fibonacciBackoff.on('fail', () => {
88-
reject(lastError)
89-
})
90-
91-
function tryUpload() {
78+
const tryUpload = () => {
9279
uploadFn()
9380
.then((results) => resolve(results))
9481
.catch((error) => {
@@ -105,6 +92,20 @@ function retryUpload(uploadFn, maxRetry) {
10592
})
10693
}
10794

95+
fibonacciBackoff.failAfter(maxRetry)
96+
97+
fibonacciBackoff.on('backoff', () => {
98+
// Do something when backoff starts, e.g. show to the
99+
// user the delay before next reconnection attempt.
100+
})
101+
102+
fibonacciBackoff.on('ready', tryUpload)
103+
104+
fibonacciBackoff.on('fail', () => {
105+
reject(lastError)
106+
})
107+
108108
tryUpload(0, 0)
109109
})
110-
}
110+
111+
module.exports = { uploadFiles }

src/deploy/util.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const flatten = require('lodash.flatten')
44
const pWaitFor = require('p-wait-for')
55

66
// Default filter when scanning for files
7-
exports.defaultFilter = (filename) => {
7+
const defaultFilter = (filename) => {
88
if (filename == null) return false
99
const n = path.basename(filename)
1010
switch (true) {
@@ -18,7 +18,7 @@ exports.defaultFilter = (filename) => {
1818
}
1919

2020
// normalize windows paths to unix paths
21-
exports.normalizePath = (relname) => {
21+
const normalizePath = (relname) => {
2222
if (relname.includes('#') || relname.includes('?')) {
2323
throw new Error(`Invalid filename ${relname}. Deployed filenames cannot contain # or ? characters`)
2424
}
@@ -30,20 +30,11 @@ exports.normalizePath = (relname) => {
3030
)
3131
}
3232

33-
exports.waitForDiff = waitForDiff
3433
// poll an async deployId until its done diffing
35-
async function waitForDiff(api, deployId, siteId, timeout) {
34+
const waitForDiff = async (api, deployId, siteId, timeout) => {
3635
let deploy // capture ready deploy during poll
3736

38-
await pWaitFor(loadDeploy, {
39-
interval: 1000,
40-
timeout,
41-
message: 'Timeout while waiting for deploy',
42-
})
43-
44-
return deploy
45-
46-
async function loadDeploy() {
37+
const loadDeploy = async () => {
4738
const d = await api.getSiteDeploy({ siteId, deployId })
4839

4940
switch (d.state) {
@@ -66,12 +57,6 @@ async function waitForDiff(api, deployId, siteId, timeout) {
6657
}
6758
}
6859
}
69-
}
70-
71-
// Poll a deployId until its ready
72-
exports.waitForDeploy = waitForDeploy
73-
async function waitForDeploy(api, deployId, siteId, timeout) {
74-
let deploy // capture ready deploy during poll
7560

7661
await pWaitFor(loadDeploy, {
7762
interval: 1000,
@@ -80,8 +65,13 @@ async function waitForDeploy(api, deployId, siteId, timeout) {
8065
})
8166

8267
return deploy
68+
}
8369

84-
async function loadDeploy() {
70+
// Poll a deployId until its ready
71+
const waitForDeploy = async (api, deployId, siteId, timeout) => {
72+
let deploy // capture ready deploy during poll
73+
74+
const loadDeploy = async () => {
8575
const d = await api.getSiteDeploy({ siteId, deployId })
8676
switch (d.state) {
8777
// https://github.com/netlify/bitballoon/blob/master/app/models/deploy.rb#L21-L33
@@ -103,12 +93,26 @@ async function waitForDeploy(api, deployId, siteId, timeout) {
10393
}
10494
}
10595
}
96+
97+
await pWaitFor(loadDeploy, {
98+
interval: 1000,
99+
timeout,
100+
message: 'Timeout while waiting for deploy',
101+
})
102+
103+
return deploy
106104
}
107105

108106
// Transform the fileShaMap and fnShaMap into a generic shaMap that file-uploader.js can use
109-
exports.getUploadList = function (required, shaMap) {
107+
const getUploadList = (required, shaMap) => {
110108
if (!required || !shaMap) return []
111109
return flatten(required.map((sha) => shaMap[sha]))
112110
}
113111

114-
exports.retry = async () => {}
112+
module.exports = {
113+
defaultFilter,
114+
normalizePath,
115+
waitForDiff,
116+
waitForDeploy,
117+
getUploadList,
118+
}

0 commit comments

Comments
 (0)