@oipage/cli 1.0.0-alpha.0 → 1.0.0-alpha.1
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
|
@@ -4,7 +4,7 @@ const { createServer } = require('http');
|
|
|
4
4
|
const { gzipSync, createGzip } = require("zlib");
|
|
5
5
|
const packageValue = require("../package.json");
|
|
6
6
|
const network = require("./tools/network.js");
|
|
7
|
-
const
|
|
7
|
+
const mimeTypes = require("./data/mimeTypes.json");
|
|
8
8
|
const resolveImportFactory = require("./tools/resolveImport.js");
|
|
9
9
|
const { replaceInCode } = require("./tools/moduleForm.js");
|
|
10
10
|
const openBrowser = require("./tools/openBrowser.js");
|
|
@@ -239,7 +239,7 @@ module.exports = function (config) {
|
|
|
239
239
|
const isCjsShim = /(^|&)oipage=cjs($|&)/.test(query);
|
|
240
240
|
|
|
241
241
|
let dotName = (filePath.match(/\.([^.]+)$/) || [])[1] || "";
|
|
242
|
-
let fileType =
|
|
242
|
+
let fileType = mimeTypes[dotName]; // 文件类型
|
|
243
243
|
let fileInfo = statSync(filePath);
|
|
244
244
|
|
|
245
245
|
let fileModifiedTime = new Date(fileInfo.mtime).toGMTString();
|
package/bin/tools/isBinary.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { openSync, readSync, closeSync } = require("fs");
|
|
2
|
-
const
|
|
2
|
+
const mimeTypes = require("../data/mimeTypes.json");
|
|
3
3
|
|
|
4
4
|
// 读取文件头部用于判断的字节数
|
|
5
5
|
const CHECK_BYTES = 4096;
|
|
@@ -25,7 +25,7 @@ const TEXT_TYPES = new Set([
|
|
|
25
25
|
*/
|
|
26
26
|
function isBinaryByExtension(filepath) {
|
|
27
27
|
const dotName = (filepath.match(/\.([^.]+)$/) || [])[1] || "";
|
|
28
|
-
const fileType =
|
|
28
|
+
const fileType = mimeTypes[dotName];
|
|
29
29
|
|
|
30
30
|
if (!fileType) {
|
|
31
31
|
// 未知类型默认视为二进制
|
package/bin/tools/resolve404.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { readdirSync, lstatSync, readFileSync, statSync } = require("fs");
|
|
2
2
|
const { join } = require("path");
|
|
3
3
|
const { formatByte, formatTime } = require("./format");
|
|
4
|
-
const
|
|
4
|
+
const mimeTypes = require("../data/mimeTypes.json");
|
|
5
5
|
|
|
6
6
|
// HTML 实体转义,防止 XSS
|
|
7
7
|
function escapeHtml(str) {
|
|
@@ -82,7 +82,7 @@ module.exports = function (filePath, url, website, name, rawIp) {
|
|
|
82
82
|
${formatTime(statObj.mtime)}
|
|
83
83
|
</th>
|
|
84
84
|
<th>
|
|
85
|
-
${
|
|
85
|
+
${mimeTypes[dotName] || "text/plain"}
|
|
86
86
|
</th>
|
|
87
87
|
<th>
|
|
88
88
|
${formatByte(statObj.size)}
|
package/package.json
CHANGED
|
File without changes
|