diff --git a/.eslintrc.js b/.eslintrc.js index 90eefd67d8ebe4..578e00417db95b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -29,7 +29,14 @@ 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'] } ], @@ -37,7 +44,7 @@ module.exports = defineConfig({ 'error', { // for try-catching yarn pnp - allowModules: ['pnpapi'], + allowModules: ['pnpapi', 'vite'], tryExtensions: ['.ts', '.js', '.jsx', '.tsx', '.d.ts'] } ], @@ -91,6 +98,12 @@ module.exports = defineConfig({ 'no-console': ['error'] } }, + { + files: ['packages/vite/types/**'], + rules: { + 'node/no-extraneous-import': 'off' + } + }, { files: ['packages/playground/**'], rules: { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b83701f3d8b632..ef4a33afb17f05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/.prettierignore b/.prettierignore index 102b615c0b6415..76d0e7f08c2be1 100644 --- a/.prettierignore +++ b/.prettierignore @@ -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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f4dee0a0c3f6cd..54dab6b183e4fc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 @@ -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. @@ -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. diff --git a/docs/guide/index.md b/docs/guide/index.md index fbf5e87ab4ff57..3a358c9b5d1ac3 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -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 diff --git a/jest.config.ts b/jest.config.ts index c925b81b27c782..e17a90841914e7 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -11,8 +11,8 @@ const config: Config.InitialOptions = { globalTeardown: './scripts/jestGlobalTeardown.js', testEnvironment: './scripts/jestEnv.js', setupFilesAfterEnv: ['./scripts/jestPerTestSetup.ts'], - watchPathIgnorePatterns: ['/temp'], - modulePathIgnorePatterns: ['/temp'], + watchPathIgnorePatterns: ['/packages/temp'], + modulePathIgnorePatterns: ['/packages/temp'], moduleNameMapper: { testUtils: '/packages/playground/testUtils.ts' }, diff --git a/netlify.toml b/netlify.toml new file mode 100644 index 00000000000000..ba9d1c55f567c5 --- /dev/null +++ b/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" \ No newline at end of file diff --git a/package.json b/package.json index 1919038f5ab41c..aa00cb25a90dee 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { @@ -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", @@ -73,5 +77,11 @@ "packages/**/*.d.ts": [ "eslint --ext .ts" ] + }, + "pnpm": { + "overrides": { + "vite": "workspace:*", + "@vitejs/plugin-vue": "workspace:*" + } } } diff --git a/packages/create-vite/template-vue-ts/package.json b/packages/create-vite/template-vue-ts/package.json index d3d8b6bd81467f..906cacefa9464c 100644 --- a/packages/create-vite/template-vue-ts/package.json +++ b/packages/create-vite/template-vue-ts/package.json @@ -7,7 +7,7 @@ "serve": "vite preview" }, "dependencies": { - "vue": "^3.2.13" + "vue": "^3.2.16" }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", diff --git a/packages/create-vite/template-vue/package.json b/packages/create-vite/template-vue/package.json index 14c112be400b3c..54ff45b5c676cf 100644 --- a/packages/create-vite/template-vue/package.json +++ b/packages/create-vite/template-vue/package.json @@ -7,7 +7,7 @@ "serve": "vite preview" }, "dependencies": { - "vue": "^3.2.13" + "vue": "^3.2.16" }, "devDependencies": { "@vitejs/plugin-vue": "^1.9.0", diff --git a/packages/playground/alias/package.json b/packages/playground/alias/package.json index 2313f31f325a10..6e5602edf9644a 100644 --- a/packages/playground/alias/package.json +++ b/packages/playground/alias/package.json @@ -9,6 +9,9 @@ "serve": "vite preview" }, "dependencies": { - "vue": "^3.2.13" + "vue": "^3.2.16" + }, + "devDependencies": { + "resolve-linked": "workspace:*" } } diff --git a/packages/playground/extensions/package.json b/packages/playground/extensions/package.json index d9b9996ce94e9a..5d7e3015e92b5d 100644 --- a/packages/playground/extensions/package.json +++ b/packages/playground/extensions/package.json @@ -9,6 +9,6 @@ "serve": "vite preview" }, "dependencies": { - "vue": "^3.2.13" + "vue": "^3.2.16" } } diff --git a/packages/playground/file-delete-restore/package.json b/packages/playground/file-delete-restore/package.json index 03d0e08bb69b89..8a5a38ab71ceae 100644 --- a/packages/playground/file-delete-restore/package.json +++ b/packages/playground/file-delete-restore/package.json @@ -13,6 +13,6 @@ "react-dom": "^17.0.1" }, "devDependencies": { - "@vitejs/plugin-react": "^1.0.0" + "@vitejs/plugin-react": "workspace:*" } } diff --git a/packages/playground/json/__tests__/json.spec.ts b/packages/playground/json/__tests__/json.spec.ts index 476aabae99607e..2897ee22332e44 100644 --- a/packages/playground/json/__tests__/json.spec.ts +++ b/packages/playground/json/__tests__/json.spec.ts @@ -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) diff --git a/packages/playground/json/index.html b/packages/playground/json/index.html index d10145511b5996..4f6e2b6ae57466 100644 --- a/packages/playground/json/index.html +++ b/packages/playground/json/index.html @@ -21,7 +21,7 @@

Raw Import