@sjcrh/proteinpaint-server 2.109.0 → 2.109.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,13 +5,19 @@
5
5
 
6
6
  import fs from 'fs'
7
7
  import path from 'path'
8
+ import { fileURLToPath } from 'url'
9
+
10
+ // import.meta.dirname is undefined when using docker dev environment
11
+ // use __dirname and __filename global variable convention from commonjs
12
+ const __dirname = import.meta.dirname || (new URL('.', import.meta.url)).pathname
13
+ const __filename = import.meta.filename || fileURLToPath(import.meta.url)
8
14
 
9
15
  // do not assume that serverconfig.json is in the same dir as server.js
10
16
  // for example, when using proteinpaint as an npm module or binary
11
17
  // or when calling a pp utility script from a tp data directory
12
18
  const workdirconfig = process.cwd() ? process.cwd() + '/serverconfig.json' : ''
13
- const serverdirconfig = path.join(import.meta.dirname, '../serverconfig.json')
14
- const pprootdirconfig = path.join(import.meta.dirname, '../../serverconfig.json')
19
+ const serverdirconfig = path.join(__dirname, '../serverconfig.json')
20
+ const pprootdirconfig = path.join(__dirname, '../../serverconfig.json')
15
21
  // check which config file exists in order of usage priority
16
22
  const serverconfigfile =
17
23
  workdirconfig && fs.existsSync(workdirconfig)
@@ -83,9 +89,9 @@ if (!serverconfig.binpath) {
83
89
  } else {
84
90
  const specfile = process.argv.find(n => n.includes('.spec.js'))
85
91
  if (specfile) {
86
- serverconfig.binpath = path.dirname(import.meta.dirname)
87
- } else if (import.meta.filename.includes('node_modules/@sjcrh/proteinpaint-server')) {
88
- const p = import.meta.filename.split('/proteinpaint-server')[0]
92
+ serverconfig.binpath = path.dirname(__dirname)
93
+ } else if (__filename.includes('node_modules/@sjcrh/proteinpaint-server')) {
94
+ const p = __filename.split('/proteinpaint-server')[0]
89
95
  serverconfig.binpath = `${p}/proteinpaint-server`
90
96
  } else {
91
97
  const jsfile = process.argv.find(
@@ -106,9 +112,9 @@ if (!serverconfig.binpath) {
106
112
  } else {
107
113
  if (fs.existsSync('./server')) serverconfig.binpath = fs.realpathSync('./server')
108
114
  else if (fs.existsSync('./src')) serverconfig.binpath = fs.realpathSync('./src/..')
109
- else if (import.meta.dirname.includes('/server/'))
110
- serverconfig.binpath = import.meta.dirname.split('/server/')[0] + '/server'
111
- else if (import.meta.dirname.includes('/proteinpaint')) serverconfig.binpath = import.meta.dirname
115
+ else if (__dirname.includes('/server/'))
116
+ serverconfig.binpath = __dirname.split('/server/')[0] + '/server'
117
+ else if (__dirname.includes('/proteinpaint')) serverconfig.binpath = __dirname
112
118
  else throw 'unable to determine the serverconfig.binpath'
113
119
  }
114
120
  }