这是indexloc提供的服务,不要输入任何密码
Skip to content

docs: Improve getting started #1095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 45 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
37d3c5b
upgrade nextra
shuding Apr 18, 2022
3005445
upgrade nextra
shuding Apr 18, 2022
ad2352e
Merge branch 'main' into shu/4eca
shuding Apr 18, 2022
a0bd021
Update lockfile
jaredpalmer Apr 19, 2022
c352209
Upgrade nextra
jaredpalmer Apr 20, 2022
94f50bf
Tweak getting started
jaredpalmer Apr 21, 2022
b64fc67
Merge branch 'main' into jp/docs/update-getting-started
jaredpalmer Apr 21, 2022
768f90d
Merge branch 'main' into jp/docs/update-getting-started
jaredpalmer Apr 21, 2022
06918fa
Merge branch 'main' into jp/docs/update-getting-started
Apr 26, 2022
e3c0f0f
fix conflicts
megbird May 5, 2022
66610ad
major edits
megbird May 5, 2022
74feadd
more clean up
megbird May 5, 2022
3f70d8c
Update docs/pages/docs/getting-started.mdx
megbird May 5, 2022
5f01183
Merge branch 'main' into jp/docs/update-getting-started
megbird May 5, 2022
9d2d4cb
workspaces cleanup
megbird May 5, 2022
7c90886
Merge branch 'main' into jp/docs/update-getting-started
megbird May 5, 2022
499018f
fix build
megbird May 5, 2022
c1484e7
apply @nathanhammond's feedback
megbird May 5, 2022
22b4bed
fix
megbird May 5, 2022
06e50fa
up one more level
megbird May 5, 2022
d31518c
Merge branch 'main' into jp/docs/update-getting-started
megbird May 6, 2022
9d2281c
fix
megbird May 6, 2022
b999350
again
megbird May 6, 2022
e1cf0e9
another
megbird May 6, 2022
a082de7
k
megbird May 6, 2022
8773a1d
again
megbird May 6, 2022
7b0a06e
fix
megbird May 6, 2022
c298ea4
typo
megbird May 6, 2022
de5d2e2
one last thing
megbird May 6, 2022
369d3c6
Update docs/pages/docs/getting-started.mdx
megbird May 9, 2022
d65ab4f
Update docs/pages/docs/getting-started.mdx
megbird May 9, 2022
1f58698
Update docs/pages/docs/core-concepts/workspaces.mdx
megbird May 9, 2022
820126e
Update docs/pages/docs/core-concepts/workspaces.mdx
megbird May 9, 2022
e431224
Update docs/pages/docs/getting-started.mdx
megbird May 9, 2022
19f7532
Update docs/pages/docs/core-concepts/workspaces.mdx
megbird May 9, 2022
3771df8
Update docs/pages/docs/core-concepts/workspaces.mdx
megbird May 9, 2022
a7005aa
Update docs/pages/docs/core-concepts/workspaces.mdx
megbird May 9, 2022
858b527
Merge branch 'main' into jp/docs/update-getting-started
megbird May 23, 2022
27d4517
update with root/monorepo clarity
megbird May 23, 2022
1d31402
Update docs/pages/docs/core-concepts/pipelines.mdx
jaredpalmer May 31, 2022
e47e2bb
Update docs/pages/docs/getting-started.mdx
jaredpalmer May 31, 2022
121328c
Update docs/pages/docs/getting-started.mdx
jaredpalmer May 31, 2022
453b977
Update docs/pages/docs/getting-started.mdx
jaredpalmer May 31, 2022
4f409e7
Update docs/pages/docs/core-concepts/workspaces.mdx
jaredpalmer May 31, 2022
38c5d3a
Merge branch 'main' into jp/docs/update-getting-started
jaredpalmer May 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/pages/docs/core-concepts/filtering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import HeartIcon from "@heroicons/react/solid/HeartIcon";
Filtering packages allows you to target your tasks to only the packages you care about.
Turborepo supports a `pnpm`-like `--filter` flag that allows you to select the packages
that will act as "entry points" into your monorepo's package/task graph.
You can filter packages by name, directory, include dependents/dependencies, and by changes
You can filter your project by package name, package directory, whether packages include dependents/dependencies, and by changes
in git history.

`turbo` will run each task against each matched package, ensuring that any dependencies
Expand All @@ -34,7 +34,7 @@ Supports exact matches (`--filter=my-pkg`), and globs (`--filter=*my-pkg*`) are
Scoped packages (`@foo/bar`) can be abbreviated to just the package name (`bar`) as long as the package name
is unique within the monorepo (e.g. `@foo/bar` exists, but `@baz/bar` does not).

The root package can be selected using the token `//`.
The monorepo's root package can be selected using the token `//`.

```sh
# Build 'my-pkg', letting turbo infer task dependencies from the pipeline defined in turbo.json
Expand Down
1 change: 1 addition & 0 deletions docs/pages/docs/core-concepts/meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"workspaces": "Workspaces",
"pipelines": "Pipelines",
"filtering": "Filtering Packages",
"caching": "Caching",
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/docs/core-concepts/pipelines.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Notice that `turbo` is able to schedule tasks efficiently--collapsing waterfalls

## Defining a `pipeline`

To define your project's task dependency graph, use the [`pipeline`](../reference/configuration#pipeline) key in the `turbo.json` configuration file at the root of your project. `turbo` interprets this configuration and conventions to properly schedule, execute, and cache the outputs of the tasks in your project.
To define your monorepo's task dependency graph, use the [`pipeline`](../reference/configuration#pipeline) key in the `turbo.json` configuration file at the root of your monorepo. `turbo` interprets this configuration and conventions to properly schedule, execute, and cache the outputs of the tasks in your monorepo.

Each key in the [`pipeline`](../reference/configuration#pipeline) object is the name of a task that can be executed by [`turbo run`](../reference/command-line-reference#turbo-run-task1-task2-1). You can specify its dependencies with the [`dependsOn`](../reference/configuration#dependson) key beneath it as well as some other options related to [caching](./caching).

Expand Down Expand Up @@ -222,12 +222,12 @@ This seems like it goes against the `"test": { "dependsOn": ["build"] }` and `"d
[`outputs`](../reference/configuration#outputs) at the moment.**
</Callout>

### Running tasks defined in the root `package.json`
### Running tasks defined in the monorepo's root `package.json` file

`turbo` can run tasks that exist in the `package.json` file at the root of the monorepo.
These must be added to the pipeline configuration using the form `"//#<task>": {...}`. This is
true even for tasks that already have their own entry. For example, if you already have `"build": {...}`
in your pipeline, but want to include the `build` script defined in the root `package.json` when running
in your pipeline, but want to include the `build` script defined in the monorepo's root `package.json` file when running
`turbo run build`, you must opt the root into it by also including `"//#build": {...}` in your configuration.
Conversely, you _do not_ need to define a generic `"my-task": {...}` entry if all you need is `"//#my-task": {...}`.

Expand Down Expand Up @@ -263,9 +263,9 @@ A sample pipeline that defines the root task `format` and opts the root into `te
}
```

**A note on recursion**: Scripts defined in the root `package.json` often call `turbo` themselves.
**A note on recursion**: Scripts defined in the monorepo's root `package.json` often call `turbo` themselves.
For example, the `build` script might be `turbo run build`. In this situation, including `//#build` in
`turbo run build` will cause infinite recursion. It is for this reason that tasks run from the root must
`turbo run build` will cause infinite recursion. It is for this reason that tasks run from the monorepo's root must
be explicitly opted into via including `//#<task>` in the pipeline configuration. `turbo` includes
some best-effort checking to produce an error in the recursion situations, but it is up to you to to only
opt in those tasks which don't themselves trigger a `turbo` run that would recurse.
Expand Down
201 changes: 201 additions & 0 deletions docs/pages/docs/core-concepts/workspaces.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
title: Workspaces
description: Use workspaces to organize your turborepo apps and packages.
---

import Callout from "../../../components/callout";
import HeartIcon from "@heroicons/react/solid/HeartIcon";
import { Tabs, Tab } from '../../../components/Tabs'

# Getting started with workspaces

Workspaces are a feature implemented by package managers to assist with working on multiple apps and packages in the same codebase.

Turborepo is compatible with three package managers, [npm](https://docs.npmjs.com/cli/v8/using-npm/workspaces#description), [Yarn](https://classic.yarnpkg.com/lang/en/docs/workspaces/), and [pnpm](https://pnpm.io/workspaces), each with its own implementation of workspaces and functionality. Your package manager will determine how your apps and packages are organized in your workspaces and run in your turborepo.

## Configuring workspaces

To use workspaces, you'll first need to declare their file system locations to your package manager

A common/recommended convention is to have an `apps` folder and a `packages` folder. The `apps` folder can contain workspaces for launchable apps, such as a Next.js or Svelte app. The `packages` folder can contain workspaces for packages that are used by either an app, or another package. Again, this isn't a requirement, but just a suggested folder structure

<Callout>
Unlike when working in a single-package repository, you'll need to consider how to name your workspaces. If you avoid npm naming collisions, you can use an npm organization or user scope to namespace your packages. For example, you might set the `name` key in `./apps/api/package.json` to `@mycompany/api`.
</Callout>

<Tabs items={['npm', 'yarn', 'pnpm']} storageKey="selected-pkg-manager">
<Tab>

Add the folders you want to configure as workspaces to the `workspaces` field in your root `package.json` file. This field contains a list of workspace folders in the form of globs:

```json
{
"name": "monorepo",
"version": "1.0.0",
"workspaces": [
"docs",
"apps/*",
"packages/*"
]
}
```

</Tab>
<Tab>

Add the folders you want to configure as workspaces to the `workspaces` field in the root `package.json` file. This field contains a list of workspace folders in the form of globs:

```json
{
"name": "monorepo",
"version": "1.0.0",
"workspaces": [
"docs",
"apps/*",
"packages/*"
]
}
```

</Tab>

<Tab>

Add the folders you want to configure as workspaces to the `pnpm-workspace.yaml` file that exists in your root directory. This file contains a list of workspace folders in the form of globs:

```yaml
packages:
- "docs"
- "apps/*"
- "packages/*"
```

</Tab>
</Tabs>

Each folder that matches any of the globs in the list is considered a workspace folder. In the examples, the `apps` and `packages` folders contain folders that are workspaces, and the `docs` folder itself is a workspace.

```
monorepo/
├─ docs/
├─ apps/
│ ├─ api/
│ ├─ mobile/
├─ packages/
│ ├─ tsconfig/
│ ├─ config/
├─ sdk/
```

Using the same workspace configuration, the `monorepo/docs/`, `monorepo/apps/api/`, `monorepo/apps/mobile/`, `monorepo/packages/config/`, and `monorepo/packages/tsconfig/` folders are all considered workspaces.
The `monorepo/sdk/` folder is not considered a workspace and it is not included in the workspace configuration.

## Managing workspaces

When you move, delete, or rename your workspaces, you will have to make sure that all folders linked within your `package.json` matches. Anytime you change the configuration of your workspace, make sure all the dependencies of the workspace are also updated. Re-run your npm client's install command to check your configuration. If there are any problems after that, you may have to delete your `node_modules` folder and run an install again.

## Managing dependencies

To manage dependencies within workspaces in your monorepo, you will need to run commands that will only manage the dependencies of each workspace rather than for the entire monorepo.

<Tabs items={['npm', 'yarn', 'pnpm']} storageKey="selected-pkg-manager">
<Tab>

**Install**
```bash
npm install <package> -w=<workspace>
```

Example:
```bash
npm install react -w=web
```

**Uninstall**
```bash
npm uninstall <package> -w=<workspace>
```

Example:
```bash
npm uninstall react -w=web
```

**Update**
```bash
npm update <package> -w=<workspace>
```

Example:
```bash
npm update react -w=web
```

</Tab>
<Tab>

**Install**
```bash
yarn workspace <workspace> add <package>
```

Example:
```bash
yarn workspace web add react
```

**Uninstall**
```bash
yarn workspace <workspace> remove <package>
```

Example:
```bash
yarn workspace web remove react
```

**Update**
```bash
yarn workspace <workspace> upgrade <package>
```

Example:
```bash
yarn workspace web upgrade react
```

</Tab>
<Tab>

**Install**
```bash
pnpm add <package> --filter <workspace>
```

Example:
```bash
pnpm add react --filter web
```

**Uninstall**
```bash
pnpm uninstall <package> --filter <workspace>
```

Example:
```bash
pnpm uninstall react --filter web
```

**Update**
```bash
pnpm up <package> --filter <workspace>
```

Example:
```bash
pnpm up react --filter web
```

</Tab>
</Tabs>
Loading