@allurereport/static-server 3.3.1 → 3.4.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/dist/index.js +8 -3
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +32 -0
- package/package.json +14 -25
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import watchDirectory from "@allurereport/directory-watcher";
|
|
2
1
|
import * as console from "node:console";
|
|
3
2
|
import { createReadStream } from "node:fs";
|
|
4
3
|
import { readFile, readdir, stat } from "node:fs/promises";
|
|
5
4
|
import { createServer } from "node:http";
|
|
6
5
|
import { basename, extname, join, resolve } from "node:path";
|
|
7
6
|
import { cwd } from "node:process";
|
|
7
|
+
import watchDirectory from "@allurereport/directory-watcher";
|
|
8
8
|
import openUrl from "open";
|
|
9
|
-
import { TYPES_BY_EXTENSION, identity, injectLiveReloadScript } from "./utils.js";
|
|
9
|
+
import { TYPES_BY_EXTENSION, identity, injectLiveReloadScript, resolveUrlPathnameUnderServeRoot } from "./utils.js";
|
|
10
10
|
export const renderDirectory = async (entries, dirPath) => {
|
|
11
11
|
const links = [];
|
|
12
12
|
const files = [];
|
|
@@ -68,7 +68,12 @@ export const serve = async (options) => {
|
|
|
68
68
|
});
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
const resolvedPublic = resolveUrlPathnameUnderServeRoot(pathToServe, pathname);
|
|
72
|
+
if (resolvedPublic === null) {
|
|
73
|
+
res.writeHead(404);
|
|
74
|
+
return res.end();
|
|
75
|
+
}
|
|
76
|
+
let fsPath = resolvedPublic;
|
|
72
77
|
let stats;
|
|
73
78
|
try {
|
|
74
79
|
stats = await stat(fsPath);
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export declare const EXTENSIONS_BY_TYPE: Record<string, string>;
|
|
|
2
2
|
export declare const TYPES_BY_EXTENSION: Record<string, string>;
|
|
3
3
|
export declare const identity: <T>(value?: T) => T | undefined;
|
|
4
4
|
export declare const injectLiveReloadScript: (html: string) => string;
|
|
5
|
+
export declare function resolveUrlPathnameUnderServeRoot(rootDir: string, urlPathname: string): string | null;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve, sep } from "node:path";
|
|
1
2
|
const ALLURE_LIVE_RELOAD_HASH_STORAGE_KEY = "__allure_report_live_reload_hash__";
|
|
2
3
|
export const EXTENSIONS_BY_TYPE = {
|
|
3
4
|
"application/andrew-inset": ".ez",
|
|
@@ -913,3 +914,34 @@ export const injectLiveReloadScript = (html) => {
|
|
|
913
914
|
`;
|
|
914
915
|
return html.replace("</body>", `${liveReloadScript}</body>`);
|
|
915
916
|
};
|
|
917
|
+
function isPathContainedInServeRoot(rootDir, candidatePath) {
|
|
918
|
+
const rootResolved = resolve(rootDir);
|
|
919
|
+
const candidateResolved = resolve(candidatePath);
|
|
920
|
+
if (process.platform === "win32") {
|
|
921
|
+
const rootLower = rootResolved.toLowerCase();
|
|
922
|
+
const candLower = candidateResolved.toLowerCase();
|
|
923
|
+
const prefix = rootLower.endsWith("\\") ? rootLower : `${rootLower}\\`;
|
|
924
|
+
return candLower === rootLower || candLower.startsWith(prefix);
|
|
925
|
+
}
|
|
926
|
+
const prefix = rootResolved.endsWith(sep) ? rootResolved : `${rootResolved}${sep}`;
|
|
927
|
+
return candidateResolved === rootResolved || candidateResolved.startsWith(prefix);
|
|
928
|
+
}
|
|
929
|
+
export function resolveUrlPathnameUnderServeRoot(rootDir, urlPathname) {
|
|
930
|
+
let decoded;
|
|
931
|
+
try {
|
|
932
|
+
decoded = decodeURI(urlPathname);
|
|
933
|
+
}
|
|
934
|
+
catch {
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
if (decoded.includes("\0")) {
|
|
938
|
+
return null;
|
|
939
|
+
}
|
|
940
|
+
const relative = decoded.replace(/^[/\\]+/, "");
|
|
941
|
+
const rootResolved = resolve(rootDir);
|
|
942
|
+
const candidate = resolve(rootResolved, relative);
|
|
943
|
+
if (!isPathContainedInServeRoot(rootResolved, candidate)) {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
return candidate;
|
|
947
|
+
}
|
package/package.json
CHANGED
|
@@ -1,60 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allurereport/static-server",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Minimalistic web-server for serving static files",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"allure",
|
|
7
|
-
"testing",
|
|
8
|
-
"web",
|
|
9
7
|
"http",
|
|
10
|
-
"server"
|
|
8
|
+
"server",
|
|
9
|
+
"testing",
|
|
10
|
+
"web"
|
|
11
11
|
],
|
|
12
|
-
"repository": "https://github.com/allure-framework/allure3",
|
|
13
12
|
"license": "Apache-2.0",
|
|
14
13
|
"author": "Qameta Software",
|
|
14
|
+
"repository": "https://github.com/allure-framework/allure3",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
15
18
|
"type": "module",
|
|
19
|
+
"module": "dist/index.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
16
21
|
"exports": {
|
|
17
22
|
".": "./dist/index.js"
|
|
18
23
|
},
|
|
19
|
-
"module": "dist/index.js",
|
|
20
|
-
"types": "dist/index.d.ts",
|
|
21
|
-
"files": [
|
|
22
|
-
"dist"
|
|
23
|
-
],
|
|
24
24
|
"scripts": {
|
|
25
25
|
"build": "run clean && tsc --project ./tsconfig.json",
|
|
26
26
|
"clean": "rimraf ./dist",
|
|
27
27
|
"pretest": "rimraf ./out",
|
|
28
28
|
"test": "run-p 'test:*'",
|
|
29
29
|
"test:unit": "vitest run",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
30
|
+
"test:e2e": "playwright test",
|
|
31
|
+
"lint": "oxlint --import-plugin src test features stories",
|
|
32
|
+
"lint:fix": "oxlint --import-plugin --fix src test features stories"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@allurereport/directory-watcher": "3.
|
|
35
|
+
"@allurereport/directory-watcher": "3.4.0",
|
|
36
36
|
"open": "^10.1.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@playwright/test": "^1.56.1",
|
|
40
|
-
"@stylistic/eslint-plugin": "^2.6.1",
|
|
41
|
-
"@types/eslint": "^8.56.11",
|
|
42
40
|
"@types/node": "^20.17.9",
|
|
43
|
-
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
44
|
-
"@typescript-eslint/parser": "^8.0.0",
|
|
45
41
|
"@vitest/runner": "^2.1.9",
|
|
46
42
|
"@vitest/snapshot": "^2.1.9",
|
|
47
43
|
"allure-js-commons": "^3.3.3",
|
|
48
44
|
"allure-playwright": "^3.3.3",
|
|
49
45
|
"allure-vitest": "^3.3.3",
|
|
50
46
|
"axios": "^1.13.5",
|
|
51
|
-
"eslint": "^8.57.0",
|
|
52
|
-
"eslint-config-prettier": "^9.1.0",
|
|
53
|
-
"eslint-plugin-import": "^2.29.1",
|
|
54
|
-
"eslint-plugin-jsdoc": "^50.0.0",
|
|
55
|
-
"eslint-plugin-n": "^17.10.1",
|
|
56
|
-
"eslint-plugin-no-null": "^1.0.2",
|
|
57
|
-
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
58
47
|
"get-port": "^7.1.0",
|
|
59
48
|
"npm-run-all2": "^7.0.1",
|
|
60
49
|
"rimraf": "^6.0.1",
|