Skip to content

Commit

Permalink
version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
stagas committed Dec 23, 2021
1 parent acb83a3 commit e414058
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 2 deletions.
83 changes: 82 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,82 @@
# run-in-client
<h1 align="center">run-in-client</h1>

<p align="center">
runs a single function in the client using puppeteer and esbuild
</p>

<p align="center">
<a href="#install"> 🔧 <strong>Install</strong></a>
· <a href="#example"> 🧩 <strong>Example</strong></a>
· <a href="#api"> 📜 <strong>API docs</strong></a>
· <a href="https://github.com/stagas/run-in-client/releases"> 🔥 <strong>Releases</strong></a>
· <a href="#contribute"> 💪🏼 <strong>Contribute</strong></a>
· <a href="https://github.com/stagas/run-in-client/issues"> 🖐️ <strong>Help</strong></a>
</p>

***

## Install

```sh
$ npm i run-in-client
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

* [runInClient](#runinclient)
* [Parameters](#parameters)

### runInClient

[src/index.ts:44-82](https://github.com/stagas/run-in-client/blob/acb83a343b40b2dd23a8d0f3d248ed9cb9775013/src/index.ts#L44-L82 "Source code on GitHub")

Creates a static server with esbuild transforms, creates a puppeteer instance,
executes a single function, returns its result and tears down.

```ts
const setup = {
root: path.resolve(path.join(__dirname, '..')),
include: `
import { someModule } from './some-module.ts' // note we can import .ts files
window.someModule = someModule
`,
}

// this is how our function below gets intellisense
declare window: WindowOrWorkerGlobalScope & { someModule: typeof someModule }

// the function runs in the client, as such doesn't have access to the scope!
const result = await runInClient(setup, async () => {
const output = await window.someModule.doSomething()
return output
})
// => `result` is now `output`
```

#### Parameters

* `setup` **ClientSetup** A setup object

* `setup.root` The static root directory to serve and esbuild transform files from
* `setup.include` JavaScript to run before the function, like import statements
* `setup.buildOptions` Esbuild build options (@see <https://esbuild.github.io/api/#build-api>)
* `setup.launchOptions` Puppeteer launch options (@see <https://puppeteer.github.io/puppeteer/docs/puppeteer.launch/>)
* `fn` **function (): any** The function to run. This will be passed in `page.evaluate(fn)`

Returns **any** The result value of `page.evaluate(fn)`

## Contribute

[Fork](https://github.com/stagas/run-in-client/fork) or
[edit](https://github.dev/stagas/run-in-client) and submit a PR.

All contributions are welcome!

## License

MIT © 2021
[stagas](https://github.com/stagas)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "stagas",
"short": "stagas/run-in-client",
"description": "runs a single function in the client using puppeteer and esbuild",
"version": "0.0.0",
"version": "1.0.0",
"license": "MIT",
"repository": {
"type": "git",
Expand Down

0 comments on commit e414058

Please sign in to comment.