Skip to content

Commit

Permalink
chore: rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
poyoho committed May 6, 2022
2 parents 0d556c6 + 95eb45b commit fe061ee
Show file tree
Hide file tree
Showing 181 changed files with 2,147 additions and 1,055 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,17 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node_version: [12, 14, 16, 17]
node_version: [14, 16, 18]
include:
- os: macos-latest
node_version: 16
- os: macos-latest
node_version: 18
- os: windows-latest
node_version: 16
# Maybe bug with jest on windows and node-v18
# - os: windows-latest
# node_version: 18
fail-fast: false

name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}"
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Semantic Pull Request

on:
pull_request_target:
types:
- opened
- edited
- synchronize

jobs:
main:
runs-on: ubuntu-latest
name: Semantic Pull Request
steps:
- name: Validate PR title
uses: amannn/action-semantic-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Some errors are masked and hidden away because of the layers of abstraction and

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 @@ -69,7 +69,7 @@ And re-run `pnpm install` to link the package.

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.

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.

Expand All @@ -95,6 +95,8 @@ test('should work', async () => {

Some common test helpers, e.g. `testDir`, `isBuild` or `editFile` are available in `packages/playground/testUtils.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.

### 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):
Expand Down
19 changes: 11 additions & 8 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ If the config needs to call async function, it can export a async function inste
export default defineConfig(async ({ command, mode }) => {
const data = await asyncFunction()
return {
// build specific config
// vite config
}
})
```
Expand All @@ -109,10 +109,14 @@ Note that Vite doesn't load `.env` files by default as the files to load can onl
import { defineConfig, loadEnv } from 'vite'

export default defineConfig(({ command, mode }) => {
// Load env file based on `mode` in the current working directory
const env = loadEnv(mode, process.cwd())
// Load env file based on `mode` in the current working directory.
// Set the third parameter to '' to load all env regardless of the `VITE_` prefix.
const env = loadEnv(mode, process.cwd(), '')
return {
// build specific config
// vite config
define: {
__APP_ENV__: env.APP_ENV
}
}
})
```
Expand Down Expand Up @@ -160,7 +164,7 @@ export default defineConfig(({ command, mode }) => {

- To be consistent with [esbuild behavior](https://esbuild.github.io/api/#define), expressions must either be a JSON object (null, boolean, number, string, array, or object) or a single identifier.

- Replacements are performed only when the match is surrounded by word boundaries (`\b`).
- Replacements are performed only when the match isn't surrounded by other letters, numbers, `_` or `$`.

::: warning
Because it's implemented as straightforward text replacements without any syntax analysis, we recommend using `define` for CONSTANTS only.
Expand Down Expand Up @@ -237,7 +241,7 @@ export default defineConfig(({ command, mode }) => {
{
"exports": {
".": {
"import": "./index.esm.js",
"import": "./index.esm.mjs",
"require": "./index.cjs.js"
}
}
Expand Down Expand Up @@ -706,7 +710,7 @@ Defines the origin of the generated asset URLs during development.
```js
export default defineConfig({
server: {
origin: 'http://127.0.0.1:8080/'
origin: 'http://127.0.0.1:8080'
}
})
```
Expand Down Expand Up @@ -1018,7 +1022,6 @@ export default defineConfig({

- `external` is also omitted, use Vite's `optimizeDeps.exclude` option
- `plugins` are merged with Vite's dep plugin
- `keepNames` takes precedence over the deprecated `optimizeDeps.keepNames`

## SSR Options

Expand Down
30 changes: 18 additions & 12 deletions docs/guide/api-hmr.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,27 @@ Vite exposes its manual HMR API via the special `import.meta.hot` object:

```ts
interface ImportMeta {
readonly hot?: {
readonly data: any
readonly hot?: ViteHotContext
}

interface ViteHotContext {
readonly data: any

accept(): void
accept(cb: (mod: any) => void): void
accept(dep: string, cb: (mod: any) => void): void
accept(deps: string[], cb: (mods: any[]) => void): void
accept(): void
accept(cb: (mod: any) => void): void
accept(dep: string, cb: (mod: any) => void): void
accept(deps: readonly string[], cb: (mods: any[]) => void): void

prune(cb: () => void): void
dispose(cb: (data: any) => void): void
decline(): void
invalidate(): void
dispose(cb: (data: any) => void): void
decline(): void
invalidate(): void

on(event: string, cb: (...args: any[]) => void): void
}
// `InferCustomEventPayload` provides types for built-in Vite events
on<T extends string>(
event: T,
cb: (payload: InferCustomEventPayload<T>) => void
): void
send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
}
```

Expand Down
9 changes: 5 additions & 4 deletions docs/guide/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ module.exports = defineConfig({
lib: {
entry: path.resolve(__dirname, 'lib/main.js'),
name: 'MyLib',
fileName: (format) => `my-lib.${format}.js`
// the proper extensions will be added
fileName: 'my-lib'
},
rollupOptions: {
// make sure to externalize deps that shouldn't be bundled
Expand Down Expand Up @@ -159,7 +160,7 @@ Running `vite build` with this config uses a Rollup preset that is oriented towa
```
$ vite build
building for production...
[write] my-lib.es.js 0.08kb, brotli: 0.07kb
[write] my-lib.es.mjs 0.08kb, brotli: 0.07kb
[write] my-lib.umd.js 0.30kb, brotli: 0.16kb
```

Expand All @@ -170,10 +171,10 @@ Recommended `package.json` for your lib:
"name": "my-lib",
"files": ["dist"],
"main": "./dist/my-lib.umd.js",
"module": "./dist/my-lib.es.js",
"module": "./dist/my-lib.es.mjs",
"exports": {
".": {
"import": "./dist/my-lib.es.js",
"import": "./dist/my-lib.es.mjs",
"require": "./dist/my-lib.umd.js"
}
}
Expand Down
8 changes: 8 additions & 0 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ interface ImportMeta {
}
```

If your code relies on types from browser environments such as [DOM](https://github.com/microsoft/TypeScript/blob/main/lib/lib.dom.d.ts) and [WebWorker](https://github.com/microsoft/TypeScript/blob/main/lib/lib.webworker.d.ts), you can update the [lib](https://www.typescriptlang.org/tsconfig#lib) field in `tsconfig.json`.

```json
{
"lib": ["WebWorker"]
}
```

## Modes

By default, the dev server (`dev` command) runs in `development` mode and the `build` command run in `production` mode.
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ document.getElementById('foo').className = applyColor

### CSS Pre-processors

Because Vite targets modern browsers only, it is recommended to use native CSS variables with PostCSS plugins that implement CSSWG drafts (e.g. [postcss-nesting](https://github.com/jonathantneal/postcss-nesting)) and author plain, future-standards-compliant CSS.
Because Vite targets modern browsers only, it is recommended to use native CSS variables with PostCSS plugins that implement CSSWG drafts (e.g. [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting)) and author plain, future-standards-compliant CSS.

That said, Vite does provide built-in support for `.scss`, `.sass`, `.less`, `.styl` and `.stylus` files. There is no need to install Vite-specific plugins for them, but the corresponding pre-processor itself must be installed:

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The supported template presets are:
## Scaffolding Your First Vite Project

::: tip Compatibility Note
Vite requires [Node.js](https://nodejs.org/en/) version >=12.2.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
Vite requires [Node.js](https://nodejs.org/en/) version >=14.6.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
:::

With NPM:
Expand Down Expand Up @@ -113,7 +113,7 @@ Running `vite` starts the dev server using the current working directory as root

## Command Line Interface

In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here is the default npm scripts in a scaffolded Vite project:
In a project where Vite is installed, you can use the `vite` binary in your npm scripts, or run it directly with `npx vite`. Here are the default npm scripts in a scaffolded Vite project:

<!-- prettier-ignore -->
```json5
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
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"
command = "npx pnpm@6 i --store=node_modules/.pnpm-store --frozen-lockfile && npx pnpm@6 run ci-docs"
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vite-monorepo",
"private": true,
"engines": {
"node": ">=12.2.0"
"node": ">=14.6.0"
},
"homepage": "https://vitejs.dev/",
"keywords": [
Expand Down Expand Up @@ -34,24 +34,24 @@
"ci-docs": "run-s build-vite build-plugin-vue build-docs"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.22.2",
"@microsoft/api-extractor": "^7.23.0",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^27.4.1",
"@types/node": "^16.11.27",
"@types/node": "^17.0.25",
"@types/prompts": "^2.0.14",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"@typescript-eslint/eslint-plugin": "^5.21.0",
"@typescript-eslint/parser": "^5.21.0",
"conventional-changelog-cli": "^2.2.2",
"cross-env": "^7.0.3",
"esbuild": "^0.14.27",
"eslint": "^8.13.0",
"eslint-define-config": "^1.3.0",
"eslint": "^8.14.0",
"eslint-define-config": "^1.4.0",
"eslint-plugin-node": "^11.1.0",
"execa": "^5.1.1",
"fs-extra": "^10.1.0",
"jest": "^27.5.1",
"lint-staged": "^12.3.8",
"lint-staged": "^12.4.1",
"minimist": "^1.2.6",
"node-fetch": "^2.6.6",
"npm-run-all": "^4.1.5",
Expand Down Expand Up @@ -85,7 +85,7 @@
"eslint --ext .ts"
]
},
"packageManager": "pnpm@6.32.9",
"packageManager": "pnpm@6.32.11",
"pnpm": {
"overrides": {
"vite": "workspace:*",
Expand Down
7 changes: 7 additions & 0 deletions packages/create-vite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## <small>2.9.3 (2022-05-02)</small>

* chore(create-vite): update reference to volar vscode extension (#7994) ([2b6d8fe](https://github.com/vitejs/vite/commit/2b6d8fe)), closes [#7994](https://github.com/vitejs/vite/issues/7994)
* feat(create-vite): scaffold directory with only .git (#7971) ([a5bdb9f](https://github.com/vitejs/vite/commit/a5bdb9f)), closes [#7971](https://github.com/vitejs/vite/issues/7971)



## <small>2.9.2 (2022-04-19)</small>

* chore: remove useless code in preact template (#7789) ([e5729be](https://github.com/vitejs/vite/commit/e5729be)), closes [#7789](https://github.com/vitejs/vite/issues/7789)
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Scaffolding Your First Vite Project

> **Compatibility Note:**
> Vite requires [Node.js](https://nodejs.org/en/) version >=12.2.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
> Vite requires [Node.js](https://nodejs.org/en/) version >=14.6.0. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.
With NPM:

Expand Down
3 changes: 2 additions & 1 deletion packages/create-vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ function copyDir(srcDir, destDir) {
}

function isEmpty(path) {
return fs.readdirSync(path).length === 0
const files = fs.readdirSync(path)
return files.length === 0 || (files.length === 1 && files[0] === '.git')
}

function emptyDir(dir) {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-vite",
"version": "2.9.2",
"version": "2.9.3",
"license": "MIT",
"author": "Evan You",
"bin": {
Expand All @@ -13,7 +13,7 @@
],
"main": "index.js",
"engines": {
"node": ">=12.0.0"
"node": ">=14.6.0"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-vite/template-lit-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "vite-lit-ts-starter",
"private": true,
"version": "0.0.0",
"main": "dist/my-element.es.js",
"main": "dist/my-element.es.mjs",
"exports": {
".": "./dist/my-element.es.js"
".": "./dist/my-element.es.mjs"
},
"types": "types/my-element.d.ts",
"files": [
Expand All @@ -19,7 +19,7 @@
"lit": "^2.0.2"
},
"devDependencies": {
"vite": "^2.9.5",
"vite": "^2.9.7",
"typescript": "^4.5.4"
}
}
6 changes: 3 additions & 3 deletions packages/create-vite/template-lit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "vite-lit-starter",
"private": true,
"version": "0.0.0",
"main": "dist/my-element.es.js",
"main": "dist/my-element.es.mjs",
"exports": {
".": "./dist/my-element.es.js"
".": "./dist/my-element.es.mjs"
},
"files": [
"dist"
Expand All @@ -17,6 +17,6 @@
"lit": "^2.0.2"
},
"devDependencies": {
"vite": "^2.9.5"
"vite": "^2.9.7"
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"devDependencies": {
"@preact/preset-vite": "^2.1.5",
"typescript": "^4.5.4",
"vite": "^2.9.5"
"vite": "^2.9.7"
}
}
Loading

0 comments on commit fe061ee

Please sign in to comment.