@t8/serve 0.1.2 → 0.1.3

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.js CHANGED
@@ -38,7 +38,7 @@ async function isValidFilePath(filePath, dirPath) {
38
38
  if (!filePath.startsWith(dirPath)) return false;
39
39
  try {
40
40
  await (0, import_promises.access)(filePath);
41
- return true;
41
+ return !(await (0, import_promises.lstat)(filePath)).isDirectory();
42
42
  } catch {
43
43
  return false;
44
44
  }
@@ -46,15 +46,13 @@ async function isValidFilePath(filePath, dirPath) {
46
46
 
47
47
  // src/getFilePath.ts
48
48
  var cwd = process.cwd();
49
- async function getFilePath(urlPath = "", { path = "", dirs = [""] }) {
50
- for (let dir of dirs) {
49
+ async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
50
+ for (let dir of dirs.length === 0 ? [""] : dirs) {
51
51
  let dirPath = (0, import_node_path.join)(cwd, path, dir);
52
52
  let filePath = (0, import_node_path.join)(dirPath, urlPath);
53
53
  if (await isValidFilePath(filePath, dirPath)) return filePath;
54
- if (!/\.\w+$/.test(filePath)) {
55
- filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
56
- if (await isValidFilePath(filePath, dirPath)) return filePath;
57
- }
54
+ filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
55
+ if (await isValidFilePath(filePath, dirPath)) return filePath;
58
56
  }
59
57
  }
60
58
 
package/dist/run.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
 
4
4
  // src/run.ts
5
5
  var import_node_child_process = require("node:child_process");
6
+ var import_promises2 = require("node:fs/promises");
6
7
  var import_node_path3 = require("node:path");
7
8
  var import_node_util = require("node:util");
8
9
 
@@ -20,7 +21,7 @@ async function isValidFilePath(filePath, dirPath) {
20
21
  if (!filePath.startsWith(dirPath)) return false;
21
22
  try {
22
23
  await (0, import_promises.access)(filePath);
23
- return true;
24
+ return !(await (0, import_promises.lstat)(filePath)).isDirectory();
24
25
  } catch {
25
26
  return false;
26
27
  }
@@ -28,15 +29,13 @@ async function isValidFilePath(filePath, dirPath) {
28
29
 
29
30
  // src/getFilePath.ts
30
31
  var cwd = process.cwd();
31
- async function getFilePath(urlPath = "", { path = "", dirs = [""] }) {
32
- for (let dir of dirs) {
32
+ async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
33
+ for (let dir of dirs.length === 0 ? [""] : dirs) {
33
34
  let dirPath = (0, import_node_path.join)(cwd, path, dir);
34
35
  let filePath = (0, import_node_path.join)(dirPath, urlPath);
35
36
  if (await isValidFilePath(filePath, dirPath)) return filePath;
36
- if (!/\.\w+$/.test(filePath)) {
37
- filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
38
- if (await isValidFilePath(filePath, dirPath)) return filePath;
39
- }
37
+ filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
38
+ if (await isValidFilePath(filePath, dirPath)) return filePath;
40
39
  }
41
40
  }
42
41
 
@@ -91,6 +90,7 @@ async function run() {
91
90
  if (buildFlagIndex !== -1) {
92
91
  let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
93
92
  let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
93
+ await (0, import_promises2.rm)((0, import_node_path3.join)(path, "dist"), { recursive: true, force: true });
94
94
  await exec(
95
95
  `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`
96
96
  );
package/dist/run.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  // src/run.ts
4
4
  import { exec as originalExec } from "node:child_process";
5
+ import { rm } from "node:fs/promises";
5
6
  import { join as join2 } from "node:path";
6
7
  import { promisify } from "node:util";
7
8
 
@@ -14,12 +15,12 @@ import { extname } from "node:path";
14
15
  import { join } from "node:path";
15
16
 
16
17
  // src/isValidFilePath.ts
17
- import { access } from "node:fs/promises";
18
+ import { access, lstat } from "node:fs/promises";
18
19
  async function isValidFilePath(filePath, dirPath) {
19
20
  if (!filePath.startsWith(dirPath)) return false;
20
21
  try {
21
22
  await access(filePath);
22
- return true;
23
+ return !(await lstat(filePath)).isDirectory();
23
24
  } catch {
24
25
  return false;
25
26
  }
@@ -27,15 +28,13 @@ async function isValidFilePath(filePath, dirPath) {
27
28
 
28
29
  // src/getFilePath.ts
29
30
  var cwd = process.cwd();
30
- async function getFilePath(urlPath = "", { path = "", dirs = [""] }) {
31
- for (let dir of dirs) {
31
+ async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
32
+ for (let dir of dirs.length === 0 ? [""] : dirs) {
32
33
  let dirPath = join(cwd, path, dir);
33
34
  let filePath = join(dirPath, urlPath);
34
35
  if (await isValidFilePath(filePath, dirPath)) return filePath;
35
- if (!/\.\w+$/.test(filePath)) {
36
- filePath = join(dirPath, urlPath, "index.html");
37
- if (await isValidFilePath(filePath, dirPath)) return filePath;
38
- }
36
+ filePath = join(dirPath, urlPath, "index.html");
37
+ if (await isValidFilePath(filePath, dirPath)) return filePath;
39
38
  }
40
39
  }
41
40
 
@@ -90,6 +89,7 @@ async function run() {
90
89
  if (buildFlagIndex !== -1) {
91
90
  let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
92
91
  let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
92
+ await rm(join2(path, "dist"), { recursive: true, force: true });
93
93
  await exec(
94
94
  `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`
95
95
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "node",
@@ -6,18 +6,16 @@ const cwd = process.cwd();
6
6
 
7
7
  export async function getFilePath(
8
8
  urlPath: string = "",
9
- { path = "", dirs = [""] }: Config,
9
+ { path = "", dirs = [] }: Config,
10
10
  ) {
11
- for (let dir of dirs) {
11
+ for (let dir of dirs.length === 0 ? [""] : dirs) {
12
12
  let dirPath = join(cwd, path, dir);
13
13
  let filePath = join(dirPath, urlPath);
14
14
 
15
15
  if (await isValidFilePath(filePath, dirPath)) return filePath;
16
16
 
17
- if (!/\.\w+$/.test(filePath)) {
18
- filePath = join(dirPath, urlPath, "index.html");
17
+ filePath = join(dirPath, urlPath, "index.html");
19
18
 
20
- if (await isValidFilePath(filePath, dirPath)) return filePath;
21
- }
19
+ if (await isValidFilePath(filePath, dirPath)) return filePath;
22
20
  }
23
21
  }
@@ -1,11 +1,11 @@
1
- import { access } from "node:fs/promises";
1
+ import { access, lstat } from "node:fs/promises";
2
2
 
3
3
  export async function isValidFilePath(filePath: string, dirPath: string) {
4
4
  if (!filePath.startsWith(dirPath)) return false;
5
5
 
6
6
  try {
7
7
  await access(filePath);
8
- return true;
8
+ return !(await lstat(filePath)).isDirectory();
9
9
  } catch {
10
10
  return false;
11
11
  }
package/src/run.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { exec as originalExec } from "node:child_process";
3
+ import { rm } from "node:fs/promises";
3
4
  import { join } from "node:path";
4
5
  import { promisify } from "node:util";
5
6
  import { serve } from "./serve";
@@ -21,6 +22,7 @@ async function run() {
21
22
  let inputFile = join(path, args[buildFlagIndex + 1] ?? "index.ts");
22
23
  let outputFile = join(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
23
24
 
25
+ await rm(join(path, "dist"), { recursive: true, force: true });
24
26
  await exec(
25
27
  `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`,
26
28
  );