Skip to content

Commit c9698c6

Browse files
authored
Merge branch 'vuejs:main' into main
2 parents aad8bcb + 9a09e47 commit c9698c6

File tree

329 files changed

+10856
-8302
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

329 files changed

+10856
-8302
lines changed

.eslintrc.js renamed to .eslintrc.cjs

+14-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = {
66
parserOptions: {
77
sourceType: 'module'
88
},
9-
plugins: ["jest"],
9+
plugins: ['jest'],
1010
rules: {
1111
'no-debugger': 'error',
1212
'no-unused-vars': [
@@ -17,20 +17,22 @@ module.exports = {
1717
],
1818
// most of the codebase are expected to be env agnostic
1919
'no-restricted-globals': ['error', ...DOMGlobals, ...NodeGlobals],
20-
// since we target ES2015 for baseline support, we need to forbid object
21-
// rest spread usage in destructure as it compiles into a verbose helper.
22-
// TS now compiles assignment spread into Object.assign() calls so that
23-
// is allowed.
20+
2421
'no-restricted-syntax': [
2522
'error',
23+
// since we target ES2015 for baseline support, we need to forbid object
24+
// rest spread usage in destructure as it compiles into a verbose helper.
2625
'ObjectPattern > RestElement',
26+
// tsc compiles assignment spread into Object.assign() calls, but esbuild
27+
// still generates verbose helpers, so spread assignment is also prohiboted
28+
'ObjectExpression > SpreadElement',
2729
'AwaitExpression'
2830
]
2931
},
3032
overrides: [
3133
// tests, no restrictions (runs in Node / jest with jsdom)
3234
{
33-
files: ['**/__tests__/**', 'test-dts/**'],
35+
files: ['**/__tests__/**', 'packages/dts-test/**'],
3436
rules: {
3537
'no-restricted-globals': 'off',
3638
'no-restricted-syntax': 'off',
@@ -72,7 +74,12 @@ module.exports = {
7274
},
7375
// Node scripts
7476
{
75-
files: ['scripts/**', './*.js', 'packages/**/index.js', 'packages/size-check/**'],
77+
files: [
78+
'scripts/**',
79+
'*.{js,ts}',
80+
'packages/**/index.js',
81+
'packages/size-check/**'
82+
],
7683
rules: {
7784
'no-restricted-globals': 'off',
7885
'no-restricted-syntax': 'off'

.github/contributing.md

+57-24
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Hi! I'm really excited that you are interested in contributing to Vue.js. Before
3030

3131
- 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. `update entities encoding/decoding (fix #3899)`.
3232
- Provide a detailed description of the bug in the PR. Live demo preferred.
33-
- Add appropriate test coverage if applicable. You can check the coverage of your code addition by running `npm test -- --coverage`.
33+
- Add appropriate test coverage if applicable. You can check the coverage of your code addition by running `nr test-coverage`.
3434

3535
- It's OK to have multiple small commits as you work on the PR - GitHub can automatically squash them before merging.
3636

@@ -70,16 +70,36 @@ $ pnpm i # install the dependencies of the project
7070
A high level overview of tools used:
7171

7272
- [TypeScript](https://www.typescriptlang.org/) as the development language
73-
- [Rollup](https://rollupjs.org) for bundling
74-
- [Jest](https://jestjs.io/) for unit testing
73+
- [Vite](https://vitejs.dev/) and [ESBuild](https://esbuild.github.io/) for development bundling
74+
- [Rollup](https://rollupjs.org) for production bundling
75+
- [Vitest](https://vitest.dev/) for unit testing
7576
- [Prettier](https://prettier.io/) for code formatting
77+
- [ESLint](https://eslint.org/) for static error prevention (outside of types)
78+
79+
## Git Hooks
80+
81+
The project uses [simple-git-hooks](https://github.com/toplenboren/simple-git-hooks) to enforce the following on each commit:
82+
83+
- Type check the entire project
84+
- Automatically format changed files using Prettier
85+
- Verify commit message format (logic in `scripts/verifyCommit.js`)
7686

7787
## Scripts
7888

7989
**The examples below will be using the `nr` command from the [ni](https://github.com/antfu/ni) package.** You can also use plain `npm run`, but you will need to pass all additional arguments after the command after an extra `--`. For example, `nr build runtime --all` is equivalent to `npm run build -- runtime --all`.
8090

8191
The `run-s` and `run-p` commands found in some scripts are from [npm-run-all](https://github.com/mysticatea/npm-run-all) for orchestrating multiple scripts. `run-s` means "run in sequence" while `run-p` means "run in parallel".
8292

93+
- [`nr build`](#nr-build)
94+
- [`nr build-dts`](#nr-build-dts)
95+
- [`nr check`](#nr-check)
96+
- [`nr dev`](#nr-dev)
97+
- [`nr dev-sfc`](#nr-dev-sfc)
98+
- [`nr dev-esm`](#nr-dev-esm)
99+
- [`nr dev-compiler`](#nr-dev-compiler)
100+
- [`nr test`](#nr-test)
101+
- [`nr test-dts`](#nr-test-dts)
102+
83103
### `nr build`
84104

85105
The `build` script builds all public packages (packages without `private: true` in their `package.json`).
@@ -94,6 +114,8 @@ nr build runtime-core
94114
nr build runtime --all
95115
```
96116

117+
Note that `nr build` uses `rollup-plugin-esbuild` for transpiling typescript and **does not perform type checking**. To run type check on the entire codebase, run `nr check`. Type checks are also automatically run on each commit.
118+
97119
#### Build Formats
98120

99121
By default, each package will be built in multiple distribution formats as specified in the `buildOptions.formats` field in its `package.json`. These can be overwritten via the `-f` flag. The following formats are supported:
@@ -127,13 +149,11 @@ nr build runtime-core -f esm-browser,cjs
127149

128150
Use the `--sourcemap` or `-s` flag to build with source maps. Note this will make the build much slower.
129151

130-
#### Build with Type Declarations
152+
### `nr build-dts`
131153

132-
The `--types` or `-t` flag will generate type declarations during the build and in addition:
154+
This command builds the type declarations for all packages. It first generates the raw `.d.ts` files in the `temp` directory, then uses [rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts) to roll the types into a single `.d.ts` file for each package.
133155

134-
- Roll the declarations into a single `.d.ts` file for each package;
135-
- Generate an API report in `<projectRoot>/temp/<packageName>.api.md`. This report contains potential warnings emitted by [api-extractor](https://api-extractor.com/).
136-
- Generate an API model json in `<projectRoot>/temp/<packageName>.api.json`. This file can be used to generate a Markdown version of the exported APIs.
156+
### `nr check`
137157

138158
### `nr dev`
139159

@@ -142,7 +162,7 @@ The `dev` script bundles a target package (default: `vue`) in a specified format
142162
```bash
143163
$ nr dev
144164

145-
> watching: packages/vue/dist/vue.global.js
165+
> built: packages/vue/dist/vue.global.js
146166
```
147167

148168
- **Important:** output of the `dev` script is for development and debugging only. While it has the same runtime behavior, the generated code should never be published to npm.
@@ -169,23 +189,30 @@ The `dev-compiler` script builds, watches and serves the [Template Explorer](htt
169189

170190
### `nr test`
171191

172-
The `test` script simply calls the `jest` binary, so all [Jest CLI Options](https://jestjs.io/docs/en/cli) can be used. Some examples:
192+
The `test` script simply calls the `vitest` binary, so all [Vitest CLI Options](https://vitest.dev/guide/cli.html#options) can be used. Some examples:
173193

174194
```bash
175-
# run all tests
195+
# run all tests in watch mode
176196
$ nr test
177197

198+
# run once and exit (equivalent to `vitest run`)
199+
$ nr test run
200+
178201
# run all tests under the runtime-core package
179202
$ nr test runtime-core
180203

181-
# run tests in a specific file
182-
$ nr test fileName
204+
# run tests in files matching the pattern
205+
$ nr test <fileNamePattern>
183206

184-
# run a specific test in a specific file
185-
$ nr test fileName -t 'test name'
207+
# run a specific test in specific files
208+
$ nr test <fileNamePattern> -t 'test name'
186209
```
187210

188-
The default `test` script includes the `--runInBand` jest flag to improve test stability, especially for the CSS transition related tests. When you are testing specific test specs, you can also run `npx jest` with flags directly to speed up tests (jest runs them in parallel by default).
211+
Tests that test against source code are grouped under `nr test-unit`, while tests that test against built files that run in real browsers are grouped under `nr test-e2e`.
212+
213+
### `nr test-dts`
214+
215+
Runs `nr build-dts` first, then verify the type tests in `packages/dts-test` are working correctly against the actual built type declarations.
189216

190217
## Project Structure
191218

@@ -209,14 +236,20 @@ This repository employs a [monorepo](https://en.wikipedia.org/wiki/Monorepo) set
209236

210237
- `compiler-ssr`: Compiler that produces render functions optimized for server-side rendering.
211238

212-
- `template-explorer`: A development tool for debugging compiler output. You can run `nr dev template-explorer` and open its `index.html` to get a repl of template compilation based on current source code.
213-
214-
A [live version](https://vue-next-template-explorer.netlify.com) of the template explorer is also available, which can be used for providing reproductions for compiler bugs. You can also pick the deployment for a specific commit from the [deploy logs](https://app.netlify.com/sites/vue-next-template-explorer/deploys).
215-
216239
- `shared`: Internal utilities shared across multiple packages (especially environment-agnostic utils used by both runtime and compiler packages).
217240

218241
- `vue`: The public facing "full build" which includes both the runtime AND the compiler.
219242

243+
- Private utility packages:
244+
245+
- `dts-test`: Contains type-only tests against generated dts files.
246+
247+
- `sfc-playground`: The playground continuously deployed at https://sfc.vuejs.org. To run the playground locally, use [`nr dev-sfc`](#nr-dev-sfc).
248+
249+
- `template-explorer`: A development tool for debugging compiler output, continuously deployed at https://template-explorer.vuejs.org/. To run it locally, run [`nr dev-compiler`](#nr-dev-compiler).
250+
251+
- `size-check`: Used for checking built bundle sizes on CI.
252+
220253
### Importing Packages
221254

222255
The packages can import each other directly using their package names. Note that when importing a package, the name listed in its `package.json` should be used. Most of the time the `@vue/` prefix is needed:
@@ -228,7 +261,7 @@ import { h } from '@vue/runtime-core'
228261
This is made possible via several configurations:
229262

230263
- For TypeScript, `compilerOptions.paths` in `tsconfig.json`
231-
- For Jest, `moduleNameMapper` in `jest.config.js`
264+
- Vitest and Rollup share the sae set of aliases from `scripts/aliases.js`
232265
- For plain Node.js, they are linked using [PNPM Workspaces](https://pnpm.io/workspaces).
233266

234267
### Package Dependencies
@@ -268,19 +301,19 @@ There are some rules to follow when importing across package boundaries:
268301

269302
## Contributing Tests
270303

271-
Unit tests are collocated with the code being tested in each package, inside directories named `__tests__`. Consult the [Jest docs](https://jestjs.io/docs/en/using-matchers) and existing test cases for how to write new test specs. Here are some additional guidelines:
304+
Unit tests are collocated with the code being tested in each package, inside directories named `__tests__`. Consult the [Vitest docs](https://vitest.dev/api/) and existing test cases for how to write new test specs. Here are some additional guidelines:
272305

273306
- Use the minimal API needed for a test case. For example, if a test can be written without involving the reactivity system or a component, it should be written so. This limits the test's exposure to changes in unrelated parts and makes it more stable.
274307

275308
- If testing platform agnostic behavior or asserting low-level virtual DOM operations, use `@vue/runtime-test`.
276309

277310
- Only use platform-specific runtimes if the test is asserting platform-specific behavior.
278311

279-
Test coverage is continuously deployed at https://vue-next-coverage.netlify.app/. PRs that improve test coverage are welcome, but in general the test coverage should be used as a guidance for finding API use cases that are not covered by tests. We don't recommend adding tests that only improve coverage but not actually test a meaning use case.
312+
Test coverage is continuously deployed at https://coverage.vuejs.org. PRs that improve test coverage are welcome, but in general the test coverage should be used as a guidance for finding API use cases that are not covered by tests. We don't recommend adding tests that only improve coverage but not actually test a meaning use case.
280313

281314
### Testing Type Definition Correctness
282315

283-
Type tests are located in the `test-dts` directory. To run the dts tests, run `nr test-dts`. Note that the type test requires all relevant `*.d.ts` files to be built first (and the script does it for you). Once the `d.ts` files are built and up-to-date, the tests can be re-run by simply running `nr test-dts`.
316+
Type tests are located in the `packages/dts-test` directory. To run the dts tests, run `nr test-dts`. Note that the type test requires all relevant `*.d.ts` files to be built first (and the script does it for you). Once the `d.ts` files are built and up-to-date, the tests can be re-run by running `nr test-dts-only`.
284317

285318
## Financial Contribution
286319

.github/workflows/canary.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: canary release
2+
on:
3+
# Runs every Monday at 1 AM UTC (9:00 AM in Singapore)
4+
schedule:
5+
- cron: 0 1 * * MON
6+
workflow_dispatch:
7+
8+
jobs:
9+
canary:
10+
# prevents this action from running on forks
11+
if: github.repository == 'vuejs/core'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install pnpm
17+
uses: pnpm/action-setup@v2
18+
19+
- name: Set node version to 18
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
registry-url: 'https://registry.npmjs.org'
24+
cache: 'pnpm'
25+
26+
- run: pnpm install
27+
28+
- run: pnpm release --canary
29+
env:
30+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/ci.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ permissions:
1313
jobs:
1414
unit-test:
1515
runs-on: ubuntu-latest
16+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
1617
steps:
1718
- uses: actions/checkout@v3
1819

@@ -32,6 +33,7 @@ jobs:
3233

3334
e2e-test:
3435
runs-on: ubuntu-latest
36+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
3537
steps:
3638
- uses: actions/checkout@v3
3739

@@ -57,6 +59,7 @@ jobs:
5759

5860
lint-and-test-dts:
5961
runs-on: ubuntu-latest
62+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
6063
steps:
6164
- uses: actions/checkout@v3
6265

@@ -82,6 +85,7 @@ jobs:
8285

8386
size:
8487
runs-on: ubuntu-latest
88+
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
8589
env:
8690
CI_JOB_NUMBER: 1
8791
steps:
@@ -98,10 +102,3 @@ jobs:
98102

99103
- run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install
100104
- run: pnpm run size
101-
102-
# - name: Check build size
103-
# uses: posva/[email protected]
104-
# with:
105-
# github_token: ${{ secrets.GITHUB_TOKEN }}
106-
# build_script: size
107-
# files: packages/vue/dist/vue.global.prod.js packages/runtime-dom/dist/runtime-dom.global.prod.js packages/size-check/dist/index.js
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: ecosystem-ci trigger
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
jobs:
8+
trigger:
9+
runs-on: ubuntu-latest
10+
if: github.repository == 'vuejs/core' && github.event.issue.pull_request && startsWith(github.event.comment.body, '/ecosystem-ci run')
11+
steps:
12+
- uses: actions/github-script@v6
13+
with:
14+
script: |
15+
const user = context.payload.sender.login
16+
console.log(`Validate user: ${user}`)
17+
18+
let isVuejsMember = false
19+
try {
20+
const { status } = await github.rest.orgs.checkMembershipForUser({
21+
org: 'vuejs',
22+
username: user
23+
});
24+
25+
isVuejsMember = (status === 204)
26+
} catch (e) {}
27+
28+
if (isVuejsMember) {
29+
console.log('Allowed')
30+
await github.rest.reactions.createForIssueComment({
31+
owner: context.repo.owner,
32+
repo: context.repo.repo,
33+
comment_id: context.payload.comment.id,
34+
content: '+1',
35+
})
36+
} else {
37+
console.log('Not allowed')
38+
await github.rest.reactions.createForIssueComment({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
comment_id: context.payload.comment.id,
42+
content: '-1',
43+
})
44+
throw new Error('not allowed')
45+
}
46+
- uses: actions/github-script@v6
47+
id: get-pr-data
48+
with:
49+
script: |
50+
console.log(`Get PR info: ${context.repo.owner}/${context.repo.repo}#${context.issue.number}`)
51+
const { data: pr } = await github.rest.pulls.get({
52+
owner: context.repo.owner,
53+
repo: context.repo.repo,
54+
pull_number: context.issue.number
55+
})
56+
return {
57+
num: context.issue.number,
58+
branchName: pr.head.ref,
59+
repo: pr.head.repo.full_name
60+
}
61+
- uses: actions/github-script@v6
62+
id: trigger
63+
env:
64+
COMMENT: ${{ github.event.comment.body }}
65+
with:
66+
github-token: ${{ secrets.ECOSYSTEM_CI_ACCESS_TOKEN }}
67+
result-encoding: string
68+
script: |
69+
const comment = process.env.COMMENT.trim()
70+
const prData = ${{ steps.get-pr-data.outputs.result }}
71+
72+
const suite = comment.replace(/^\/ecosystem-ci run/, '').trim()
73+
74+
await github.rest.actions.createWorkflowDispatch({
75+
owner: context.repo.owner,
76+
repo: 'ecosystem-ci',
77+
workflow_id: 'ecosystem-ci-from-pr.yml',
78+
ref: 'main',
79+
inputs: {
80+
prNumber: '' + prData.num,
81+
branchName: prData.branchName,
82+
repo: prData.repo,
83+
suite: suite === '' ? '-' : suite
84+
}
85+
})

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ TODOs.md
88
*.log
99
.idea
1010
.eslintcache
11+
dts-build/packages
12+
*.tsbuildinfo

0 commit comments

Comments
 (0)