-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switch to esbuild and fix ws and google bugs
- Loading branch information
Showing
16 changed files
with
833 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as esbuild from 'esbuild'; | ||
|
||
const build = async () => { | ||
console.time("esbuild"); | ||
|
||
const worker = await esbuild.context({ | ||
entryPoints: ['lib/worker/index.ts'], | ||
bundle: true, | ||
outfile: 'static/dynamic/dynamic.worker.js', | ||
format: 'iife', | ||
minify: true, | ||
platform: 'browser', | ||
sourcemap: true, | ||
target: ['es2020'], | ||
plugins: [], | ||
metafile: true, | ||
}) | ||
|
||
worker.watch(); | ||
|
||
const handler = await esbuild.context({ | ||
entryPoints: ['lib/handler/index.ts'], | ||
bundle: true, | ||
outfile: 'static/dynamic/dynamic.handler.js', | ||
format: 'iife', | ||
minify: true, | ||
platform: 'browser', | ||
sourcemap: true, | ||
target: ['es2020'], | ||
plugins: [], | ||
metafile: true, | ||
}); | ||
|
||
handler.watch(); | ||
|
||
const client = await esbuild.context({ | ||
entryPoints: ['lib/client/index.ts'], | ||
bundle: true, | ||
outfile: 'static/dynamic/dynamic.client.js', | ||
format: 'iife', | ||
minify: true, | ||
platform: 'browser', | ||
sourcemap: true, | ||
target: ['es2020'], | ||
plugins: [], | ||
metafile: true, | ||
}); | ||
|
||
client.watch(); | ||
|
||
const html = await esbuild.context({ | ||
entryPoints: ['lib/html/index.ts'], | ||
bundle: true, | ||
outfile: 'static/dynamic/dynamic.html.js', | ||
format: 'iife', | ||
minify: true, | ||
platform: 'browser', | ||
sourcemap: true, | ||
target: ['es2020'], | ||
plugins: [], | ||
metafile: true, | ||
}); | ||
|
||
html.watch(); | ||
|
||
console.log(await esbuild.analyzeMetafile((await worker.rebuild()).metafile)); | ||
|
||
console.timeEnd("esbuild"); | ||
|
||
await new Promise(resolve => null); | ||
} | ||
|
||
await build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const valid_chars = "!#$%&'*+-.0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`abcdefghijklmnopqrstuvwxyz|~"; | ||
const reserved_chars = "%"; | ||
|
||
export function validProtocol(protocol:any){ | ||
protocol = protocol.toString(); | ||
|
||
for(let i = 0; i < protocol.length; i++){ | ||
const char = protocol[i]; | ||
|
||
if(!valid_chars.includes(char)){ | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
export function encodeProtocol(protocol:any){ | ||
protocol = protocol.toString(); | ||
|
||
let result = ''; | ||
|
||
for(let i = 0; i < protocol.length; i++){ | ||
const char = protocol[i]; | ||
|
||
if(valid_chars.includes(char) && !reserved_chars.includes(char)){ | ||
result += char; | ||
}else{ | ||
const code = char.charCodeAt(); | ||
result += '%' + code.toString(16).padStart(2, 0); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export function decodeProtocol(protocol:any){ | ||
if(typeof protocol != 'string')throw new TypeError('protocol must be a string'); | ||
|
||
let result = ''; | ||
|
||
for(let i = 0; i < protocol.length; i++){ | ||
const char = protocol[i]; | ||
|
||
if(char == '%'){ | ||
const code = parseInt(protocol.slice(i + 1, i + 3), 16); | ||
const decoded = String.fromCharCode(code); | ||
|
||
result += decoded; | ||
i += 2; | ||
}else{ | ||
result += char; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export default {encodeProtocol, decodeProtocol} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.