@tnotesjs/core 0.0.1 → 0.0.2

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.
@@ -3355,14 +3355,16 @@ var NoteService = class _NoteService {
3355
3355
  // services/file-watcher/service.ts
3356
3356
  var NOTES_DIR_NOT_SET_ERROR = "NOTES_DIR_PATH \u672A\u8BBE\u7F6E\uFF0C\u65E0\u6CD5\u542F\u52A8\u6587\u4EF6\u76D1\u542C";
3357
3357
  var UPDATE_UNLOCK_DELAY_MS2 = 500;
3358
- var FileWatcherService = class {
3358
+ var FileWatcherService = class _FileWatcherService {
3359
3359
  constructor(notesDir = NOTES_DIR_PATH) {
3360
3360
  this.notesDir = notesDir;
3361
3361
  if (!this.notesDir) {
3362
3362
  throw new Error(NOTES_DIR_NOT_SET_ERROR);
3363
3363
  }
3364
3364
  this.init();
3365
+ _FileWatcherService.instance = this;
3365
3366
  }
3367
+ static instance = null;
3366
3368
  watchState;
3367
3369
  scheduler;
3368
3370
  renameDetector;
@@ -3375,6 +3377,9 @@ var FileWatcherService = class {
3375
3377
  readmeService;
3376
3378
  noteIndexCache;
3377
3379
  unlockTimer = null;
3380
+ static getInstance() {
3381
+ return _FileWatcherService.instance;
3382
+ }
3378
3383
  init() {
3379
3384
  this.noteService = NoteService.getInstance();
3380
3385
  this.readmeService = ReadmeService.getInstance();
@@ -3479,6 +3484,24 @@ var FileWatcherService = class {
3479
3484
  isWatching() {
3480
3485
  return this.adapter.isWatching();
3481
3486
  }
3487
+ /**
3488
+ * 挂起文件监听(关闭 fs.watch 句柄),用于需要操作文件夹的场景(如重命名)
3489
+ * Windows 上 fs.watch 会锁住文件夹句柄,必须先关闭才能重命名
3490
+ */
3491
+ suspend() {
3492
+ this.adapter.stop();
3493
+ this.scheduler.setUpdating(true);
3494
+ logger.info("\u6587\u4EF6\u76D1\u542C\u5DF2\u6302\u8D77\uFF08fs.watch \u5DF2\u5173\u95ED\uFF09");
3495
+ }
3496
+ /**
3497
+ * 恢复文件监听(重新启动 fs.watch)
3498
+ */
3499
+ unsuspend() {
3500
+ this.watchState.initializeFromDisk();
3501
+ this.scheduler.setUpdating(false);
3502
+ this.adapter.start();
3503
+ logger.info("\u6587\u4EF6\u76D1\u542C\u5DF2\u6062\u590D\uFF08fs.watch \u5DF2\u91CD\u542F\uFF09");
3504
+ }
3482
3505
  // #region - 私有实现
3483
3506
  onNoteEvent(event) {
3484
3507
  if (!this.isNoteFile(event.path)) return;
@@ -4210,7 +4233,9 @@ var RenameNoteCommand = class extends BaseCommand {
4210
4233
  if (existsSync8(newPath)) {
4211
4234
  throw new Error(`\u76EE\u6807\u6587\u4EF6\u5939\u5DF2\u5B58\u5728: ${newDirName}`);
4212
4235
  }
4236
+ const watcher = FileWatcherService.getInstance();
4213
4237
  try {
4238
+ if (watcher) watcher.suspend();
4214
4239
  renameSync(note.path, newPath);
4215
4240
  this.logger.info(`\u2705 \u6587\u4EF6\u5939\u5DF2\u91CD\u547D\u540D:`);
4216
4241
  this.logger.info(` \u539F\u540D\u79F0: ${note.dirName}`);
@@ -4219,6 +4244,8 @@ var RenameNoteCommand = class extends BaseCommand {
4219
4244
  throw new Error(
4220
4245
  `\u91CD\u547D\u540D\u6587\u4EF6\u5939\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`
4221
4246
  );
4247
+ } finally {
4248
+ if (watcher) watcher.unsuspend();
4222
4249
  }
4223
4250
  try {
4224
4251
  this.logger.info("\u6B63\u5728\u66F4\u65B0\u7B14\u8BB0\u5185\u90E8\u6807\u9898...");
package/dist/cli/index.js CHANGED
@@ -22,7 +22,7 @@ import {
22
22
  parseArgs,
23
23
  parseReadmeCompletedNotes,
24
24
  runCommand
25
- } from "../chunk-CSSIRO3I.js";
25
+ } from "../chunk-LZQDLU3S.js";
26
26
  import {
27
27
  ConfigManager
28
28
  } from "../chunk-NASIL5FY.js";
@@ -4,7 +4,7 @@ import {
4
4
  UpdateNoteConfigCommand,
5
5
  generateAnchor,
6
6
  logger
7
- } from "../../chunk-CSSIRO3I.js";
7
+ } from "../../chunk-LZQDLU3S.js";
8
8
  import "../../chunk-NASIL5FY.js";
9
9
 
10
10
  // vitepress/config/index.ts
package/package.json CHANGED
@@ -1,77 +1,77 @@
1
- {
2
- "name": "@tnotesjs/core",
3
- "version": "0.0.1",
4
- "description": "TNotes 知识库核心框架 —— 基于 VitePress 的笔记管理系统",
5
- "type": "module",
6
- "bin": {
7
- "tnotes": "./dist/cli/index.js"
8
- },
9
- "exports": {
10
- ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
13
- },
14
- "./vitepress/config": {
15
- "import": "./dist/vitepress/config/index.js"
16
- },
17
- "./vitepress/theme": {
18
- "types": "./vitepress/theme/index.ts",
19
- "import": "./vitepress/theme/index.ts"
20
- },
21
- "./vitepress/*": "./vitepress/*"
22
- },
23
- "files": [
24
- "dist/",
25
- "vitepress/",
26
- "types/"
27
- ],
28
- "scripts": {
29
- "build": "tsup",
30
- "build:check": "tsc --noEmit",
31
- "dev": "tsup --watch",
32
- "release": "node scripts/release.mjs"
33
- },
34
- "peerDependencies": {
35
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
36
- "vitepress": "^1.6.0",
37
- "vue": "^3.5.0"
38
- },
39
- "dependencies": {
40
- "d3": "^7.9.0",
41
- "echarts": "^6.0.0",
42
- "github-slugger": "^2.0.0",
43
- "markdown-it-container": "^4.0.0",
44
- "markdown-it-link-attributes": "^4.0.1",
45
- "markdown-it-mathjax3": "^4.3.2",
46
- "markdown-it-task-lists": "^2.1.1",
47
- "marked": "^15.0.11",
48
- "markmap-lib": "^0.18.12",
49
- "markmap-toolbar": "^0.18.12",
50
- "markmap-view": "^0.18.12",
51
- "mermaid": "^11.5.0",
52
- "sass-embedded": "^1.90.0",
53
- "swiper": "^11.2.1",
54
- "uuid": "^11.1.0",
55
- "vue-echarts": "^8.0.1"
56
- },
57
- "devDependencies": {
58
- "@types/markdown-it": "^14.1.2",
59
- "@types/node": "^24.6.2",
60
- "tsup": "^8.5.1",
61
- "typescript": "^5.9.3"
62
- },
63
- "engines": {
64
- "node": ">=18.0.0"
65
- },
66
- "license": "MIT",
67
- "repository": {
68
- "type": "git",
69
- "url": "https://github.com/tnotesjs/core"
70
- },
71
- "keywords": [
72
- "tnotes",
73
- "vitepress",
74
- "knowledge-base",
75
- "notes"
76
- ]
77
- }
1
+ {
2
+ "name": "@tnotesjs/core",
3
+ "version": "0.0.2",
4
+ "description": "TNotes 知识库核心框架 —— 基于 VitePress 的笔记管理系统",
5
+ "type": "module",
6
+ "bin": {
7
+ "tnotes": "./dist/cli/index.js"
8
+ },
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./vitepress/config": {
15
+ "import": "./dist/vitepress/config/index.js"
16
+ },
17
+ "./vitepress/theme": {
18
+ "types": "./vitepress/theme/index.ts",
19
+ "import": "./vitepress/theme/index.ts"
20
+ },
21
+ "./vitepress/*": "./vitepress/*"
22
+ },
23
+ "files": [
24
+ "dist/",
25
+ "vitepress/",
26
+ "types/"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsup",
30
+ "build:check": "tsc --noEmit -p tsconfig.build.json",
31
+ "dev": "tsup --watch",
32
+ "release": "node scripts/release.mjs"
33
+ },
34
+ "peerDependencies": {
35
+ "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
36
+ "vitepress": "^1.6.0",
37
+ "vue": "^3.5.0"
38
+ },
39
+ "dependencies": {
40
+ "d3": "^7.9.0",
41
+ "echarts": "^6.0.0",
42
+ "github-slugger": "^2.0.0",
43
+ "markdown-it-container": "^4.0.0",
44
+ "markdown-it-link-attributes": "^4.0.1",
45
+ "markdown-it-mathjax3": "^4.3.2",
46
+ "markdown-it-task-lists": "^2.1.1",
47
+ "marked": "^15.0.11",
48
+ "markmap-lib": "^0.18.12",
49
+ "markmap-toolbar": "^0.18.12",
50
+ "markmap-view": "^0.18.12",
51
+ "mermaid": "^11.5.0",
52
+ "sass-embedded": "^1.90.0",
53
+ "swiper": "^11.2.1",
54
+ "uuid": "^11.1.0",
55
+ "vue-echarts": "^8.0.1"
56
+ },
57
+ "devDependencies": {
58
+ "@types/markdown-it": "^14.1.2",
59
+ "@types/node": "^24.6.2",
60
+ "tsup": "^8.5.1",
61
+ "typescript": "^5.9.3"
62
+ },
63
+ "engines": {
64
+ "node": ">=18.0.0"
65
+ },
66
+ "license": "MIT",
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "https://github.com/tnotesjs/core"
70
+ },
71
+ "keywords": [
72
+ "tnotes",
73
+ "vitepress",
74
+ "knowledge-base",
75
+ "notes"
76
+ ]
77
+ }