2017-04-07 04:24:51 +03:00
# Prepack [![Circle CI](https://circleci.com/gh/facebook/prepack.png?style=shield&circle-token=1109197a81e634fd06e162c25d309a420585acd5)](https://circleci.com/gh/facebook/prepack)
2015-10-15 02:59:41 +03:00
Prepack is a partial evaluator for JavaScript. Prepack rewrites a JavaScript bundle, resulting in JavaScript code that executes more efficiently.
For initialization-heavy code, Prepack works best in an environment where JavaScript parsing is effectively cached.
2017-10-01 00:01:28 +03:00
See the official [prepack.io ](https://prepack.io ) website for an introduction and an [interactive REPL playground ](https://prepack.io/repl.html ).
2015-10-15 02:59:41 +03:00
2017-05-09 20:00:22 +03:00
## How to use Prepack
2017-07-11 03:30:45 +03:00
Install the CLI via npm,
2017-05-09 20:00:22 +03:00
```bash
2017-07-11 03:30:45 +03:00
$ npm install -g prepack
2017-05-09 20:00:22 +03:00
```
2017-07-11 03:30:45 +03:00
Or if you prefer yarn, make sure you get yarn first,
```bash
$ npm install -g yarn
```
and then install the Prepack CLI via yarn:
2017-05-09 20:00:22 +03:00
```bash
$ yarn global add prepack
```
2017-05-22 20:07:54 +03:00
You may need to `prepend` (pun intended!) the command with `sudo` in some cases.
2017-05-09 20:00:22 +03:00
### Let the party begin
To compile a file and print the output to the console:
```bash
$ prepack script.js
```
If you want to compile a file and output to another file:
```bash
$ prepack script.js --out script-processed.js
```
Detailed instructions and the API can be found at [Prepack CLI: Getting Started ](https://prepack.io/getting-started.html )
2015-10-15 02:59:41 +03:00
## Status
2017-04-06 04:02:05 +03:00
- [test262 status on master branch ](https://circleci.com/api/v1/project/facebook/prepack/latest/artifacts/0/$CIRCLE_ARTIFACTS/test262-status.txt?branch=master )
2017-04-10 23:35:48 +03:00
- [code coverage report for serialization tests ](https://circleci.com/api/v1/project/facebook/prepack/latest/artifacts/0/$CIRCLE_ARTIFACTS/coverage-report-sourcemapped/index.html?branch=master )
2015-10-15 02:59:41 +03:00
- To see the status for a pull request, look for the message *All checks have passed* or *All checks have failed* . Click on *Show all checks* , *Details* , *Artifacts* , and then *test262-status.txt* or *coverage-report-sourcemapped/index.html* .
## How to get the code
0. Clone repository and make it your current directory.
1. `git submodule init`
2017-05-18 03:39:51 +03:00
2. `git submodule update --init`
2017-06-30 22:14:32 +03:00
3. Get yarn and node, then do
`yarn`
2015-10-15 02:59:41 +03:00
2017-07-11 03:30:45 +03:00
Note: For development work you really need `yarn` , as many scripts require it.
2015-10-15 02:59:41 +03:00
### How to build, lint, type check
0. Get the code
2017-06-30 22:14:32 +03:00
1. `yarn build`
You can later run `yarn watch` in the background to just compile changed files on the fly.
2. `yarn lint`
3. `yarn flow`
2015-10-15 02:59:41 +03:00
### How to run tests
0. Get the code
2017-06-30 22:14:32 +03:00
1. Make sure the code is built, either by running `yarn build` or `yarn watch`
2. `yarn test`
2015-10-15 02:59:41 +03:00
2017-05-22 20:07:54 +03:00
You can run individual test suites as follows:
2017-06-30 22:14:32 +03:00
- `yarn test-serializer`
2017-04-10 23:35:48 +03:00
This tests the interpreter and serializer. All tests should pass.
2017-06-30 22:14:32 +03:00
- `yarn test-test262`
2015-10-15 02:59:41 +03:00
This tests conformance against the test262 suite. Not all will pass, increasing conformance is work in progress.
## How to run the interpreter
0. Get the code
2017-06-30 22:14:32 +03:00
1. Make sure the code is built, either by running `yarn build` or `yarn watch`
2. `yarn repl`
2015-10-15 02:59:41 +03:00
This starts an interactive interpreter session.
## How to run Prepack
0. Get the code
2017-06-30 22:14:32 +03:00
1. Make sure the code is built, either by running `yarn build` or `yarn watch` .
2015-10-15 02:59:41 +03:00
2. Have a JavaScript file handy that you want to prepack, for example:
`echo "function hello() { return 'hello'; } function world() { return 'world'; } s = hello() + ' ' + world();" >/tmp/sample.js`
2017-06-30 22:14:32 +03:00
3. `cat /tmp/sample.js | yarn prepack`
2015-10-15 02:59:41 +03:00
Try `--help` for more options.
## How to validate changes
Instead of building, linting, type checking, testing separately, the following does everything together:
2017-06-30 22:14:32 +03:00
`yarn validate`
2015-10-15 02:59:41 +03:00
2017-04-19 20:17:24 +03:00
## How to edit the website
2017-10-01 00:01:28 +03:00
The content for [prepack.io ](https://prepack.io ) resides in the [gh-pages branch ](https://github.com/facebook/prepack/tree/gh-pages ) of this repository. To make changes, submit a pull request, just like for any code changes. In order to run the website locally at [localhost:8000 ](http://localhost:8000 ), run `python -m SimpleHTTPServer` (Python 2) or `python -m http.server` (Python 3) from the cloned `gh-pages` branch.
2017-04-19 20:17:24 +03:00
2017-06-30 22:14:32 +03:00
At this time, a particular bundled version of Prepack is checked in to the `gh-pages` branch at `js/prepack.min.js` . To update the bundle, run `yarn build-bundle` from the `master` branch, and copy the resulting `prepack.min.js` file into the `gh-pages` branch into the `js` directory, and submit a pull request for that change.
2017-04-19 20:17:24 +03:00
2015-10-15 02:59:41 +03:00
## How to contribute
For more information about contributing pull requests and issues, see our [Contribution Guidelines ](./CONTRIBUTING.md ).
## License
Prepack is BSD-licensed. We also provide an additional patent grant.