Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed May 12, 2022
2 parents 09bc12e + 50f8f3b commit 402cee9
Show file tree
Hide file tree
Showing 1,004 changed files with 7,665 additions and 7,103 deletions.
32 changes: 20 additions & 12 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = defineConfig({
'plugin:node/recommended',
'plugin:@typescript-eslint/recommended'
],
plugins: ['import'],
parser: '@typescript-eslint/parser',
parserOptions: {
sourceType: 'module',
Expand All @@ -29,14 +30,7 @@ module.exports = defineConfig({
'node/no-missing-import': [
'error',
{
allowModules: [
'types',
'estree',
'testUtils',
'less',
'sass',
'stylus'
],
allowModules: ['types', 'estree', 'less', 'sass', 'stylus'],
tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts']
}
],
Expand All @@ -63,7 +57,7 @@ module.exports = defineConfig({
'node/no-extraneous-import': [
'error',
{
allowModules: ['vite', 'less', 'sass']
allowModules: ['vite', 'less', 'sass', 'vitest']
}
],
'node/no-extraneous-require': [
Expand Down Expand Up @@ -93,6 +87,18 @@ module.exports = defineConfig({
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports' }
],

'import/order': 'error',
'sort-imports': [
'error',
{
ignoreCase: false,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
allowSeparatedGroups: false
}
]
},
overrides: [
Expand All @@ -103,16 +109,18 @@ module.exports = defineConfig({
}
},
{
files: ['packages/vite/types/**'],
files: ['packages/vite/types/**', '*.spec.ts'],
rules: {
'node/no-extraneous-import': 'off'
}
},
{
files: ['packages/playground/**'],
files: ['playground/**'],
rules: {
'node/no-extraneous-import': 'off',
'node/no-extraneous-require': 'off'
'node/no-extraneous-require': 'off',
'node/no-missing-import': 'off',
'node/no-missing-require': 'off'
}
},
{
Expand Down
6 changes: 1 addition & 5 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"extends": ["config:base", "schedule:weekly", "group:allNonMajor"],
"labels": ["dependencies"],
"ignorePaths": [
"packages/playground/**",
"packages/create-vite/template-*/**",
"**/__tests__/**"
],
"ignorePaths": ["**/__tests__/**"],
"pin": false,
"rangeStrategy": "bump",
"node": false,
Expand Down
28 changes: 21 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ on:
- feat/*
- fix/*
- perf/*
- v1
- v2
pull_request:
workflow_dispatch:

Expand All @@ -27,7 +29,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node_version: [12, 14, 16, 17, 18]
node_version: [14, 16, 18]
include:
- os: macos-latest
node_version: 16
Expand All @@ -40,15 +42,17 @@ jobs:
# node_version: 18
fail-fast: false

env:
# Install playwright's binray under node_modules so it will be cached together
PLAYWRIGHT_BROWSERS_PATH: "0"

name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 6

- name: Set node version to ${{ matrix.node_version }}
uses: actions/setup-node@v3
Expand All @@ -59,6 +63,9 @@ jobs:
- name: Install deps
run: pnpm install

- name: Install Playwright
run: pnpm playwright install

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

Expand All @@ -68,11 +75,14 @@ jobs:
- name: Build plugin-react
run: pnpm run build-plugin-react

- name: Test unit
run: pnpm run test-unit

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

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

lint:
timeout-minutes: 10
Expand All @@ -85,8 +95,6 @@ jobs:

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 6

- name: Set node version to 16
uses: actions/setup-node@v3
Expand All @@ -96,14 +104,20 @@ jobs:

- name: Install deps
run: pnpm install
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"

- name: Prepare
run: |
pnpm run ci-build-vite
pnpm run build-plugin-vue
pnpm run build-plugin-react
- name: Lint
run: pnpm run lint

- name: Check formatting
run: pnpm prettier --check .

- name: Typecheck
run: pnpm run typecheck
8 changes: 1 addition & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ jobs:

- name: Install deps
run: pnpm install

- name: Creating .npmrc
run: |
cat << EOF > "$HOME/.npmrc"
//registry.npmjs.org/:_authToken=$NPM_TOKEN
EOF
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "1"

- name: Publish package
run: pnpm run ci-publish -- ${{ github.ref_name }}
Expand Down
21 changes: 11 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
.DS_Store
node_modules
!**/glob-import/dir/node_modules
dist
dist-ssr
TODOs.md
*.log
temp
explorations
.DS_Store
.idea
*.local
/packages/vite/LICENSE
*.cpuprofile
*.local
*.log
/.vscode/
/packages/vite/LICENSE
dist
dist-ssr
explorations
node_modules
playground-temp
temp
TODOs.md
1 change: 0 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*
hoist-pattern[]=*jest*
hoist-pattern[]=@emotion/*
hoist-pattern[]=postcss
hoist-pattern[]=pug
Expand Down
7 changes: 4 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ packages/vite/temp/
packages/plugin-react/dist/
packages/plugin-vue/dist/
packages/*/CHANGELOG.md
playground-temp/
LICENSE.md
.prettierignore
pnpm-lock.yaml
pnpm-workspace.yaml
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
packages/playground/html/invalid.html
packages/playground/worker/classic-worker.js
playground/tsconfig-json-load-error/has-error/tsconfig.json
playground/html/invalid.html
playground/worker/classic-worker.js
52 changes: 33 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ To develop and test the core `vite` package:

You can alternatively use [Vite.js Docker Dev](https://github.com/nystudio107/vitejs-docker-dev) for a containerized Docker setup for Vite.js development.

> Vite uses pnpm v7. If you are working on multiple projects with different versions of pnpm, it's recommend to enable [Corepack](https://github.com/nodejs/corepack) by running `corepack enable`.
## Debugging

If you want to use break point and explore code execution you can use the ["Run and debug"](https://code.visualstudio.com/docs/editor/debugging) feature from vscode.
Expand All @@ -26,23 +28,23 @@ If you want to use break point and explore code execution you can use the ["Run

3. Click on the "JavaScript Debug Terminal" button.

4. It will open a terminal, then go to `packages/playground/xxx` and run `pnpm run dev`.
4. It will open a terminal, then go to `playground/xxx` and run `pnpm run dev`.

5. The execution will stop and you'll use the [Debug toolbar](https://code.visualstudio.com/docs/editor/debugging#_debug-actions) to continue, step over, restart the process...

### Debugging errors in Jest tests using Playwright (Chromium)
### Debugging errors in Vitest tests using Playwright (Chromium)

Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Jest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup:
Some errors are masked and hidden away because of the layers of abstraction and sandboxed nature added by Vitest, Playwright, and Chromium. In order to see what's actually going wrong and the contents of the devtools console in those instances, follow this setup:

1. Add a `debugger` statement to the `scripts/jestPerTestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits.
1. Add a `debugger` statement to the `playground/vitestSetup.ts` -> `afterAll` hook. This will pause execution before the tests quit and the Playwright browser instance exits.

1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve -- --runInBand resolve`.
1. Run the tests with the `debug-serve` script command which will enable remote debugging: `pnpm run debug-serve resolve`.

1. Wait for inspector devtools to open in your browser and the debugger to attach.

1. In the sources panel in the right column, click the play button to resume execution and allow the tests to run which will open a Chromium instance.

1. Focusing the Chomium instance, you can open the browser devtools and inspect the console there to find the underlying problems.
1. Focusing the Chromium instance, you can open the browser devtools and inspect the console there to find the underlying problems.

1. To close everything, just stop the test process back in your terminal.

Expand All @@ -67,46 +69,58 @@ And re-run `pnpm install` to link the package.

## Running Tests

Each package under `packages/playground/` contains a `__tests__` directory. The tests are run using [Jest](https://jestjs.io/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `jest.config.js` and `scripts/jest*` files.
### Integration Tests

Each package under `playground/` contains a `__tests__` directory. The tests are run using [Vitest](https://vitest.dev/) + [Playwright](https://playwright.dev/) with custom integrations to make writing tests simple. The detailed setup is inside `vitest.config.e2e.js` and `playground/vitest*` files.

Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390).
Before running the tests, make sure that [Vite has been built](#repo-setup). On Windows, you may want to [activate Developer Mode](https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development) to solve [issues with symlink creation for non-admins](https://github.com/vitejs/vite/issues/7390). Also you may want to [set git `core.symlinks` to `true` to solve issues with symlinks in git](https://github.com/vitejs/vite/issues/5242).

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

- `pnpm test` by default runs every test in both serve and build mode.
- `pnpm test` by default runs every integration test in both serve and build mode, and also unit tests.

- `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`.
- `pnpm run test-serve` runs tests only under serve mode.

- `pnpm run test-build` runs tests only under build 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 -- asset` will run tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode and `vite/src/node/__tests__/**/*` just run in 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 asset` will run tests for both `playground/asset` and `vite/src/node/__tests__/asset` under serve mode and `vite/src/node/__tests__/**/*` just run in serve mode.

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

### Unit Tests

Other than tests under `playground/` for integration tests, packages might contains unit tests under their `__tests__` directory. Unit tests are powered by [Vitest](https://vitest.dev/). The detailed config is inside `vitest.config.ts` files.

- `pnpm run test-unit` runs unit tests under each package.

- You can also use `pnpm run test-unit [match]` to run related tests.

### Test Env and Helpers

Inside playground tests, a global `page` object is automatically available, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as:
Inside playground tests, you can import the `page` object from `~utils`, which is a Playwright [`Page`](https://playwright.dev/docs/api/class-page) instance that has already navigated to the served page of the current playground. So writing a test is as simple as:

```js
import { page } from '~utils'

test('should work', async () => {
expect(await page.textContent('.foo')).toMatch('foo')
})
```

Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.ts`.
Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are also available in the utils. Source code is located at `playground/test-utils.ts`.

Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/9c6501d9c363eaa3c1e7708d531fb2a92b633db6/scripts/jestPerTestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.
Note: The test build environment uses a [different default set of Vite config](https://github.com/vitejs/vite/blob/main/playground/vitestSetup.ts#L102-L122) to skip transpilation during tests to make it faster. This may produce a different result compared to the default production build.

### Extending the Test Suite

To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/packages/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L121):
To add new tests, you should find a related playground to the fix or feature (or create a new one). As an example, static assets loading are tested in the [assets playground](https://github.com/vitejs/vite/tree/main/playground/assets). In this Vite App, there is a test for `?raw` imports, with [a section is defined in the `index.html` for it](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L121):

```html
<h2>?raw import</h2>
<code class="raw"></code>
```

This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/index.html#L151):
This will be modified [with the result of a file import](https://github.com/vitejs/vite/blob/main/playground/assets/index.html#L151):

```js
import rawSvg from './nested/fragment.svg?raw'
Expand All @@ -121,7 +135,7 @@ function text(el, text) {
}
```

In the [spec tests](https://github.com/vitejs/vite/blob/71215533ac60e8ff566dc3467feabfc2c71a01e2/packages/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:
In the [spec tests](https://github.com/vitejs/vite/blob/main/playground/assets/__tests__/assets.spec.ts#L180), the modifications to the DOM listed above are used to test this feature:

```js
test('?raw import', async () => {
Expand All @@ -138,7 +152,7 @@ To work around this, playground packages that uses the `file:` protocol should a
```jsonc
"scripts": {
//...
"postinstall": "ts-node ../../../scripts/patchFileDeps.ts"
"postinstall": "ts-node ../../scripts/patchFileDeps.ts"
}
```

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ In addition, Vite is highly extensible via its [Plugin API](https://vitejs.dev/g

## Packages

> This branch is for the upcoming v3.0, if you are looking for current stable releases, check the [`v2` branch](https://github.com/vitejs/vite/tree/v2) instead.
| Package | Version (click for changelogs) |
| ------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------- |
| [vite](packages/vite) | [![vite version](https://img.shields.io/npm/v/vite.svg?label=%20)](packages/vite/CHANGELOG.md) |
Expand Down
Loading

0 comments on commit 402cee9

Please sign in to comment.