@platformatic/vite 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 (57) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +13 -0
  3. package/README.md +13 -0
  4. package/config.d.ts +164 -0
  5. package/eslint.config.js +5 -0
  6. package/index.js +198 -0
  7. package/lib/schema.js +46 -0
  8. package/package.json +47 -0
  9. package/schema.json +541 -0
  10. package/test/fixtures/platformatic-composer/platformatic.composer.json +20 -0
  11. package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +23 -0
  12. package/test/fixtures/platformatic-composer/plugin.js +9 -0
  13. package/test/fixtures/platformatic-service/platformatic.service.json +15 -0
  14. package/test/fixtures/platformatic-service/plugin.js +19 -0
  15. package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +3 -0
  16. package/test/fixtures/vite/composer-autodetect-prefix/index.html +13 -0
  17. package/test/fixtures/vite/composer-autodetect-prefix/main.js +3 -0
  18. package/test/fixtures/vite/composer-autodetect-prefix/package.json +14 -0
  19. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +11 -0
  20. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +20 -0
  21. package/test/fixtures/vite/composer-with-prefix/index.html +13 -0
  22. package/test/fixtures/vite/composer-with-prefix/main.js +3 -0
  23. package/test/fixtures/vite/composer-with-prefix/package.json +14 -0
  24. package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +11 -0
  25. package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +21 -0
  26. package/test/fixtures/vite/composer-without-prefix/index.html +13 -0
  27. package/test/fixtures/vite/composer-without-prefix/main.js +3 -0
  28. package/test/fixtures/vite/composer-without-prefix/package.json +14 -0
  29. package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +8 -0
  30. package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +21 -0
  31. package/test/fixtures/vite/ssr-autodetect-prefix/client/index.html +12 -0
  32. package/test/fixtures/vite/ssr-autodetect-prefix/client/index.js +7 -0
  33. package/test/fixtures/vite/ssr-autodetect-prefix/package.json +15 -0
  34. package/test/fixtures/vite/ssr-autodetect-prefix/platformatic.application.json +11 -0
  35. package/test/fixtures/vite/ssr-autodetect-prefix/platformatic.runtime.json +21 -0
  36. package/test/fixtures/vite/ssr-autodetect-prefix/server.js +35 -0
  37. package/test/fixtures/vite/ssr-autodetect-prefix/vite.config.js +7 -0
  38. package/test/fixtures/vite/ssr-with-prefix/client/index.html +12 -0
  39. package/test/fixtures/vite/ssr-with-prefix/client/index.js +7 -0
  40. package/test/fixtures/vite/ssr-with-prefix/package.json +15 -0
  41. package/test/fixtures/vite/ssr-with-prefix/platformatic.application.json +14 -0
  42. package/test/fixtures/vite/ssr-with-prefix/platformatic.runtime.json +21 -0
  43. package/test/fixtures/vite/ssr-with-prefix/server.js +35 -0
  44. package/test/fixtures/vite/ssr-with-prefix/vite.config.js +7 -0
  45. package/test/fixtures/vite/ssr-without-prefix/client/index.html +12 -0
  46. package/test/fixtures/vite/ssr-without-prefix/client/index.js +7 -0
  47. package/test/fixtures/vite/ssr-without-prefix/package.json +15 -0
  48. package/test/fixtures/vite/ssr-without-prefix/platformatic.application.json +11 -0
  49. package/test/fixtures/vite/ssr-without-prefix/platformatic.runtime.json +21 -0
  50. package/test/fixtures/vite/ssr-without-prefix/server.js +34 -0
  51. package/test/fixtures/vite/ssr-without-prefix/vite.config.js +7 -0
  52. package/test/fixtures/vite/standalone/custom.vite.config.js +3 -0
  53. package/test/fixtures/vite/standalone/index.html +13 -0
  54. package/test/fixtures/vite/standalone/main.js +3 -0
  55. package/test/fixtures/vite/standalone/package.json +15 -0
  56. package/test/fixtures/vite/standalone/platformatic.runtime.json +18 -0
  57. package/test/index.test.js +161 -0
@@ -0,0 +1,161 @@
1
+ import { resolve } from 'node:path'
2
+ import { test } from 'node:test'
3
+ import {
4
+ createRuntime,
5
+ setFixturesDir,
6
+ updateHMRVersion,
7
+ verifyHMR,
8
+ verifyHTMLViaHTTP,
9
+ verifyHTMLViaInject,
10
+ verifyJSONViaHTTP,
11
+ verifyJSONViaInject,
12
+ } from '../../basic/test/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
+ const packageRoot = resolve(import.meta.dirname, '..')
25
+ setFixturesDir(resolve(import.meta.dirname, './fixtures'))
26
+
27
+ test('can detect and start a Vite application', async t => {
28
+ await updateHMRVersion()
29
+ const { url } = await createRuntime(t, 'vite/standalone/platformatic.runtime.json', packageRoot)
30
+
31
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/main.js"></script>']
32
+
33
+ await verifyHTMLViaHTTP(url, '/', htmlContents)
34
+ await verifyHMR(url, '/', 'vite-hmr', websocketHMRHandler)
35
+ })
36
+
37
+ test('can detect and start a Vite application when exposed in a composer with a prefix', async t => {
38
+ await updateHMRVersion()
39
+ const { runtime, url } = await createRuntime(t, 'vite/composer-with-prefix/platformatic.runtime.json', packageRoot)
40
+
41
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/frontend/main.js"></script>']
42
+
43
+ await verifyHTMLViaHTTP(url, '/frontend/', htmlContents)
44
+ await verifyHTMLViaInject(runtime, 'main', '/frontend', htmlContents)
45
+ await verifyHMR(url, '/frontend/', 'vite-hmr', websocketHMRHandler)
46
+
47
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
48
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
49
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
50
+
51
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
52
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
53
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
54
+ })
55
+
56
+ test('can detect and start a Vite application when exposed in a composer without a prefix', async t => {
57
+ await updateHMRVersion()
58
+ const { runtime, url } = await createRuntime(t, 'vite/composer-without-prefix/platformatic.runtime.json', packageRoot)
59
+
60
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/main.js"></script>']
61
+
62
+ await verifyHTMLViaHTTP(url, '/', htmlContents)
63
+ await verifyHTMLViaInject(runtime, 'main', '/', htmlContents)
64
+ await verifyHMR(url, '/', 'vite-hmr', websocketHMRHandler)
65
+
66
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
67
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
68
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
69
+
70
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
71
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
72
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
73
+ })
74
+
75
+ // In this file the application purposely does not specify a platformatic.application.json to see if we automatically detect one
76
+ test('can detect and start a Vite application when exposed in a composer with a custom config and by autodetecting the prefix', async t => {
77
+ await updateHMRVersion()
78
+ const { runtime, url } = await createRuntime(
79
+ t,
80
+ 'vite/composer-autodetect-prefix/platformatic.runtime.json',
81
+ packageRoot
82
+ )
83
+
84
+ const htmlContents = ['<title>Vite App</title>', '<script type="module" src="/nested/base/dir/main.js"></script>']
85
+
86
+ await verifyHTMLViaHTTP(url, '/nested/base/dir/', htmlContents)
87
+ await verifyHTMLViaInject(runtime, 'main', '/nested/base/dir', htmlContents)
88
+ await verifyHMR(url, '/nested/base/dir/', 'vite-hmr', websocketHMRHandler)
89
+
90
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
91
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
92
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
93
+
94
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
95
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
96
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
97
+ })
98
+
99
+ test('can detect and start a Vite application in SSR mode when exposed in a composer with a prefix', async t => {
100
+ await updateHMRVersion()
101
+ const { runtime, url } = await createRuntime(t, 'vite/ssr-with-prefix/platformatic.runtime.json', packageRoot)
102
+
103
+ const htmlContents = ['<title>Vite App</title>', /Hello from v\d+ t\d+/]
104
+
105
+ await verifyHTMLViaHTTP(url, '/frontend/', htmlContents)
106
+ await verifyHTMLViaInject(runtime, 'main', '/frontend', htmlContents)
107
+ await verifyHMR(url, '/frontend/', 'vite-hmr', websocketHMRHandler)
108
+
109
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
110
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
111
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
112
+ await verifyJSONViaHTTP(url, '/service/mesh', 200, { ok: true })
113
+
114
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
115
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
116
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
117
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/mesh', 200, { ok: true })
118
+ })
119
+
120
+ test('can detect and start a Vite application in SSR mode when exposed in a composer without a prefix', async t => {
121
+ await updateHMRVersion()
122
+ const { runtime, url } = await createRuntime(t, 'vite/ssr-without-prefix/platformatic.runtime.json', packageRoot)
123
+
124
+ const htmlContents = ['<title>Vite App</title>', /Hello from v\d+ t\d+/]
125
+
126
+ await verifyHTMLViaHTTP(url, '/', htmlContents)
127
+ await verifyHTMLViaInject(runtime, 'main', '/', htmlContents)
128
+ await verifyHMR(url, '/', 'vite-hmr', websocketHMRHandler)
129
+
130
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
131
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
132
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
133
+ await verifyJSONViaHTTP(url, '/service/mesh', 200, { ok: true })
134
+
135
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
136
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
137
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
138
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/mesh', 200, { ok: true })
139
+ })
140
+
141
+ // In this file the application purposely does not specify a platformatic.application.json to see if we automatically detect one
142
+ test('can detect and start a Vite application in SSR mode when exposed in a composer with a custom config and by autodetecting the prefix', async t => {
143
+ await updateHMRVersion()
144
+ const { runtime, url } = await createRuntime(t, 'vite/ssr-autodetect-prefix/platformatic.runtime.json', packageRoot)
145
+
146
+ const htmlContents = ['<title>Vite App</title>', /Hello from v\d+ t\d+/]
147
+
148
+ await verifyHTMLViaHTTP(url, '/nested/base/dir/', htmlContents)
149
+ await verifyHTMLViaInject(runtime, 'main', '/nested/base/dir', htmlContents)
150
+ await verifyHMR(url, '/nested/base/dir/', 'vite-hmr', websocketHMRHandler)
151
+
152
+ await verifyJSONViaHTTP(url, '/plugin', 200, { ok: true })
153
+ await verifyJSONViaHTTP(url, '/frontend/plugin', 200, { ok: true })
154
+ await verifyJSONViaHTTP(url, '/service/direct', 200, { ok: true })
155
+ await verifyJSONViaHTTP(url, '/service/mesh', 200, { ok: true })
156
+
157
+ await verifyJSONViaInject(runtime, 'main', 'GET', 'plugin', 200, { ok: true })
158
+ await verifyJSONViaInject(runtime, 'main', 'GET', '/frontend/plugin', 200, { ok: true })
159
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/direct', 200, { ok: true })
160
+ await verifyJSONViaInject(runtime, 'service', 'GET', '/mesh', 200, { ok: true })
161
+ })