diff --git a/package.json b/package.json index 4388c15..5875588 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "scripts": { "build": "rollup -c", "dev": "node server.js", + "temp": "rollup -c -w", "prepublish": "pnpm build", "pub": "pnpm publish --no-git-checks --access public" }, @@ -28,6 +29,7 @@ "@mercuryworkshop/libcurl-transport": "^1.3.6", "@rollup/plugin-inject": "^5.0.5", "@rollup/plugin-replace": "^5.0.5", + "@rollup/plugin-node-resolve": "^15.2.3", "@tomphttp/bare-server-node": "^2.0.3", "@types/eslint": "^8.56.10", "@types/estree": "^1.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12f2fab..88d8867 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,9 @@ importers: '@rollup/plugin-inject': specifier: ^5.0.5 version: 5.0.5(rollup@4.17.2) + '@rollup/plugin-node-resolve': + specifier: ^15.2.3 + version: 15.2.3(rollup@4.17.2) '@rollup/plugin-replace': specifier: ^5.0.5 version: 5.0.7(rollup@4.17.2) @@ -201,6 +204,15 @@ packages: rollup: optional: true + '@rollup/plugin-node-resolve@15.2.3': + resolution: {integrity: sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^2.78.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/plugin-replace@5.0.7': resolution: {integrity: sha512-PqxSfuorkHz/SPpyngLyg5GCEkOcee9M1bkxiVDr41Pd61mqP1PLOoDPbpl44SB2mQGKwV/In74gqQmGITOhEQ==} engines: {node: '>=14.0.0'} @@ -323,6 +335,9 @@ packages: '@types/resolve@0.0.8': resolution: {integrity: sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==} + '@types/resolve@1.20.2': + resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} + '@types/semver@7.5.8': resolution: {integrity: sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==} @@ -551,6 +566,10 @@ packages: deep-is@0.1.4: resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==} + deepmerge@4.3.1: + resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} + engines: {node: '>=0.10.0'} + depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -819,6 +838,10 @@ packages: resolution: {integrity: sha512-Ag3wB2o37wslZS19hZqorUnrnzSkpOVy+IiiDEiTqNubEYpYuHWIf6K4psgN2ZWKExS4xhVCrRVfb/wfW8fWJA==} engines: {node: '>= 10'} + is-builtin-module@3.2.1: + resolution: {integrity: sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==} + engines: {node: '>=6'} + is-core-module@2.13.1: resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==} @@ -1429,6 +1452,17 @@ snapshots: optionalDependencies: rollup: 4.17.2 + '@rollup/plugin-node-resolve@15.2.3(rollup@4.17.2)': + dependencies: + '@rollup/pluginutils': 5.1.0(rollup@4.17.2) + '@types/resolve': 1.20.2 + deepmerge: 4.3.1 + is-builtin-module: 3.2.1 + is-module: 1.0.0 + resolve: 1.22.8 + optionalDependencies: + rollup: 4.17.2 + '@rollup/plugin-replace@5.0.7(rollup@4.17.2)': dependencies: '@rollup/pluginutils': 5.1.0(rollup@4.17.2) @@ -1527,6 +1561,8 @@ snapshots: dependencies: '@types/node': 20.14.10 + '@types/resolve@1.20.2': {} + '@types/semver@7.5.8': {} '@types/serviceworker@0.0.85': {} @@ -1751,6 +1787,8 @@ snapshots: deep-is@0.1.4: {} + deepmerge@4.3.1: {} + depd@2.0.0: {} dir-glob@3.0.1: @@ -2077,6 +2115,10 @@ snapshots: ipaddr.js@2.2.0: {} + is-builtin-module@3.2.1: + dependencies: + builtin-modules: 3.3.0 + is-core-module@2.13.1: dependencies: hasown: 2.0.2 diff --git a/rollup.config.js b/rollup.config.js index 4237c21..fe9e6ae 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,5 @@ import typescript from "rollup-plugin-typescript2"; +import { nodeResolve } from '@rollup/plugin-node-resolve'; import { join } from "node:path"; import fs from "node:fs" import { fileURLToPath } from "node:url"; @@ -9,9 +10,8 @@ console.log(production) fs.rmSync(join(fileURLToPath(new URL(".", import.meta.url)), "./dist"), { recursive: true, force: true }) const commonPlugins = () => [ - typescript({ - tsconfig: "tsconfig.json", - }), + typescript(), + nodeResolve(), ] export default { diff --git a/src/bundle/rewriters/headers.ts b/src/bundle/rewriters/headers.ts index fb83bcf..ef74ccc 100644 --- a/src/bundle/rewriters/headers.ts +++ b/src/bundle/rewriters/headers.ts @@ -1,6 +1,5 @@ import { encodeUrl } from "./url"; import { BareHeaders } from "@mercuryworkshop/bare-mux"; - const cspHeaders = [ "cross-origin-embedder-policy", "cross-origin-opener-policy", diff --git a/src/client/index.ts b/src/client/index.ts index 0ea155c..f44b3bd 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -1,3 +1,4 @@ +import "./window.ts"; import "./native/eval.ts"; import "./location.ts"; import "./trustedTypes.ts"; @@ -12,5 +13,6 @@ import "./worker.ts"; declare global { interface Window { __location: Location; + __window: Window; } } diff --git a/src/client/window.ts b/src/client/window.ts index 288d600..7478745 100644 --- a/src/client/window.ts +++ b/src/client/window.ts @@ -1 +1,18 @@ -// the DAMN WINDOW PROXY \ No newline at end of file +const windowProxy = new Proxy(window, { + get(target, prop) { + const propIsString = typeof prop === "string"; + if (propIsString && prop === "location") { + return target.__location; + } else if (propIsString && ["window", "top", "parent", "self", "globalThis"].includes(prop)) { + return target.__window; + } + + return target[prop]; + }, + + set(target, p, newValue, receiver) { + return Reflect.set(target, p, newValue, receiver); + }, +}); + +window.__window = windowProxy; \ No newline at end of file