@@ -4,7 +4,7 @@ const flatten = require('lodash.flatten')
44const 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