@platformatic/vite 2.0.0-alpha.7 → 2.0.0-alpha.8

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 (54) hide show
  1. package/config.d.ts +14 -7
  2. package/eslint.config.js +1 -1
  3. package/index.js +274 -53
  4. package/lib/schema.js +49 -26
  5. package/package.json +11 -10
  6. package/schema.json +63 -31
  7. package/test/fixtures/platformatic-composer/platformatic.composer.json +0 -20
  8. package/test/fixtures/platformatic-composer/platformatic.no-prefix.composer.json +0 -23
  9. package/test/fixtures/platformatic-composer/plugin.js +0 -9
  10. package/test/fixtures/platformatic-service/platformatic.service.json +0 -15
  11. package/test/fixtures/platformatic-service/plugin.js +0 -19
  12. package/test/fixtures/vite/composer-autodetect-prefix/custom.vite.config.js +0 -3
  13. package/test/fixtures/vite/composer-autodetect-prefix/index.html +0 -13
  14. package/test/fixtures/vite/composer-autodetect-prefix/main.js +0 -3
  15. package/test/fixtures/vite/composer-autodetect-prefix/package.json +0 -14
  16. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.application.json +0 -11
  17. package/test/fixtures/vite/composer-autodetect-prefix/platformatic.runtime.json +0 -20
  18. package/test/fixtures/vite/composer-with-prefix/index.html +0 -13
  19. package/test/fixtures/vite/composer-with-prefix/main.js +0 -3
  20. package/test/fixtures/vite/composer-with-prefix/package.json +0 -14
  21. package/test/fixtures/vite/composer-with-prefix/platformatic.application.json +0 -11
  22. package/test/fixtures/vite/composer-with-prefix/platformatic.runtime.json +0 -21
  23. package/test/fixtures/vite/composer-without-prefix/index.html +0 -13
  24. package/test/fixtures/vite/composer-without-prefix/main.js +0 -3
  25. package/test/fixtures/vite/composer-without-prefix/package.json +0 -14
  26. package/test/fixtures/vite/composer-without-prefix/platformatic.application.json +0 -8
  27. package/test/fixtures/vite/composer-without-prefix/platformatic.runtime.json +0 -21
  28. package/test/fixtures/vite/ssr-autodetect-prefix/client/index.html +0 -12
  29. package/test/fixtures/vite/ssr-autodetect-prefix/client/index.js +0 -7
  30. package/test/fixtures/vite/ssr-autodetect-prefix/package.json +0 -15
  31. package/test/fixtures/vite/ssr-autodetect-prefix/platformatic.application.json +0 -11
  32. package/test/fixtures/vite/ssr-autodetect-prefix/platformatic.runtime.json +0 -21
  33. package/test/fixtures/vite/ssr-autodetect-prefix/server.js +0 -35
  34. package/test/fixtures/vite/ssr-autodetect-prefix/vite.config.js +0 -7
  35. package/test/fixtures/vite/ssr-with-prefix/client/index.html +0 -12
  36. package/test/fixtures/vite/ssr-with-prefix/client/index.js +0 -7
  37. package/test/fixtures/vite/ssr-with-prefix/package.json +0 -15
  38. package/test/fixtures/vite/ssr-with-prefix/platformatic.application.json +0 -14
  39. package/test/fixtures/vite/ssr-with-prefix/platformatic.runtime.json +0 -21
  40. package/test/fixtures/vite/ssr-with-prefix/server.js +0 -35
  41. package/test/fixtures/vite/ssr-with-prefix/vite.config.js +0 -7
  42. package/test/fixtures/vite/ssr-without-prefix/client/index.html +0 -12
  43. package/test/fixtures/vite/ssr-without-prefix/client/index.js +0 -7
  44. package/test/fixtures/vite/ssr-without-prefix/package.json +0 -15
  45. package/test/fixtures/vite/ssr-without-prefix/platformatic.application.json +0 -11
  46. package/test/fixtures/vite/ssr-without-prefix/platformatic.runtime.json +0 -21
  47. package/test/fixtures/vite/ssr-without-prefix/server.js +0 -34
  48. package/test/fixtures/vite/ssr-without-prefix/vite.config.js +0 -7
  49. package/test/fixtures/vite/standalone/custom.vite.config.js +0 -3
  50. package/test/fixtures/vite/standalone/index.html +0 -13
  51. package/test/fixtures/vite/standalone/main.js +0 -3
  52. package/test/fixtures/vite/standalone/package.json +0 -15
  53. package/test/fixtures/vite/standalone/platformatic.runtime.json +0 -18
  54. package/test/index.test.js +0 -161
@@ -1,35 +0,0 @@
1
- import fastifyVite from '@fastify/vite'
2
- import fastify from 'fastify'
3
-
4
- export async function build () {
5
- const server = fastify()
6
-
7
- await server.register(fastifyVite, {
8
- root: import.meta.url,
9
- dev: true,
10
- createRenderFunction ({ generate }) {
11
- return async () => {
12
- return {
13
- element: await generate()
14
- }
15
- }
16
- }
17
- })
18
-
19
- await server.vite.ready()
20
- const prefix = server.vite.devServer.config.base.replace(/\/$/, '')
21
-
22
- server.get(prefix, (req, reply) => {
23
- return reply.type('text/html').html()
24
- })
25
-
26
- server.get(prefix + '/direct', (req, reply) => {
27
- return { ok: true }
28
- })
29
-
30
- server.get(prefix + '/*', (req, reply) => {
31
- return reply.type('text/html').html()
32
- })
33
-
34
- return server
35
- }
@@ -1,7 +0,0 @@
1
- import { dirname, resolve } from 'node:path'
2
- import { fileURLToPath } from 'node:url'
3
-
4
- const path = fileURLToPath(import.meta.url)
5
- const root = resolve(dirname(path), 'client')
6
-
7
- export default { root, base: globalThis.platformatic.basePath, logLevel: globalThis.platformatic.logger.level }
@@ -1,12 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite App</title>
8
- </head>
9
- <body>
10
- <div id="app"><!-- element --></div>
11
- </body>
12
- </html>
@@ -1,7 +0,0 @@
1
- import { version } from '../../../../tmp/version.js'
2
-
3
- export async function generate () {
4
- const response = await fetch('http://service.plt.local/time')
5
- const { time } = await response.json()
6
- return `<div>Hello from v${version} t${time}</div>`
7
- }
@@ -1,15 +0,0 @@
1
- {
2
- "name": "vite",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "preview": "vite preview"
10
- },
11
- "dependencies": {
12
- "@platformatic/vite": "workspace:*",
13
- "vite": "^5.3.4"
14
- }
15
- }
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/vite/2.0.0.json",
3
- "server": {
4
- "logger": {
5
- "level": "error"
6
- }
7
- },
8
- "vite": {
9
- "ssr": true
10
- }
11
- }
@@ -1,21 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "frontend",
15
- "path": ".",
16
- "config": "platformatic.application.json"
17
- },
18
- { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
19
- { "id": "main", "config": "platformatic.no-prefix.composer.json", "path": "../../platformatic-composer" }
20
- ]
21
- }
@@ -1,34 +0,0 @@
1
- import fastifyVite from '@fastify/vite'
2
- import fastify from 'fastify'
3
-
4
- export async function build () {
5
- const server = fastify()
6
-
7
- await server.register(fastifyVite, {
8
- root: import.meta.url,
9
- dev: true,
10
- createRenderFunction ({ generate }) {
11
- return async () => {
12
- return {
13
- element: await generate()
14
- }
15
- }
16
- }
17
- })
18
-
19
- await server.vite.ready()
20
-
21
- server.get('/', (req, reply) => {
22
- return reply.type('text/html').html()
23
- })
24
-
25
- server.get('/direct', (req, reply) => {
26
- return { ok: true }
27
- })
28
-
29
- server.get('/*', (req, reply) => {
30
- return reply.type('text/html').html()
31
- })
32
-
33
- return server
34
- }
@@ -1,7 +0,0 @@
1
- import { dirname, resolve } from 'node:path'
2
- import { fileURLToPath } from 'node:url'
3
-
4
- const path = fileURLToPath(import.meta.url)
5
- const root = resolve(dirname(path), 'client')
6
-
7
- export default { root, logLevel: globalThis.platformatic.logger.level }
@@ -1,3 +0,0 @@
1
- export default {
2
- base: '/nested/base/dir',
3
- }
@@ -1,13 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
- <title>Vite App</title>
8
- </head>
9
- <body>
10
- <div id="app"></div>
11
- <script type="module" src="/main.js"></script>
12
- </body>
13
- </html>
@@ -1,3 +0,0 @@
1
- import { version } from '../../../tmp/version.js'
2
-
3
- document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -1,15 +0,0 @@
1
- {
2
- "name": "vite",
3
- "private": true,
4
- "version": "0.0.0",
5
- "type": "module",
6
- "scripts": {
7
- "dev": "vite",
8
- "build": "vite build",
9
- "preview": "vite preview"
10
- },
11
- "dependencies": {
12
- "@platformatic/vite": "workspace:*",
13
- "vite": "^5.3.4"
14
- }
15
- }
@@ -1,18 +0,0 @@
1
- {
2
- "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/1.52.0.json",
3
- "entrypoint": "main",
4
- "watch": false,
5
- "managementApi": false,
6
- "metrics": false,
7
- "server": {
8
- "logger": {
9
- "level": "error"
10
- }
11
- },
12
- "services": [
13
- {
14
- "id": "main",
15
- "path": "."
16
- }
17
- ]
18
- }
@@ -1,161 +0,0 @@
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
- })