@platformatic/basic 2.0.0-alpha.4 → 2.0.0-alpha.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.
Files changed (103) hide show
  1. package/NOTICE +13 -0
  2. package/README.md +13 -0
  3. package/config.d.ts +1 -149
  4. package/index.js +60 -87
  5. package/lib/base.js +4 -4
  6. package/lib/schema.js +26 -33
  7. package/lib/utils.js +1 -5
  8. package/lib/worker/child-manager.js +12 -0
  9. package/lib/worker/child-process.js +66 -0
  10. package/package.json +6 -13
  11. package/schema.json +2 -512
  12. package/test/helper.js +38 -9
  13. package/lib/next.js +0 -105
  14. package/lib/server.js +0 -134
  15. package/lib/vite.js +0 -105
  16. package/lib/worker/next-loader.js +0 -137
  17. package/test/express.test.js +0 -34
  18. package/test/fastify.test.js +0 -34
  19. package/test/fixtures/express/no-build/index.js +0 -16
  20. package/test/fixtures/express/no-build/package.json +0 -7
  21. package/test/fixtures/express/no-build/platformatic.app.json +0 -3
  22. package/test/fixtures/express/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  23. package/test/fixtures/express/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  24. package/test/fixtures/express/with-build/index.js +0 -17
  25. package/test/fixtures/express/with-build/package.json +0 -7
  26. package/test/fixtures/express/with-build/platformatic.app.json +0 -3
  27. package/test/fixtures/express/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  28. package/test/fixtures/express/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  29. package/test/fixtures/fastify/no-build/index.js +0 -14
  30. package/test/fixtures/fastify/no-build/package.json +0 -7
  31. package/test/fixtures/fastify/no-build/platformatic.app.json +0 -3
  32. package/test/fixtures/fastify/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  33. package/test/fixtures/fastify/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  34. package/test/fixtures/fastify/with-build/index.js +0 -15
  35. package/test/fixtures/fastify/with-build/package.json +0 -7
  36. package/test/fixtures/fastify/with-build/platformatic.app.json +0 -3
  37. package/test/fixtures/fastify/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  38. package/test/fixtures/fastify/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  39. package/test/fixtures/next/composer-autodetect-prefix/next.config.mjs +0 -5
  40. package/test/fixtures/next/composer-autodetect-prefix/package.json +0 -15
  41. package/test/fixtures/next/composer-autodetect-prefix/platformatic.application.json +0 -8
  42. package/test/fixtures/next/composer-autodetect-prefix/platformatic.runtime.json +0 -21
  43. package/test/fixtures/next/composer-autodetect-prefix/src/app/layout.js +0 -7
  44. package/test/fixtures/next/composer-autodetect-prefix/src/app/page.js +0 -5
  45. package/test/fixtures/next/composer-with-prefix/next.config.js +0 -1
  46. package/test/fixtures/next/composer-with-prefix/package.json +0 -15
  47. package/test/fixtures/next/composer-with-prefix/platformatic.application.json +0 -11
  48. package/test/fixtures/next/composer-with-prefix/platformatic.runtime.json +0 -21
  49. package/test/fixtures/next/composer-with-prefix/src/app/layout.js +0 -7
  50. package/test/fixtures/next/composer-with-prefix/src/app/page.js +0 -5
  51. package/test/fixtures/next/composer-without-prefix/next.config.mjs +0 -3
  52. package/test/fixtures/next/composer-without-prefix/package.json +0 -15
  53. package/test/fixtures/next/composer-without-prefix/platformatic.application.json +0 -8
  54. package/test/fixtures/next/composer-without-prefix/platformatic.runtime.json +0 -21
  55. package/test/fixtures/next/composer-without-prefix/src/app/layout.js +0 -7
  56. package/test/fixtures/next/composer-without-prefix/src/app/page.js +0 -5
  57. package/test/fixtures/next/standalone/next.config.mjs +0 -3
  58. package/test/fixtures/next/standalone/package.json +0 -15
  59. package/test/fixtures/next/standalone/platformatic.runtime.json +0 -18
  60. package/test/fixtures/next/standalone/src/app/layout.js +0 -7
  61. package/test/fixtures/next/standalone/src/app/page.js +0 -5
  62. package/test/fixtures/nodejs/no-build/index.js +0 -21
  63. package/test/fixtures/nodejs/no-build/package.json +0 -7
  64. package/test/fixtures/nodejs/no-build/platformatic.app.json +0 -3
  65. package/test/fixtures/nodejs/no-build/platformatic.as-entrypoint.runtime.json +0 -19
  66. package/test/fixtures/nodejs/no-build/platformatic.no-entrypoint.runtime.json +0 -16
  67. package/test/fixtures/nodejs/no-configuration/index.js +0 -21
  68. package/test/fixtures/nodejs/no-configuration/platformatic.as-entrypoint.runtime.json +0 -18
  69. package/test/fixtures/nodejs/no-configuration/platformatic.no-entrypoint.runtime.json +0 -16
  70. package/test/fixtures/nodejs/with-build/index.js +0 -20
  71. package/test/fixtures/nodejs/with-build/package.json +0 -7
  72. package/test/fixtures/nodejs/with-build/platformatic.app.json +0 -3
  73. package/test/fixtures/nodejs/with-build/platformatic.as-entrypoint.runtime.json +0 -19
  74. package/test/fixtures/nodejs/with-build/platformatic.no-entrypoint.runtime.json +0 -16
  75. package/test/fixtures/platformatic-composer/platformatic.composer.json +0 -20
  76. package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +0 -23
  77. package/test/fixtures/platformatic-composer/plugin.js +0 -9
  78. package/test/fixtures/platformatic-service/platformatic.service.json +0 -15
  79. package/test/fixtures/platformatic-service/plugin.js +0 -12
  80. package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +0 -3
  81. package/test/fixtures/vite/composer-autodetect-prefix/index.html +0 -13
  82. package/test/fixtures/vite/composer-autodetect-prefix/main.js +0 -3
  83. package/test/fixtures/vite/composer-autodetect-prefix/package.json +0 -14
  84. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +0 -11
  85. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +0 -21
  86. package/test/fixtures/vite/composer-with-prefix/index.html +0 -13
  87. package/test/fixtures/vite/composer-with-prefix/main.js +0 -3
  88. package/test/fixtures/vite/composer-with-prefix/package.json +0 -14
  89. package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +0 -11
  90. package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +0 -21
  91. package/test/fixtures/vite/composer-without-prefix/index.html +0 -13
  92. package/test/fixtures/vite/composer-without-prefix/main.js +0 -3
  93. package/test/fixtures/vite/composer-without-prefix/package.json +0 -14
  94. package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +0 -8
  95. package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +0 -21
  96. package/test/fixtures/vite/standalone/custom.vite.config.js +0 -3
  97. package/test/fixtures/vite/standalone/index.html +0 -13
  98. package/test/fixtures/vite/standalone/main.js +0 -3
  99. package/test/fixtures/vite/standalone/package.json +0 -14
  100. package/test/fixtures/vite/standalone/platformatic.runtime.json +0 -18
  101. package/test/next.test.js +0 -85
  102. package/test/node.test.js +0 -66
  103. package/test/vite.test.js +0 -89
package/schema.json CHANGED
@@ -1,522 +1,12 @@
1
1
  {
2
- "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.0.0-alpha.4.json",
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/basic/2.0.0-alpha.5.json",
3
3
  "$schema": "http://json-schema.org/draft-07/schema#",
4
4
  "title": "Platformatic Stackable",
5
5
  "type": "object",
6
6
  "properties": {
7
7
  "$schema": {
8
8
  "type": "string"
9
- },
10
- "server": {
11
- "type": "object",
12
- "properties": {
13
- "hostname": {
14
- "type": "string"
15
- },
16
- "port": {
17
- "anyOf": [
18
- {
19
- "type": "integer"
20
- },
21
- {
22
- "type": "string"
23
- }
24
- ]
25
- },
26
- "pluginTimeout": {
27
- "type": "integer"
28
- },
29
- "healthCheck": {
30
- "anyOf": [
31
- {
32
- "type": "boolean"
33
- },
34
- {
35
- "type": "object",
36
- "properties": {
37
- "enabled": {
38
- "type": "boolean"
39
- },
40
- "interval": {
41
- "type": "integer"
42
- }
43
- },
44
- "additionalProperties": true
45
- }
46
- ]
47
- },
48
- "ignoreTrailingSlash": {
49
- "type": "boolean"
50
- },
51
- "ignoreDuplicateSlashes": {
52
- "type": "boolean"
53
- },
54
- "connectionTimeout": {
55
- "type": "integer"
56
- },
57
- "keepAliveTimeout": {
58
- "type": "integer",
59
- "default": 5000
60
- },
61
- "maxRequestsPerSocket": {
62
- "type": "integer"
63
- },
64
- "forceCloseConnections": {
65
- "anyOf": [
66
- {
67
- "type": "boolean"
68
- },
69
- {
70
- "type": "string",
71
- "pattern": "^idle$"
72
- }
73
- ]
74
- },
75
- "requestTimeout": {
76
- "type": "integer"
77
- },
78
- "bodyLimit": {
79
- "type": "integer"
80
- },
81
- "maxParamLength": {
82
- "type": "integer"
83
- },
84
- "disableRequestLogging": {
85
- "type": "boolean"
86
- },
87
- "exposeHeadRoutes": {
88
- "type": "boolean"
89
- },
90
- "logger": {
91
- "anyOf": [
92
- {
93
- "type": "boolean"
94
- },
95
- {
96
- "type": "object",
97
- "properties": {
98
- "level": {
99
- "type": "string"
100
- },
101
- "transport": {
102
- "anyOf": [
103
- {
104
- "type": "object",
105
- "properties": {
106
- "target": {
107
- "type": "string",
108
- "resolveModule": true
109
- },
110
- "options": {
111
- "type": "object"
112
- }
113
- },
114
- "additionalProperties": false
115
- },
116
- {
117
- "type": "object",
118
- "properties": {
119
- "targets": {
120
- "type": "array",
121
- "items": {
122
- "type": "object",
123
- "properties": {
124
- "target": {
125
- "type": "string",
126
- "resolveModule": true
127
- },
128
- "options": {
129
- "type": "object"
130
- },
131
- "level": {
132
- "type": "string"
133
- },
134
- "additionalProperties": false
135
- }
136
- }
137
- },
138
- "options": {
139
- "type": "object"
140
- }
141
- },
142
- "additionalProperties": false
143
- }
144
- ]
145
- },
146
- "pipeline": {
147
- "type": "object",
148
- "properties": {
149
- "target": {
150
- "type": "string",
151
- "resolveModule": true
152
- },
153
- "options": {
154
- "type": "object"
155
- }
156
- },
157
- "additionalProperties": false
158
- }
159
- },
160
- "additionalProperties": true
161
- }
162
- ]
163
- },
164
- "serializerOpts": {
165
- "type": "object",
166
- "properties": {
167
- "schema": {
168
- "type": "object"
169
- },
170
- "ajv": {
171
- "type": "object"
172
- },
173
- "rounding": {
174
- "type": "string",
175
- "enum": [
176
- "floor",
177
- "ceil",
178
- "round",
179
- "trunc"
180
- ],
181
- "default": "trunc"
182
- },
183
- "debugMode": {
184
- "type": "boolean"
185
- },
186
- "mode": {
187
- "type": "string",
188
- "enum": [
189
- "debug",
190
- "standalone"
191
- ]
192
- },
193
- "largeArraySize": {
194
- "anyOf": [
195
- {
196
- "type": "integer"
197
- },
198
- {
199
- "type": "string"
200
- }
201
- ],
202
- "default": 20000
203
- },
204
- "largeArrayMechanism": {
205
- "type": "string",
206
- "enum": [
207
- "default",
208
- "json-stringify"
209
- ],
210
- "default": "default"
211
- }
212
- }
213
- },
214
- "caseSensitive": {
215
- "type": "boolean"
216
- },
217
- "requestIdHeader": {
218
- "anyOf": [
219
- {
220
- "type": "string"
221
- },
222
- {
223
- "type": "boolean",
224
- "const": false
225
- }
226
- ]
227
- },
228
- "requestIdLogLabel": {
229
- "type": "string"
230
- },
231
- "jsonShorthand": {
232
- "type": "boolean"
233
- },
234
- "trustProxy": {
235
- "anyOf": [
236
- {
237
- "type": "boolean"
238
- },
239
- {
240
- "type": "string"
241
- },
242
- {
243
- "type": "array",
244
- "items": {
245
- "type": "string"
246
- }
247
- },
248
- {
249
- "type": "integer"
250
- }
251
- ]
252
- },
253
- "http2": {
254
- "type": "boolean"
255
- },
256
- "https": {
257
- "type": "object",
258
- "properties": {
259
- "allowHTTP1": {
260
- "type": "boolean"
261
- },
262
- "key": {
263
- "anyOf": [
264
- {
265
- "type": "string"
266
- },
267
- {
268
- "type": "object",
269
- "properties": {
270
- "path": {
271
- "type": "string",
272
- "resolvePath": true
273
- }
274
- },
275
- "additionalProperties": false
276
- },
277
- {
278
- "type": "array",
279
- "items": {
280
- "anyOf": [
281
- {
282
- "type": "string"
283
- },
284
- {
285
- "type": "object",
286
- "properties": {
287
- "path": {
288
- "type": "string",
289
- "resolvePath": true
290
- }
291
- },
292
- "additionalProperties": false
293
- }
294
- ]
295
- }
296
- }
297
- ]
298
- },
299
- "cert": {
300
- "anyOf": [
301
- {
302
- "type": "string"
303
- },
304
- {
305
- "type": "object",
306
- "properties": {
307
- "path": {
308
- "type": "string",
309
- "resolvePath": true
310
- }
311
- },
312
- "additionalProperties": false
313
- },
314
- {
315
- "type": "array",
316
- "items": {
317
- "anyOf": [
318
- {
319
- "type": "string"
320
- },
321
- {
322
- "type": "object",
323
- "properties": {
324
- "path": {
325
- "type": "string",
326
- "resolvePath": true
327
- }
328
- },
329
- "additionalProperties": false
330
- }
331
- ]
332
- }
333
- }
334
- ]
335
- },
336
- "requestCert": {
337
- "type": "boolean"
338
- },
339
- "rejectUnauthorized": {
340
- "type": "boolean"
341
- }
342
- },
343
- "additionalProperties": false,
344
- "required": [
345
- "key",
346
- "cert"
347
- ]
348
- },
349
- "cors": {
350
- "type": "object",
351
- "$comment": "See https://github.com/fastify/fastify-cors",
352
- "properties": {
353
- "origin": {
354
- "anyOf": [
355
- {
356
- "type": "boolean"
357
- },
358
- {
359
- "type": "string"
360
- },
361
- {
362
- "type": "array",
363
- "items": {
364
- "anyOf": [
365
- {
366
- "type": "string"
367
- },
368
- {
369
- "type": "object",
370
- "properties": {
371
- "regexp": {
372
- "type": "string"
373
- }
374
- },
375
- "required": [
376
- "regexp"
377
- ]
378
- }
379
- ]
380
- }
381
- },
382
- {
383
- "type": "object",
384
- "properties": {
385
- "regexp": {
386
- "type": "string"
387
- }
388
- },
389
- "required": [
390
- "regexp"
391
- ]
392
- }
393
- ]
394
- },
395
- "methods": {
396
- "type": "array",
397
- "items": {
398
- "type": "string"
399
- }
400
- },
401
- "allowedHeaders": {
402
- "type": "string",
403
- "description": "Comma separated string of allowed headers."
404
- },
405
- "exposedHeaders": {
406
- "anyOf": [
407
- {
408
- "type": "array",
409
- "items": {
410
- "type": "string"
411
- }
412
- },
413
- {
414
- "type": "string",
415
- "description": "Comma separated string of exposed headers."
416
- }
417
- ]
418
- },
419
- "credentials": {
420
- "type": "boolean"
421
- },
422
- "maxAge": {
423
- "type": "integer"
424
- },
425
- "preflightContinue": {
426
- "type": "boolean",
427
- "default": false
428
- },
429
- "optionsSuccessStatus": {
430
- "type": "integer",
431
- "default": 204
432
- },
433
- "preflight": {
434
- "type": "boolean",
435
- "default": true
436
- },
437
- "strictPreflight": {
438
- "type": "boolean",
439
- "default": true
440
- },
441
- "hideOptionsRoute": {
442
- "type": "boolean",
443
- "default": true
444
- }
445
- },
446
- "additionalProperties": false
447
- }
448
- },
449
- "additionalProperties": false
450
- },
451
- "watch": {
452
- "anyOf": [
453
- {
454
- "type": "object",
455
- "properties": {
456
- "enabled": {
457
- "default": true,
458
- "anyOf": [
459
- {
460
- "type": "boolean"
461
- },
462
- {
463
- "type": "string"
464
- }
465
- ]
466
- },
467
- "allow": {
468
- "type": "array",
469
- "items": {
470
- "type": "string"
471
- },
472
- "minItems": 1,
473
- "nullable": true,
474
- "default": null
475
- },
476
- "ignore": {
477
- "type": "array",
478
- "items": {
479
- "type": "string"
480
- },
481
- "nullable": true,
482
- "default": null
483
- }
484
- },
485
- "additionalProperties": false
486
- },
487
- {
488
- "type": "boolean"
489
- },
490
- {
491
- "type": "string"
492
- }
493
- ]
494
- },
495
- "application": {
496
- "type": "object",
497
- "properties": {
498
- "base": {
499
- "type": "string"
500
- }
501
- },
502
- "additionalProperties": false
503
- },
504
- "vite": {
505
- "type": "object",
506
- "properties": {
507
- "configFile": {
508
- "oneOf": [
509
- {
510
- "type": "string"
511
- },
512
- {
513
- "type": "boolean"
514
- }
515
- ]
516
- }
517
- },
518
- "additionalProperties": false
519
9
  }
520
10
  },
521
- "additionalProperties": false
11
+ "additionalProperties": true
522
12
  }
package/test/helper.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { createDirectory, withResolvers } from '@platformatic/utils'
2
2
  import { deepStrictEqual, ok, strictEqual } from 'node:assert'
3
- import { writeFile } from 'node:fs/promises'
3
+ import { existsSync } from 'node:fs'
4
+ import { readFile, symlink, writeFile } from 'node:fs/promises'
4
5
  import { dirname, resolve } from 'node:path'
5
6
  import { setTimeout as sleep } from 'node:timers/promises'
6
7
  import { Client, request } from 'undici'
@@ -11,10 +12,38 @@ import { buildServer, platformaticRuntime } from '../../runtime/index.js'
11
12
  export { setTimeout as sleep } from 'node:timers/promises'
12
13
 
13
14
  let hrmVersion = Date.now()
14
- export const fixturesDir = resolve(import.meta.dirname, './fixtures')
15
+ export let fixturesDir
15
16
 
16
- export async function createRuntime (t, path) {
17
+ export function setFixturesDir (directory) {
18
+ fixturesDir = directory
19
+ }
20
+
21
+ // This is used to debug tests
22
+ export function pause (url, timeout = 300000) {
23
+ console.log(`Server is listening at ${url}`)
24
+ return sleep(timeout)
25
+ }
26
+
27
+ export async function ensureDependency (directory, pkg, source) {
28
+ const [namespace, name] = pkg.includes('/') ? pkg.split('/') : ['', pkg]
29
+ const basedir = resolve(fixturesDir, directory, `node_modules/${namespace}`)
30
+ const destination = resolve(basedir, name)
31
+
32
+ await createDirectory(basedir)
33
+ if (!existsSync(destination)) {
34
+ await symlink(source, destination, 'dir')
35
+ }
36
+ }
37
+
38
+ export async function createRuntime (t, path, packageRoot) {
17
39
  const configFile = resolve(fixturesDir, path)
40
+
41
+ if (packageRoot) {
42
+ const packageName = JSON.parse(await readFile(resolve(packageRoot, 'package.json'), 'utf-8')).name
43
+ const root = dirname(configFile)
44
+ await ensureDependency(root, packageName, packageRoot)
45
+ }
46
+
18
47
  const config = await loadConfig({}, ['-c', configFile], platformaticRuntime)
19
48
  const runtime = await buildServer(config.configManager.current)
20
49
  const url = await runtime.start()
@@ -58,8 +87,8 @@ export async function getLogs (app) {
58
87
  .map(m => JSON.parse(m))
59
88
  }
60
89
 
61
- export async function updateHMRVersion () {
62
- const versionFile = resolve(fixturesDir, '../tmp/version.js')
90
+ export async function updateHMRVersion (versionFile) {
91
+ versionFile ??= resolve(fixturesDir, '../tmp/version.js')
63
92
  await createDirectory(dirname(versionFile))
64
93
  await writeFile(versionFile, `export const version = ${hrmVersion++}\n`, 'utf-8')
65
94
  }
@@ -81,10 +110,10 @@ export async function verifyHTMLViaHTTP (baseUrl, path, contents) {
81
110
  const html = await body.text()
82
111
 
83
112
  deepStrictEqual(statusCode, 200)
84
- ok(headers['content-type'].startsWith('text/html'))
113
+ ok(headers['content-type']?.startsWith('text/html'))
85
114
 
86
115
  for (const content of contents) {
87
- ok(html.includes(content))
116
+ ok(content instanceof RegExp ? content.test(html) : html.includes(content))
88
117
  }
89
118
  }
90
119
 
@@ -95,11 +124,11 @@ export async function verifyHTMLViaInject (app, serviceId, url, contents) {
95
124
  ok(headers['content-type'].startsWith('text/html'))
96
125
 
97
126
  for (const content of contents) {
98
- ok(html.includes(content))
127
+ ok(content instanceof RegExp ? content.test(html) : html.includes(content))
99
128
  }
100
129
  }
101
130
 
102
- export async function verifyHMR (baseUrl, path, versionFile, protocol, handler) {
131
+ export async function verifyHMR (baseUrl, path, protocol, handler) {
103
132
  const connection = withResolvers()
104
133
  const reload = withResolvers()
105
134
  const ac = new AbortController()