Skip to content

Commit 565b1dd

Browse files
BrooooooklynQard
authored andcommitted
migrate napi cli to v3 (#33)
1 parent e8e7d8f commit 565b1dd

File tree

5 files changed

+1187
-157
lines changed

5 files changed

+1187
-157
lines changed

crates/php/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ hostname = "0.4.1"
1717
lang_handler = { path = "../lang_handler", features = ["c"] }
1818
libc = "0.2.171"
1919
once_cell = "1.21.0"
20-
ext-php-rs = { git = "ssh://git@github.com/platformatic/ext-php-rs.git" }
20+
ext-php-rs = { git = "https://github.com/platformatic/ext-php-rs.git" }
2121
# ext-php-rs = { path = "../../../ext-php-rs" }
2222

2323
[build-dependencies]

crates/php_node/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ path = "src/lib.rs"
99

1010
[dependencies]
1111
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
12-
napi = { version = "3.0.0-beta.3", default-features = false, features = ["napi4"] }
13-
napi-derive = "3.0.0-beta.3"
12+
napi = { version = "3.0.0-beta.7", default-features = false, features = ["napi4"] }
13+
napi-derive = "3.0.0-beta.6"
1414
php = { path = "../php" }
1515

1616
[build-dependencies]
17-
napi-build = "2.0.1"
17+
napi-build = "2.2.1"

index.d.ts

Lines changed: 136 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,5 @@
1-
/* tslint:disable */
2-
/* eslint-disable */
3-
41
/* auto-generated by NAPI-RS */
5-
6-
export interface PhpRequestSocketOptions {
7-
/** The string representation of the local IP address the remote client is connecting on. */
8-
localAddress: string
9-
/** The numeric representation of the local port. For example, 80 or 21. */
10-
localPort: number
11-
/** The string representation of the remote IP address. */
12-
remoteAddress: string
13-
/** The numeric representation of the remote port. For example, 80 or 21. */
14-
remotePort: number
15-
}
16-
/** Options for creating a new PHP request. */
17-
export interface PhpRequestOptions {
18-
/** The HTTP method for the request. */
19-
method?: string
20-
/** The URL for the request. */
21-
url: string
22-
/**
23-
* The headers for the request.
24-
* TODO: Figure out how to accept a Headers instance
25-
* TODO: Figure out how to support both single values without array wrap
26-
*/
27-
headers?: Record<string, Array<string>>
28-
/** The body for the request. */
29-
body?: Uint8Array
30-
/** The socket information for the request. */
31-
socket?: PhpRequestSocketOptions
32-
}
33-
/** Options for creating a new PHP response. */
34-
export interface PhpResponseOptions {
35-
/** The HTTP status code for the response. */
36-
status?: number
37-
/**
38-
* The headers for the response.
39-
* TODO: Figure out how to accept a Headers instance
40-
* TODO: Figure out how to support both single values without array wrap
41-
*/
42-
headers?: Record<string, Array<string>>
43-
/** The body for the response. */
44-
body?: Uint8Array
45-
/** The log for the response. */
46-
log?: Uint8Array
47-
/** The exception for the response. */
48-
exception?: string
49-
}
50-
/** Options for creating a new PHP instance. */
51-
export interface PhpOptions {
52-
/** The command-line arguments for the PHP instance. */
53-
argv?: Array<string>
54-
/** The document root for the PHP instance. */
55-
docroot?: string
56-
/** Throw request errors */
57-
throwRequestErrors?: boolean
58-
}
59-
undefinedundefined
60-
export type PhpHeaders = Headers
2+
/* eslint-disable */
613
/**
624
* A multi-map of HTTP headers.
635
*
@@ -273,7 +215,86 @@ export declare class Headers {
273215
*/
274216
forEach(this: this, callback: (arg0: string, arg1: string, arg2: this) => void): void
275217
}
276-
export type PhpRequest = Request
218+
export type PhpHeaders = Headers
219+
220+
/**
221+
* A PHP instance.
222+
*
223+
* # Examples
224+
*
225+
* ```js
226+
* const php = new Php({
227+
* code: 'echo "Hello, world!";'
228+
* });
229+
*
230+
* const response = php.handleRequest(new Request({
231+
* method: 'GET',
232+
* url: 'http://example.com'
233+
* }));
234+
*
235+
* console.log(response.status);
236+
* console.log(response.body);
237+
* ```
238+
*/
239+
export declare class Php {
240+
/**
241+
* Create a new PHP instance.
242+
*
243+
* # Examples
244+
*
245+
* ```js
246+
* const php = new Php({
247+
* docroot: process.cwd(),
248+
* argv: process.argv
249+
* });
250+
* ```
251+
*/
252+
constructor(options?: PhpOptions | undefined | null)
253+
/**
254+
* Handle a PHP request.
255+
*
256+
* # Examples
257+
*
258+
* ```js
259+
* const php = new Php({
260+
* docroot: process.cwd(),
261+
* argv: process.argv
262+
* });
263+
*
264+
* const response = php.handleRequest(new Request({
265+
* method: 'GET',
266+
* url: 'http://example.com'
267+
* }));
268+
*
269+
* console.log(response.status);
270+
* console.log(response.body);
271+
* ```
272+
*/
273+
handleRequest(request: Request, signal?: AbortSignal | undefined | null): Promise<unknown>
274+
/**
275+
* Handle a PHP request synchronously.
276+
*
277+
* # Examples
278+
*
279+
* ```js
280+
* const php = new Php({
281+
* docroot: process.cwd(),
282+
* argv: process.argv
283+
* });
284+
*
285+
* const response = php.handleRequestSync(new Request({
286+
* method: 'GET',
287+
* url: 'http://example.com'
288+
* }));
289+
*
290+
* console.log(response.status);
291+
* console.log(response.body);
292+
* ```
293+
*/
294+
handleRequestSync(request: Request): Response
295+
}
296+
export type PhpRuntime = Php
297+
277298
/**
278299
* A PHP request.
279300
*
@@ -369,7 +390,8 @@ export declare class Request {
369390
*/
370391
get body(): Buffer
371392
}
372-
export type PhpResponse = Response
393+
export type PhpRequest = Request
394+
373395
/** A PHP response. */
374396
export declare class Response {
375397
/**
@@ -463,80 +485,61 @@ export declare class Response {
463485
*/
464486
get exception(): string | null
465487
}
466-
export type PhpRuntime = Php
467-
/**
468-
* A PHP instance.
469-
*
470-
* # Examples
471-
*
472-
* ```js
473-
* const php = new Php({
474-
* code: 'echo "Hello, world!";'
475-
* });
476-
*
477-
* const response = php.handleRequest(new Request({
478-
* method: 'GET',
479-
* url: 'http://example.com'
480-
* }));
481-
*
482-
* console.log(response.status);
483-
* console.log(response.body);
484-
* ```
485-
*/
486-
export declare class Php {
487-
/**
488-
* Create a new PHP instance.
489-
*
490-
* # Examples
491-
*
492-
* ```js
493-
* const php = new Php({
494-
* docroot: process.cwd(),
495-
* argv: process.argv
496-
* });
497-
* ```
498-
*/
499-
constructor(options?: PhpOptions | undefined | null)
488+
export type PhpResponse = Response
489+
490+
/** Options for creating a new PHP instance. */
491+
export interface PhpOptions {
492+
/** The command-line arguments for the PHP instance. */
493+
argv?: Array<string>
494+
/** The document root for the PHP instance. */
495+
docroot?: string
496+
/** Throw request errors */
497+
throwRequestErrors?: boolean
498+
}
499+
500+
/** Options for creating a new PHP request. */
501+
export interface PhpRequestOptions {
502+
/** The HTTP method for the request. */
503+
method?: string
504+
/** The URL for the request. */
505+
url: string
500506
/**
501-
* Handle a PHP request.
502-
*
503-
* # Examples
504-
*
505-
* ```js
506-
* const php = new Php({
507-
* docroot: process.cwd(),
508-
* argv: process.argv
509-
* });
510-
*
511-
* const response = php.handleRequest(new Request({
512-
* method: 'GET',
513-
* url: 'http://example.com'
514-
* }));
515-
*
516-
* console.log(response.status);
517-
* console.log(response.body);
518-
* ```
507+
* The headers for the request.
508+
* TODO: Figure out how to accept a Headers instance
509+
* TODO: Figure out how to support both single values without array wrap
519510
*/
520-
handleRequest(request: Request, signal?: AbortSignal | undefined | null): Promise<unknown>
511+
headers?: Record<string, Array<string>>
512+
/** The body for the request. */
513+
body?: Uint8Array
514+
/** The socket information for the request. */
515+
socket?: PhpRequestSocketOptions
516+
}
517+
518+
export interface PhpRequestSocketOptions {
519+
/** The string representation of the local IP address the remote client is connecting on. */
520+
localAddress: string
521+
/** The numeric representation of the local port. For example, 80 or 21. */
522+
localPort: number
523+
/** The string representation of the remote IP address. */
524+
remoteAddress: string
525+
/** The numeric representation of the remote port. For example, 80 or 21. */
526+
remotePort: number
527+
}
528+
529+
/** Options for creating a new PHP response. */
530+
export interface PhpResponseOptions {
531+
/** The HTTP status code for the response. */
532+
status?: number
521533
/**
522-
* Handle a PHP request synchronously.
523-
*
524-
* # Examples
525-
*
526-
* ```js
527-
* const php = new Php({
528-
* docroot: process.cwd(),
529-
* argv: process.argv
530-
* });
531-
*
532-
* const response = php.handleRequestSync(new Request({
533-
* method: 'GET',
534-
* url: 'http://example.com'
535-
* }));
536-
*
537-
* console.log(response.status);
538-
* console.log(response.body);
539-
* ```
534+
* The headers for the response.
535+
* TODO: Figure out how to accept a Headers instance
536+
* TODO: Figure out how to support both single values without array wrap
540537
*/
541-
handleRequestSync(request: Request): Response
538+
headers?: Record<string, Array<string>>
539+
/** The body for the response. */
540+
body?: Uint8Array
541+
/** The log for the response. */
542+
log?: Uint8Array
543+
/** The exception for the response. */
544+
exception?: string
542545
}

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@
44
"main": "index.js",
55
"types": "index.d.ts",
66
"napi": {
7-
"name": "php",
8-
"triples": {
9-
"additional": [
10-
"aarch64-apple-darwin",
11-
"x86_64-apple-darwin",
12-
"x86_64-unknown-linux-gnu",
13-
"universal-apple-darwin"
14-
]
15-
}
7+
"binaryName": "php",
8+
"targets": [
9+
"aarch64-apple-darwin",
10+
"x86_64-apple-darwin",
11+
"x86_64-unknown-linux-gnu",
12+
"universal-apple-darwin"
13+
]
1614
},
1715
"license": "MIT",
1816
"devDependencies": {
19-
"@napi-rs/cli": "^2.18.4",
17+
"@napi-rs/cli": "^3.0.0-alpha.86",
2018
"@oxc-node/core": "^0.0.23",
2119
"ava": "^6.0.1",
2220
"oxlint": "^0.16.0"
@@ -28,8 +26,8 @@
2826
"node": ">= 10"
2927
},
3028
"scripts": {
31-
"build": "napi build --cargo-name php_node --platform --js false --release",
32-
"build:debug": "napi build --cargo-name php_node --platform --js false",
29+
"build": "napi build --manifest-path ./crates/php_node/Cargo.toml --platform --js false --release",
30+
"build:debug": "napi build --manifest-path ./crates/php_node/Cargo.toml --platform --js false",
3331
"lint": "oxlint",
3432
"test": "ava __test__/**.spec.mjs",
3533
"universal": "napi universal",

0 commit comments

Comments
 (0)