@platformatic/runtime 2.5.5-alpha.2 → 2.5.5

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/config.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * and run json-schema-to-typescript to regenerate this file.
6
6
  */
7
7
 
8
- export type HttpsSchemasPlatformaticDevPlatformaticRuntime255Alpha2Json = {
8
+ export type HttpsSchemasPlatformaticDevPlatformaticRuntime255Json = {
9
9
  [k: string]: unknown;
10
10
  } & {
11
11
  $schema?: string;
package/lib/runtime.js CHANGED
@@ -3,7 +3,6 @@
3
3
  const { once, EventEmitter } = require('node:events')
4
4
  const { createReadStream, watch } = require('node:fs')
5
5
  const { readdir, readFile, stat, access } = require('node:fs/promises')
6
- const inspector = require('node:inspector')
7
6
  const { join } = require('node:path')
8
7
  const { setTimeout: sleep } = require('node:timers/promises')
9
8
  const { Worker } = require('node:worker_threads')
@@ -21,6 +20,8 @@ const { getRuntimeTmpDir } = require('./utils')
21
20
  const { sendViaITC, waitEventFromITC } = require('./worker/itc')
22
21
  const { kId, kITC, kConfig } = require('./worker/symbols')
23
22
 
23
+ const Fastify = require('fastify')
24
+
24
25
  const platformaticVersion = require('../package.json').version
25
26
  const kWorkerFile = join(__dirname, 'worker/main.js')
26
27
 
@@ -50,6 +51,8 @@ class Runtime extends EventEmitter {
50
51
  #startedServices
51
52
  #restartPromises
52
53
  #bootstrapAttempts
54
+ #inspectors
55
+ #inspectorServer
53
56
 
54
57
  constructor (configManager, runtimeLogsDir, env) {
55
58
  super()
@@ -68,6 +71,7 @@ class Runtime extends EventEmitter {
68
71
  this.#startedServices = new Map()
69
72
  this.#restartPromises = new Map()
70
73
  this.#bootstrapAttempts = new Map()
74
+ this.#inspectors = []
71
75
  }
72
76
 
73
77
  async init () {
@@ -90,17 +94,6 @@ class Runtime extends EventEmitter {
90
94
  this.logger = logger
91
95
  this.#loggerDestination = destination
92
96
 
93
- // Handle inspector
94
- const inspectorOptions = config.inspectorOptions
95
- if (inspectorOptions) {
96
- /* c8 ignore next 6 */
97
- if (inspectorOptions.watchDisabled) {
98
- logger.info('debugging flags were detected. hot reloading has been disabled')
99
- }
100
-
101
- inspector.open(inspectorOptions.port, inspectorOptions.host, inspectorOptions.breakFirstLine)
102
- }
103
-
104
97
  // Create all services, each in is own worker thread
105
98
  for (const serviceConfig of config.services) {
106
99
  // Setup forwarding of logs from the worker threads to the main thread
@@ -137,6 +130,33 @@ class Runtime extends EventEmitter {
137
130
  for (const service of this.#servicesIds) {
138
131
  await this.startService(service)
139
132
  }
133
+
134
+ if (this.#configManager.current.inspectorOptions) {
135
+ const { port } = this.#configManager.current.inspectorOptions
136
+
137
+ const server = Fastify({
138
+ loggerInstance: this.logger.child({ name: 'inspector' }, { level: 'warn' })
139
+ })
140
+
141
+ const version = await fetch(`http://127.0.0.1:${this.#configManager.current.inspectorOptions.port + 1}/json/version`).then((res) => res.json())
142
+
143
+ const data = (await Promise.all(this.#inspectors.map(async (data) => {
144
+ const res = await fetch(`http://127.0.0.1:${data.port}/json/list`)
145
+ const details = await res.json()
146
+ return {
147
+ ...details[0],
148
+ title: data.id
149
+ }
150
+ })))
151
+
152
+ server.get('/json/list', () => data)
153
+ server.get('/json', () => data)
154
+ server.get('/json/version', () => version)
155
+
156
+ await server.listen({ port })
157
+ this.logger.info('The inspector server is now listening for all services. Open `chrome://inspect` in Google Chrome to connect.')
158
+ this.#inspectorServer = server
159
+ }
140
160
  } catch (error) {
141
161
  // Wait for the next tick so that the error is logged first
142
162
  await sleep(1)
@@ -162,6 +182,10 @@ class Runtime extends EventEmitter {
162
182
  this.#updateStatus('stopping')
163
183
  this.#startedServices.clear()
164
184
 
185
+ if (this.#inspectorServer) {
186
+ await this.#inspectorServer.close()
187
+ }
188
+
165
189
  await Promise.all(this.#servicesIds.map(service => this._stopService(service, silent)))
166
190
 
167
191
  this.#updateStatus('stopped')
@@ -750,6 +774,25 @@ class Runtime extends EventEmitter {
750
774
  this.#bootstrapAttempts.set(id, 0)
751
775
  }
752
776
 
777
+ // Handle inspector
778
+ let inspectorOptions
779
+
780
+ if (this.#configManager.current.inspectorOptions) {
781
+ inspectorOptions = {
782
+ ...this.#configManager.current.inspectorOptions
783
+ }
784
+
785
+ inspectorOptions.port = inspectorOptions.port + this.#inspectors.length + 1
786
+
787
+ const inspectorData = {
788
+ port: inspectorOptions.port,
789
+ id,
790
+ dirname: this.#configManager.dirname
791
+ }
792
+
793
+ this.#inspectors.push(inspectorData)
794
+ }
795
+
753
796
  const service = new Worker(kWorkerFile, {
754
797
  workerData: {
755
798
  config,
@@ -757,6 +800,7 @@ class Runtime extends EventEmitter {
757
800
  ...serviceConfig,
758
801
  isProduction: this.#configManager.args?.production ?? false
759
802
  },
803
+ inspectorOptions,
760
804
  dirname: this.#configManager.dirname,
761
805
  runtimeLogsDir: this.#runtimeLogsDir,
762
806
  loggingPort
@@ -4,6 +4,7 @@ const { createRequire } = require('node:module')
4
4
  const { join } = require('node:path')
5
5
  const { parentPort, workerData, threadId } = require('node:worker_threads')
6
6
  const { pathToFileURL } = require('node:url')
7
+ const inspector = require('node:inspector')
7
8
 
8
9
  const pino = require('pino')
9
10
  const { fetch, setGlobalDispatcher, Agent } = require('undici')
@@ -109,6 +110,24 @@ async function main () {
109
110
  }
110
111
  }
111
112
 
113
+ const inspectorOptions = workerData.inspectorOptions
114
+
115
+ if (inspectorOptions) {
116
+ for (let i = 0; !inspector.url(); i++) {
117
+ inspector.open(inspectorOptions.port + i, inspectorOptions.host, inspectorOptions.breakFirstLine)
118
+ }
119
+
120
+ const url = new URL(inspector.url())
121
+
122
+ url.protocol = 'http'
123
+ url.pathname = '/json/list'
124
+
125
+ const res = await fetch(url)
126
+ const [{ devtoolsFrontendUrl }] = await res.json()
127
+
128
+ console.log(`For ${service.id} debugger open the following in chrome: "${devtoolsFrontendUrl}"`)
129
+ }
130
+
112
131
  // Create the application
113
132
  app = new PlatformaticApp(
114
133
  service,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/runtime",
3
- "version": "2.5.5-alpha.2",
3
+ "version": "2.5.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -26,6 +26,7 @@
26
26
  "express": "^4.18.3",
27
27
  "fast-jwt": "^4.0.0",
28
28
  "get-port": "^7.1.0",
29
+ "inspector-client": "^0.1.2",
29
30
  "json-schema-to-typescript": "^15.0.0",
30
31
  "neostandard": "^0.11.1",
31
32
  "pino-abstract-transport": "^2.0.0",
@@ -34,11 +35,11 @@
34
35
  "typescript": "^5.5.4",
35
36
  "undici-oidc-interceptor": "^0.5.0",
36
37
  "why-is-node-running": "^2.2.2",
37
- "@platformatic/composer": "2.5.5-alpha.2",
38
- "@platformatic/db": "2.5.5-alpha.2",
39
- "@platformatic/service": "2.5.5-alpha.2",
40
- "@platformatic/sql-mapper": "2.5.5-alpha.2",
41
- "@platformatic/sql-graphql": "2.5.5-alpha.2"
38
+ "@platformatic/db": "2.5.5",
39
+ "@platformatic/composer": "2.5.5",
40
+ "@platformatic/sql-graphql": "2.5.5",
41
+ "@platformatic/sql-mapper": "2.5.5",
42
+ "@platformatic/service": "2.5.5"
42
43
  },
43
44
  "dependencies": {
44
45
  "@fastify/error": "^4.0.0",
@@ -69,13 +70,13 @@
69
70
  "undici": "^6.9.0",
70
71
  "undici-thread-interceptor": "^0.7.0",
71
72
  "ws": "^8.16.0",
72
- "@platformatic/basic": "2.5.5-alpha.2",
73
- "@platformatic/config": "2.5.5-alpha.2",
74
- "@platformatic/generators": "2.5.5-alpha.2",
75
- "@platformatic/itc": "2.5.5-alpha.2",
76
- "@platformatic/telemetry": "2.5.5-alpha.2",
77
- "@platformatic/ts-compiler": "2.5.5-alpha.2",
78
- "@platformatic/utils": "2.5.5-alpha.2"
73
+ "@platformatic/basic": "2.5.5",
74
+ "@platformatic/generators": "2.5.5",
75
+ "@platformatic/itc": "2.5.5",
76
+ "@platformatic/config": "2.5.5",
77
+ "@platformatic/telemetry": "2.5.5",
78
+ "@platformatic/ts-compiler": "2.5.5",
79
+ "@platformatic/utils": "2.5.5"
79
80
  },
80
81
  "scripts": {
81
82
  "test": "npm run lint && borp --concurrency=1 --timeout=180000 && tsd",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.5.5-alpha.2.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/runtime/2.5.5.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "type": "object",
5
5
  "properties": {