Skip to content

Commit

Permalink
chore(6.0): remove @bazel/create
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard authored and alexeagle committed Apr 5, 2023
1 parent 72beda0 commit 222509e
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 580 deletions.
3 changes: 0 additions & 3 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ tasks:
platform: ubuntu1804
run_targets:
- "@yarn//:yarn"
# Regression test for #1493
- "//packages/create:npm_package.pack"
- "//internal/node/test:no_deps"
- "//internal/node/test:has_deps_legacy"
- "//internal/node/test:has_deps"
Expand Down Expand Up @@ -111,7 +109,6 @@ tasks:
# run_targets:
# - "@yarn//:yarn"
# # Regression test for #1493
# - "//packages/create:npm_package.pack"
# - "//internal/node/test:no_deps"
# - "//internal/node/test:has_deps_legacy"
# - "//internal/node/test:has_deps"
Expand Down
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@ If you use code from an `/internal` path, these are not subject to our support p
Comprehensive documentation for installing and using the rules, including generated API docs:
https://bazelbuild.github.io/rules_nodejs/

## Quickstart

This is the fastest way to get started.
See the [installation documentation](https://bazelbuild.github.io/rules_nodejs/install.html) for details and alternative methods, or if you already have a Bazel project and you're adding Node/JavaScript support to it.

```sh
$ npx @bazel/create my_workspace
$ cd my_workspace
```

> The `npx` tool is distributed with node. If you prefer, you can run equivalent commands `npm init @bazel` or `yarn create @bazel`.
> If you've used `@bazel/create` before, you may want to use `npx @bazel/create@latest` to get the most recent version.
> Run without any arguments to see available command-line flags.
## Adopters

Thanks to the following active users!
Expand Down
125 changes: 0 additions & 125 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,131 +63,6 @@ The JS ecosystem is also full of false equivalence arguments. The first question
This is understandable, since most JS tooling is forced to provide a single turn-key experience with an isolated ecosystem of plugins, and humans love a head-to-head competition.
Instead Bazel just orchestrates calling these tools.

## Quickstart

First we create a new workspace, which will be in a new directory.
We can use the `@bazel/create` npm package to do this in one command.
This is the fastest way to get started for most use cases.

> See [the installation page](install.html) for details and alternative methods.
```sh
$ npm init @bazel my_workspace
$ cd my_workspace
```

> You could do the same thing with yarn:
> ```sh
> $ yarn create @bazel my_workspace
> $ cd my_workspace
> ```
> Both of these commands are equivalent to `npx @bazel/create` which downloads the latest version of the `@bazel/create` package from npm and runs the program it contains.
> Run the tool with no arguments for command-line options and next steps.
Next we install some development tools.
For this example, we'll use Babel to transpile our JavaScript, Mocha for running tests, and http-server to serve our app.
These are arbitrary choices, you may use whatever are your favorites.
```sh
$ npm install @babel/core @babel/cli @babel/preset-env http-server mocha domino
```
Let's run these tools with Bazel. There are two ways to run tools:
- Use an auto-generated Bazel rule by importing from an `index.bzl` file in the npm package
- Use a custom rule in rules_nodejs or write one yourself
In this example we use the auto-generated rules.
First we need to import them, using a load statement.
So edit `BUILD.bazel` and add:
```python
load("@npm//@babel/cli:index.bzl", "babel")
load("@npm//mocha:index.bzl", "mocha_test")
load("@npm//http-server:index.bzl", "http_server")
```
> This shows us that rules_nodejs has told Bazel that a workspace named @npm is available
> (think of the at-sign like a scoped package for Bazel).
> rules_nodejs will add `index.bzl` files exposing all the binaries the package manager installed
> (the same as the content of the `node_modules/.bin folder`).
> The three tools we installed are in this @npm scope and each has an index file with a .bzl extension.
Next we teach Bazel how to transform our JavaScript inputs into transpiled outputs.
Here we assume that you have `app.js` and `es5.babelrc` in your project. See [our example webapp](https://github.com/bazelbuild/rules_nodejs/tree/1.4.0/examples/webapp) for an example of what those files might look like.
Now we want Babel to produce `app.es5.js` so we add to `BUILD.bazel`:

```python
babel(
name = "compile",
data = [
"app.js",
"es5.babelrc",
"@npm//@babel/preset-env",
],
outs = ["app.es5.js"],
args = [
"app.js",
"--config-file",
"./$(execpath es5.babelrc)",
"--out-file",
"$(execpath app.es5.js)",
],
)
```

> This just calls the Babel CLI, so you can see [their documentation](https://babeljs.io/docs/en/babel-cli) for what arguments to pass.
> We use the $(execpath) helper in Bazel so we don't need to hardcode paths to the inputs or outputs.
We can now build the application: `npm run build`

and we see the .js outputs from babel appear in the `dist/bin` folder.

Let's serve the app to see how it looks, by adding to `BUILD.bazel`:

```
http_server(
name = "server",
data = [
"index.html",
"app.es5.js",
],
args = ["."],
)
```

Add a `serve` entry to the scripts in `package.json`:

```json
{
"scripts": {
"serve": "ibazel run :server"
}
}
```

> ibazel is the watch mode for bazel.
>
> Note that on Windows, you need to pass `--enable_runfiles` flag to Bazel.
> That's because Bazel creates a directory where inputs and outputs both conveniently appear together.
Now we can serve the app: `npm run serve`

Finally we'll add a test using Mocha, and the domino package so we don't need a browser. Add to `BUILD.bazel`:

```python
mocha_test(
name = "unit_tests",
args = ["*.spec.js"],
data = glob(["*.spec.js"]) + [
"@npm//domino",
"app.es5.js",
],
)
```

Run the tests: `npm test`

## Next steps

Look through the `/examples` directory in this repo for many examples of running tools under Bazel.
Expand Down
43 changes: 0 additions & 43 deletions packages/create/BUILD.bazel

This file was deleted.

19 changes: 0 additions & 19 deletions packages/create/README.md

This file was deleted.

Loading

0 comments on commit 222509e

Please sign in to comment.