@platformatic/basic 2.0.0-alpha.15 → 2.0.0-alpha.16

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
@@ -7,13 +7,16 @@ import pino from 'pino'
7
7
  import { packageJson, schema } from './lib/schema.js'
8
8
  import { importFile } from './lib/utils.js'
9
9
 
10
+ const importStackablePackageMarker = '__pltImportStackablePackage.js'
11
+
10
12
  function isImportFailedError (error, pkg) {
11
- if (error.code !== 'ERR_MODULE_NOT_FOUND') {
13
+ if (error.code !== 'ERR_MODULE_NOT_FOUND' && error.code !== 'MODULE_NOT_FOUND') {
12
14
  return false
13
15
  }
14
16
 
15
17
  const match = error.message.match(/Cannot find package '(.+)' imported from (.+)/)
16
- return match?.[1] === pkg
18
+
19
+ return match?.[1] === pkg || error.requireStack?.[0].endsWith(importStackablePackageMarker)
17
20
  }
18
21
 
19
22
  async function importStackablePackage (opts, pkg, autodetectDescription) {
@@ -27,7 +30,7 @@ async function importStackablePackage (opts, pkg, autodetectDescription) {
27
30
  }
28
31
 
29
32
  // Scope to the service
30
- const require = createRequire(resolve(opts.context.directory, 'index.js'))
33
+ const require = createRequire(resolve(opts.context.directory, importStackablePackageMarker))
31
34
  const imported = require.resolve(pkg)
32
35
  return await importFile(imported)
33
36
  }
@@ -38,10 +41,10 @@ async function importStackablePackage (opts, pkg, autodetectDescription) {
38
41
 
39
42
  const rootFolder = relative(process.cwd(), workerData.dirname)
40
43
 
41
- let errorMessage = `Unable to import package, "${pkg}". Please add it as a dependency `
44
+ let errorMessage = `Unable to import package '${pkg}'. Please add it as a dependency `
42
45
 
43
46
  if (rootFolder) {
44
- errorMessage += `in the package.json file in the folder ${rootFolder}.`
47
+ errorMessage += `in the package.json file in the folder ${relative(rootFolder, opts.context.directory)}.`
45
48
  } else {
46
49
  errorMessage += 'in the root package.json file.'
47
50
  }
package/lib/base.js CHANGED
@@ -1,4 +1,4 @@
1
- import deepmerge from '@fastify/deepmerge'
1
+ import { deepmerge } from '@platformatic/utils'
2
2
  import { parseCommandString } from 'execa'
3
3
  import { spawn } from 'node:child_process'
4
4
  import { once } from 'node:events'
@@ -11,8 +11,6 @@ import { NonZeroExitCode } from './errors.js'
11
11
  import { cleanBasePath } from './utils.js'
12
12
  import { ChildManager } from './worker/child-manager.js'
13
13
 
14
- const merge = deepmerge()
15
-
16
14
  export class BaseStackable {
17
15
  #childManager
18
16
  #subprocess
@@ -25,7 +23,7 @@ export class BaseStackable {
25
23
  this.options = options
26
24
  this.root = root
27
25
  this.configManager = configManager
28
- this.serverConfig = merge(options.context.serverConfig, configManager.current.server)
26
+ this.serverConfig = deepmerge(options.context.serverConfig ?? {}, configManager.current.server ?? {})
29
27
  this.openapiSchema = null
30
28
  this.getGraphqlSchema = null
31
29
  this.isEntrypoint = options.context.isEntrypoint
@@ -57,6 +55,10 @@ export class BaseStackable {
57
55
  return this.configManager.current
58
56
  }
59
57
 
58
+ async getEnv () {
59
+ return this.configManager.env
60
+ }
61
+
60
62
  async getWatchConfig () {
61
63
  const config = this.configManager.current
62
64
 
@@ -1,5 +1,5 @@
1
1
  import { ITC, generateNotification } from '@platformatic/itc'
2
- import { createDirectory, errors } from '@platformatic/utils'
2
+ import { createDirectory, ensureLoggableError } from '@platformatic/utils'
3
3
  import { once } from 'node:events'
4
4
  import { rm, writeFile } from 'node:fs/promises'
5
5
  import { createServer } from 'node:http'
@@ -213,7 +213,7 @@ export class ChildManager extends ITC {
213
213
  }
214
214
 
215
215
  #handleUnexpectedError (error, message, exitCode) {
216
- this.#logger.error({ err: errors.ensureLoggableError(error) }, message)
216
+ this.#logger.error({ err: ensureLoggableError(error) }, message)
217
217
  process.exit(exitCode)
218
218
  }
219
219
  }
@@ -1,5 +1,5 @@
1
1
  import { ITC } from '@platformatic/itc'
2
- import { createPinoWritable, errors } from '@platformatic/utils'
2
+ import { createPinoWritable, ensureLoggableError } from '@platformatic/utils'
3
3
  import { tracingChannel } from 'node:diagnostics_channel'
4
4
  import { once } from 'node:events'
5
5
  import { readFile } from 'node:fs/promises'
@@ -115,7 +115,7 @@ export class ChildProcess extends ITC {
115
115
  try {
116
116
  this.#listener(JSON.parse(message))
117
117
  } catch (error) {
118
- this.#logger.error({ err: errors.ensureLoggableError(error) }, 'Handling a message failed.')
118
+ this.#logger.error({ err: ensureLoggableError(error) }, 'Handling a message failed.')
119
119
  process.exit(exitCodes.PROCESS_MESSAGE_HANDLING_FAILED)
120
120
  }
121
121
  })
@@ -158,7 +158,7 @@ export class ChildProcess extends ITC {
158
158
  })
159
159
 
160
160
  Reflect.defineProperty(process, 'stdout', { value: createPinoWritable(this.#logger, 'info') })
161
- Reflect.defineProperty(process, 'stderr', { value: createPinoWritable(this.#logger, 'error') })
161
+ Reflect.defineProperty(process, 'stderr', { value: createPinoWritable(this.#logger, 'error', true) })
162
162
  } else {
163
163
  this.#logger = pino({ level: 'info', name: globalThis.platformatic.id })
164
164
  }
@@ -196,9 +196,8 @@ export class ChildProcess extends ITC {
196
196
 
197
197
  #setupHandlers () {
198
198
  function handleUnhandled (type, err) {
199
- process._rawDebug(globalThis.platformatic.id, err)
200
199
  this.#logger.error(
201
- { err: errors.ensureLoggableError(err) },
200
+ { err: ensureLoggableError(err) },
202
201
  `Child process for service ${globalThis.platformatic.id} threw an ${type}.`
203
202
  )
204
203
 
@@ -1,5 +1,5 @@
1
1
  import { generateRequest } from '@platformatic/itc'
2
- import { errors } from '@platformatic/utils'
2
+ import { ensureLoggableError } from '@platformatic/utils'
3
3
  import { once } from 'node:events'
4
4
  import { platform } from 'node:os'
5
5
  import { workerData } from 'node:worker_threads'
@@ -9,7 +9,7 @@ import { getSocketPath } from './child-manager.js'
9
9
 
10
10
  function logDirectError (message, error) {
11
11
  process._rawDebug(`Logger thread for child process of service ${workerData.id} ${message}.`, {
12
- error: errors.ensureLoggableError(error)
12
+ error: ensureLoggableError(error)
13
13
  })
14
14
  }
15
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/basic",
3
- "version": "2.0.0-alpha.15",
3
+ "version": "2.0.0-alpha.16",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -16,7 +16,6 @@
16
16
  "homepage": "https://github.com/platformatic/platformatic#readme",
17
17
  "dependencies": {
18
18
  "@fastify/error": "^4.0.0",
19
- "@fastify/deepmerge": "^2.0.0",
20
19
  "execa": "^9.3.1",
21
20
  "pino": "^9.3.2",
22
21
  "pino-abstract-transport": "^2.0.0",
@@ -24,9 +23,9 @@
24
23
  "split2": "^4.2.0",
25
24
  "undici": "^6.19.5",
26
25
  "ws": "^8.18.0",
27
- "@platformatic/config": "2.0.0-alpha.15",
28
- "@platformatic/itc": "2.0.0-alpha.15",
29
- "@platformatic/utils": "2.0.0-alpha.15"
26
+ "@platformatic/config": "2.0.0-alpha.16",
27
+ "@platformatic/itc": "2.0.0-alpha.16",
28
+ "@platformatic/utils": "2.0.0-alpha.16"
30
29
  },
31
30
  "devDependencies": {
32
31
  "borp": "^0.17.0",
@@ -40,8 +39,8 @@
40
39
  "react-dom": "^18.3.1",
41
40
  "typescript": "^5.5.4",
42
41
  "vite": "^5.4.0",
43
- "@platformatic/composer": "2.0.0-alpha.15",
44
- "@platformatic/service": "2.0.0-alpha.15"
42
+ "@platformatic/composer": "2.0.0-alpha.16",
43
+ "@platformatic/service": "2.0.0-alpha.16"
45
44
  },
46
45
  "scripts": {
47
46
  "gen-schema": "node lib/schema.js > schema.json",
package/schema.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.0.0-alpha.15.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.0.0-alpha.16.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Stackable",
5
5
  "type": "object",