oipage 1.2.0-alpha.3 → 1.2.0-beta.0
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/AUTHORS.txt +6 -0
- package/CHANGELOG +1 -1
- package/bin/serve.js +7 -6
- package/bin/tools/resolveImport.js +20 -6
- 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/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/style/index.js +1 -1
- package/web/throttle/index.js +1 -1
package/AUTHORS.txt
ADDED
package/CHANGELOG
CHANGED
package/bin/serve.js
CHANGED
|
@@ -39,10 +39,11 @@ module.exports = function (config) {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
let sendType = "";
|
|
42
|
+
let entry = headers.Accept !== "*/*";
|
|
42
43
|
|
|
43
44
|
// 如果文件小于10M,认为不大,直接读取
|
|
44
45
|
if (fileInfo.size < 10 * 1024 * 1024) {
|
|
45
|
-
let { source, resolveImport } = resolveImportFactory(basePath, filePath,
|
|
46
|
+
let { source, resolveImport } = resolveImportFactory(basePath, filePath, entry, urlArray[1] === "download")
|
|
46
47
|
|
|
47
48
|
// 只处理非下载文件
|
|
48
49
|
// 过大的也不进行处理
|
|
@@ -52,12 +53,12 @@ module.exports = function (config) {
|
|
|
52
53
|
source = config.module.rules[i].use.call({
|
|
53
54
|
root: basePath, // 服务器根路径
|
|
54
55
|
path: filePath.replace(basePath, ""), // 文件相对路径
|
|
55
|
-
entry
|
|
56
|
-
setFileType(
|
|
57
|
-
|
|
56
|
+
entry, // 是否是浏览器地址栏直接访问
|
|
57
|
+
setFileType(_fileType) { // 设置文件类型
|
|
58
|
+
fileType = _fileType;
|
|
59
|
+
responseHeader['Content-type'] = _fileType + ";charset=utf-8";
|
|
58
60
|
}
|
|
59
61
|
}, source);
|
|
60
|
-
source = resolveImport(source);
|
|
61
62
|
break;
|
|
62
63
|
}
|
|
63
64
|
}
|
|
@@ -65,7 +66,7 @@ module.exports = function (config) {
|
|
|
65
66
|
|
|
66
67
|
sendType = "Read";
|
|
67
68
|
response.writeHead('200', responseHeader);
|
|
68
|
-
response.write(source);
|
|
69
|
+
response.write(resolveImport(source, fileType !== "application/javascript"));
|
|
69
70
|
response.end();
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const { readFileSync, existsSync, lstatSync } = require("fs");
|
|
2
2
|
const { join } = require("path");
|
|
3
3
|
|
|
4
|
-
module.exports = function (basePath, filePath,
|
|
4
|
+
module.exports = function (basePath, filePath, entry, isDownload) {
|
|
5
5
|
let source = readFileSync(filePath);
|
|
6
|
+
let resolveImport = content => content;
|
|
6
7
|
|
|
7
|
-
let
|
|
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, "../");
|
|
@@ -47,15 +60,16 @@ module.exports = function (basePath, filePath, needResolve, isDownload) {
|
|
|
47
60
|
// todo
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
//
|
|
51
|
-
else if (
|
|
52
|
-
source
|
|
63
|
+
// 如果不是直接访问的
|
|
64
|
+
else if (!entry) {
|
|
65
|
+
source += "";
|
|
66
|
+
resolveImport = (content, notResolve) => notResolve ? content : __resolveImport(content);
|
|
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">${
|
|
72
|
+
return `<script type="module">${__resolveImport(_matchCode)}</script>`;
|
|
59
73
|
});
|
|
60
74
|
}
|
|
61
75
|
|
package/nodejs/cmdlog/index.js
CHANGED
package/nodejs/disk/index.js
CHANGED
package/nodejs/logform/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/style/index.js
CHANGED
package/web/throttle/index.js
CHANGED