mm_statics 1.7.2 → 1.7.5

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.
Files changed (2) hide show
  1. package/index.js +32 -22
  2. package/package.json +7 -9
package/index.js CHANGED
@@ -298,7 +298,7 @@ Static.prototype._sendFile = async function (ctx, path) {
298
298
  };
299
299
  }
300
300
 
301
- await send(ctx, path, config);
301
+ return await send(ctx, path, config);
302
302
  };
303
303
 
304
304
  /**
@@ -608,29 +608,20 @@ Static.prototype._handleCache = async function (url, ctx) {
608
608
  return false;
609
609
  };
610
610
 
611
- /**
612
- * 将路由路径转换为物理路径
613
- * @param {string} path 文件路径
614
- * @returns {string} 根路径
615
- */
616
- Static.prototype.pathToRoot = function (path) {
617
- return path.replace(this.config.path, "/");
618
- }
619
-
620
611
  /**
621
612
  * 处理文件编译逻辑
622
613
  * @param {string} path 文件路径
623
614
  * @returns {string|null} 编译后的内容
624
615
  */
625
616
  Static.prototype._handleFileCompile = async function (path) {
626
- if (this.config.compile_md && path.extname() === '.md') {
617
+ let { src_path, compile_md, files, compile_vue, convert_amd } = this.config;
618
+ if (compile_md && path.extname() === '.md') {
627
619
  return await this._runMarkdown(path);
628
- } else if (!path.startsWith(this.config.src_path)) return null;
620
+ } else if (!path.startsWith(src_path)) return null;
629
621
 
630
622
  let file_type = this._getType(path);
631
- let { compile_vue, convert_amd } = this.config;
632
623
 
633
- if (convert_amd && this.config.files.includes('.' + file_type)) {
624
+ if (convert_amd && files.includes('.' + file_type)) {
634
625
  return await this._runAmd(path, file_type);
635
626
  }
636
627
  else if (compile_vue && file_type === 'vue') {
@@ -661,38 +652,57 @@ Static.prototype._handleCompiledResp = async function (url, path, body, ctx) {
661
652
  }
662
653
  };
663
654
 
655
+ /**
656
+ * 获取真实路径
657
+ * @param {string} path 文件路径
658
+ * @returns {string} 真实路径
659
+ */
660
+ Static.prototype._getRealPath = function (path) {
661
+ return path.replace(this.config.path, "/");
662
+ }
663
+
664
+ /**
665
+ * 将路由路径转换为物理路径
666
+ * @param {string} path 文件路径
667
+ * @returns {string} 根路径
668
+ */
669
+ Static.prototype._pathToRoot = function (path) {
670
+ return ("." + path).fullname(this.config.root);
671
+ }
672
+
664
673
  /**
665
674
  * 主处理函数
666
675
  * @param {object} ctx Koa上下文对象
667
676
  * @param {Function} next Koa中间件函数
668
677
  */
669
678
  Static.prototype.main = async function (ctx, next) {
670
- const url = ctx.url; // 使用完整URL(包含查询参数)
671
- if (!url.startsWith(this.config.path)) {
679
+ let url = ctx.url; // 使用完整URL(包含查询参数)
680
+ if (!ctx.path.startsWith(this.config.path)) {
672
681
  await next();
673
- return;
682
+ return '';
674
683
  }
684
+ let path = this._getRealPath(ctx.path);
685
+
675
686
  // 检查缓存
676
687
  if (await this._handleCache(url, ctx)) {
677
- return;
688
+ return this._pathToRoot(path);
678
689
  }
679
690
 
680
- const path = this.pathToRoot(ctx.path);
681
-
682
691
  // 处理文件编译
683
692
  let body = await this._handleFileCompile(path);
684
693
  if (body) {
685
694
  await this._handleCompiledResp(url, path, body, ctx);
686
- return;
695
+ return this._pathToRoot(path);
687
696
  }
688
697
 
689
698
  // 直接发送文件
690
699
  try {
691
- await this._sendFile(ctx, path);
700
+ return await this._sendFile(ctx, path);
692
701
  }
693
702
  catch {
694
703
  await next();
695
704
  }
705
+ return '';
696
706
  };
697
707
 
698
708
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_statics",
3
- "version": "1.7.2",
3
+ "version": "1.7.5",
4
4
  "description": "这是超级美眉statics函数模块,用于web服务端statics缓存",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,20 +37,18 @@
37
37
  "static/"
38
38
  ],
39
39
  "dependencies": {
40
- "@vue/compiler-sfc": "^3.5.27",
40
+ "@vue/compiler-sfc": "^3.5.33",
41
41
  "abstract-syntax-tree": "^2.22.0",
42
42
  "chokidar": "^5.0.0",
43
- "koa": "^3.1.1",
44
- "koa-send": "^5.0.1",
45
- "marked": "^17.0.1",
43
+ "marked": "^18.0.2",
46
44
  "mm_cache": "^1.4.8",
47
45
  "mm_es6_to_amd": "^1.4.7",
48
- "prettier": "^3.8.1"
46
+ "prettier": "^3.8.3"
49
47
  },
50
48
  "devDependencies": {
51
- "eslint": "^9.39.2",
52
- "eslint-plugin-jsdoc": "^62.5.0",
53
- "mm_eslint": "^1.6.3",
49
+ "eslint": "^10.2.1",
50
+ "eslint-plugin-jsdoc": "^62.9.0",
51
+ "mm_eslint": "^1.7.1",
54
52
  "mocha": "^11.7.5",
55
53
  "supertest": "^7.2.2"
56
54
  }