@t8/serve 0.1.20 → 0.1.21

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 CHANGED
@@ -1,6 +1,10 @@
1
1
  # @t8/serve
2
2
 
3
- Simple static file server + bundler, primarily for tests, manual or automated
3
+ Simple static file server + bundler, primarily for demo apps and tests, manual or automated
4
+
5
+ Use cases:
6
+ - Use the CLI-based server to launch a demo or test app with a single CLI command.
7
+ - Use the code-based setup to launch an own server from multiple tests, each with its own app.
4
8
 
5
9
  ## CLI
6
10
 
@@ -19,7 +23,7 @@ npx @t8/serve 3000 app public dist -b src/index.ts
19
23
  ```
20
24
 
21
25
  <details>
22
- <summary>Example</summary>
26
+ <summary>Example 1 (flat)</summary>
23
27
 
24
28
  ```
25
29
  // package.json
@@ -32,7 +36,8 @@ npx @t8/serve 3000 app public dist -b src/index.ts
32
36
  /playground
33
37
  - index.css
34
38
  - index.html
35
- + <script src="/dist/index.js"></script>
39
+ contains <script src="/dist/index.js"></script>
40
+ contains <link rel="stylesheet" href="/index.css"></script>
36
41
  - index.ts
37
42
  ```
38
43
 
@@ -54,6 +59,46 @@ webServer: {
54
59
 
55
60
  </details>
56
61
 
62
+ <details>
63
+ <summary>Example 2 (nested)</summary>
64
+
65
+ ```
66
+ // package.json
67
+ "scripts": {
68
+ "play": "npx @t8/serve 3000 * playground -b src/index.tsx"
69
+ }
70
+ ```
71
+
72
+ ```
73
+ /playground
74
+ src
75
+ - App.tsx
76
+ - index.css
77
+ - index.tsx // imports "./App.tsx", "./index.css"
78
+ - index.html
79
+ contains <script src="/dist/index.js"></script>
80
+ contains <link rel="stylesheet" href="/dist/index.css"></script>
81
+ ```
82
+
83
+ ```sh
84
+ npm run play
85
+ ```
86
+
87
+ ```
88
+ // With Playwright:
89
+ // playwright.config.ts
90
+ ...
91
+ use: {
92
+ baseURL: "http://localhost:3000",
93
+ },
94
+ webServer: {
95
+ command: "npm run play",
96
+ url: "http://localhost:3000",
97
+ },
98
+ ```
99
+
100
+ </details>
101
+
57
102
  ## Code
58
103
 
59
104
  ```ts
@@ -63,7 +108,7 @@ import { serve } from "@t8/serve";
63
108
  let server = await serve({
64
109
  port: 3000,
65
110
  path: "app",
66
- bundle: true, // or `{ input, output }`, or `input` path
111
+ bundle: true, // or input path, or `{ input, output, dir }`
67
112
  spa: true,
68
113
  });
69
114
 
@@ -72,26 +117,64 @@ server.close();
72
117
  ```
73
118
 
74
119
  <details>
75
- <summary>Example</summary>
120
+ <summary>Example 1 (flat)</summary>
76
121
 
77
122
  ```
78
123
  /playground
79
124
  - index.css
80
125
  - index.html
81
- + <script src="/dist/index.js"></script>
126
+ contains <script src="/dist/index.js"></script>
127
+ contains <link rel="stylesheet" href="/index.css"></script>
82
128
  - index.ts
83
129
  ```
84
130
 
85
131
  ```ts
86
132
  // x.test.ts
87
133
  import { test } from "@playwright/test";
88
- import { serve, type Server } from "@t8/serve";
134
+ import { type Server, serve } from "@t8/serve";
89
135
 
90
136
  let server: Server;
91
137
 
92
138
  test.beforeAll(async () => {
93
139
  server = await serve({
94
140
  path: "playground",
141
+ bundle: true,
142
+ spa: true,
143
+ });
144
+ });
145
+
146
+ test.afterAll(() => {
147
+ server.close();
148
+ });
149
+ ```
150
+
151
+ </details>
152
+
153
+ <details>
154
+ <summary>Example 2 (nested)</summary>
155
+
156
+ ```
157
+ /tests/x
158
+ src
159
+ - index.css
160
+ - index.tsx // imports "./App.tsx", "./index.css"
161
+ - index.html
162
+ contains <script src="/dist/index.js"></script>
163
+ contains <link rel="stylesheet" href="/dist/index.css"></script>
164
+ - index.ts
165
+ - index.test.ts
166
+ ```
167
+
168
+ ```ts
169
+ // tests/x/index.test.ts
170
+ import { test } from "@playwright/test";
171
+ import { serve, type Server } from "@t8/serve";
172
+
173
+ let server: Server;
174
+
175
+ test.beforeAll(async () => {
176
+ server = await serve({
177
+ path: "tests/x",
95
178
  bundle: "src/index.tsx",
96
179
  spa: true,
97
180
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.20",
4
- "description": "",
3
+ "version": "0.1.21",
4
+ "description": "Simple static file server + bundler, primarily for demo apps and tests, manual or automated",
5
5
  "keywords": [
6
6
  "node",
7
7
  "server",
@@ -20,7 +20,7 @@
20
20
  "main": "dist/index.js",
21
21
  "scripts": {
22
22
  "build": "npx npm-run-all clean -p compile compile-mjs-bin compile-cjs-bin",
23
- "clean": "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true});\"",
23
+ "clean": "node -e \"require('node:fs').rmSync('dist', { force: true, recursive: true });\"",
24
24
  "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=node --format=esm --external:esbuild",
25
25
  "compile-mjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm --external:esbuild",
26
26
  "compile-cjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.cjs --platform=node --format=cjs --external:esbuild",
@@ -1,6 +1,7 @@
1
1
  import { access, lstat } from "node:fs/promises";
2
2
 
3
3
  export async function isValidFilePath(filePath: string, dirPath: string) {
4
+ // Disallow path traversal outside `dirPath`
4
5
  if (!filePath.startsWith(dirPath)) return false;
5
6
 
6
7
  try {