@platformatic/runtime 0.39.0 → 0.41.0
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.
- package/fixtures/start-command-in-runtime.js +1 -1
- package/fixtures/start-command.js +1 -1
- package/fixtures/starter.js +1 -1
- package/index.js +4 -3
- package/lib/app.js +21 -4
- package/lib/build-server.js +22 -4
- package/lib/compile.js +1 -1
- package/lib/load-config.js +20 -0
- package/lib/loader.mjs +8 -17
- package/lib/start.js +69 -14
- package/lib/worker.js +19 -3
- package/package.json +10 -10
- package/runtime.mjs +1 -1
- package/test/cli/watch.test.mjs +4 -4
- package/test/unified-api.test.js +1 -1
- package/lib/unified-api.js +0 -110
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const assert = require('node:assert')
|
|
3
3
|
const { request } = require('undici')
|
|
4
|
-
const { startCommand } = require('
|
|
4
|
+
const { startCommand } = require('..')
|
|
5
5
|
|
|
6
6
|
async function main () {
|
|
7
7
|
const entrypoint = await startCommand(['-c', process.argv[2]])
|
package/fixtures/starter.js
CHANGED
package/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const { buildServer } = require('./lib/build-server')
|
|
3
3
|
const { platformaticRuntime } = require('./lib/config')
|
|
4
|
-
const { start } = require('./lib/start')
|
|
5
|
-
const unifiedApi = require('./lib/unified-api')
|
|
4
|
+
const { start, startCommand } = require('./lib/start')
|
|
6
5
|
const RuntimeApi = require('./lib/api')
|
|
7
6
|
const { compile } = require('./lib/compile')
|
|
7
|
+
const { loadConfig } = require('./lib/load-config')
|
|
8
8
|
|
|
9
9
|
module.exports.buildServer = buildServer
|
|
10
10
|
module.exports.platformaticRuntime = platformaticRuntime
|
|
11
11
|
module.exports.schema = platformaticRuntime.schema
|
|
12
12
|
module.exports.RuntimeApi = RuntimeApi
|
|
13
13
|
module.exports.start = start
|
|
14
|
-
module.exports.
|
|
14
|
+
module.exports.startCommand = startCommand
|
|
15
15
|
module.exports.compile = compile
|
|
16
|
+
module.exports.loadConfig = loadConfig
|
package/lib/app.js
CHANGED
|
@@ -4,10 +4,8 @@ const { once } = require('node:events')
|
|
|
4
4
|
const { dirname } = require('node:path')
|
|
5
5
|
const { FileWatcher } = require('@platformatic/utils')
|
|
6
6
|
const debounce = require('debounce')
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
loadConfig
|
|
10
|
-
} = require('./unified-api')
|
|
7
|
+
const { buildServer } = require('./build-server')
|
|
8
|
+
const { loadConfig } = require('./load-config')
|
|
11
9
|
|
|
12
10
|
class PlatformaticApp {
|
|
13
11
|
#hotReload
|
|
@@ -57,6 +55,10 @@ class PlatformaticApp {
|
|
|
57
55
|
|
|
58
56
|
this.#restarting = true
|
|
59
57
|
|
|
58
|
+
// The CJS cache should not be cleared from the loader because v20 moved
|
|
59
|
+
// the loader to a different thread with a different CJS cache.
|
|
60
|
+
clearCjsCache()
|
|
61
|
+
|
|
60
62
|
/* c8 ignore next 4 - tests may not pass in a MessagePort. */
|
|
61
63
|
if (this.#loaderPort) {
|
|
62
64
|
this.#loaderPort.postMessage('plt:clear-cache')
|
|
@@ -257,4 +259,19 @@ class PlatformaticApp {
|
|
|
257
259
|
}
|
|
258
260
|
}
|
|
259
261
|
|
|
262
|
+
/* c8 ignore next 11 - c8 upgrade marked many existing things as uncovered */
|
|
263
|
+
function clearCjsCache () {
|
|
264
|
+
// This evicts all of the modules from the require() cache.
|
|
265
|
+
// Note: This does not clean up children references to the deleted module.
|
|
266
|
+
// It's likely not a big deal for most cases, but it is a leak. The child
|
|
267
|
+
// references can be cleaned up, but it is expensive and involves walking
|
|
268
|
+
// the entire require() cache. See the DEP0144 documentation for how to do
|
|
269
|
+
// it.
|
|
270
|
+
Object.keys(require.cache).forEach((key) => {
|
|
271
|
+
if (!key.match(/node_modules/)) {
|
|
272
|
+
delete require.cache[key]
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
260
277
|
module.exports = { PlatformaticApp }
|
package/lib/build-server.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
const ConfigManager = require('@platformatic/config')
|
|
3
3
|
const { platformaticRuntime } = require('./config')
|
|
4
4
|
const { startWithConfig } = require('./start')
|
|
5
|
+
const { buildServer: buildServerService } = require('@platformatic/service')
|
|
6
|
+
const { loadConfig } = require('./load-config')
|
|
5
7
|
|
|
6
|
-
async function
|
|
8
|
+
async function buildServerRuntime (options = {}) {
|
|
7
9
|
if (!options.configManager) {
|
|
8
10
|
// Instantiate a new config manager from the current options.
|
|
9
11
|
const cm = new ConfigManager({
|
|
@@ -19,10 +21,26 @@ async function buildServer (options = {}) {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
// The transformConfig() function can't be sent between threads.
|
|
23
|
-
delete options.configManager._transformConfig
|
|
24
|
-
|
|
25
24
|
return startWithConfig(options.configManager)
|
|
26
25
|
}
|
|
27
26
|
|
|
27
|
+
async function buildServer (options) {
|
|
28
|
+
if (typeof options === 'string') {
|
|
29
|
+
const config = await loadConfig({}, ['-c', options])
|
|
30
|
+
options = config.configManager.current
|
|
31
|
+
options.configManager = config.configManager
|
|
32
|
+
options.app = config.app
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const app = options.app
|
|
36
|
+
|
|
37
|
+
delete options.app
|
|
38
|
+
|
|
39
|
+
if (app === platformaticRuntime || !app) {
|
|
40
|
+
return buildServerRuntime(options)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return buildServerService(options, app)
|
|
44
|
+
}
|
|
45
|
+
|
|
28
46
|
module.exports = { buildServer }
|
package/lib/compile.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { Store, loadConfig } = require('@platformatic/config')
|
|
4
|
+
|
|
5
|
+
const { platformaticService } = require('@platformatic/service')
|
|
6
|
+
const { platformaticDB } = require('@platformatic/db')
|
|
7
|
+
const { platformaticComposer } = require('@platformatic/composer')
|
|
8
|
+
const { platformaticRuntime } = require('./config')
|
|
9
|
+
|
|
10
|
+
const store = new Store()
|
|
11
|
+
store.add(platformaticService)
|
|
12
|
+
store.add(platformaticDB)
|
|
13
|
+
store.add(platformaticComposer)
|
|
14
|
+
store.add(platformaticRuntime)
|
|
15
|
+
|
|
16
|
+
function _loadConfig (minimistConfig, args, overrides) {
|
|
17
|
+
return loadConfig(minimistConfig, args, store, overrides)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = { loadConfig: _loadConfig }
|
package/lib/loader.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createRequire, isBuiltin } from 'node:module'
|
|
2
2
|
import { dirname, isAbsolute, resolve as pathResolve } from 'node:path'
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
4
|
-
const require = createRequire(import.meta.url)
|
|
5
4
|
const isWindows = process.platform === 'win32'
|
|
6
5
|
let timestamp = process.hrtime.bigint()
|
|
7
6
|
let port
|
|
@@ -11,21 +10,6 @@ function bustEsmCache () {
|
|
|
11
10
|
timestamp = process.hrtime.bigint()
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
/* c8 ignore next 11 - c8 upgrade marked many existing things as uncovered */
|
|
15
|
-
function clearCjsCache () {
|
|
16
|
-
// This evicts all of the modules from the require() cache.
|
|
17
|
-
// Note: This does not clean up children references to the deleted module.
|
|
18
|
-
// It's likely not a big deal for most cases, but it is a leak. The child
|
|
19
|
-
// references can be cleaned up, but it is expensive and involves walking
|
|
20
|
-
// the entire require() cache. See the DEP0144 documentation for how to do
|
|
21
|
-
// it.
|
|
22
|
-
Object.keys(require.cache).forEach((key) => {
|
|
23
|
-
if (!key.match(/node_modules/)) {
|
|
24
|
-
delete require.cache[key]
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
|
|
29
13
|
function isRelativePath (p) {
|
|
30
14
|
// This function is extracted from Node core, so it should work.
|
|
31
15
|
/* c8 ignore next - c8 upgrade marked many existing things as uncovered */
|
|
@@ -103,9 +87,16 @@ export function globalPreload (context) {
|
|
|
103
87
|
port.on('message', () => {
|
|
104
88
|
/* c8 ignore next 3 - c8 upgrade marked many existing things as uncovered */
|
|
105
89
|
bustEsmCache()
|
|
106
|
-
clearCjsCache()
|
|
107
90
|
port.postMessage('plt:cache-cleared')
|
|
108
91
|
})
|
|
109
92
|
|
|
110
93
|
return 'globalThis.LOADER_PORT = port;'
|
|
111
94
|
}
|
|
95
|
+
|
|
96
|
+
export async function initialize (data) {
|
|
97
|
+
port = data.port
|
|
98
|
+
port.on('message', () => {
|
|
99
|
+
bustEsmCache()
|
|
100
|
+
port.postMessage('plt:cache-cleared')
|
|
101
|
+
})
|
|
102
|
+
}
|
package/lib/start.js
CHANGED
|
@@ -5,9 +5,12 @@ const { join } = require('node:path')
|
|
|
5
5
|
const { pathToFileURL } = require('node:url')
|
|
6
6
|
const { Worker } = require('node:worker_threads')
|
|
7
7
|
const closeWithGrace = require('close-with-grace')
|
|
8
|
-
const {
|
|
9
|
-
const {
|
|
8
|
+
const { start: serviceStart } = require('@platformatic/service')
|
|
9
|
+
const { loadConfig } = require('./load-config')
|
|
10
|
+
const { parseInspectorOptions, wrapConfigInRuntimeConfig } = require('./config')
|
|
10
11
|
const RuntimeApiClient = require('./api-client.js')
|
|
12
|
+
const { printConfigValidationErrors } = require('@platformatic/config')
|
|
13
|
+
|
|
11
14
|
const kLoaderFile = pathToFileURL(join(__dirname, 'loader.mjs')).href
|
|
12
15
|
const kWorkerFile = join(__dirname, 'worker.js')
|
|
13
16
|
const kWorkerExecArgv = [
|
|
@@ -16,17 +19,6 @@ const kWorkerExecArgv = [
|
|
|
16
19
|
kLoaderFile
|
|
17
20
|
]
|
|
18
21
|
|
|
19
|
-
async function start (argv) {
|
|
20
|
-
const config = await loadConfig({}, argv, platformaticRuntime, {
|
|
21
|
-
watch: true
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
config.configManager.args = config.args
|
|
25
|
-
const app = await startWithConfig(config.configManager)
|
|
26
|
-
await app.start()
|
|
27
|
-
return app
|
|
28
|
-
}
|
|
29
|
-
|
|
30
22
|
async function startWithConfig (configManager, env = process.env) {
|
|
31
23
|
const config = configManager.current
|
|
32
24
|
|
|
@@ -38,6 +30,12 @@ async function startWithConfig (configManager, env = process.env) {
|
|
|
38
30
|
parseInspectorOptions(configManager)
|
|
39
31
|
}
|
|
40
32
|
|
|
33
|
+
if (config.hotReload) {
|
|
34
|
+
config.loaderFile = kLoaderFile
|
|
35
|
+
}
|
|
36
|
+
// The configManager cannot be transferred to the worker, so remove it.
|
|
37
|
+
delete config.configManager
|
|
38
|
+
|
|
41
39
|
const worker = new Worker(kWorkerFile, {
|
|
42
40
|
/* c8 ignore next */
|
|
43
41
|
execArgv: config.hotReload ? kWorkerExecArgv : [],
|
|
@@ -86,4 +84,61 @@ async function startWithConfig (configManager, env = process.env) {
|
|
|
86
84
|
return runtimeApiClient
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
async function start (args) {
|
|
88
|
+
const config = await loadConfig({}, args)
|
|
89
|
+
|
|
90
|
+
if (config.configType === 'runtime') {
|
|
91
|
+
config.configManager.args = config.args
|
|
92
|
+
const app = await startWithConfig(config.configManager)
|
|
93
|
+
await app.start()
|
|
94
|
+
return app
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return serviceStart(config.app, args)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function startCommand (args) {
|
|
101
|
+
try {
|
|
102
|
+
const config = await loadConfig({}, args)
|
|
103
|
+
let runtime
|
|
104
|
+
|
|
105
|
+
if (config.configType === 'runtime') {
|
|
106
|
+
config.configManager.args = config.args
|
|
107
|
+
runtime = await startWithConfig(config.configManager)
|
|
108
|
+
} else {
|
|
109
|
+
const wrappedConfig = await wrapConfigInRuntimeConfig(config)
|
|
110
|
+
wrappedConfig.args = config.args
|
|
111
|
+
runtime = await startWithConfig(wrappedConfig)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return await runtime.start()
|
|
115
|
+
} catch (err) {
|
|
116
|
+
logErrorAndExit(err)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function logErrorAndExit (err) {
|
|
121
|
+
if (err.filenames) {
|
|
122
|
+
console.error(`Missing config file!
|
|
123
|
+
Be sure to have a config file with one of the following names:
|
|
124
|
+
|
|
125
|
+
${err.filenames.map((s) => ' * ' + s).join('\n')}
|
|
126
|
+
|
|
127
|
+
In alternative run "npm create platformatic@latest" to generate a basic plt service config.`)
|
|
128
|
+
process.exit(1)
|
|
129
|
+
} else if (err.validationErrors) {
|
|
130
|
+
printConfigValidationErrors(err)
|
|
131
|
+
process.exit(1)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
delete err?.stack
|
|
135
|
+
console.error(err?.message)
|
|
136
|
+
|
|
137
|
+
if (err?.cause) {
|
|
138
|
+
console.error(`${err.cause}`)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
process.exit(1)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports = { start, startWithConfig, startCommand }
|
package/lib/worker.js
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const inspector = require('node:inspector')
|
|
4
|
+
const { register } = require('node:module')
|
|
4
5
|
const { isatty } = require('node:tty')
|
|
5
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
MessageChannel,
|
|
8
|
+
parentPort,
|
|
9
|
+
workerData
|
|
10
|
+
} = require('node:worker_threads')
|
|
6
11
|
const undici = require('undici')
|
|
7
12
|
const pino = require('pino')
|
|
8
13
|
const RuntimeApi = require('./api')
|
|
9
14
|
const { MessagePortWritable } = require('./message-port-writable')
|
|
10
|
-
|
|
15
|
+
let loaderPort
|
|
16
|
+
|
|
17
|
+
if (typeof register === 'function' && workerData.config.loaderFile) {
|
|
18
|
+
const { port1, port2 } = new MessageChannel()
|
|
19
|
+
register(workerData.config.loaderFile, {
|
|
20
|
+
data: { port: port2 },
|
|
21
|
+
transferList: [port2]
|
|
22
|
+
})
|
|
23
|
+
loaderPort = port1
|
|
24
|
+
} else if (globalThis.LOADER_PORT) {
|
|
25
|
+
loaderPort = globalThis.LOADER_PORT
|
|
26
|
+
delete globalThis.LOADER_PORT
|
|
27
|
+
}
|
|
11
28
|
|
|
12
29
|
globalThis.fetch = undici.fetch
|
|
13
|
-
delete globalThis.LOADER_PORT
|
|
14
30
|
|
|
15
31
|
let transport
|
|
16
32
|
let destination
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"snazzy": "^9.0.0",
|
|
23
23
|
"split2": "^4.2.0",
|
|
24
24
|
"standard": "^17.1.0",
|
|
25
|
-
"tsd": "^0.
|
|
25
|
+
"tsd": "^0.29.0",
|
|
26
26
|
"typescript": "^5.1.6",
|
|
27
|
-
"@platformatic/sql-graphql": "0.
|
|
28
|
-
"@platformatic/sql-mapper": "0.
|
|
27
|
+
"@platformatic/sql-graphql": "0.41.0",
|
|
28
|
+
"@platformatic/sql-mapper": "0.41.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@hapi/topo": "^6.0.2",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"pino": "^8.14.1",
|
|
43
43
|
"pino-pretty": "^10.0.0",
|
|
44
44
|
"undici": "^5.22.1",
|
|
45
|
-
"@platformatic/composer": "0.
|
|
46
|
-
"@platformatic/config": "0.
|
|
47
|
-
"@platformatic/db": "0.
|
|
48
|
-
"@platformatic/service": "0.
|
|
49
|
-
"@platformatic/telemetry": "0.
|
|
50
|
-
"@platformatic/utils": "0.
|
|
45
|
+
"@platformatic/composer": "0.41.0",
|
|
46
|
+
"@platformatic/config": "0.41.0",
|
|
47
|
+
"@platformatic/db": "0.41.0",
|
|
48
|
+
"@platformatic/service": "0.41.0",
|
|
49
|
+
"@platformatic/telemetry": "0.41.0",
|
|
50
|
+
"@platformatic/utils": "0.41.0"
|
|
51
51
|
},
|
|
52
52
|
"standard": {
|
|
53
53
|
"ignore": [
|
package/runtime.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from 'desm'
|
|
|
6
6
|
import isMain from 'es-main'
|
|
7
7
|
import helpMe from 'help-me'
|
|
8
8
|
import parseArgs from 'minimist'
|
|
9
|
-
import { startCommand } from './
|
|
9
|
+
import { startCommand } from './index.js'
|
|
10
10
|
import { compile as compileCmd } from './lib/compile.js'
|
|
11
11
|
|
|
12
12
|
export const compile = compileCmd
|
package/test/cli/watch.test.mjs
CHANGED
|
@@ -132,7 +132,7 @@ test('should not hot reload files with `--hot-reload false', async (t) => {
|
|
|
132
132
|
assert.strictEqual(version, 'v1')
|
|
133
133
|
})
|
|
134
134
|
|
|
135
|
-
test('watches CommonJS files with hotreload', { timeout: 30000
|
|
135
|
+
test('watches CommonJS files with hotreload', { timeout: 30000 }, async (t) => {
|
|
136
136
|
const tmpDir = await mkdtemp(join(base, 'watch-'))
|
|
137
137
|
t.after(() => saferm(tmpDir))
|
|
138
138
|
t.diagnostic(`using ${tmpDir}`)
|
|
@@ -171,7 +171,7 @@ test('watches CommonJS files with hotreload', { timeout: 30000, skip: process.en
|
|
|
171
171
|
assert.ok(restartedThirdTime)
|
|
172
172
|
})
|
|
173
173
|
|
|
174
|
-
test('watches CommonJS files with hotreload on a single service', { timeout: 30000
|
|
174
|
+
test('watches CommonJS files with hotreload on a single service', { timeout: 30000 }, async (t) => {
|
|
175
175
|
const tmpDir = await mkdtemp(join(base, 'watch-'))
|
|
176
176
|
t.after(() => saferm(tmpDir))
|
|
177
177
|
t.diagnostic(`using ${tmpDir}`)
|
|
@@ -207,7 +207,7 @@ test('watches CommonJS files with hotreload on a single service', { timeout: 300
|
|
|
207
207
|
assert.ok(restartedThirdTime)
|
|
208
208
|
})
|
|
209
209
|
|
|
210
|
-
test('do not hot reload dependencies', { timeout: 30000
|
|
210
|
+
test('do not hot reload dependencies', { timeout: 30000 }, async (t) => {
|
|
211
211
|
process.env.PORT = 0
|
|
212
212
|
const config = join(fixturesDir, 'do-not-reload-dependencies', 'platformatic.service.json')
|
|
213
213
|
const { child, url } = await start('-c', config)
|
|
@@ -247,7 +247,7 @@ test('do not hot reload dependencies', { timeout: 30000, skip: process.env.CI },
|
|
|
247
247
|
assert.strictEqual((await res4.body.json()).hello, plugin2)
|
|
248
248
|
})
|
|
249
249
|
|
|
250
|
-
test('watches CommonJS files with hotreload on a single service', { timeout: 30000
|
|
250
|
+
test('watches CommonJS files with hotreload on a single service', { timeout: 30000 }, async (t) => {
|
|
251
251
|
const tmpDir = await mkdtemp(join(base, 'watch-'))
|
|
252
252
|
t.after(() => saferm(tmpDir))
|
|
253
253
|
t.diagnostic(`using ${tmpDir}`)
|
package/test/unified-api.test.js
CHANGED
package/lib/unified-api.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const { Store, loadConfig, printConfigValidationErrors } = require('@platformatic/config')
|
|
3
|
-
const {
|
|
4
|
-
platformaticService,
|
|
5
|
-
buildServer,
|
|
6
|
-
start
|
|
7
|
-
} = require('@platformatic/service')
|
|
8
|
-
const {
|
|
9
|
-
platformaticDB
|
|
10
|
-
} = require('@platformatic/db')
|
|
11
|
-
const {
|
|
12
|
-
platformaticComposer
|
|
13
|
-
} = require('@platformatic/composer')
|
|
14
|
-
const { buildServer: runtimeBuildServer } = require('./build-server')
|
|
15
|
-
const { platformaticRuntime, wrapConfigInRuntimeConfig } = require('./config')
|
|
16
|
-
const {
|
|
17
|
-
start: runtimeStart,
|
|
18
|
-
startWithConfig: runtimeStartWithConfig
|
|
19
|
-
} = require('./start')
|
|
20
|
-
|
|
21
|
-
const store = new Store()
|
|
22
|
-
store.add(platformaticService)
|
|
23
|
-
store.add(platformaticDB)
|
|
24
|
-
store.add(platformaticComposer)
|
|
25
|
-
store.add(platformaticRuntime)
|
|
26
|
-
|
|
27
|
-
/* c8 ignore next 10 - for some reason c8 is not seeing this as covered. */
|
|
28
|
-
async function _buildServer (options) {
|
|
29
|
-
if (typeof options === 'string') {
|
|
30
|
-
const config = await _loadConfig({}, ['-c', options])
|
|
31
|
-
options = config.configManager.current
|
|
32
|
-
options.configManager = config.configManager
|
|
33
|
-
options.app = config.app
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const app = options.app
|
|
37
|
-
|
|
38
|
-
delete options.app
|
|
39
|
-
|
|
40
|
-
if (app === platformaticRuntime) {
|
|
41
|
-
return runtimeBuildServer(options)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return buildServer(options, app)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function _loadConfig (minimistConfig, args, overrides) {
|
|
48
|
-
return loadConfig(minimistConfig, args, store, overrides)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async function _start (args) {
|
|
52
|
-
const config = await _loadConfig({}, args)
|
|
53
|
-
|
|
54
|
-
if (config.configType === 'runtime') {
|
|
55
|
-
return runtimeStart(args)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return start(config.app, args)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async function startCommand (args) {
|
|
62
|
-
try {
|
|
63
|
-
const config = await _loadConfig({}, args)
|
|
64
|
-
let runtime
|
|
65
|
-
|
|
66
|
-
if (config.configType === 'runtime') {
|
|
67
|
-
config.configManager.args = config.args
|
|
68
|
-
runtime = await runtimeStartWithConfig(config.configManager)
|
|
69
|
-
} else {
|
|
70
|
-
const wrappedConfig = await wrapConfigInRuntimeConfig(config)
|
|
71
|
-
wrappedConfig.args = config.args
|
|
72
|
-
runtime = await runtimeStartWithConfig(wrappedConfig)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return await runtime.start()
|
|
76
|
-
} catch (err) {
|
|
77
|
-
logErrorAndExit(err)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function logErrorAndExit (err) {
|
|
82
|
-
if (err.filenames) {
|
|
83
|
-
console.error(`Missing config file!
|
|
84
|
-
Be sure to have a config file with one of the following names:
|
|
85
|
-
|
|
86
|
-
${err.filenames.map((s) => ' * ' + s).join('\n')}
|
|
87
|
-
|
|
88
|
-
In alternative run "npm create platformatic@latest" to generate a basic plt service config.`)
|
|
89
|
-
process.exit(1)
|
|
90
|
-
} else if (err.validationErrors) {
|
|
91
|
-
printConfigValidationErrors(err)
|
|
92
|
-
process.exit(1)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
delete err?.stack
|
|
96
|
-
console.error(err?.message)
|
|
97
|
-
|
|
98
|
-
if (err?.cause) {
|
|
99
|
-
console.error(`${err.cause}`)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
process.exit(1)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
module.exports = {
|
|
106
|
-
buildServer: _buildServer,
|
|
107
|
-
loadConfig: _loadConfig,
|
|
108
|
-
start: _start,
|
|
109
|
-
startCommand
|
|
110
|
-
}
|