Skip to content

Commit 86e67d1

Browse files
authored
feat: Updated to Watt 3. (#12)
Signed-off-by: Paolo Insogna <[email protected]>
1 parent ee2c105 commit 86e67d1

File tree

12 files changed

+6093
-385
lines changed

12 files changed

+6093
-385
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
node-version: [22, 24]
99
os: [ubuntu-latest]
1010
runs-on: ${{matrix.os}}
11-
timeout-minutes: 10
11+
timeout-minutes: 20
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v4
@@ -25,13 +25,7 @@ jobs:
2525
uses: pnpm/action-setup@v4
2626
with:
2727
version: latest
28-
- name: Set private package config
29-
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NODE_AUTH_TOKEN}"
30-
env:
31-
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3228
- name: Install dependencies
33-
run: pnpm install
34-
- name: Lint
35-
run: pnpm run lint
29+
run: pnpm install --frozen-lockfile
3630
- name: Run Tests
37-
run: pnpm run test
31+
run: pnpm run ci
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: "The version number to tag and release"
8+
required: true
9+
type: string
10+
prerelease:
11+
description: "Release as pre-release"
12+
required: false
13+
type: boolean
14+
default: false
15+
16+
jobs:
17+
release-npm:
18+
runs-on: ubuntu-latest
19+
environment: main
20+
permissions:
21+
contents: write
22+
id-token: write
23+
steps:
24+
- name: Checkout
25+
uses: actions/checkout@v4
26+
- name: Use supported Node.js Version
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: 22
30+
- name: Restore cached dependencies
31+
uses: actions/cache@v4
32+
with:
33+
path: ~/.pnpm-store
34+
key: node-modules-${{ hashFiles('package.json') }}
35+
- name: Setup pnpm
36+
uses: pnpm/action-setup@v4
37+
with:
38+
version: latest
39+
- name: Install dependencies
40+
run: pnpm install --frozen-lockfile
41+
- name: Bump version and push commit
42+
run: |
43+
pnpm version ${{ inputs.version }} --no-git-tag-version
44+
git config --global user.name "${{ github.actor }}"
45+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
46+
git commit -a -m "Bumped v${{ inputs.version }}"
47+
git push origin HEAD:${{ github.ref }}
48+
- name: Publish new version
49+
run: |
50+
npm install npm -g
51+
npm publish --access public --tag ${{ inputs.prerelease == true && 'next' || 'latest' }}
52+
- name: Create release notes
53+
run: |
54+
npx @matteo.collina/release-notes -a ${{ secrets.GITHUB_TOKEN }} -t v${{ inputs.version }} -r ${{ github.repository }} ${{ github.event.inputs.prerelease == 'true' && '-p' || '' }} -c ${{ github.ref }}

config.d.ts

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -164,32 +164,14 @@ export interface PlatformaticPHPConfiguration {
164164
plugins?: {
165165
[k: string]: unknown;
166166
};
167-
metrics?:
168-
| boolean
169-
| {
170-
port?: number | string;
171-
hostname?: string;
172-
endpoint?: string;
173-
server?: "own" | "parent" | "hide";
174-
defaultMetrics?: {
175-
enabled: boolean;
176-
};
177-
auth?: {
178-
username: string;
179-
password: string;
180-
};
181-
labels?: {
182-
[k: string]: string;
183-
};
184-
};
185167
telemetry?: {
186168
enabled?: boolean | string;
187169
/**
188-
* The name of the service. Defaults to the folder name if not specified.
170+
* The name of the application. Defaults to the folder name if not specified.
189171
*/
190-
serviceName: string;
172+
applicationName: string;
191173
/**
192-
* The version of the service (optional)
174+
* The version of the application (optional)
193175
*/
194176
version?: string;
195177
/**
@@ -271,6 +253,7 @@ export interface PlatformaticPHPConfiguration {
271253
| string;
272254
$schema?: string;
273255
module?: string;
256+
application?: {};
274257
service?: {
275258
openapi?:
276259
| {
@@ -324,20 +307,12 @@ export interface PlatformaticPHPConfiguration {
324307
};
325308
};
326309
};
327-
clients?: {
328-
serviceId?: string;
329-
name?: string;
330-
type?: "openapi" | "graphql";
331-
path?: string;
332-
schema?: string;
333-
url?: string;
334-
fullResponse?: boolean;
335-
fullRequest?: boolean;
336-
validateResponse?: boolean;
337-
}[];
338310
runtime?: {
339311
preload?: string | string[];
340312
basePath?: string;
313+
services?: {
314+
[k: string]: unknown;
315+
}[];
341316
workers?: number | string;
342317
logger?: {
343318
level: (
@@ -423,9 +398,10 @@ export interface PlatformaticPHPConfiguration {
423398
};
424399
startTimeout?: number;
425400
restartOnError?: boolean | number;
401+
exitOnUnhandledErrors?: boolean;
426402
gracefulShutdown?: {
427403
runtime: number | string;
428-
service: number | string;
404+
application: number | string;
429405
};
430406
health?: {
431407
enabled?: boolean | string;
@@ -435,7 +411,7 @@ export interface PlatformaticPHPConfiguration {
435411
maxELU?: number | string;
436412
maxHeapUsed?: number | string;
437413
maxHeapTotal?: number | string;
438-
maxYoungGeneration?: number;
414+
maxYoungGeneration?: number | string;
439415
};
440416
undici?: {
441417
agentOptions?: {
@@ -544,11 +520,11 @@ export interface PlatformaticPHPConfiguration {
544520
telemetry?: {
545521
enabled?: boolean | string;
546522
/**
547-
* The name of the service. Defaults to the folder name if not specified.
523+
* The name of the application. Defaults to the folder name if not specified.
548524
*/
549-
serviceName: string;
525+
applicationName: string;
550526
/**
551-
* The version of the service (optional)
527+
* The version of the application (optional)
552528
*/
553529
version?: string;
554530
/**
@@ -624,7 +600,8 @@ export interface PlatformaticPHPConfiguration {
624600
watchDisabled?: boolean;
625601
[k: string]: unknown;
626602
};
627-
serviceTimeout?: number | string;
603+
applicationTimeout?: number | string;
604+
messagingTimeout?: number | string;
628605
env?: {
629606
[k: string]: string;
630607
};

lib/generator.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Generator as ServiceGenerator } from '@platformatic/service'
22
import { readFile } from 'node:fs/promises'
3-
import { resolve, join } from 'node:path'
3+
import { join } from 'node:path'
4+
import { packageJson } from '../lib/schema.js'
45

56
export class Generator extends ServiceGenerator {
67
constructor (opts = {}) {
@@ -31,14 +32,13 @@ export class Generator extends ServiceGenerator {
3132
}
3233

3334
async _getConfigFileContents () {
34-
const packageJson = await this._getStackablePackageJson()
3535
const { server, watch } = await super._getConfigFileContents()
3636

3737
return {
3838
$schema: `https://schemas.platformatic.dev/@platformatic/php/${packageJson.version}.json`,
3939
module: `${packageJson.name}`,
4040
php: {
41-
docroot: 'public',
41+
docroot: 'public'
4242
},
4343
server,
4444
watch
@@ -51,8 +51,6 @@ export class Generator extends ServiceGenerator {
5151
delete this.config.env.PLT_TYPESCRIPT
5252
delete this.config.defaultEnv.PLT_TYPESCRIPT
5353

54-
const packageJson = await this._getStackablePackageJson()
55-
5654
this.config.dependencies = {
5755
[packageJson.name]: `^${packageJson.version}`
5856
}
@@ -63,15 +61,11 @@ export class Generator extends ServiceGenerator {
6361
delete this.files['.gitignore']
6462

6563
if (!this.config.isUpdating) {
66-
this.addFile({ path: 'public', file: 'index.php', contents: await readFile(join(import.meta.dirname, 'index.php'), 'utf-8') })
64+
this.addFile({
65+
path: 'public',
66+
file: 'index.php',
67+
contents: await readFile(join(import.meta.dirname, 'index.php'), 'utf-8')
68+
})
6769
}
6870
}
69-
70-
async _getStackablePackageJson () {
71-
if (!this._packageJson) {
72-
this._packageJson = JSON.parse(await readFile(resolve(import.meta.dirname, '../package.json'), 'utf-8'))
73-
}
74-
75-
return this._packageJson
76-
}
7771
}

lib/index.js

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
1-
import { buildStackable } from '@platformatic/service'
2-
import { Generator as _Generator } from './generator.js'
1+
import { create as createService, platformaticService } from '@platformatic/service'
32
import { plugin } from './plugin.js'
4-
import { packageJson, schema } from './schema.js'
3+
import { schema } from './schema.js'
54

6-
export async function stackable (fastify, opts) {
7-
await fastify.register(plugin, opts)
5+
export async function php (app, capability) {
6+
await platformaticService(app, capability)
7+
await app.register(plugin, capability)
88
}
99

10-
stackable.Generator = _Generator
11-
stackable.configType = 'php'
12-
stackable.schema = schema
13-
stackable.configManagerConfig = {
14-
schemaOptions: {
15-
useDefaults: true,
16-
coerceTypes: true,
17-
allErrors: true,
18-
strict: false
19-
}
10+
export async function create (configOrRoot, sourceOrConfig, context) {
11+
return createService(configOrRoot, sourceOrConfig, {
12+
schema,
13+
applicationFactory: php,
14+
...context
15+
})
2016
}
2117

22-
export const Generator = _Generator
23-
24-
export default {
25-
configType: 'php',
26-
configManagerConfig: stackable.configManagerConfig,
27-
/* c8 ignore next 3 */
28-
async buildStackable (opts) {
29-
return buildStackable(opts, stackable)
30-
},
31-
schema,
32-
version: packageJson.version
33-
}
18+
export { Generator } from './generator.js'
19+
export { packageJson, schema, schemaComponents, version } from './schema.js'

lib/plugin.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
import fp from 'fastify-plugin'
2+
13
const HTTP_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'TRACE']
24

35
const capitalizeHeaders = header => header.replace(/(^|-)([a-z])/g, (_, dash, letter) => dash + letter.toUpperCase())
46

5-
export async function plugin (server, opts) {
7+
// A full URL string is needed for PHP, but Node.js splits that across a bunch of places.
8+
function urlForRequest (req) {
9+
const proto = req.raw.protocol ?? 'http:'
10+
const host = req.headers.host ?? 'localhost'
11+
return new URL(req.url, `${proto}//${host}`)
12+
}
13+
14+
export async function phpPlugin (server, opts) {
615
// We import this dynically to provide better error reporting in case
716
// this module fails to load one of the native bindings
817
const { Php, Request, Rewriter } = await import('@platformatic/php-node')
@@ -61,7 +70,7 @@ export async function plugin (server, opts) {
6170
method: req.method,
6271
url: url.href,
6372
headers,
64-
body: req.body,
73+
body: req.body
6574
}
6675

6776
const phpReq = new Request(reqInput)
@@ -97,9 +106,4 @@ export async function plugin (server, opts) {
97106
}
98107
}
99108

100-
// A full URL string is needed for PHP, but Node.js splits that across a bunch of places.
101-
function urlForRequest (req) {
102-
const proto = req.raw.protocol ?? 'http:'
103-
const host = req.headers.host ?? 'localhost'
104-
return new URL(req.url, `${proto}//${host}`)
105-
}
109+
export const plugin = fp(phpPlugin)

0 commit comments

Comments
 (0)