Skip to content
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

fix(Turborepo): copy yarn berry config files when running turbo prune #6073

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions crates/turborepo-lib/src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ lazy_static! {
RelativeUnixPath::new(".npmrc").unwrap(),
Some(CopyDestination::Docker)
),
(
RelativeUnixPath::new(".yarnrc.yml").unwrap(),
Some(CopyDestination::Docker)
),
];
static ref ADDITIONAL_DIRECTORIES: Vec<(&'static RelativeUnixPath, Option<CopyDestination>)> = vec![
(
RelativeUnixPath::new(".yarn/plugins").unwrap(),
Some(CopyDestination::Docker)
),
(
RelativeUnixPath::new(".yarn/releases").unwrap(),
Some(CopyDestination::Docker)
),
];
}

Expand Down Expand Up @@ -153,6 +167,11 @@ pub fn prune(
prune.copy_file(&path, *required_for_install)?;
}

for (relative_path, required_for_install) in ADDITIONAL_DIRECTORIES.as_slice() {
let path = relative_path.to_anchored_system_path_buf();
prune.copy_directory(&path, *required_for_install)?;
}

prune.copy_turbo_json(&workspace_names)?;

let original_patches = prune
Expand Down Expand Up @@ -320,6 +339,34 @@ impl<'a> Prune<'a> {
Ok(())
}

fn copy_directory(
&self,
path: &AnchoredSystemPath,
destination: Option<CopyDestination>,
) -> Result<(), Error> {
let from_path = self.root.resolve(path);
if !from_path.try_exists()? {
trace!("{from_path} doesn't exist, skipping copying");
return Ok(());
}
let full_to = self.full_directory.resolve(path);
turborepo_fs::recursive_copy(&from_path, full_to)?;
if matches!(destination, Some(CopyDestination::All)) {
let out_to = self.out_directory.resolve(path);
turborepo_fs::recursive_copy(&from_path, out_to)?;
}
if self.docker
&& matches!(
destination,
Some(CopyDestination::Docker) | Some(CopyDestination::All)
)
{
let docker_to = self.docker_directory().resolve(path);
turborepo_fs::recursive_copy(&from_path, docker_to)?;
}
Ok(())
}

fn copy_workspace(&self, package_json_path: &AnchoredSystemPath) -> Result<(), Error> {
let package_json_path = self.root.resolve(package_json_path);
let original_dir = package_json_path
Expand Down
10 changes: 10 additions & 0 deletions examples/with-berry/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ["custom"],
settings: {
next: {
rootDir: ["apps/*/"],
},
},
};
41 changes: 41 additions & 0 deletions examples/with-berry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# next.js
.next/
out/
build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# turbo
.turbo

# yarn
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
874 changes: 874 additions & 0 deletions examples/with-berry/.yarn/releases/yarn-3.6.3.cjs

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/with-berry/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.6.3.cjs
81 changes: 81 additions & 0 deletions examples/with-berry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Turborepo starter with berry (yarn v2+)

This is an official starter Turborepo.

## Using this example

Run the following command:

```sh
npx create-turbo@latest -e with-berry
```

## What's inside?

This Turborepo uses [yarn v2+ (berry)](https://yarnpkg.com/) as a packages manager. It includes the following packages/apps:

### Apps and Packages

- `docs`: a [Next.js](https://nextjs.org/) app
- `web`: another [Next.js](https://nextjs.org/) app
- `ui`: a stub React component library shared by both `web` and `docs` applications
- `eslint-config-custom`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `tsconfig`: `tsconfig.json`s used throughout the monorepo

Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).

### Utilities

This Turborepo has some additional tools already setup for you:

- [TypeScript](https://www.typescriptlang.org/) for static type checking
- [ESLint](https://eslint.org/) for code linting
- [Prettier](https://prettier.io) for code formatting

### Build

To build all apps and packages, run the following command:

```
cd my-turborepo
yarn build
```

### Develop

To develop all apps and packages, run the following command:

```
cd my-turborepo
yarn dev
```

### Remote Caching

Turborepo can use a technique known as [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching) to share cache artifacts across machines, enabling you to share build caches with your team and CI/CD pipelines.

By default, Turborepo will cache locally. To enable Remote Caching you will need an account with Vercel. If you don't have an account you can [create one](https://vercel.com/signup), then enter the following commands:

```
cd my-turborepo
npx turbo login
```

This will authenticate the Turborepo CLI with your [Vercel account](https://vercel.com/docs/concepts/personal-accounts/overview).

Next, you can link your Turborepo to your Remote Cache by running the following command from the root of your turborepo:

```
npx turbo link
```

## Useful Links

Learn more about the power of Turborepo:

- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)
4 changes: 4 additions & 0 deletions examples/with-berry/apps/docs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["custom"],
};
34 changes: 34 additions & 0 deletions examples/with-berry/apps/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
30 changes: 30 additions & 0 deletions examples/with-berry/apps/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Getting Started

First, run the development server:

```bash
yarn dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn/foundations/about-nextjs) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
11 changes: 11 additions & 0 deletions examples/with-berry/apps/docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
10 changes: 10 additions & 0 deletions examples/with-berry/apps/docs/app/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Button, Header } from "ui";

export default function Page() {
return (
<>
<Header text="Docs" />
<Button />
</>
);
}
5 changes: 5 additions & 0 deletions examples/with-berry/apps/docs/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
4 changes: 4 additions & 0 deletions examples/with-berry/apps/docs/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
reactStrictMode: true,
transpilePackages: ["ui"],
};
25 changes: 25 additions & 0 deletions examples/with-berry/apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "docs",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev --port 3001",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "^13.4.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"ui": "*"
},
"devDependencies": {
"@types/node": "^17.0.12",
"@types/react": "^18.2.5",
"@types/react-dom": "^18.2.4",
"eslint-config-custom": "*",
"tsconfig": "*",
"typescript": "^4.5.3"
}
}
8 changes: 8 additions & 0 deletions examples/with-berry/apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "tsconfig/nextjs.json",
"compilerOptions": {
"plugins": [{ "name": "next" }]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
4 changes: 4 additions & 0 deletions examples/with-berry/apps/web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["custom"],
};
34 changes: 34 additions & 0 deletions examples/with-berry/apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
Loading
Loading