oipage 1.2.0-alpha.2 → 1.2.0-alpha.3

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/bin/serve.js CHANGED
@@ -5,7 +5,7 @@ const packageValue = require("../package.json");
5
5
  const network = require("./tools/network.js");
6
6
  const mineTypes = require("./data/mineTypes.json");
7
7
  const resolve404 = require("./tools/resolve404.js");
8
- const resolveImport = require("./tools/resolveImport.js");
8
+ const resolveImportFactory = require("./tools/resolveImport.js");
9
9
  const { formatRawHeaders } = require("./tools/format.js");
10
10
 
11
11
  // 开发服务器
@@ -42,7 +42,7 @@ module.exports = function (config) {
42
42
 
43
43
  // 如果文件小于10M,认为不大,直接读取
44
44
  if (fileInfo.size < 10 * 1024 * 1024) {
45
- let source = resolveImport(basePath, filePath, headers.Accept === "*/*", urlArray[1] === "download")
45
+ let { source, resolveImport } = resolveImportFactory(basePath, filePath, headers.Accept === "*/*", urlArray[1] === "download")
46
46
 
47
47
  // 只处理非下载文件
48
48
  // 过大的也不进行处理
@@ -57,6 +57,7 @@ module.exports = function (config) {
57
57
  responseHeader['Content-type'] = fileType + ";charset=utf-8";
58
58
  }
59
59
  }, source);
60
+ source = resolveImport(source);
60
61
  break;
61
62
  }
62
63
  }
@@ -2,7 +2,7 @@ const { readFileSync, existsSync, lstatSync } = require("fs");
2
2
  const { join } = require("path");
3
3
 
4
4
  module.exports = function (basePath, filePath, needResolve, isDownload) {
5
- let code = readFileSync(filePath);
5
+ let source = readFileSync(filePath);
6
6
 
7
7
  let resolveImport = function (content) {
8
8
  return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
@@ -44,23 +44,23 @@ module.exports = function (basePath, filePath, needResolve, isDownload) {
44
44
 
45
45
  // 如果是下载
46
46
  if (isDownload) {
47
- return code;
47
+ // todo
48
48
  }
49
49
 
50
50
  // 如果需要解析
51
51
  else if (needResolve) {
52
- return resolveImport(code + "");
52
+ source = resolveImport(source + "");
53
53
  }
54
54
 
55
55
  // 如果是.html或.htm结尾
56
56
  else if (/\.html{0,1}$/.test(filePath)) {
57
- return (code + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
57
+ source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
58
58
  return `<script type="module">${resolveImport(_matchCode)}</script>`;
59
59
  });
60
60
  }
61
61
 
62
- // 否则直接返回即可
63
- else {
64
- return code;
65
- }
62
+ return {
63
+ source,
64
+ resolveImport
65
+ };
66
66
  };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.2.0-alpha.2
2
+ * animation of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * cmdlog of OIPage v1.2.0-alpha.2
2
+ * cmdlog of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * disk of OIPage v1.2.0-alpha.2
2
+ * disk of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * logform of OIPage v1.2.0-alpha.2
2
+ * logform of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
  const {linelog} = require("../cmdlog/index.js");
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.2.0-alpha.2
2
+ * throttle of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "1.2.0-alpha.2",
3
+ "version": "1.2.0-alpha.3",
4
4
  "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.2.0-alpha.2
2
+ * animation of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * onReady of OIPage v1.2.0-alpha.2
2
+ * onReady of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * style of OIPage v1.2.0-alpha.2
2
+ * style of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * throttle of OIPage v1.2.0-alpha.2
2
+ * throttle of OIPage v1.2.0-alpha.3
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5