Skip to content

Commit 31739db

Browse files
committed
:3:3:3
1 parent 5c9d8ac commit 31739db

5 files changed

Lines changed: 67 additions & 69 deletions

File tree

build.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rimraf from 'rimraf';
1+
// import { rimraf } from 'rimraf';
22
import { copyFile, mkdir, readFile } from 'node:fs/promises';
33
import { build } from 'esbuild';
44

@@ -8,30 +8,30 @@ process.env.ULTRAVIOLET_VERSION = pkg.version;
88

99
const isDevelopment = process.argv.includes('--dev');
1010

11-
rimraf('dist', async () => { //rimraf was being a meanie to me
12-
await mkdir('dist');
11+
// rimraf('dist', async () => { //rimraf was being a meanie to me
12+
await mkdir('dist');
1313

14-
// don't compile these files
15-
await copyFile('src/sw.js', 'dist/sw.js');
16-
await copyFile('src/uv.config.js', 'dist/uv.config.js');
14+
// don't compile these files
15+
await copyFile('src/sw.js', 'dist/sw.js');
16+
await copyFile('src/uv.config.js', 'dist/uv.config.js');
1717

18-
await build({
19-
platform: 'browser',
20-
sourcemap: true,
21-
minify: !isDevelopment,
22-
entryPoints: {
23-
'uv.bundle': './src/rewrite/index.js',
24-
'uv.client': './src/client/index.js',
25-
'uv.handler': './src/uv.handler.js',
26-
'uv.sw': './src/uv.sw.js',
27-
},
28-
define: {
29-
'process.env.ULTRAVIOLET_VERSION': JSON.stringify(
30-
process.env.ULTRAVIOLET_VERSION
31-
),
32-
},
33-
bundle: true,
34-
logLevel: 'info',
35-
outdir: 'dist/',
36-
});
18+
await build({
19+
platform: 'browser',
20+
sourcemap: true,
21+
minify: !isDevelopment,
22+
entryPoints: {
23+
'uv.bundle': './src/rewrite/index.js',
24+
'uv.client': './src/client/index.js',
25+
'uv.handler': './src/uv.handler.js',
26+
'uv.sw': './src/uv.sw.js',
27+
},
28+
define: {
29+
'process.env.ULTRAVIOLET_VERSION': JSON.stringify(
30+
process.env.ULTRAVIOLET_VERSION
31+
),
32+
},
33+
bundle: true,
34+
logLevel: 'info',
35+
outdir: 'dist/',
3736
});
37+
// });

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"publish": "npm run build && npm publish --access public"
2020
},
2121
"dependencies": {
22-
"@nebula-services/bare-client": "^1.1.2-beta.3-patch.1",
22+
"@mercuryworkshop/bare-mux": "workspace: *",
2323
"crypto-js": "^4.2.0",
2424
"css-tree": "^2.0.4",
2525
"esbuild": "^0.19.11",
@@ -29,6 +29,7 @@
2929
"meriyah": "^4.3.3",
3030
"mime-db": "^1.51.0",
3131
"parse5": "^7.1.2",
32+
"rimraf": "^5.0.5",
3233
"set-cookie-parser": "^2.4.8"
3334
},
3435
"devDependencies": {

src/rewrite/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
wrapEval,
3535
} from './rewrite.script.js';
3636
import { openDB } from 'idb';
37-
import BareClient from '@nebula-services/bare-client';
37+
import BareClient from '@mercuryworkshop/bare-mux';
3838
import EventEmitter from 'events';
3939

4040
/**

src/uv.handler.js

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ function __uvHook(window) {
5858
const methodPrefix = '__uv$';
5959
const __uv = new Ultraviolet(__uv$config);
6060

61+
const OldWebSocket = WebSocket;
62+
6163
/*if (typeof config.construct === 'function') {
6264
config.construct(__uv, worker ? 'worker' : 'window');
6365
}*/
@@ -109,7 +111,7 @@ function __uvHook(window) {
109111
__uv.sessionStorageObj = {};
110112

111113
// websockets
112-
const bareClient = new Ultraviolet.BareClient(__uv$bareURL, __uv$bareData);
114+
const bareClient = new Ultraviolet.BareClient();
113115

114116
__uv.bareClient = bareClient;
115117

@@ -480,19 +482,19 @@ function __uvHook(window) {
480482
event.respondWith(
481483
worker
482484
? call(
483-
event.target,
484-
[event.data.message, event.data.transfer],
485-
event.that
486-
)
485+
event.target,
486+
[event.data.message, event.data.transfer],
487+
event.that
488+
)
487489
: call(
488-
event.target,
489-
[
490-
event.data.message,
491-
event.data.origin,
492-
event.data.transfer,
493-
],
494-
event.that
495-
)
490+
event.target,
491+
[
492+
event.data.message,
493+
event.data.origin,
494+
event.data.transfer,
495+
],
496+
event.that
497+
)
496498
);
497499
});
498500

@@ -1073,10 +1075,9 @@ function __uvHook(window) {
10731075

10741076
this.#socket = await bareClient.createWebSocket(
10751077
url,
1076-
requestHeaders,
10771078
protocol,
1078-
__uv$config.proxyIp,
1079-
__uv$config.proxyPort
1079+
OldWebSocket,
1080+
requestHeaders
10801081
);
10811082

10821083
this.#socket.binaryType = this.#binaryType;
@@ -1097,18 +1098,16 @@ function __uvHook(window) {
10971098
this.dispatchEvent(new Event('close', event));
10981099
});
10991100

1100-
const meta = await this.#socket.meta;
1101-
1102-
if (meta.headers.has('sec-websocket-protocol'))
1103-
this.#protocol = meta.headers.get('sec-websocket-protocol');
1104-
1105-
if (meta.headers.has('sec-websocket-extensions'))
1106-
this.#extensions = meta.headers.get('sec-websocket-extensions');
1107-
1108-
let setCookie = meta.rawHeaders['set-cookie'] || [];
1109-
if (!Array.isArray(setCookie)) setCookie = [];
1110-
// trip the hook
1111-
for (const cookie of setCookie) document.cookie = cookie;
1101+
// const meta = await this.#socket.meta;
1102+
//
1103+
// if (meta && meta.headers['sec-websocket-protocol'])
1104+
// this.#protocol = meta.headers['sec-websocket-protocol'];
1105+
//
1106+
//
1107+
// let setCookie = meta.rawHeaders['set-cookie'] || [];
1108+
// if (!Array.isArray(setCookie)) setCookie = [];
1109+
// // trip the hook
1110+
// for (const cookie of setCookie) document.cookie = cookie;
11121111
}
11131112
get url() {
11141113
return this.#url;
@@ -1142,10 +1141,10 @@ function __uvHook(window) {
11421141
this.#ready = this.#open(parsed, protocol);
11431142
}
11441143
get protocol() {
1145-
return this.#protocol;
1144+
return this.#socket.protocol;
11461145
}
11471146
get extensions() {
1148-
return this.#extensions;
1147+
return this.#socket.extensions;
11491148
}
11501149
get readyState() {
11511150
if (this.#socket) {
@@ -1465,13 +1464,13 @@ function __uvHook(window) {
14651464
return target.call(that, url);
14661465
});
14671466

1468-
__uv.$wrap = function (name) {
1467+
__uv.$wrap = function(name) {
14691468
if (name === 'location') return __uv.methods.location;
14701469
if (name === 'eval') return __uv.methods.eval;
14711470
return name;
14721471
};
14731472

1474-
__uv.$get = function (that) {
1473+
__uv.$get = function(that) {
14751474
if (that === window.location) return __uv.location;
14761475
if (that === window.eval) return __uv.eval;
14771476
if (that === window.parent) {
@@ -1492,11 +1491,11 @@ function __uvHook(window) {
14921491
return target.call(that, script);
14931492
});
14941493

1495-
__uv.call = function (target, args, that) {
1494+
__uv.call = function(target, args, that) {
14961495
return that ? target.apply(that, args) : target(...args);
14971496
};
14981497

1499-
__uv.call$ = function (obj, prop, args = []) {
1498+
__uv.call$ = function(obj, prop, args = []) {
15001499
return obj[prop].apply(obj, args);
15011500
};
15021501

@@ -1511,7 +1510,7 @@ function __uvHook(window) {
15111510
window.Object.prototype,
15121511
__uv.methods.setSource,
15131512
{
1514-
value: function (source) {
1513+
value: function(source) {
15151514
if (!client.nativeMethods.isExtensible(this)) return this;
15161515

15171516
client.nativeMethods.defineProperty(this, __uv.methods.source, {

src/uv.sw.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class UVServiceWorker extends Ultraviolet.EventEmitter {
4040
/**
4141
* @type {InstanceType<Ultraviolet['BareClient']>}
4242
*/
43-
this.bareClient = new Ultraviolet.BareClient(this.address);
43+
this.bareClient = new Ultraviolet.BareClient();
4444
}
4545
/**
4646
*
@@ -187,8 +187,8 @@ class UVServiceWorker extends Ultraviolet.EventEmitter {
187187
ultraviolet.meta
188188
)
189189
).then(() => {
190-
self.clients.matchAll().then(function (clients) {
191-
clients.forEach(function (client) {
190+
self.clients.matchAll().then(function(clients) {
191+
clients.forEach(function(client) {
192192
client.postMessage({
193193
msg: 'updateCookies',
194194
url: ultraviolet.meta.url.href,
@@ -430,8 +430,7 @@ function hostnameErrorTemplate(fetchedURL, bareServer) {
430430
'<button id="reload">Reload</button>' +
431431
'<hr />' +
432432
'<p><i>Ultraviolet v<span id="uvVersion"></span></i></p>' +
433-
`<script src="${
434-
'data:application/javascript,' + encodeURIComponent(script)
433+
`<script src="${'data:application/javascript,' + encodeURIComponent(script)
435434
}"></script>` +
436435
'</body>' +
437436
'</html>'
@@ -513,8 +512,7 @@ function errorTemplate(
513512
'<button id="reload">Reload</button>' +
514513
'<hr />' +
515514
'<p><i>Ultraviolet v<span id="uvVersion"></span></i></p>' +
516-
`<script src="${
517-
'data:application/javascript,' + encodeURIComponent(script)
515+
`<script src="${'data:application/javascript,' + encodeURIComponent(script)
518516
}"></script>` +
519517
'</body>' +
520518
'</html>'

0 commit comments

Comments
 (0)