@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
package/schema.json ADDED
@@ -0,0 +1,541 @@
1
+ {
2
+ "$id": "https://schemas.platformatic.dev/@platformatic/vite/2.0.0-alpha.5.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "title": "Platformatic Vite Stackable",
5
+ "type": "object",
6
+ "properties": {
7
+ "$schema": {
8
+ "type": "string"
9
+ },
10
+ "server": {
11
+ "type": "object",
12
+ "properties": {
13
+ "hostname": {
14
+ "type": "string"
15
+ },
16
+ "port": {
17
+ "anyOf": [
18
+ {
19
+ "type": "integer"
20
+ },
21
+ {
22
+ "type": "string"
23
+ }
24
+ ]
25
+ },
26
+ "pluginTimeout": {
27
+ "type": "integer"
28
+ },
29
+ "healthCheck": {
30
+ "anyOf": [
31
+ {
32
+ "type": "boolean"
33
+ },
34
+ {
35
+ "type": "object",
36
+ "properties": {
37
+ "enabled": {
38
+ "type": "boolean"
39
+ },
40
+ "interval": {
41
+ "type": "integer"
42
+ }
43
+ },
44
+ "additionalProperties": true
45
+ }
46
+ ]
47
+ },
48
+ "ignoreTrailingSlash": {
49
+ "type": "boolean"
50
+ },
51
+ "ignoreDuplicateSlashes": {
52
+ "type": "boolean"
53
+ },
54
+ "connectionTimeout": {
55
+ "type": "integer"
56
+ },
57
+ "keepAliveTimeout": {
58
+ "type": "integer",
59
+ "default": 5000
60
+ },
61
+ "maxRequestsPerSocket": {
62
+ "type": "integer"
63
+ },
64
+ "forceCloseConnections": {
65
+ "anyOf": [
66
+ {
67
+ "type": "boolean"
68
+ },
69
+ {
70
+ "type": "string",
71
+ "pattern": "^idle$"
72
+ }
73
+ ]
74
+ },
75
+ "requestTimeout": {
76
+ "type": "integer"
77
+ },
78
+ "bodyLimit": {
79
+ "type": "integer"
80
+ },
81
+ "maxParamLength": {
82
+ "type": "integer"
83
+ },
84
+ "disableRequestLogging": {
85
+ "type": "boolean"
86
+ },
87
+ "exposeHeadRoutes": {
88
+ "type": "boolean"
89
+ },
90
+ "logger": {
91
+ "anyOf": [
92
+ {
93
+ "type": "boolean"
94
+ },
95
+ {
96
+ "type": "object",
97
+ "properties": {
98
+ "level": {
99
+ "type": "string"
100
+ },
101
+ "transport": {
102
+ "anyOf": [
103
+ {
104
+ "type": "object",
105
+ "properties": {
106
+ "target": {
107
+ "type": "string",
108
+ "resolveModule": true
109
+ },
110
+ "options": {
111
+ "type": "object"
112
+ }
113
+ },
114
+ "additionalProperties": false
115
+ },
116
+ {
117
+ "type": "object",
118
+ "properties": {
119
+ "targets": {
120
+ "type": "array",
121
+ "items": {
122
+ "type": "object",
123
+ "properties": {
124
+ "target": {
125
+ "type": "string",
126
+ "resolveModule": true
127
+ },
128
+ "options": {
129
+ "type": "object"
130
+ },
131
+ "level": {
132
+ "type": "string"
133
+ },
134
+ "additionalProperties": false
135
+ }
136
+ }
137
+ },
138
+ "options": {
139
+ "type": "object"
140
+ }
141
+ },
142
+ "additionalProperties": false
143
+ }
144
+ ]
145
+ },
146
+ "pipeline": {
147
+ "type": "object",
148
+ "properties": {
149
+ "target": {
150
+ "type": "string",
151
+ "resolveModule": true
152
+ },
153
+ "options": {
154
+ "type": "object"
155
+ }
156
+ },
157
+ "additionalProperties": false
158
+ }
159
+ },
160
+ "additionalProperties": true
161
+ }
162
+ ]
163
+ },
164
+ "serializerOpts": {
165
+ "type": "object",
166
+ "properties": {
167
+ "schema": {
168
+ "type": "object"
169
+ },
170
+ "ajv": {
171
+ "type": "object"
172
+ },
173
+ "rounding": {
174
+ "type": "string",
175
+ "enum": [
176
+ "floor",
177
+ "ceil",
178
+ "round",
179
+ "trunc"
180
+ ],
181
+ "default": "trunc"
182
+ },
183
+ "debugMode": {
184
+ "type": "boolean"
185
+ },
186
+ "mode": {
187
+ "type": "string",
188
+ "enum": [
189
+ "debug",
190
+ "standalone"
191
+ ]
192
+ },
193
+ "largeArraySize": {
194
+ "anyOf": [
195
+ {
196
+ "type": "integer"
197
+ },
198
+ {
199
+ "type": "string"
200
+ }
201
+ ],
202
+ "default": 20000
203
+ },
204
+ "largeArrayMechanism": {
205
+ "type": "string",
206
+ "enum": [
207
+ "default",
208
+ "json-stringify"
209
+ ],
210
+ "default": "default"
211
+ }
212
+ }
213
+ },
214
+ "caseSensitive": {
215
+ "type": "boolean"
216
+ },
217
+ "requestIdHeader": {
218
+ "anyOf": [
219
+ {
220
+ "type": "string"
221
+ },
222
+ {
223
+ "type": "boolean",
224
+ "const": false
225
+ }
226
+ ]
227
+ },
228
+ "requestIdLogLabel": {
229
+ "type": "string"
230
+ },
231
+ "jsonShorthand": {
232
+ "type": "boolean"
233
+ },
234
+ "trustProxy": {
235
+ "anyOf": [
236
+ {
237
+ "type": "boolean"
238
+ },
239
+ {
240
+ "type": "string"
241
+ },
242
+ {
243
+ "type": "array",
244
+ "items": {
245
+ "type": "string"
246
+ }
247
+ },
248
+ {
249
+ "type": "integer"
250
+ }
251
+ ]
252
+ },
253
+ "http2": {
254
+ "type": "boolean"
255
+ },
256
+ "https": {
257
+ "type": "object",
258
+ "properties": {
259
+ "allowHTTP1": {
260
+ "type": "boolean"
261
+ },
262
+ "key": {
263
+ "anyOf": [
264
+ {
265
+ "type": "string"
266
+ },
267
+ {
268
+ "type": "object",
269
+ "properties": {
270
+ "path": {
271
+ "type": "string",
272
+ "resolvePath": true
273
+ }
274
+ },
275
+ "additionalProperties": false
276
+ },
277
+ {
278
+ "type": "array",
279
+ "items": {
280
+ "anyOf": [
281
+ {
282
+ "type": "string"
283
+ },
284
+ {
285
+ "type": "object",
286
+ "properties": {
287
+ "path": {
288
+ "type": "string",
289
+ "resolvePath": true
290
+ }
291
+ },
292
+ "additionalProperties": false
293
+ }
294
+ ]
295
+ }
296
+ }
297
+ ]
298
+ },
299
+ "cert": {
300
+ "anyOf": [
301
+ {
302
+ "type": "string"
303
+ },
304
+ {
305
+ "type": "object",
306
+ "properties": {
307
+ "path": {
308
+ "type": "string",
309
+ "resolvePath": true
310
+ }
311
+ },
312
+ "additionalProperties": false
313
+ },
314
+ {
315
+ "type": "array",
316
+ "items": {
317
+ "anyOf": [
318
+ {
319
+ "type": "string"
320
+ },
321
+ {
322
+ "type": "object",
323
+ "properties": {
324
+ "path": {
325
+ "type": "string",
326
+ "resolvePath": true
327
+ }
328
+ },
329
+ "additionalProperties": false
330
+ }
331
+ ]
332
+ }
333
+ }
334
+ ]
335
+ },
336
+ "requestCert": {
337
+ "type": "boolean"
338
+ },
339
+ "rejectUnauthorized": {
340
+ "type": "boolean"
341
+ }
342
+ },
343
+ "additionalProperties": false,
344
+ "required": [
345
+ "key",
346
+ "cert"
347
+ ]
348
+ },
349
+ "cors": {
350
+ "type": "object",
351
+ "$comment": "See https://github.com/fastify/fastify-cors",
352
+ "properties": {
353
+ "origin": {
354
+ "anyOf": [
355
+ {
356
+ "type": "boolean"
357
+ },
358
+ {
359
+ "type": "string"
360
+ },
361
+ {
362
+ "type": "array",
363
+ "items": {
364
+ "anyOf": [
365
+ {
366
+ "type": "string"
367
+ },
368
+ {
369
+ "type": "object",
370
+ "properties": {
371
+ "regexp": {
372
+ "type": "string"
373
+ }
374
+ },
375
+ "required": [
376
+ "regexp"
377
+ ]
378
+ }
379
+ ]
380
+ }
381
+ },
382
+ {
383
+ "type": "object",
384
+ "properties": {
385
+ "regexp": {
386
+ "type": "string"
387
+ }
388
+ },
389
+ "required": [
390
+ "regexp"
391
+ ]
392
+ }
393
+ ]
394
+ },
395
+ "methods": {
396
+ "type": "array",
397
+ "items": {
398
+ "type": "string"
399
+ }
400
+ },
401
+ "allowedHeaders": {
402
+ "type": "string",
403
+ "description": "Comma separated string of allowed headers."
404
+ },
405
+ "exposedHeaders": {
406
+ "anyOf": [
407
+ {
408
+ "type": "array",
409
+ "items": {
410
+ "type": "string"
411
+ }
412
+ },
413
+ {
414
+ "type": "string",
415
+ "description": "Comma separated string of exposed headers."
416
+ }
417
+ ]
418
+ },
419
+ "credentials": {
420
+ "type": "boolean"
421
+ },
422
+ "maxAge": {
423
+ "type": "integer"
424
+ },
425
+ "preflightContinue": {
426
+ "type": "boolean",
427
+ "default": false
428
+ },
429
+ "optionsSuccessStatus": {
430
+ "type": "integer",
431
+ "default": 204
432
+ },
433
+ "preflight": {
434
+ "type": "boolean",
435
+ "default": true
436
+ },
437
+ "strictPreflight": {
438
+ "type": "boolean",
439
+ "default": true
440
+ },
441
+ "hideOptionsRoute": {
442
+ "type": "boolean",
443
+ "default": true
444
+ }
445
+ },
446
+ "additionalProperties": false
447
+ }
448
+ },
449
+ "additionalProperties": false
450
+ },
451
+ "watch": {
452
+ "anyOf": [
453
+ {
454
+ "type": "object",
455
+ "properties": {
456
+ "enabled": {
457
+ "default": true,
458
+ "anyOf": [
459
+ {
460
+ "type": "boolean"
461
+ },
462
+ {
463
+ "type": "string"
464
+ }
465
+ ]
466
+ },
467
+ "allow": {
468
+ "type": "array",
469
+ "items": {
470
+ "type": "string"
471
+ },
472
+ "minItems": 1,
473
+ "nullable": true,
474
+ "default": null
475
+ },
476
+ "ignore": {
477
+ "type": "array",
478
+ "items": {
479
+ "type": "string"
480
+ },
481
+ "nullable": true,
482
+ "default": null
483
+ }
484
+ },
485
+ "additionalProperties": false
486
+ },
487
+ {
488
+ "type": "boolean"
489
+ },
490
+ {
491
+ "type": "string"
492
+ }
493
+ ]
494
+ },
495
+ "application": {
496
+ "type": "object",
497
+ "properties": {
498
+ "basePath": {
499
+ "type": "string"
500
+ }
501
+ },
502
+ "additionalProperties": false
503
+ },
504
+ "vite": {
505
+ "type": "object",
506
+ "properties": {
507
+ "configFile": {
508
+ "oneOf": [
509
+ {
510
+ "type": "string"
511
+ },
512
+ {
513
+ "type": "boolean"
514
+ }
515
+ ]
516
+ },
517
+ "ssr": {
518
+ "oneOf": [
519
+ {
520
+ "type": "object",
521
+ "properties": {
522
+ "entrypoint": {
523
+ "type": "string"
524
+ }
525
+ },
526
+ "required": [
527
+ "entrypoint"
528
+ ],
529
+ "additionalProperties": false
530
+ },
531
+ {
532
+ "type": "boolean"
533
+ }
534
+ ]
535
+ }
536
+ },
537
+ "additionalProperties": false
538
+ }
539
+ },
540
+ "additionalProperties": false
541
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/composer/1.52.0.json",
3
+ "composer": {
4
+ "services": [
5
+ {
6
+ "id": "frontend"
7
+ },
8
+ {
9
+ "id": "service"
10
+ }
11
+ ]
12
+ },
13
+ "plugins": {
14
+ "paths": [
15
+ {
16
+ "path": "./plugin.js"
17
+ }
18
+ ]
19
+ }
20
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/composer/1.52.0.json",
3
+ "composer": {
4
+ "services": [
5
+ {
6
+ "id": "frontend",
7
+ "proxy": {
8
+ "prefix": ""
9
+ }
10
+ },
11
+ {
12
+ "id": "service"
13
+ }
14
+ ]
15
+ },
16
+ "plugins": {
17
+ "paths": [
18
+ {
19
+ "path": "./plugin.js"
20
+ }
21
+ ]
22
+ }
23
+ }
@@ -0,0 +1,9 @@
1
+ export default async function (app) {
2
+ app.get('/plugin', async () => {
3
+ return { ok: true }
4
+ })
5
+
6
+ app.get('/frontend/plugin', async () => {
7
+ return { ok: true }
8
+ })
9
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "$schema": "https://schemas.platformatic.dev/@platformatic/service/1.52.0.json",
3
+ "server": {
4
+ "logger": {
5
+ "level": "error"
6
+ }
7
+ },
8
+ "plugins": {
9
+ "paths": [
10
+ {
11
+ "path": "./plugin.js"
12
+ }
13
+ ]
14
+ }
15
+ }
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ export default async function (app) {
4
+ app.get('/mesh', async () => {
5
+ const meta = await globalThis[Symbol.for('plt.runtime.itc')].send('getServiceMeta', 'frontend')
6
+
7
+ const url = new URL(`${meta.composer.prefix}/direct`.replaceAll(/\/+/g, '/'), 'http://frontend.plt.local')
8
+ const response = await fetch(url)
9
+ return response.json()
10
+ })
11
+
12
+ app.get('/direct', async () => {
13
+ return { ok: true }
14
+ })
15
+
16
+ app.get('/time', async () => {
17
+ return { time: Date.now() }
18
+ })
19
+ }
@@ -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,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
+ "vite": {
9
+ "configFile": "custom.vite.config.js"
10
+ }
11
+ }