11import fs from 'node:fs'
22import path from 'node:path'
3- import { until } from '@open-draft/ until'
3+ import { until } from 'until-async '
44
55/**
66 * Copies the given Service Worker source file into the destination.
@@ -11,20 +11,23 @@ export default async function copyServiceWorker(
1111 destFilePath : string ,
1212 checksum : string ,
1313) : Promise < void > {
14+ // eslint-disable-next-line no-console
1415 console . log ( 'Compiling Service Worker...' )
1516
16- const readFileResult = await until ( ( ) =>
17+ const [ readFileError , readFileResult ] = await until ( ( ) =>
1718 fs . promises . readFile ( sourceFilePath , 'utf8' ) ,
1819 )
1920
20- if ( readFileResult . error ) {
21+ if ( readFileError ) {
2122 throw new Error ( 'Failed to read file.\n${readError.message}' )
2223 }
2324
2425 const destFileDirectory = path . dirname ( destFilePath )
26+ // eslint-disable-next-line no-console
2527 console . log ( 'Checking if "%s" path exists...' , destFileDirectory )
2628
2729 if ( ! fs . existsSync ( destFileDirectory ) ) {
30+ // eslint-disable-next-line no-console
2831 console . log ( 'Destination directory does not exist, creating...' )
2932 await fs . promises . mkdir ( destFileDirectory , { recursive : true } )
3033 }
@@ -33,17 +36,18 @@ export default async function copyServiceWorker(
3336 fs . readFileSync ( new URL ( '../package.json' , import . meta. url ) , 'utf8' ) ,
3437 )
3538
36- const nextFileContent = readFileResult . data
39+ const nextFileContent = readFileResult
3740 . replace ( '<INTEGRITY_CHECKSUM>' , checksum )
3841 . replace ( '<PACKAGE_VERSION>' , packageJson . version )
3942
40- const writeFileResult = await until ( ( ) =>
43+ const [ writeFileError ] = await until ( ( ) =>
4144 fs . promises . writeFile ( destFilePath , nextFileContent ) ,
4245 )
4346
44- if ( writeFileResult . error ) {
45- throw new Error ( `Failed to write file.\n${ writeFileResult . error . message } ` )
47+ if ( writeFileError ) {
48+ throw new Error ( `Failed to write file.\n${ writeFileError . message } ` )
4649 }
4750
51+ // eslint-disable-next-line no-console
4852 console . log ( 'Service Worker copied to: %s' , destFilePath )
4953}
0 commit comments