Skip to content

Commit

Permalink
Support live debugging, fix aero's config, start working on Feature F…
Browse files Browse the repository at this point in the history
…lags for aero, move config.ts into src, fix bugs, comment out broken code, and much more
  • Loading branch information
MovByte committed Jul 28, 2024
1 parent aae1d77 commit ecd78dd
Show file tree
Hide file tree
Showing 73 changed files with 840 additions and 541 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
## For NixOS
mutable_node_modules

# Rspack
# Builds
/**/dist/
/tests/aero

# aero

Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/node_modules": false,
"**/.circleci": false,
"**/.compodocrc*": false,
"**/.editorconfig": false,
Expand Down
5 changes: 5 additions & 0 deletions .vsls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json.schemastore.org/vsls",
"gitignore": "exclude",
"excludeFiles": ["!node_modules"]
}
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,26 @@ Web Proxies can be used for:
```
npm i
npm run build
cd src/AeroSandbox
npm i
npm run build
```

> Ensure to build AeroSandbox separately
## How to debug aero

1. Install pm2
2. Execute these commands

```
./deps.sh
pm2 start ecosystem.config.js
```

### Notes

* You must run `pm2 restart <aero-build-watch/aero-sandbox-build-watch>` when you modify a compile-time Feature Flag

## How to run unit tests

## Related

Expand Down
38 changes: 38 additions & 0 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const config = {
buildForUnitTests: true
};

module.exports = {
apps: [
{
name: "aero-dev-server",
script: "dev-server/app.js"
},
{
name: "aero-build-watch",
script: "npm",
args: "run build",
env: {
DEBUG: ""
}
},
{
name: "aero-sandbox-build-watch",
script: "npm",
cwd: "src/AeroSandbox",
args: "run build",
env: {
DEBUG: ""
}
},
{
name: "aero-sandbox-for-unit-tests-build-watch",
script: "npm",
cwd: "src/AeroSandbox",
args: "run build",
env: {
TEST_BUILD: ""
}
}
]
};
89 changes: 40 additions & 49 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
{
"name": "aero-proxy",
"version": "0.0.2",
"description": "The innovative interception proxy (alpha)",
"main": "dist/sw.aero.js",
"files": [
"dist/sw.aero.js",
"dist/sw.aero.js.map"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rspack build -c rspack.config.ts",
"buildDebug": "rspack --stats-error-detail --watch --info-verbosity",
"format": "biome format --write .",
"lint": "biome lint --write ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/ProxyHaven/aero.git"
},
"keywords": [
"Proxy",
"Archiver",
"Unblock",
"Interception"
],
"author": "Ryan Wilson",
"license": "AGPL-3.0-or-later",
"homepage": "https://github.com/ProxyHaven/aero#readme",
"devDependencies": {
"@biomejs/biome": "^1.3.3",
"@rsdoctor/rspack-plugin": "^0.3.9",
"@rspack/cli": "^0.7.5",
"@rspack/core": "^0.7.5",
"@types/chrome": "^0.0.237",
"@types/serviceworker": "^0.0.89",
"@types/web-app-manifest": "^1.0.8",
"clean-webpack-plugin": "^4.0.0",
"typescript": "^5.0.4",
"webpack-bundle-analyzer": "^4.10.2"
},
"dependencies": {
"@mercuryworkshop/bare-as-module3": "^2.2.2",
"@mercuryworkshop/bare-mux": "^2.0.2",
"esbuild-loader": "^4.0.1",
"esbuild-wasm": "^0.23.0",
"esniff": "^2.0.1",
"seafox": "^1.7.1",
"traverse-the-universe": "^2.1.2"
}
"name": "aero-proxy",
"version": "0.0.2",
"description": "The innovative interception proxy (alpha)",
"main": "dist/sw.aero.js",
"files": ["dist/sw.aero.js", "dist/sw.aero.js.map"],
"scripts": {
"build": "rspack build -c rspack.config.ts",
"buildDebug": "rspack --stats-error-detail --watch --info-verbosity",
"format": "biome format --write .",
"lint": "biome lint --write ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/ProxyHaven/aero.git"
},
"keywords": ["Proxy", "Archiver", "Unblock", "Interception"],
"author": "Ryan Wilson",
"license": "AGPL-3.0-or-later",
"homepage": "https://github.com/ProxyHaven/aero#readme",
"devDependencies": {
"@biomejs/biome": "^1.3.3",
"@rsdoctor/rspack-plugin": "^0.3.9",
"@rspack/cli": "^0.7.5",
"@rspack/core": "^0.7.5",
"@types/chrome": "^0.0.237",
"@types/serviceworker": "^0.0.89",
"@types/web-app-manifest": "^1.0.8",
"clean-webpack-plugin": "^4.0.0",
"typescript": "^5.0.4",
"webpack-bundle-analyzer": "^4.10.2"
},
"dependencies": {
"@mercuryworkshop/bare-as-module3": "^2.2.2",
"@mercuryworkshop/bare-mux": "^2.0.2",
"esbuild-loader": "^4.0.1",
"esbuild-wasm": "^0.23.0",
"esniff": "^2.0.1",
"seafox": "^1.7.1",
"traverse-the-universe": "^2.1.2"
}
}
64 changes: 41 additions & 23 deletions rspack.config.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
import { boolFlag, FeatureFlags } from "./src/featureFlags";

import path from "path";
import rspack from "@rspack/core";

import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin";
import { CleanWebpackPlugin } from "clean-webpack-plugin";

const debugMode = process.env.DEBUG;
const debugMode = "DEBUG" in process.env;

const webpackFeatureFlags: FeatureFlags = {
FEATURE_URL_ENC: boolFlag(false),
FEATURE_CORS_EMULATION: boolFlag(false),
FEATURE_INTEGRITY_EMULATION: boolFlag(false),
FEATURE_ENC_BODY_EMULATION: boolFlag(false),
FEATURE_CACHES_EMULATION: boolFlag(false),
FEATURE_CLEAR_EMULATION: boolFlag(false),
REWRITER_HTML: boolFlag(false),
REWRITER_XSLT: boolFlag(false),
REWRITER_JS: boolFlag(false),
REWRITER_CACHE_MANIFEST: boolFlag(false),
SUPPORT_LEGACY: boolFlag(false),
SUPPORT_WORKER: boolFlag(false),
DEBUG: JSON.stringify(debugMode)
};

// biome-ignore lint/suspicious/noExplicitAny: <explanation>
const plugins: any[] = [
const plugins: any = [
// @ts-ignore
new CleanWebpackPlugin(),
new rspack.DefinePlugin({
// Webpack Feature Flags
FEATURE_CORS_EMULATION: JSON.stringify(false),
FEATURE_INTEGRITY_EMULATION: JSON.stringify(false),
FEATURE_ENC_BODY_EMULATION: JSON.stringify(false),
FEATURE_CACHES_EMULATION: JSON.stringify(false),
FEATURE_CLEAR_EMULATION: JSON.stringify(false),
REWRITER_HTML: JSON.stringify(false),
REWRITER_XSLT: JSON.stringify(false),
REWRITER_JS: JSON.stringify(false),
REWRITER_CACHE_MANIFEST: JSON.stringify(false),
SUPPORT_LEGACY: JSON.stringify(false),
SUPPORT_WORKER: JSON.stringify(false),
DEBUG: JSON.stringify(false)
})
// @ts-ignore
new rspack.DefinePlugin(webpackFeatureFlags)
];

if (debugMode)
Expand All @@ -33,9 +39,12 @@ if (debugMode)
})
);

export default {
const config: rspack.Configuration = {
mode: debugMode ? "development" : "production",
entry: "./src/this/handle.ts",
entry: {
sw: path.resolve(__dirname, "./src/this/handle.ts"),
config: path.resolve(__dirname, "./src/config.ts")
},
plugins,
resolve: {
extensions: [".ts"],
Expand All @@ -51,7 +60,16 @@ export default {
]
},
output: {
filename: "sw.aero.js",
path: path.resolve(__dirname, "dist")
}
} as rspack.Configuration;
filename: "[name].aero.js",
path: debugMode
? path.resolve(__dirname, "dev-server/aero-demo-site/aero")
: path.resolve(__dirname, "dist"),
iife: true,
clean: true
},
target: "webworker"
};

if (debugMode) config.watch = true;

export default config;
4 changes: 1 addition & 3 deletions rspack.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
"baseUrl": "./",
"lib": ["ESNext"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"paths": {},
"types": []
"esModuleInterop": true
},
"include": ["./webpack.config.ts"],
"exclude": ["node_modules"]
Expand Down
2 changes: 2 additions & 0 deletions src/AeroSandbox/build/AeroSandbox.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// TODO: This will be the runtime version of AeroSandbox

export default class AeroSandboxRuntime {}
2 changes: 2 additions & 0 deletions src/AeroSandbox/build/AeroSandboxBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AeroSandboxConfig } from "../types/aeroSandbox";

export default class AeroSandbox {
config: AeroSandboxConfig;
fakeOrigin(
Expand Down
4 changes: 1 addition & 3 deletions src/AeroSandbox/build/customBuilds/aero.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { defaultSWProxyFeatures } from "../featureMembers";

import config from "$aero/config";

import AeroSandbox from "../AeroSandboxBuilder";

const buildConfig = {
proxyConfig: {
...config
...self.config
},
specialInterceptionFeatures: defaultSWProxyFeatures
};
Expand Down
45 changes: 45 additions & 0 deletions src/AeroSandbox/build/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { htmlRewriterMode } from "../types/rewriters/html";

export type boolFlagType = "true" | "false";

export interface FeatureFlags {
// JS Rewriter
INCLUDE_ESNIFF: boolFlagType;
INCLUDE_AST_PARSER_SEAFOX: boolFlagType;
/** @warning currently unsupported */
INCLUDE_AST_PARSER_OXC: boolFlagType;
INCLUDE_AST_WALKER_TRAVERSE_THE_UNIVERSE: boolFlagType;
/** @warning `custom_elements` is currently unsupported */
SUPPORTED_HTML_REWRITER_MODES: string;
/** @warning currently unsupported */
HTML_USE_IS_ATTR: boolFlagType;
/** @warning currently unsupported */
HTML_USE_NAV_EVENTS: boolFlagType;
/** @warning currently unsupported */
FEATURE_EMU_SECURE_CONTEXT: boolFlagType;
/**
* TODO: This will make the URL proceed after the hash, evading all peeping by extension filters.
* @warning currently unsupported */
FEATURE_HASH_URL: boolFlagType;
DEBUG: boolFlagType;
}

export interface FeatureFlagsRuntime extends FeatureFlags {
// JS Rewriter
INCLUDE_ESNIFF: boolFlagType;
INCLUDE_AST_PARSER_SEAFOX: boolFlagType;
/** @warning currently unsupported */
INCLUDE_AST_PARSER_OXC: boolFlagType;
INCLUDE_AST_WALKER_TRAVERSE_THE_UNIVERSE: boolFlagType;
/** @warning `custom_elements` is currently unsupported */
HTML_REWRITER_MODE: htmlRewriterMode;
/** @warning currently unsupported */
HTML_USE_IS_ATTR: boolFlagType;
/** @warning currently unsupported */
HTML_USE_NAV_EVENTS: boolFlagType;
DEBUG: boolFlagType;
}

export function boolFlag(bool: boolean): boolFlagType {
return bool ? "true" : "false";
}
29 changes: 29 additions & 0 deletions src/AeroSandbox/build/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ import {
proxifiedObjGeneratorContext
} from "../types";

import { htmlRewriterMode } from "../types/rewriters/html";

import { buildConfig } from "./customBuilds/aero";
import { buildConfig as buildConfigFrakenUV } from "./customBuilds/frankenUV.inject.ts";

import { config } from "../src/config.ts";
import { FeatureFlags } from "./featureFlags";

declare const HTML_REWRITER_MODE: htmlRewriterMode;

let proxifiedObjGenCtx: proxifiedObjGeneratorContext = {
...buildConfig.specialInterceptionFeatures
};
Expand Down Expand Up @@ -97,3 +104,25 @@ function resolveProxifiedObj(
else if (typeof proxifiedObj === "object") proxyObject = proxifiedObj;
return proxyObject;
}

// Run the HTML Interceptors as per the config
const supportedHTMLRewriterModes: string[] = JSON.parse(
// @ts-ignore
SUPPORTED_HTML_REWRITER_MODES
);

const preferredMode = config.FeatureFlags.HTML_REWRITER_MODE;
if (!supportedHTMLRewriterModes.includes(preferredMode)) {
throw new Error(
`This build of AeroSandbox does not support ${preferredMode}`
);
}

if (preferredMode === "mutation_observer")
import("../src/sandboxers/HTML/adaptors/useMutationObservers.ts");
if (preferredMode === "custom_elements")
throw new Error("Unsupported rewriter mode!");
if (preferredMode === "domparser")
import("../src/sandboxers/HTML/adaptors/useDOMParser.ts");
if (preferredMode === "sw_parser")
import("../src/sandboxers/HTML/adaptors/useParser.ts");
Loading

0 comments on commit ecd78dd

Please sign in to comment.