Skip to content

Commit

Permalink
[FB] Build | add puppeteer to launch browser
Browse files Browse the repository at this point in the history
  • Loading branch information
nyanrus committed May 30, 2024
1 parent 5eb9f67 commit 774194a
Show file tree
Hide file tree
Showing 8 changed files with 989 additions and 1,962 deletions.
3 changes: 2 additions & 1 deletion nora/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/node_modules/
/node_modules/
/dist/profile/
2 changes: 1 addition & 1 deletion nora/dist/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ floorp.jar:
nora/csk.js (csk.js)
nora/content.js (content.js)
nora/assets/utils.js (assets/utils.js)
nora/content.js.map (content.js.map)
nora/csk.js.map (csk.js.map)
nora/content.js.map (content.js.map)
nora/assets/utils.js.map (assets/utils.js.map)
2 changes: 2 additions & 0 deletions nora/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"license": "MPL-2.0",
"type": "module",
"devDependencies": {
"execa": "^9.1.0",
"puppeteer-core": "^22.10.0",
"solid-styled-jsx": "^0.27.1",
"tsx": "^4.10.1",
"vite": "^5.2.11",
Expand Down
871 changes: 863 additions & 8 deletions nora/pnpm-lock.yaml

Large diffs are not rendered by default.

15 changes: 6 additions & 9 deletions nora/scripts/gen_jarmn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ export async function generateJarManifest(bundle: object) {
for (const i of Object.values(viteManifest)) {
arr.push((i as { fileName: string })["fileName"]);
}

await fs.writeFile(
"dist/jar.mn",
`floorp.jar:\n% content nora %nora/ contentaccessible=yes\n ${Array.from(
new Set(arr),
)
.map((v) => `nora/${v} (${v})`)
.join("\n ")}`,
);
console.log("generate end jar.mn");

return `floorp.jar:\n% content nora %nora/ contentaccessible=yes\n ${Array.from(
new Set(arr),
)
.map((v) => `nora/${v} (${v})`)
.join("\n ")}`;
}
59 changes: 57 additions & 2 deletions nora/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,25 @@

import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
import { $ } from "execa";

import * as path from "node:path";
import { generateJarManifest } from "./scripts/gen_jarmn";
import puppeteer from "puppeteer-core";
import { Browser } from "puppeteer-core";

const r = (dir: string) => {
return path.resolve(import.meta.dirname, dir);
};

function binPath(platform: "windows-x64"): string {
switch (platform) {
case "windows-x64": {
return "obj-x86_64-pc-windows-msvc/dist/bin/floorp.exe";
}
}
}

export default defineConfig({
publicDir: r("public"),
build: {
Expand Down Expand Up @@ -44,10 +55,54 @@ export default defineConfig({
}),
{
name: "gen_jarmn",
generateBundle(options, bundle, isWrite) {
generateJarManifest(bundle);
enforce: "post",
async generateBundle(options, bundle, isWrite) {
this.emitFile({
type: "asset",
fileName: "jar.mn",
needsCodeReference: false,
source: await generateJarManifest(bundle),
});
},
},
(() => {
let browser: Browser;
let intended_close = false;
return {
name: "run_browser",
enforce: "post",
buildEnd(error) {
(async () => {
if (this.meta.watchMode) {
if (browser) {
console.log("Browser Restarting...");
intended_close = true;
await browser.close();
intended_close = false;
}
const _cwd = process.cwd();
process.chdir("../..");
await $({ stdio: "inherit" })`./mach build faster`;
process.chdir(_cwd);

browser = await puppeteer.launch({
headless: false,
protocol: "webDriverBiDi",
dumpio: true,
product: "firefox",
executablePath: binPath("windows-x64"),
userDataDir: "./dist/profile/test",
extraPrefsFirefox: { "browser.newtabpage.enabled": true },
});
(await browser.pages())[0].goto("about:newtab");
browser.on("disconnected", () => {
if (!intended_close) process.exit(1);
});
}
})();
},
};
})(),
],
resolve: {
alias: {
Expand Down
13 changes: 2 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-mozilla": "^3.3.2",
"prettier": "^3.1.1",
"solid-styled-jsx": "^0.27.1",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"unocss": "^0.60.2",
"vite": "^5.2.11"
"prettier": "^3.1.1"
},
"private": true,
"dependencies": {
"solid-js": "^1.8.17",
"zod": "^3.23.8"
}
"private": true
}
Loading

0 comments on commit 774194a

Please sign in to comment.