@platformatic/service 0.35.5 → 0.36.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/index.js CHANGED
@@ -16,7 +16,6 @@ const loadPlugins = require('./lib/plugins/plugins')
16
16
  const { telemetry } = require('@platformatic/telemetry')
17
17
 
18
18
  const { schema } = require('./lib/schema')
19
- const { loadConfig } = require('./lib/load-config')
20
19
  const { addLoggerToTheConfig } = require('./lib/utils')
21
20
  const { start, buildServer } = require('./lib/start')
22
21
 
@@ -130,7 +129,6 @@ function _buildServer (options, app) {
130
129
  module.exports.buildServer = _buildServer
131
130
  module.exports.schema = require('./lib/schema')
132
131
  module.exports.platformaticService = platformaticService
133
- module.exports.loadConfig = loadConfig
134
132
  module.exports.addLoggerToTheConfig = addLoggerToTheConfig
135
133
  module.exports.tsCompiler = compiler
136
134
  module.exports.start = start
package/lib/compile.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const { resolve, join, dirname } = require('path')
4
4
  const pino = require('pino')
5
5
  const pretty = require('pino-pretty')
6
- const { loadConfig } = require('./load-config.js')
6
+ const { loadConfig } = require('@platformatic/config')
7
7
  const { isFileAccessible } = require('./utils.js')
8
8
 
9
9
  async function getTSCExecutablePath (cwd) {
package/lib/start.js CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  const { readFile } = require('fs/promises')
4
4
  const close = require('close-with-grace')
5
- const { loadConfig } = require('./load-config')
5
+ const { loadConfig, ConfigManager, printConfigValidationErrors, printAndExitLoadConfigError } = require('@platformatic/config')
6
6
  const { addLoggerToTheConfig } = require('./utils.js')
7
- const ConfigManager = require('@platformatic/config')
8
7
  const { restartable } = require('@fastify/restartable')
9
8
 
10
9
  async function adjustHttpsKeyAndCert (arg) {
@@ -98,7 +97,17 @@ async function safeRestart (app) {
98
97
 
99
98
  async function start (appType, _args) {
100
99
  /* c8 ignore next 55 */
101
- const { configManager } = await loadConfig({}, _args, appType)
100
+ let configManager = null
101
+ try {
102
+ configManager = (await loadConfig({}, _args, appType)).configManager
103
+ } catch (err) {
104
+ if (err.validationErrors) {
105
+ printConfigValidationErrors(err)
106
+ process.exit(1)
107
+ } else {
108
+ throw err
109
+ }
110
+ }
102
111
 
103
112
  const config = configManager.current
104
113
 
@@ -118,9 +127,7 @@ async function start (appType, _args) {
118
127
  app = await buildServer({ ...config, configManager }, appType)
119
128
  await app.start()
120
129
  } catch (err) {
121
- // TODO route this to a logger
122
- console.error(err)
123
- process.exit(1)
130
+ printAndExitLoadConfigError(err)
124
131
  }
125
132
 
126
133
  // Ignore from CI because SIGUSR2 is not available
@@ -144,6 +151,8 @@ async function start (appType, _args) {
144
151
  app.log.info({ signal }, 'received signal')
145
152
  }
146
153
 
154
+ // Weird coverage issue in c8
155
+ /* c8 ignore next 2 */
147
156
  await app.close()
148
157
  })
149
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/service",
3
- "version": "0.35.5",
3
+ "version": "0.36.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -65,12 +65,12 @@
65
65
  "pino-pretty": "^10.0.0",
66
66
  "rfdc": "^1.3.0",
67
67
  "ua-parser-js": "^1.0.35",
68
- "@platformatic/client": "0.35.5",
69
- "@platformatic/config": "0.35.5",
70
- "@platformatic/swagger-ui-theme": "0.35.5",
71
- "@platformatic/types": "0.35.5",
72
- "@platformatic/utils": "0.35.5",
73
- "@platformatic/telemetry": "0.35.5"
68
+ "@platformatic/client": "0.36.0",
69
+ "@platformatic/config": "0.36.0",
70
+ "@platformatic/swagger-ui-theme": "0.36.0",
71
+ "@platformatic/types": "0.36.0",
72
+ "@platformatic/utils": "0.36.0",
73
+ "@platformatic/telemetry": "0.36.0"
74
74
  },
75
75
  "standard": {
76
76
  "ignore": [
@@ -1,79 +0,0 @@
1
- 'use strict'
2
-
3
- const parseArgs = require('minimist')
4
- const { access } = require('fs/promises')
5
- const ConfigManager = require('@platformatic/config')
6
- const deepmerge = require('@fastify/deepmerge')
7
-
8
- // Unfortunately c8 does not see those on Windows
9
- /* c8 ignore next 70 */
10
- async function loadConfig (minimistConfig, _args, app, overrides = {}) {
11
- const configManagerConfig = {
12
- ...app.configManagerConfig,
13
- ...overrides
14
- }
15
-
16
- const configType = app.configType
17
-
18
- const args = parseArgs(_args, deepmerge({ all: true })({
19
- string: ['allow-env'],
20
- default: {
21
- allowEnv: '' // The default is set in ConfigManager
22
- },
23
- alias: {
24
- v: 'version',
25
- c: 'config',
26
- allowEnv: ['allow-env', 'E']
27
- }
28
- }, minimistConfig))
29
-
30
- try {
31
- if (!args.config) {
32
- args.config = await ConfigManager.findConfigFile(process.cwd(), configType)
33
- }
34
- await access(args.config)
35
- } catch (err) {
36
- const configFiles = ConfigManager.listConfigFiles(configType)
37
- console.error(`
38
- Missing config file!
39
- Be sure to have a config file with one of the following names:
40
-
41
- ${configFiles.map((s) => ' * ' + s).join('\n')}
42
-
43
- In alternative run "npm create platformatic@latest" to generate a basic plt service config.
44
- Error: ${err}
45
- `)
46
- process.exit(1)
47
- }
48
-
49
- const envWhitelist = args.allowEnv ? args.allowEnv : configManagerConfig.envWhitelist
50
- const configManager = new ConfigManager({
51
- source: args.config,
52
- ...configManagerConfig,
53
- envWhitelist
54
- })
55
-
56
- try {
57
- const parsingResult = await configManager.parse()
58
- if (!parsingResult) {
59
- printConfigValidationErrors(configManager)
60
- process.exit(1)
61
- }
62
- } finally {
63
- configManager.stopWatching()
64
- }
65
-
66
- return { configManager, args }
67
- }
68
-
69
- function printConfigValidationErrors (configManager) {
70
- const tabularData = configManager.validationErrors.map((err) => {
71
- return {
72
- path: err.path,
73
- message: err.message
74
- }
75
- })
76
- console.table(tabularData, ['path', 'message'])
77
- }
78
-
79
- module.exports.loadConfig = loadConfig