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

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,21 +60,59 @@ 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
+ const serviceRoot = relative(process.cwd(), opts.context.directory)
77
+ if (!hadConfig && !existsSync(resolve(serviceRoot, 'platformatic.application.json'))) {
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
 
95
+ /* c8 ignore next 3 */
96
+ export function transformConfig () {
97
+ // This is currently empty but it left as a placeholder for the future
98
+ }
99
+
100
+ export const schemaOptions = {
101
+ useDefaults: true,
102
+ coerceTypes: true,
103
+ allErrors: true,
104
+ strict: false
105
+ }
106
+
78
107
  export default {
79
108
  configType: 'nodejs',
80
- configManagerConfig: {},
109
+ configManagerConfig: {
110
+ schemaOptions,
111
+ transformConfig
112
+ },
81
113
  buildStackable,
82
114
  schema,
83
- version: packageJson.version,
115
+ version: packageJson.version
84
116
  }
85
117
 
86
118
  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
 
@@ -57,8 +57,11 @@ export class BaseStackable {
57
57
  return this
58
58
  }
59
59
 
60
- async getMetrics ({ format }) {
61
- return null
60
+ async collectMetrics () {
61
+ return {
62
+ defaultMetrics: true,
63
+ httpMetrics: false
64
+ }
62
65
  }
63
66
 
64
67
  async getOpenapiSchema () {
@@ -81,4 +84,8 @@ export class BaseStackable {
81
84
  const logLevel = level ?? 'info'
82
85
  this.logger[logLevel](message)
83
86
  }
87
+
88
+ registerGlobals (globals) {
89
+ globalThis.platformatic = Object.assign(globalThis.platformatic ?? {}, globals)
90
+ }
84
91
  }
package/lib/schema.js CHANGED
@@ -7,25 +7,51 @@ const application = {
7
7
  type: 'object',
8
8
  properties: {
9
9
  basePath: {
10
- type: 'string',
11
- },
10
+ type: 'string'
11
+ }
12
12
  },
13
- additionalProperties: false,
13
+ additionalProperties: false
14
14
  }
15
15
 
16
16
  const watch = {
17
17
  anyOf: [
18
18
  schemas.watch,
19
19
  {
20
- type: 'boolean',
20
+ type: 'boolean'
21
21
  },
22
22
  {
23
+ type: 'string'
24
+ }
25
+ ]
26
+ }
27
+
28
+ const deploy = {
29
+ type: 'object',
30
+ properties: {
31
+ include: {
32
+ type: 'array',
33
+ items: {
34
+ type: 'string'
35
+ },
36
+ default: ['dist']
37
+ },
38
+ buildCommand: {
23
39
  type: 'string',
40
+ default: 'npm run build'
24
41
  },
25
- ],
42
+ installCommand: {
43
+ type: 'string',
44
+ default: 'npm ci --omit-dev'
45
+ },
46
+ startCommand: {
47
+ type: 'string',
48
+ default: 'npm run start'
49
+ }
50
+ },
51
+ default: {}
26
52
  }
27
53
 
28
- export const schemaComponents = { application, watch }
54
+ export const schemaComponents = { application, deploy, watch }
29
55
 
30
56
  export const schema = {
31
57
  $id: `https://schemas.platformatic.dev/@platformatic/basic/${packageJson.version}.json`,
@@ -34,10 +60,10 @@ export const schema = {
34
60
  type: 'object',
35
61
  properties: {
36
62
  $schema: {
37
- type: 'string',
38
- },
63
+ type: 'string'
64
+ }
39
65
  },
40
- additionalProperties: true,
66
+ additionalProperties: true
41
67
  }
42
68
 
43
69
  /* c8 ignore next 3 */
@@ -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.7",
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.7",
23
+ "@platformatic/itc": "2.0.0-alpha.7",
24
+ "@platformatic/utils": "2.0.0-alpha.7"
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.7",
40
+ "@platformatic/service": "2.0.0-alpha.7"
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.7.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)