oipage 1.3.0-alpha.0 → 1.3.0-alpha.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.
package/CHANGELOG CHANGED
@@ -52,8 +52,13 @@ v1.2.1:
52
52
  v1.3.0:
53
53
  date:
54
54
  changes:
55
+ - 修复bug
56
+ 1、开发服务器
57
+ * 修复服务器根路径判断错误导致node_modules包查找错误问题
55
58
  - 新增功能
56
59
  1、API功能(浏览器)
57
60
  * reader 文本分析读取器
58
61
  2、API功能(Node.js)
59
62
  * reader 文本分析读取器
63
+ 3、开发服务器
64
+ * 新增 devServer.intercept 请求拦截
@@ -0,0 +1,16 @@
1
+ exports.doIntercept = function (url, intercept, request, response) {
2
+ for (let item of intercept) {
3
+ if (item.test.test(url)) {
4
+ item.handler(request, response);
5
+ return true;
6
+ }
7
+ }
8
+ }
9
+
10
+ exports.testIntercept = function (url, intercept) {
11
+ for (let item of intercept) {
12
+ if (item.test.test(url)) {
13
+ return true;
14
+ }
15
+ }
16
+ }
package/bin/run CHANGED
@@ -22,6 +22,7 @@ if (process.argv[2] === "serve") {
22
22
  devServer: {
23
23
  port: 8080,
24
24
  baseUrl: "./",
25
+ intercept: []
25
26
  },
26
27
  module: {
27
28
  rules: []
package/bin/serve.js CHANGED
@@ -7,6 +7,7 @@ const mineTypes = require("./data/mineTypes.json");
7
7
  const resolve404 = require("./tools/resolve404.js");
8
8
  const resolveImportFactory = require("./tools/resolveImport.js");
9
9
  const { formatRawHeaders } = require("./tools/format.js");
10
+ const { doIntercept } = require("./intercept.js");
10
11
 
11
12
  // 开发服务器
12
13
  module.exports = function (config) {
@@ -25,8 +26,13 @@ module.exports = function (config) {
25
26
  // 请求的文件路径
26
27
  let filePath = join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
27
28
 
29
+ // 请求拦截
30
+ if (doIntercept(url.replace(/^\/@modules\//, ""), config.devServer.intercept, request, response)) {
31
+ console.log("<i> \x1b[1m\x1b[32m[OIPage-dev-server] intercept: " + url + '\x1b[0m ' + new Date().toLocaleString());
32
+ }
33
+
28
34
  // 如果存在且是文件
29
- if (existsSync(filePath) && !lstatSync(filePath).isDirectory()) {
35
+ else if (existsSync(filePath) && !lstatSync(filePath).isDirectory()) {
30
36
 
31
37
  let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
32
38
  let fileType = mineTypes[dotName]; // 文件类型
@@ -43,7 +49,7 @@ module.exports = function (config) {
43
49
 
44
50
  // 如果文件小于10M,认为不大,直接读取
45
51
  if (fileInfo.size < 10 * 1024 * 1024) {
46
- let { source, resolveImport } = resolveImportFactory(basePath, filePath, entry, urlArray[1] === "download")
52
+ let { source, resolveImport } = resolveImportFactory(basePath, filePath, entry, config.devServer.intercept, urlArray[1] === "download")
47
53
 
48
54
  // 只处理非下载文件
49
55
  // 过大的也不进行处理
@@ -1,7 +1,10 @@
1
1
  const { readFileSync, existsSync, lstatSync } = require("fs");
2
2
  const { join } = require("path");
3
+ const { testIntercept } = require("../intercept.js");
4
+
5
+ module.exports = function (basePath, filePath, entry, intercept, isDownload) {
6
+ basePath = join(basePath, "./");
3
7
 
4
- module.exports = function (basePath, filePath, entry, isDownload) {
5
8
  let source = readFileSync(filePath);
6
9
  let resolveImport = content => content;
7
10
 
@@ -12,43 +15,49 @@ module.exports = function (basePath, filePath, entry, isDownload) {
12
15
  } else {
13
16
  return _importCode.replace(_importUrl, _importUrl.replace(/([^/])+/s, function (npmName) {
14
17
 
15
- let node_modulesRootPath = join(filePath, "../");
16
- let prePath = "";
17
- while (true) {
18
- let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
19
-
20
- // 如果存在
21
- if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
22
- let npmNameValue = npmName;
23
-
24
- // 对于类似 import VISLite from "vislite"
25
- // 需要把包名解析成具体的文件
26
- if (!/\//.test(_importUrl)) {
27
- let bundlePackage = require(join(npmBundlePath, "./package.json"));
28
- npmNameValue = npmName + "/" + bundlePackage.main;
29
- }
18
+ if (testIntercept(npmName, intercept)) {
19
+ return "/@modules/" + npmName;
20
+ } else {
30
21
 
31
- return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
32
- }
22
+ let node_modulesRootPath = join(filePath, "../");
23
+ let prePath = "";
24
+ while (true) {
25
+ let npmBundlePath = join(node_modulesRootPath, "./node_modules/", npmName);
33
26
 
34
- if (node_modulesRootPath === basePath) {
27
+ // 如果存在
28
+ if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
29
+ let npmNameValue = npmName;
35
30
 
36
- // 如果命令行根目录是一个项目
37
- let packagePath = join(basePath, "./package.json");
38
- if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
39
- let bundlePackage = require(packagePath);
31
+ // 对于类似 import VISLite from "vislite"
32
+ // 需要把包名解析成具体的文件
40
33
  if (!/\//.test(_importUrl)) {
41
- return "/" + bundlePackage.main;
42
- } else {
43
- return "/"
34
+ let bundlePackage = require(join(npmBundlePath, "./package.json"));
35
+ npmNameValue = npmName + "/" + bundlePackage.main;
44
36
  }
37
+
38
+ return (prePath ? prePath : "./") + "node_modules/" + npmNameValue;
45
39
  }
46
40
 
47
- return npmName;
48
- } else {
49
- node_modulesRootPath = join(node_modulesRootPath, "../");
50
- prePath = "../" + prePath;
41
+ if (node_modulesRootPath === basePath) {
42
+
43
+ // 如果命令行根目录是一个项目
44
+ let packagePath = join(basePath, "./package.json");
45
+ if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
46
+ let bundlePackage = require(packagePath);
47
+ if (!/\//.test(_importUrl)) {
48
+ return "/" + bundlePackage.main;
49
+ } else {
50
+ return "/"
51
+ }
52
+ }
53
+
54
+ return npmName;
55
+ } else {
56
+ node_modulesRootPath = join(node_modulesRootPath, "../");
57
+ prePath = "../" + prePath;
58
+ }
51
59
  }
60
+
52
61
  }
53
62
  }));
54
63
  }
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.3.0-alpha.0
2
+ * animation of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * cmdlog of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * disk of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * logform of OIPage v1.3.0-alpha.2
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
- * reader of OIPage v1.3.0-alpha.0
2
+ * reader of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * throttle of OIPage v1.3.0-alpha.2
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.3.0-alpha.0",
3
+ "version": "1.3.0-alpha.2",
4
4
  "description": "前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.3.0-alpha.0
2
+ * animation of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * onReady of OIPage v1.3.0-alpha.2
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * reader of OIPage v1.3.0-alpha.0
2
+ * reader of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * style of OIPage v1.3.0-alpha.2
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.3.0-alpha.0
2
+ * throttle of OIPage v1.3.0-alpha.2
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5