Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions build/build-jsbundle.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@ const fs = require('node:fs');
const { execSync } = require('node:child_process');

const argv = require('./minimist.cjs')(process.argv.slice(2));
const { clean, minify } = argv;
const { clean } = argv;
const withoutPack = argv['without-pack'];

const shell = (cmd, options) => execSync(cmd, { stdio: 'inherit', ...options });
const jsDir = path.join(__dirname, '../');

function installDeps() {
shell('npm install', { cwd: jsDir });

const babylonjsTypeDefPath = path.join(jsDir, 'node_modules/babylonjs/babylon.d.ts');
const babylonjsPostTxtPath = path.join(__dirname, './patches/babylonjs-post.txt');
const babylonjsTypeDefContent = fs.readFileSync(babylonjsTypeDefPath, { encoding: 'utf-8' });
const babylonjsPostTxtContent = fs.readFileSync(babylonjsPostTxtPath, { encoding: 'utf-8' });
fs.writeFileSync(babylonjsTypeDefPath, babylonjsTypeDefContent + babylonjsPostTxtContent);
}

if (clean === 'yes' || !fs.existsSync(path.join(jsDir, 'node_modules'))) {
Expand Down
7 changes: 0 additions & 7 deletions build/patches/babylonjs-post.txt

This file was deleted.

1 change: 0 additions & 1 deletion crates/runtime_apis/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ fn main() {
env_logger::init();

install_nodejs_library();
install_script("jsar-bootstrap-babylon.js");
install_script("jsar-client-entry.js");
install_script("jsar-webworkers-entry.js");
install_header("jsar_jsbundle.h");
Expand Down
34 changes: 0 additions & 34 deletions crates/runtime_apis/jsar_jsbundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ extern "C"
uintptr_t get_libnode_size();
const uint8_t *get_libnode_md5_ptr();
uintptr_t get_libnode_md5_size();
const uint8_t *get_jsbootstrap_ptr(int jsframework_name);
uintptr_t get_jsbootstrap_size(int jsframework_name);
const uint8_t *get_jsbundle_ptr(int id);
uintptr_t get_jsbundle_size(int id);
int32_t carbonite_decompress_binary(const uint8_t *input_ptr,
Expand All @@ -23,15 +21,6 @@ extern "C"
void carbonite_release_memory(uint8_t *ptr, size_t len);
}

/**
* The name of the JavaScript framework to bootstrap runtime: Babylon or Three.js.
*/
enum class JSFrameworkName
{
BABYLON = 0,
THREE = 1
};

enum class JSBundles
{
MainEntry = 0,
Expand All @@ -41,29 +30,6 @@ enum class JSBundles
class JSBundle
{
public:
/**
* Get the pointer to the JavaScript bootstrap source code.
*
* @param jsframework_name The name of the JavaScript framework.
* @returns The pointer to the JavaScript bootstrap source code.
* Get the str pointer to the libnode source code.
*/
static inline const uint8_t *GetBootstrapSourcePtr(JSFrameworkName jsframework_name = JSFrameworkName::BABYLON)
{
return get_jsbootstrap_ptr(static_cast<int>(jsframework_name));
}

/**
* Get the size of the JavaScript bootstrap source code.
*
* @param jsframework_name The name of the JavaScript framework.
* @returns The size of the JavaScript bootstrap source code.
*/
static inline uintptr_t GetBootstrapSourceSize(JSFrameworkName jsframework_name = JSFrameworkName::BABYLON)
{
return get_jsbootstrap_size(static_cast<int>(jsframework_name));
}

/**
* Get the pointer to the JavaScript client entry source code.
*
Expand Down
38 changes: 0 additions & 38 deletions crates/runtime_apis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ mod platform {
pub const LIBNODE_SRC_MD5: &str = "";
}

const JSBOOTSTRAP_BABYLON_COMPRESSED: &[u8] = include_bytes!("jsar-bootstrap-babylon.js.gz");
const JSBUNDLE_CLIENT_ENTRY_COMPRESSED: &[u8] = include_bytes!("jsar-client-entry.js.gz");
const JSBUNDLE_WEBWORKERS_ENTRY_COMPRESSED: &[u8] = include_bytes!("jsar-webworkers-entry.js.gz");

Expand All @@ -55,7 +54,6 @@ fn decompress_js_source(js: &[u8]) -> String {
}

lazy_static! {
static ref JSBOOTSTRAP_BABYLON_SRC: String = decompress_js_source(JSBOOTSTRAP_BABYLON_COMPRESSED);
static ref JSBUNDLE_CLIENT_ENTRY_SRC: String =
decompress_js_source(JSBUNDLE_CLIENT_ENTRY_COMPRESSED);
static ref JSBUNDLE_WEBWORKERS_ENTRY_SRC: String =
Expand All @@ -82,16 +80,6 @@ extern "C" fn get_libnode_md5_size() -> usize {
platform::LIBNODE_SRC_MD5.len()
}

#[no_mangle]
extern "C" fn get_jsbootstrap_ptr(_framework_id: i32) -> *const u8 {
JSBOOTSTRAP_BABYLON_SRC.as_ptr()
}

#[no_mangle]
extern "C" fn get_jsbootstrap_size(_framework_id: i32) -> usize {
JSBOOTSTRAP_BABYLON_SRC.len()
}

#[no_mangle]
extern "C" fn get_jsbundle_ptr(id: i32) -> *const u8 {
if id == 0 {
Expand Down Expand Up @@ -159,29 +147,3 @@ extern "C" fn carbonite_release_memory(ptr: *mut u8, len: usize) {
let _ = Box::from_raw(ptr::slice_from_raw_parts_mut(ptr, len));
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_decompress_js_source() {
let js = include_bytes!("jsar-bootstrap-babylon.js.gz");
let decompressed_js = decompress_js_source(js);
assert_eq!(decompressed_js.len() > 0, true);
}

#[test]
fn test_decompress_binary() {
let js = include_bytes!("jsar-bootstrap-babylon.js.gz");
let mut output_ptr: *mut u8 = ptr::null_mut();
let mut output_len: usize = 0;
let result =
carbonite_decompress_binary(js.as_ptr(), js.len(), &mut output_ptr, &mut output_len);
assert_eq!(result, 0);
assert_eq!(output_len, 5024048);
println!("output: {:?}", output_ptr);

carbonite_release_memory(output_ptr, output_len);
}
}
37 changes: 0 additions & 37 deletions lib/bootstrap-babylon.ts

This file was deleted.

2 changes: 1 addition & 1 deletion lib/navigator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class NavigatorImpl implements Navigator {
/**
* The `gpu` provides the WebGPU context.
*/
get gpu(): GPU {
get gpu() {
throw new TypeError('WebGPU is not supported in this environment');
}
get webdriver(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import fsPromises from 'node:fs/promises';
import { resolveObjectURL } from 'node:buffer';

import {
type ResourceLoader as JSARResourceLoader,
} from '@yodaos-jsar/dom';
import { getClientContext, isResourcesCachingDisabled, getResourceCacheExpirationTime } from '@transmute/env';
getClientContext,
isResourcesCachingDisabled,
getResourceCacheExpirationTime
} from '@transmute/env';
import * as undici from 'undici';
import { CacheControl, parse as parseCacheControl } from 'cache-control-parser';
import { IncomingHttpHeaders } from 'undici/types/header';
Expand All @@ -18,6 +19,7 @@ type FetchReturnsMap = {
};
type FetchOptions = {
accept?: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
cookieJar?: any;
referrer?: string;
headers?: undici.HeadersInit;
Expand All @@ -32,7 +34,7 @@ const getHashOfUri = (uri: string) => hash('md5', uri);
const getOrigin = (url: string) => {
let origin: string = '';
try {
let urlObject = new URL(url);
const urlObject = new URL(url);
origin = urlObject.hostname;
// TODO(yorkie): support the port?
} catch (_) {
Expand Down Expand Up @@ -182,8 +184,8 @@ type ResponseCacheInfo<D> = {
type ResponseContentCallback<D> = (content: NodeJS.ArrayBufferView | string, info: ResponseCacheInfo<D>) => void;

function buildCacheInfoFrom<D>(response: ResponseCacheInfo<D>['responseData']): ResponseCacheInfo<D> {
let statusCode = response.status || response.statusCode;
let useCache = statusCode === 304;
const statusCode = response.status || response.statusCode;
const useCache = statusCode === 304;
let storeCache = true;
if (!useCache && response.headers['cache-control']) {
const cacheControl = parseCacheControl(response.headers['cache-control'].toString());
Expand Down Expand Up @@ -256,6 +258,7 @@ class CacheStorage {
return null;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
async put(url: string, headers: any, content?: NodeJS.ArrayBufferView | string): Promise<void> {
if (this.#disabled) {
return;
Expand Down Expand Up @@ -327,7 +330,7 @@ class CacheStorage {
await Promise.all(writes);
}

async delete(url: string): Promise<void> {
async delete(_url: string): Promise<void> {
if (this.#disabled) {
return;
}
Expand Down Expand Up @@ -415,7 +418,7 @@ class CacheStorage {
}
}

export class ResourceLoaderOnTransmute implements JSARResourceLoader {
export class ResourceLoaderOnTransmute {
#cacheDirectory: string;
#cacheStorage: CacheStorage;
#defaultHeaders: Record<string, string> = {};
Expand Down Expand Up @@ -500,7 +503,8 @@ export class ResourceLoaderOnTransmute implements JSARResourceLoader {
} else {
return this.#cacheStorage.requestWithCache(url, this.#getRequestInit(options), {
readFile: (filename: string) => this.#readFile(filename, returnsAs),
sendRequest: (url: string, init: RequestInit) => this.#sendRequest(url, init),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sendRequest: (url: string, init: RequestInit) => this.#sendRequest(url, init as any),
readResponse: (...args) => this.#readBody(...args, returnsAs),
});
}
Expand All @@ -513,6 +517,7 @@ export class ResourceLoaderOnTransmute implements JSARResourceLoader {
* @returns the fetch(input, init?) function.
*/
createWHATWGFetchImpl(baseURI: string): (input: RequestInfo, init?: RequestInit) => Promise<Response> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self: ResourceLoaderOnTransmute = this;
const forceFetch = fetch; // Save the Node.js fetch implementation.

Expand Down Expand Up @@ -586,6 +591,7 @@ export class ResourceLoaderOnTransmute implements JSARResourceLoader {
const reqInit: undici.RequestInit = {
...(options == null ? {} : options),
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const responseData = await undici.request(url, <any>{
maxRedirections: 5,
dispatcher: this.#networkProxyAgent || undici.getGlobalDispatcher(),
Expand Down Expand Up @@ -616,10 +622,13 @@ export class ResourceLoaderOnTransmute implements JSARResourceLoader {
if (returnsAs === 'string') {
return text as FetchReturnsMap[AsType];
} else if (returnsAs === 'json') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let obj: any;
try {
obj = JSON.parse(text);
} catch (_) { }
} catch (_) {
// Nothing to do here
}
return obj as FetchReturnsMap[AsType];
} else {
throw new TypeError(`Unknown return type: "${returnsAs}"`);
Expand Down
Loading