@await-widget/runtime 0.0.22 → 0.0.24

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.
@@ -23,6 +23,10 @@ function main() {
23
23
  function startDevServer(args) {
24
24
  const options = parseDevArgs(args);
25
25
  const root = path.resolve(options.root);
26
+ if (!isSubdirectory(root)) {
27
+ printHelp();
28
+ process.exit(1);
29
+ }
26
30
  const stats = fs.statSync(root);
27
31
  if (!stats.isDirectory()) {
28
32
  throw new Error(`${root} is not a directory`);
@@ -42,7 +46,7 @@ function startDevServer(args) {
42
46
  }
43
47
 
44
48
  function parseDevArgs(args) {
45
- let root = ".";
49
+ let root;
46
50
  let port = defaultPort;
47
51
  for (let index = 0; index < args.length; index += 1) {
48
52
  const arg = args[index];
@@ -57,9 +61,18 @@ function parseDevArgs(args) {
57
61
  }
58
62
  root = arg;
59
63
  }
64
+ if (!root) {
65
+ printHelp();
66
+ process.exit(1);
67
+ }
60
68
  return {root, port};
61
69
  }
62
70
 
71
+ function isSubdirectory(root) {
72
+ const relativePath = path.relative(process.cwd(), root);
73
+ return relativePath !== "" && !relativePath.startsWith("..") && !path.isAbsolute(relativePath);
74
+ }
75
+
63
76
  function handleRequest({request, response, root, token}) {
64
77
  const url = new URL(request.url ?? "/", "http://localhost");
65
78
  if (url.pathname === "/") {
@@ -297,7 +310,12 @@ function urlForRequest(request, token) {
297
310
 
298
311
  function printHelp() {
299
312
  console.log(`Usage:
300
- await-widget dev [directory] [--port ${defaultPort}]
313
+ await-widget dev <widget-directory> [--port ${defaultPort}]
314
+
315
+ Example:
316
+ await-widget dev YourWidget
317
+
318
+ Pass a widget subdirectory, not the current package directory.
301
319
  `);
302
320
  }
303
321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@await-widget/runtime",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "TypeScript declarations for Await widgets.",
5
5
  "license": "MIT",
6
6
  "author": "LitoMore",