sable 0.5.15 → 0.5.16

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/cjs/cli.cjs ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
+ // If the importer is in node compatibility mode or this is not an ESM
19
+ // file that has been converted to a CommonJS file using a Babel-
20
+ // compatible transform (i.e. "__esModule" has not been set), then set
21
+ // "default" to the CommonJS "module.exports" for node compatibility.
22
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
+ mod
24
+ ));
25
+
26
+ // src/cli.ts
27
+ var import_node_fs = require("node:fs");
28
+ var import_node_path = require("node:path");
29
+ var import_commander = require("commander");
30
+ var import_middleware_static_livereload2 = require("middleware-static-livereload");
31
+
32
+ // src/index.ts
33
+ var http = __toESM(require("node:http"), 1);
34
+ var import_connect = __toESM(require("connect"), 1);
35
+ var staticLivereload = __toESM(require("middleware-static-livereload"), 1);
36
+ var import_middleware_static_livereload = require("middleware-static-livereload");
37
+ var startServer = async (options2 = {}) => {
38
+ const app = (0, import_connect.default)();
39
+ for (const middleware2 of options2.middlewares || []) {
40
+ app.use(middleware2);
41
+ }
42
+ app.use(staticLivereload.middleware(options2));
43
+ const server = http.createServer(app);
44
+ return await new Promise((resolve, reject) => {
45
+ server.once("listening", () => {
46
+ const addressInfo = server.address();
47
+ if (addressInfo && typeof addressInfo === "object") {
48
+ const { address, family, port: port2 } = addressInfo;
49
+ const portSuffix = port2 === 80 ? "" : `:${port2}`;
50
+ const hostname = options2.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
51
+ process.stdout.write(`http://${hostname}${portSuffix}
52
+ `);
53
+ }
54
+ resolve(server);
55
+ });
56
+ const listen = (port2, host2) => {
57
+ server.once("error", (error) => {
58
+ if (error.code === "EADDRINUSE") {
59
+ listen(port2 + 1, host2);
60
+ } else {
61
+ reject(error);
62
+ }
63
+ });
64
+ server.listen(port2, host2);
65
+ };
66
+ listen(options2.port || 4e3, options2.host);
67
+ });
68
+ };
69
+
70
+ // src/cli.ts
71
+ var import_meta = {};
72
+ var packageJsonPath = typeof __dirname !== "undefined" ? (0, import_node_path.join)(__dirname, "../package.json") : typeof import_meta !== "undefined" ? new URL("../package.json", import_meta.url) : void 0;
73
+ if (!packageJsonPath) {
74
+ throw new Error("Unable to resolve path to package.json");
75
+ }
76
+ var { version } = JSON.parse((0, import_node_fs.readFileSync)(packageJsonPath, "utf8"));
77
+ var program = new import_commander.Command().version(version).description("Starts a HTTP server for development").option(
78
+ "-p, --port <n>",
79
+ "A port number for HTTP, HTTPS (4000)",
80
+ Number.parseInt
81
+ ).option("-h, --host <s>", "Hostname").option("-v, --verbose", "Enable verbose logging").option("--noWatch", "Disable watching").option("-i, --index <s>", "A filename of index (index.html)").argument("[documentRoot...]", "Paths to serve");
82
+ program.parse();
83
+ var {
84
+ noWatch,
85
+ port,
86
+ host,
87
+ verbose = false,
88
+ index
89
+ } = program.opts();
90
+ var documentRoot = program.args;
91
+ if (documentRoot.length === 0) {
92
+ documentRoot.push(process.cwd());
93
+ }
94
+ var options = {
95
+ watch: !noWatch,
96
+ documentRoot,
97
+ logLevel: verbose ? import_middleware_static_livereload2.LogLevel.debug : import_middleware_static_livereload2.LogLevel.info
98
+ };
99
+ if (Array.isArray(port)) {
100
+ options.port = port[0];
101
+ } else if (port) {
102
+ options.port = port;
103
+ }
104
+ if (Array.isArray(host)) {
105
+ options.host = host[0];
106
+ } else if (host) {
107
+ options.host = host;
108
+ }
109
+ if (Array.isArray(index)) {
110
+ options.index = index[0];
111
+ } else if (index) {
112
+ options.index = index;
113
+ }
114
+ startServer(options).catch((error) => {
115
+ console.error(error);
116
+ process.exit(1);
117
+ });
package/cjs/index.cjs ADDED
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ LogLevel: () => import_middleware_static_livereload.LogLevel,
34
+ startServer: () => startServer
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+ var http = __toESM(require("node:http"), 1);
38
+ var import_connect = __toESM(require("connect"), 1);
39
+ var staticLivereload = __toESM(require("middleware-static-livereload"), 1);
40
+ var import_middleware_static_livereload = require("middleware-static-livereload");
41
+ var startServer = async (options = {}) => {
42
+ const app = (0, import_connect.default)();
43
+ for (const middleware2 of options.middlewares || []) {
44
+ app.use(middleware2);
45
+ }
46
+ app.use(staticLivereload.middleware(options));
47
+ const server = http.createServer(app);
48
+ return await new Promise((resolve, reject) => {
49
+ server.once("listening", () => {
50
+ const addressInfo = server.address();
51
+ if (addressInfo && typeof addressInfo === "object") {
52
+ const { address, family, port } = addressInfo;
53
+ const portSuffix = port === 80 ? "" : `:${port}`;
54
+ const hostname = options.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
55
+ process.stdout.write(`http://${hostname}${portSuffix}
56
+ `);
57
+ }
58
+ resolve(server);
59
+ });
60
+ const listen = (port, host) => {
61
+ server.once("error", (error) => {
62
+ if (error.code === "EADDRINUSE") {
63
+ listen(port + 1, host);
64
+ } else {
65
+ reject(error);
66
+ }
67
+ });
68
+ server.listen(port, host);
69
+ };
70
+ listen(options.port || 4e3, options.host);
71
+ });
72
+ };
package/esm/cli.mjs ADDED
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { readFileSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { Command } from "commander";
7
+ import { LogLevel as LogLevel2 } from "middleware-static-livereload";
8
+
9
+ // src/index.ts
10
+ import * as http from "node:http";
11
+ import connect from "connect";
12
+ import * as staticLivereload from "middleware-static-livereload";
13
+ import { LogLevel } from "middleware-static-livereload";
14
+ var startServer = async (options2 = {}) => {
15
+ const app = connect();
16
+ for (const middleware2 of options2.middlewares || []) {
17
+ app.use(middleware2);
18
+ }
19
+ app.use(staticLivereload.middleware(options2));
20
+ const server = http.createServer(app);
21
+ return await new Promise((resolve, reject) => {
22
+ server.once("listening", () => {
23
+ const addressInfo = server.address();
24
+ if (addressInfo && typeof addressInfo === "object") {
25
+ const { address, family, port: port2 } = addressInfo;
26
+ const portSuffix = port2 === 80 ? "" : `:${port2}`;
27
+ const hostname = options2.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
28
+ process.stdout.write(`http://${hostname}${portSuffix}
29
+ `);
30
+ }
31
+ resolve(server);
32
+ });
33
+ const listen = (port2, host2) => {
34
+ server.once("error", (error) => {
35
+ if (error.code === "EADDRINUSE") {
36
+ listen(port2 + 1, host2);
37
+ } else {
38
+ reject(error);
39
+ }
40
+ });
41
+ server.listen(port2, host2);
42
+ };
43
+ listen(options2.port || 4e3, options2.host);
44
+ });
45
+ };
46
+
47
+ // src/cli.ts
48
+ var packageJsonPath = typeof __dirname !== "undefined" ? join(__dirname, "../package.json") : typeof import.meta !== "undefined" ? new URL("../package.json", import.meta.url) : void 0;
49
+ if (!packageJsonPath) {
50
+ throw new Error("Unable to resolve path to package.json");
51
+ }
52
+ var { version } = JSON.parse(readFileSync(packageJsonPath, "utf8"));
53
+ var program = new Command().version(version).description("Starts a HTTP server for development").option(
54
+ "-p, --port <n>",
55
+ "A port number for HTTP, HTTPS (4000)",
56
+ Number.parseInt
57
+ ).option("-h, --host <s>", "Hostname").option("-v, --verbose", "Enable verbose logging").option("--noWatch", "Disable watching").option("-i, --index <s>", "A filename of index (index.html)").argument("[documentRoot...]", "Paths to serve");
58
+ program.parse();
59
+ var {
60
+ noWatch,
61
+ port,
62
+ host,
63
+ verbose = false,
64
+ index
65
+ } = program.opts();
66
+ var documentRoot = program.args;
67
+ if (documentRoot.length === 0) {
68
+ documentRoot.push(process.cwd());
69
+ }
70
+ var options = {
71
+ watch: !noWatch,
72
+ documentRoot,
73
+ logLevel: verbose ? LogLevel2.debug : LogLevel2.info
74
+ };
75
+ if (Array.isArray(port)) {
76
+ options.port = port[0];
77
+ } else if (port) {
78
+ options.port = port;
79
+ }
80
+ if (Array.isArray(host)) {
81
+ options.host = host[0];
82
+ } else if (host) {
83
+ options.host = host;
84
+ }
85
+ if (Array.isArray(index)) {
86
+ options.index = index[0];
87
+ } else if (index) {
88
+ options.index = index;
89
+ }
90
+ startServer(options).catch((error) => {
91
+ console.error(error);
92
+ process.exit(1);
93
+ });
package/esm/index.mjs ADDED
@@ -0,0 +1,41 @@
1
+ // src/index.ts
2
+ import * as http from "node:http";
3
+ import connect from "connect";
4
+ import * as staticLivereload from "middleware-static-livereload";
5
+ import { LogLevel } from "middleware-static-livereload";
6
+ var startServer = async (options = {}) => {
7
+ const app = connect();
8
+ for (const middleware2 of options.middlewares || []) {
9
+ app.use(middleware2);
10
+ }
11
+ app.use(staticLivereload.middleware(options));
12
+ const server = http.createServer(app);
13
+ return await new Promise((resolve, reject) => {
14
+ server.once("listening", () => {
15
+ const addressInfo = server.address();
16
+ if (addressInfo && typeof addressInfo === "object") {
17
+ const { address, family, port } = addressInfo;
18
+ const portSuffix = port === 80 ? "" : `:${port}`;
19
+ const hostname = options.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
20
+ process.stdout.write(`http://${hostname}${portSuffix}
21
+ `);
22
+ }
23
+ resolve(server);
24
+ });
25
+ const listen = (port, host) => {
26
+ server.once("error", (error) => {
27
+ if (error.code === "EADDRINUSE") {
28
+ listen(port + 1, host);
29
+ } else {
30
+ reject(error);
31
+ }
32
+ });
33
+ server.listen(port, host);
34
+ };
35
+ listen(options.port || 4e3, options.host);
36
+ });
37
+ };
38
+ export {
39
+ LogLevel,
40
+ startServer
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sable",
3
- "version": "0.5.15",
3
+ "version": "0.5.16",
4
4
  "description": "Starts a server and a file watcher",
5
5
  "author": {
6
6
  "name": "Kei Ito",
@@ -12,27 +12,36 @@
12
12
  "node": ">=14"
13
13
  },
14
14
  "repository": "https://github.com/gjbkz/sable",
15
- "type": "commonjs",
16
- "main": "./lib/index.js",
15
+ "type": "module",
16
+ "main": "./esm/index.mjs",
17
17
  "bin": {
18
- "sable": "./lib/cli.js"
18
+ "sable": "./esm/cli.mjs"
19
+ },
20
+ "exports": {
21
+ ".": {
22
+ "types": "./types/index.d.ts",
23
+ "import": "./esm/index.mjs",
24
+ "require": "./cjs/index.cjs"
25
+ }
19
26
  },
20
27
  "files": [
21
- "lib"
28
+ "esm",
29
+ "cjs",
30
+ "types"
22
31
  ],
23
32
  "scripts": {
24
33
  "lint": "npx @biomejs/biome lint",
25
34
  "build": "run-s build:*",
26
- "build:tsc": "tsc",
27
- "build:chmod": "chmod +x lib/cli.js",
35
+ "build:typedef": "tsc --project tsconfig.typedef.json",
36
+ "build:code": "node build.ts",
28
37
  "test": "node --test test/index.mjs",
29
38
  "version": "run-s version:changelog version:add",
30
- "version:changelog": "nlib-changelog --output CHANGELOG.md",
39
+ "version:changelog": "npx @nlib/changelog --output CHANGELOG.md",
31
40
  "version:add": "git add ."
32
41
  },
33
42
  "dependencies": {
34
- "commander": "12.1.0",
43
+ "commander": "14.0.1",
35
44
  "connect": "3.7.0",
36
- "middleware-static-livereload": "1.3.0"
45
+ "middleware-static-livereload": "1.4.3"
37
46
  }
38
47
  }
@@ -1,10 +1,10 @@
1
- import * as http from "http";
2
- import type * as Connect from "connect";
1
+ import * as http from "node:http";
2
+ import { type HandleFunction } from "connect";
3
3
  import * as staticLivereload from "middleware-static-livereload";
4
4
  export { LogLevel } from "middleware-static-livereload";
5
5
  export interface SableOptions extends Partial<staticLivereload.MiddlewareOptions> {
6
6
  port?: number;
7
7
  host?: string;
8
- middlewares?: Array<Connect.HandleFunction>;
8
+ middlewares?: Array<HandleFunction>;
9
9
  }
10
10
  export declare const startServer: (options?: SableOptions) => Promise<http.Server>;
package/lib/cli.js DELETED
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const commander_1 = require("commander");
5
- const middleware_static_livereload_1 = require("middleware-static-livereload");
6
- const index_1 = require("./index");
7
- const { version } = require("../package.json");
8
- const program = new commander_1.Command()
9
- .version(version)
10
- .description("Starts a HTTP server for development")
11
- .usage("[options] <documentRoot ...>")
12
- .option("-p, --port <n>", "A port number for HTTP, HTTPS (4000)", Number.parseInt)
13
- .option("-h, --host <s>", "Hostname")
14
- .option("-v, --verbose", "Enable verbose logging")
15
- .option("--noWatch", "Disable watching")
16
- .option("-i, --index <s>", "A filename of index (index.html)")
17
- .action(async ({ noWatch, port, host, verbose = false, index, }, { args: documentRoot }) => {
18
- if (documentRoot.length === 0) {
19
- documentRoot.push(process.cwd());
20
- }
21
- const options = {
22
- watch: !noWatch,
23
- documentRoot,
24
- logLevel: verbose ? middleware_static_livereload_1.LogLevel.debug : middleware_static_livereload_1.LogLevel.info,
25
- };
26
- if (Array.isArray(port)) {
27
- options.port = port[0];
28
- }
29
- else if (port) {
30
- options.port = port;
31
- }
32
- if (Array.isArray(host)) {
33
- options.host = host[0];
34
- }
35
- else if (host) {
36
- options.host = host;
37
- }
38
- if (Array.isArray(index)) {
39
- options.index = index[0];
40
- }
41
- else if (index) {
42
- options.index = index;
43
- }
44
- await (0, index_1.startServer)(options);
45
- });
46
- program.parse();
package/lib/index.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startServer = exports.LogLevel = void 0;
4
- const http = require("http");
5
- const staticLivereload = require("middleware-static-livereload");
6
- var middleware_static_livereload_1 = require("middleware-static-livereload");
7
- Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return middleware_static_livereload_1.LogLevel; } });
8
- const startServer = async (options = {}) => {
9
- const app = require("connect")();
10
- for (const middleware of options.middlewares || []) {
11
- app.use(middleware);
12
- }
13
- app.use(staticLivereload.middleware(options));
14
- const server = http.createServer(app);
15
- return await new Promise((resolve, reject) => {
16
- server.once("listening", () => {
17
- const addressInfo = server.address();
18
- if (addressInfo && typeof addressInfo === "object") {
19
- const { address, family, port } = addressInfo;
20
- const portSuffix = port === 80 ? "" : `:${port}`;
21
- const hostname = options.host ||
22
- (portSuffix && family === "IPv6" ? `[${address}]` : address);
23
- process.stdout.write(`http://${hostname}${portSuffix}\n`);
24
- }
25
- resolve(server);
26
- });
27
- const listen = (port, host) => {
28
- server.once("error", (error) => {
29
- if (error.code === "EADDRINUSE") {
30
- listen(port + 1, host);
31
- }
32
- else {
33
- reject(error);
34
- }
35
- });
36
- server.listen(port, host);
37
- };
38
- listen(options.port || 4000, options.host);
39
- });
40
- };
41
- exports.startServer = startServer;
File without changes