@platformatic/nitro 3.71.1-alpha.0 → 4.0.0-alpha.1
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/config.d.ts +759 -825
- package/index.d.ts +8 -1
- package/index.js +9 -9
- package/lib/capability.js +28 -41
- package/lib/factory.js +12 -0
- package/lib/schema.js +7 -3
- package/package.json +10 -9
- package/schema.js +7 -0
- package/schema.json +180 -390
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseCapability, BaseContext, BaseOptions } from '@platformatic/basic'
|
|
1
|
+
import { ApplicationDefinition, BaseCapability, BaseContext, BaseOptions, CapabilityFactoryOptions, ConfigContext, DeferredApplicationDefinition } from '@platformatic/basic'
|
|
2
2
|
import { Configuration, ConfigurationOptions } from '@platformatic/foundation'
|
|
3
3
|
import { ViteCapability } from '@platformatic/vite'
|
|
4
4
|
import { JSONSchemaType } from 'ajv'
|
|
@@ -52,3 +52,10 @@ export declare const schema: JSONSchemaType<PlatformaticNitroConfig>
|
|
|
52
52
|
export declare const schemaComponents: { nitro: JSONSchemaType<object> }
|
|
53
53
|
export declare const version: string
|
|
54
54
|
export declare const supportedVersions: { nitro: string, nitropack: string }
|
|
55
|
+
|
|
56
|
+
export type NitroConfigOptions = CapabilityFactoryOptions<PlatformaticNitroConfig, 'vite' | 'nitro', never>
|
|
57
|
+
|
|
58
|
+
export declare function createNitroConfig (options?: NitroConfigOptions): ApplicationDefinition
|
|
59
|
+
export declare function createNitroConfig (
|
|
60
|
+
callback: (context: ConfigContext) => NitroConfigOptions | Promise<NitroConfigOptions>
|
|
61
|
+
): DeferredApplicationDefinition
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { kMetadata
|
|
1
|
+
import { loadCapabilityConfiguration, transform as basicTransform, validationOptions } from '@platformatic/basic'
|
|
2
|
+
import { kMetadata } from '@platformatic/foundation'
|
|
3
3
|
import { hasViteConfigFile, NitroCapability, NitroViteCapability } from './lib/capability.js'
|
|
4
4
|
import { schema } from './lib/schema.js'
|
|
5
5
|
|
|
@@ -16,14 +16,12 @@ export async function transform (config, schema, options) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export async function loadConfiguration (configOrRoot, sourceOrConfig, context) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
return loadCapabilityConfiguration(configOrRoot, sourceOrConfig, context, {
|
|
20
|
+
schema,
|
|
21
|
+
scope: import.meta.filename,
|
|
22
|
+
suffixes: 'application',
|
|
22
23
|
validationOptions,
|
|
23
|
-
transform
|
|
24
|
-
replaceEnv: true,
|
|
25
|
-
root,
|
|
26
|
-
...context
|
|
24
|
+
transform
|
|
27
25
|
})
|
|
28
26
|
}
|
|
29
27
|
|
|
@@ -37,3 +35,5 @@ export async function create (configOrRoot, sourceOrConfig, context) {
|
|
|
37
35
|
|
|
38
36
|
export * from './lib/capability.js'
|
|
39
37
|
export { packageJson, schema, schemaComponents, version } from './lib/schema.js'
|
|
38
|
+
|
|
39
|
+
export * from './lib/factory.js'
|
package/lib/capability.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BaseCapability,
|
|
3
|
-
buildAdditionalServerOptions,
|
|
4
3
|
cleanBasePath,
|
|
5
4
|
createServerListener,
|
|
6
5
|
ensureTrailingSlash,
|
|
@@ -170,13 +169,8 @@ export class NitroCapability extends BaseCapability {
|
|
|
170
169
|
})
|
|
171
170
|
}
|
|
172
171
|
|
|
173
|
-
async
|
|
174
|
-
|
|
175
|
-
if (this.url) {
|
|
176
|
-
return this.url
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
await super._start({ listen })
|
|
172
|
+
async _start () {
|
|
173
|
+
await super._start()
|
|
180
174
|
|
|
181
175
|
const command = this.config.application.commands[this.isProduction ? 'production' : 'development']
|
|
182
176
|
if (command) {
|
|
@@ -187,6 +181,10 @@ export class NitroCapability extends BaseCapability {
|
|
|
187
181
|
return this.startWithCommand(command)
|
|
188
182
|
}
|
|
189
183
|
|
|
184
|
+
if (typeof this.serverConfig?.port === 'undefined') {
|
|
185
|
+
return
|
|
186
|
+
}
|
|
187
|
+
|
|
190
188
|
if (this.isProduction) {
|
|
191
189
|
await this.#startProduction()
|
|
192
190
|
} else {
|
|
@@ -194,11 +192,10 @@ export class NitroCapability extends BaseCapability {
|
|
|
194
192
|
}
|
|
195
193
|
|
|
196
194
|
await this._collectMetrics()
|
|
197
|
-
return this.url
|
|
198
195
|
}
|
|
199
196
|
|
|
200
|
-
async
|
|
201
|
-
await super.
|
|
197
|
+
async _stop () {
|
|
198
|
+
await super._stop()
|
|
202
199
|
|
|
203
200
|
if (this.childManager) {
|
|
204
201
|
return this.stopCommand()
|
|
@@ -250,15 +247,12 @@ export class NitroCapability extends BaseCapability {
|
|
|
250
247
|
getMeta () {
|
|
251
248
|
const hasBasePath = this.basePath || this.#basePath
|
|
252
249
|
|
|
253
|
-
return {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
needsRootTrailingSlash: false
|
|
260
|
-
}
|
|
261
|
-
}
|
|
250
|
+
return super.getMeta({
|
|
251
|
+
includeConnection: true,
|
|
252
|
+
prefix: this.basePath ?? this.#basePath,
|
|
253
|
+
wantsAbsoluteUrls: !!hasBasePath,
|
|
254
|
+
needsRootTrailingSlash: false
|
|
255
|
+
})
|
|
262
256
|
}
|
|
263
257
|
|
|
264
258
|
/* c8 ignore next 5 */
|
|
@@ -360,11 +354,7 @@ export class NitroCapability extends BaseCapability {
|
|
|
360
354
|
let serverPromise
|
|
361
355
|
|
|
362
356
|
try {
|
|
363
|
-
serverPromise = createServerListener(
|
|
364
|
-
serverConfig?.port ?? true,
|
|
365
|
-
serverConfig?.hostname ?? true,
|
|
366
|
-
await buildAdditionalServerOptions(serverConfig)
|
|
367
|
-
)
|
|
357
|
+
serverPromise = createServerListener()
|
|
368
358
|
await importFile(entrypointPath)
|
|
369
359
|
this.#server = await serverPromise
|
|
370
360
|
this.#dispatcher = this.#server.listeners('request')[0]
|
|
@@ -452,9 +442,9 @@ export class NitroViteCapability extends ViteCapability {
|
|
|
452
442
|
this.registerGlobals({ basePath: this.#basePath })
|
|
453
443
|
}
|
|
454
444
|
|
|
455
|
-
async
|
|
445
|
+
async _stop () {
|
|
456
446
|
const commandWasRunning = !!this.childManager
|
|
457
|
-
await super.
|
|
447
|
+
await super._stop()
|
|
458
448
|
|
|
459
449
|
if (!commandWasRunning && this.isProduction && this.#server?.listening) {
|
|
460
450
|
return this._closeServer(this.#server)
|
|
@@ -510,15 +500,12 @@ export class NitroViteCapability extends ViteCapability {
|
|
|
510
500
|
|
|
511
501
|
const hasBasePath = this.basePath || this.#basePath
|
|
512
502
|
|
|
513
|
-
return {
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
needsRootTrailingSlash: false
|
|
520
|
-
}
|
|
521
|
-
}
|
|
503
|
+
return super.getMeta({
|
|
504
|
+
includeConnection: true,
|
|
505
|
+
prefix: this.basePath ?? this.#basePath,
|
|
506
|
+
wantsAbsoluteUrls: !!hasBasePath,
|
|
507
|
+
needsRootTrailingSlash: false
|
|
508
|
+
})
|
|
522
509
|
}
|
|
523
510
|
|
|
524
511
|
async getScheduledTasks () {
|
|
@@ -586,6 +573,10 @@ export class NitroViteCapability extends ViteCapability {
|
|
|
586
573
|
)
|
|
587
574
|
}
|
|
588
575
|
|
|
576
|
+
if (typeof this.serverConfig?.port === 'undefined') {
|
|
577
|
+
return
|
|
578
|
+
}
|
|
579
|
+
|
|
589
580
|
const serverConfig = this.serverConfig
|
|
590
581
|
const host = serverConfig?.hostname ?? '127.0.0.1'
|
|
591
582
|
const port = serverConfig?.port ?? 0
|
|
@@ -611,11 +602,7 @@ export class NitroViteCapability extends ViteCapability {
|
|
|
611
602
|
let serverPromise
|
|
612
603
|
|
|
613
604
|
try {
|
|
614
|
-
serverPromise = createServerListener(
|
|
615
|
-
serverConfig?.port ?? true,
|
|
616
|
-
serverConfig?.hostname ?? true,
|
|
617
|
-
await buildAdditionalServerOptions(serverConfig)
|
|
618
|
-
)
|
|
605
|
+
serverPromise = createServerListener()
|
|
619
606
|
await importFile(entrypointPath)
|
|
620
607
|
this.#server = await serverPromise
|
|
621
608
|
this.#dispatcher = this.#server.listeners('request')[0]
|
package/lib/factory.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineCapabilityFactory } from '@platformatic/basic'
|
|
2
|
+
import { schema, version } from './schema.js'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
Vite-derived capabilities flatten the vite block alongside their own; outputDirectory comes
|
|
6
|
+
from the capability's block while application.outputDirectory stays nested, which is why the
|
|
7
|
+
application block is not flattened anywhere.
|
|
8
|
+
*/
|
|
9
|
+
export const createNitroConfig = defineCapabilityFactory('@platformatic/nitro', schema, {
|
|
10
|
+
version,
|
|
11
|
+
flatten: ['vite', 'nitro']
|
|
12
|
+
})
|
package/lib/schema.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import { schemaComponents as basicSchemaComponents } from '@platformatic/basic'
|
|
2
|
-
import { schemaComponents as utilsSchemaComponents } from '@platformatic/foundation'
|
|
3
|
-
import { schemaComponents as viteSchemaComponents } from '@platformatic/vite'
|
|
1
|
+
import { schemaComponents as basicSchemaComponents } from '@platformatic/basic/schema'
|
|
2
|
+
import { schemaComponents as utilsSchemaComponents } from '@platformatic/foundation/schema'
|
|
3
|
+
import { schemaComponents as viteSchemaComponents } from '@platformatic/vite/schema'
|
|
4
4
|
import { readFileSync } from 'node:fs'
|
|
5
5
|
import { resolve } from 'node:path'
|
|
6
6
|
|
|
7
7
|
export const packageJson = JSON.parse(readFileSync(resolve(import.meta.dirname, '../package.json'), 'utf8'))
|
|
8
8
|
export const version = packageJson.version
|
|
9
9
|
|
|
10
|
+
// The port is checked before any startup path is selected, in both capability classes
|
|
11
|
+
// this package ships.
|
|
12
|
+
export const servesWithoutPort = { development: false, production: false }
|
|
13
|
+
|
|
10
14
|
export const nitro = {
|
|
11
15
|
type: 'object',
|
|
12
16
|
properties: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/nitro",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Platformatic Nitro Capability",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"import": "./lib/scheduler/module.js",
|
|
17
17
|
"default": "./lib/scheduler/module.js"
|
|
18
18
|
},
|
|
19
|
+
"./schema": "./schema.js",
|
|
19
20
|
"./*": "./*"
|
|
20
21
|
},
|
|
21
22
|
"repository": {
|
|
@@ -31,10 +32,10 @@
|
|
|
31
32
|
"dependencies": {
|
|
32
33
|
"light-my-request": "^6.6.0",
|
|
33
34
|
"semver": "^7.6.3",
|
|
34
|
-
"@platformatic/
|
|
35
|
-
"@platformatic/
|
|
36
|
-
"@platformatic/globals": "
|
|
37
|
-
"@platformatic/vite": "
|
|
35
|
+
"@platformatic/foundation": "4.0.0-alpha.1",
|
|
36
|
+
"@platformatic/basic": "4.0.0-alpha.1",
|
|
37
|
+
"@platformatic/globals": "4.0.0-alpha.1",
|
|
38
|
+
"@platformatic/vite": "4.0.0-alpha.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"cleaner-spec-reporter": "^0.5.0",
|
|
@@ -45,13 +46,13 @@
|
|
|
45
46
|
"nitropack": "^2.12.9",
|
|
46
47
|
"tstyche": "^7.0.0",
|
|
47
48
|
"typescript": "~6.0.3",
|
|
48
|
-
"vite": "^
|
|
49
|
+
"vite": "^7.2.4",
|
|
49
50
|
"ws": "^8.18.0",
|
|
50
|
-
"@platformatic/gateway": "
|
|
51
|
-
"@platformatic/service": "
|
|
51
|
+
"@platformatic/gateway": "4.0.0-alpha.1",
|
|
52
|
+
"@platformatic/service": "4.0.0-alpha.1"
|
|
52
53
|
},
|
|
53
54
|
"engines": {
|
|
54
|
-
"node": ">=
|
|
55
|
+
"node": ">=24.20.0"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"test": "npm run test:types && node --test --test-reporter=cleaner-spec-reporter --test-concurrency=1 --test-timeout=2000000 test/*.test.js test/**/*.test.js",
|
package/schema.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The light /schema subpath, part of the capability contract. It carries the schema and the
|
|
2
|
+
// package-level metadata main-side preparation needs, and imports nothing that would pull the
|
|
3
|
+
// capability's implementation in with it — boot resolves this rather than the package entry.
|
|
4
|
+
//
|
|
5
|
+
// Light is a statement about import cost, never about safety: this executes in the main process
|
|
6
|
+
// with full privileges, like any capability code.
|
|
7
|
+
export * from './lib/schema.js'
|