mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-06-26 16:18:51 +00:00
refactor!: cleanup platform support (#306)
* refactor!: cleanup platform support * chore: lint * fix: web platform * feat: provide UniversalCache Provide UniversalCache as a wrapper around Platform.shim.Cache. * fix: invalid import * refactor: remove isolated-vm support * fix: type info * refactor: cleanup exports * fix: mark jintr as external dependency In the bundled CJS node build, mark jintr as external. * chore: add additional exports web exports provide a way to select web implementation manually without relying on the bundler to select it correctly from the "exports" field web points to src/platform/web.js web.bundle points to bundle/browser.js web.bundle.browser points to bundle/browser.min.js agnostic exports provide users of the library to provide their own platform implementation without first importing the default one. agnostic points to src/platform/lib.ts * fix: toDash on web * revert: eval is synchronous * fix: use serializeDOM in FormatUtils * ci: automate releases with `release-please` * chore: clean up workflow files * ci: fix NPM publish action --------- Co-authored-by: LuanRT <luan.lrt4@gmail.com>
This commit is contained in:
54
src/platform/README.md
Normal file
54
src/platform/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Platform Support
|
||||
|
||||
YouTube.js is designed to be as platform agnostic as possible. To achieve this, we require all platforms wishing to use YouTube.js to provide a few shims around the platform's native APIs.
|
||||
|
||||
## Supported Platforms
|
||||
|
||||
We provide shims for the following platforms:
|
||||
|
||||
- Modern Browsers
|
||||
- Node.js
|
||||
- Deno
|
||||
|
||||
## Contributing Support for a New Platform
|
||||
|
||||
If you wish to bring YouTube.js to another platform, you will need to provide the following shims as specified by the `PlatformShim` type:
|
||||
|
||||
- `runtime`: String name of the platform.
|
||||
- `info`: Object containing the package information read from `package.json`.
|
||||
- `version`: The version of the package.
|
||||
- `bugs_url`: The URL to the package's bug tracker.
|
||||
- `repository_url`: The URL to the package's repository.
|
||||
- `server`: Boolean indicating whether the platform is a server or not. Used for setting some additional headers not possible on a web browser.
|
||||
- `Cache`: Class that implements the `ICache` interface using the platform's native APIs.
|
||||
- `sha1hash(data: string)`: Function that takes a string and returns a SHA-1 hash of it.
|
||||
- `uuidv4()`: Function that returns a UUIDv4 string.
|
||||
- `eval(code: string, env: Record<string, VMPrimative>)`: Function to evaluate untrusted javascript script and return the result.
|
||||
- `DOMParser`: DOMParser implementation. Used for generating DASH manifests.
|
||||
- `fetch`: WHATWG Fetch API implementation.
|
||||
- `Headers`: Headers implementation.
|
||||
- `Request`: Request implementation.
|
||||
- `Response`: Response implementation.
|
||||
- `FormData`: FormData implementation.
|
||||
- `File`: File implementation.
|
||||
- `ReadableStream`: ReadableStream implementation.
|
||||
|
||||
An entry point for the platform should be added in the `src/platform` directory and should be formatted as follows:
|
||||
|
||||
```ts
|
||||
import { Platform } from '../utils/Utils.js';
|
||||
import { PlatformShim } from "../types";
|
||||
import { ICache } from '../types/Cache.js';
|
||||
|
||||
class Cache implements ICache {
|
||||
// ...
|
||||
}
|
||||
|
||||
Platform.load({
|
||||
// ... shims
|
||||
});
|
||||
|
||||
export * from './lib.js';
|
||||
import Innertube from './lib.js';
|
||||
export default Innertube;
|
||||
```
|
||||
Reference in New Issue
Block a user