Skip to content

Commit

Permalink
Merge branch 'vitejs:main' into fix-vitejs#3295
Browse files Browse the repository at this point in the history
  • Loading branch information
torsteinringnes committed Sep 27, 2021
2 parents 45e7d5e + 8456a6f commit 48db10e
Show file tree
Hide file tree
Showing 107 changed files with 9,930 additions and 11,800 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
19 changes: 16 additions & 3 deletions .eslintrc.js
Expand Up @@ -11,7 +11,7 @@ module.exports = defineConfig({
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
ecmaVersion: 'latest'
ecmaVersion: 2021
},
rules: {
eqeqeq: ['warn', 'always', { null: 'never' }],
Expand All @@ -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
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto eol=lf
60 changes: 25 additions & 35 deletions .github/workflows/ci.yml
Expand Up @@ -10,6 +10,7 @@ on:
branches:
- main
- release/*
- feat/*
pull_request:
workflow_dispatch:

Expand All @@ -32,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 @@ -79,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
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
35 changes: 25 additions & 10 deletions CONTRIBUTING.md
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 `tsc` 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,21 @@ 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 +107,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
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@
- 🔩 Universal Plugin Interface
- 🔑 Fully Typed APIs

Vite (French word for "quick", pronounced `/vit/`, like "veet") is a new breed of frontend build tool that significantly improves the frontend development experience. It consists of two major parts:
Vite (French word for "quick", pronounced [`/vit/`](https://cdn.jsdelivr.net/gh/vitejs/vite@main/docs/public/vite.mp3), like "veet") is a new breed of frontend build tool that significantly improves the frontend development experience. It consists of two major parts:

- A dev server that serves your source files over [native ES modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules), with [rich built-in features](https://vitejs.dev/guide/features.html) and astonishingly fast [Hot Module Replacement (HMR)](https://vitejs.dev/guide/features.html#hot-module-replacement).

Expand Down
21 changes: 20 additions & 1 deletion docs/config/index.md
Expand Up @@ -543,7 +543,7 @@ createServer()
- contains one of the following file
- `pnpm-workspace.yaml`

Accepts a path to specify the custom workspace root. Could be a absolute path or a path relative to [project root](/guide/#index-html-and-project-root). For example
Accepts a path to specify the custom workspace root. Could be a absolute path or a path relative to [project root](/guide/#index-html-and-project-root). For example:

```js
export default defineConfig({
Expand All @@ -556,6 +556,25 @@ createServer()
})
```

When `server.fs.allow` is specified, the auto workspace root detection will be disabled. To extend the original behavior, a utility `searchForWorkspaceRoot` is exposed:

```js
import { defineConfig, searchForWorkspaceRoot } from 'vite'

export default defineConfig({
server: {
fs: {
allow: [
// search up for workspace root
searchForWorkspaceRoot(process.cwd()),
// your custom rules
'/path/to/custom/allow'
]
}
}
})
```

## Build Options

### build.target
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/env-and-mode.md
Expand Up @@ -72,7 +72,7 @@ interface ImportMeta {

## Modes

By default, the dev server (`serve` command) runs in `development` mode, and the `build` command runs in `production` mode.
By default, the dev server (`dev` command) runs in `development` mode and the `build` and `serve` commands run in `production` mode.

This means when running `vite build`, it will load the env variables from `.env.production` if there is one:

Expand Down
14 changes: 7 additions & 7 deletions docs/guide/index.md
Expand Up @@ -69,8 +69,8 @@ Supported template presets include:
- `react-ts`
- `preact`
- `preact-ts`
- `lit-element`
- `lit-element-ts`
- `lit`
- `lit-ts`
- `svelte`
- `svelte-ts`

Expand Down 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
Binary file modified docs/images/vite-plugin-inspect.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions jest.config.ts
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
@@ -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
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:*"
}
}
}

0 comments on commit 48db10e

Please sign in to comment.