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 +5 -0
- package/bin/intercept.js +16 -0
- package/bin/run +1 -0
- package/bin/serve.js +8 -2
- package/bin/tools/resolveImport.js +39 -30
- package/nodejs/animation/index.js +1 -1
- package/nodejs/cmdlog/index.js +1 -1
- package/nodejs/disk/index.js +1 -1
- package/nodejs/logform/index.js +1 -1
- package/nodejs/reader/index.js +1 -1
- package/nodejs/throttle/index.js +1 -1
- package/package.json +1 -1
- package/web/animation/index.js +1 -1
- package/web/onReady/index.js +1 -1
- package/web/reader/index.js +1 -1
- package/web/style/index.js +1 -1
- package/web/throttle/index.js +1 -1
package/CHANGELOG
CHANGED
package/bin/intercept.js
ADDED
|
@@ -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
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
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
|
-
|
|
27
|
+
// 如果存在
|
|
28
|
+
if (existsSync(npmBundlePath) && lstatSync(npmBundlePath).isDirectory()) {
|
|
29
|
+
let npmNameValue = npmName;
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (existsSync(packagePath) && !lstatSync(packagePath).isDirectory()) {
|
|
39
|
-
let bundlePackage = require(packagePath);
|
|
31
|
+
// 对于类似 import VISLite from "vislite"
|
|
32
|
+
// 需要把包名解析成具体的文件
|
|
40
33
|
if (!/\//.test(_importUrl)) {
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
}
|
package/nodejs/cmdlog/index.js
CHANGED
package/nodejs/disk/index.js
CHANGED
package/nodejs/logform/index.js
CHANGED
package/nodejs/reader/index.js
CHANGED
package/nodejs/throttle/index.js
CHANGED
package/package.json
CHANGED
package/web/animation/index.js
CHANGED
package/web/onReady/index.js
CHANGED
package/web/reader/index.js
CHANGED
package/web/style/index.js
CHANGED
package/web/throttle/index.js
CHANGED