Skip to content

Commit

Permalink
workflow: switch to pnpm (vitejs#5060)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 authored and aleclarson committed Nov 8, 2021
1 parent 650d768 commit 2e1992b
Show file tree
Hide file tree
Showing 53 changed files with 9,372 additions and 11,678 deletions.
17 changes: 15 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,22 @@ module.exports = defineConfig({
'node/no-missing-import': [
'error',
{
allowModules: ['types', 'estree', 'testUtils', 'stylus'],
allowModules: [
'types',
'estree',
'testUtils',
'less',
'sass',
'stylus'
],
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts']
}
],
'node/no-missing-require': [
'error',
{
// for try-catching yarn pnp
allowModules: ['pnpapi'],
allowModules: ['pnpapi', 'vite'],
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts']
}
],
Expand Down Expand Up @@ -91,6 +98,12 @@ module.exports = defineConfig({
'no-console': ['error']
}
},
{
files: ['packages/vite/types/**'],
rules: {
'node/no-extraneous-import': 'off'
}
},
{
files: ['packages/playground/**'],
rules: {
Expand Down
59 changes: 24 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,34 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

- name: Install pnpm
uses: pnpm/action-setup@v2.0.1
with:
version: 6.15.1

- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node_version }}
cache: "pnpm"

- name: Get yarn cache directory
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Set dependencies cache
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles('yarn.lock') }}
${{ runner.os }}-${{ matrix.node_version }}-
- name: Versions
run: yarn versions

- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Install deps
run: pnpm install

- name: Build vite
run: yarn ci-build-vite
run: pnpm run ci-build-vite

- name: Build plugin-vue
run: yarn build-plugin-vue
run: pnpm run build-plugin-vue

- name: Build plugin-react
run: yarn build-plugin-react
run: pnpm run build-plugin-react

- name: Test serve
run: yarn test-serve --runInBand
run: pnpm run test-serve -- --runInBand

- name: Test build
run: yarn test-build --runInBand
run: pnpm run test-build -- --runInBand

lint:
runs-on: ubuntu-latest
Expand All @@ -80,25 +70,24 @@ jobs:
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v2.0.1
with:
version: 6.15.1

- name: Set node version to 14
uses: actions/setup-node@v2
with:
node-version: 14
cache: "pnpm"

- name: Set dependencies cache
uses: actions/cache@v2
with:
path: ~/.cache/yarn
key: lint-dependencies-${{ hashFiles('yarn.lock') }}
restore-keys: |
lint-dependencies-${{ hashFiles('yarn.lock') }}
lint-dependencies-
- name: Install deps
run: pnpm install

- name: Prepare
run: |
yarn install --frozen-lockfile
yarn ci-build-vite
yarn build-plugin-vue
pnpm run ci-build-vite
pnpm run build-plugin-vue
- name: Lint
run: yarn lint
run: pnpm run lint
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ packages/plugin-vue/dist/
packages/*/CHANGELOG.md
LICENSE.md
.prettierignore
yarn.lock
pnpm-lock.yaml
pnpm-workspace.yaml
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
34 changes: 24 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Hi! We are really excited that you are interested in contributing to Vite. Befor

## Repo Setup

The Vite repo is a monorepo using Yarn workspaces. The package manager used to install and link dependencies must be [Yarn v1](https://classic.yarnpkg.com/).
The Vite repo is a monorepo using pnpm workspaces. The package manager used to install and link dependencies must be [pnpm](https://pnpm.io/).

To development and test the core `vite` package:

1. Go to `packages/vite` and run `yarn dev`. This starts `rollup` in watch mode.
1. Go to `packages/vite` and run `pnpm run dev`. This starts `rollup` in watch mode.

2. Run `yarn link` in `packages/vite`. This links `vite` globally so that you can:
2. Run `pnpm link` in `packages/vite`. This links `vite` globally so that you can:

- Run `yarn link vite` in another Vite project to use the locally built Vite;
- Run `pnpm link vite` in another Vite project to use the locally built Vite;
- Use the `vite` binary anywhere.

## Running Tests
Expand All @@ -21,15 +21,15 @@ Each package under `packages/playground/` contains a `__tests__` directory. The

Each test can be run under either dev server mode or build mode.

- `yarn test` by default runs every test in both serve and build mode.
- `pnpm test` by default runs every test in both serve and build mode.

- `yarn test-serve` runs tests only under serve mode.
- `pnpm run test-serve` runs tests only under serve mode. This is just calling `jest` so you can pass any Jest flags to this command. Since Jest will attempt to run tests in parallel, if your machine has many cores this may cause flaky test failures with multiple Playwright instances running at the same time. You can force the tests to run in series with `pnpm run test-serve -- --runInBand`.

- `yarn test-build` runs tests only under build mode.
- `pnpm run test-build` runs tests only under build mode.

- You can also use `yarn test-serve [match]` or `yarn test-build [match]` to run tests in a specific playground package, e.g. `yarn test-serve css` will run tests for both `playground/css` and `playground/css-codesplit` under serve mode.
- You can also use `pnpm run test-serve -- [match]` or `pnpm run test-build -- [match]` to run tests in a specific playground package, e.g. `pnpm run test-serve -- css` will run tests for both `playground/css` and `playground/css-codesplit` under serve mode.

Note package matching is not available for the `yarn test` script, which always runs all tests.
Note package matching is not available for the `pnpm test` script, which always runs all tests.

### Test Env and Helpers

Expand Down Expand Up @@ -75,6 +75,20 @@ test('?raw import', async () => {
})
```

## Note on Test Dependencies

In many test cases we need to mock dependencies using `link:` and `file:` protocols (which are supported by package managers like `yarn` and `pnpm`). However, `pnpm` treats `link:` and `file:` the same way and always use symlinks. This can be undesirable in cases where we want the dependency to be actually copied into `node_modules`.

To work around this, playground packages that uses the `file:` protocol should also include the following `postinstall` script:

```jsonc
"scripts": {
//...
"postinstall": "node ../../../scripts/patchFileDeps"
}

This script patches the dependencies using `file:` protocol to match the copying behavior instead of linking.

## Debug Logging

You can set the `DEBUG` environment variable to turn on debugging logs. E.g. `DEBUG="vite:resolve"`. To see all debug logs you can set `DEBUG="vite:*"`, but be warned that it will be quite noisy. You can run `grep -r "createDebugger('vite:" packages/vite/src/` to see a list of available debug scopes.
Expand All @@ -92,7 +106,7 @@ You can set the `DEBUG` environment variable to turn on debugging logs. E.g. `DE

- If you are resolving a special issue, add `(fix #xxxx[,#xxxx])` (#xxxx is the issue id) in your PR title for a better release log, e.g. `fix: update entities encoding/decoding (fix #3899)`.
- Provide a detailed description of the bug in the PR. Live demo preferred.
- Add appropriate test coverage if applicable. You can check the coverage of your code addition by running `yarn test --coverage`.
- Add appropriate test coverage if applicable.

- It's OK to have multiple small commits as you work on the PR - GitHub can automatically squash them before merging.
Expand Down
10 changes: 5 additions & 5 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ You can specify additional CLI options like `--port` or `--https`. For a full li

## Using Unreleased Commits

If you can't wait for a new release to test the latest features, you will need to clone the [vite repo](https://github.com/vitejs/vite) to your local machine and then build and link it yourself ([Yarn 1.x](https://classic.yarnpkg.com/lang/en/) is required):
If you can't wait for a new release to test the latest features, you will need to clone the [vite repo](https://github.com/vitejs/vite) to your local machine and then build and link it yourself ([pnpm](https://pnpm.io/) is required):

```bash
git clone https://github.com/vitejs/vite.git
cd vite
yarn
pnpm install
cd packages/vite
yarn build
yarn link
pnpm run build
pnpm link # you can use your preferred package manager for this step
```

Then go to your Vite based project and run `yarn link vite`. Now restart the development server (`yarn dev`) to ride on the bleeding edge!
Then go to your Vite based project and run `pnpm link vite` (or the package manager that you used to link `vite` globally). Now restart the development server to ride on the bleeding edge!

## Community

Expand Down
4 changes: 2 additions & 2 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const config: Config.InitialOptions = {
globalTeardown: './scripts/jestGlobalTeardown.js',
testEnvironment: './scripts/jestEnv.js',
setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'],
watchPathIgnorePatterns: ['<rootDir>/temp'],
modulePathIgnorePatterns: ['<rootDir>/temp'],
watchPathIgnorePatterns: ['<rootDir>/packages/temp'],
modulePathIgnorePatterns: ['<rootDir>/packages/temp'],
moduleNameMapper: {
testUtils: '<rootDir>/packages/playground/testUtils.ts'
},
Expand Down
6 changes: 6 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build.environment]
NODE_VERSION = "16"
NPM_FLAGS = "--version" # prevent Netlify npm install
[build]
publish = "docs/.vitepress/dist"
command = "npx pnpm i --store=node_modules/.pnpm-store && npm run ci-docs"
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"node": ">=12.0.0"
},
"scripts": {
"preinstall": "node scripts/preinstall",
"format": "prettier --write .",
"lint": "eslint packages/*/{src,types}/**",
"test": "run-s test-serve test-build",
Expand All @@ -20,10 +21,10 @@
"build-docs": "vitepress build docs",
"serve-docs": "vitepress serve docs",
"build": "run-s build-vite build-plugin-vue build-plugin-react",
"build-vite": "cd packages/vite && yarn build",
"build-plugin-vue": "cd packages/plugin-vue && yarn build",
"build-plugin-react": "cd packages/plugin-react && yarn build",
"ci-build-vite": "cd packages/vite && yarn ci-build",
"build-vite": "cd packages/vite && npm run build",
"build-plugin-vue": "cd packages/plugin-vue && npm run build",
"build-plugin-react": "cd packages/plugin-react && npm run build",
"ci-build-vite": "cd packages/vite && npm run ci-build",
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
},
"devDependencies": {
Expand Down Expand Up @@ -57,7 +58,10 @@
"ts-node": "^10.1.0",
"typescript": "~4.3.5",
"vitepress": "^0.19.1",
"yorkie": "^2.0.0"
"yorkie": "^2.0.0",
"rollup": "^2.57.0",
"esbuild": "^0.13.2",
"vite": "workspace:*"
},
"gitHooks": {
"pre-commit": "lint-staged --concurrent false",
Expand All @@ -73,5 +77,11 @@
"packages/**/*.d.ts": [
"eslint --ext .ts"
]
},
"pnpm": {
"overrides": {
"vite": "workspace:*",
"@vitejs/plugin-vue": "workspace:*"
}
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.13"
"vue": "^3.2.16"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.9.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.13"
"vue": "^3.2.16"
},
"devDependencies": {
"@vitejs/plugin-vue": "^1.9.0",
Expand Down
5 changes: 4 additions & 1 deletion packages/playground/alias/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.13"
"vue": "^3.2.16"
},
"devDependencies": {
"resolve-linked": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/playground/extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.2.13"
"vue": "^3.2.16"
}
}
2 changes: 1 addition & 1 deletion packages/playground/file-delete-restore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"react-dom": "^17.0.1"
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.0"
"@vitejs/plugin-react": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/playground/json/__tests__/json.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isBuild } from '../../testUtils'

const json = require('../test.json')
const deepJson = require('@vue/runtime-core/package.json')
const deepJson = require('vue/package.json')
const stringified = JSON.stringify(json)
const deepStringified = JSON.stringify(deepJson)

Expand Down
2 changes: 1 addition & 1 deletion packages/playground/json/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Raw Import</h2>

<script type="module">
import json, { hello } from './test.json'
import deepJson, { name } from '@vue/runtime-core/package.json'
import deepJson, { name } from 'vue/package.json'

text('.full', JSON.stringify(json))
text('.named', hello)
Expand Down
3 changes: 3 additions & 0 deletions packages/playground/json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"build": "vite build",
"debug": "node --inspect-brk ../../vite/bin/vite",
"serve": "vite preview"
},
"devDependencies": {
"vue": "^3.2.16"
}
}
2 changes: 1 addition & 1 deletion packages/playground/legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"serve": "vite preview"
},
"devDependencies": {
"@vitejs/plugin-legacy": "^1.0.0"
"@vitejs/plugin-legacy": "workspace:*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"nested-include": "file:./nested-include"
"nested-include": "link:./nested-include"
}
}
Loading

0 comments on commit 2e1992b

Please sign in to comment.