oipage 1.2.0-alpha.3 → 1.2.0-alpha.4

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
@@ -57,7 +57,6 @@ module.exports = function (config) {
57
57
  responseHeader['Content-type'] = fileType + ";charset=utf-8";
58
58
  }
59
59
  }, source);
60
- source = resolveImport(source);
61
60
  break;
62
61
  }
63
62
  }
@@ -65,7 +64,7 @@ module.exports = function (config) {
65
64
 
66
65
  sendType = "Read";
67
66
  response.writeHead('200', responseHeader);
68
- response.write(source);
67
+ response.write(resolveImport(source));
69
68
  response.end();
70
69
  }
71
70
 
@@ -3,8 +3,9 @@ const { join } = require("path");
3
3
 
4
4
  module.exports = function (basePath, filePath, needResolve, isDownload) {
5
5
  let source = readFileSync(filePath);
6
+ let resolveImport = content => content;
6
7
 
7
- let resolveImport = function (content) {
8
+ let __resolveImport = function (content) {
8
9
  return content.replace(/import [^'"]* from (['"])([^'"]*)['"]/sg, function (_importCode, _, _importUrl) {
9
10
  if (/^[./]/.test(_importUrl)) {
10
11
  return _importCode;
@@ -31,6 +32,18 @@ module.exports = function (basePath, filePath, needResolve, isDownload) {
31
32
  }
32
33
 
33
34
  if (node_modulesRootPath === basePath) {
35
+
36
+ // 如果命令行根目录是一个项目
37
+ let packagePath = join(basePath, "./package.json");
38
+ if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
39
+ let bundlePackage = require(packagePath);
40
+ if (!/\//.test(_importUrl)) {
41
+ return "/" + bundlePackage.main;
42
+ } else {
43
+ return "/"
44
+ }
45
+ }
46
+
34
47
  return npmName;
35
48
  } else {
36
49
  node_modulesRootPath = join(node_modulesRootPath, "../");
@@ -49,13 +62,14 @@ module.exports = function (basePath, filePath, needResolve, isDownload) {
49
62
 
50
63
  // 如果需要解析
51
64
  else if (needResolve) {
52
- source = resolveImport(source + "");
65
+ source += "";
66
+ resolveImport = __resolveImport;
53
67
  }
54
68
 
55
69
  // 如果是.html或.htm结尾
56
70
  else if (/\.html{0,1}$/.test(filePath)) {
57
71
  source = (source + "").replace(/<script type="module">(.*)<\/script>/sg, function (_, _matchCode) {
58
- return `<script type="module">${resolveImport(_matchCode)}</script>`;
72
+ return `<script type="module">${__resolveImport(_matchCode)}</script>`;
59
73
  });
60
74
  }
61
75
 
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * animation of OIPage v1.2.0-alpha.3
2
+ * animation of OIPage v1.2.0-alpha.4
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.3
2
+ * cmdlog of OIPage v1.2.0-alpha.4
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.3
2
+ * disk of OIPage v1.2.0-alpha.4
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.3
2
+ * logform of OIPage v1.2.0-alpha.4
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.3
2
+ * throttle of OIPage v1.2.0-alpha.4
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.3",
3
+ "version": "1.2.0-alpha.4",
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.3
2
+ * animation of OIPage v1.2.0-alpha.4
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.3
2
+ * onReady of OIPage v1.2.0-alpha.4
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.3
2
+ * style of OIPage v1.2.0-alpha.4
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.3
2
+ * throttle of OIPage v1.2.0-alpha.4
3
3
  * git+https://github.com/oi-contrib/OIPage.git
4
4
  */
5
5