@t8/serve 0.1.34 → 0.1.35
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/index.d.ts +3 -0
- package/dist/src/BundleConfig.d.ts +20 -0
- package/dist/src/Config.d.ts +47 -0
- package/dist/src/bundle.d.ts +2 -0
- package/dist/src/getFilePath.d.ts +2 -0
- package/dist/src/getTarget.d.ts +5 -0
- package/dist/src/isValidFilePath.d.ts +1 -0
- package/dist/src/mimeTypes.d.ts +1 -0
- package/dist/src/run.d.ts +2 -0
- package/dist/src/serve.d.ts +4 -0
- package/package.json +5 -3
- package/src/serve.ts +1 -1
- package/tsconfig.json +2 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type BundleConfig = {
|
|
2
|
+
/**
|
|
3
|
+
* Output directory path relative to the server config `path`.
|
|
4
|
+
*
|
|
5
|
+
* @defaultValue "dist"
|
|
6
|
+
*/
|
|
7
|
+
dir?: string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Input path relative to the server config `path`.
|
|
10
|
+
*
|
|
11
|
+
* @defaultValue "index.ts"
|
|
12
|
+
*/
|
|
13
|
+
input?: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Output path relative to the bundle config `dir`.
|
|
16
|
+
*
|
|
17
|
+
* @defaultValue "index.js"
|
|
18
|
+
*/
|
|
19
|
+
output?: string | undefined;
|
|
20
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
import type { BundleConfig } from "./BundleConfig.ts";
|
|
3
|
+
export type Config = {
|
|
4
|
+
/** Server URL. */
|
|
5
|
+
url?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Server host.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue "localhost"
|
|
10
|
+
*/
|
|
11
|
+
host?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Server port.
|
|
14
|
+
*
|
|
15
|
+
* @defaultValue 3000
|
|
16
|
+
*/
|
|
17
|
+
port?: number;
|
|
18
|
+
/** Application path. */
|
|
19
|
+
path?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Public assets directories. If not provided, the application
|
|
22
|
+
* `path` is served as a public assets directory.
|
|
23
|
+
*/
|
|
24
|
+
dirs?: string[];
|
|
25
|
+
/**
|
|
26
|
+
* Enables single-page application (SPA) mode. If `true`, all
|
|
27
|
+
* unmatched URLs are served as "/".
|
|
28
|
+
*/
|
|
29
|
+
spa?: boolean;
|
|
30
|
+
/** Whether to rebuild whenever the bundled files change. */
|
|
31
|
+
watch?: boolean;
|
|
32
|
+
/** Whether the bundle should be minified. */
|
|
33
|
+
minify?: boolean;
|
|
34
|
+
/** Whether to log to the console. */
|
|
35
|
+
log?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Bundle config.
|
|
38
|
+
*
|
|
39
|
+
* If `undefined`, bundling is skipped.
|
|
40
|
+
* Otherwise, its type is `BundleConfig`, with the following shorthand options:
|
|
41
|
+
* If `true`, it's equivalent to `{ input: "index.ts", output: "index.js" }`.
|
|
42
|
+
* If `string`, it's equivalent to `input` in `{ input, ouput: "index.js" }`.
|
|
43
|
+
*/
|
|
44
|
+
bundle?: boolean | string | BundleConfig | undefined;
|
|
45
|
+
/** Custom request handler. */
|
|
46
|
+
onRequest?: (req?: IncomingMessage, res?: ServerResponse<IncomingMessage>) => void | Promise<void>;
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidFilePath(filePath: string, dirPath: string): Promise<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mimeTypes: Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t8/serve",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.35",
|
|
4
4
|
"description": "Simple static file server + bundler, primarily for demo apps and tests, manual or automated",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
"author": "axtk",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"main": "dist/index.js",
|
|
21
|
+
"types": "dist/index.d.ts",
|
|
21
22
|
"scripts": {
|
|
22
|
-
"build": "npx npm-run-all clean -p compile compile-mjs-bin compile-cjs-bin",
|
|
23
|
+
"build": "npx npm-run-all clean -p compile compile-mjs-bin compile-cjs-bin -s types",
|
|
23
24
|
"clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
|
|
24
25
|
"compile": "npx esbuild index.ts --bundle --outdir=dist --platform=node --format=esm --external:esbuild",
|
|
25
26
|
"compile-mjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm --external:esbuild",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"prepublishOnly": "npm run build",
|
|
28
29
|
"preversion": "npx npm-run-all typecheck shape build",
|
|
29
30
|
"shape": "npx codeshape",
|
|
30
|
-
"typecheck": "tsc --noEmit"
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"types": "tsc --emitDeclarationOnly"
|
|
31
33
|
},
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"@types/node": "^24.5.2",
|
package/src/serve.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { mimeTypes } from "./mimeTypes.ts";
|
|
|
9
9
|
|
|
10
10
|
export type Server = ReturnType<typeof createServer>;
|
|
11
11
|
|
|
12
|
-
export async function serve(config: Config = {}) {
|
|
12
|
+
export async function serve(config: Config = {}): Promise<Server> {
|
|
13
13
|
let stop = await bundle(config);
|
|
14
14
|
|
|
15
15
|
return new Promise<Server>((resolve) => {
|