@modern-js/main-doc 2.51.0 → 2.53.0
Sign up to get free protection for your applications and to get access to all the features.
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +30 -4
- package/docs/en/guides/advanced-features/web-server.mdx +4 -2
- package/docs/en/guides/basic-features/data/data-fetch.mdx +28 -0
- package/docs/en/guides/basic-features/deploy.mdx +143 -33
- package/docs/en/guides/basic-features/routes.mdx +2 -2
- package/docs/en/guides/get-started/tech-stack.mdx +0 -6
- package/docs/en/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
- package/docs/en/guides/topic-detail/generator/create/option.md +0 -5
- package/docs/en/guides/topic-detail/generator/create/use.mdx +1 -10
- package/docs/en/guides/topic-detail/generator/new/config.md +0 -29
- package/docs/en/guides/topic-detail/generator/new/use.md +0 -20
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +30 -4
- package/docs/zh/guides/advanced-features/web-server.mdx +1 -1
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +27 -2
- package/docs/zh/guides/basic-features/deploy.mdx +140 -36
- package/docs/zh/guides/basic-features/routes.mdx +2 -2
- package/docs/zh/guides/get-started/tech-stack.mdx +0 -6
- package/docs/zh/guides/topic-detail/framework-plugin/plugin-api.mdx +1 -1
- package/docs/zh/guides/topic-detail/generator/create/option.md +0 -5
- package/docs/zh/guides/topic-detail/generator/create/use.mdx +1 -10
- package/docs/zh/guides/topic-detail/generator/new/config.md +0 -31
- package/docs/zh/guides/topic-detail/generator/new/use.md +0 -20
- package/package.json +5 -5
- package/docs/en/apis/app/runtime/testing/_category_.json +0 -4
- package/docs/en/apis/app/runtime/testing/act.mdx +0 -35
- package/docs/en/apis/app/runtime/testing/cleanup.mdx +0 -40
- package/docs/en/apis/app/runtime/testing/render.mdx +0 -71
- package/docs/en/apis/app/runtime/testing/renderApp.mdx +0 -34
- package/docs/en/configure/app/testing/_category_.json +0 -4
- package/docs/en/configure/app/testing/transformer.mdx +0 -17
- package/docs/en/configure/app/tools/jest.mdx +0 -40
- package/docs/en/guides/advanced-features/testing.mdx +0 -47
- package/docs/en/guides/topic-detail/changesets/_category_.json +0 -4
- package/docs/en/guides/topic-detail/changesets/add.mdx +0 -125
- package/docs/en/guides/topic-detail/changesets/changelog.mdx +0 -238
- package/docs/en/guides/topic-detail/changesets/commit.mdx +0 -269
- package/docs/en/guides/topic-detail/changesets/config.mdx +0 -147
- package/docs/en/guides/topic-detail/changesets/github.mdx +0 -175
- package/docs/en/guides/topic-detail/changesets/introduce.mdx +0 -56
- package/docs/en/guides/topic-detail/changesets/release-note.mdx +0 -274
- package/docs/en/guides/topic-detail/changesets/release-pre.mdx +0 -49
- package/docs/en/guides/topic-detail/changesets/release.mdx +0 -229
- package/docs/en/guides/topic-detail/model/test-model.mdx +0 -45
- package/docs/zh/apis/app/runtime/testing/_category_.json +0 -4
- package/docs/zh/apis/app/runtime/testing/act.mdx +0 -35
- package/docs/zh/apis/app/runtime/testing/cleanup.mdx +0 -40
- package/docs/zh/apis/app/runtime/testing/render.mdx +0 -71
- package/docs/zh/apis/app/runtime/testing/renderApp.mdx +0 -32
- package/docs/zh/configure/app/testing/_category_.json +0 -4
- package/docs/zh/configure/app/testing/transformer.mdx +0 -19
- package/docs/zh/configure/app/tools/jest.mdx +0 -40
- package/docs/zh/guides/advanced-features/testing.mdx +0 -47
- package/docs/zh/guides/topic-detail/changesets/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/changesets/add.mdx +0 -126
- package/docs/zh/guides/topic-detail/changesets/changelog.mdx +0 -238
- package/docs/zh/guides/topic-detail/changesets/commit.mdx +0 -269
- package/docs/zh/guides/topic-detail/changesets/config.mdx +0 -147
- package/docs/zh/guides/topic-detail/changesets/github.mdx +0 -175
- package/docs/zh/guides/topic-detail/changesets/introduce.mdx +0 -56
- package/docs/zh/guides/topic-detail/changesets/release-note.mdx +0 -274
- package/docs/zh/guides/topic-detail/changesets/release-pre.mdx +0 -50
- package/docs/zh/guides/topic-detail/changesets/release.mdx +0 -231
- package/docs/zh/guides/topic-detail/model/test-model.mdx +0 -45
- package/docs/zh/guides/topic-detail/monorepo/_category_.json +0 -4
- package/docs/zh/guides/topic-detail/monorepo/create-sub-project.mdx +0 -53
- package/docs/zh/guides/topic-detail/monorepo/intro.mdx +0 -14
- package/docs/zh/guides/topic-detail/monorepo/publish.mdx +0 -69
- package/docs/zh/guides/topic-detail/monorepo/sub-project-interface.mdx +0 -143
@@ -1,274 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 8
|
3
|
-
---
|
4
|
-
|
5
|
-
# Customizing Release Note Format
|
6
|
-
|
7
|
-
Modern.js provides the `modern gen-release-note` command, which supports automatically generating Release Note through the current existing changeset and git commit information. Before running the release command, you can run this command to generate the Release Note for this release.
|
8
|
-
|
9
|
-
The default generated Release Note format is:
|
10
|
-
|
11
|
-
```markdown
|
12
|
-
- fix: add missing type definitions by @zllkjc in https://github.com/web-infra-dev/modern.js/pull/3835
|
13
|
-
```
|
14
|
-
|
15
|
-
Get the Pull Request ID of the changeset through the commit information, and generate a Github link, which includes the changeset's changelog information and author information.
|
16
|
-
|
17
|
-
:::info
|
18
|
-
To get author information, you need to provide the Github Token environment variable, which is passed in through GITHUB_AUTH_TOKEN.
|
19
|
-
:::
|
20
|
-
|
21
|
-
When the default generated Release Note logic cannot meet the requirements, custom Release Note format is supported.
|
22
|
-
|
23
|
-
## Information
|
24
|
-
|
25
|
-
### getReleaseInfo
|
26
|
-
|
27
|
-
To generate Release Note information, some information needs to be collected, such as commit ID, Pull Request ID, commit message, etc.
|
28
|
-
|
29
|
-
This logic can be implemented through the `getReleaseInfo` function.
|
30
|
-
|
31
|
-
#### Params
|
32
|
-
|
33
|
-
- commit
|
34
|
-
|
35
|
-
Type: string;
|
36
|
-
|
37
|
-
The commit message information corresponding to the current changeset.
|
38
|
-
|
39
|
-
The result of executing `git log --pretty=format:%h--%s--%ae .changeset/${changeset.id}.md`.
|
40
|
-
|
41
|
-
- commitObj
|
42
|
-
|
43
|
-
Basic information about commit.
|
44
|
-
|
45
|
-
```ts
|
46
|
-
export enum CommitType {
|
47
|
-
Performance = 'performance',
|
48
|
-
Features = 'features',
|
49
|
-
BugFix = 'bugFix',
|
50
|
-
Doc = 'doc',
|
51
|
-
Other = 'other',
|
52
|
-
}
|
53
|
-
|
54
|
-
interface Commit {
|
55
|
-
id: string; // commit id
|
56
|
-
type: CommitType;
|
57
|
-
repository?: string; // Repo information passed in as a parameter or defined in package.json
|
58
|
-
pullRequestId?: string;
|
59
|
-
author?: string;
|
60
|
-
message: string; // Commit message
|
61
|
-
summary: string; // Changeset summary
|
62
|
-
summary_zh: string; // Changeset summary in Chinese
|
63
|
-
[key: string]: string | undefined;
|
64
|
-
}
|
65
|
-
```
|
66
|
-
|
67
|
-
#### Returns
|
68
|
-
|
69
|
-
commitObj, the complete commit object after supplementation.
|
70
|
-
|
71
|
-
#### Default Implementation
|
72
|
-
|
73
|
-
The default implementation of Modern.js is to split out the Pull Request ID based on the commit information, and get the user information based on the commit ID and add it to the commitObj.
|
74
|
-
|
75
|
-
```ts
|
76
|
-
function getReleaseInfo(commit: string, commitObj: Commit) {
|
77
|
-
const commitRegex = /(.*)\(#(\d*)\)/;
|
78
|
-
|
79
|
-
const [commitId, message, email] = commit.split('--');
|
80
|
-
|
81
|
-
const author = AuthorMap.get(email);
|
82
|
-
const token = authToken || process.env.GITHUB_AUTH_TOKEN;
|
83
|
-
if (author) {
|
84
|
-
commitObj.author = author;
|
85
|
-
} else if (repo && token) {
|
86
|
-
try {
|
87
|
-
const res = await axios.get(
|
88
|
-
`https://api.github.com/repos/${repo}/commits/${commitId}`,
|
89
|
-
{
|
90
|
-
method: 'GET',
|
91
|
-
headers: {
|
92
|
-
'Content-Type': 'application/json',
|
93
|
-
Authorization: token,
|
94
|
-
},
|
95
|
-
},
|
96
|
-
);
|
97
|
-
const author = res.data.author.login;
|
98
|
-
commitObj.author = author;
|
99
|
-
AuthorMap.set(email, author);
|
100
|
-
} catch (e) {
|
101
|
-
console.warn(e);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
if ((message || commitObj.summary).match(commitRegex)) {
|
106
|
-
const [, messageShort, pullRequestId] = (
|
107
|
-
message || commitObj.summary
|
108
|
-
).match(commitRegex)!;
|
109
|
-
commitObj.pullRequestId = pullRequestId;
|
110
|
-
commitObj.message = messageShort.trim();
|
111
|
-
}
|
112
|
-
|
113
|
-
return commitObj;
|
114
|
-
}
|
115
|
-
```
|
116
|
-
|
117
|
-
### getReleaseNoteLine
|
118
|
-
|
119
|
-
Generate the corresponding Release Note based on the commit object information getted in `getReleaseInfo`.
|
120
|
-
|
121
|
-
This logic can be implemented through the `getReleaseNoteLine` function.
|
122
|
-
|
123
|
-
#### Params
|
124
|
-
|
125
|
-
- commit
|
126
|
-
|
127
|
-
The type is the same as the above `commitObj` type.
|
128
|
-
|
129
|
-
- lang
|
130
|
-
|
131
|
-
Type: string;
|
132
|
-
|
133
|
-
Get the Release Note information of the corresponding language, supporting `en` and `zh`, the default is `en`.
|
134
|
-
|
135
|
-
#### Returns
|
136
|
-
|
137
|
-
The generated Release Note.
|
138
|
-
|
139
|
-
#### Default Implementation
|
140
|
-
|
141
|
-
The default implementation of Modern.js is:
|
142
|
-
|
143
|
-
```ts
|
144
|
-
export function getReleaseNoteLine(
|
145
|
-
commit: Commit,
|
146
|
-
lang: 'en' | 'zh' = 'en',
|
147
|
-
) {
|
148
|
-
const { repository, pullRequestId, summary, summary_zh, author } = commit;
|
149
|
-
const pullRequest =
|
150
|
-
pullRequestId && repository
|
151
|
-
? `https://github.com/${repository}/pull/${pullRequestId}`
|
152
|
-
: '';
|
153
|
-
if (lang === 'en') {
|
154
|
-
return `- ${summary}${author ? ` by @${author}` : ''}${
|
155
|
-
pullRequest ? ` in ${pullRequest}` : ''
|
156
|
-
}\n`;
|
157
|
-
}
|
158
|
-
return `- ${summary_zh}${author ? ` 由 @${author} 实现` : ''}${
|
159
|
-
pullRequest ? `, 详情可查看 ${pullRequest}` : ''
|
160
|
-
}\n`;
|
161
|
-
}
|
162
|
-
```
|
163
|
-
|
164
|
-
## Using Custom Modules
|
165
|
-
|
166
|
-
The `gen-release-note` command supports the `--custom` parameter, which can pass in the module name or path of the custom Release Note module.
|
167
|
-
|
168
|
-
### Configuring Relative Paths
|
169
|
-
|
170
|
-
If the custom parameter value is a relative path, it is the **project root directory**.
|
171
|
-
|
172
|
-
For example, create the `scripts/my-release-note-config.js` file and define the following content:
|
173
|
-
|
174
|
-
```ts title="scripts/my-release-note-config.js"
|
175
|
-
function getReleaseInfo(commit, commitObj) {
|
176
|
-
return commitObj;
|
177
|
-
}
|
178
|
-
|
179
|
-
function getReleaseNoteLine(commit) {}
|
180
|
-
|
181
|
-
module.exports = {
|
182
|
-
getReleaseInfo,
|
183
|
-
getReleaseNoteLine,
|
184
|
-
};
|
185
|
-
```
|
186
|
-
|
187
|
-
Run the following command:
|
188
|
-
|
189
|
-
```bash
|
190
|
-
pnpm run gen-release-note --custom ./scripts/my-release-note-config.js
|
191
|
-
```
|
192
|
-
|
193
|
-
You can also define the command parameters directly in `package.json`:
|
194
|
-
|
195
|
-
```json title="package.json"
|
196
|
-
{
|
197
|
-
"scripts": {
|
198
|
-
...
|
199
|
-
"gen-release-note": "modern gen-release-note --custom ./scripts/my-release-note-config.js"
|
200
|
-
},
|
201
|
-
...
|
202
|
-
}
|
203
|
-
```
|
204
|
-
|
205
|
-
Run the command `pnpm run gen-release-note` directly.
|
206
|
-
|
207
|
-
### Using Modern.js Module
|
208
|
-
|
209
|
-
Customizing release note can also be managed using the Modern.js Module to provide a common solution.
|
210
|
-
|
211
|
-
#### Use `npx @modern-js/create@latest` to create a Modern.js Module
|
212
|
-
|
213
|
-
```md
|
214
|
-
? Please select the type of project you want to create: Npm Module
|
215
|
-
? Please fill in the project name: custom-release-note
|
216
|
-
? Please select the programming language: TS
|
217
|
-
? Please select the package manager: pnpm
|
218
|
-
```
|
219
|
-
|
220
|
-
#### Implement Custom Content
|
221
|
-
|
222
|
-
```ts title="src/index.ts"
|
223
|
-
export function getReleaseInfo() {}
|
224
|
-
|
225
|
-
export function getReleaseNoteLine() {}
|
226
|
-
```
|
227
|
-
|
228
|
-
#### Publish the module to NPM
|
229
|
-
#### Install the corresponding module in the root directory of the target repository, such as `custom-release-note`
|
230
|
-
#### Run the `gen-release-note` command with the `custom` parameter added
|
231
|
-
|
232
|
-
```bash
|
233
|
-
pnpm run gen-release-note --custom custom-release-note
|
234
|
-
```
|
235
|
-
|
236
|
-
### Using Monorepo Sub-Project
|
237
|
-
|
238
|
-
If your current repository is Monorepo, you can directly manage it using NPM module sub-projects.
|
239
|
-
|
240
|
-
#### Run `pnpm run new` to create a module sub-project
|
241
|
-
|
242
|
-
```md
|
243
|
-
? Please select the type of project you want to create: Npm Module
|
244
|
-
? Please fill in the sub-project name: custom-release-note
|
245
|
-
? Please fill in the sub-project directory name: custom-release-note
|
246
|
-
? Please select the programming language: TS
|
247
|
-
```
|
248
|
-
|
249
|
-
#### Implement Custom Content
|
250
|
-
|
251
|
-
```ts title="src/index.ts"
|
252
|
-
export function getReleaseInfo() {}
|
253
|
-
|
254
|
-
export function getReleaseNoteLine() {}
|
255
|
-
```
|
256
|
-
|
257
|
-
#### Add the sub-project module dependency, such as `custom-release-note`, to the Monorepo root directory
|
258
|
-
|
259
|
-
```json title="package.json"
|
260
|
-
{
|
261
|
-
"devDependencies": {
|
262
|
-
"custom-release-note": "workspace:*",
|
263
|
-
...
|
264
|
-
}
|
265
|
-
}
|
266
|
-
```
|
267
|
-
|
268
|
-
#### Run the `gen-release-note` command with the `custom` parameter added
|
269
|
-
|
270
|
-
```bash
|
271
|
-
pnpm run gen-release-note --custom custom-release-note
|
272
|
-
```
|
273
|
-
|
274
|
-
After the module is published to NPM, it can still be used like a module type for other repositories.
|
@@ -1,49 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 4
|
3
|
-
---
|
4
|
-
|
5
|
-
# Publishing Pre-Release Version
|
6
|
-
|
7
|
-
Before doing an actual release, we also need to publish a pre-release version for internal testing and user use. Changesets also support publishing pre-release versions.
|
8
|
-
|
9
|
-
## Steps
|
10
|
-
|
11
|
-
:::info
|
12
|
-
The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
|
13
|
-
:::
|
14
|
-
|
15
|
-
#### Run the bump command to upgrade the version of the pre-release
|
16
|
-
|
17
|
-
```bash
|
18
|
-
pnpm run bump --canary --preid <preid>
|
19
|
-
```
|
20
|
-
|
21
|
-
`preid` is the tag for the pre-release version, such as `alpha`, `beta`, etc., and the default value is `next`.
|
22
|
-
|
23
|
-
After using the `--canary` parameter, the `bump` command completes the following three steps:
|
24
|
-
|
25
|
-
- `changeset pre enter <preid>`: Enters pre-release mode.
|
26
|
-
|
27
|
-
- `changeset version`: Upgrades the version.
|
28
|
-
|
29
|
-
- `changeset pre exit`: Exits pre-release mode.
|
30
|
-
|
31
|
-
#### Check the changes and submit
|
32
|
-
|
33
|
-
Check whether the version changes are correct and submit the changes.
|
34
|
-
|
35
|
-
It is recommended to perform pre-release operations not on the main branch and not merge them into the main branch. After the pre-release verification is completed, an actual version can be directly released based on the main branch.
|
36
|
-
|
37
|
-
#### Run the release command to publish the pre-release version:
|
38
|
-
|
39
|
-
```bash
|
40
|
-
pnpm run release --tag <tag>
|
41
|
-
```
|
42
|
-
|
43
|
-
When publishing a pre-release version, you must use the `--tag` parameter. The parameter value is best the same as the `preid` value to facilitate user use.
|
44
|
-
|
45
|
-
## Notes
|
46
|
-
|
47
|
-
### Exiting pre-release mode
|
48
|
-
|
49
|
-
After entering pre-release mode, changesets will automatically create a `pre.json` file in the `.changeset` directory to record some status information when entering pre-release mode. When the status information is inconsistent with the current repository status, you can directly delete this file to exit pre-release mode.
|
@@ -1,229 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 3
|
3
|
-
---
|
4
|
-
|
5
|
-
# Publishing Version
|
6
|
-
|
7
|
-
When releasing a version, we need to upgrade the version of the corresponding packages based on the changeset generated during development, and run the publish command to publish them to NPM.
|
8
|
-
|
9
|
-
## Steps
|
10
|
-
|
11
|
-
:::info
|
12
|
-
The following example commands are all using pnpm. If you need to use other package managers, please replace them as needed.
|
13
|
-
|
14
|
-
:::
|
15
|
-
|
16
|
-
### Modern.js Module
|
17
|
-
|
18
|
-
#### Run the bump command in the root directory
|
19
|
-
|
20
|
-
```bash
|
21
|
-
pnpm run bump
|
22
|
-
```
|
23
|
-
|
24
|
-

|
25
|
-
|
26
|
-
When running this command, changesets will automatically perform the following operations:
|
27
|
-
|
28
|
-
- Delete all changeset files under the `.changesets` directory.
|
29
|
-
|
30
|
-
- Upgrade the package version based on the changeset information.
|
31
|
-
|
32
|
-
- Write changelog information to the `CHANGELOG.md` file in the root directory. The file will be automatically created if it does not exist.
|
33
|
-
|
34
|
-
#### Confirm and submit the current changes
|
35
|
-
|
36
|
-
```bash
|
37
|
-
git add .
|
38
|
-
git commit -m "release: bump package"
|
39
|
-
```
|
40
|
-
|
41
|
-
#### Run the release command in the root directory to publish the package to NPM
|
42
|
-
|
43
|
-
```bash
|
44
|
-
pnpm run release
|
45
|
-
```
|
46
|
-
|
47
|
-

|
48
|
-
|
49
|
-
#### Push the tag to the remote repository
|
50
|
-
|
51
|
-
```bash
|
52
|
-
git push --follow-tags
|
53
|
-
```
|
54
|
-
|
55
|
-
### Monorepo
|
56
|
-
|
57
|
-
#### Run the bmp command in the root directory
|
58
|
-
|
59
|
-
```bash
|
60
|
-
pnpm run bump
|
61
|
-
```
|
62
|
-
|
63
|
-

|
64
|
-
|
65
|
-
When running this command, changesets will automatically perform the following operations:
|
66
|
-
|
67
|
-
- Delete all changeset files under the `.changesets` directory.
|
68
|
-
|
69
|
-
- Upgrade the version of the relevant packages based on the changeset information. In addition to the packages written in the changeset, changesets will also analyze the dependency graph of all packages in the Monorepo during running. If is required, the version will be automatically upgraded accordingly.
|
70
|
-
|
71
|
-
- Write changelog to the `CHANGELOG.md` file in the directory of the package that needs to be upgraded. The file will be automatically created if it does not exist.
|
72
|
-
|
73
|
-
#### Confirm and submit the current changes
|
74
|
-
|
75
|
-
:::info
|
76
|
-
Make sure that the automatically upgraded version meet the expected requirements. If you need to understand the version upgrade strategy, please refer to [Version Upgrade Strategy](/guides/topic-detail/changesets/release#version-upgrade-strategy).
|
77
|
-
:::
|
78
|
-
|
79
|
-
```bash
|
80
|
-
git add .
|
81
|
-
git commit -m "release: bump package"
|
82
|
-
```
|
83
|
-
|
84
|
-
#### Run the release command in the root directory to publish the package to NPM
|
85
|
-
|
86
|
-
```bash
|
87
|
-
pnpm run release
|
88
|
-
```
|
89
|
-
|
90
|
-
When running this command, it will sequentially determine whether the versions of all packages in the Monorepo exist on NPM. If they do not exist, the `publish` command will be run to publish them.
|
91
|
-
|
92
|
-
:::warning
|
93
|
-
When the dependencies between packages in the Monorepo are declared using workspace, do not directly run `npm publish` to publish the package in the corresponding subdirectory of the package. Use the `release` command instead. When publishing, the workspace declaration will be automatically removed to ensure that the NPM package is available after publishing.
|
94
|
-
:::
|
95
|
-
|
96
|
-
#### Push the tag to the remote repository
|
97
|
-
|
98
|
-
```bash
|
99
|
-
git push --follow-tags
|
100
|
-
```
|
101
|
-
|
102
|
-
## Parameters
|
103
|
-
|
104
|
-
### Parameters for the `bump` command
|
105
|
-
|
106
|
-
- `--snapshot`: Generates a timestamp-based version.
|
107
|
-
|
108
|
-
```bash
|
109
|
-
pnpm run bump --snapshot canary
|
110
|
-
```
|
111
|
-
|
112
|
-
After running, the corresponding upgraded version will become `0.0.0-canary-20220622092823`, and `canary` is the tag configured for snapshot. If not configured, it will directly generate the form of `0.0.0-20220622092823`.
|
113
|
-
|
114
|
-
This parameter is mainly used to publish temporary test versions for testing and does not require code submission.
|
115
|
-
|
116
|
-
- `--ignore`: Manually ignore some packages during publishing.
|
117
|
-
|
118
|
-
For example, if you need to ignore the `module-2` package for this release:
|
119
|
-
|
120
|
-
```bash
|
121
|
-
pnpm run bump --ignore module-2
|
122
|
-
```
|
123
|
-
|
124
|
-
After running the command, the update of the `module-2` package will be ignored. Note that if there are packages that depend on `module-2`, the corresponding packages also need to be added to the `ignore` parameter, otherwise the `bump` command will fail.
|
125
|
-
|
126
|
-
The usage for adding multiple packages is as follows:
|
127
|
-
|
128
|
-
```bash
|
129
|
-
pnpm run bump --ignore module-2 --ignore module-3
|
130
|
-
```
|
131
|
-
|
132
|
-
### Parameters for the `release` command
|
133
|
-
|
134
|
-
- `--otp`: Uses `npm token` to publish the package.
|
135
|
-
|
136
|
-
```bash
|
137
|
-
pnpm run relese --otp <token>
|
138
|
-
```
|
139
|
-
|
140
|
-
- `--tag`: Uses a specific tag for publishing, and `latest` is used by default.
|
141
|
-
|
142
|
-
```bash
|
143
|
-
pnpm run release --tag <tag>
|
144
|
-
```
|
145
|
-
|
146
|
-
- `--ignore-scripts`: Ignores npm scripts during publishing.
|
147
|
-
|
148
|
-
When running the `publish` command, npm will automatically trigger many commands, such as `prepare` and `prepublish`. Using this parameter can ignore the running of these commands. This parameter is only supported in Monorepo using pnpm.
|
149
|
-
|
150
|
-
```bash
|
151
|
-
pnpm run release --ignore-scripts
|
152
|
-
```
|
153
|
-
|
154
|
-
- `--no-git-checks`: Ignores checking the current branch during publishing.
|
155
|
-
|
156
|
-
By default, when running the `release` command, it will automatically check whether the current branch is a release branch, whether there are uncommitted changes, etc. Using this parameter can ignore git-related checks.
|
157
|
-
|
158
|
-
```bash
|
159
|
-
pnpm run release --no-git-checks
|
160
|
-
```
|
161
|
-
|
162
|
-
## Version Upgrade Strategy
|
163
|
-
|
164
|
-
### dependencies or devDependencies
|
165
|
-
|
166
|
-
- Only upgrade the patch version of the package itself for patch version
|
167
|
-
|
168
|
-
For example, the following scenario exists:
|
169
|
-
|
170
|
-
There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `dependencies` of `module-2`.
|
171
|
-
|
172
|
-
The current changeset is the patch version upgrade of `module-1`.
|
173
|
-
|
174
|
-
After running the `bump` command, only the patch version of `module-1` will be upgraded.
|
175
|
-
|
176
|
-
- Upgrade the major or minor version of the package itself for major/minor version upgrades, and upgrade the patch version of the dependent packages
|
177
|
-
|
178
|
-
For example, the following scenario exists:
|
179
|
-
|
180
|
-
There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `dependencies` of `module-2`.
|
181
|
-
|
182
|
-
The current changeset is the minor version upgrade of `module-1`.
|
183
|
-
|
184
|
-
After running the `bump` command, `module-1` will upgrade the `minor` version, and `module-2` will upgrade the `patch` version number.
|
185
|
-
|
186
|
-
### peerDependencies
|
187
|
-
|
188
|
-
- Upgrade the patch version of the package itself and the dependent package for patch version dependencies
|
189
|
-
|
190
|
-
For example, the following scenario exists:
|
191
|
-
|
192
|
-
There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `peerDependencies` of `module-2`.
|
193
|
-
|
194
|
-
The current changeset is the patch version upgrade of `module-1`.
|
195
|
-
|
196
|
-
After running the `bump` command, both `module-1` and `module-2` will upgrade the patch version.
|
197
|
-
|
198
|
-
- Upgrade the major version of the dependent package for major/minor version upgrades of the package itself
|
199
|
-
|
200
|
-
For example, the following scenario exists:
|
201
|
-
|
202
|
-
There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `peerDependencies` of `module-2`.
|
203
|
-
|
204
|
-
The current changeset is the minor version upgrade of `module-1`.
|
205
|
-
|
206
|
-
After running the bump command, `module-1` will upgrade the `minor` version, and `module-2` will upgrade the `major` version number.
|
207
|
-
|
208
|
-
- Modify the upgrade strategy for peerDependencies
|
209
|
-
|
210
|
-
The upgrade strategy of `peerDependencies` can be modified by configuring `onlyUpdatePeerDependentsWhenOutOfRange`. When only the declared version type range is exceeded, the corresponding `peerDependencies` will be upgraded.
|
211
|
-
|
212
|
-
```json
|
213
|
-
{
|
214
|
-
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
|
215
|
-
"onlyUpdatePeerDependentsWhenOutOfRange": true
|
216
|
-
},
|
217
|
-
...
|
218
|
-
}
|
219
|
-
```
|
220
|
-
|
221
|
-
For example, the following scenario exists:
|
222
|
-
|
223
|
-
There are two packages in Monorepo, `module-1` and `module-2`, and `module-1` exists in the `peerDependencies` of `module-2`, and the version of `module-1` is declared using `^`.
|
224
|
-
|
225
|
-
The current changeset is the patch or minor version upgrade of `module-1`.
|
226
|
-
|
227
|
-
After running the `bump` command, only the version of `module-1` will be upgraded.
|
228
|
-
|
229
|
-
Note that if the package version is in the `0.x.x` range, upgrading the `minor` version is also beyond the declared version type range.
|
@@ -1,45 +0,0 @@
|
|
1
|
-
---
|
2
|
-
sidebar_position: 9
|
3
|
-
title: Test Model
|
4
|
-
---
|
5
|
-
# Test Model
|
6
|
-
|
7
|
-
Testing is crucial for the stability of code. Here's an example using the `countModel` from [Quick Start](/guides/topic-detail/model/quick-start) to demonstrate how to perform unit testing on a Model in Modern.js.
|
8
|
-
|
9
|
-
To use the testing feature, you need to first enable it. In the project root directory, execute `pnpm run new` and make the following selection:
|
10
|
-
|
11
|
-
```bash
|
12
|
-
? Please select the operation you want to perform: Enable optional features
|
13
|
-
? Enable optional features Enable "Unit Testing / Integration Testing" feature
|
14
|
-
```
|
15
|
-
|
16
|
-
This will enable testing feature support.
|
17
|
-
|
18
|
-
Create a new file called `count.test.ts` with the following code:
|
19
|
-
|
20
|
-
```ts
|
21
|
-
import { createStore } from '@modern-js/runtime/testing';
|
22
|
-
import countModel from './count';
|
23
|
-
|
24
|
-
describe('test model', () => {
|
25
|
-
it('count value should plus one after add', () => {
|
26
|
-
const store = createStore();
|
27
|
-
const [state, { add }] = store.use(countModel);
|
28
|
-
|
29
|
-
expect(state).toEqual({ value: 1 });
|
30
|
-
|
31
|
-
add();
|
32
|
-
|
33
|
-
expect(store.use(countModel)[0]).toEqual({ value: 2 });
|
34
|
-
});
|
35
|
-
});
|
36
|
-
```
|
37
|
-
|
38
|
-
:::info
|
39
|
-
The [`createStore`](/apis/app/runtime/model/create-store) used here is imported from `@modern-js/runtime/testing`, which internally uses the configuration of [`runtime.state`](/configure/app/runtime/state) to create a `store`.
|
40
|
-
|
41
|
-
:::
|
42
|
-
|
43
|
-
In the test case, we create a new `store` to mount `countModel`, use `store.use` to get the State and Actions of `countModel`. Then, we call the `add` Action to update the state and assert the updated state value.
|
44
|
-
|
45
|
-
Execute the `pnpm run test` command to trigger the execution of the test case.
|
@@ -1,35 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: act
|
3
|
-
---
|
4
|
-
# act
|
5
|
-
|
6
|
-
用于确保渲染、事件、数据获取等行为已经应用在 DOM 上。
|
7
|
-
|
8
|
-
## 使用姿势
|
9
|
-
|
10
|
-
```ts
|
11
|
-
import { act } from '@modern-js/runtime/testing';
|
12
|
-
```
|
13
|
-
|
14
|
-
## 函数签名
|
15
|
-
|
16
|
-
`act` 和 [react-dom/test-utils act 函数](https://reactjs.org/docs/testing-recipes.html#act) 是一致的。
|
17
|
-
|
18
|
-
## 示例
|
19
|
-
|
20
|
-
```tsx
|
21
|
-
import ReactDOM from 'react-dom';
|
22
|
-
import { act } from '@modern-js/runtime/testing';
|
23
|
-
import { Foo } from '@/components/Foo';
|
24
|
-
|
25
|
-
describe('test act', () => {
|
26
|
-
it('it should be foo', () => {
|
27
|
-
const el = document.createElement('div');
|
28
|
-
act(() => {
|
29
|
-
ReactDOM.render(<Foo />, el);
|
30
|
-
});
|
31
|
-
|
32
|
-
expect(el.innerHTML).toBe('<div>Foo</div>');
|
33
|
-
});
|
34
|
-
});
|
35
|
-
```
|
@@ -1,40 +0,0 @@
|
|
1
|
-
---
|
2
|
-
title: cleanup
|
3
|
-
sidebar_position: 3
|
4
|
-
---
|
5
|
-
# cleanup
|
6
|
-
|
7
|
-
用于卸载掉当前已渲染的所有组件。
|
8
|
-
|
9
|
-
## 使用姿势
|
10
|
-
|
11
|
-
```ts
|
12
|
-
import { cleanup } from '@modenr-js/runtime/testing';
|
13
|
-
```
|
14
|
-
|
15
|
-
## 函数签名
|
16
|
-
|
17
|
-
`function cleanup(): void`
|
18
|
-
|
19
|
-
## 示例
|
20
|
-
|
21
|
-
:::info
|
22
|
-
请注意,如果你使用的测试框架支持 afterEach,并且它被注入到你的测试环境中(如 mocha、Jest 和 Jasmine),**会默认在 afterEach 钩子里执行 `cleanup`**。否则,你将需要在每次测试后进行手动清理。
|
23
|
-
|
24
|
-
:::
|
25
|
-
|
26
|
-
例如,如果你使用[ava](https://github.com/avajs/ava)测试框架,那么你需要像这样使用 test.afterEach 钩子。
|
27
|
-
|
28
|
-
```tsx
|
29
|
-
import { cleanup, render } from '@modern-js/runtime/testing';
|
30
|
-
import test from 'ava';
|
31
|
-
|
32
|
-
test.afterEach(cleanup);
|
33
|
-
|
34
|
-
test('renders into document', () => {
|
35
|
-
render(<div />);
|
36
|
-
// ...
|
37
|
-
});
|
38
|
-
|
39
|
-
// ... more tests ...
|
40
|
-
```
|