dontmakeitugly 0.1.0 → 0.1.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/README.md +1 -1
- package/dist/check.js +23 -6
- package/dist/cli.js +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,4 +22,4 @@ npx dontmakeitugly check # .dmiu/report.md for the agent t
|
|
|
22
22
|
|
|
23
23
|
Skip an element and its subtree with `data-design-check="ignore"`, or add selectors to `ignore` in `dmiu.config.json`.
|
|
24
24
|
|
|
25
|
-
Chromium
|
|
25
|
+
The first `check` installs a headless Chromium for Playwright (about 200 MB) if it isn't already there.
|
package/dist/check.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
3
5
|
import { chromium } from "playwright";
|
|
4
6
|
import { loadConfig } from "./config.js";
|
|
5
7
|
import { loadContract } from "./contract.js";
|
|
@@ -10,16 +12,31 @@ import { summarise, writeReport } from "./report.js";
|
|
|
10
12
|
function slugify(s) {
|
|
11
13
|
return s.replace(/^\//, "").replace(/[^a-z0-9]+/gi, "-").replace(/^-|-$/g, "") || "home";
|
|
12
14
|
}
|
|
13
|
-
|
|
15
|
+
function isMissingBrowser(e) {
|
|
16
|
+
return /Executable doesn't exist|browserType\.launch|playwright install/.test(e.message ?? "");
|
|
17
|
+
}
|
|
18
|
+
/** Installs the Chromium build that this copy of Playwright expects. */
|
|
19
|
+
function installChromium(log) {
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
// "playwright/cli" is not an exported subpath; go via the package root.
|
|
22
|
+
const cli = path.join(path.dirname(require.resolve("playwright/package.json")), "cli.js");
|
|
23
|
+
log("Chromium is not installed for Playwright yet. Installing the headless build once (about 200 MB)…");
|
|
24
|
+
execFileSync(process.execPath, [cli, "install", "chromium", "--only-shell"], { stdio: "inherit" });
|
|
25
|
+
}
|
|
26
|
+
async function launch(log) {
|
|
14
27
|
try {
|
|
15
28
|
return await chromium.launch();
|
|
16
29
|
}
|
|
17
30
|
catch (e) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
if (!isMissingBrowser(e))
|
|
32
|
+
throw e;
|
|
33
|
+
try {
|
|
34
|
+
installChromium(log);
|
|
35
|
+
}
|
|
36
|
+
catch (installError) {
|
|
37
|
+
throw new Error(`Chromium could not be installed automatically (${installError.message.split("\n")[0]}). Run: npx playwright install chromium`);
|
|
21
38
|
}
|
|
22
|
-
|
|
39
|
+
return chromium.launch();
|
|
23
40
|
}
|
|
24
41
|
}
|
|
25
42
|
async function reachable(url) {
|
|
@@ -52,7 +69,7 @@ export async function runCheck(opts) {
|
|
|
52
69
|
const outDir = path.resolve(opts.cwd, cfg.outDir);
|
|
53
70
|
const shotsDir = path.join(outDir, "screenshots");
|
|
54
71
|
fs.mkdirSync(shotsDir, { recursive: true });
|
|
55
|
-
const browser = await launch();
|
|
72
|
+
const browser = await launch(log);
|
|
56
73
|
const pages = [];
|
|
57
74
|
try {
|
|
58
75
|
for (const vp of cfg.viewports) {
|
package/dist/cli.js
CHANGED
|
@@ -53,8 +53,7 @@ async function main() {
|
|
|
53
53
|
log(` kept ${s} (already exists; use --force to overwrite)`);
|
|
54
54
|
log("");
|
|
55
55
|
log("Next: build with your agent, then start the dev server and run `npx dontmakeitugly check`.");
|
|
56
|
-
if
|
|
57
|
-
log("If Chromium isn't installed for Playwright yet: npx playwright install chromium");
|
|
56
|
+
log("The first check installs a headless Chromium for Playwright (about 200 MB) if it isn't there yet.");
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
59
|
if (cmd === "check") {
|