@mryhryki/markdown-preview 0.6.2 → 0.7.1

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mryhryki/markdown-preview",
3
3
  "description": "Markdown realtime preview on browser with your favorite editor",
4
- "version": "0.6.2",
4
+ "version": "0.7.1",
5
5
  "author": "mryhryki",
6
6
  "license": "MIT",
7
7
  "publishConfig": {
@@ -32,8 +32,8 @@
32
32
  "build:server": "tsc",
33
33
  "build:css": "cp ./node_modules/github-markdown-css/github-markdown.css ./static/github-markdown.css && cp ./node_modules/highlight.js/styles/github.css ./static/highlightjs-github.css",
34
34
  "build:js": "esbuild --bundle --platform=browser --format=esm --outfile=./static/convert-markdown.js ./script/convert-markdown.ts",
35
- "fmt": "prettier --write ./src/**/*.ts ./**/*.html && eslint ./src/**/*.ts --fix",
36
- "lint": "prettier --check ./src/**/*.ts ./**/*.html && eslint ./src/**/*.ts",
35
+ "fmt": "biome check --write ./src/**/*.ts ./**/*.html",
36
+ "lint": "biome check ./src/**/*.ts ./**/*.html",
37
37
  "release": "npm run build && npm publish",
38
38
  "start": "npm run build && node ./index.js",
39
39
  "test": "jest",
@@ -47,35 +47,27 @@
47
47
  "log4js": "^6.9.1",
48
48
  "opener": "^1.5.2",
49
49
  "serve-index": "^1.9.1",
50
- "ws": "^8.17.0"
50
+ "ws": "^8.18.0"
51
51
  },
52
52
  "devDependencies": {
53
+ "@biomejs/biome": "1.8.3",
53
54
  "@types/express": "^4.17.21",
54
55
  "@types/express-ws": "^3.0.4",
55
56
  "@types/jest": "^29.5.12",
56
57
  "@types/opener": "^1.4.3",
57
58
  "@types/serve-index": "^1.9.4",
58
59
  "emojilib": "^3.0.12",
59
- "esbuild": "^0.21.3",
60
- "eslint": "^8.57.0",
61
- "eslint-config-prettier": "^9.1.0",
62
- "eslint-plugin-jest": "^28.5.0",
63
- "eslint-plugin-node": "^11.1.0",
64
- "eslint-plugin-prettier": "^5.1.3",
65
- "eslint-plugin-react": "^7.34.1",
66
- "eslint-plugin-react-hooks": "^4.6.2",
67
- "eslint-plugin-simple-import-sort": "^12.1.0",
68
- "eslint-plugin-unused-imports": "^3.2.0",
69
- "github-markdown-css": "^5.5.1",
70
- "highlight.js": "^11.9.0",
60
+ "esbuild": "^0.23.1",
61
+ "github-markdown-css": "^5.6.1",
62
+ "highlight.js": "^11.10.0",
71
63
  "jest": "^29.7.0",
72
- "marked": "^12.0.2",
73
- "marked-emoji": "^1.4.0",
74
- "marked-highlight": "^2.1.1",
64
+ "marked": "^14.0.0",
65
+ "marked-emoji": "^1.4.2",
66
+ "marked-highlight": "^2.1.4",
75
67
  "mermaid": "^10.9.1",
76
- "nodemon": "^3.1.0",
77
- "ts-jest": "^29.1.2",
78
- "typescript": "^5.4.5"
68
+ "nodemon": "^3.1.4",
69
+ "ts-jest": "^29.2.4",
70
+ "typescript": "^5.5.4"
79
71
  },
80
72
  "files": [
81
73
  "index.js",
@@ -83,9 +75,6 @@
83
75
  "static/**/*",
84
76
  "template/**/*"
85
77
  ],
86
- "prettier": {
87
- "printWidth": 120
88
- },
89
78
  "jest": {
90
79
  "preset": "ts-jest",
91
80
  "testEnvironment": "node"
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.templateDir = exports.staticDir = exports.projectDir = exports.rootDir = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  exports.rootDir = process.cwd();
9
- exports.projectDir = path_1.default.resolve(__dirname, "..", "..");
10
- exports.staticDir = path_1.default.resolve(exports.projectDir, "static");
11
- exports.templateDir = path_1.default.resolve(exports.projectDir, "template");
9
+ exports.projectDir = node_path_1.default.resolve(__dirname, "..", "..");
10
+ exports.staticDir = node_path_1.default.resolve(exports.projectDir, "static");
11
+ exports.templateDir = node_path_1.default.resolve(exports.projectDir, "template");
package/src/lib/file.js CHANGED
@@ -3,15 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.existsFile = void 0;
7
- const fs_1 = __importDefault(require("fs"));
6
+ exports.existsFile = existsFile;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
8
  function existsFile(filepath) {
9
9
  try {
10
- fs_1.default.statSync(filepath);
10
+ node_fs_1.default.statSync(filepath);
11
11
  return true;
12
12
  }
13
13
  catch (_) {
14
14
  return false;
15
15
  }
16
16
  }
17
- exports.existsFile = existsFile;
@@ -4,20 +4,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FileWatcher = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
9
  const directory_1 = require("./directory");
10
10
  class FileWatcher {
11
11
  constructor(logger) {
12
12
  this.logger = logger;
13
13
  this._target = {};
14
14
  setInterval(() => {
15
- Object.keys(this._target).forEach((filepath) => {
15
+ for (const filepath in this._target) {
16
16
  try {
17
17
  const fileinfo = this._target[filepath];
18
18
  const currentLastModified = this.getFileLastModified(filepath);
19
19
  if (fileinfo.lastModified !== currentLastModified) {
20
- this.logger.info("File update:", path_1.default.resolve(directory_1.rootDir, filepath));
20
+ this.logger.info("File update:", node_path_1.default.resolve(directory_1.rootDir, filepath));
21
21
  fileinfo.lastModified = currentLastModified;
22
22
  if (this._onFileChanged != null) {
23
23
  this._onFileChanged(this.getFileInfo(filepath));
@@ -27,7 +27,7 @@ class FileWatcher {
27
27
  catch (err) {
28
28
  console.error(err);
29
29
  }
30
- });
30
+ }
31
31
  }, 250 /* check 4 times per second */);
32
32
  }
33
33
  onFileChanged(callback) {
@@ -48,11 +48,11 @@ class FileWatcher {
48
48
  delete this._target[filepath];
49
49
  }
50
50
  getFileLastModified(filepath) {
51
- return fs_1.default.statSync(path_1.default.resolve(directory_1.rootDir, filepath)).mtimeMs;
51
+ return node_fs_1.default.statSync(node_path_1.default.resolve(directory_1.rootDir, filepath)).mtimeMs;
52
52
  }
53
53
  getFileInfo(filepath) {
54
- const absolutePath = path_1.default.resolve(directory_1.rootDir, filepath);
55
- const markdown = fs_1.default.readFileSync(absolutePath, "utf-8");
54
+ const absolutePath = node_path_1.default.resolve(directory_1.rootDir, filepath);
55
+ const markdown = node_fs_1.default.readFileSync(absolutePath, "utf-8");
56
56
  return { filepath, markdown };
57
57
  }
58
58
  }
package/src/lib/logger.js CHANGED
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getLogger = exports.getLogLevel = void 0;
6
+ exports.getLogLevel = getLogLevel;
7
+ exports.getLogger = getLogger;
7
8
  const log4js_1 = __importDefault(require("log4js"));
8
9
  const LogLevels = ["trace", "debug", "info", "warn", "error", "fatal"];
9
10
  function getLogLevel(level) {
@@ -19,7 +20,6 @@ function getLogLevel(level) {
19
20
  throw new Error(`Undefined log level: ${level}`);
20
21
  }
21
22
  }
22
- exports.getLogLevel = getLogLevel;
23
23
  function getLogger(logLevel) {
24
24
  log4js_1.default.configure({
25
25
  appenders: {
@@ -39,4 +39,3 @@ function getLogger(logLevel) {
39
39
  });
40
40
  return log4js_1.default.getLogger();
41
41
  }
42
- exports.getLogger = getLogger;
package/src/lib/params.js CHANGED
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Params = void 0;
7
- const path_1 = __importDefault(require("path"));
7
+ const node_path_1 = __importDefault(require("node:path"));
8
8
  const directory_1 = require("./directory");
9
9
  const file_1 = require("./file");
10
10
  const logger_1 = require("./logger");
@@ -46,7 +46,7 @@ class Params {
46
46
  params.template = env.MARKDOWN_PREVIEW_TEMPLATE;
47
47
  }
48
48
  if (env.MARKDOWN_PREVIEW_PORT) {
49
- params.port = parseInt(env.MARKDOWN_PREVIEW_PORT, 10);
49
+ params.port = Number.parseInt(env.MARKDOWN_PREVIEW_PORT, 10);
50
50
  }
51
51
  if (env.MARKDOWN_PREVIEW_NO_OPENER) {
52
52
  params.noOpener = env.MARKDOWN_PREVIEW_NO_OPENER === "true";
@@ -77,7 +77,7 @@ class Params {
77
77
  break;
78
78
  case "-p":
79
79
  case "--port":
80
- params.port = parseInt(argv[i + 1], 10);
80
+ params.port = Number.parseInt(argv[i + 1], 10);
81
81
  i++;
82
82
  break;
83
83
  case "-l":
@@ -103,13 +103,13 @@ class Params {
103
103
  return params;
104
104
  }
105
105
  checkFilepath(filepath) {
106
- if (path_1.default.isAbsolute(filepath)) {
106
+ if (node_path_1.default.isAbsolute(filepath)) {
107
107
  throw new Error(`Absolute path is prohibited: ${filepath}`);
108
108
  }
109
109
  if (!(0, file_1.existsFile)(filepath)) {
110
110
  throw new Error(`File not found: ${filepath}`);
111
111
  }
112
- if (path_1.default.relative(directory_1.rootDir, filepath).match(/\.\./) != null) {
112
+ if (node_path_1.default.relative(directory_1.rootDir, filepath).match(/\.\./) != null) {
113
113
  throw new Error(`Illegal file path: ${filepath}`);
114
114
  }
115
115
  return filepath;
@@ -122,16 +122,16 @@ class Params {
122
122
  return extensionList;
123
123
  }
124
124
  checkTemplate(template) {
125
- if ((0, file_1.existsFile)(path_1.default.resolve(directory_1.templateDir, `${template}.html`))) {
126
- return path_1.default.resolve(directory_1.templateDir, `${template}.html`);
125
+ if ((0, file_1.existsFile)(node_path_1.default.resolve(directory_1.templateDir, `${template}.html`))) {
126
+ return node_path_1.default.resolve(directory_1.templateDir, `${template}.html`);
127
127
  }
128
- else if ((0, file_1.existsFile)(path_1.default.resolve(directory_1.rootDir, template))) {
129
- return path_1.default.resolve(directory_1.rootDir, template);
128
+ if ((0, file_1.existsFile)(node_path_1.default.resolve(directory_1.rootDir, template))) {
129
+ return node_path_1.default.resolve(directory_1.rootDir, template);
130
130
  }
131
131
  throw new Error(`Template file not found: ${template}`);
132
132
  }
133
133
  checkPort(port) {
134
- if (!isNaN(port) && 0 < port && port <= 65535) {
134
+ if (!Number.isNaN(port) && 0 < port && port <= 65535) {
135
135
  return port;
136
136
  }
137
137
  throw new Error(`Invalid port: ${port}`);
@@ -3,13 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const path_1 = __importDefault(require("path"));
6
+ const node_path_1 = __importDefault(require("node:path"));
7
7
  const directory_1 = require("./directory");
8
8
  const params_1 = require("./params");
9
9
  const DEFAULT_VALUES = {
10
10
  filepath: "README.md",
11
11
  extensions: ["md", "markdown"],
12
- template: path_1.default.resolve(directory_1.projectDir, "template/default.html"),
12
+ template: node_path_1.default.resolve(directory_1.projectDir, "template/default.html"),
13
13
  port: 34567,
14
14
  logLevel: "info",
15
15
  noOpener: false,
@@ -37,7 +37,7 @@ describe("Params", () => {
37
37
  const expectParams = {
38
38
  filepath: "test/markdown/markdown1.md",
39
39
  extensions: ["ext1", "ext2"],
40
- template: path_1.default.resolve(directory_1.projectDir, "test/template/template1.html"),
40
+ template: node_path_1.default.resolve(directory_1.projectDir, "test/template/template1.html"),
41
41
  port: 100,
42
42
  logLevel: "info",
43
43
  noOpener: false,
@@ -66,7 +66,7 @@ describe("Params", () => {
66
66
  const expectParams = {
67
67
  filepath: "test/markdown/markdown1.md",
68
68
  extensions: ["ext1", "ext2"],
69
- template: path_1.default.resolve(directory_1.projectDir, "test/template/template1.html"),
69
+ template: node_path_1.default.resolve(directory_1.projectDir, "test/template/template1.html"),
70
70
  port: 100,
71
71
  logLevel: "trace",
72
72
  noOpener: true,
@@ -88,7 +88,7 @@ describe("Params", () => {
88
88
  const expectParams = {
89
89
  filepath: "test/markdown/markdown1.md",
90
90
  extensions: ["ext1", "ext2"],
91
- template: path_1.default.resolve(directory_1.projectDir, "test/template/template1.html"),
91
+ template: node_path_1.default.resolve(directory_1.projectDir, "test/template/template1.html"),
92
92
  port: 100,
93
93
  logLevel: "trace",
94
94
  noOpener: true,
package/src/lib/show.js CHANGED
@@ -23,7 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.showVersion = exports.getVersion = exports.showUsage = void 0;
26
+ exports.showUsage = showUsage;
27
+ exports.getVersion = getVersion;
28
+ exports.showVersion = showVersion;
27
29
  const pkg = __importStar(require("../../package.json"));
28
30
  function showUsage(error = false) {
29
31
  const usage = `
@@ -41,13 +43,10 @@ Options:
41
43
  console.log(usage);
42
44
  process.exit(error ? 1 : 0);
43
45
  }
44
- exports.showUsage = showUsage;
45
46
  function getVersion() {
46
47
  return `v${pkg.version}`;
47
48
  }
48
- exports.getVersion = getVersion;
49
49
  function showVersion() {
50
50
  console.log(getVersion());
51
51
  process.exit(0);
52
52
  }
53
- exports.showVersion = showVersion;
@@ -12,7 +12,9 @@ class SocketManager {
12
12
  this._sockets = this._sockets.filter(({ socket: s }) => s !== socket);
13
13
  }
14
14
  getSockets(filepath) {
15
- return this._sockets.filter(({ filepath: fp }) => fp === filepath).map((s) => s.socket);
15
+ return this._sockets
16
+ .filter(({ filepath: fp }) => fp === filepath)
17
+ .map((s) => s.socket);
16
18
  }
17
19
  countSocket(filepath = null) {
18
20
  if (filepath == null) {
@@ -1,9 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const socket_manager_1 = require("./socket_manager");
4
- const dummySocket1 = { name: "socket1" }; // eslint-disable-line @typescript-eslint/no-explicit-any
5
- const dummySocket2 = { name: "socket2" }; // eslint-disable-line @typescript-eslint/no-explicit-any
6
- const dummySocket3 = { name: "socket3" }; // eslint-disable-line @typescript-eslint/no-explicit-any
4
+ // biome-ignore lint/suspicious/noExplicitAny: It is used for testing only.
5
+ const dummySocket1 = { name: "socket1" };
6
+ // biome-ignore lint/suspicious/noExplicitAny: It is used for testing only.
7
+ const dummySocket2 = { name: "socket2" };
8
+ // biome-ignore lint/suspicious/noExplicitAny: It is used for testing only.
9
+ const dummySocket3 = { name: "socket3" };
7
10
  const dummyFilepath1 = "file1";
8
11
  const dummyFilepath2 = "file2";
9
12
  const dummyInfo1 = { socket: dummySocket1, filepath: dummyFilepath1 };
@@ -18,9 +21,16 @@ describe("SocketManager", () => {
18
21
  socketManager.addSocket(dummySocket2, dummyFilepath2);
19
22
  expect(socketManager._sockets).toEqual([dummyInfo1, dummyInfo2]);
20
23
  socketManager.addSocket(dummySocket3, dummyFilepath2);
21
- expect(socketManager._sockets).toEqual([dummyInfo1, dummyInfo2, dummyInfo3]);
24
+ expect(socketManager._sockets).toEqual([
25
+ dummyInfo1,
26
+ dummyInfo2,
27
+ dummyInfo3,
28
+ ]);
22
29
  expect(socketManager.getSockets(dummyFilepath1)).toEqual([dummySocket1]);
23
- expect(socketManager.getSockets(dummyFilepath2)).toEqual([dummySocket2, dummySocket3]);
30
+ expect(socketManager.getSockets(dummyFilepath2)).toEqual([
31
+ dummySocket2,
32
+ dummySocket3,
33
+ ]);
24
34
  expect(socketManager.countSocket()).toEqual(3);
25
35
  expect(socketManager.countSocket(dummyFilepath1)).toEqual(1);
26
36
  expect(socketManager.countSocket(dummyFilepath2)).toEqual(2);
package/src/markdown.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.MarkdownHandler = void 0;
6
+ exports.MarkdownHandler = MarkdownHandler;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const directory_1 = require("./lib/directory");
9
9
  const file_1 = require("./lib/file");
@@ -18,4 +18,3 @@ function MarkdownHandler(template) {
18
18
  }
19
19
  };
20
20
  }
21
- exports.MarkdownHandler = MarkdownHandler;
package/src/websocket.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.WebSocketHandler = void 0;
6
+ exports.WebSocketHandler = WebSocketHandler;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const file_watcher_1 = require("./lib/file_watcher");
9
9
  const socket_manager_1 = require("./lib/socket_manager");
@@ -39,4 +39,3 @@ function WebSocketHandler(logger) {
39
39
  }
40
40
  };
41
41
  }
42
- exports.WebSocketHandler = WebSocketHandler;