@modern-js/core 1.0.0-rc.9 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +226 -0
- package/README.md +21 -20
- package/dist/js/modern/config/defaults.js +2 -1
- package/dist/js/modern/config/index.js +1 -1
- package/dist/js/modern/config/schema/deploy.js +1 -15
- package/dist/js/modern/config/schema/index.js +3 -0
- package/dist/js/modern/config/schema/server.js +3 -0
- package/dist/js/modern/context.js +1 -1
- package/dist/js/modern/index.js +17 -13
- package/dist/js/modern/initWatcher.js +2 -8
- package/dist/js/modern/loadEnv.js +1 -1
- package/dist/js/modern/loadPlugins.js +3 -3
- package/dist/js/node/config/defaults.js +2 -1
- package/dist/js/node/config/index.js +1 -1
- package/dist/js/node/config/schema/deploy.js +1 -15
- package/dist/js/node/config/schema/index.js +3 -0
- package/dist/js/node/config/schema/server.js +3 -0
- package/dist/js/node/context.js +6 -6
- package/dist/js/node/index.js +54 -23
- package/dist/js/node/initWatcher.js +5 -12
- package/dist/js/node/loadEnv.js +3 -3
- package/dist/js/node/loadPlugins.js +2 -2
- package/dist/types/config/defaults.d.ts +1 -0
- package/dist/types/config/index.d.ts +3 -3
- package/dist/types/config/schema/deploy.d.ts +1 -15
- package/dist/types/config/schema/index.d.ts +7 -15
- package/dist/types/config/schema/server.d.ts +3 -0
- package/dist/types/index.d.ts +5 -3
- package/dist/types/initWatcher.d.ts +1 -2
- package/package.json +19 -8
- package/src/config/defaults.ts +1 -1
- package/src/config/index.ts +4 -4
- package/src/config/schema/deploy.ts +1 -7
- package/src/config/schema/index.ts +6 -1
- package/src/config/schema/server.ts +1 -0
- package/src/context.ts +1 -1
- package/src/index.ts +30 -22
- package/src/initWatcher.ts +2 -6
- package/src/loadEnv.ts +1 -1
- package/src/loadPlugins.ts +2 -1
- package/tests/loadEnv.test.ts +1 -1
- package/tests/loadPlugin.test.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,231 @@
|
|
|
1
1
|
# @modern-js/core
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 224f7fe: fix server route match
|
|
8
|
+
- 30ac27c: feat: add generator package description
|
|
9
|
+
- 0fd196e: feat: fix bugs
|
|
10
|
+
- 204c626: feat: initial
|
|
11
|
+
- 63be0a5: fix: #118 #104
|
|
12
|
+
- Updated dependencies [224f7fe]
|
|
13
|
+
- Updated dependencies [30ac27c]
|
|
14
|
+
- Updated dependencies [0fd196e]
|
|
15
|
+
- Updated dependencies [204c626]
|
|
16
|
+
- Updated dependencies [63be0a5]
|
|
17
|
+
- @modern-js/load-config@1.0.0
|
|
18
|
+
- @modern-js/plugin@1.0.0
|
|
19
|
+
- @modern-js/utils@1.0.0
|
|
20
|
+
|
|
21
|
+
## 1.0.0-rc.23
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 224f7fe: fix server route match
|
|
26
|
+
- 30ac27c: feat: add generator package description
|
|
27
|
+
- 0fd196e: feat: fix bugs
|
|
28
|
+
- 204c626: feat: initial
|
|
29
|
+
- 63be0a5: fix: #118 #104
|
|
30
|
+
- Updated dependencies [224f7fe]
|
|
31
|
+
- Updated dependencies [30ac27c]
|
|
32
|
+
- Updated dependencies [0fd196e]
|
|
33
|
+
- Updated dependencies [204c626]
|
|
34
|
+
- Updated dependencies [63be0a5]
|
|
35
|
+
- @modern-js/load-config@1.0.0-rc.28
|
|
36
|
+
- @modern-js/plugin@1.0.0-rc.23
|
|
37
|
+
- @modern-js/utils@1.0.0-rc.23
|
|
38
|
+
|
|
39
|
+
## 1.0.0-rc.22
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- 224f7fe: fix server route match
|
|
44
|
+
- 30ac27c: feat: add generator package description
|
|
45
|
+
- 0fd196e: feat: fix bugs
|
|
46
|
+
- 204c626: feat: initial
|
|
47
|
+
- 63be0a5: fix: #118 #104
|
|
48
|
+
- Updated dependencies [224f7fe]
|
|
49
|
+
- Updated dependencies [30ac27c]
|
|
50
|
+
- Updated dependencies [0fd196e]
|
|
51
|
+
- Updated dependencies [204c626]
|
|
52
|
+
- Updated dependencies [63be0a5]
|
|
53
|
+
- @modern-js/load-config@1.0.0-rc.27
|
|
54
|
+
- @modern-js/plugin@1.0.0-rc.22
|
|
55
|
+
- @modern-js/utils@1.0.0-rc.22
|
|
56
|
+
|
|
57
|
+
## 1.0.0-rc.21
|
|
58
|
+
|
|
59
|
+
### Patch Changes
|
|
60
|
+
|
|
61
|
+
- 224f7fe: fix server route match
|
|
62
|
+
- 30ac27c: feat: add generator package description
|
|
63
|
+
- 0fd196e: feat: fix bugs
|
|
64
|
+
- 204c626: feat: initial
|
|
65
|
+
- 63be0a5: fix: #118 #104
|
|
66
|
+
- Updated dependencies [224f7fe]
|
|
67
|
+
- Updated dependencies [30ac27c]
|
|
68
|
+
- Updated dependencies [0fd196e]
|
|
69
|
+
- Updated dependencies [204c626]
|
|
70
|
+
- Updated dependencies [63be0a5]
|
|
71
|
+
- @modern-js/load-config@1.0.0-rc.26
|
|
72
|
+
- @modern-js/plugin@1.0.0-rc.21
|
|
73
|
+
- @modern-js/utils@1.0.0-rc.21
|
|
74
|
+
|
|
75
|
+
## 1.0.0-rc.20
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- 224f7fe: fix server route match
|
|
80
|
+
- 30ac27c: feat: add generator package description
|
|
81
|
+
- feat: fix bugs
|
|
82
|
+
- 204c626: feat: initial
|
|
83
|
+
- 63be0a5: fix: #118 #104
|
|
84
|
+
- Updated dependencies [224f7fe]
|
|
85
|
+
- Updated dependencies [30ac27c]
|
|
86
|
+
- Updated dependencies [undefined]
|
|
87
|
+
- Updated dependencies [204c626]
|
|
88
|
+
- Updated dependencies [63be0a5]
|
|
89
|
+
- @modern-js/load-config@1.0.0-rc.24
|
|
90
|
+
- @modern-js/plugin@1.0.0-rc.20
|
|
91
|
+
- @modern-js/utils@1.0.0-rc.20
|
|
92
|
+
|
|
93
|
+
## 1.0.0-rc.19
|
|
94
|
+
|
|
95
|
+
### Patch Changes
|
|
96
|
+
|
|
97
|
+
- 224f7fe: fix server route match
|
|
98
|
+
- 30ac27c: feat: add generator package description
|
|
99
|
+
- 204c626: feat: initial
|
|
100
|
+
- 63be0a5: fix: #118 #104
|
|
101
|
+
- Updated dependencies [224f7fe]
|
|
102
|
+
- Updated dependencies [30ac27c]
|
|
103
|
+
- Updated dependencies [204c626]
|
|
104
|
+
- Updated dependencies [63be0a5]
|
|
105
|
+
- @modern-js/load-config@1.0.0-rc.23
|
|
106
|
+
- @modern-js/plugin@1.0.0-rc.19
|
|
107
|
+
- @modern-js/utils@1.0.0-rc.19
|
|
108
|
+
|
|
109
|
+
## 1.0.0-rc.18
|
|
110
|
+
|
|
111
|
+
### Patch Changes
|
|
112
|
+
|
|
113
|
+
- 224f7fe: fix server route match
|
|
114
|
+
- 30ac27c: feat: add generator package description
|
|
115
|
+
- 204c626: feat: initial
|
|
116
|
+
- 63be0a5: fix: #118 #104
|
|
117
|
+
- Updated dependencies [224f7fe]
|
|
118
|
+
- Updated dependencies [30ac27c]
|
|
119
|
+
- Updated dependencies [204c626]
|
|
120
|
+
- Updated dependencies [63be0a5]
|
|
121
|
+
- @modern-js/load-config@1.0.0-rc.22
|
|
122
|
+
- @modern-js/plugin@1.0.0-rc.18
|
|
123
|
+
- @modern-js/utils@1.0.0-rc.18
|
|
124
|
+
|
|
125
|
+
## 1.0.0-rc.17
|
|
126
|
+
|
|
127
|
+
### Patch Changes
|
|
128
|
+
|
|
129
|
+
- 224f7fe: fix server route match
|
|
130
|
+
- 30ac27c: feat: add generator package description
|
|
131
|
+
- 204c626: feat: initial
|
|
132
|
+
- fix: #118 #104
|
|
133
|
+
- Updated dependencies [224f7fe]
|
|
134
|
+
- Updated dependencies [30ac27c]
|
|
135
|
+
- Updated dependencies [204c626]
|
|
136
|
+
- Updated dependencies [undefined]
|
|
137
|
+
- @modern-js/load-config@1.0.0-rc.17
|
|
138
|
+
- @modern-js/plugin@1.0.0-rc.17
|
|
139
|
+
- @modern-js/utils@1.0.0-rc.17
|
|
140
|
+
|
|
141
|
+
## 1.0.0-rc.16
|
|
142
|
+
|
|
143
|
+
### Patch Changes
|
|
144
|
+
|
|
145
|
+
- 224f7fe: fix server route match
|
|
146
|
+
- 30ac27c: feat: add generator package description
|
|
147
|
+
- 204c626: feat: initial
|
|
148
|
+
- Updated dependencies [224f7fe]
|
|
149
|
+
- Updated dependencies [30ac27c]
|
|
150
|
+
- Updated dependencies [204c626]
|
|
151
|
+
- @modern-js/load-config@1.0.0-rc.16
|
|
152
|
+
- @modern-js/plugin@1.0.0-rc.16
|
|
153
|
+
- @modern-js/utils@1.0.0-rc.16
|
|
154
|
+
|
|
155
|
+
## 1.0.0-rc.15
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- 224f7fe: fix server route match
|
|
160
|
+
- 30ac27c: feat: add generator package description
|
|
161
|
+
- 204c626: feat: initial
|
|
162
|
+
- Updated dependencies [224f7fe]
|
|
163
|
+
- Updated dependencies [30ac27c]
|
|
164
|
+
- Updated dependencies [204c626]
|
|
165
|
+
- @modern-js/load-config@1.0.0-rc.15
|
|
166
|
+
- @modern-js/plugin@1.0.0-rc.15
|
|
167
|
+
- @modern-js/utils@1.0.0-rc.15
|
|
168
|
+
|
|
169
|
+
## 1.0.0-rc.14
|
|
170
|
+
|
|
171
|
+
### Patch Changes
|
|
172
|
+
|
|
173
|
+
- 224f7fe: fix server route match
|
|
174
|
+
- 204c626: feat: initial
|
|
175
|
+
- Updated dependencies [224f7fe]
|
|
176
|
+
- Updated dependencies [204c626]
|
|
177
|
+
- @modern-js/load-config@1.0.0-rc.14
|
|
178
|
+
- @modern-js/plugin@1.0.0-rc.14
|
|
179
|
+
- @modern-js/utils@1.0.0-rc.14
|
|
180
|
+
|
|
181
|
+
## 1.0.0-rc.13
|
|
182
|
+
|
|
183
|
+
### Patch Changes
|
|
184
|
+
|
|
185
|
+
- 224f7fe: fix server route match
|
|
186
|
+
- 204c626: feat: initial
|
|
187
|
+
- Updated dependencies [224f7fe]
|
|
188
|
+
- Updated dependencies [204c626]
|
|
189
|
+
- @modern-js/load-config@1.0.0-rc.13
|
|
190
|
+
- @modern-js/plugin@1.0.0-rc.13
|
|
191
|
+
- @modern-js/utils@1.0.0-rc.13
|
|
192
|
+
|
|
193
|
+
## 1.0.0-rc.12
|
|
194
|
+
|
|
195
|
+
### Patch Changes
|
|
196
|
+
|
|
197
|
+
- 224f7fe: fix server route match
|
|
198
|
+
- 204c626: feat: initial
|
|
199
|
+
- Updated dependencies [224f7fe]
|
|
200
|
+
- Updated dependencies [204c626]
|
|
201
|
+
- @modern-js/load-config@1.0.0-rc.12
|
|
202
|
+
- @modern-js/plugin@1.0.0-rc.12
|
|
203
|
+
- @modern-js/utils@1.0.0-rc.12
|
|
204
|
+
|
|
205
|
+
## 1.0.0-rc.11
|
|
206
|
+
|
|
207
|
+
### Patch Changes
|
|
208
|
+
|
|
209
|
+
- 224f7fe: fix server route match
|
|
210
|
+
- 204c626: feat: initial
|
|
211
|
+
- Updated dependencies [224f7fe]
|
|
212
|
+
- Updated dependencies [204c626]
|
|
213
|
+
- @modern-js/load-config@1.0.0-rc.11
|
|
214
|
+
- @modern-js/plugin@1.0.0-rc.11
|
|
215
|
+
- @modern-js/utils@1.0.0-rc.11
|
|
216
|
+
|
|
217
|
+
## 1.0.0-rc.10
|
|
218
|
+
|
|
219
|
+
### Patch Changes
|
|
220
|
+
|
|
221
|
+
- 224f7fe: fix server route match
|
|
222
|
+
- 204c626: feat: initial
|
|
223
|
+
- Updated dependencies [224f7fe]
|
|
224
|
+
- Updated dependencies [204c626]
|
|
225
|
+
- @modern-js/load-config@1.0.0-rc.10
|
|
226
|
+
- @modern-js/plugin@1.0.0-rc.10
|
|
227
|
+
- @modern-js/utils@1.0.0-rc.10
|
|
228
|
+
|
|
3
229
|
## 1.0.0-rc.9
|
|
4
230
|
|
|
5
231
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -2,31 +2,32 @@
|
|
|
2
2
|
<p align="center">
|
|
3
3
|
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
4
4
|
</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
现代 Web 工程体系
|
|
7
|
+
<br/>
|
|
8
|
+
<a href="https://modernjs.dev" target="blank">
|
|
9
|
+
modernjs.dev
|
|
10
|
+
</a>
|
|
11
|
+
</p>
|
|
12
|
+
<p align="center">
|
|
13
|
+
The meta-framework suite designed from scratch for frontend-focused modern web development
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
# Introduction
|
|
5
17
|
|
|
6
|
-
|
|
18
|
+
> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.
|
|
7
19
|
|
|
8
|
-
|
|
20
|
+
- 介绍 Modern.js (即将上线)
|
|
9
21
|
- [迈入现代 Web 开发](https://zhuanlan.zhihu.com/p/386607009)
|
|
10
22
|
- [现代 Web 开发者问卷调查报告](https://zhuanlan.zhihu.com/p/403206195)
|
|
23
|
+
- [字节跳动是如何落地微前端的](https://mp.weixin.qq.com/s/L9wbfNG5fTXF5bx7dcgj4Q)
|
|
11
24
|
|
|
12
|
-
##
|
|
13
|
-
|
|
14
|
-
Modern.js 的 1.0.0.rc 版已经发到 npm,目前在做测试改进,README 文档之后统一提供(现阶段加入测试和开发,可以发 [issue](https://github.com/modern-js-dev/modern.js/issues) 留微信联系),完整的文档站计划在10月14日上线
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
## Getting Started
|
|
30
26
|
|
|
27
|
+
- [Quick Start](https://modernjs.dev/docs/start)
|
|
28
|
+
- [Guides](https://modernjs.dev/docs/guides)
|
|
29
|
+
- [API References](https://modernjs.dev/docs/apis)
|
|
31
30
|
|
|
31
|
+
## Contributing
|
|
32
32
|
|
|
33
|
+
- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)
|
|
@@ -20,7 +20,7 @@ const debug = createDebugger('resolve-config');
|
|
|
20
20
|
export { defaults as defaultsConfig };
|
|
21
21
|
export const defineConfig = config => config;
|
|
22
22
|
export const loadUserConfig = async (appDirectory, filePath) => {
|
|
23
|
-
const loaded = loadConfig(appDirectory, filePath);
|
|
23
|
+
const loaded = await loadConfig(appDirectory, filePath);
|
|
24
24
|
const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
|
|
25
25
|
return {
|
|
26
26
|
config: mergeWith({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
|
|
@@ -3,21 +3,7 @@ export const deploy = {
|
|
|
3
3
|
type: 'object',
|
|
4
4
|
properties: {
|
|
5
5
|
microFrontend: {
|
|
6
|
-
type: 'object'
|
|
7
|
-
dependencies: {
|
|
8
|
-
enableHtmlEntry: {
|
|
9
|
-
properties: {
|
|
10
|
-
enableLegacy: {
|
|
11
|
-
enum: [false]
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
properties: {
|
|
17
|
-
enableHtmlEntry: {
|
|
18
|
-
type: 'boolean'
|
|
19
|
-
}
|
|
20
|
-
}
|
|
6
|
+
type: ['boolean', 'object']
|
|
21
7
|
},
|
|
22
8
|
domain: {
|
|
23
9
|
type: ['array', 'string']
|
package/dist/js/modern/index.js
CHANGED
|
@@ -4,10 +4,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
|
-
import path from '
|
|
8
|
-
import { createAsyncManager,
|
|
7
|
+
import { path, upath, compatRequire, pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
|
|
8
|
+
import { createAsyncManager, createAsyncWorkflow, createParallelWorkflow } from '@modern-js/plugin';
|
|
9
9
|
import { enable } from '@modern-js/plugin/node';
|
|
10
|
-
import { compatRequire, pkgUp, ensureAbsolutePath, logger } from '@modern-js/utils';
|
|
11
10
|
import { program } from "./utils/commander";
|
|
12
11
|
import { resolveConfig, defineConfig, loadUserConfig } from "./config";
|
|
13
12
|
import { loadPlugins } from "./loadPlugins";
|
|
@@ -15,6 +14,8 @@ import { AppContext, ConfigContext, initAppContext, ResolvedConfigContext, useAp
|
|
|
15
14
|
import { initWatcher } from "./initWatcher";
|
|
16
15
|
import { loadEnv } from "./loadEnv";
|
|
17
16
|
export { defaultsConfig } from "./config";
|
|
17
|
+
export * from '@modern-js/plugin';
|
|
18
|
+
export * from '@modern-js/plugin/node';
|
|
18
19
|
program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
19
20
|
const hooksMap = {
|
|
20
21
|
config: createParallelWorkflow(),
|
|
@@ -33,8 +34,8 @@ export const {
|
|
|
33
34
|
registe: registerHook,
|
|
34
35
|
useRunner: mountHook
|
|
35
36
|
} = manager;
|
|
36
|
-
export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(require.resolve(plugin))));
|
|
37
|
-
export { defineConfig,
|
|
37
|
+
export const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin(compatRequire(upath.normalize(require.resolve(plugin)))));
|
|
38
|
+
export { defineConfig, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
|
|
38
39
|
|
|
39
40
|
const initAppDir = async () => {
|
|
40
41
|
const pkg = await pkgUp({
|
|
@@ -53,6 +54,7 @@ const createCli = () => {
|
|
|
53
54
|
let isRestart = false;
|
|
54
55
|
|
|
55
56
|
const init = async (argv = []) => {
|
|
57
|
+
enable();
|
|
56
58
|
manager.clear();
|
|
57
59
|
const appDirectory = await initAppDir();
|
|
58
60
|
loadEnv(appDirectory);
|
|
@@ -100,31 +102,33 @@ const createCli = () => {
|
|
|
100
102
|
};
|
|
101
103
|
|
|
102
104
|
async function run(argv) {
|
|
103
|
-
enable();
|
|
104
105
|
const {
|
|
105
106
|
loadedConfig,
|
|
106
107
|
appContext,
|
|
107
108
|
resolved
|
|
108
109
|
} = await init(argv);
|
|
109
|
-
initWatcher(loadedConfig, appContext.appDirectory, resolved, hooksRunner, argv);
|
|
110
110
|
await hooksRunner.commands({
|
|
111
111
|
program
|
|
112
112
|
});
|
|
113
|
+
initWatcher(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
113
114
|
manager.run(() => program.parse(process.argv));
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
async function restart() {
|
|
117
118
|
isRestart = true;
|
|
119
|
+
logger.info('Restart...\n');
|
|
120
|
+
let hasGetError = false;
|
|
118
121
|
|
|
119
122
|
try {
|
|
120
|
-
|
|
121
|
-
await init();
|
|
122
|
-
return true;
|
|
123
|
+
await init(process.argv.slice(2));
|
|
123
124
|
} catch (err) {
|
|
124
|
-
|
|
125
|
+
console.error(err);
|
|
126
|
+
hasGetError = true;
|
|
127
|
+
} finally {
|
|
128
|
+
if (!hasGetError) {
|
|
129
|
+
manager.run(() => program.parse(process.argv));
|
|
130
|
+
}
|
|
125
131
|
}
|
|
126
|
-
|
|
127
|
-
return false;
|
|
128
132
|
}
|
|
129
133
|
|
|
130
134
|
return {
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import crypto from 'crypto';
|
|
3
2
|
import fs from 'fs';
|
|
3
|
+
import { path, isDev, createDebugger } from '@modern-js/utils';
|
|
4
4
|
import chokidar from 'chokidar';
|
|
5
|
-
import { isDev, createDebugger } from '@modern-js/utils';
|
|
6
5
|
const debug = createDebugger('watch-files');
|
|
7
6
|
|
|
8
7
|
const md5 = data => crypto.createHash('md5').update(data).digest('hex');
|
|
9
8
|
|
|
10
9
|
const hashMap = new Map();
|
|
11
|
-
export const initWatcher = async (loaded, appDirectory,
|
|
10
|
+
export const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
|
|
12
11
|
// only add fs watcher on dev mode.
|
|
13
12
|
if (isDev() && argv[0] === 'dev') {
|
|
14
|
-
const {
|
|
15
|
-
source: {
|
|
16
|
-
configDir
|
|
17
|
-
}
|
|
18
|
-
} = resovledConfig;
|
|
19
13
|
const extraFiles = await hooksRunner.watchFiles();
|
|
20
14
|
const configPath = path.join(appDirectory, configDir);
|
|
21
15
|
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS } from '@modern-js/utils';
|
|
1
|
+
import { isDepExists, createDebugger, compatRequire, INTERNAL_PLUGINS, upath } from '@modern-js/utils';
|
|
2
2
|
const debug = createDebugger('load-plugins');
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -12,9 +12,9 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
12
12
|
let filePath = '';
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
|
-
filePath = require.resolve(name, {
|
|
15
|
+
filePath = upath.normalizeSafe(require.resolve(name, {
|
|
16
16
|
paths: [appDirectory]
|
|
17
|
-
});
|
|
17
|
+
}));
|
|
18
18
|
delete require.cache[filePath];
|
|
19
19
|
} catch (err) {
|
|
20
20
|
if (err.code === 'MODULE_NOT_FOUND') {
|
|
@@ -50,7 +50,7 @@ const defineConfig = config => config;
|
|
|
50
50
|
exports.defineConfig = defineConfig;
|
|
51
51
|
|
|
52
52
|
const loadUserConfig = async (appDirectory, filePath) => {
|
|
53
|
-
const loaded = (0, _loadConfig.loadConfig)(appDirectory, filePath);
|
|
53
|
+
const loaded = await (0, _loadConfig.loadConfig)(appDirectory, filePath);
|
|
54
54
|
const config = !loaded ? {} : await (typeof loaded.config === 'function' ? loaded.config(0) : loaded.config);
|
|
55
55
|
return {
|
|
56
56
|
config: (0, _lodash.default)({}, config || {}, (loaded === null || loaded === void 0 ? void 0 : loaded.pkgConfig) || {}),
|
|
@@ -11,21 +11,7 @@ const deploy = {
|
|
|
11
11
|
type: 'object',
|
|
12
12
|
properties: {
|
|
13
13
|
microFrontend: {
|
|
14
|
-
type: 'object'
|
|
15
|
-
dependencies: {
|
|
16
|
-
enableHtmlEntry: {
|
|
17
|
-
properties: {
|
|
18
|
-
enableLegacy: {
|
|
19
|
-
enum: [false]
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
properties: {
|
|
25
|
-
enableHtmlEntry: {
|
|
26
|
-
type: 'boolean'
|
|
27
|
-
}
|
|
28
|
-
}
|
|
14
|
+
type: ['boolean', 'object']
|
|
29
15
|
},
|
|
30
16
|
domain: {
|
|
31
17
|
type: ['array', 'string']
|
package/dist/js/node/context.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useResolvedConfigContext = exports.useConfigContext = exports.useAppContext = exports.initAppContext = exports.ResolvedConfigContext = exports.ConfigContext = exports.AppContext = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
9
|
|
|
10
10
|
var _plugin = require("@modern-js/plugin");
|
|
11
11
|
|
|
@@ -37,12 +37,12 @@ const initAppContext = (appDirectory, plugins, configFile) => ({
|
|
|
37
37
|
configFile,
|
|
38
38
|
ip: _address.default.ip(),
|
|
39
39
|
port: 0,
|
|
40
|
-
packageName: require(
|
|
41
|
-
srcDirectory:
|
|
40
|
+
packageName: require(_utils.path.resolve(appDirectory, './package.json')).name,
|
|
41
|
+
srcDirectory: _utils.path.resolve(appDirectory, './src'),
|
|
42
42
|
distDirectory: '',
|
|
43
|
-
sharedDirectory:
|
|
44
|
-
nodeModulesDirectory:
|
|
45
|
-
internalDirectory:
|
|
43
|
+
sharedDirectory: _utils.path.resolve(appDirectory, './shared'),
|
|
44
|
+
nodeModulesDirectory: _utils.path.resolve(appDirectory, './node_modules'),
|
|
45
|
+
internalDirectory: _utils.path.resolve(appDirectory, './node_modules/.modern-js'),
|
|
46
46
|
plugins,
|
|
47
47
|
htmlTemplates: {},
|
|
48
48
|
serverRoutes: [],
|
package/dist/js/node/index.js
CHANGED
|
@@ -3,20 +3,27 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
manager: true,
|
|
8
|
+
createPlugin: true,
|
|
9
|
+
registerHook: true,
|
|
10
|
+
mountHook: true,
|
|
11
|
+
usePlugins: true,
|
|
12
|
+
cli: true,
|
|
13
|
+
defineConfig: true,
|
|
14
|
+
defaultsConfig: true,
|
|
15
|
+
AppContext: true,
|
|
16
|
+
useAppContext: true,
|
|
17
|
+
useConfigContext: true,
|
|
18
|
+
useResolvedConfigContext: true
|
|
19
|
+
};
|
|
6
20
|
Object.defineProperty(exports, "AppContext", {
|
|
7
21
|
enumerable: true,
|
|
8
22
|
get: function () {
|
|
9
23
|
return _context.AppContext;
|
|
10
24
|
}
|
|
11
25
|
});
|
|
12
|
-
exports.cli = void 0;
|
|
13
|
-
Object.defineProperty(exports, "createContext", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _plugin.createContext;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
exports.createPlugin = void 0;
|
|
26
|
+
exports.createPlugin = exports.cli = void 0;
|
|
20
27
|
Object.defineProperty(exports, "defaultsConfig", {
|
|
21
28
|
enumerable: true,
|
|
22
29
|
get: function () {
|
|
@@ -50,13 +57,35 @@ Object.defineProperty(exports, "useResolvedConfigContext", {
|
|
|
50
57
|
}
|
|
51
58
|
});
|
|
52
59
|
|
|
53
|
-
var
|
|
60
|
+
var _utils = require("@modern-js/utils");
|
|
54
61
|
|
|
55
62
|
var _plugin = require("@modern-js/plugin");
|
|
56
63
|
|
|
64
|
+
Object.keys(_plugin).forEach(function (key) {
|
|
65
|
+
if (key === "default" || key === "__esModule") return;
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
67
|
+
if (key in exports && exports[key] === _plugin[key]) return;
|
|
68
|
+
Object.defineProperty(exports, key, {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () {
|
|
71
|
+
return _plugin[key];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
57
76
|
var _node = require("@modern-js/plugin/node");
|
|
58
77
|
|
|
59
|
-
|
|
78
|
+
Object.keys(_node).forEach(function (key) {
|
|
79
|
+
if (key === "default" || key === "__esModule") return;
|
|
80
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
81
|
+
if (key in exports && exports[key] === _node[key]) return;
|
|
82
|
+
Object.defineProperty(exports, key, {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function () {
|
|
85
|
+
return _node[key];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
60
89
|
|
|
61
90
|
var _commander = require("./utils/commander");
|
|
62
91
|
|
|
@@ -70,8 +99,6 @@ var _initWatcher = require("./initWatcher");
|
|
|
70
99
|
|
|
71
100
|
var _loadEnv = require("./loadEnv");
|
|
72
101
|
|
|
73
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
74
|
-
|
|
75
102
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
76
103
|
|
|
77
104
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
@@ -102,7 +129,7 @@ exports.mountHook = mountHook;
|
|
|
102
129
|
exports.registerHook = registerHook;
|
|
103
130
|
exports.createPlugin = createPlugin;
|
|
104
131
|
|
|
105
|
-
const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(require.resolve(plugin))));
|
|
132
|
+
const usePlugins = plugins => plugins.forEach(plugin => manager.usePlugin((0, _utils.compatRequire)(_utils.upath.normalize(require.resolve(plugin)))));
|
|
106
133
|
|
|
107
134
|
exports.usePlugins = usePlugins;
|
|
108
135
|
|
|
@@ -115,7 +142,7 @@ const initAppDir = async () => {
|
|
|
115
142
|
throw new Error(`no package.json found in current work dir: ${process.cwd()}`);
|
|
116
143
|
}
|
|
117
144
|
|
|
118
|
-
return
|
|
145
|
+
return _utils.path.dirname(pkg);
|
|
119
146
|
};
|
|
120
147
|
|
|
121
148
|
const createCli = () => {
|
|
@@ -123,6 +150,7 @@ const createCli = () => {
|
|
|
123
150
|
let isRestart = false;
|
|
124
151
|
|
|
125
152
|
const init = async (argv = []) => {
|
|
153
|
+
(0, _node.enable)();
|
|
126
154
|
manager.clear();
|
|
127
155
|
const appDirectory = await initAppDir();
|
|
128
156
|
(0, _loadEnv.loadEnv)(appDirectory);
|
|
@@ -173,32 +201,35 @@ const createCli = () => {
|
|
|
173
201
|
};
|
|
174
202
|
|
|
175
203
|
async function run(argv) {
|
|
176
|
-
(0, _node.enable)();
|
|
177
204
|
const {
|
|
178
205
|
loadedConfig,
|
|
179
206
|
appContext,
|
|
180
207
|
resolved
|
|
181
208
|
} = await init(argv);
|
|
182
|
-
(0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved, hooksRunner, argv);
|
|
183
209
|
await hooksRunner.commands({
|
|
184
210
|
program: _commander.program
|
|
185
211
|
});
|
|
212
|
+
(0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
186
213
|
manager.run(() => _commander.program.parse(process.argv));
|
|
187
214
|
}
|
|
188
215
|
|
|
189
216
|
async function restart() {
|
|
190
217
|
isRestart = true;
|
|
191
218
|
|
|
192
|
-
|
|
193
|
-
|
|
219
|
+
_utils.logger.info('Restart...\n');
|
|
220
|
+
|
|
221
|
+
let hasGetError = false;
|
|
194
222
|
|
|
195
|
-
|
|
196
|
-
|
|
223
|
+
try {
|
|
224
|
+
await init(process.argv.slice(2));
|
|
197
225
|
} catch (err) {
|
|
198
|
-
|
|
226
|
+
console.error(err);
|
|
227
|
+
hasGetError = true;
|
|
228
|
+
} finally {
|
|
229
|
+
if (!hasGetError) {
|
|
230
|
+
manager.run(() => _commander.program.parse(process.argv));
|
|
231
|
+
}
|
|
199
232
|
}
|
|
200
|
-
|
|
201
|
-
return false;
|
|
202
233
|
}
|
|
203
234
|
|
|
204
235
|
return {
|
|
@@ -5,16 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.initWatcher = void 0;
|
|
7
7
|
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
11
9
|
|
|
12
10
|
var _fs = _interopRequireDefault(require("fs"));
|
|
13
11
|
|
|
14
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
15
|
-
|
|
16
12
|
var _utils = require("@modern-js/utils");
|
|
17
13
|
|
|
14
|
+
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
15
|
+
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
17
|
|
|
20
18
|
const debug = (0, _utils.createDebugger)('watch-files');
|
|
@@ -23,17 +21,12 @@ const md5 = data => _crypto.default.createHash('md5').update(data).digest('hex')
|
|
|
23
21
|
|
|
24
22
|
const hashMap = new Map();
|
|
25
23
|
|
|
26
|
-
const initWatcher = async (loaded, appDirectory,
|
|
24
|
+
const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) => {
|
|
27
25
|
// only add fs watcher on dev mode.
|
|
28
26
|
if ((0, _utils.isDev)() && argv[0] === 'dev') {
|
|
29
|
-
const {
|
|
30
|
-
source: {
|
|
31
|
-
configDir
|
|
32
|
-
}
|
|
33
|
-
} = resovledConfig;
|
|
34
27
|
const extraFiles = await hooksRunner.watchFiles();
|
|
35
28
|
|
|
36
|
-
const configPath =
|
|
29
|
+
const configPath = _utils.path.join(appDirectory, configDir);
|
|
37
30
|
|
|
38
31
|
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
39
32
|
debug(`watched: %o`, watched);
|
|
@@ -46,7 +39,7 @@ const initWatcher = async (loaded, appDirectory, resovledConfig, hooksRunner, ar
|
|
|
46
39
|
|
|
47
40
|
watcher.on('change', changed => {
|
|
48
41
|
const lastHash = hashMap.get(changed);
|
|
49
|
-
const currentHash = md5(_fs.default.readFileSync(
|
|
42
|
+
const currentHash = md5(_fs.default.readFileSync(_utils.path.join(appDirectory, changed), 'utf8'));
|
|
50
43
|
|
|
51
44
|
if (currentHash !== lastHash) {
|
|
52
45
|
debug(`file change: %s`, changed);
|
package/dist/js/node/loadEnv.js
CHANGED
|
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.loadEnv = void 0;
|
|
7
7
|
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
9
|
|
|
10
|
+
var _utils = require("@modern-js/utils");
|
|
11
|
+
|
|
12
12
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
13
13
|
|
|
14
14
|
var _dotenvExpand = _interopRequireDefault(require("dotenv-expand"));
|
|
@@ -16,7 +16,7 @@ var _dotenvExpand = _interopRequireDefault(require("dotenv-expand"));
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
18
|
const loadEnv = (appDirectory, mode = process.env.NODE_ENV) => {
|
|
19
|
-
[`.env.${mode}`, '.env'].map(name =>
|
|
19
|
+
[`.env.${mode}`, '.env'].map(name => _utils.path.resolve(appDirectory, name)).filter(filePath => _fs.default.existsSync(filePath) && !_fs.default.statSync(filePath).isDirectory()).forEach(filePath => {
|
|
20
20
|
const envConfig = _dotenv.default.config({
|
|
21
21
|
path: filePath
|
|
22
22
|
});
|
|
@@ -20,9 +20,9 @@ const resolvePlugin = (appDirectory, plugin) => {
|
|
|
20
20
|
let filePath = '';
|
|
21
21
|
|
|
22
22
|
try {
|
|
23
|
-
filePath = require.resolve(name, {
|
|
23
|
+
filePath = _utils.upath.normalizeSafe(require.resolve(name, {
|
|
24
24
|
paths: [appDirectory]
|
|
25
|
-
});
|
|
25
|
+
}));
|
|
26
26
|
delete require.cache[filePath];
|
|
27
27
|
} catch (err) {
|
|
28
28
|
if (err.code === 'MODULE_NOT_FOUND') {
|
|
@@ -73,14 +73,14 @@ export interface ServerConfig {
|
|
|
73
73
|
port?: number;
|
|
74
74
|
logger?: Record<string, string>;
|
|
75
75
|
measure?: Record<string, string>;
|
|
76
|
+
enableMicroFrontendDebug?: boolean;
|
|
76
77
|
}
|
|
77
78
|
export interface DevConfig {
|
|
78
79
|
assetPrefix?: string | boolean;
|
|
80
|
+
https?: boolean;
|
|
79
81
|
}
|
|
80
82
|
export interface DeployConfig {
|
|
81
|
-
microFrontend?:
|
|
82
|
-
enableHtmlEntry?: boolean;
|
|
83
|
-
};
|
|
83
|
+
microFrontend?: boolean | Record<string, unknown>;
|
|
84
84
|
domain?: string | Array<string>;
|
|
85
85
|
domainByEntries?: Record<string, string | Array<string>>;
|
|
86
86
|
}
|
|
@@ -2,21 +2,7 @@ export declare const deploy: {
|
|
|
2
2
|
type: string;
|
|
3
3
|
properties: {
|
|
4
4
|
microFrontend: {
|
|
5
|
-
type: string;
|
|
6
|
-
dependencies: {
|
|
7
|
-
enableHtmlEntry: {
|
|
8
|
-
properties: {
|
|
9
|
-
enableLegacy: {
|
|
10
|
-
enum: boolean[];
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
properties: {
|
|
16
|
-
enableHtmlEntry: {
|
|
17
|
-
type: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
5
|
+
type: string[];
|
|
20
6
|
};
|
|
21
7
|
domain: {
|
|
22
8
|
type: string[];
|
|
@@ -388,27 +388,16 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
|
|
|
388
388
|
proxy: {
|
|
389
389
|
type: string;
|
|
390
390
|
};
|
|
391
|
+
enableMicroFrontendDebug: {
|
|
392
|
+
type: string;
|
|
393
|
+
};
|
|
391
394
|
};
|
|
392
395
|
};
|
|
393
396
|
deploy: {
|
|
394
397
|
type: string;
|
|
395
398
|
properties: {
|
|
396
399
|
microFrontend: {
|
|
397
|
-
type: string;
|
|
398
|
-
dependencies: {
|
|
399
|
-
enableHtmlEntry: {
|
|
400
|
-
properties: {
|
|
401
|
-
enableLegacy: {
|
|
402
|
-
enum: boolean[];
|
|
403
|
-
};
|
|
404
|
-
};
|
|
405
|
-
};
|
|
406
|
-
};
|
|
407
|
-
properties: {
|
|
408
|
-
enableHtmlEntry: {
|
|
409
|
-
type: string;
|
|
410
|
-
};
|
|
411
|
-
};
|
|
400
|
+
type: string[];
|
|
412
401
|
};
|
|
413
402
|
domain: {
|
|
414
403
|
type: string[];
|
|
@@ -433,6 +422,9 @@ export declare const patchSchema: (pluginSchemas: Array<PluginValidateSchema | P
|
|
|
433
422
|
assetPrefix: {
|
|
434
423
|
type: string[];
|
|
435
424
|
};
|
|
425
|
+
https: {
|
|
426
|
+
type: string;
|
|
427
|
+
};
|
|
436
428
|
};
|
|
437
429
|
additionalProperties: boolean;
|
|
438
430
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParallelWorkflow, AsyncWorkflow, Progresses2Runners } from '@modern-js/plugin';
|
|
2
2
|
import type { Hooks } from '@modern-js/types';
|
|
3
3
|
import { Command } from './utils/commander';
|
|
4
4
|
import { defineConfig, UserConfig, ToolsConfig } from './config';
|
|
@@ -6,6 +6,8 @@ import { AppContext, IAppContext, useAppContext, useConfigContext, useResolvedCo
|
|
|
6
6
|
import { NormalizedConfig } from './config/mergeConfig';
|
|
7
7
|
export type { Hooks };
|
|
8
8
|
export { defaultsConfig } from './config';
|
|
9
|
+
export * from '@modern-js/plugin';
|
|
10
|
+
export * from '@modern-js/plugin/node';
|
|
9
11
|
export declare type HooksRunner = Progresses2Runners<{
|
|
10
12
|
config: ParallelWorkflow<void>;
|
|
11
13
|
validateSchema: ParallelWorkflow<void>;
|
|
@@ -70,7 +72,7 @@ export declare const createPlugin: (initializer: import("@modern-js/plugin").Asy
|
|
|
70
72
|
beforeExit: AsyncWorkflow<void, void>;
|
|
71
73
|
} & import("@modern-js/plugin").ClearDraftProgress<Hooks>>;
|
|
72
74
|
export declare const usePlugins: (plugins: string[]) => void;
|
|
73
|
-
export { defineConfig,
|
|
75
|
+
export { defineConfig, AppContext, useAppContext, useConfigContext, useResolvedConfigContext };
|
|
74
76
|
export type { NormalizedConfig, IAppContext, UserConfig, ToolsConfig };
|
|
75
77
|
export interface CoreOption {
|
|
76
78
|
dryRun?: boolean;
|
|
@@ -82,5 +84,5 @@ export declare const cli: {
|
|
|
82
84
|
resolved: NormalizedConfig;
|
|
83
85
|
}>;
|
|
84
86
|
run: (argv: string[]) => Promise<void>;
|
|
85
|
-
restart: () => Promise<
|
|
87
|
+
restart: () => Promise<void>;
|
|
86
88
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { NormalizedConfig } from './config/mergeConfig';
|
|
2
1
|
import { LoadedConfig } from './config';
|
|
3
2
|
import { HooksRunner } from '.';
|
|
4
|
-
export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string,
|
|
3
|
+
export declare const initWatcher: (loaded: LoadedConfig, appDirectory: string, configDir: string | undefined, hooksRunner: HooksRunner, argv: string[]) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modern-js/core",
|
|
3
|
-
"
|
|
3
|
+
"description": "The meta-framework suite designed from scratch for frontend-focused modern web development.",
|
|
4
|
+
"homepage": "https://modernjs.dev",
|
|
5
|
+
"bugs": "https://github.com/modern-js-dev/modern.js/issues",
|
|
6
|
+
"repository": "modern-js-dev/modern.js",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"react",
|
|
10
|
+
"framework",
|
|
11
|
+
"modern",
|
|
12
|
+
"modern.js"
|
|
13
|
+
],
|
|
14
|
+
"version": "1.0.0",
|
|
4
15
|
"jsnext:source": "./src/index.ts",
|
|
5
16
|
"types": "./dist/types/index.d.ts",
|
|
6
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -25,11 +36,11 @@
|
|
|
25
36
|
},
|
|
26
37
|
"bin": "./bin/modern-js.js",
|
|
27
38
|
"dependencies": {
|
|
28
|
-
"@babel/runtime": "^7",
|
|
29
39
|
"@babel/code-frame": "^7.14.5",
|
|
30
|
-
"@
|
|
31
|
-
"@modern-js/
|
|
32
|
-
"@modern-js/
|
|
40
|
+
"@babel/runtime": "^7",
|
|
41
|
+
"@modern-js/load-config": "^1.0.0",
|
|
42
|
+
"@modern-js/plugin": "^1.0.0",
|
|
43
|
+
"@modern-js/utils": "^1.0.0",
|
|
33
44
|
"address": "^1.1.2",
|
|
34
45
|
"ajv": "^8.6.2",
|
|
35
46
|
"ajv-keywords": "^5.0.0",
|
|
@@ -46,7 +57,7 @@
|
|
|
46
57
|
},
|
|
47
58
|
"devDependencies": {
|
|
48
59
|
"@types/babel__code-frame": "^7.0.3",
|
|
49
|
-
"@modern-js/types": "^1.0.0
|
|
60
|
+
"@modern-js/types": "^1.0.0",
|
|
50
61
|
"@types/jest": "^26",
|
|
51
62
|
"@types/lodash.clonedeep": "^4.5.6",
|
|
52
63
|
"@types/lodash.mergewith": "^4.6.6",
|
|
@@ -55,8 +66,8 @@
|
|
|
55
66
|
"@types/react-dom": "^17",
|
|
56
67
|
"@types/signale": "^1.4.2",
|
|
57
68
|
"typescript": "^4",
|
|
58
|
-
"@modern-js/plugin-testing": "^1.0.0
|
|
59
|
-
"@modern-js/module-tools": "^1.0.0
|
|
69
|
+
"@modern-js/plugin-testing": "^1.0.0",
|
|
70
|
+
"@modern-js/module-tools": "^1.0.0"
|
|
60
71
|
},
|
|
61
72
|
"sideEffects": false,
|
|
62
73
|
"modernConfig": {
|
package/src/config/defaults.ts
CHANGED
package/src/config/index.ts
CHANGED
|
@@ -107,16 +107,16 @@ export interface ServerConfig {
|
|
|
107
107
|
port?: number;
|
|
108
108
|
logger?: Record<string, string>;
|
|
109
109
|
measure?: Record<string, string>;
|
|
110
|
+
enableMicroFrontendDebug?: boolean;
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
export interface DevConfig {
|
|
113
114
|
assetPrefix?: string | boolean;
|
|
115
|
+
https?: boolean;
|
|
114
116
|
}
|
|
115
117
|
|
|
116
118
|
export interface DeployConfig {
|
|
117
|
-
microFrontend?:
|
|
118
|
-
enableHtmlEntry?: boolean;
|
|
119
|
-
};
|
|
119
|
+
microFrontend?: boolean | Record<string, unknown>;
|
|
120
120
|
domain?: string | Array<string>;
|
|
121
121
|
domainByEntries?: Record<string, string | Array<string>>;
|
|
122
122
|
}
|
|
@@ -175,7 +175,7 @@ export const loadUserConfig = async (
|
|
|
175
175
|
appDirectory: string,
|
|
176
176
|
filePath?: string,
|
|
177
177
|
): Promise<LoadedConfig> => {
|
|
178
|
-
const loaded = loadConfig<ConfigParam>(appDirectory, filePath);
|
|
178
|
+
const loaded = await loadConfig<ConfigParam>(appDirectory, filePath);
|
|
179
179
|
|
|
180
180
|
const config = !loaded
|
|
181
181
|
? {}
|
|
@@ -4,13 +4,7 @@ export const deploy = {
|
|
|
4
4
|
type: 'object',
|
|
5
5
|
properties: {
|
|
6
6
|
microFrontend: {
|
|
7
|
-
type: 'object',
|
|
8
|
-
dependencies: {
|
|
9
|
-
enableHtmlEntry: { properties: { enableLegacy: { enum: [false] } } },
|
|
10
|
-
},
|
|
11
|
-
properties: {
|
|
12
|
-
enableHtmlEntry: { type: 'boolean' },
|
|
13
|
-
},
|
|
7
|
+
type: ['boolean', 'object'],
|
|
14
8
|
},
|
|
15
9
|
domain: { type: ['array', 'string'] },
|
|
16
10
|
domainByEntries: {
|
|
@@ -16,7 +16,12 @@ const plugins = {
|
|
|
16
16
|
|
|
17
17
|
const dev = {
|
|
18
18
|
type: 'object',
|
|
19
|
-
properties: {
|
|
19
|
+
properties: {
|
|
20
|
+
assetPrefix: { type: ['boolean', 'string'] },
|
|
21
|
+
https: {
|
|
22
|
+
type: 'boolean',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
20
25
|
additionalProperties: false,
|
|
21
26
|
};
|
|
22
27
|
export interface PluginValidateSchema {
|
package/src/context.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
path,
|
|
3
|
+
upath,
|
|
4
|
+
compatRequire,
|
|
5
|
+
pkgUp,
|
|
6
|
+
ensureAbsolutePath,
|
|
7
|
+
logger,
|
|
8
|
+
} from '@modern-js/utils';
|
|
2
9
|
import {
|
|
3
10
|
createAsyncManager,
|
|
4
|
-
createContext,
|
|
5
11
|
createAsyncWorkflow,
|
|
6
12
|
createParallelWorkflow,
|
|
7
13
|
ParallelWorkflow,
|
|
@@ -9,12 +15,7 @@ import {
|
|
|
9
15
|
Progresses2Runners,
|
|
10
16
|
} from '@modern-js/plugin';
|
|
11
17
|
import { enable } from '@modern-js/plugin/node';
|
|
12
|
-
|
|
13
|
-
compatRequire,
|
|
14
|
-
pkgUp,
|
|
15
|
-
ensureAbsolutePath,
|
|
16
|
-
logger,
|
|
17
|
-
} from '@modern-js/utils';
|
|
18
|
+
|
|
18
19
|
import type { Hooks } from '@modern-js/types';
|
|
19
20
|
import { program, Command } from './utils/commander';
|
|
20
21
|
import {
|
|
@@ -42,6 +43,9 @@ import { loadEnv } from './loadEnv';
|
|
|
42
43
|
export type { Hooks };
|
|
43
44
|
export { defaultsConfig } from './config';
|
|
44
45
|
|
|
46
|
+
export * from '@modern-js/plugin';
|
|
47
|
+
export * from '@modern-js/plugin/node';
|
|
48
|
+
|
|
45
49
|
program
|
|
46
50
|
.name('modern')
|
|
47
51
|
.usage('<command> [options]')
|
|
@@ -101,12 +105,11 @@ export const {
|
|
|
101
105
|
|
|
102
106
|
export const usePlugins = (plugins: string[]) =>
|
|
103
107
|
plugins.forEach(plugin =>
|
|
104
|
-
manager.usePlugin(compatRequire(require.resolve(plugin))),
|
|
108
|
+
manager.usePlugin(compatRequire(upath.normalize(require.resolve(plugin)))),
|
|
105
109
|
);
|
|
106
110
|
|
|
107
111
|
export {
|
|
108
112
|
defineConfig,
|
|
109
|
-
createContext,
|
|
110
113
|
AppContext,
|
|
111
114
|
useAppContext,
|
|
112
115
|
useConfigContext,
|
|
@@ -136,6 +139,8 @@ const createCli = () => {
|
|
|
136
139
|
let isRestart = false;
|
|
137
140
|
|
|
138
141
|
const init = async (argv: string[] = []) => {
|
|
142
|
+
enable();
|
|
143
|
+
|
|
139
144
|
manager.clear();
|
|
140
145
|
|
|
141
146
|
const appDirectory = await initAppDir();
|
|
@@ -201,33 +206,36 @@ const createCli = () => {
|
|
|
201
206
|
};
|
|
202
207
|
|
|
203
208
|
async function run(argv: string[]) {
|
|
204
|
-
enable();
|
|
205
|
-
|
|
206
209
|
const { loadedConfig, appContext, resolved } = await init(argv);
|
|
207
210
|
|
|
211
|
+
await hooksRunner.commands({ program });
|
|
212
|
+
|
|
208
213
|
initWatcher(
|
|
209
214
|
loadedConfig,
|
|
210
215
|
appContext.appDirectory,
|
|
211
|
-
resolved,
|
|
216
|
+
resolved.source.configDir,
|
|
212
217
|
hooksRunner,
|
|
213
218
|
argv,
|
|
214
219
|
);
|
|
215
|
-
|
|
216
|
-
await hooksRunner.commands({ program });
|
|
217
|
-
|
|
218
220
|
manager.run(() => program.parse(process.argv));
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
async function restart() {
|
|
222
224
|
isRestart = true;
|
|
225
|
+
|
|
226
|
+
logger.info('Restart...\n');
|
|
227
|
+
|
|
228
|
+
let hasGetError = false
|
|
223
229
|
try {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
230
|
+
await init(process.argv.slice(2));
|
|
231
|
+
} catch(err) {
|
|
232
|
+
console.error(err)
|
|
233
|
+
hasGetError = true
|
|
234
|
+
} finally {
|
|
235
|
+
if (!hasGetError) {
|
|
236
|
+
manager.run(() => program.parse(process.argv));
|
|
237
|
+
}
|
|
229
238
|
}
|
|
230
|
-
return false;
|
|
231
239
|
}
|
|
232
240
|
|
|
233
241
|
return {
|
package/src/initWatcher.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import crypto from 'crypto';
|
|
3
2
|
import fs from 'fs';
|
|
3
|
+
import { path, isDev, createDebugger } from '@modern-js/utils';
|
|
4
4
|
import chokidar from 'chokidar';
|
|
5
|
-
import { isDev, createDebugger } from '@modern-js/utils';
|
|
6
5
|
import { NormalizedConfig } from './config/mergeConfig';
|
|
7
6
|
import { LoadedConfig } from './config';
|
|
8
7
|
import { HooksRunner } from '.';
|
|
@@ -17,15 +16,12 @@ const hashMap = new Map<string, string>();
|
|
|
17
16
|
export const initWatcher = async (
|
|
18
17
|
loaded: LoadedConfig,
|
|
19
18
|
appDirectory: string,
|
|
20
|
-
|
|
19
|
+
configDir: string | undefined,
|
|
21
20
|
hooksRunner: HooksRunner,
|
|
22
21
|
argv: string[],
|
|
23
22
|
) => {
|
|
24
23
|
// only add fs watcher on dev mode.
|
|
25
24
|
if (isDev() && argv[0] === 'dev') {
|
|
26
|
-
const {
|
|
27
|
-
source: { configDir },
|
|
28
|
-
} = resovledConfig;
|
|
29
25
|
|
|
30
26
|
const extraFiles = await hooksRunner.watchFiles();
|
|
31
27
|
|
package/src/loadEnv.ts
CHANGED
package/src/loadPlugins.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
createDebugger,
|
|
4
4
|
compatRequire,
|
|
5
5
|
INTERNAL_PLUGINS,
|
|
6
|
+
upath
|
|
6
7
|
} from '@modern-js/utils';
|
|
7
8
|
|
|
8
9
|
const debug = createDebugger('load-plugins');
|
|
@@ -24,7 +25,7 @@ const resolvePlugin = (appDirectory: string, plugin: PluginConfigItem) => {
|
|
|
24
25
|
const tryResolve = (name: string) => {
|
|
25
26
|
let filePath = '';
|
|
26
27
|
try {
|
|
27
|
-
filePath = require.resolve(name, { paths: [appDirectory] });
|
|
28
|
+
filePath = upath.normalizeSafe(require.resolve(name, { paths: [appDirectory] }));
|
|
28
29
|
delete require.cache[filePath];
|
|
29
30
|
} catch (err) {
|
|
30
31
|
if ((err as any).code === 'MODULE_NOT_FOUND') {
|
package/tests/loadEnv.test.ts
CHANGED
package/tests/loadPlugin.test.ts
CHANGED