@modern-js/main-doc 2.39.2 → 2.40.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -84,72 +84,6 @@ The configuration returned by the `config` hook will be collected and merged by
|
|
84
84
|
2. Configuration defined by the plugin through the `config` hook.
|
85
85
|
3. Default configuration of Modern.js.
|
86
86
|
|
87
|
-
### `validateSchema`
|
88
|
-
|
89
|
-
- Functionality: Collect the JSON schema used to validate user configurations in various plugins.
|
90
|
-
- Execution phase: After the `config` Hook has run.
|
91
|
-
- Hook model: `ParallelWorkflow`
|
92
|
-
- Type: `ParallelWorkflow<void, unknown>`
|
93
|
-
- Example:
|
94
|
-
|
95
|
-
```ts
|
96
|
-
import type { CliPlugin } from '@modern-js/core';
|
97
|
-
|
98
|
-
export const myPlugin = (): CliPlugin => ({
|
99
|
-
setup(api) {
|
100
|
-
return {
|
101
|
-
validateSchema: () => {
|
102
|
-
return {
|
103
|
-
// target is field
|
104
|
-
target: 'foo',
|
105
|
-
schema: {
|
106
|
-
type: 'string',
|
107
|
-
},
|
108
|
-
};
|
109
|
-
},
|
110
|
-
};
|
111
|
-
},
|
112
|
-
});
|
113
|
-
```
|
114
|
-
|
115
|
-
The returned JSON Schema here is used to validate the configuration information in `modern.config.js`.
|
116
|
-
|
117
|
-
For example, the following JSON Schema is returned:
|
118
|
-
|
119
|
-
```json
|
120
|
-
{
|
121
|
-
"target": "foo",
|
122
|
-
"schema": {
|
123
|
-
"type": "string"
|
124
|
-
}
|
125
|
-
}
|
126
|
-
```
|
127
|
-
|
128
|
-
You can configure it in `modern.config.ts` like this:
|
129
|
-
|
130
|
-
```ts title="modern.config.ts"
|
131
|
-
export const myPlugin = defineConfig({
|
132
|
-
foo: 'test',
|
133
|
-
});
|
134
|
-
```
|
135
|
-
|
136
|
-
If it is another type, validation will fail and an error will be reported. For example:
|
137
|
-
|
138
|
-
```ts title="modern.config.ts"
|
139
|
-
export const myPlugin = defineConfig({
|
140
|
-
foo: {},
|
141
|
-
});
|
142
|
-
```
|
143
|
-
|
144
|
-
then throw error:
|
145
|
-
|
146
|
-
```
|
147
|
-
$ modern dev
|
148
|
-
1 | {
|
149
|
-
> 2 | "foo": {},
|
150
|
-
| ^^^^^ Property foo is not expected to be here
|
151
|
-
```
|
152
|
-
|
153
87
|
### `prepare`
|
154
88
|
|
155
89
|
- Functionality: Preparatory process for running the main process.
|
@@ -84,72 +84,6 @@ export const myPlugin = (): CliPlugin => ({
|
|
84
84
|
2. 插件通过 `config` hook 定义的配置
|
85
85
|
3. Modern.js 默认配置。
|
86
86
|
|
87
|
-
### `validateSchema`
|
88
|
-
|
89
|
-
- 功能:收集各个插件中配置的用来校验用户配置的 [JSON Schema](https://json-schema.org/)
|
90
|
-
- 执行阶段:`config` Hook 运行完成之后。
|
91
|
-
- Hook 模型:`ParallelWorkflow`
|
92
|
-
- 类型:`ParallelWorkflow<void, unknown>`
|
93
|
-
- 使用示例:
|
94
|
-
|
95
|
-
```ts
|
96
|
-
import type { CliPlugin } from '@modern-js/core';
|
97
|
-
|
98
|
-
export const myPlugin = (): CliPlugin => ({
|
99
|
-
setup(api) {
|
100
|
-
return {
|
101
|
-
validateSchema: () => {
|
102
|
-
return {
|
103
|
-
// target is field
|
104
|
-
target: 'foo',
|
105
|
-
schema: {
|
106
|
-
type: 'string',
|
107
|
-
},
|
108
|
-
};
|
109
|
-
},
|
110
|
-
};
|
111
|
-
},
|
112
|
-
});
|
113
|
-
```
|
114
|
-
|
115
|
-
这里返回的 JSON Schema 会用来校验 `modern.config.js` 中的配置信息。
|
116
|
-
|
117
|
-
比如这里返回:
|
118
|
-
|
119
|
-
```json
|
120
|
-
{
|
121
|
-
"target": "foo",
|
122
|
-
"schema": {
|
123
|
-
"type": "string"
|
124
|
-
}
|
125
|
-
}
|
126
|
-
```
|
127
|
-
|
128
|
-
就可以在 `modern.config.ts` 中这样配置:
|
129
|
-
|
130
|
-
```ts title="modern.config.ts"
|
131
|
-
export const myPlugin = defineConfig({
|
132
|
-
foo: 'test',
|
133
|
-
});
|
134
|
-
```
|
135
|
-
|
136
|
-
如果是别的类型,校验就不通过会报错,比如这样:
|
137
|
-
|
138
|
-
```ts title="modern.config.ts"
|
139
|
-
export const myPlugin = defineConfig({
|
140
|
-
foo: {},
|
141
|
-
});
|
142
|
-
```
|
143
|
-
|
144
|
-
就会报错:
|
145
|
-
|
146
|
-
```
|
147
|
-
$ modern dev
|
148
|
-
1 | {
|
149
|
-
> 2 | "foo": {},
|
150
|
-
| ^^^^^ Property foo is not expected to be here
|
151
|
-
```
|
152
|
-
|
153
87
|
### `prepare`
|
154
88
|
|
155
89
|
- 功能:运行主流程的前置准备流程
|
package/package.json
CHANGED
@@ -15,17 +15,17 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.40.0",
|
19
19
|
"publishConfig": {
|
20
20
|
"registry": "https://registry.npmjs.org/",
|
21
21
|
"access": "public",
|
22
22
|
"provenance": true
|
23
23
|
},
|
24
24
|
"dependencies": {
|
25
|
-
"@modern-js/sandpack-react": "2.
|
25
|
+
"@modern-js/sandpack-react": "2.40.0"
|
26
26
|
},
|
27
27
|
"peerDependencies": {
|
28
|
-
"@modern-js/builder-doc": "^2.
|
28
|
+
"@modern-js/builder-doc": "^2.40.0"
|
29
29
|
},
|
30
30
|
"devDependencies": {
|
31
31
|
"classnames": "^2",
|
@@ -35,12 +35,12 @@
|
|
35
35
|
"ts-node": "^10.9.1",
|
36
36
|
"typescript": "^5",
|
37
37
|
"fs-extra": "^10",
|
38
|
-
"rspress": "1.
|
39
|
-
"@rspress/shared": "1.
|
38
|
+
"rspress": "1.5.0",
|
39
|
+
"@rspress/shared": "1.5.0",
|
40
40
|
"@types/node": "^16",
|
41
41
|
"@types/fs-extra": "^9",
|
42
|
-
"@modern-js/doc
|
43
|
-
"@modern-js/
|
42
|
+
"@modern-js/builder-doc": "2.40.0",
|
43
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.40.0"
|
44
44
|
},
|
45
45
|
"scripts": {
|
46
46
|
"dev": "rspress dev",
|