@platformatic/basic 2.0.0-alpha.3 → 2.0.0-alpha.4

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 (69) hide show
  1. package/config.d.ts +159 -0
  2. package/eslint.config.js +3 -1
  3. package/index.js +15 -2
  4. package/lib/base.js +7 -5
  5. package/lib/errors.js +8 -0
  6. package/lib/next.js +105 -0
  7. package/lib/schema.js +23 -0
  8. package/lib/server.js +8 -9
  9. package/lib/utils.js +5 -34
  10. package/lib/vite.js +105 -0
  11. package/lib/worker/child-manager.js +78 -0
  12. package/lib/worker/child-process.js +84 -0
  13. package/lib/worker/next-loader.js +137 -0
  14. package/lib/worker/server-listener.js +29 -0
  15. package/package.json +22 -8
  16. package/schema.json +522 -0
  17. package/test/express.test.js +9 -9
  18. package/test/fastify.test.js +9 -9
  19. package/test/fixtures/next/composer-autodetect-prefix/next.config.mjs +5 -0
  20. package/test/fixtures/next/composer-autodetect-prefix/package.json +15 -0
  21. package/test/fixtures/next/composer-autodetect-prefix/platformatic.application.json +8 -0
  22. package/test/fixtures/next/composer-autodetect-prefix/platformatic.runtime.json +21 -0
  23. package/test/fixtures/next/composer-autodetect-prefix/src/app/layout.js +7 -0
  24. package/test/fixtures/next/composer-autodetect-prefix/src/app/page.js +5 -0
  25. package/test/fixtures/next/composer-with-prefix/next.config.js +1 -0
  26. package/test/fixtures/next/composer-with-prefix/package.json +15 -0
  27. package/test/fixtures/next/composer-with-prefix/platformatic.application.json +11 -0
  28. package/test/fixtures/next/composer-with-prefix/platformatic.runtime.json +21 -0
  29. package/test/fixtures/next/composer-with-prefix/src/app/layout.js +7 -0
  30. package/test/fixtures/next/composer-with-prefix/src/app/page.js +5 -0
  31. package/test/fixtures/next/composer-without-prefix/next.config.mjs +3 -0
  32. package/test/fixtures/next/composer-without-prefix/package.json +15 -0
  33. package/test/fixtures/next/composer-without-prefix/platformatic.application.json +8 -0
  34. package/test/fixtures/next/composer-without-prefix/platformatic.runtime.json +21 -0
  35. package/test/fixtures/next/composer-without-prefix/src/app/layout.js +7 -0
  36. package/test/fixtures/next/composer-without-prefix/src/app/page.js +5 -0
  37. package/test/fixtures/next/standalone/next.config.mjs +3 -0
  38. package/test/fixtures/next/standalone/package.json +15 -0
  39. package/test/fixtures/next/standalone/platformatic.runtime.json +18 -0
  40. package/test/fixtures/next/standalone/src/app/layout.js +7 -0
  41. package/test/fixtures/next/standalone/src/app/page.js +5 -0
  42. package/test/fixtures/platformatic-composer/platformatic.composer.json +20 -0
  43. package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +23 -0
  44. package/test/fixtures/platformatic-composer/plugin.js +9 -0
  45. package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +3 -0
  46. package/test/fixtures/vite/composer-autodetect-prefix/index.html +13 -0
  47. package/test/fixtures/vite/composer-autodetect-prefix/main.js +3 -0
  48. package/test/fixtures/vite/composer-autodetect-prefix/package.json +14 -0
  49. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +11 -0
  50. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +21 -0
  51. package/test/fixtures/vite/composer-with-prefix/index.html +13 -0
  52. package/test/fixtures/vite/composer-with-prefix/main.js +3 -0
  53. package/test/fixtures/vite/composer-with-prefix/package.json +14 -0
  54. package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +11 -0
  55. package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +21 -0
  56. package/test/fixtures/vite/composer-without-prefix/index.html +13 -0
  57. package/test/fixtures/vite/composer-without-prefix/main.js +3 -0
  58. package/test/fixtures/vite/composer-without-prefix/package.json +14 -0
  59. package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +8 -0
  60. package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +21 -0
  61. package/test/fixtures/vite/standalone/custom.vite.config.js +3 -0
  62. package/test/fixtures/vite/standalone/index.html +13 -0
  63. package/test/fixtures/vite/standalone/main.js +3 -0
  64. package/test/fixtures/vite/standalone/package.json +14 -0
  65. package/test/fixtures/vite/standalone/platformatic.runtime.json +18 -0
  66. package/test/helper.js +85 -14
  67. package/test/next.test.js +85 -0
  68. package/test/node.test.js +13 -13
  69. package/test/vite.test.js +89 -0
@@ -0,0 +1,85 @@
1
+ import { test } from 'node:test'
2
+ import {
3
+ createRuntime,
4
+ updateHMRVersion,
5
+ verifyHMR,
6
+ verifyHTMLViaHTTP,
7
+ verifyHTMLViaInject,
8
+ verifyJSONViaHTTP,
9
+ verifyJSONViaInject,
10
+ } from './helper.js'
11
+
12
+ function websocketHMRHandler (message, resolveConnection, resolveReload) {
13
+ switch (message.action) {
14
+ case 'sync':
15
+ resolveConnection()
16
+ break
17
+ case 'serverComponentChanges':
18
+ resolveReload()
19
+ }
20
+ }
21
+
22
+ test('can detect and start a Next application', async t => {
23
+ const versionFile = await updateHMRVersion()
24
+ const { url } = await createRuntime(t, 'next/standalone/platformatic.runtime.json')
25
+
26
+ await verifyHTMLViaHTTP(url, '/', ['<script src="/_next/static/chunks/main-app.js'])
27
+ await verifyHMR(url, '/_next/webpack-hmr', versionFile, undefined, websocketHMRHandler)
28
+ })
29
+
30
+ test('can detect and start a Next application when exposed in a composer with a prefix', async t => {
31
+ const versionFile = await updateHMRVersion()
32
+ const { runtime, url } = await createRuntime(t, 'next/composer-with-prefix/platformatic.runtime.json')
33
+
34
+ const htmlContents = ['<script src="/frontend/_next/static/chunks/main-app.js']
35
+
36
+ await verifyHTMLViaHTTP(url, '/frontend/', htmlContents)
37
+ await verifyHTMLViaInject(runtime, 'main', '/frontend', htmlContents)
38
+ await verifyHMR(url, '/frontend/_next/webpack-hmr', versionFile, undefined, websocketHMRHandler)
39
+
40
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
41
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
42
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
43
+
44
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
45
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
46
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
47
+ })
48
+
49
+ test('can detect and start a Next application when exposed in a composer without a prefix', async t => {
50
+ const versionFile = await updateHMRVersion()
51
+ const { runtime, url } = await createRuntime(t, 'next/composer-without-prefix/platformatic.runtime.json')
52
+
53
+ const htmlContents = ['<script src="/_next/static/chunks/main-app.js']
54
+
55
+ await verifyHTMLViaHTTP(url, '/', htmlContents)
56
+ await verifyHTMLViaInject(runtime, 'main', '/', htmlContents)
57
+ await verifyHMR(url, '/_next/webpack-hmr', versionFile, undefined, websocketHMRHandler)
58
+
59
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
60
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
61
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
62
+
63
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
64
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
65
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
66
+ })
67
+
68
+ test('can detect and start a Next application when exposed in a composer with a custom config and by autodetecting the prefix', async t => {
69
+ const versionFile = await updateHMRVersion()
70
+ const { runtime, url } = await createRuntime(t, 'next/composer-autodetect-prefix/platformatic.runtime.json')
71
+
72
+ const htmlContents = ['<script src="/nested/base/dir/_next/static/chunks/main-app.js']
73
+
74
+ await verifyHTMLViaHTTP(url, '/nested/base/dir/', htmlContents)
75
+ await verifyHTMLViaInject(runtime, 'main', '/nested/base/dir', htmlContents)
76
+ await verifyHMR(url, '/nested/base/dir/_next/webpack-hmr', versionFile, undefined, websocketHMRHandler)
77
+
78
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
79
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
80
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
81
+
82
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
83
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
84
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
85
+ })
package/test/node.test.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import { deepStrictEqual, ifError } from 'node:assert'
2
2
  import { test } from 'node:test'
3
- import { createRuntime, getLogs, verifyViaHTTP, verifyViaInject } from './helper.js'
3
+ import { createRuntime, getLogs, verifyJSONViaHTTP, verifyJSONViaInject } from './helper.js'
4
4
 
5
5
  test('can detect and start a Node.js application with no configuration files', async t => {
6
6
  const { runtime, url } = await createRuntime(t, 'nodejs/no-configuration/platformatic.as-entrypoint.runtime.json')
7
7
 
8
- await verifyViaHTTP(url, '/direct', 200, { ok: true })
9
- await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
8
+ await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
9
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
10
10
 
11
11
  const logs = await getLogs(runtime)
12
12
  deepStrictEqual(
@@ -18,8 +18,8 @@ test('can detect and start a Node.js application with no configuration files', a
18
18
  test('can detect and start a Node.js application with no configuration files and when not the entrypoint', async t => {
19
19
  const { runtime, url } = await createRuntime(t, 'nodejs/no-configuration/platformatic.no-entrypoint.runtime.json')
20
20
 
21
- await verifyViaHTTP(url, '/mesh', 200, { ok: true })
22
- await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
21
+ await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
22
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
23
23
 
24
24
  const logs = await getLogs(runtime)
25
25
 
@@ -34,8 +34,8 @@ test('can detect and start a Node.js application with no configuration files and
34
34
  test('can detect and start a Node.js application with no build function defined', async t => {
35
35
  const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.as-entrypoint.runtime.json')
36
36
 
37
- await verifyViaHTTP(url, '/direct', 200, { ok: true })
38
- await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
37
+ await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
38
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
39
39
 
40
40
  const logs = await getLogs(runtime)
41
41
  deepStrictEqual(logs, [])
@@ -44,22 +44,22 @@ test('can detect and start a Node.js application with no build function defined'
44
44
  test('can detect and start a Node.js application with no build function and when not the entrypoint', async t => {
45
45
  const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.no-entrypoint.runtime.json')
46
46
 
47
- await verifyViaHTTP(url, '/mesh', 200, { ok: true })
48
- await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
47
+ await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
48
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
49
49
  })
50
50
 
51
51
  test('can detect and start a Node.js application with build function defined', async t => {
52
52
  const { runtime, url } = await createRuntime(t, 'nodejs/with-build/platformatic.as-entrypoint.runtime.json')
53
53
 
54
- await verifyViaHTTP(url, '/direct', 200, { ok: true })
55
- await verifyViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
54
+ await verifyJSONViaHTTP(url, '/direct', 200, { ok: true })
55
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/direct', 200, { ok: true })
56
56
  })
57
57
 
58
58
  test('can detect and start a Node.js application with build function defined and when not the entrypoint', async t => {
59
59
  const { runtime, url } = await createRuntime(t, 'nodejs/no-build/platformatic.no-entrypoint.runtime.json')
60
60
 
61
- await verifyViaHTTP(url, '/mesh', 200, { ok: true })
62
- await verifyViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
61
+ await verifyJSONViaHTTP(url, '/mesh', 200, { ok: true })
62
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/mesh', 200, { ok: true })
63
63
 
64
64
  const details = await runtime.getServiceDetails('internal')
65
65
  ifError(details.url)
@@ -0,0 +1,89 @@
1
+ 'use strict'
2
+
3
+ import { test } from 'node:test'
4
+ import {
5
+ createRuntime,
6
+ updateHMRVersion,
7
+ verifyHMR,
8
+ verifyHTMLViaHTTP,
9
+ verifyHTMLViaInject,
10
+ verifyJSONViaHTTP,
11
+ verifyJSONViaInject,
12
+ } from './helper.js'
13
+
14
+ function websocketHMRHandler (message, resolveConnection, resolveReload) {
15
+ switch (message.type) {
16
+ case 'connected':
17
+ resolveConnection()
18
+ break
19
+ case 'full-reload':
20
+ resolveReload()
21
+ }
22
+ }
23
+
24
+ test('can detect and start a Vite application', async t => {
25
+ const versionFile = await updateHMRVersion()
26
+ const { url } = await createRuntime(t, 'vite/standalone/platformatic.runtime.json')
27
+
28
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/main.js"></script>']
29
+
30
+ await verifyHTMLViaHTTP(url, '/', htmlContents)
31
+ await verifyHMR(url, '/', versionFile, 'vite-hmr', websocketHMRHandler)
32
+ })
33
+
34
+ test('can detect and start a Vite application when exposed in a composer with a prefix', async t => {
35
+ const versionFile = await updateHMRVersion()
36
+ const { runtime, url } = await createRuntime(t, 'vite/composer-with-prefix/platformatic.runtime.json')
37
+
38
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/frontend/main.js"></script>']
39
+
40
+ await verifyHTMLViaHTTP(url, '/frontend/', htmlContents)
41
+ await verifyHTMLViaInject(runtime, 'main', '/frontend', htmlContents)
42
+ await verifyHMR(url, '/frontend/', versionFile, 'vite-hmr', websocketHMRHandler)
43
+
44
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
45
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
46
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
47
+
48
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
49
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
50
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
51
+ })
52
+
53
+ test('can detect and start a Vite application when exposed in a composer without a prefix', async t => {
54
+ const versionFile = await updateHMRVersion()
55
+ const { runtime, url } = await createRuntime(t, 'vite/composer-without-prefix/platformatic.runtime.json')
56
+
57
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/main.js"></script>']
58
+
59
+ await verifyHTMLViaHTTP(url, '/', htmlContents)
60
+ await verifyHTMLViaInject(runtime, 'main', '/', htmlContents)
61
+ await verifyHMR(url, '/', versionFile, 'vite-hmr', websocketHMRHandler)
62
+
63
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
64
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
65
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
66
+
67
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
68
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
69
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
70
+ })
71
+
72
+ test('can detect and start a Vite application when exposed in a composer with a custom config and by autodetecting the prefix', async t => {
73
+ const versionFile = await updateHMRVersion()
74
+ const { runtime, url } = await createRuntime(t, 'vite/composer-autodetect-prefix/platformatic.runtime.json')
75
+
76
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/nested/base/dir/main.js"></script>']
77
+
78
+ await verifyHTMLViaHTTP(url, '/nested/base/dir/', htmlContents)
79
+ await verifyHTMLViaInject(runtime, 'main', '/nested/base/dir', htmlContents)
80
+ await verifyHMR(url, '/nested/base/dir/', versionFile, 'vite-hmr', websocketHMRHandler)
81
+
82
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
83
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
84
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
85
+
86
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
87
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
88
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
89
+ })