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

Turborepo support #557

Merged
merged 39 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d02c8c1
Turborepo support
aleksrutins Sep 14, 2022
ac8c15b
Merge current main, add tests
aleksrutins Sep 15, 2022
acd033e
Merge branch 'railwayapp:main' into turborepo
aleksrutins Sep 15, 2022
b6e25c1
add docs, use node v18
aleksrutins Sep 15, 2022
6ca15f7
Update test to expect node 18
aleksrutins Sep 15, 2022
19b27e2
Fix lints
aleksrutins Sep 15, 2022
e09bbd1
Remove weird F# stuff
aleksrutins Sep 15, 2022
a16c1aa
[untested] add docker run test
aleksrutins Sep 15, 2022
7706acc
Update docs/pages/docs/providers/node.md
aleksrutins Sep 17, 2022
c453df2
Use snake case
aleksrutins Sep 17, 2022
3e357ff
Use snake case, pt. 2
aleksrutins Sep 17, 2022
c1ed597
fixes
Milo123459 Sep 17, 2022
9ba1df9
Don't care if bind fails
aleksrutins Sep 17, 2022
4a30b94
Use correct package manager/dlx command
aleksrutins Sep 21, 2022
409d293
Use executor everywhere, remove drop
aleksrutins Sep 24, 2022
c78bc4d
Fix detecting app name
aleksrutins Sep 24, 2022
1c252cb
Merge remote-tracking branch 'upstream/main' into turborepo
aleksrutins Sep 29, 2022
542f383
Fix lints
aleksrutins Sep 29, 2022
6e728b8
Update docs/pages/docs/providers/node.md
Milo123459 Oct 2, 2022
8ec1f1e
Check if requested app exists before running it
aleksrutins Oct 4, 2022
edb7099
Fix lints
aleksrutins Oct 4, 2022
eda95f9
Add custom app turborepo test
aleksrutins Oct 4, 2022
9293125
Merge branch 'main' into turborepo
Milo123459 Oct 8, 2022
0ab886c
Merge branch 'main' into turborepo
Milo123459 Oct 11, 2022
0b765f7
It finally works!
aleksrutins Oct 12, 2022
18802e5
clippy
aleksrutins Oct 12, 2022
f6943f7
Fix Turborepo test
aleksrutins Oct 18, 2022
dada3eb
Merge branch 'main' of github.com:railwayapp/nixpacks into turborepo
aleksrutins Oct 18, 2022
2e07507
Merge branch 'main' into turborepo
aleksrutins Oct 19, 2022
35ad8f7
Fall back to regular Node build behavior
aleksrutins Oct 19, 2022
456a45d
Extract get_executor
aleksrutins Oct 19, 2022
49bd5b2
Make app not found warning clearer
aleksrutins Oct 19, 2022
80c1835
Do not need to parallelize
aleksrutins Oct 19, 2022
4971203
Fall back to regular Node start behavior
aleksrutins Oct 19, 2022
5456239
Unwrap in turborepo test
aleksrutins Oct 19, 2022
fab55e9
Extract logic into `turborepo.rs`
aleksrutins Oct 19, 2022
638eb66
Merge branch 'main' into turborepo
coffee-cup Oct 19, 2022
0e5ba9c
Merge branch 'main' into turborepo
aleksrutins Oct 21, 2022
259ade3
Merge branch 'main' into turborepo
coffee-cup Oct 25, 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
7 changes: 7 additions & 0 deletions docs/pages/docs/providers/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The Node provider sets the following environment variables:
- `NODE_ENV=production`
- `NPM_CONFIG_PRODUCTION=false`: Ensure that dev deps are always installed
- `NIXPACKS_NX_APP_NAME`: Provide a name of the NX app you want to build from your NX Monorepo
- `NIXPACKS_TURBO_APP_NAME`: Provide the name of the app you want to build from your Turborepo, if there is no `start` pipeline.

## Setup

Expand Down Expand Up @@ -42,6 +43,8 @@ All dependencies found in `packages.json` are installed with either NPM, Yarn, o

The build script found in `package.json` if it exists or if its an NX Monorepo `(npm|pnpm|yarn|bun) run build <NxAppName> --configuration=production`.

Or, if it's a Turborepo monorepo (detected if `turbo.json` exists), the `build` pipeline will be called, if it exists; otherwise, the `build` script of the package referenced by `NIXPACKS_TURBO_APP_NAME` will be called, if the variable is provided; otherwise, it will fall back to the build script found in `package.json`.
Milo123459 marked this conversation as resolved.
Show resolved Hide resolved

## Start

The start command priority is
Expand All @@ -51,6 +54,10 @@ The start command priority is
- If the app is a NextJS project: `npm run start`
- If `targets.build.options.main` exists in the apps `Project.json`: `node <outputPath>/<mainFileName>.js` (e.g `node dist/apps/my-app/main.js`)
- Fallback: `node <outputPath>/index.js` (e.g `node dist/apps/my-app/index.js`)
- If Turborepo is detected
- If a `start` pipeline exists, call that;
- Otherwise, if `NIXPACKS_TURBO_APP_NAME` is provided, call the `start` script of that package;
- Otherwise, run `npx turbo run start`, which will simply run all `start` scripts in the monorepo in parallel.
- Start script in `package.json`
- Main file
- `index.js`
Expand Down
10 changes: 10 additions & 0 deletions examples/node-turborepo/.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/*/"],
},
},
};
33 changes: 33 additions & 0 deletions examples/node-turborepo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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*
.pnpm-debug.log*

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

# turbo
.turbo
73 changes: 73 additions & 0 deletions examples/node-turborepo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Turborepo starter

This is an official npm starter turborepo.

## What's inside?

This turborepo uses [npm](https://www.npmjs.com/) as a package 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
npm run build
```

### Develop

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

```
cd my-turborepo
npm run dev
```

### Remote Caching

Turborepo can use a technique known as [Remote Caching](https://turborepo.org/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:

- [Pipelines](https://turborepo.org/docs/core-concepts/pipelines)
- [Caching](https://turborepo.org/docs/core-concepts/caching)
- [Remote Caching](https://turborepo.org/docs/core-concepts/remote-caching)
- [Scoped Tasks](https://turborepo.org/docs/core-concepts/scopes)
- [Configuration Options](https://turborepo.org/docs/reference/configuration)
- [CLI Usage](https://turborepo.org/docs/reference/command-line-reference)
4 changes: 4 additions & 0 deletions examples/node-turborepo/apps/docs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["custom"],
};
30 changes: 30 additions & 0 deletions examples/node-turborepo/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) - 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.
5 changes: 5 additions & 0 deletions examples/node-turborepo/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.
5 changes: 5 additions & 0 deletions examples/node-turborepo/apps/docs/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const withTM = require("next-transpile-modules")(["ui"]);

module.exports = withTM({
reactStrictMode: true,
});
27 changes: 27 additions & 0 deletions examples/node-turborepo/apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "docs",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev --port 3001",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui": "*"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"eslint": "7.32.0",
"eslint-config-custom": "*",
"next-transpile-modules": "9.0.0",
"tsconfig": "*",
"@types/node": "^17.0.12",
"@types/react": "18.0.17",
"typescript": "^4.5.3"
}
}
10 changes: 10 additions & 0 deletions examples/node-turborepo/apps/docs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Button } from "ui";

export default function Docs() {
return (
<div>
<h1>Docs</h1>
<Button />
</div>
);
}
5 changes: 5 additions & 0 deletions examples/node-turborepo/apps/docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "tsconfig/nextjs.json",
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
4 changes: 4 additions & 0 deletions examples/node-turborepo/apps/web/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ["custom"],
};
30 changes: 30 additions & 0 deletions examples/node-turborepo/apps/web/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) - 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.
5 changes: 5 additions & 0 deletions examples/node-turborepo/apps/web/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.
5 changes: 5 additions & 0 deletions examples/node-turborepo/apps/web/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const withTM = require("next-transpile-modules")(["ui"]);

module.exports = withTM({
reactStrictMode: true,
});
27 changes: 27 additions & 0 deletions examples/node-turborepo/apps/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "web",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "12.2.5",
"react": "18.2.0",
"react-dom": "18.2.0",
"ui": "*"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"eslint": "7.32.0",
"eslint-config-custom": "*",
"next-transpile-modules": "9.0.0",
"tsconfig": "*",
"@types/node": "^17.0.12",
"@types/react": "18.0.17",
"typescript": "^4.5.3"
}
}
10 changes: 10 additions & 0 deletions examples/node-turborepo/apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Button } from "ui";

export default function Web() {
return (
<div>
<h1>Web</h1>
<Button />
</div>
);
}
5 changes: 5 additions & 0 deletions examples/node-turborepo/apps/web/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "tsconfig/nextjs.json",
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Loading