@platformatic/basic 2.0.0-alpha.5 → 2.0.0-alpha.6

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
@@ -3,6 +3,7 @@ import { readFile } from 'node:fs/promises'
3
3
  import { createRequire } from 'node:module'
4
4
  import { relative, resolve } from 'node:path'
5
5
  import { workerData } from 'node:worker_threads'
6
+ import pino from 'pino'
6
7
  import { packageJson, schema } from './lib/schema.js'
7
8
  import { importFile } from './lib/utils.js'
8
9
 
@@ -28,15 +29,6 @@ async function importStackablePackage (opts, pkg, autodetectDescription) {
28
29
  errorMessage += 'in the root package.json file.'
29
30
  }
30
31
 
31
- if (!opts.config) {
32
- const serviceRoot = relative(process.cwd(), opts.context.directory)
33
- errorMessage += [
34
- '', // Do not remove this
35
- `Platformatic has auto-detected that service ${opts.context.serviceId} ${autodetectDescription}.`,
36
- `We suggest you create a platformatic.application.json file in the folder ${serviceRoot} with the "$schema" property set to "https://schemas.platformatic.dev/${pkg}/${packageJson.version}.json".`,
37
- ].join('\n')
38
- }
39
-
40
32
  throw new Error(errorMessage)
41
33
  }
42
34
  }
@@ -53,7 +45,9 @@ async function buildStackable (opts) {
53
45
  rootPackageJson = {}
54
46
  }
55
47
 
56
- if (!opts.config) {
48
+ const hadConfig = opts.config
49
+
50
+ if (!hadConfig) {
57
51
  const candidate = resolve(root, 'platformatic.application.json')
58
52
 
59
53
  if (existsSync(candidate)) {
@@ -66,12 +60,35 @@ async function buildStackable (opts) {
66
60
  if (dependencies?.next || devDependencies?.next) {
67
61
  autodetectDescription = 'is using Next.js'
68
62
  toImport = '@platformatic/next'
63
+ } else if (dependencies?.['@remix-run/dev'] || devDependencies?.['@remix-run/dev']) {
64
+ autodetectDescription = 'is using Remix'
65
+ toImport = '@platformatic/remix'
69
66
  } else if (dependencies?.vite || devDependencies?.vite) {
70
67
  autodetectDescription = 'is using Vite'
71
68
  toImport = '@platformatic/vite'
69
+ } else if (dependencies?.astro || devDependencies?.astro) {
70
+ autodetectDescription = 'is using Astro'
71
+ toImport = '@platformatic/astro'
72
72
  }
73
73
 
74
74
  const imported = await importStackablePackage(opts, toImport, autodetectDescription)
75
+
76
+ if (!hadConfig) {
77
+ const serviceRoot = relative(process.cwd(), opts.context.directory)
78
+ const logger = pino({
79
+ level: opts.context.serverConfig?.logger?.level ?? 'warn',
80
+ name: opts.context.serviceId
81
+ })
82
+
83
+ logger.warn(
84
+ [
85
+ `Platformatic has auto-detected that service ${opts.context.serviceId} ${autodetectDescription}.\n`,
86
+ `We suggest you create a platformatic.application.json file in the folder ${serviceRoot} with the "$schema" `,
87
+ `property set to "https://schemas.platformatic.dev/${toImport}/${packageJson.version}.json".`
88
+ ].join('')
89
+ )
90
+ }
91
+
75
92
  return imported.buildStackable(opts)
76
93
  }
77
94
 
@@ -80,7 +97,7 @@ export default {
80
97
  configManagerConfig: {},
81
98
  buildStackable,
82
99
  schema,
83
- version: packageJson.version,
100
+ version: packageJson.version
84
101
  }
85
102
 
86
103
  export * from './lib/base.js'
package/lib/base.js CHANGED
@@ -13,7 +13,7 @@ export class BaseStackable {
13
13
 
14
14
  // Setup the logger
15
15
  const pinoOptions = {
16
- level: (this.configManager.current.server ?? this.serverConfig)?.logger?.level ?? 'trace',
16
+ level: (this.configManager.current.server ?? this.serverConfig)?.logger?.level ?? 'trace'
17
17
  }
18
18
 
19
19
  if (this.id) {
@@ -22,10 +22,10 @@ export class BaseStackable {
22
22
  this.logger = pino(pinoOptions)
23
23
 
24
24
  // Setup globals
25
- globalThis.platformatic = {
25
+ this.registerGlobals({
26
26
  setOpenapiSchema: this.setOpenapiSchema.bind(this),
27
- setGraphqlSchema: this.setGraphqlSchema.bind(this),
28
- }
27
+ setGraphqlSchema: this.setGraphqlSchema.bind(this)
28
+ })
29
29
  }
30
30
 
31
31
  getUrl () {
@@ -45,7 +45,7 @@ export class BaseStackable {
45
45
  enabled,
46
46
  path: this.root,
47
47
  allow: config.watch?.allow,
48
- ignore: config.watch?.ignore,
48
+ ignore: config.watch?.ignore
49
49
  }
50
50
  }
51
51
 
@@ -81,4 +81,8 @@ export class BaseStackable {
81
81
  const logLevel = level ?? 'info'
82
82
  this.logger[logLevel](message)
83
83
  }
84
+
85
+ registerGlobals (globals) {
86
+ globalThis.platformatic = Object.assign(globalThis.platformatic ?? {}, globals)
87
+ }
84
88
  }
@@ -13,7 +13,16 @@ export class ChildManager extends ITC {
13
13
  #originalNodeOptions
14
14
 
15
15
  constructor ({ loader, context }) {
16
- super({})
16
+ super({
17
+ handlers: {
18
+ log (message) {
19
+ workerData.loggingPort.postMessage(JSON.parse(message))
20
+ },
21
+ fetch: request => {
22
+ return this.#fetch(request)
23
+ }
24
+ }
25
+ })
17
26
 
18
27
  const childHandler = ({ process: child }) => {
19
28
  unsubscribe('child_process', childHandler)
@@ -28,12 +37,6 @@ export class ChildManager extends ITC {
28
37
 
29
38
  subscribe('child_process', childHandler)
30
39
 
31
- this.handle('log', message => {
32
- workerData.loggingPort.postMessage(JSON.parse(message))
33
- })
34
-
35
- this.handle('fetch', this.#fetch.bind(this))
36
-
37
40
  this.#prepareChildEnvironment(loader, context)
38
41
  }
39
42
 
@@ -75,7 +78,7 @@ export class ChildManager extends ITC {
75
78
  this.#injectedNodeOptions = [
76
79
  `--import="data:text/javascript,${loaderScript.replaceAll(/\n/g, '')}"`,
77
80
  `--import=${childProcessWorkerFile}`,
78
- process.env.NODE_OPTIONS ?? '',
81
+ process.env.NODE_OPTIONS ?? ''
79
82
  ].join(' ')
80
83
  }
81
84
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/basic",
3
- "version": "2.0.0-alpha.5",
3
+ "version": "2.0.0-alpha.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -19,9 +19,9 @@
19
19
  "pino": "^9.3.2",
20
20
  "semver": "^7.6.3",
21
21
  "undici": "^6.19.5",
22
- "@platformatic/config": "2.0.0-alpha.5",
23
- "@platformatic/utils": "2.0.0-alpha.5",
24
- "@platformatic/itc": "2.0.0-alpha.5"
22
+ "@platformatic/config": "2.0.0-alpha.6",
23
+ "@platformatic/itc": "2.0.0-alpha.6",
24
+ "@platformatic/utils": "2.0.0-alpha.6"
25
25
  },
26
26
  "devDependencies": {
27
27
  "borp": "^0.17.0",
@@ -36,8 +36,8 @@
36
36
  "typescript": "^5.5.4",
37
37
  "vite": "^5.4.0",
38
38
  "ws": "^8.18.0",
39
- "@platformatic/composer": "2.0.0-alpha.5",
40
- "@platformatic/service": "2.0.0-alpha.5"
39
+ "@platformatic/composer": "2.0.0-alpha.6",
40
+ "@platformatic/service": "2.0.0-alpha.6"
41
41
  },
42
42
  "scripts": {
43
43
  "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.5.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.0.0-alpha.6.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Stackable",
5
5
  "type": "object",
package/test/helper.js CHANGED
@@ -11,6 +11,7 @@ import { buildServer, platformaticRuntime } from '../../runtime/index.js'
11
11
 
12
12
  export { setTimeout as sleep } from 'node:timers/promises'
13
13
 
14
+ const HMR_TIMEOUT = process.env.CI ? 20000 : 10000
14
15
  let hrmVersion = Date.now()
15
16
  export let fixturesDir
16
17
 
@@ -59,12 +60,12 @@ export async function getLogs (app) {
59
60
  const client = new Client(
60
61
  {
61
62
  hostname: 'localhost',
62
- protocol: 'http:',
63
+ protocol: 'http:'
63
64
  },
64
65
  {
65
66
  socketPath: app.getManagementApiUrl(),
66
67
  keepAliveTimeout: 10,
67
- keepAliveMaxTimeout: 10,
68
+ keepAliveMaxTimeout: 10
68
69
  }
69
70
  )
70
71
 
@@ -73,7 +74,7 @@ export async function getLogs (app) {
73
74
 
74
75
  const { statusCode, body } = await client.request({
75
76
  method: 'GET',
76
- path: '/api/v1/logs/all',
77
+ path: '/api/v1/logs/all'
77
78
  })
78
79
 
79
80
  strictEqual(statusCode, 200)
@@ -113,7 +114,7 @@ export async function verifyHTMLViaHTTP (baseUrl, path, contents) {
113
114
  ok(headers['content-type']?.startsWith('text/html'))
114
115
 
115
116
  for (const content of contents) {
116
- ok(content instanceof RegExp ? content.test(html) : html.includes(content))
117
+ ok(content instanceof RegExp ? content.test(html) : html.includes(content), content)
117
118
  }
118
119
  }
119
120
 
@@ -124,7 +125,7 @@ export async function verifyHTMLViaInject (app, serviceId, url, contents) {
124
125
  ok(headers['content-type'].startsWith('text/html'))
125
126
 
126
127
  for (const content of contents) {
127
- ok(content instanceof RegExp ? content.test(html) : html.includes(content))
128
+ ok(content instanceof RegExp ? content.test(html) : html.includes(content), content)
128
129
  }
129
130
  }
130
131
 
@@ -132,7 +133,7 @@ export async function verifyHMR (baseUrl, path, protocol, handler) {
132
133
  const connection = withResolvers()
133
134
  const reload = withResolvers()
134
135
  const ac = new AbortController()
135
- const timeout = sleep(10000, 'timeout', { signal: ac.signal })
136
+ const timeout = sleep(HMR_TIMEOUT, 'timeout', { signal: ac.signal })
136
137
 
137
138
  const url = baseUrl.replace('http:', 'ws:') + path
138
139
  const webSocket = new WebSocket(url, protocol)