prepack/README.md

133 lines
5.4 KiB
Markdown
Raw Normal View History

# 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
<img src="assets/PrepackLogo.png" width=150 align=right>
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.
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
## Status
**We, the Prepack team at Facebook, have temporarily set down work on Prepack including the React compiler project. You won't see many Prepack PRs while we are currently prioritizing some other projects. However, we'd like to resume work on Prepack again in a few months.**
## How to use Prepack
Install the CLI via npm,
```bash
$ npm install -g prepack
```
Or if you prefer yarn, make sure you get yarn first,
```bash
$ npm install -g yarn
```
and then install the Prepack CLI via yarn:
```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.
### 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)
### Plugins to other tools
The following are a few plugins to other tools. They have been created and are maintained separately from Prepack itself. If you run into any issues with those plugins, please ask the plugin maintainers for support.
- [A Rollup plugin for Prepack](https://www.npmjs.com/package/rollup-plugin-prepack)
- [A Webpack plugin for Prepack](https://www.npmjs.com/package/prepack-webpack-plugin)
- [A Parcel plugin for Prepack](https://www.npmjs.com/package/parcel-plugin-prepack)
- [A Visual Studio code plugin for Prepack](https://marketplace.visualstudio.com/items?itemName=RobinMalfait.prepack-vscode)
- [A babel plugin which transforms Flow annotations into prepack model declarations](https://www.npmjs.com/package/babel-plugin-flow-prepack).
## Test Results and Code Coverage
2015-10-15 02:59:41 +03:00
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)
- [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`
3. Get yarn and node, then do
`yarn`
2015-10-15 02:59:41 +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
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
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:
- `yarn test-serializer`
This tests the interpreter and serializer. All tests should pass.
- `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
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
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`
3. `cat /tmp/sample.js | yarn prepack-cli`
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:
`yarn validate`
2015-10-15 02:59:41 +03:00
## How to edit the website
Make master/docs a single source of truth for gh-pages Summary: Release note: none To address issue #956 . The idea is to have all documentation (aka "the website") in a single `docs/` directory on the `master` branch like [Jest](https://github.com/facebook/jest/tree/master/docs) and [Relay](https://github.com/facebook/relay/tree/master/docs) do. This directory then serves as a single source of truth to publish the `gh-pages` branch. This PR: - Moves the current content of the `gh-pages` branch to a `docs/` directory in `master` - Provides a bash script for maintainers to easily publish the `gh-pages` branch from the `docs/` directory. The script also builds `prepack.min.js` from master to make sure gh-pages always has the latest version of prepack. Additionally, I noticed the `gh-pages` branch had two `prepack.min.js` files (one in `./` and one in `./js/`). I removed the first one because it is apparently not used but it may break other websites if they references that file. 0. Fork the repo to avoid modifying the real website 1. Change the site `> git checkout master` `> echo ".nav { background-color: chartreuse; }" >> docs/css/style.css` `> git add docs/css/style.css` `> commit -m "The navigation bar looks better in green"` `> git push` 2. Run the publication script: `> ./scripts/publish-gh-pages.sh` 3. Verify that the gh-pages has been updated: `> git checkout gh-pages` `> git pull` `> git diff HEAD~ # should show the line you added` Closes https://github.com/facebook/prepack/pull/1223 Differential Revision: D6547395 Pulled By: j-nolan fbshipit-source-id: 6e6d3aec97c0bcc2555c421d6f4a889bcd8df208
2017-12-12 23:01:53 +03:00
The content for [prepack.io](https://prepack.io) resides in the [website directory](https://github.com/facebook/prepack/tree/master/website) of this repository. To make changes, submit a pull request, just like for any code changes.
Make master/docs a single source of truth for gh-pages Summary: Release note: none To address issue #956 . The idea is to have all documentation (aka "the website") in a single `docs/` directory on the `master` branch like [Jest](https://github.com/facebook/jest/tree/master/docs) and [Relay](https://github.com/facebook/relay/tree/master/docs) do. This directory then serves as a single source of truth to publish the `gh-pages` branch. This PR: - Moves the current content of the `gh-pages` branch to a `docs/` directory in `master` - Provides a bash script for maintainers to easily publish the `gh-pages` branch from the `docs/` directory. The script also builds `prepack.min.js` from master to make sure gh-pages always has the latest version of prepack. Additionally, I noticed the `gh-pages` branch had two `prepack.min.js` files (one in `./` and one in `./js/`). I removed the first one because it is apparently not used but it may break other websites if they references that file. 0. Fork the repo to avoid modifying the real website 1. Change the site `> git checkout master` `> echo ".nav { background-color: chartreuse; }" >> docs/css/style.css` `> git add docs/css/style.css` `> commit -m "The navigation bar looks better in green"` `> git push` 2. Run the publication script: `> ./scripts/publish-gh-pages.sh` 3. Verify that the gh-pages has been updated: `> git checkout gh-pages` `> git pull` `> git diff HEAD~ # should show the line you added` Closes https://github.com/facebook/prepack/pull/1223 Differential Revision: D6547395 Pulled By: j-nolan fbshipit-source-id: 6e6d3aec97c0bcc2555c421d6f4a889bcd8df208
2017-12-12 23:01:53 +03:00
In order to run the website locally at [localhost:8000](http://localhost:8000):
1. Build prepack into the website: `yarn build && mv prepack.min.js website/js`
Make master/docs a single source of truth for gh-pages Summary: Release note: none To address issue #956 . The idea is to have all documentation (aka "the website") in a single `docs/` directory on the `master` branch like [Jest](https://github.com/facebook/jest/tree/master/docs) and [Relay](https://github.com/facebook/relay/tree/master/docs) do. This directory then serves as a single source of truth to publish the `gh-pages` branch. This PR: - Moves the current content of the `gh-pages` branch to a `docs/` directory in `master` - Provides a bash script for maintainers to easily publish the `gh-pages` branch from the `docs/` directory. The script also builds `prepack.min.js` from master to make sure gh-pages always has the latest version of prepack. Additionally, I noticed the `gh-pages` branch had two `prepack.min.js` files (one in `./` and one in `./js/`). I removed the first one because it is apparently not used but it may break other websites if they references that file. 0. Fork the repo to avoid modifying the real website 1. Change the site `> git checkout master` `> echo ".nav { background-color: chartreuse; }" >> docs/css/style.css` `> git add docs/css/style.css` `> commit -m "The navigation bar looks better in green"` `> git push` 2. Run the publication script: `> ./scripts/publish-gh-pages.sh` 3. Verify that the gh-pages has been updated: `> git checkout gh-pages` `> git pull` `> git diff HEAD~ # should show the line you added` Closes https://github.com/facebook/prepack/pull/1223 Differential Revision: D6547395 Pulled By: j-nolan fbshipit-source-id: 6e6d3aec97c0bcc2555c421d6f4a889bcd8df208
2017-12-12 23:01:53 +03:00
2. Run `python -m SimpleHTTPServer` (Python 2) or `python -m http.server` (Python 3) from the `website/` directory
2015-10-15 02:59:41 +03:00
## How to contribute
To read more about the project, check out this [suggested reading wiki](https://github.com/facebook/prepack/wiki/Suggested-reading)
2015-10-15 02:59:41 +03:00
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.