1
+ import type { Subprocess } from 'bun'
2
+ import type { LaunchOptions } from './types'
1
3
import * as fs from 'node:fs'
2
4
import * as https from 'node:https'
3
5
import * as path from 'node:path'
4
6
import process from 'node:process'
5
7
import { promisify } from 'node:util'
6
8
import * as zlib from 'node:zlib'
7
- import type { Subprocess } from 'bun'
8
9
import Debug from 'debug'
9
10
import * as tar from 'tar'
10
11
import { config } from './config'
11
- import type { LaunchOptions } from './types'
12
12
import { exists } from './utils'
13
13
14
14
const debug = Debug ( 'dynamodb-local' )
@@ -27,7 +27,8 @@ export const dynamoDb = {
27
27
javaOpts = '' ,
28
28
} = options ?? { }
29
29
30
- if ( runningProcesses [ port ] ) return runningProcesses [ port ]
30
+ if ( runningProcesses [ port ] )
31
+ return runningProcesses [ port ]
31
32
32
33
const args = [
33
34
'-Xrs' ,
@@ -53,18 +54,23 @@ export const dynamoDb = {
53
54
const child = Bun . spawn ( [ 'java' , ...args ] , {
54
55
cwd : config . installPath ,
55
56
onExit : ( proc , exitCode , signalCode , error ) => {
56
- if ( exitCode !== 0 && verbose ) debug ( 'Local DynamoDB exit code:' , exitCode )
57
- if ( error ) debug ( 'Local DynamoDB error:' , error )
57
+ if ( exitCode !== 0 && verbose )
58
+ debug ( 'Local DynamoDB exit code:' , exitCode )
59
+ if ( error )
60
+ debug ( 'Local DynamoDB error:' , error )
58
61
} ,
59
62
} )
60
63
61
- if ( ! child . pid ) throw new Error ( 'Unable to launch DynamoDBLocal process' )
64
+ if ( ! child . pid )
65
+ throw new Error ( 'Unable to launch DynamoDBLocal process' )
62
66
63
- if ( ! detached ) process . on ( 'exit' , ( ) => child . kill ( ) )
67
+ if ( ! detached )
68
+ process . on ( 'exit' , ( ) => child . kill ( ) )
64
69
65
70
runningProcesses [ port ] = child
66
71
return child
67
- } catch ( error ) {
72
+ }
73
+ catch ( error ) {
68
74
debug ( 'Error launching DynamoDB Local:' , error )
69
75
throw error
70
76
}
@@ -80,12 +86,15 @@ export const dynamoDb = {
80
86
81
87
async install ( ) : Promise < void > {
82
88
const installPathExists = await exists ( config . installPath )
83
- if ( ! installPathExists ) await promisify ( fs . mkdir ) ( config . installPath )
89
+ if ( ! installPathExists )
90
+ await promisify ( fs . mkdir ) ( config . installPath )
84
91
85
92
const jarPath = path . join ( config . installPath , JARNAME )
86
93
const jarExists = await exists ( jarPath )
87
- if ( jarExists ) return
94
+ if ( jarExists )
95
+ return
88
96
97
+ // eslint-disable-next-line no-console
89
98
console . log ( 'Installing DynamoDB locally...' )
90
99
const downloadUrl = config . downloadUrl
91
100
await new Promise ( ( resolve , reject ) => {
0 commit comments