@t8/serve 0.1.17 → 0.1.19

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
@@ -4,20 +4,28 @@ import { createServer } from "node:http";
4
4
  import { extname } from "node:path";
5
5
 
6
6
  // src/bundle.ts
7
- import { exec as originalExec } from "node:child_process";
8
7
  import { rm } from "node:fs/promises";
9
8
  import { join } from "node:path";
10
- import { promisify } from "node:util";
11
- var exec = promisify(originalExec);
9
+ import { build } from "esbuild";
12
10
  async function bundle({ path = "", bundle: options } = {}) {
13
11
  if (!options) return;
14
- let normalizedOptions = typeof options === "boolean" ? {} : options;
12
+ let normalizedOptions;
13
+ if (typeof options === "boolean") normalizedOptions = {};
14
+ else if (typeof options === "string")
15
+ normalizedOptions = {
16
+ input: options
17
+ };
18
+ else normalizedOptions = options;
15
19
  let inputFile = join(path, normalizedOptions.input ?? "index.ts");
16
20
  let outputFile = join(path, "dist", normalizedOptions.output ?? "index.js");
17
21
  await rm(join(path, "dist"), { recursive: true, force: true });
18
- await exec(
19
- `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=browser --log-level=warning`
20
- );
22
+ await build({
23
+ entryPoints: [inputFile],
24
+ outfile: outputFile,
25
+ bundle: true,
26
+ platform: "browser",
27
+ logLevel: "warning"
28
+ });
21
29
  }
22
30
 
23
31
  // src/getFilePath.ts
package/dist/run.cjs CHANGED
@@ -7,20 +7,28 @@ var import_node_http = require("node:http");
7
7
  var import_node_path3 = require("node:path");
8
8
 
9
9
  // src/bundle.ts
10
- var import_node_child_process = require("node:child_process");
11
10
  var import_promises = require("node:fs/promises");
12
11
  var import_node_path = require("node:path");
13
- var import_node_util = require("node:util");
14
- var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
12
+ var import_esbuild = require("esbuild");
15
13
  async function bundle({ path = "", bundle: options } = {}) {
16
14
  if (!options) return;
17
- let normalizedOptions = typeof options === "boolean" ? {} : options;
15
+ let normalizedOptions;
16
+ if (typeof options === "boolean") normalizedOptions = {};
17
+ else if (typeof options === "string")
18
+ normalizedOptions = {
19
+ input: options
20
+ };
21
+ else normalizedOptions = options;
18
22
  let inputFile = (0, import_node_path.join)(path, normalizedOptions.input ?? "index.ts");
19
23
  let outputFile = (0, import_node_path.join)(path, "dist", normalizedOptions.output ?? "index.js");
20
24
  await (0, import_promises.rm)((0, import_node_path.join)(path, "dist"), { recursive: true, force: true });
21
- await exec(
22
- `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=browser --log-level=warning`
23
- );
25
+ await (0, import_esbuild.build)({
26
+ entryPoints: [inputFile],
27
+ outfile: outputFile,
28
+ bundle: true,
29
+ platform: "browser",
30
+ logLevel: "warning"
31
+ });
24
32
  }
25
33
 
26
34
  // src/getFilePath.ts
package/dist/run.mjs CHANGED
@@ -6,20 +6,28 @@ import { createServer } from "node:http";
6
6
  import { extname } from "node:path";
7
7
 
8
8
  // src/bundle.ts
9
- import { exec as originalExec } from "node:child_process";
10
9
  import { rm } from "node:fs/promises";
11
10
  import { join } from "node:path";
12
- import { promisify } from "node:util";
13
- var exec = promisify(originalExec);
11
+ import { build } from "esbuild";
14
12
  async function bundle({ path = "", bundle: options } = {}) {
15
13
  if (!options) return;
16
- let normalizedOptions = typeof options === "boolean" ? {} : options;
14
+ let normalizedOptions;
15
+ if (typeof options === "boolean") normalizedOptions = {};
16
+ else if (typeof options === "string")
17
+ normalizedOptions = {
18
+ input: options
19
+ };
20
+ else normalizedOptions = options;
17
21
  let inputFile = join(path, normalizedOptions.input ?? "index.ts");
18
22
  let outputFile = join(path, "dist", normalizedOptions.output ?? "index.js");
19
23
  await rm(join(path, "dist"), { recursive: true, force: true });
20
- await exec(
21
- `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=browser --log-level=warning`
22
- );
24
+ await build({
25
+ entryPoints: [inputFile],
26
+ outfile: outputFile,
27
+ bundle: true,
28
+ platform: "browser",
29
+ logLevel: "warning"
30
+ });
23
31
  }
24
32
 
25
33
  // src/getFilePath.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "node",
@@ -21,9 +21,9 @@
21
21
  "scripts": {
22
22
  "build": "npx npm-run-all clean -p compile compile-mjs-bin compile-cjs-bin",
23
23
  "clean": "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true});\"",
24
- "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=node --format=esm",
25
- "compile-mjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm",
26
- "compile-cjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.cjs --platform=node --format=cjs",
24
+ "compile": "npx esbuild index.ts --bundle --outdir=dist --platform=node --format=esm --external:esbuild",
25
+ "compile-mjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm --external:esbuild",
26
+ "compile-cjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.cjs --platform=node --format=cjs --external:esbuild",
27
27
  "prepublishOnly": "npm run build",
28
28
  "preversion": "npx npm-run-all typecheck shape build",
29
29
  "shape": "npx codeshape",
@@ -32,5 +32,8 @@
32
32
  "devDependencies": {
33
33
  "@types/node": "^24.5.2",
34
34
  "typescript": "^5.9.2"
35
+ },
36
+ "dependencies": {
37
+ "esbuild": "^0.25.10"
35
38
  }
36
39
  }
package/src/Config.ts CHANGED
@@ -8,5 +8,5 @@ export type Config = {
8
8
  dirs?: string[];
9
9
  spa?: boolean;
10
10
  log?: boolean;
11
- bundle?: boolean | BundleConfig;
11
+ bundle?: boolean | string | BundleConfig;
12
12
  };
package/src/bundle.ts CHANGED
@@ -1,23 +1,31 @@
1
- import { exec as originalExec } from "node:child_process";
2
1
  import { rm } from "node:fs/promises";
3
2
  import { join } from "node:path";
4
- import { promisify } from "node:util";
3
+ import { build } from "esbuild";
5
4
  import type { BundleConfig } from "./BundleConfig";
6
5
  import type { Config } from "./Config";
7
6
 
8
- const exec = promisify(originalExec);
9
-
10
7
  export async function bundle({ path = "", bundle: options }: Config = {}) {
11
8
  if (!options) return;
12
9
 
13
- let normalizedOptions: BundleConfig =
14
- typeof options === "boolean" ? {} : options;
10
+ let normalizedOptions: BundleConfig;
11
+
12
+ if (typeof options === "boolean") normalizedOptions = {};
13
+ else if (typeof options === "string")
14
+ normalizedOptions = {
15
+ input: options,
16
+ };
17
+ else normalizedOptions = options;
15
18
 
16
19
  let inputFile = join(path, normalizedOptions.input ?? "index.ts");
17
20
  let outputFile = join(path, "dist", normalizedOptions.output ?? "index.js");
18
21
 
19
22
  await rm(join(path, "dist"), { recursive: true, force: true });
20
- await exec(
21
- `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=browser --log-level=warning`,
22
- );
23
+
24
+ await build({
25
+ entryPoints: [inputFile],
26
+ outfile: outputFile,
27
+ bundle: true,
28
+ platform: "browser",
29
+ logLevel: "warning",
30
+ });
23
31
  }