nextrush 3.0.5 → 3.0.7
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/README.md +28 -13
- package/dist/class.d.ts +5 -0
- package/dist/index.d.ts +0 -84
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/package.json +11 -14
- package/scripts/postinstall.d.ts +5 -0
- package/scripts/postinstall.js +84 -0
package/README.md
CHANGED
|
@@ -55,18 +55,33 @@ listen(app, 3000);
|
|
|
55
55
|
|
|
56
56
|
## Performance
|
|
57
57
|
|
|
58
|
-
Benchmark snapshot from a single lab machine (Intel i5-8300H, 8 cores) running Node.js v25.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
69
|
-
|
|
58
|
+
Benchmark snapshot from a single lab machine (Intel i5-8300H, 8 cores) running Node.js v25.9.0.
|
|
59
|
+
Two tools available: **wrk** (C-based, process-isolated) and **autocannon** (Node.js, automatic fallback).
|
|
60
|
+
All tests: 10s duration, 64 connections, no pipelining. See [Performance](https://github.com/0xTanzim/nextRush/blob/main/apps/docs/content/docs/performance/index.mdx) for methodology and numbers.
|
|
61
|
+
|
|
62
|
+
### wrk
|
|
63
|
+
|
|
64
|
+
| Framework | Hello World | Route Params | POST JSON | Middleware Stack |
|
|
65
|
+
| --------------- | -------------- | -------------- | -------------- | ---------------- |
|
|
66
|
+
| Raw Node.js | 35,863 RPS | 33,326 RPS | 25,116 RPS | 30,738 RPS |
|
|
67
|
+
| Fastify | 35,592 RPS | 32,407 RPS | 18,799 RPS | 27,968 RPS |
|
|
68
|
+
| **NextRush v3** | **31,311 RPS** | **29,688 RPS** | **18,460 RPS** | **32,377 RPS** |
|
|
69
|
+
| Hono | 26,438 RPS | 26,586 RPS | 10,826 RPS | 22,179 RPS |
|
|
70
|
+
| Koa | 23,350 RPS | 21,890 RPS | 14,954 RPS | 20,972 RPS |
|
|
71
|
+
| Express | 17,784 RPS | 17,598 RPS | 12,947 RPS | 17,356 RPS |
|
|
72
|
+
|
|
73
|
+
### autocannon
|
|
74
|
+
|
|
75
|
+
| Framework | Hello World | Route Params | POST JSON | Middleware Stack |
|
|
76
|
+
| --------------- | -------------- | -------------- | -------------- | ---------------- |
|
|
77
|
+
| Raw Node.js | 36,903 RPS | 33,936 RPS | 24,936 RPS | 31,471 RPS |
|
|
78
|
+
| Fastify | 34,063 RPS | 31,095 RPS | 18,532 RPS | 28,744 RPS |
|
|
79
|
+
| **NextRush v3** | **31,733 RPS** | **29,534 RPS** | **19,192 RPS** | **32,220 RPS** |
|
|
80
|
+
| Hono | 28,209 RPS | 25,966 RPS | 10,798 RPS | 22,258 RPS |
|
|
81
|
+
| Koa | 23,845 RPS | 22,421 RPS | 15,323 RPS | 21,125 RPS |
|
|
82
|
+
| Express | 19,496 RPS | 18,209 RPS | 13,063 RPS | 17,352 RPS |
|
|
83
|
+
|
|
84
|
+
> Performance varies by hardware. Run `apps/benchmark` on your machine.
|
|
70
85
|
|
|
71
86
|
## Adding Middleware
|
|
72
87
|
|
|
@@ -227,7 +242,7 @@ app.use(async (ctx) => {
|
|
|
227
242
|
|
|
228
243
|
```typescript
|
|
229
244
|
import { VERSION } from 'nextrush';
|
|
230
|
-
console.log(VERSION); // '3.0.
|
|
245
|
+
console.log(VERSION); // '3.0.5'
|
|
231
246
|
```
|
|
232
247
|
|
|
233
248
|
## License
|
package/dist/class.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { AutoInjectable, ClassProvider, Config, ConfigOptions, ContainerInterface, FactoryProvider, Injectable, Optional, Provider, Repository, Scope, Service, ServiceOptions, Token, ValueProvider, container, createContainer, delay, inject } from '@nextrush/di';
|
|
2
2
|
export { All, Body, BodyOptions, CanActivate, Controller, ControllerMetadata, ControllerOptions, Ctx, CustomParamExtractor, Delete, Get, GuardContext, GuardFn, Head, Header, HeaderOptions, Options, Param, ParamMetadata, ParamOptions, ParamSource, Patch, Post, Put, Query, QueryOptions, Redirect, Req, Res, RouteMetadata, RouteOptions, SetHeader, TransformFn, UseGuard, createCustomParamDecorator } from '@nextrush/decorators';
|
|
3
3
|
export { ControllersPluginOptions, controllersPlugin } from '@nextrush/controllers';
|
|
4
|
+
import '@nextrush/core';
|
|
5
|
+
import '@nextrush/router';
|
|
6
|
+
import '@nextrush/adapter-node';
|
|
7
|
+
import '@nextrush/errors';
|
|
8
|
+
import '@nextrush/types';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,87 +3,3 @@ export { Router, RouterOptions, createRouter } from '@nextrush/router';
|
|
|
3
3
|
export { ServeOptions, ServerInstance, createHandler, listen, serve } from '@nextrush/adapter-node';
|
|
4
4
|
export { BadGatewayError, BadRequestError, ConflictError, ErrorHandlerOptions, ForbiddenError, GatewayTimeoutError, HttpError, HttpErrorOptions, InternalServerError, MethodNotAllowedError, NextRushError, NotFoundError, NotImplementedError, ServiceUnavailableError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, catchAsync, createError, errorHandler, isHttpError, notFoundHandler } from '@nextrush/errors';
|
|
5
5
|
export { ContentType, Context, HttpMethod, HttpStatus, HttpStatusCode, Middleware, Next, Plugin, RouteHandler, Runtime } from '@nextrush/types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* NextRush - Minimal, Modular, Blazing Fast Node.js Framework
|
|
9
|
-
*
|
|
10
|
-
* This meta package provides the **functional** API for building Node.js APIs:
|
|
11
|
-
* - Application creation (createApp)
|
|
12
|
-
* - Routing (createRouter)
|
|
13
|
-
* - Server start (listen)
|
|
14
|
-
* - HTTP errors
|
|
15
|
-
* - Essential types
|
|
16
|
-
*
|
|
17
|
-
* For the class-based paradigm (DI, decorators, controllers),
|
|
18
|
-
* import from `nextrush/class` instead.
|
|
19
|
-
*
|
|
20
|
-
* For middleware, install separately:
|
|
21
|
-
* - @nextrush/cors
|
|
22
|
-
* - @nextrush/helmet
|
|
23
|
-
* - @nextrush/body-parser
|
|
24
|
-
* - @nextrush/rate-limit
|
|
25
|
-
* - @nextrush/logger
|
|
26
|
-
*
|
|
27
|
-
* For other runtimes, install the appropriate adapter:
|
|
28
|
-
* - @nextrush/adapter-bun
|
|
29
|
-
* - @nextrush/adapter-deno
|
|
30
|
-
* - @nextrush/adapter-edge
|
|
31
|
-
*
|
|
32
|
-
* @packageDocumentation
|
|
33
|
-
* @module nextrush
|
|
34
|
-
*
|
|
35
|
-
* @example Quick Start (Functional)
|
|
36
|
-
* ```typescript
|
|
37
|
-
* import { createApp, createRouter, listen } from 'nextrush';
|
|
38
|
-
*
|
|
39
|
-
* const app = createApp();
|
|
40
|
-
* const router = createRouter();
|
|
41
|
-
*
|
|
42
|
-
* router.get('/', (ctx) => {
|
|
43
|
-
* ctx.json({ message: 'Hello NextRush!' });
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* app.route('/', router);
|
|
47
|
-
* listen(app, 3000);
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @example With Middleware (install separately)
|
|
51
|
-
* ```typescript
|
|
52
|
-
* import { createApp, listen } from 'nextrush';
|
|
53
|
-
* import { cors } from '@nextrush/cors';
|
|
54
|
-
* import { json } from '@nextrush/body-parser';
|
|
55
|
-
*
|
|
56
|
-
* const app = createApp();
|
|
57
|
-
* app.use(cors());
|
|
58
|
-
* app.use(json());
|
|
59
|
-
*
|
|
60
|
-
* listen(app, 3000);
|
|
61
|
-
* ```
|
|
62
|
-
*
|
|
63
|
-
* @example Class-Based (import from nextrush/class)
|
|
64
|
-
* ```typescript
|
|
65
|
-
* import { createApp, listen } from 'nextrush';
|
|
66
|
-
* import { Controller, Get, Service, controllersPlugin } from 'nextrush/class';
|
|
67
|
-
*
|
|
68
|
-
* @Service()
|
|
69
|
-
* class UserService {
|
|
70
|
-
* findAll() { return [{ id: 1, name: 'Alice' }]; }
|
|
71
|
-
* }
|
|
72
|
-
*
|
|
73
|
-
* @Controller('/users')
|
|
74
|
-
* class UserController {
|
|
75
|
-
* constructor(private users: UserService) {}
|
|
76
|
-
*
|
|
77
|
-
* @Get()
|
|
78
|
-
* findAll() { return this.users.findAll(); }
|
|
79
|
-
* }
|
|
80
|
-
*
|
|
81
|
-
* const app = createApp();
|
|
82
|
-
* app.plugin(controllersPlugin({ root: './src' }));
|
|
83
|
-
* listen(app, 3000);
|
|
84
|
-
* ```
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
declare const VERSION = "3.0.4";
|
|
88
|
-
|
|
89
|
-
export { VERSION };
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,30 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Application, compose, createApp } from "@nextrush/core";
|
|
3
|
-
import {
|
|
3
|
+
import { Router, createRouter } from "@nextrush/router";
|
|
4
4
|
import { createHandler, listen, serve } from "@nextrush/adapter-node";
|
|
5
5
|
import {
|
|
6
6
|
BadGatewayError,
|
|
7
7
|
BadRequestError,
|
|
8
|
-
catchAsync,
|
|
9
8
|
ConflictError,
|
|
10
|
-
createError,
|
|
11
|
-
errorHandler,
|
|
12
9
|
ForbiddenError,
|
|
13
10
|
GatewayTimeoutError,
|
|
14
11
|
HttpError,
|
|
15
12
|
InternalServerError,
|
|
16
|
-
isHttpError,
|
|
17
13
|
MethodNotAllowedError,
|
|
18
14
|
NextRushError,
|
|
19
15
|
NotFoundError,
|
|
20
|
-
notFoundHandler,
|
|
21
16
|
NotImplementedError,
|
|
22
17
|
ServiceUnavailableError,
|
|
23
18
|
TooManyRequestsError,
|
|
24
19
|
UnauthorizedError,
|
|
25
|
-
UnprocessableEntityError
|
|
20
|
+
UnprocessableEntityError,
|
|
21
|
+
catchAsync,
|
|
22
|
+
createError,
|
|
23
|
+
errorHandler,
|
|
24
|
+
isHttpError,
|
|
25
|
+
notFoundHandler
|
|
26
26
|
} from "@nextrush/errors";
|
|
27
27
|
import { ContentType, HttpStatus } from "@nextrush/types";
|
|
28
|
-
var VERSION = "3.0.4";
|
|
29
28
|
export {
|
|
30
29
|
Application,
|
|
31
30
|
BadGatewayError,
|
|
@@ -46,7 +45,6 @@ export {
|
|
|
46
45
|
TooManyRequestsError,
|
|
47
46
|
UnauthorizedError,
|
|
48
47
|
UnprocessableEntityError,
|
|
49
|
-
VERSION,
|
|
50
48
|
catchAsync,
|
|
51
49
|
compose,
|
|
52
50
|
createApp,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * NextRush - Minimal, Modular, Blazing Fast Node.js Framework\n *\n * This meta package provides the **functional** API for building Node.js APIs:\n * - Application creation (createApp)\n * - Routing (createRouter)\n * - Server start (listen)\n * - HTTP errors\n * - Essential types\n *\n * For the class-based paradigm (DI, decorators, controllers),\n * import from `nextrush/class` instead.\n *\n * For middleware, install separately:\n * - @nextrush/cors\n * - @nextrush/helmet\n * - @nextrush/body-parser\n * - @nextrush/rate-limit\n * - @nextrush/logger\n *\n * For other runtimes, install the appropriate adapter:\n * - @nextrush/adapter-bun\n * - @nextrush/adapter-deno\n * - @nextrush/adapter-edge\n *\n * @packageDocumentation\n * @module nextrush\n *\n * @example Quick Start (Functional)\n * ```typescript\n * import { createApp, createRouter, listen } from 'nextrush';\n *\n * const app = createApp();\n * const router = createRouter();\n *\n * router.get('/', (ctx) => {\n * ctx.json({ message: 'Hello NextRush!' });\n * });\n *\n * app.route('/', router);\n * listen(app, 3000);\n * ```\n *\n * @example With Middleware (install separately)\n * ```typescript\n * import { createApp, listen } from 'nextrush';\n * import { cors } from '@nextrush/cors';\n * import { json } from '@nextrush/body-parser';\n *\n * const app = createApp();\n * app.use(cors());\n * app.use(json());\n *\n * listen(app, 3000);\n * ```\n *\n * @example Class-Based (import from nextrush/class)\n * ```typescript\n * import { createApp, listen } from 'nextrush';\n * import { Controller, Get, Service, controllersPlugin } from 'nextrush/class';\n *\n * @Service()\n * class UserService {\n * findAll() { return [{ id: 1, name: 'Alice' }]; }\n * }\n *\n * @Controller('/users')\n * class UserController {\n * constructor(private users: UserService) {}\n *\n * @Get()\n * findAll() { return this.users.findAll(); }\n * }\n *\n * const app = createApp();\n * app.plugin(controllersPlugin({ root: './src' }));\n * listen(app, 3000);\n * ```\n */\n\n// ============================================\n// CORE: Application & Middleware Composition\n// ============================================\nexport { Application, compose, createApp } from '@nextrush/core';\nexport type { ApplicationOptions, ComposedMiddleware } from '@nextrush/core';\n\n// ============================================\n// ROUTER: Radix Tree Routing\n// ============================================\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * NextRush - Minimal, Modular, Blazing Fast Node.js Framework\n *\n * This meta package provides the **functional** API for building Node.js APIs:\n * - Application creation (createApp)\n * - Routing (createRouter)\n * - Server start (listen)\n * - HTTP errors\n * - Essential types\n *\n * For the class-based paradigm (DI, decorators, controllers),\n * import from `nextrush/class` instead.\n *\n * For middleware, install separately:\n * - @nextrush/cors\n * - @nextrush/helmet\n * - @nextrush/body-parser\n * - @nextrush/rate-limit\n * - @nextrush/logger\n *\n * For other runtimes, install the appropriate adapter:\n * - @nextrush/adapter-bun\n * - @nextrush/adapter-deno\n * - @nextrush/adapter-edge\n *\n * @packageDocumentation\n * @module nextrush\n *\n * @example Quick Start (Functional)\n * ```typescript\n * import { createApp, createRouter, listen } from 'nextrush';\n *\n * const app = createApp();\n * const router = createRouter();\n *\n * router.get('/', (ctx) => {\n * ctx.json({ message: 'Hello NextRush!' });\n * });\n *\n * app.route('/', router);\n * listen(app, 3000);\n * ```\n *\n * @example With Middleware (install separately)\n * ```typescript\n * import { createApp, listen } from 'nextrush';\n * import { cors } from '@nextrush/cors';\n * import { json } from '@nextrush/body-parser';\n *\n * const app = createApp();\n * app.use(cors());\n * app.use(json());\n *\n * listen(app, 3000);\n * ```\n *\n * @example Class-Based (import from nextrush/class)\n * ```typescript\n * import { createApp, listen } from 'nextrush';\n * import { Controller, Get, Service, controllersPlugin } from 'nextrush/class';\n *\n * @Service()\n * class UserService {\n * findAll() { return [{ id: 1, name: 'Alice' }]; }\n * }\n *\n * @Controller('/users')\n * class UserController {\n * constructor(private users: UserService) {}\n *\n * @Get()\n * findAll() { return this.users.findAll(); }\n * }\n *\n * const app = createApp();\n * app.plugin(controllersPlugin({ root: './src' }));\n * listen(app, 3000);\n * ```\n */\n\n// ============================================\n// CORE: Application & Middleware Composition\n// ============================================\nexport { Application, compose, createApp } from '@nextrush/core';\nexport type { ApplicationOptions, ComposedMiddleware } from '@nextrush/core';\n\n// ============================================\n// ROUTER: Radix Tree Routing\n// ============================================\nexport { Router, createRouter } from '@nextrush/router';\nexport type { RouterOptions } from '@nextrush/router';\n\n// ============================================\n// ADAPTER: Node.js HTTP (Default Runtime)\n// ============================================\nexport { createHandler, listen, serve } from '@nextrush/adapter-node';\nexport type { ServeOptions, ServerInstance } from '@nextrush/adapter-node';\n\n// ============================================\n// ERRORS: HTTP Error Classes & Factory\n// ============================================\nexport {\n BadGatewayError,\n // 4xx Client Errors\n BadRequestError, ConflictError, ForbiddenError,\n GatewayTimeoutError,\n // Base\n HttpError,\n // 5xx Server Errors\n InternalServerError, MethodNotAllowedError,\n NextRushError,\n NotFoundError, NotImplementedError,\n ServiceUnavailableError,\n TooManyRequestsError,\n UnauthorizedError,\n UnprocessableEntityError, catchAsync,\n // Factory functions\n createError,\n // Error handling middleware\n errorHandler, isHttpError, notFoundHandler\n} from '@nextrush/errors';\n\nexport type { ErrorHandlerOptions, HttpErrorOptions } from '@nextrush/errors';\n\n// ============================================\n// TYPES: Essential TypeScript Types\n// ============================================\nexport type {\n // Core types\n Context,\n // HTTP types\n HttpMethod,\n HttpStatusCode,\n Middleware,\n Next,\n Plugin,\n RouteHandler,\n // Runtime\n Runtime\n} from '@nextrush/types';\n\n// HTTP constants\nexport { ContentType, HttpStatus } from '@nextrush/types';\n\n// NOTE: VERSION is not exported from the core package to maintain\n// Edge runtime compatibility (no node:fs). Use @nextrush/dev or\n// check package.json directly if you need the version.\n"],"mappings":";AAmFA,SAASA,aAAaC,SAASC,iBAAiB;AAMhD,SAASC,QAAQC,oBAAoB;AAMrC,SAASC,eAAeC,QAAQC,aAAa;AAM7C;EACIC;EAEAC;EAAiBC;EAAeC;EAChCC;EAEAC;EAEAC;EAAqBC;EACrBC;EACAC;EAAeC;EACfC;EACAC;EACAC;EACAC;EAA0BC;EAE1BC;EAEAC;EAAcC;EAAaC;OACxB;AAsBP,SAASC,aAAaC,kBAAkB;","names":["Application","compose","createApp","Router","createRouter","createHandler","listen","serve","BadGatewayError","BadRequestError","ConflictError","ForbiddenError","GatewayTimeoutError","HttpError","InternalServerError","MethodNotAllowedError","NextRushError","NotFoundError","NotImplementedError","ServiceUnavailableError","TooManyRequestsError","UnauthorizedError","UnprocessableEntityError","catchAsync","createError","errorHandler","isHttpError","notFoundHandler","ContentType","HttpStatus"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextrush",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"description": "Minimal, modular, blazing fast Node.js framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,12 +16,9 @@
|
|
|
16
16
|
"import": "./dist/class.js"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
-
"bin": {
|
|
20
|
-
"nextrush": "./bin/nextrush.js"
|
|
21
|
-
},
|
|
22
19
|
"files": [
|
|
23
|
-
"bin",
|
|
24
20
|
"dist",
|
|
21
|
+
"scripts",
|
|
25
22
|
"README.md"
|
|
26
23
|
],
|
|
27
24
|
"keywords": [
|
|
@@ -63,15 +60,14 @@
|
|
|
63
60
|
],
|
|
64
61
|
"dependencies": {
|
|
65
62
|
"reflect-metadata": "^0.2.2",
|
|
66
|
-
"@nextrush/
|
|
67
|
-
"@nextrush/
|
|
68
|
-
"@nextrush/
|
|
69
|
-
"@nextrush/
|
|
70
|
-
"@nextrush/
|
|
71
|
-
"@nextrush/
|
|
72
|
-
"@nextrush/
|
|
73
|
-
"@nextrush/
|
|
74
|
-
"@nextrush/types": "3.0.5"
|
|
63
|
+
"@nextrush/adapter-node": "3.0.7",
|
|
64
|
+
"@nextrush/controllers": "3.0.7",
|
|
65
|
+
"@nextrush/core": "3.0.7",
|
|
66
|
+
"@nextrush/decorators": "3.0.7",
|
|
67
|
+
"@nextrush/di": "3.0.7",
|
|
68
|
+
"@nextrush/errors": "3.0.7",
|
|
69
|
+
"@nextrush/router": "3.0.7",
|
|
70
|
+
"@nextrush/types": "3.0.7"
|
|
75
71
|
},
|
|
76
72
|
"devDependencies": {
|
|
77
73
|
"tsup": "^8.5.1",
|
|
@@ -83,6 +79,7 @@
|
|
|
83
79
|
"@nextrush/helmet": "3.0.5"
|
|
84
80
|
},
|
|
85
81
|
"scripts": {
|
|
82
|
+
"postinstall": "node scripts/postinstall.js",
|
|
86
83
|
"build": "tsup",
|
|
87
84
|
"clean": "rm -rf dist",
|
|
88
85
|
"typecheck": "tsc --noEmit",
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* nextrush postinstall script
|
|
5
|
+
*
|
|
6
|
+
* Automatically installs @nextrush/dev (dev server & build CLI) when
|
|
7
|
+
* a user installs the `nextrush` meta package. This ensures `nextrush dev`
|
|
8
|
+
* and `nextrush build` commands work out of the box.
|
|
9
|
+
*
|
|
10
|
+
* Skips installation when:
|
|
11
|
+
* - Running in CI (process.env.CI is set)
|
|
12
|
+
* - NEXTRUSH_SKIP_POSTINSTALL=1 is set
|
|
13
|
+
* - @nextrush/dev is already resolvable
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { createRequire } from 'node:module';
|
|
17
|
+
import { execSync } from 'node:child_process';
|
|
18
|
+
|
|
19
|
+
export function shouldSkip() {
|
|
20
|
+
if (process.env.CI) return true;
|
|
21
|
+
if (process.env.NEXTRUSH_SKIP_POSTINSTALL === '1') return true;
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isDevInstalled() {
|
|
26
|
+
const require = createRequire(import.meta.url);
|
|
27
|
+
try {
|
|
28
|
+
require.resolve('@nextrush/dev');
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function detectPackageManager() {
|
|
36
|
+
const userAgent = process.env.npm_config_user_agent || '';
|
|
37
|
+
|
|
38
|
+
if (userAgent.includes('pnpm')) return 'pnpm';
|
|
39
|
+
if (userAgent.includes('yarn')) return 'yarn';
|
|
40
|
+
if (userAgent.includes('bun')) return 'bun';
|
|
41
|
+
return 'npm';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function getInstallCommand(packageManager) {
|
|
45
|
+
const cmds = {
|
|
46
|
+
pnpm: 'pnpm add -D @nextrush/dev@latest',
|
|
47
|
+
yarn: 'yarn add -D @nextrush/dev@latest',
|
|
48
|
+
bun: 'bun add -D @nextrush/dev@latest',
|
|
49
|
+
npm: 'npm install -D @nextrush/dev@latest',
|
|
50
|
+
};
|
|
51
|
+
return cmds[packageManager];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function installDevPackage(packageManager) {
|
|
55
|
+
const cmd = getInstallCommand(packageManager);
|
|
56
|
+
console.log('\n[nextrush] Installing @nextrush/dev (dev server & build CLI)...');
|
|
57
|
+
try {
|
|
58
|
+
execSync(cmd, { stdio: 'inherit' });
|
|
59
|
+
console.log('[nextrush] @nextrush/dev installed successfully.');
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
console.warn('[nextrush] Warning: Failed to auto-install @nextrush/dev.');
|
|
63
|
+
console.warn(`[nextrush] Run manually: ${cmd}`);
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Only run when executed directly (not imported for testing)
|
|
69
|
+
const isMainModule = process.argv[1] &&
|
|
70
|
+
(process.argv[1].endsWith('postinstall.js') || process.argv[1].endsWith('postinstall'));
|
|
71
|
+
|
|
72
|
+
if (isMainModule) {
|
|
73
|
+
if (shouldSkip()) {
|
|
74
|
+
process.exit(0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (isDevInstalled()) {
|
|
78
|
+
process.exit(0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const pm = detectPackageManager();
|
|
82
|
+
const success = installDevPackage(pm);
|
|
83
|
+
process.exit(success ? 0 : 0); // Don't fail the parent install
|
|
84
|
+
}
|