Skip to content

Commit

Permalink
chore: adopt turborepo (#5316
Browse files Browse the repository at this point in the history
* chore: revert pnpm use plain npm

* fix: package.json

* chore: remove warnings and add node_env

* chore: cross-env

* fix: fix turbo pipelines

* chore: only cache certain files

* chore: turbo shouldn't care about coverage outputs

* chore: proper inputs and outputs for pipelines

* chore: do not store some outputs and updated inputs for lint

* chore: added prettier configs

* chore: remove console.info

* chore: updated inputs of all other entries
  • Loading branch information
ovflowd authored Apr 21, 2023
1 parent 1f4530e commit b8c76cd
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 264 deletions.
14 changes: 12 additions & 2 deletions .browserslistrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# https://github.com/browserslist/browserslist#readme

defaults
Explorer >= 10
defaults and supports es6-module
maintained node versions

[production]

cover 95%
not dead

[development]

defaults and supports es6-module
maintained node versions
6 changes: 3 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Please follow this check list to ensure that you've followed all items before op
-->

- [ ] I have read the [Contributing Guidelines](https://github.com/nodejs/nodejs.org/blob/main/CONTRIBUTING.md) and made commit messages that follow the guideline.
- [ ] I have run `lint` to ensure the code follows the style guide. And run `npm run lint:fix` to fix the style errors if necessary.
- [ ] I have run `npm run format` to ensure the code follows the style guide.
- [ ] I have run `npm run test` to check if all tests are passing, and/or `npm run test -- -u` to update snapshots if I created and/or updated React Components.
- [ ] I have run `npx turbo lint` to ensure the code follows the style guide. And run `npx turbo lint:fix` to fix the style errors if necessary.
- [ ] I have run `npx turbo format` to ensure the code follows the style guide.
- [ ] I have run `npx turbo test` to check if all tests are passing, and/or `npx turbo test:snapshot` to update snapshots if I created and/or updated React Components.
- [ ] I've covered new added functionality with unit tests if necessary.
20 changes: 13 additions & 7 deletions .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
steps:
- name: Git Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -36,28 +38,30 @@ jobs:
- name: Setup GitHub Pages
uses: actions/configure-pages@v3

- name: Restore Next.js cache
- name: Restore Cache
uses: actions/cache/restore@v3
with:
path: |
.next/cache
node_modules/.cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-

- name: Build Next.js
run: npm run build
run: npx turbo build
env:
NODE_OPTIONS: '--max_old_space_size=4096'
NEXT_BASE_PATH: /nodejs.org

- name: Save Next.js cache
- name: Save Cache
uses: actions/cache/save@v3
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.next/cache/eslint') }}
node_modules/.cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('node_modules/.cache/turbo') }}

- name: Export Next.js static files
run: npm run export
run: npx turbo export

- name: Upload Artifact
uses: actions/upload-pages-artifact@v1
Expand All @@ -66,11 +70,13 @@ jobs:

deploy:
name: Deploy to GitHub Pages
runs-on: ubuntu-latest
needs: build

environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build

steps:
- name: Deploy to GitHub Pages
id: deployment
Expand Down
51 changes: 42 additions & 9 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
pull_request:
workflow_dispatch:

env:
FORCE_COLOR: 2

jobs:
lint:
name: Lint
Expand All @@ -15,6 +12,8 @@ jobs:
steps:
- name: Git Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -25,8 +24,22 @@ jobs:
- name: Install NPM packages
run: npm ci

- name: Restore Cache
uses: actions/cache/restore@v3
with:
path: |
node_modules/.cache
key: ${{ runner.os }}-tests-${{ hashFiles('**/package-lock.json') }}-

- name: Run Linting
run: npm run lint
run: npx turbo lint

- name: Save Cache
uses: actions/cache/save@v3
with:
path: |
node_modules/.cache
key: ${{ runner.os }}-tests-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('node_modules/.cache') }}

unit-tests:
name: Tests on ${{ matrix.os }}
Expand All @@ -40,6 +53,8 @@ jobs:
steps:
- name: Git Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -50,8 +65,22 @@ jobs:
- name: Install NPM packages
run: npm ci

- name: Restore Cache
uses: actions/cache/restore@v3
with:
path: |
node_modules/.cache
key: ${{ runner.os }}-tests-${{ hashFiles('**/package-lock.json') }}-

- name: Run Unit Tests
run: npm run test-ci
run: npx turbo test:ci

- name: Save Cache
uses: actions/cache/save@v3
with:
path: |
node_modules/.cache
key: ${{ runner.os }}-tests-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('node_modules/.cache') }}

build:
name: Build on ${{ matrix.os }}
Expand All @@ -65,6 +94,8 @@ jobs:
steps:
- name: Git Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Set up Node.js
uses: actions/setup-node@v3
Expand All @@ -75,21 +106,23 @@ jobs:
- name: Install NPM packages
run: npm ci

- name: Restore Next.js cache
- name: Restore Cache
uses: actions/cache/restore@v3
with:
path: |
.next/cache
node_modules/.cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-

- name: Build Next.js
run: npm run build
run: npx turbo build
env:
NODE_OPTIONS: '--max_old_space_size=4096'

- name: Save Next.js cache
- name: Save Cache
uses: actions/cache/save@v3
with:
path: |
.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('.next/cache/eslint') }}
node_modules/.cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('node_modules/.cache/turbo') }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@ storybook-static

# Vercel Config
.vercel

# TurboRepo
.turbo
3 changes: 3 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const config: StorybookConfig = {
name: '@storybook/nextjs',
options: {},
},
features: {
storyStoreV7: true,
},
docs: {
autodocs: 'tag',
},
Expand Down
8 changes: 8 additions & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Next.js files
build

# Public Folder
public

# Jest
coverage

# Storybook
storybook-static
33 changes: 17 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ git checkout -b name-of-your-branch

```bash
npm ci # installs this project's dependencies
npm run serve # starts a preview of your local changes
npx turbo serve # starts a preview of your local changes
```

7. Perform a merge to sync your current branch with the upstream branch.
Expand All @@ -59,10 +59,10 @@ git fetch upstream
git merge upstream/main
```

8. Run `npm run format` to confirm that linting, and formatting are passing.
8. Run `npx turbo format` to confirm that linting, and formatting are passing.

```bash
npm run format
npx turbo format
```

9. Once you're happy with your changes, add and commit them to your branch,
Expand All @@ -83,25 +83,26 @@ npm run format

#### Serve/Build Options

- `npm run serve` runs Next.js's Local Development Server, listening by default on `http://localhost:3000/`.
- `npm run build` builds the Application on Production mode. The output is by default within `.next` folder.
- `npm run export` exports the website from the `.next` into a fully static website. The output is by default within `build` folder.
- `npx turbo serve` runs Next.js's Local Development Server, listening by default on `http://localhost:3000/`.
- `npx turbo build` builds the Application on Production mode. The output is by default within `.next` folder.
- `npx turbo export` exports the website from the `.next` into a fully static website. The output is by default within `build` folder.
- This is what it's used to deploy the website on our current Node.js servers.
- `npm run start` starts a web server running serving the built content from `npm run build`
- `npx turbo start` starts a web server running serving the built content from `npx turbo build`

#### Other CLI options

We also offer other commands that offer you assistance during your local development

- `npm run lint` runs the linter for all the js files.
- `npm run lint:fix` attempts to fix any linting errors
- `npm run prettier` runs the prettier for all the js files.
- `npm run prettier:fix` attempts to fix any style errors
- `npm run format` formats and fixes the whole codebase
- `npm run scripts:release-post` generates a release post for the current release
- **Usage:** `npm run scripts:release-post -- --version=vXX.X.X --force`
- `npm run storybook` starts Storybook's local server
- `npm run build-storybook` builds Storybook as a static web application for publishing
- `npx turbo lint` runs the linter for all the js files.
- `npx turbo lint:fix` attempts to fix any linting errors
- `npx turbo prettier` runs the prettier for all the js files.
- `npx turbo prettier:fix` attempts to fix any style errors
- `npx turbo format` formats and fixes the whole codebase
- `npx turbo scripts:release-post` generates a release post for the current release
- **Usage:** `npx turbo scripts:release-post -- --version=vXX.X.X --force`
- `npx turbo storybook` starts Storybook's local server
- `npx turbo storybook:build` builds Storybook as a static web application for publishing
- `npx turbo test` runs jest (unit-tests) locally

## Creating Components

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

```bash
npm ci
npm run serve
npx turbo serve
# listening at localhost:3000
```

Expand Down
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const createJestConfig = nextJest({

/** @type {import('jest').Config} */
const customJestConfig = {
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
setupFilesAfterEnv: ['<rootDir>/jest.setup.mjs'],
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
};
Expand Down
File renamed without changes.
2 changes: 0 additions & 2 deletions next.data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ preBuild.generateWebsiteFeeds(cachedBlogData);
const cachedNodeVersionData = getNodeVersionData();
const cachedLocalisationData = getLocalisationData();

console.info('info - Pre-build files generated successfully!');

const getNextData = async (content, { route }) => {
const localisationData = await cachedLocalisationData(route);
const nodeVersionData = await cachedNodeVersionData(route);
Expand Down
Loading

1 comment on commit b8c76cd

@vercel
Copy link

@vercel vercel bot commented on b8c76cd Apr 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.