@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.
- package/LICENSE +201 -0
- package/NOTICE +13 -0
- package/README.md +13 -0
- package/config.d.ts +164 -0
- package/eslint.config.js +5 -0
- package/index.js +198 -0
- package/lib/schema.js +46 -0
- package/package.json +47 -0
- package/schema.json +541 -0
- package/test/fixtures/platformatic-composer/platformatic.composer.json +20 -0
- package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +23 -0
- package/test/fixtures/platformatic-composer/plugin.js +9 -0
- package/test/fixtures/platformatic-service/platformatic.service.json +15 -0
- package/test/fixtures/platformatic-service/plugin.js +19 -0
- package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +3 -0
- package/test/fixtures/vite/composer-autodetect-prefix/index.html +13 -0
- package/test/fixtures/vite/composer-autodetect-prefix/main.js +3 -0
- package/test/fixtures/vite/composer-autodetect-prefix/package.json +14 -0
- package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +11 -0
- package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +20 -0
- package/test/fixtures/vite/composer-with-prefix/index.html +13 -0
- package/test/fixtures/vite/composer-with-prefix/main.js +3 -0
- package/test/fixtures/vite/composer-with-prefix/package.json +14 -0
- package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +11 -0
- package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +21 -0
- package/test/fixtures/vite/composer-without-prefix/index.html +13 -0
- package/test/fixtures/vite/composer-without-prefix/main.js +3 -0
- package/test/fixtures/vite/composer-without-prefix/package.json +14 -0
- package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +8 -0
- package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +21 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/client/index.html +12 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/client/index.js +7 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/package.json +15 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/platformatic.application.json +11 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/platformatic.runtime.json +21 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/server.js +35 -0
- package/test/fixtures/vite/ssr-autodetect-prefix/vite.config.js +7 -0
- package/test/fixtures/vite/ssr-with-prefix/client/index.html +12 -0
- package/test/fixtures/vite/ssr-with-prefix/client/index.js +7 -0
- package/test/fixtures/vite/ssr-with-prefix/package.json +15 -0
- package/test/fixtures/vite/ssr-with-prefix/platformatic.application.json +14 -0
- package/test/fixtures/vite/ssr-with-prefix/platformatic.runtime.json +21 -0
- package/test/fixtures/vite/ssr-with-prefix/server.js +35 -0
- package/test/fixtures/vite/ssr-with-prefix/vite.config.js +7 -0
- package/test/fixtures/vite/ssr-without-prefix/client/index.html +12 -0
- package/test/fixtures/vite/ssr-without-prefix/client/index.js +7 -0
- package/test/fixtures/vite/ssr-without-prefix/package.json +15 -0
- package/test/fixtures/vite/ssr-without-prefix/platformatic.application.json +11 -0
- package/test/fixtures/vite/ssr-without-prefix/platformatic.runtime.json +21 -0
- package/test/fixtures/vite/ssr-without-prefix/server.js +34 -0
- package/test/fixtures/vite/ssr-without-prefix/vite.config.js +7 -0
- package/test/fixtures/vite/standalone/custom.vite.config.js +3 -0
- package/test/fixtures/vite/standalone/index.html +13 -0
- package/test/fixtures/vite/standalone/main.js +3 -0
- package/test/fixtures/vite/standalone/package.json +15 -0
- package/test/fixtures/vite/standalone/platformatic.runtime.json +18 -0
- 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
|
+
})
|