@ohos-ports/unlighthouse-server 0.0.0-stage → 0.18.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/LICENSE.md +21 -0
- package/README.md +22 -2
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +15 -0
- package/package.json +51 -4
- package/patches/r1-src-chrome-launcher.patch +13 -0
- package/patches/r1-src-core.patch +72 -0
- package/postinstall.js +36 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016-present - Harlan Wilton
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @unlighthouse/server
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The server package for [Unlighthouse](https://github.com/harlan-zw/unlighthouse) that provides the web server and API endpoints for the scanning interface.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { createServer } from '@unlighthouse/server'
|
|
9
|
+
|
|
10
|
+
const { server, app } = await createServer()
|
|
11
|
+
// server is an instance of listhen, app is an instance of h3
|
|
12
|
+
await unlighthouse.setServerContext({ url: server.url, server: server.server, app })
|
|
13
|
+
await unlighthouse.start()
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Documentation
|
|
17
|
+
|
|
18
|
+
- [API Reference](https://unlighthouse.dev/api/index.html)
|
|
19
|
+
- [Configuration Guide](https://unlighthouse.dev/guide/config.html)
|
|
20
|
+
|
|
21
|
+
## License
|
|
22
|
+
|
|
23
|
+
MIT License © 2021-PRESENT [Harlan Wilton](https://github.com/harlan-zw)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a web server and web app to host the unlighthouse client and API on.
|
|
3
|
+
*
|
|
4
|
+
* Some providers, such as Nuxt, do not need this, so this can be safely tree-shaken.
|
|
5
|
+
*/
|
|
6
|
+
declare function createServer(): Promise<{
|
|
7
|
+
app: any;
|
|
8
|
+
server: any;
|
|
9
|
+
}>;
|
|
10
|
+
export { createServer };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useUnlighthouse } from "@unlighthouse/core";
|
|
2
|
+
import { createApp, toNodeListener } from "h3";
|
|
3
|
+
import { listen } from "listhen";
|
|
4
|
+
async function createServer() {
|
|
5
|
+
const { resolvedConfig } = useUnlighthouse();
|
|
6
|
+
const app = createApp();
|
|
7
|
+
return {
|
|
8
|
+
app,
|
|
9
|
+
server: await listen(toNodeListener(app), {
|
|
10
|
+
...resolvedConfig.server,
|
|
11
|
+
open: false
|
|
12
|
+
})
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export { createServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-ports/unlighthouse-server",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.18.0-beta.0",
|
|
5
|
+
"description": "Server for Unlighthouse",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/harlan-zw/unlighthouse#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
11
|
+
"directory": "ports/@unlighthouse/server/0.18.0"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"lighthouse",
|
|
18
|
+
"audit",
|
|
19
|
+
"seo",
|
|
20
|
+
"performance",
|
|
21
|
+
"server",
|
|
22
|
+
"unlighthouse"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.mjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"main": "dist/index.mjs",
|
|
32
|
+
"module": "dist/index.mjs",
|
|
33
|
+
"types": "dist/index.d.ts",
|
|
34
|
+
"files": [
|
|
35
|
+
"*.d.ts",
|
|
36
|
+
"dist",
|
|
37
|
+
"patches",
|
|
38
|
+
"postinstall.js"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=22.18.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"h3": "^1.15.11",
|
|
45
|
+
"listhen": "^1.10.0",
|
|
46
|
+
"@unlighthouse/core": "0.18.0"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "obuild",
|
|
50
|
+
"stub": "obuild --stub",
|
|
51
|
+
"postinstall": "node postinstall.js"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
--- a/node_modules/chrome-launcher/dist/utils.js 2026-09-30 12:19:33.476433594 +0800
|
|
2
|
+
+++ b/node_modules/chrome-launcher/dist/utils.js 2026-09-30 12:14:21.944432813 +0800
|
|
3
|
+
@@ -52,7 +52,9 @@
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export function getPlatform() {
|
|
7
|
+
- return isWsl ? 'wsl' : process.platform;
|
|
8
|
+
+ const platform = isWsl ? 'wsl' : process.platform;
|
|
9
|
+
+ // HarmonyOS (openharmony) uses Linux-compatible Chromium builds
|
|
10
|
+
+ if (platform === 'openharmony') return 'linux';
|
|
11
|
+
return platform;
|
|
12
|
+
}
|
|
13
|
+
export function makeTmpDir() {
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
--- a/node_modules/@unlighthouse/core/dist/index.mjs 2026-09-30 12:19:51.944434688 +0800
|
|
2
|
+
+++ b/node_modules/@unlighthouse/core/dist/index.mjs 2026-09-30 12:16:04.708432657 +0800
|
|
3
|
+
@@ -1651,7 +1651,7 @@
|
|
4
|
+
config.scanner.exclude.push("/cdn-cgi/*");
|
|
5
|
+
config.chrome = defu(config.chrome || {}, {
|
|
6
|
+
useSystem: true,
|
|
7
|
+
- useDownloadFallback: true,
|
|
8
|
+
+ useDownloadFallback: process.platform === "openharmony" ? false : true,
|
|
9
|
+
downloadFallbackCacheDir: join(homedir(), ".unlighthouse")
|
|
10
|
+
});
|
|
11
|
+
if (config.auth) {
|
|
12
|
+
@@ -1697,11 +1697,18 @@
|
|
13
|
+
ignoreHTTPSErrors: true
|
|
14
|
+
});
|
|
15
|
+
config.puppeteerOptions.defaultViewport = config.lighthouseOptions.screenEmulation;
|
|
16
|
+
- if (process.getuid?.() === 0) {
|
|
17
|
+
+ if (process.getuid?.() === 0 || process.platform === "openharmony") {
|
|
18
|
+
config.puppeteerOptions.args = config.puppeteerOptions.args || [];
|
|
19
|
+
if (!config.puppeteerOptions.args.includes("--no-sandbox")) config.puppeteerOptions.args.push("--no-sandbox");
|
|
20
|
+
if (!config.puppeteerOptions.args.includes("--disable-setuid-sandbox")) config.puppeteerOptions.args.push("--disable-setuid-sandbox");
|
|
21
|
+
}
|
|
22
|
+
+ if (process.platform === "openharmony") {
|
|
23
|
+
+ config.puppeteerOptions.args = config.puppeteerOptions.args || [];
|
|
24
|
+
+ if (!config.puppeteerOptions.args.includes("--no-zygote")) config.puppeteerOptions.args.push("--no-zygote");
|
|
25
|
+
+ if (!config.puppeteerOptions.args.includes("--single-process")) config.puppeteerOptions.args.push("--single-process");
|
|
26
|
+
+ if (!config.puppeteerOptions.args.includes("--disable-dev-shm-usage")) config.puppeteerOptions.args.push("--disable-dev-shm-usage");
|
|
27
|
+
+ if (!config.puppeteerOptions.args.includes("--disable-gpu")) config.puppeteerOptions.args.push("--disable-gpu");
|
|
28
|
+
+ }
|
|
29
|
+
let foundChrome = !!config.puppeteerOptions?.executablePath;
|
|
30
|
+
if (config.chrome.useSystem && !foundChrome) {
|
|
31
|
+
let chromePath = false;
|
|
32
|
+
@@ -1721,7 +1728,7 @@
|
|
33
|
+
logger.debug("Testing system Chrome installation.");
|
|
34
|
+
const instance = await launch$1(config.puppeteerOptions).catch((e) => {
|
|
35
|
+
logger.warn(`Failed to launch puppeteer instance using \`${config.puppeteerOptions?.executablePath}\`.`, e);
|
|
36
|
+
-
|
|
37
|
+
+ if (process.platform !== "openharmony") foundChrome = false;
|
|
38
|
+
});
|
|
39
|
+
if (instance) await instance.close();
|
|
40
|
+
}
|
|
41
|
+
@@ -1732,8 +1739,14 @@
|
|
42
|
+
buildId: config.chrome.downloadFallbackVersion || PUPPETEER_REVISIONS.chrome,
|
|
43
|
+
browser: "chrome"
|
|
44
|
+
};
|
|
45
|
+
- const chromePath = computeExecutablePath(browserOptions);
|
|
46
|
+
- if (!existsSync(chromePath)) {
|
|
47
|
+
+ let chromePath;
|
|
48
|
+
+ try {
|
|
49
|
+
+ chromePath = computeExecutablePath(browserOptions);
|
|
50
|
+
+ } catch (e) {
|
|
51
|
+
+ logger.warn(`Cannot compute executable path for platform ${process.platform}. Skipping download fallback.`);
|
|
52
|
+
+ chromePath = null;
|
|
53
|
+
+ }
|
|
54
|
+
+ if (chromePath && !existsSync(chromePath)) {
|
|
55
|
+
logger.info(`Missing ${browserOptions.browser} binary, downloading v${browserOptions.buildId}...`);
|
|
56
|
+
let lastPercent = 0;
|
|
57
|
+
await install({
|
|
58
|
+
@@ -1747,9 +1760,11 @@
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
- logger.info(`Using downloaded ${browserOptions.browser} v${browserOptions.buildId} located at: ${chromePath}`);
|
|
63
|
+
- config.puppeteerOptions.executablePath = chromePath;
|
|
64
|
+
- foundChrome = true;
|
|
65
|
+
+ if (chromePath) {
|
|
66
|
+
+ logger.info(`Using downloaded ${browserOptions.browser} v${browserOptions.buildId} located at: ${chromePath}`);
|
|
67
|
+
+ config.puppeteerOptions.executablePath = chromePath;
|
|
68
|
+
+ foundChrome = true;
|
|
69
|
+
+ }
|
|
70
|
+
}
|
|
71
|
+
if (!foundChrome) throw new Error("Failed to find chrome. Please ensure you have a valid chrome installed.");
|
|
72
|
+
const instance = await launch$1(config.puppeteerOptions).catch((e) => {
|
package/postinstall.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const { execSync } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
|
|
6
|
+
// Find project node_modules by walking up from package dir
|
|
7
|
+
function findNodeModules(startDir) {
|
|
8
|
+
let dir = startDir;
|
|
9
|
+
for (let i = 0; i < 10; i++) {
|
|
10
|
+
const candidate = path.join(dir, 'node_modules');
|
|
11
|
+
if (fs.existsSync(candidate)) return dir;
|
|
12
|
+
const parent = path.dirname(dir);
|
|
13
|
+
if (parent === dir) break;
|
|
14
|
+
dir = parent;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const pkgDir = __dirname;
|
|
20
|
+
const projectRoot = findNodeModules(pkgDir) || path.dirname(pkgDir);
|
|
21
|
+
|
|
22
|
+
const patches = [
|
|
23
|
+
{ patch: path.join(pkgDir, 'patches', 'r1-src-chrome-launcher.patch'), target: 'chrome-launcher/dist/utils.js' },
|
|
24
|
+
{ patch: path.join(pkgDir, 'patches', 'r1-src-core.patch'), target: '@unlighthouse/core/dist/index.mjs' }
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
for (const { patch, target } of patches) {
|
|
28
|
+
if (!fs.existsSync(patch)) continue;
|
|
29
|
+
const targetFile = path.join(projectRoot, 'node_modules', target);
|
|
30
|
+
if (!fs.existsSync(targetFile)) continue;
|
|
31
|
+
try {
|
|
32
|
+
execSync(`patch -p1 < "${patch}"`, { cwd: path.join(projectRoot, 'node_modules'), stdio: 'inherit' });
|
|
33
|
+
} catch (e) {
|
|
34
|
+
// Already patched or patch failed - continue silently
|
|
35
|
+
}
|
|
36
|
+
}
|