@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,20 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/runtime/2.0.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
+ },
17
+ { "id": "service", "config": "platformatic.service.json", "path": "../../platformatic-service" },
18
+ { "id": "main", "config": "platformatic.no-prefix.composer.json", "path": "../../platformatic-composer" }
19
+ ]
20
+ }
@@ -0,0 +1,13 @@
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>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,14 @@
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
+ "devDependencies": {
12
+ "vite": "^5.3.4"
13
+ }
14
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/vite/2.0.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "application": {
9
+ "basePath": "/frontend"
10
+ }
11
+ }
@@ -0,0 +1,21 @@
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.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,13 @@
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>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,14 @@
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
+ "devDependencies": {
12
+ "vite": "^5.3.4"
13
+ }
14
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/basic/2.0.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ }
8
+ }
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,12 @@
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>
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,35 @@
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
+ }
@@ -0,0 +1,7 @@
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: '/nested/base/dir', logLevel: globalThis.platformatic.logger.level }
@@ -0,0 +1,12 @@
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>
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/vite/2.0.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "application": {
9
+ "basePath": "/frontend"
10
+ },
11
+ "vite": {
12
+ "ssr": true
13
+ }
14
+ }
@@ -0,0 +1,21 @@
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.composer.json", "path": "../../platformatic-composer" }
20
+ ]
21
+ }
@@ -0,0 +1,35 @@
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
+ }
@@ -0,0 +1,7 @@
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 }
@@ -0,0 +1,12 @@
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>
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,7 @@
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 }
@@ -0,0 +1,3 @@
1
+ export default {
2
+ base: '/nested/base/dir',
3
+ }
@@ -0,0 +1,13 @@
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>
@@ -0,0 +1,3 @@
1
+ import { version } from '../../../tmp/version.js'
2
+
3
+ document.querySelector('#app').innerHTML = `<div>Hello from ${version}</div>`
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,18 @@
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
+ }