@modern-js/server 2.69.5 → 3.0.0-alpha.0
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/dist/cjs/createDevServer.js +98 -100
- package/dist/cjs/dev-tools/https/index.js +57 -49
- package/dist/cjs/dev-tools/watcher/dependencyTree.js +94 -92
- package/dist/cjs/dev-tools/watcher/index.js +129 -124
- package/dist/cjs/dev-tools/watcher/statsCache.js +84 -81
- package/dist/cjs/dev.js +104 -110
- package/dist/cjs/helpers/devOptions.js +55 -54
- package/dist/cjs/helpers/fileReader.js +48 -44
- package/dist/cjs/helpers/index.js +168 -107
- package/dist/cjs/helpers/mock.js +121 -124
- package/dist/cjs/helpers/repack.js +45 -39
- package/dist/cjs/helpers/utils.js +34 -26
- package/dist/cjs/index.js +33 -25
- package/dist/cjs/types.js +17 -15
- package/dist/esm/createDevServer.mjs +59 -0
- package/dist/esm/dev-tools/https/index.mjs +28 -0
- package/dist/esm/dev-tools/watcher/dependencyTree.mjs +57 -0
- package/dist/esm/dev-tools/watcher/index.mjs +88 -0
- package/dist/esm/dev-tools/watcher/statsCache.mjs +50 -0
- package/dist/esm/dev.mjs +77 -0
- package/dist/esm/helpers/devOptions.mjs +24 -0
- package/dist/esm/helpers/fileReader.mjs +18 -0
- package/dist/esm/helpers/index.mjs +65 -0
- package/dist/esm/helpers/mock.mjs +87 -0
- package/dist/esm/helpers/repack.mjs +16 -0
- package/dist/esm/helpers/utils.mjs +3 -0
- package/dist/{esm-node/index.js → esm/index.mjs} +1 -3
- package/dist/esm-node/createDevServer.mjs +59 -0
- package/dist/esm-node/dev-tools/https/index.mjs +28 -0
- package/dist/esm-node/dev-tools/watcher/dependencyTree.mjs +57 -0
- package/dist/esm-node/dev-tools/watcher/index.mjs +88 -0
- package/dist/esm-node/dev-tools/watcher/statsCache.mjs +50 -0
- package/dist/esm-node/dev.mjs +77 -0
- package/dist/esm-node/helpers/devOptions.mjs +24 -0
- package/dist/esm-node/helpers/fileReader.mjs +18 -0
- package/dist/esm-node/helpers/index.mjs +65 -0
- package/dist/esm-node/helpers/mock.mjs +87 -0
- package/dist/esm-node/helpers/repack.mjs +16 -0
- package/dist/esm-node/helpers/utils.mjs +3 -0
- package/dist/esm-node/index.mjs +2 -0
- package/dist/types/createDevServer.d.ts +1 -1
- package/dist/types/dev.d.ts +4 -4
- package/dist/types/helpers/devOptions.d.ts +10 -6
- package/dist/types/helpers/fileReader.d.ts +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/types.d.ts +48 -12
- package/package.json +42 -31
- package/rslib.config.mts +4 -0
- package/dist/cjs/helpers/constants.js +0 -49
- package/dist/esm/createDevServer.js +0 -154
- package/dist/esm/dev-tools/https/index.js +0 -74
- package/dist/esm/dev-tools/watcher/dependencyTree.js +0 -88
- package/dist/esm/dev-tools/watcher/index.js +0 -120
- package/dist/esm/dev-tools/watcher/statsCache.js +0 -80
- package/dist/esm/dev.js +0 -126
- package/dist/esm/helpers/constants.js +0 -25
- package/dist/esm/helpers/devOptions.js +0 -35
- package/dist/esm/helpers/fileReader.js +0 -43
- package/dist/esm/helpers/index.js +0 -123
- package/dist/esm/helpers/mock.js +0 -266
- package/dist/esm/helpers/repack.js +0 -20
- package/dist/esm/helpers/utils.js +0 -5
- package/dist/esm/index.js +0 -4
- package/dist/esm-node/createDevServer.js +0 -71
- package/dist/esm-node/dev-tools/https/index.js +0 -30
- package/dist/esm-node/dev-tools/watcher/dependencyTree.js +0 -67
- package/dist/esm-node/dev-tools/watcher/index.js +0 -100
- package/dist/esm-node/dev-tools/watcher/statsCache.js +0 -58
- package/dist/esm-node/dev.js +0 -93
- package/dist/esm-node/helpers/constants.js +0 -25
- package/dist/esm-node/helpers/devOptions.js +0 -35
- package/dist/esm-node/helpers/fileReader.js +0 -24
- package/dist/esm-node/helpers/index.js +0 -73
- package/dist/esm-node/helpers/mock.js +0 -104
- package/dist/esm-node/helpers/repack.js +0 -20
- package/dist/esm-node/helpers/utils.js +0 -5
- package/dist/types/helpers/constants.d.ts +0 -2
- /package/dist/esm/{types.js → types.mjs} +0 -0
- /package/dist/esm-node/{types.js → types.mjs} +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fileReader } from "@modern-js/runtime-utils/fileReader";
|
|
2
|
+
const cleanSSRCache = (distDir)=>{
|
|
3
|
+
Object.keys(require.cache).forEach((key)=>{
|
|
4
|
+
if (key.startsWith(distDir)) delete require.cache[key];
|
|
5
|
+
});
|
|
6
|
+
};
|
|
7
|
+
const onRepack = (distDir, hooks)=>{
|
|
8
|
+
cleanSSRCache(distDir);
|
|
9
|
+
fileReader.reset();
|
|
10
|
+
hooks.onReset.call({
|
|
11
|
+
event: {
|
|
12
|
+
type: 'repack'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
export { onRepack };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ApplyPlugins, ModernDevServerOptions } from './types';
|
|
2
2
|
export declare function createDevServer(options: ModernDevServerOptions, applyPlugins: ApplyPlugins): Promise<{
|
|
3
3
|
server: (import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("http2").Http2SecureServer<typeof import("http").IncomingMessage, typeof import("http").ServerResponse, typeof import("http2").Http2ServerRequest, typeof import("http2").Http2ServerResponse>) & {
|
|
4
|
-
getRequestListener: () => ReturnType<(handler: import("@modern-js/server-core/dist/types/types").RequestHandler) => (req: import("@modern-js/types").NodeRequest, res: import("@modern-js/types").NodeResponse) => Promise<void>>;
|
|
4
|
+
getRequestListener: () => ReturnType<(handler: import("@modern-js/server-core/dist/types/types").RequestHandler) => (req: import("@modern-js/types/server").NodeRequest, res: import("@modern-js/types/server").NodeResponse) => Promise<void>>;
|
|
5
5
|
getRequestHandler: () => import("@modern-js/server-core/dist/types/types").RequestHandler;
|
|
6
6
|
};
|
|
7
7
|
afterListen: () => Promise<void>;
|
package/dist/types/dev.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { BuilderInstance, Rspack } from '@modern-js/builder';
|
|
2
|
+
import type { ServerBaseOptions, ServerPlugin } from '@modern-js/server-core';
|
|
3
3
|
import type { ModernDevServerOptions } from './types';
|
|
4
|
-
type BuilderDevServer = Awaited<ReturnType<
|
|
4
|
+
type BuilderDevServer = Awaited<ReturnType<BuilderInstance['createDevServer']>>;
|
|
5
5
|
export type DevPluginOptions = ModernDevServerOptions<ServerBaseOptions> & {
|
|
6
6
|
builderDevServer?: BuilderDevServer;
|
|
7
7
|
};
|
|
8
|
-
export declare const devPlugin: (options: DevPluginOptions, compiler: Rspack.Compiler | Rspack.MultiCompiler | null) =>
|
|
8
|
+
export declare const devPlugin: (options: DevPluginOptions, compiler: Rspack.Compiler | Rspack.MultiCompiler | null) => ServerPlugin;
|
|
9
9
|
export {};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
export declare const getDevOptions: (
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { BuilderInstance } from '@modern-js/builder';
|
|
2
|
+
import type { DevServerOptions } from '../types';
|
|
3
|
+
export declare const getDevOptions: (devOptions: DevServerOptions) => {
|
|
4
|
+
setupMiddlewares?: Array<(middlewares: {
|
|
5
|
+
unshift: (...handlers: import("@modern-js/types/server").RequestHandler[]) => void;
|
|
6
|
+
push: (...handlers: import("@modern-js/types/server").RequestHandler[]) => void;
|
|
7
|
+
}, server: import("@modern-js/types/server").ExposeServerApis) => void>;
|
|
8
|
+
https?: import("@modern-js/types/server/devServer").DevServerHttpsOptions;
|
|
9
|
+
server?: import("../types").DevServerConfig;
|
|
6
10
|
};
|
|
7
|
-
export declare const getDevAssetPrefix: (builder?:
|
|
11
|
+
export declare const getDevAssetPrefix: (builder?: BuilderInstance) => Promise<string>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
+
import type { Rspack } from '@modern-js/builder';
|
|
1
2
|
import type { Middleware } from '@modern-js/server-core';
|
|
2
|
-
import type { Rspack } from '@modern-js/uni-builder';
|
|
3
3
|
export declare const initFileReader: (compiler: Rspack.Compiler | Rspack.MultiCompiler | null) => Middleware;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import type { DevServerOptions } from './types';
|
|
1
2
|
export { createDevServer } from './createDevServer';
|
|
2
|
-
export type { ModernDevServerOptions, ApplyPlugins } from './types';
|
|
3
|
+
export type { ModernDevServerOptions, ApplyPlugins, CorsOptions, } from './types';
|
|
4
|
+
export type SetupMiddlewares = DevServerOptions['setupMiddlewares'];
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,24 +1,60 @@
|
|
|
1
1
|
import type { Server as NodeServer } from 'node:http';
|
|
2
2
|
import type { Http2SecureServer } from 'node:http2';
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { ServerBase, ServerBaseOptions, ServerPlugin
|
|
6
|
-
export type {
|
|
3
|
+
import type { BuilderInstance, Rspack } from '@modern-js/builder';
|
|
4
|
+
import type { DevServerHttpsOptions, ExposeServerApis, RequestHandler } from '@modern-js/types';
|
|
5
|
+
import type { ServerBase, ServerBaseOptions, ServerPlugin } from '@modern-js/server-core';
|
|
6
|
+
export type { DevServerHttpsOptions };
|
|
7
|
+
type StaticOrigin = boolean | string | RegExp | Array<boolean | string | RegExp>;
|
|
8
|
+
type CustomOrigin = (requestOrigin: string | undefined, callback: (err: Error | null, origin?: StaticOrigin) => void) => void;
|
|
9
|
+
export interface CorsOptions {
|
|
10
|
+
/**
|
|
11
|
+
* @default '*''
|
|
12
|
+
*/
|
|
13
|
+
origin?: StaticOrigin | CustomOrigin | undefined;
|
|
14
|
+
}
|
|
15
|
+
export interface DevServerConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Configure CORS for the dev server.
|
|
18
|
+
* - object: enable CORS with the specified options.
|
|
19
|
+
* - true: enable CORS with default options (allow all origins, not recommended).
|
|
20
|
+
* - false: disable CORS.
|
|
21
|
+
* @default
|
|
22
|
+
* ```js
|
|
23
|
+
* { origin: defaultAllowedOrigins }
|
|
24
|
+
* ```
|
|
25
|
+
* where `defaultAllowedOrigins` includes:
|
|
26
|
+
* - `localhost`
|
|
27
|
+
* - `127.0.0.1`
|
|
28
|
+
*
|
|
29
|
+
* @link https://github.com/expressjs/cors
|
|
30
|
+
*/
|
|
31
|
+
cors?: boolean | CorsOptions;
|
|
32
|
+
}
|
|
33
|
+
export type DevServerOptions = {
|
|
34
|
+
/** Provides the ability to execute a custom function and apply custom middlewares */
|
|
35
|
+
setupMiddlewares?: Array<(
|
|
36
|
+
/** Order: `devServer.before` => `unshift` => internal middlewares => `push` => `devServer.after` */
|
|
37
|
+
middlewares: {
|
|
38
|
+
/** Use the `unshift` method if you want to run a middleware before all other middlewares */
|
|
39
|
+
unshift: (...handlers: RequestHandler[]) => void;
|
|
40
|
+
/** Use the `push` method if you want to run a middleware after all other middlewares */
|
|
41
|
+
push: (...handlers: RequestHandler[]) => void;
|
|
42
|
+
}, server: ExposeServerApis) => void>;
|
|
43
|
+
/** Whether to enable hot reload. */
|
|
44
|
+
https?: DevServerHttpsOptions;
|
|
45
|
+
/** Dev server specific options. */
|
|
46
|
+
server?: DevServerConfig;
|
|
47
|
+
};
|
|
7
48
|
export type ExtraOptions = {
|
|
8
|
-
dev:
|
|
9
|
-
port?: number;
|
|
10
|
-
host?: string;
|
|
11
|
-
};
|
|
49
|
+
dev: DevServerOptions;
|
|
12
50
|
runCompile?: boolean;
|
|
13
51
|
/**
|
|
14
52
|
* The existing compiler can be used here.
|
|
15
53
|
*/
|
|
16
54
|
compiler?: Rspack.Compiler | Rspack.MultiCompiler;
|
|
17
|
-
/** compat, the default value is modern.server-runtime.config.ts */
|
|
18
|
-
serverConfigFile?: string;
|
|
19
55
|
serverConfigPath: string;
|
|
20
|
-
builder?:
|
|
21
|
-
plugins?:
|
|
56
|
+
builder?: BuilderInstance;
|
|
57
|
+
plugins?: ServerPlugin[];
|
|
22
58
|
};
|
|
23
59
|
export type ModernDevServerOptions<O extends ServerBaseOptions = ServerBaseOptions> = O & ExtraOptions;
|
|
24
60
|
export type ApplyPlugins<O extends ServerBaseOptions = ServerBaseOptions> = (server: ServerBase, options: ModernDevServerOptions<O>, nodeServer?: NodeServer | Http2SecureServer) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -15,65 +15,77 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "
|
|
18
|
+
"version": "3.0.0-alpha.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
22
|
-
"module": "./dist/esm/index.
|
|
22
|
+
"module": "./dist/esm/index.mjs",
|
|
23
23
|
"exports": {
|
|
24
24
|
".": {
|
|
25
|
+
"types": "./dist/types/index.d.ts",
|
|
26
|
+
"modern:source": "./src/index.ts",
|
|
27
|
+
"jsnext:source": "./src/index.ts",
|
|
25
28
|
"node": {
|
|
26
|
-
"
|
|
27
|
-
"import": "./dist/esm-node/index.js",
|
|
29
|
+
"import": "./dist/esm-node/index.mjs",
|
|
28
30
|
"require": "./dist/cjs/index.js"
|
|
29
31
|
},
|
|
30
|
-
"
|
|
31
|
-
"default": "./dist/esm/index.js"
|
|
32
|
+
"default": "./dist/esm/index.mjs"
|
|
32
33
|
},
|
|
33
34
|
"./hmr-client": {
|
|
35
|
+
"types": "./dist/types/dev-tools/dev-middleware/hmr-client/index.d.ts",
|
|
36
|
+
"jsnext:source": "./src/dev-tools/dev-middleware/hmr-client/index.ts",
|
|
34
37
|
"node": {
|
|
35
|
-
"jsnext:source": "./src/dev-tools/dev-middleware/hmr-client/index.ts",
|
|
36
38
|
"require": "./dist/cjs/dev-tools/dev-middleware/hmr-client/index.js"
|
|
37
39
|
},
|
|
38
40
|
"default": "./dist/cjs/dev-tools/dev-middleware/hmr-client/index.js"
|
|
39
41
|
}
|
|
40
42
|
},
|
|
43
|
+
"typesVersions": {
|
|
44
|
+
"*": {
|
|
45
|
+
".": [
|
|
46
|
+
"./dist/types/index.d.ts"
|
|
47
|
+
],
|
|
48
|
+
"hmr-client": [
|
|
49
|
+
"./dist/types/dev-tools/dev-middleware/hmr-client/index.d.ts"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
41
53
|
"dependencies": {
|
|
42
|
-
"@babel/core": "^7.
|
|
43
|
-
"@babel/register": "^7.
|
|
54
|
+
"@babel/core": "^7.28.5",
|
|
55
|
+
"@babel/register": "^7.28.3",
|
|
44
56
|
"@swc/helpers": "^0.5.17",
|
|
45
|
-
"axios": "^1.
|
|
57
|
+
"axios": "^1.13.2",
|
|
46
58
|
"connect-history-api-fallback": "^2.0.0",
|
|
47
59
|
"http-compression": "1.0.6",
|
|
48
60
|
"minimatch": "^3.1.2",
|
|
49
61
|
"path-to-regexp": "^6.3.0",
|
|
50
|
-
"ws": "^8.
|
|
51
|
-
"@modern-js/runtime-utils": "
|
|
52
|
-
"@modern-js/server-core": "
|
|
53
|
-
"@modern-js/
|
|
54
|
-
"@modern-js/
|
|
55
|
-
"@modern-js/utils": "
|
|
62
|
+
"ws": "^8.18.3",
|
|
63
|
+
"@modern-js/runtime-utils": "3.0.0-alpha.0",
|
|
64
|
+
"@modern-js/server-core": "3.0.0-alpha.0",
|
|
65
|
+
"@modern-js/server-utils": "3.0.0-alpha.0",
|
|
66
|
+
"@modern-js/types": "3.0.0-alpha.0",
|
|
67
|
+
"@modern-js/utils": "3.0.0-alpha.0"
|
|
56
68
|
},
|
|
57
69
|
"devDependencies": {
|
|
58
|
-
"@
|
|
59
|
-
"@types/
|
|
70
|
+
"@rslib/core": "0.18.5",
|
|
71
|
+
"@types/connect-history-api-fallback": "^1.5.4",
|
|
72
|
+
"@types/jest": "^29.5.14",
|
|
60
73
|
"@types/minimatch": "^3.0.5",
|
|
61
|
-
"@types/node": "^
|
|
62
|
-
"@types/ws": "^8.
|
|
63
|
-
"jest": "^29",
|
|
64
|
-
"node-mocks-http": "^1.
|
|
65
|
-
"ts-node": "^10.9.
|
|
74
|
+
"@types/node": "^20",
|
|
75
|
+
"@types/ws": "^8.18.1",
|
|
76
|
+
"jest": "^29.7.0",
|
|
77
|
+
"node-mocks-http": "^1.17.2",
|
|
78
|
+
"ts-node": "^10.9.2",
|
|
66
79
|
"tsconfig-paths": "4.2.0",
|
|
67
80
|
"typescript": "^5",
|
|
68
|
-
"webpack": "^5.103.0",
|
|
69
81
|
"websocket": "^1.0.35",
|
|
70
|
-
"@modern-js/
|
|
71
|
-
"@scripts/
|
|
72
|
-
"@
|
|
82
|
+
"@modern-js/builder": "3.0.0-alpha.0",
|
|
83
|
+
"@scripts/jest-config": "2.66.0",
|
|
84
|
+
"@modern-js/rslib": "2.68.10"
|
|
73
85
|
},
|
|
74
86
|
"peerDependencies": {
|
|
75
87
|
"devcert": "^1.2.2",
|
|
76
|
-
"ts-node": "^10.
|
|
88
|
+
"ts-node": "^10.9.2",
|
|
77
89
|
"tsconfig-paths": ">= 3.0.0 || >= 4.0.0"
|
|
78
90
|
},
|
|
79
91
|
"peerDependenciesMeta": {
|
|
@@ -93,9 +105,8 @@
|
|
|
93
105
|
"access": "public"
|
|
94
106
|
},
|
|
95
107
|
"scripts": {
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"dev": "modern-lib build --watch",
|
|
108
|
+
"build": "rslib build",
|
|
109
|
+
"dev": "rslib build --watch",
|
|
99
110
|
"test": "jest"
|
|
100
111
|
}
|
|
101
112
|
}
|
package/rslib.config.mts
ADDED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var constants_exports = {};
|
|
20
|
-
__export(constants_exports, {
|
|
21
|
-
getDefaultDevOptions: () => getDefaultDevOptions
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(constants_exports);
|
|
24
|
-
var import_constants = require("@modern-js/utils/universal/constants");
|
|
25
|
-
const getDefaultDevOptions = () => {
|
|
26
|
-
return {
|
|
27
|
-
client: {
|
|
28
|
-
path: import_constants.HMR_SOCK_PATH,
|
|
29
|
-
// By default it is set to the port number of the dev server
|
|
30
|
-
port: "",
|
|
31
|
-
// By default it is set to "location.hostname"
|
|
32
|
-
host: "",
|
|
33
|
-
// By default it is set to "location.protocol === 'https:' ? 'wss' : 'ws'""
|
|
34
|
-
protocol: void 0
|
|
35
|
-
},
|
|
36
|
-
https: false,
|
|
37
|
-
devMiddleware: {
|
|
38
|
-
writeToDisk: true
|
|
39
|
-
},
|
|
40
|
-
watch: true,
|
|
41
|
-
hot: true,
|
|
42
|
-
compress: true,
|
|
43
|
-
liveReload: true
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
-
0 && (module.exports = {
|
|
48
|
-
getDefaultDevOptions
|
|
49
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
|
-
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
5
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
6
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
7
|
-
import path from "node:path";
|
|
8
|
-
import { createServerBase } from "@modern-js/server-core";
|
|
9
|
-
import { createNodeServer, loadServerRuntimeConfig } from "@modern-js/server-core/node";
|
|
10
|
-
import { devPlugin } from "./dev";
|
|
11
|
-
import { getDevAssetPrefix, getDevOptions } from "./helpers";
|
|
12
|
-
function createDevServer(options, applyPlugins) {
|
|
13
|
-
return _createDevServer.apply(this, arguments);
|
|
14
|
-
}
|
|
15
|
-
function _createDevServer() {
|
|
16
|
-
_createDevServer = _async_to_generator(function(options, applyPlugins) {
|
|
17
|
-
var _config_output_distPath, config, pwd, serverConfigFile, serverConfigPath, builder, metaName, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, isHttp2, nodeServer, genHttpsOptions, httpsOptions, promise, compiler, builderDevServer, assetPrefix, afterListen;
|
|
18
|
-
return _ts_generator(this, function(_state) {
|
|
19
|
-
switch (_state.label) {
|
|
20
|
-
case 0:
|
|
21
|
-
config = options.config, pwd = options.pwd, serverConfigFile = options.serverConfigFile, serverConfigPath = options.serverConfigPath, builder = options.builder, metaName = options.metaName;
|
|
22
|
-
dev = getDevOptions(options);
|
|
23
|
-
distDir = path.resolve(pwd, ((_config_output_distPath = config.output.distPath) === null || _config_output_distPath === void 0 ? void 0 : _config_output_distPath.root) || "dist");
|
|
24
|
-
return [
|
|
25
|
-
4,
|
|
26
|
-
loadServerRuntimeConfig(distDir, serverConfigFile, serverConfigPath, metaName)
|
|
27
|
-
];
|
|
28
|
-
case 1:
|
|
29
|
-
serverConfig = _state.sent() || {};
|
|
30
|
-
prodServerOptions = _object_spread_props(_object_spread({}, options), {
|
|
31
|
-
pwd: distDir,
|
|
32
|
-
serverConfig: _object_spread({}, serverConfig, options.serverConfig),
|
|
33
|
-
/**
|
|
34
|
-
* 1. server plugins from modern.server.ts
|
|
35
|
-
* 2. server plugins register by cli use _internalServerPlugins
|
|
36
|
-
* Merge plugins, the plugins from modern.server.ts will run first
|
|
37
|
-
*/
|
|
38
|
-
plugins: _to_consumable_array(serverConfig.plugins || []).concat(_to_consumable_array(options.plugins || []))
|
|
39
|
-
});
|
|
40
|
-
server = createServerBase(prodServerOptions);
|
|
41
|
-
devHttpsOption = (typeof dev === "undefined" ? "undefined" : _type_of(dev)) === "object" && dev.https;
|
|
42
|
-
isHttp2 = devHttpsOption && typeof dev.proxy === "undefined";
|
|
43
|
-
if (!devHttpsOption)
|
|
44
|
-
return [
|
|
45
|
-
3,
|
|
46
|
-
5
|
|
47
|
-
];
|
|
48
|
-
return [
|
|
49
|
-
4,
|
|
50
|
-
import("./dev-tools/https")
|
|
51
|
-
];
|
|
52
|
-
case 2:
|
|
53
|
-
genHttpsOptions = _state.sent().genHttpsOptions;
|
|
54
|
-
return [
|
|
55
|
-
4,
|
|
56
|
-
genHttpsOptions(devHttpsOption, pwd)
|
|
57
|
-
];
|
|
58
|
-
case 3:
|
|
59
|
-
httpsOptions = _state.sent();
|
|
60
|
-
return [
|
|
61
|
-
4,
|
|
62
|
-
createNodeServer(server.handle.bind(server), httpsOptions, isHttp2)
|
|
63
|
-
];
|
|
64
|
-
case 4:
|
|
65
|
-
nodeServer = _state.sent();
|
|
66
|
-
return [
|
|
67
|
-
3,
|
|
68
|
-
7
|
|
69
|
-
];
|
|
70
|
-
case 5:
|
|
71
|
-
return [
|
|
72
|
-
4,
|
|
73
|
-
createNodeServer(server.handle.bind(server))
|
|
74
|
-
];
|
|
75
|
-
case 6:
|
|
76
|
-
nodeServer = _state.sent();
|
|
77
|
-
_state.label = 7;
|
|
78
|
-
case 7:
|
|
79
|
-
promise = getDevAssetPrefix(builder);
|
|
80
|
-
compiler = null;
|
|
81
|
-
builder === null || builder === void 0 ? void 0 : builder.onAfterCreateCompiler(function(context) {
|
|
82
|
-
compiler = context.compiler;
|
|
83
|
-
});
|
|
84
|
-
return [
|
|
85
|
-
4,
|
|
86
|
-
builder === null || builder === void 0 ? void 0 : builder.createDevServer({
|
|
87
|
-
runCompile: options.runCompile,
|
|
88
|
-
compiler: options.compiler
|
|
89
|
-
})
|
|
90
|
-
];
|
|
91
|
-
case 8:
|
|
92
|
-
builderDevServer = _state.sent();
|
|
93
|
-
server.addPlugins([
|
|
94
|
-
devPlugin(_object_spread_props(_object_spread({}, options), {
|
|
95
|
-
builderDevServer
|
|
96
|
-
}), compiler)
|
|
97
|
-
]);
|
|
98
|
-
return [
|
|
99
|
-
4,
|
|
100
|
-
promise
|
|
101
|
-
];
|
|
102
|
-
case 9:
|
|
103
|
-
assetPrefix = _state.sent();
|
|
104
|
-
if (assetPrefix) {
|
|
105
|
-
prodServerOptions.config.output.assetPrefix = assetPrefix;
|
|
106
|
-
}
|
|
107
|
-
return [
|
|
108
|
-
4,
|
|
109
|
-
applyPlugins(server, prodServerOptions, nodeServer)
|
|
110
|
-
];
|
|
111
|
-
case 10:
|
|
112
|
-
_state.sent();
|
|
113
|
-
return [
|
|
114
|
-
4,
|
|
115
|
-
server.init()
|
|
116
|
-
];
|
|
117
|
-
case 11:
|
|
118
|
-
_state.sent();
|
|
119
|
-
afterListen = function() {
|
|
120
|
-
var _ref = _async_to_generator(function() {
|
|
121
|
-
return _ts_generator(this, function(_state2) {
|
|
122
|
-
switch (_state2.label) {
|
|
123
|
-
case 0:
|
|
124
|
-
return [
|
|
125
|
-
4,
|
|
126
|
-
builderDevServer === null || builderDevServer === void 0 ? void 0 : builderDevServer.afterListen()
|
|
127
|
-
];
|
|
128
|
-
case 1:
|
|
129
|
-
_state2.sent();
|
|
130
|
-
return [
|
|
131
|
-
2
|
|
132
|
-
];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
return function afterListen2() {
|
|
137
|
-
return _ref.apply(this, arguments);
|
|
138
|
-
};
|
|
139
|
-
}();
|
|
140
|
-
return [
|
|
141
|
-
2,
|
|
142
|
-
{
|
|
143
|
-
server: nodeServer,
|
|
144
|
-
afterListen
|
|
145
|
-
}
|
|
146
|
-
];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
return _createDevServer.apply(this, arguments);
|
|
151
|
-
}
|
|
152
|
-
export {
|
|
153
|
-
createDevServer
|
|
154
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import { chalk, getPackageManager, logger } from "@modern-js/utils";
|
|
4
|
-
var genHttpsOptions = function() {
|
|
5
|
-
var _ref = _async_to_generator(function(userOptions, pwd) {
|
|
6
|
-
var httpsOptions, devcertPath, err, packageManager, command, devcert, selfsign;
|
|
7
|
-
return _ts_generator(this, function(_state) {
|
|
8
|
-
switch (_state.label) {
|
|
9
|
-
case 0:
|
|
10
|
-
httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
|
|
11
|
-
if (!(!httpsOptions.key || !httpsOptions.cert))
|
|
12
|
-
return [
|
|
13
|
-
3,
|
|
14
|
-
6
|
|
15
|
-
];
|
|
16
|
-
_state.label = 1;
|
|
17
|
-
case 1:
|
|
18
|
-
_state.trys.push([
|
|
19
|
-
1,
|
|
20
|
-
2,
|
|
21
|
-
,
|
|
22
|
-
4
|
|
23
|
-
]);
|
|
24
|
-
devcertPath = require.resolve("devcert", {
|
|
25
|
-
paths: [
|
|
26
|
-
pwd,
|
|
27
|
-
__dirname
|
|
28
|
-
]
|
|
29
|
-
});
|
|
30
|
-
return [
|
|
31
|
-
3,
|
|
32
|
-
4
|
|
33
|
-
];
|
|
34
|
-
case 2:
|
|
35
|
-
err = _state.sent();
|
|
36
|
-
return [
|
|
37
|
-
4,
|
|
38
|
-
getPackageManager(pwd)
|
|
39
|
-
];
|
|
40
|
-
case 3:
|
|
41
|
-
packageManager = _state.sent();
|
|
42
|
-
command = chalk.yellow.bold("".concat(packageManager, " add devcert@1.2.2 -D"));
|
|
43
|
-
logger.error('You have enabled "dev.https" option, but the "devcert" package is not installed.');
|
|
44
|
-
logger.error("Please run ".concat(command, " to install manually, otherwise the https can not work."));
|
|
45
|
-
throw new Error('[https] "devcert" is not found.');
|
|
46
|
-
case 4:
|
|
47
|
-
devcert = require(devcertPath);
|
|
48
|
-
return [
|
|
49
|
-
4,
|
|
50
|
-
devcert.certificateFor([
|
|
51
|
-
"localhost"
|
|
52
|
-
])
|
|
53
|
-
];
|
|
54
|
-
case 5:
|
|
55
|
-
selfsign = _state.sent();
|
|
56
|
-
return [
|
|
57
|
-
2,
|
|
58
|
-
selfsign
|
|
59
|
-
];
|
|
60
|
-
case 6:
|
|
61
|
-
return [
|
|
62
|
-
2,
|
|
63
|
-
httpsOptions
|
|
64
|
-
];
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
return function genHttpsOptions2(userOptions, pwd) {
|
|
69
|
-
return _ref.apply(this, arguments);
|
|
70
|
-
};
|
|
71
|
-
}();
|
|
72
|
-
export {
|
|
73
|
-
genHttpsOptions
|
|
74
|
-
};
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
|
-
import minimatch from "minimatch";
|
|
4
|
-
var defaultIgnores = [
|
|
5
|
-
"**/coverage/**",
|
|
6
|
-
"**/node_modules/**",
|
|
7
|
-
"**/.*/**",
|
|
8
|
-
"**/*.d.ts",
|
|
9
|
-
"**/*.log"
|
|
10
|
-
];
|
|
11
|
-
var DependencyTree = /* @__PURE__ */ function() {
|
|
12
|
-
"use strict";
|
|
13
|
-
function DependencyTree2() {
|
|
14
|
-
_class_call_check(this, DependencyTree2);
|
|
15
|
-
this.tree = /* @__PURE__ */ new Map();
|
|
16
|
-
this.ignore = _to_consumable_array(defaultIgnores);
|
|
17
|
-
}
|
|
18
|
-
var _proto = DependencyTree2.prototype;
|
|
19
|
-
_proto.getNode = function getNode(path) {
|
|
20
|
-
return this.tree.get(path);
|
|
21
|
-
};
|
|
22
|
-
_proto.update = function update(cache) {
|
|
23
|
-
var _this = this;
|
|
24
|
-
this.tree.clear();
|
|
25
|
-
Object.keys(cache).forEach(function(path) {
|
|
26
|
-
if (!_this.shouldIgnore(path)) {
|
|
27
|
-
var module = cache[path];
|
|
28
|
-
_this.tree.set(module.filename, {
|
|
29
|
-
module,
|
|
30
|
-
parent: /* @__PURE__ */ new Set(),
|
|
31
|
-
children: /* @__PURE__ */ new Set()
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
36
|
-
try {
|
|
37
|
-
var _this1, _loop = function() {
|
|
38
|
-
var treeNode = _step.value;
|
|
39
|
-
var parent = treeNode.module.parent;
|
|
40
|
-
var children = treeNode.module.children;
|
|
41
|
-
if (parent && !_this1.shouldIgnore(parent.filename)) {
|
|
42
|
-
var parentTreeNode = _this1.tree.get(parent.filename);
|
|
43
|
-
if (parentTreeNode) {
|
|
44
|
-
treeNode.parent.add(parentTreeNode);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
children === null || children === void 0 ? void 0 : children.forEach(function(child) {
|
|
48
|
-
if (!_this.shouldIgnore(child.filename)) {
|
|
49
|
-
var childTreeNode = _this.tree.get(child.filename);
|
|
50
|
-
if (childTreeNode) {
|
|
51
|
-
treeNode.children.add(childTreeNode);
|
|
52
|
-
childTreeNode.parent.add(treeNode);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
for (var _iterator = this.tree.values()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
|
|
58
|
-
_this1 = this, _loop();
|
|
59
|
-
} catch (err) {
|
|
60
|
-
_didIteratorError = true;
|
|
61
|
-
_iteratorError = err;
|
|
62
|
-
} finally {
|
|
63
|
-
try {
|
|
64
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
65
|
-
_iterator.return();
|
|
66
|
-
}
|
|
67
|
-
} finally {
|
|
68
|
-
if (_didIteratorError) {
|
|
69
|
-
throw _iteratorError;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
_proto.shouldIgnore = function shouldIgnore(path) {
|
|
75
|
-
return !path || Boolean(this.ignore.find(function(rule) {
|
|
76
|
-
return minimatch.match([
|
|
77
|
-
path
|
|
78
|
-
], rule, {
|
|
79
|
-
dot: true
|
|
80
|
-
}).length > 0;
|
|
81
|
-
}));
|
|
82
|
-
};
|
|
83
|
-
return DependencyTree2;
|
|
84
|
-
}();
|
|
85
|
-
export {
|
|
86
|
-
DependencyTree,
|
|
87
|
-
defaultIgnores
|
|
88
|
-
};
|