Skip to content

Commit

Permalink
handle symlinked and npm installed directory name
Browse files Browse the repository at this point in the history
  • Loading branch information
Courey committed Jun 12, 2024
1 parent 735c443 commit 7d51368
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { spawn, untilTerminated } from './processes.js'
import type { SandboxEngine } from './engines.js'
import { UnexpectedResolveError, neverResolve } from './promises.js'
import { fork } from 'child_process'
import path from 'path'
import { fileURLToPath } from 'url'

type SearchEngineLauncherFunction<T = object> = (
props: T & {
Expand Down Expand Up @@ -56,6 +58,13 @@ const launchBinary: SearchEngineLauncherFunction<{ bin: string }> = async ({
}
}

function directoryName() {
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
return __dirname.includes('node_modules')
? __dirname
: './node_modules/@nasa-gcn/architect-plugin-search'
}
const launchDocker: SearchEngineLauncherFunction = async ({
dataDir,
logsDir,
Expand All @@ -70,25 +79,22 @@ const launchDocker: SearchEngineLauncherFunction = async ({
port,
options,
}
const subprocess = fork(
'./node_modules/@nasa-gcn/architect-plugin-search/launchSearch.js',
[JSON.stringify(argv)]
)

const waitUntilStopped = new Promise<void>((resolve) => {
subprocess.on('exit', () => {
console.log('Docker container exited')
resolve()
})
})
const subprocess = fork(`${directoryName()}/launchSearch.js`, [
JSON.stringify(argv),
])

return {
async kill() {
console.log('Killing Docker container')
subprocess.send({ action: 'kill' })
},
async waitUntilStopped() {
await waitUntilStopped
return new Promise<void>((resolve) => {
subprocess.on('exit', () => {
console.log('Docker container exited')
resolve()
})
})
},
}
}
Expand Down

0 comments on commit 7d51368

Please sign in to comment.