@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.
@@ -0,0 +1,3 @@
1
+ export * from "./src/BundleConfig.ts";
2
+ export * from "./src/Config.ts";
3
+ export * from "./src/serve.ts";
@@ -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,2 @@
1
+ import type { Config } from "./Config.ts";
2
+ export declare function bundle({ path, bundle: options, watch, minify, }?: Config): Promise<(() => Promise<void>) | undefined>;
@@ -0,0 +1,2 @@
1
+ import type { Config } from "./Config.ts";
2
+ export declare function getFilePath(url: string | undefined, { path, dirs, spa }: Config): Promise<string | undefined>;
@@ -0,0 +1,5 @@
1
+ import type { Config } from "./Config.ts";
2
+ export declare function getTarget(config?: Config): {
3
+ port: number;
4
+ host: string;
5
+ };
@@ -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>;
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,4 @@
1
+ import { createServer } from "node:http";
2
+ import type { Config } from "./Config.ts";
3
+ export type Server = ReturnType<typeof createServer>;
4
+ export declare function serve(config?: Config): Promise<Server>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.34",
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) => {
package/tsconfig.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "include": ["index.ts", "src"],
3
3
  "compilerOptions": {
4
- "noEmit": true,
4
+ "declaration": true,
5
+ "emitDeclarationOnly": true,
5
6
  "lib": ["ESNext", "DOM", "DOM.Iterable"],
6
7
  "target": "esnext",
7
8
  "outDir": "dist",