@modern-js/utils 1.2.2 → 1.3.2
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 +30 -0
- package/dist/js/modern/clearConsole.js +1 -1
- package/dist/js/modern/compatRequire.js +5 -0
- package/dist/js/modern/constants.js +18 -23
- package/dist/js/modern/{formatWebpackMessages.js → format.js} +35 -1
- package/dist/js/modern/index.js +3 -2
- package/dist/js/modern/prettyInstructions.js +15 -5
- package/dist/js/modern/wait.js +5 -0
- package/dist/js/node/clearConsole.js +1 -1
- package/dist/js/node/compatRequire.js +10 -2
- package/dist/js/node/constants.js +20 -28
- package/dist/js/node/{formatWebpackMessages.js → format.js} +34 -1
- package/dist/js/node/index.js +18 -4
- package/dist/js/node/prettyInstructions.js +15 -5
- package/dist/js/node/wait.js +12 -0
- package/dist/js/treeshaking/clearConsole.js +1 -1
- package/dist/js/treeshaking/compatRequire.js +5 -0
- package/dist/js/treeshaking/constants.js +18 -23
- package/dist/js/treeshaking/{formatWebpackMessages.js → format.js} +43 -1
- package/dist/js/treeshaking/index.js +3 -2
- package/dist/js/treeshaking/prettyInstructions.js +17 -6
- package/dist/js/treeshaking/wait.js +8 -0
- package/dist/types/compatRequire.d.ts +2 -1
- package/dist/types/constants.d.ts +14 -16
- package/dist/types/{formatWebpackMessages.d.ts → format.d.ts} +4 -1
- package/dist/types/index.d.ts +3 -2
- package/dist/types/wait.d.ts +2 -0
- package/package.json +9 -9
- package/tests/__snapshots__/prettyInstructions.test.ts.snap +19 -0
- package/tests/compatRequire.test.ts +11 -1
- package/tests/fixtures/compat-require/foo.js +3 -0
- package/tests/format.test.ts +60 -0
- package/tests/generateMetaTags.test.ts +19 -0
- package/tests/prettyInstructions.test.ts +139 -0
- package/tests/wait.ts +38 -0
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
# @modern-js/utils
|
2
2
|
|
3
|
+
## 1.3.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- deeaa602: support svg/proxy/multi-version in unbundled
|
8
|
+
|
9
|
+
## 1.3.1
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- 78279953: compiler entry bug fix and dev build console
|
14
|
+
- 4d72edea: support dev compiler by entry
|
15
|
+
|
16
|
+
## 1.3.0
|
17
|
+
|
18
|
+
### Minor Changes
|
19
|
+
|
20
|
+
- ec4dbffb: feat: support as a pure api service
|
21
|
+
- bada2879: refactor plugin-garfish:
|
22
|
+
- change @modern-js/plugin-micro-frontend => @modern-js/plugin-garfish
|
23
|
+
- remove disableCustomerRouter logic
|
24
|
+
- adding unit test
|
25
|
+
- fix plugin-garfish type error
|
26
|
+
|
27
|
+
### Patch Changes
|
28
|
+
|
29
|
+
- d099e5c5: fix error when modify modern.config.js
|
30
|
+
- 24f616ca: feat: support custom meta info
|
31
|
+
- bd819a8d: feat: add wait function
|
32
|
+
|
3
33
|
## 1.2.2
|
4
34
|
|
5
35
|
### Patch Changes
|
@@ -1,16 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* alias to src directory
|
3
|
-
*/
|
4
|
-
export const INTERNAL_SRC_ALIAS = '@_modern_js_src';
|
5
|
-
/**
|
6
|
-
* alias to node_modules/.modern-js
|
7
|
-
*/
|
8
|
-
|
9
|
-
export const INTERNAL_DIR_ALAIS = '@_modern_js_internal';
|
10
1
|
/**
|
11
2
|
* hmr socket connect path
|
12
3
|
*/
|
13
|
-
|
14
4
|
export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
15
5
|
/**
|
16
6
|
* route specification file
|
@@ -47,11 +37,6 @@ export const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
47
37
|
*/
|
48
38
|
|
49
39
|
export const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
50
|
-
/**
|
51
|
-
* real entry generate by modern.js
|
52
|
-
*/
|
53
|
-
|
54
|
-
export const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
55
40
|
/**
|
56
41
|
* internal specified folder
|
57
42
|
*/
|
@@ -133,8 +118,8 @@ export const INTERNAL_PLUGINS = {
|
|
133
118
|
cli: '@modern-js/plugin-server/cli',
|
134
119
|
server: '@modern-js/plugin-server/server'
|
135
120
|
},
|
136
|
-
'@modern-js/plugin-
|
137
|
-
cli: '@modern-js/plugin-
|
121
|
+
'@modern-js/plugin-garfish': {
|
122
|
+
cli: '@modern-js/plugin-garfish/cli'
|
138
123
|
},
|
139
124
|
'@modern-js/plugin-jarvis': {
|
140
125
|
cli: '@modern-js/plugin-jarvis/cli'
|
@@ -166,6 +151,9 @@ export const INTERNAL_PLUGINS = {
|
|
166
151
|
},
|
167
152
|
'@modern-js/plugin-nocode': {
|
168
153
|
cli: '@modern-js/plugin-nocode/cli'
|
154
|
+
},
|
155
|
+
'@modern-js/plugin-design-token': {
|
156
|
+
cli: '@modern-js/plugin-design-token/cli'
|
169
157
|
}
|
170
158
|
};
|
171
159
|
/**
|
@@ -237,11 +225,6 @@ export const PLUGIN_SCHEMAS = {
|
|
237
225
|
schema: {
|
238
226
|
typeof: ['object', 'function']
|
239
227
|
}
|
240
|
-
}, {
|
241
|
-
target: 'source.designSystem',
|
242
|
-
schema: {
|
243
|
-
typeof: ['object']
|
244
|
-
}
|
245
228
|
}],
|
246
229
|
'@modern-js/plugin-proxy': [{
|
247
230
|
target: 'dev.proxy',
|
@@ -284,6 +267,18 @@ export const PLUGIN_SCHEMAS = {
|
|
284
267
|
type: ['boolean', 'object']
|
285
268
|
}
|
286
269
|
}],
|
270
|
+
'@modern-js/plugin-design-token': [// Legacy Features
|
271
|
+
{
|
272
|
+
target: 'source.designSystem',
|
273
|
+
schema: {
|
274
|
+
typeof: ['object']
|
275
|
+
}
|
276
|
+
}, {
|
277
|
+
target: 'source.designSystem.supportStyledComponents',
|
278
|
+
schema: {
|
279
|
+
type: ['boolean']
|
280
|
+
}
|
281
|
+
}],
|
287
282
|
'@modern-js/plugin-router': [{
|
288
283
|
target: 'runtime.router',
|
289
284
|
schema: {
|
@@ -301,7 +296,7 @@ export const PLUGIN_SCHEMAS = {
|
|
301
296
|
typeof: ['object', 'function']
|
302
297
|
}
|
303
298
|
}],
|
304
|
-
'@modern-js/plugin-
|
299
|
+
'@modern-js/plugin-garfish': [{
|
305
300
|
target: 'runtime.masterApp',
|
306
301
|
schema: {
|
307
302
|
type: ['object']
|
@@ -1,3 +1,9 @@
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
2
|
+
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
4
|
+
|
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
|
+
|
1
7
|
/* eslint-disable no-param-reassign */
|
2
8
|
|
3
9
|
/* eslint-disable max-statements */
|
@@ -100,4 +106,32 @@ function formatWebpackMessages(json) {
|
|
100
106
|
export { formatWebpackMessages };
|
101
107
|
/* eslint-enable max-statements */
|
102
108
|
|
103
|
-
/* eslint-enable no-param-reassign */
|
109
|
+
/* eslint-enable no-param-reassign */
|
110
|
+
|
111
|
+
function formatProxyOptions(proxyOptions) {
|
112
|
+
const formatedProxy = [];
|
113
|
+
|
114
|
+
if (!Array.isArray(proxyOptions)) {
|
115
|
+
if ('target' in proxyOptions) {
|
116
|
+
formatedProxy.push(proxyOptions);
|
117
|
+
} else {
|
118
|
+
Array.prototype.push.apply(formatedProxy, Object.keys(proxyOptions).reduce((total, source) => {
|
119
|
+
const option = proxyOptions[source];
|
120
|
+
total.push(_objectSpread({
|
121
|
+
context: source,
|
122
|
+
changeOrigin: true,
|
123
|
+
logLevel: 'warn'
|
124
|
+
}, typeof option === 'string' ? {
|
125
|
+
target: option
|
126
|
+
} : option));
|
127
|
+
return total;
|
128
|
+
}, []));
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
formatedProxy.push(...proxyOptions);
|
132
|
+
}
|
133
|
+
|
134
|
+
return formatedProxy;
|
135
|
+
}
|
136
|
+
|
137
|
+
export { formatProxyOptions };
|
package/dist/js/modern/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as _fs from 'fs-extra';
|
2
2
|
export { _fs as fs };
|
3
3
|
export * from "./chalk";
|
4
|
-
export * from "./
|
4
|
+
export * from "./format";
|
5
5
|
export * from "./FileSizeReporter";
|
6
6
|
export * from "./printBuildError";
|
7
7
|
export * from "./debug";
|
@@ -29,4 +29,5 @@ export * from "./prettyInstructions";
|
|
29
29
|
export * from "./alias";
|
30
30
|
export * from "./import";
|
31
31
|
export * from "./watch";
|
32
|
-
export * from "./nodeEnv";
|
32
|
+
export * from "./nodeEnv";
|
33
|
+
export * from "./wait";
|
@@ -38,13 +38,15 @@ export const prettyInstructions = (appContext, config) => {
|
|
38
38
|
const {
|
39
39
|
entrypoints,
|
40
40
|
serverRoutes,
|
41
|
-
port
|
41
|
+
port,
|
42
|
+
existSrc,
|
43
|
+
checkedEntries
|
42
44
|
} = appContext;
|
43
45
|
const urls = getAddressUrls(config.dev.https && isDev() ? 'https' : 'http', port);
|
44
|
-
const routes = serverRoutes.filter(route => route.entryName);
|
46
|
+
const routes = existSrc ? serverRoutes.filter(route => route.entryName) : serverRoutes;
|
45
47
|
let message = 'App running at:\n\n';
|
46
48
|
|
47
|
-
if (isSingleEntry(entrypoints)) {
|
49
|
+
if (isSingleEntry(entrypoints) || !existSrc) {
|
48
50
|
message += urls.map(({
|
49
51
|
type,
|
50
52
|
url
|
@@ -58,11 +60,19 @@ export const prettyInstructions = (appContext, config) => {
|
|
58
60
|
message += ` ${chalk.bold(`> ${type}`)}\n`;
|
59
61
|
routes.forEach(({
|
60
62
|
entryName,
|
61
|
-
urlPath
|
63
|
+
urlPath,
|
64
|
+
isSSR
|
62
65
|
}) => {
|
63
|
-
|
66
|
+
if (!checkedEntries.includes(entryName)) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
|
70
|
+
message += ` ${chalk.yellowBright(isSSR ? 'λ' : '○')} ${chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
|
64
71
|
});
|
65
72
|
});
|
73
|
+
message += '\n';
|
74
|
+
message += chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
|
75
|
+
message += chalk.cyanBright(' ○ (Static) client-side rendered as static HTML\n');
|
66
76
|
}
|
67
77
|
|
68
78
|
return message;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.requireExistModule = exports.compatRequire = void 0;
|
6
|
+
exports.requireExistModule = exports.compatRequire = exports.cleanRequireCache = void 0;
|
7
7
|
|
8
8
|
var _findExists = require("./findExists");
|
9
9
|
|
@@ -30,4 +30,12 @@ const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
|
|
30
30
|
return compatRequire(exist);
|
31
31
|
};
|
32
32
|
|
33
|
-
exports.requireExistModule = requireExistModule;
|
33
|
+
exports.requireExistModule = requireExistModule;
|
34
|
+
|
35
|
+
const cleanRequireCache = filelist => {
|
36
|
+
filelist.forEach(filepath => {
|
37
|
+
delete require.cache[filepath];
|
38
|
+
});
|
39
|
+
};
|
40
|
+
|
41
|
+
exports.cleanRequireCache = cleanRequireCache;
|
@@ -3,23 +3,11 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.
|
6
|
+
exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_PLUGINS = exports.HMR_SOCK_PATH = exports.ENTRY_NAME_PATTERN = exports.API_DIR = void 0;
|
7
7
|
|
8
|
-
/**
|
9
|
-
* alias to src directory
|
10
|
-
*/
|
11
|
-
const INTERNAL_SRC_ALIAS = '@_modern_js_src';
|
12
|
-
/**
|
13
|
-
* alias to node_modules/.modern-js
|
14
|
-
*/
|
15
|
-
|
16
|
-
exports.INTERNAL_SRC_ALIAS = INTERNAL_SRC_ALIAS;
|
17
|
-
const INTERNAL_DIR_ALAIS = '@_modern_js_internal';
|
18
8
|
/**
|
19
9
|
* hmr socket connect path
|
20
10
|
*/
|
21
|
-
|
22
|
-
exports.INTERNAL_DIR_ALAIS = INTERNAL_DIR_ALAIS;
|
23
11
|
const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
24
12
|
/**
|
25
13
|
* route specification file
|
@@ -63,17 +51,11 @@ const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
63
51
|
|
64
52
|
exports.SERVER_RENDER_FUNCTION_NAME = SERVER_RENDER_FUNCTION_NAME;
|
65
53
|
const LOADABLE_STATS_FILE = 'loadable-stats.json';
|
66
|
-
/**
|
67
|
-
* real entry generate by modern.js
|
68
|
-
*/
|
69
|
-
|
70
|
-
exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
|
71
|
-
const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
72
54
|
/**
|
73
55
|
* internal specified folder
|
74
56
|
*/
|
75
57
|
|
76
|
-
exports.
|
58
|
+
exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
|
77
59
|
const API_DIR = 'api';
|
78
60
|
exports.API_DIR = API_DIR;
|
79
61
|
const SERVER_DIR = 'server';
|
@@ -154,8 +136,8 @@ const INTERNAL_PLUGINS = {
|
|
154
136
|
cli: '@modern-js/plugin-server/cli',
|
155
137
|
server: '@modern-js/plugin-server/server'
|
156
138
|
},
|
157
|
-
'@modern-js/plugin-
|
158
|
-
cli: '@modern-js/plugin-
|
139
|
+
'@modern-js/plugin-garfish': {
|
140
|
+
cli: '@modern-js/plugin-garfish/cli'
|
159
141
|
},
|
160
142
|
'@modern-js/plugin-jarvis': {
|
161
143
|
cli: '@modern-js/plugin-jarvis/cli'
|
@@ -187,6 +169,9 @@ const INTERNAL_PLUGINS = {
|
|
187
169
|
},
|
188
170
|
'@modern-js/plugin-nocode': {
|
189
171
|
cli: '@modern-js/plugin-nocode/cli'
|
172
|
+
},
|
173
|
+
'@modern-js/plugin-design-token': {
|
174
|
+
cli: '@modern-js/plugin-design-token/cli'
|
190
175
|
}
|
191
176
|
};
|
192
177
|
/**
|
@@ -259,11 +244,6 @@ const PLUGIN_SCHEMAS = {
|
|
259
244
|
schema: {
|
260
245
|
typeof: ['object', 'function']
|
261
246
|
}
|
262
|
-
}, {
|
263
|
-
target: 'source.designSystem',
|
264
|
-
schema: {
|
265
|
-
typeof: ['object']
|
266
|
-
}
|
267
247
|
}],
|
268
248
|
'@modern-js/plugin-proxy': [{
|
269
249
|
target: 'dev.proxy',
|
@@ -306,6 +286,18 @@ const PLUGIN_SCHEMAS = {
|
|
306
286
|
type: ['boolean', 'object']
|
307
287
|
}
|
308
288
|
}],
|
289
|
+
'@modern-js/plugin-design-token': [// Legacy Features
|
290
|
+
{
|
291
|
+
target: 'source.designSystem',
|
292
|
+
schema: {
|
293
|
+
typeof: ['object']
|
294
|
+
}
|
295
|
+
}, {
|
296
|
+
target: 'source.designSystem.supportStyledComponents',
|
297
|
+
schema: {
|
298
|
+
type: ['boolean']
|
299
|
+
}
|
300
|
+
}],
|
309
301
|
'@modern-js/plugin-router': [{
|
310
302
|
target: 'runtime.router',
|
311
303
|
schema: {
|
@@ -323,7 +315,7 @@ const PLUGIN_SCHEMAS = {
|
|
323
315
|
typeof: ['object', 'function']
|
324
316
|
}
|
325
317
|
}],
|
326
|
-
'@modern-js/plugin-
|
318
|
+
'@modern-js/plugin-garfish': [{
|
327
319
|
target: 'runtime.masterApp',
|
328
320
|
schema: {
|
329
321
|
type: ['object']
|
@@ -3,8 +3,15 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.formatProxyOptions = formatProxyOptions;
|
6
7
|
exports.formatWebpackMessages = formatWebpackMessages;
|
7
8
|
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
10
|
+
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
|
+
|
13
|
+
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; }
|
14
|
+
|
8
15
|
/* eslint-disable no-param-reassign */
|
9
16
|
|
10
17
|
/* eslint-disable max-statements */
|
@@ -103,6 +110,32 @@ function formatWebpackMessages(json) {
|
|
103
110
|
|
104
111
|
return result;
|
105
112
|
}
|
113
|
+
|
106
114
|
/* eslint-enable max-statements */
|
107
115
|
|
108
|
-
/* eslint-enable no-param-reassign */
|
116
|
+
/* eslint-enable no-param-reassign */
|
117
|
+
function formatProxyOptions(proxyOptions) {
|
118
|
+
const formatedProxy = [];
|
119
|
+
|
120
|
+
if (!Array.isArray(proxyOptions)) {
|
121
|
+
if ('target' in proxyOptions) {
|
122
|
+
formatedProxy.push(proxyOptions);
|
123
|
+
} else {
|
124
|
+
Array.prototype.push.apply(formatedProxy, Object.keys(proxyOptions).reduce((total, source) => {
|
125
|
+
const option = proxyOptions[source];
|
126
|
+
total.push(_objectSpread({
|
127
|
+
context: source,
|
128
|
+
changeOrigin: true,
|
129
|
+
logLevel: 'warn'
|
130
|
+
}, typeof option === 'string' ? {
|
131
|
+
target: option
|
132
|
+
} : option));
|
133
|
+
return total;
|
134
|
+
}, []));
|
135
|
+
}
|
136
|
+
} else {
|
137
|
+
formatedProxy.push(...proxyOptions);
|
138
|
+
}
|
139
|
+
|
140
|
+
return formatedProxy;
|
141
|
+
}
|
package/dist/js/node/index.js
CHANGED
@@ -26,16 +26,16 @@ Object.keys(_chalk).forEach(function (key) {
|
|
26
26
|
});
|
27
27
|
});
|
28
28
|
|
29
|
-
var
|
29
|
+
var _format = require("./format");
|
30
30
|
|
31
|
-
Object.keys(
|
31
|
+
Object.keys(_format).forEach(function (key) {
|
32
32
|
if (key === "default" || key === "__esModule") return;
|
33
33
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
34
|
-
if (key in exports && exports[key] ===
|
34
|
+
if (key in exports && exports[key] === _format[key]) return;
|
35
35
|
Object.defineProperty(exports, key, {
|
36
36
|
enumerable: true,
|
37
37
|
get: function () {
|
38
|
-
return
|
38
|
+
return _format[key];
|
39
39
|
}
|
40
40
|
});
|
41
41
|
});
|
@@ -432,6 +432,20 @@ Object.keys(_nodeEnv).forEach(function (key) {
|
|
432
432
|
});
|
433
433
|
});
|
434
434
|
|
435
|
+
var _wait = require("./wait");
|
436
|
+
|
437
|
+
Object.keys(_wait).forEach(function (key) {
|
438
|
+
if (key === "default" || key === "__esModule") return;
|
439
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
440
|
+
if (key in exports && exports[key] === _wait[key]) return;
|
441
|
+
Object.defineProperty(exports, key, {
|
442
|
+
enumerable: true,
|
443
|
+
get: function () {
|
444
|
+
return _wait[key];
|
445
|
+
}
|
446
|
+
});
|
447
|
+
});
|
448
|
+
|
435
449
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
436
450
|
|
437
451
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
@@ -52,13 +52,15 @@ const prettyInstructions = (appContext, config) => {
|
|
52
52
|
const {
|
53
53
|
entrypoints,
|
54
54
|
serverRoutes,
|
55
|
-
port
|
55
|
+
port,
|
56
|
+
existSrc,
|
57
|
+
checkedEntries
|
56
58
|
} = appContext;
|
57
59
|
const urls = getAddressUrls(config.dev.https && (0, _is.isDev)() ? 'https' : 'http', port);
|
58
|
-
const routes = serverRoutes.filter(route => route.entryName);
|
60
|
+
const routes = existSrc ? serverRoutes.filter(route => route.entryName) : serverRoutes;
|
59
61
|
let message = 'App running at:\n\n';
|
60
62
|
|
61
|
-
if (isSingleEntry(entrypoints)) {
|
63
|
+
if (isSingleEntry(entrypoints) || !existSrc) {
|
62
64
|
message += urls.map(({
|
63
65
|
type,
|
64
66
|
url
|
@@ -72,11 +74,19 @@ const prettyInstructions = (appContext, config) => {
|
|
72
74
|
message += ` ${_chalk.default.bold(`> ${type}`)}\n`;
|
73
75
|
routes.forEach(({
|
74
76
|
entryName,
|
75
|
-
urlPath
|
77
|
+
urlPath,
|
78
|
+
isSSR
|
76
79
|
}) => {
|
77
|
-
|
80
|
+
if (!checkedEntries.includes(entryName)) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
|
84
|
+
message += ` ${_chalk.default.yellowBright(isSSR ? 'λ' : '○')} ${_chalk.default.yellowBright(entryName.padEnd(maxNameLength + 8))}${_chalk.default.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
|
78
85
|
});
|
79
86
|
});
|
87
|
+
message += '\n';
|
88
|
+
message += _chalk.default.cyanBright(' λ (Server) server-side renders at runtime\n');
|
89
|
+
message += _chalk.default.cyanBright(' ○ (Static) client-side rendered as static HTML\n');
|
80
90
|
}
|
81
91
|
|
82
92
|
return message;
|
@@ -21,4 +21,9 @@ export var requireExistModule = function requireExistModule(filename) {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
return compatRequire(exist);
|
24
|
+
};
|
25
|
+
export var cleanRequireCache = function cleanRequireCache(filelist) {
|
26
|
+
filelist.forEach(function (filepath) {
|
27
|
+
delete require.cache[filepath];
|
28
|
+
});
|
24
29
|
};
|
@@ -1,18 +1,8 @@
|
|
1
1
|
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; }
|
2
2
|
|
3
|
-
/**
|
4
|
-
* alias to src directory
|
5
|
-
*/
|
6
|
-
export var INTERNAL_SRC_ALIAS = '@_modern_js_src';
|
7
|
-
/**
|
8
|
-
* alias to node_modules/.modern-js
|
9
|
-
*/
|
10
|
-
|
11
|
-
export var INTERNAL_DIR_ALAIS = '@_modern_js_internal';
|
12
3
|
/**
|
13
4
|
* hmr socket connect path
|
14
5
|
*/
|
15
|
-
|
16
6
|
export var HMR_SOCK_PATH = '/_modern_js_hmr_ws';
|
17
7
|
/**
|
18
8
|
* route specification file
|
@@ -49,11 +39,6 @@ export var SERVER_RENDER_FUNCTION_NAME = 'serverRender';
|
|
49
39
|
*/
|
50
40
|
|
51
41
|
export var LOADABLE_STATS_FILE = 'loadable-stats.json';
|
52
|
-
/**
|
53
|
-
* real entry generate by modern.js
|
54
|
-
*/
|
55
|
-
|
56
|
-
export var HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
|
57
42
|
/**
|
58
43
|
* internal specified folder
|
59
44
|
*/
|
@@ -135,8 +120,8 @@ export var INTERNAL_PLUGINS = {
|
|
135
120
|
cli: '@modern-js/plugin-server/cli',
|
136
121
|
server: '@modern-js/plugin-server/server'
|
137
122
|
},
|
138
|
-
'@modern-js/plugin-
|
139
|
-
cli: '@modern-js/plugin-
|
123
|
+
'@modern-js/plugin-garfish': {
|
124
|
+
cli: '@modern-js/plugin-garfish/cli'
|
140
125
|
},
|
141
126
|
'@modern-js/plugin-jarvis': {
|
142
127
|
cli: '@modern-js/plugin-jarvis/cli'
|
@@ -168,6 +153,9 @@ export var INTERNAL_PLUGINS = {
|
|
168
153
|
},
|
169
154
|
'@modern-js/plugin-nocode': {
|
170
155
|
cli: '@modern-js/plugin-nocode/cli'
|
156
|
+
},
|
157
|
+
'@modern-js/plugin-design-token': {
|
158
|
+
cli: '@modern-js/plugin-design-token/cli'
|
171
159
|
}
|
172
160
|
};
|
173
161
|
/**
|
@@ -237,11 +225,6 @@ export var PLUGIN_SCHEMAS = {
|
|
237
225
|
schema: {
|
238
226
|
"typeof": ['object', 'function']
|
239
227
|
}
|
240
|
-
}, {
|
241
|
-
target: 'source.designSystem',
|
242
|
-
schema: {
|
243
|
-
"typeof": ['object']
|
244
|
-
}
|
245
228
|
}],
|
246
229
|
'@modern-js/plugin-proxy': [{
|
247
230
|
target: 'dev.proxy',
|
@@ -284,6 +267,18 @@ export var PLUGIN_SCHEMAS = {
|
|
284
267
|
type: ['boolean', 'object']
|
285
268
|
}
|
286
269
|
}],
|
270
|
+
'@modern-js/plugin-design-token': [// Legacy Features
|
271
|
+
{
|
272
|
+
target: 'source.designSystem',
|
273
|
+
schema: {
|
274
|
+
"typeof": ['object']
|
275
|
+
}
|
276
|
+
}, {
|
277
|
+
target: 'source.designSystem.supportStyledComponents',
|
278
|
+
schema: {
|
279
|
+
type: ['boolean']
|
280
|
+
}
|
281
|
+
}],
|
287
282
|
'@modern-js/plugin-router': [{
|
288
283
|
target: 'runtime.router',
|
289
284
|
schema: {
|
@@ -301,7 +296,7 @@ export var PLUGIN_SCHEMAS = {
|
|
301
296
|
"typeof": ['object', 'function']
|
302
297
|
}
|
303
298
|
}],
|
304
|
-
'@modern-js/plugin-
|
299
|
+
'@modern-js/plugin-garfish': [{
|
305
300
|
target: 'runtime.masterApp',
|
306
301
|
schema: {
|
307
302
|
type: ['object']
|
@@ -1,3 +1,17 @@
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
2
|
+
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
4
|
+
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
6
|
+
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
8
|
+
|
9
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
10
|
+
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
12
|
+
|
13
|
+
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; }
|
14
|
+
|
1
15
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2
16
|
|
3
17
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
@@ -122,4 +136,32 @@ function formatWebpackMessages(json) {
|
|
122
136
|
export { formatWebpackMessages };
|
123
137
|
/* eslint-enable max-statements */
|
124
138
|
|
125
|
-
/* eslint-enable no-param-reassign */
|
139
|
+
/* eslint-enable no-param-reassign */
|
140
|
+
|
141
|
+
function formatProxyOptions(proxyOptions) {
|
142
|
+
var formatedProxy = [];
|
143
|
+
|
144
|
+
if (!Array.isArray(proxyOptions)) {
|
145
|
+
if ('target' in proxyOptions) {
|
146
|
+
formatedProxy.push(proxyOptions);
|
147
|
+
} else {
|
148
|
+
Array.prototype.push.apply(formatedProxy, Object.keys(proxyOptions).reduce(function (total, source) {
|
149
|
+
var option = proxyOptions[source];
|
150
|
+
total.push(_objectSpread({
|
151
|
+
context: source,
|
152
|
+
changeOrigin: true,
|
153
|
+
logLevel: 'warn'
|
154
|
+
}, typeof option === 'string' ? {
|
155
|
+
target: option
|
156
|
+
} : option));
|
157
|
+
return total;
|
158
|
+
}, []));
|
159
|
+
}
|
160
|
+
} else {
|
161
|
+
formatedProxy.push.apply(formatedProxy, _toConsumableArray(proxyOptions));
|
162
|
+
}
|
163
|
+
|
164
|
+
return formatedProxy;
|
165
|
+
}
|
166
|
+
|
167
|
+
export { formatProxyOptions };
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as _fs from 'fs-extra';
|
2
2
|
export { _fs as fs };
|
3
3
|
export * from "./chalk";
|
4
|
-
export * from "./
|
4
|
+
export * from "./format";
|
5
5
|
export * from "./FileSizeReporter";
|
6
6
|
export * from "./printBuildError";
|
7
7
|
export * from "./debug";
|
@@ -29,4 +29,5 @@ export * from "./prettyInstructions";
|
|
29
29
|
export * from "./alias";
|
30
30
|
export * from "./import";
|
31
31
|
export * from "./watch";
|
32
|
-
export * from "./nodeEnv";
|
32
|
+
export * from "./nodeEnv";
|
33
|
+
export * from "./wait";
|
@@ -56,14 +56,16 @@ export var prettyInstructions = function prettyInstructions(appContext, config)
|
|
56
56
|
var _ref = appContext,
|
57
57
|
entrypoints = _ref.entrypoints,
|
58
58
|
serverRoutes = _ref.serverRoutes,
|
59
|
-
port = _ref.port
|
59
|
+
port = _ref.port,
|
60
|
+
existSrc = _ref.existSrc,
|
61
|
+
checkedEntries = _ref.checkedEntries;
|
60
62
|
var urls = getAddressUrls(config.dev.https && isDev() ? 'https' : 'http', port);
|
61
|
-
var routes = serverRoutes.filter(function (route) {
|
63
|
+
var routes = existSrc ? serverRoutes.filter(function (route) {
|
62
64
|
return route.entryName;
|
63
|
-
});
|
65
|
+
}) : serverRoutes;
|
64
66
|
var message = 'App running at:\n\n';
|
65
67
|
|
66
|
-
if (isSingleEntry(entrypoints)) {
|
68
|
+
if (isSingleEntry(entrypoints) || !existSrc) {
|
67
69
|
message += urls.map(function (_ref2) {
|
68
70
|
var type = _ref2.type,
|
69
71
|
url = _ref2.url;
|
@@ -79,10 +81,19 @@ export var prettyInstructions = function prettyInstructions(appContext, config)
|
|
79
81
|
message += " ".concat(chalk.bold("> ".concat(type)), "\n");
|
80
82
|
routes.forEach(function (_ref4) {
|
81
83
|
var entryName = _ref4.entryName,
|
82
|
-
urlPath = _ref4.urlPath
|
83
|
-
|
84
|
+
urlPath = _ref4.urlPath,
|
85
|
+
isSSR = _ref4.isSSR;
|
86
|
+
|
87
|
+
if (!checkedEntries.includes(entryName)) {
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
|
91
|
+
message += " ".concat(chalk.yellowBright(isSSR ? 'λ' : '○'), " ").concat(chalk.yellowBright(entryName.padEnd(maxNameLength + 8))).concat(chalk.cyanBright(normalizeUrl("".concat(url, "/").concat(urlPath))), "\n");
|
84
92
|
});
|
85
93
|
});
|
94
|
+
message += '\n';
|
95
|
+
message += chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
|
96
|
+
message += chalk.cyanBright(' ○ (Static) client-side rendered as static HTML\n');
|
86
97
|
}
|
87
98
|
|
88
99
|
return message;
|
@@ -4,4 +4,5 @@
|
|
4
4
|
* @returns module export object.
|
5
5
|
*/
|
6
6
|
export declare const compatRequire: (filePath: string) => any;
|
7
|
-
export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
|
7
|
+
export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
|
8
|
+
export declare const cleanRequireCache: (filelist: string[]) => void;
|
@@ -1,16 +1,6 @@
|
|
1
|
-
/**
|
2
|
-
* alias to src directory
|
3
|
-
*/
|
4
|
-
export declare const INTERNAL_SRC_ALIAS = "@_modern_js_src";
|
5
|
-
/**
|
6
|
-
* alias to node_modules/.modern-js
|
7
|
-
*/
|
8
|
-
|
9
|
-
export declare const INTERNAL_DIR_ALAIS = "@_modern_js_internal";
|
10
1
|
/**
|
11
2
|
* hmr socket connect path
|
12
3
|
*/
|
13
|
-
|
14
4
|
export declare const HMR_SOCK_PATH = "/_modern_js_hmr_ws";
|
15
5
|
/**
|
16
6
|
* route specification file
|
@@ -47,11 +37,6 @@ export declare const SERVER_RENDER_FUNCTION_NAME = "serverRender";
|
|
47
37
|
*/
|
48
38
|
|
49
39
|
export declare const LOADABLE_STATS_FILE = "loadable-stats.json";
|
50
|
-
/**
|
51
|
-
* real entry generate by modern.js
|
52
|
-
*/
|
53
|
-
|
54
|
-
export declare const HIDE_MODERN_JS_DIR = "./node_modules/.modern-js";
|
55
40
|
/**
|
56
41
|
* internal specified folder
|
57
42
|
*/
|
@@ -176,6 +161,19 @@ export declare const PLUGIN_SCHEMAS: {
|
|
176
161
|
type: string[];
|
177
162
|
};
|
178
163
|
}[];
|
164
|
+
'@modern-js/plugin-design-token': ({
|
165
|
+
target: string;
|
166
|
+
schema: {
|
167
|
+
typeof: string[];
|
168
|
+
type?: undefined;
|
169
|
+
};
|
170
|
+
} | {
|
171
|
+
target: string;
|
172
|
+
schema: {
|
173
|
+
type: string[];
|
174
|
+
typeof?: undefined;
|
175
|
+
};
|
176
|
+
})[];
|
179
177
|
'@modern-js/plugin-router': {
|
180
178
|
target: string;
|
181
179
|
schema: {
|
@@ -188,7 +186,7 @@ export declare const PLUGIN_SCHEMAS: {
|
|
188
186
|
typeof: string[];
|
189
187
|
};
|
190
188
|
}[];
|
191
|
-
'@modern-js/plugin-
|
189
|
+
'@modern-js/plugin-garfish': {
|
192
190
|
target: string;
|
193
191
|
schema: {
|
194
192
|
type: string[];
|
@@ -6,8 +6,11 @@
|
|
6
6
|
* https://github.com/facebook/create-react-app/blob/master/LICENSE
|
7
7
|
*/
|
8
8
|
import { StatsCompilation } from 'webpack';
|
9
|
+
import { ProxyDetail, ProxyOptions } from '@modern-js/types';
|
9
10
|
declare function formatWebpackMessages(json: StatsCompilation): {
|
10
11
|
errors: string[];
|
11
12
|
warnings: string[];
|
12
13
|
};
|
13
|
-
export { formatWebpackMessages };
|
14
|
+
export { formatWebpackMessages };
|
15
|
+
declare function formatProxyOptions(proxyOptions: ProxyOptions): ProxyDetail[];
|
16
|
+
export { formatProxyOptions };
|
package/dist/types/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
export * as fs from 'fs-extra';
|
2
2
|
export * from './chalk';
|
3
|
-
export * from './
|
3
|
+
export * from './format';
|
4
4
|
export * from './FileSizeReporter';
|
5
5
|
export * from './printBuildError';
|
6
6
|
export * from './debug';
|
@@ -28,4 +28,5 @@ export * from './prettyInstructions';
|
|
28
28
|
export * from './alias';
|
29
29
|
export * from './import';
|
30
30
|
export * from './watch';
|
31
|
-
export * from './nodeEnv';
|
31
|
+
export * from './nodeEnv';
|
32
|
+
export * from './wait';
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.3.2",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -26,9 +26,9 @@
|
|
26
26
|
},
|
27
27
|
"default": "./dist/js/treeshaking/index.js"
|
28
28
|
},
|
29
|
-
"./
|
30
|
-
"jsnext:source": "./src/
|
31
|
-
"default": "./dist/js/treeshaking/
|
29
|
+
"./format": {
|
30
|
+
"jsnext:source": "./src/format.ts",
|
31
|
+
"default": "./dist/js/treeshaking/format.js"
|
32
32
|
},
|
33
33
|
"./constants": {
|
34
34
|
"jsnext:source": "./src/constants.ts",
|
@@ -37,8 +37,8 @@
|
|
37
37
|
},
|
38
38
|
"typesVersions": {
|
39
39
|
"*": {
|
40
|
-
"
|
41
|
-
"./dist/types/
|
40
|
+
"format": [
|
41
|
+
"./dist/types/format.d.ts"
|
42
42
|
],
|
43
43
|
"constants": [
|
44
44
|
"./dist/types/constants.d.ts"
|
@@ -75,13 +75,13 @@
|
|
75
75
|
"webpack": "^5.54.0",
|
76
76
|
"@scripts/build": "0.0.0",
|
77
77
|
"jest": "^27",
|
78
|
-
"@scripts/jest-config": "0.0.0"
|
78
|
+
"@scripts/jest-config": "0.0.0",
|
79
|
+
"@modern-js/types": "^1.3.3"
|
79
80
|
},
|
80
81
|
"sideEffects": false,
|
81
82
|
"publishConfig": {
|
82
83
|
"registry": "https://registry.npmjs.org/",
|
83
|
-
"access": "public"
|
84
|
-
"types": "./dist/types/index.d.ts"
|
84
|
+
"access": "public"
|
85
85
|
},
|
86
86
|
"scripts": {
|
87
87
|
"new": "modern new",
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
2
|
+
|
3
|
+
exports[`prettyInstructions The src directory does not exist 1`] = `
|
4
|
+
"App running at:
|
5
|
+
|
6
|
+
> Network: http://127.0.0.1:8080/api
|
7
|
+
> Network: http://11.11.111.11:8080/api
|
8
|
+
> Network: http://10.100.100.100:8080/api
|
9
|
+
"
|
10
|
+
`;
|
11
|
+
|
12
|
+
exports[`prettyInstructions basic usage 1`] = `
|
13
|
+
"App running at:
|
14
|
+
|
15
|
+
> Network: http://127.0.0.1:8080/
|
16
|
+
> Network: http://11.11.111.11:8080/
|
17
|
+
> Network: http://10.100.100.100:8080/
|
18
|
+
"
|
19
|
+
`;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import path from 'path';
|
2
|
-
import { compatRequire } from '../src/compatRequire';
|
2
|
+
import { compatRequire, cleanRequireCache } from '../src/compatRequire';
|
3
3
|
|
4
4
|
describe('compat require', () => {
|
5
5
|
const fixturePath = path.resolve(__dirname, './fixtures/compat-require');
|
@@ -19,4 +19,14 @@ describe('compat require', () => {
|
|
19
19
|
test(`should return null`, () => {
|
20
20
|
expect(compatRequire(path.join(fixturePath, 'empty.js'))).toEqual(null);
|
21
21
|
});
|
22
|
+
|
23
|
+
test('should clearn cache after fn', () => {
|
24
|
+
const foo = module.require('./fixtures/compat-require/foo');
|
25
|
+
const requirePath = require.resolve('./fixtures/compat-require/foo.js');
|
26
|
+
expect(foo.name).toBe('foo');
|
27
|
+
expect(require.cache[requirePath]).toBeDefined();
|
28
|
+
cleanRequireCache([requirePath]);
|
29
|
+
jest.resetModules();
|
30
|
+
expect(require.cache[requirePath]).toBeUndefined();
|
31
|
+
});
|
22
32
|
});
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { formatProxyOptions } from '../src/format';
|
2
|
+
|
3
|
+
describe('test format', () => {
|
4
|
+
it('should format correctly use simply options', async () => {
|
5
|
+
const proxy = {
|
6
|
+
'/simple': `http://localhost`,
|
7
|
+
};
|
8
|
+
|
9
|
+
const options = formatProxyOptions(proxy);
|
10
|
+
expect(options).toEqual([
|
11
|
+
{
|
12
|
+
context: '/simple',
|
13
|
+
changeOrigin: true,
|
14
|
+
logLevel: 'warn',
|
15
|
+
target: 'http://localhost',
|
16
|
+
},
|
17
|
+
]);
|
18
|
+
});
|
19
|
+
|
20
|
+
it('should format correctly use simply options', async () => {
|
21
|
+
const proxy = {
|
22
|
+
'/simple-obj': {
|
23
|
+
target: `http://localhost`,
|
24
|
+
},
|
25
|
+
};
|
26
|
+
const options = formatProxyOptions(proxy);
|
27
|
+
expect(options).toEqual([
|
28
|
+
{
|
29
|
+
context: '/simple-obj',
|
30
|
+
changeOrigin: true,
|
31
|
+
logLevel: 'warn',
|
32
|
+
target: 'http://localhost',
|
33
|
+
},
|
34
|
+
]);
|
35
|
+
});
|
36
|
+
|
37
|
+
it('should format correctly use simply options', async () => {
|
38
|
+
const proxy = {
|
39
|
+
context: '/context',
|
40
|
+
target: `http://localhost`,
|
41
|
+
};
|
42
|
+
const options = formatProxyOptions(proxy);
|
43
|
+
expect(options).toEqual([
|
44
|
+
{ context: '/context', target: 'http://localhost' },
|
45
|
+
]);
|
46
|
+
});
|
47
|
+
|
48
|
+
it('should format correctly use simply options', async () => {
|
49
|
+
const proxy = [
|
50
|
+
{
|
51
|
+
context: '/array',
|
52
|
+
target: `http://localhost`,
|
53
|
+
},
|
54
|
+
];
|
55
|
+
const options = formatProxyOptions(proxy);
|
56
|
+
expect(options).toEqual([
|
57
|
+
{ context: '/array', target: 'http://localhost' },
|
58
|
+
]);
|
59
|
+
});
|
60
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { generateMetaTags } from '../src/generateMetaTags';
|
2
|
+
|
3
|
+
describe('generateMetaTags', () => {
|
4
|
+
it('should return empty string when params is empty', () => {
|
5
|
+
expect(generateMetaTags()).toEqual('');
|
6
|
+
});
|
7
|
+
|
8
|
+
it('should generate meta tag correctly', () => {
|
9
|
+
const options = {
|
10
|
+
foo: {
|
11
|
+
name: 'viewport',
|
12
|
+
content: 'width=500, initial-scale=1',
|
13
|
+
},
|
14
|
+
};
|
15
|
+
expect(generateMetaTags(options).trim()).toEqual(
|
16
|
+
'<meta name="viewport" content="width=500, initial-scale=1">',
|
17
|
+
);
|
18
|
+
});
|
19
|
+
});
|
@@ -0,0 +1,139 @@
|
|
1
|
+
import { prettyInstructions } from '../src/prettyInstructions';
|
2
|
+
|
3
|
+
const mockNetworkInterfaces = {
|
4
|
+
lo0: [
|
5
|
+
{
|
6
|
+
address: '127.0.0.1',
|
7
|
+
netmask: '255.0.0.0',
|
8
|
+
family: 'IPv4',
|
9
|
+
mac: '00:00:00:00:00:00',
|
10
|
+
internal: true,
|
11
|
+
cidr: '127.0.0.1/8',
|
12
|
+
},
|
13
|
+
],
|
14
|
+
en5: [
|
15
|
+
{
|
16
|
+
address: 'fe80::aede:48ff:fe00:1122',
|
17
|
+
netmask: 'ffff:ffff:ffff:ffff::',
|
18
|
+
family: 'IPv6',
|
19
|
+
mac: 'ac:de:48:00:11:22',
|
20
|
+
internal: false,
|
21
|
+
cidr: 'fe80::aede:48ff:fe00:1122/64',
|
22
|
+
scopeid: 4,
|
23
|
+
},
|
24
|
+
],
|
25
|
+
en0: [
|
26
|
+
{
|
27
|
+
address: '11.11.111.11',
|
28
|
+
netmask: '255.255.252.0',
|
29
|
+
family: 'IPv4',
|
30
|
+
mac: '90:9c:4a:cf:11:d2',
|
31
|
+
internal: false,
|
32
|
+
cidr: '10.85.117.60/22',
|
33
|
+
},
|
34
|
+
],
|
35
|
+
utun2: [
|
36
|
+
{
|
37
|
+
address: '10.100.100.100',
|
38
|
+
netmask: '255.255.224.0',
|
39
|
+
family: 'IPv4',
|
40
|
+
mac: '00:00:00:00:00:00',
|
41
|
+
internal: false,
|
42
|
+
cidr: '10.255.182.172/19',
|
43
|
+
},
|
44
|
+
],
|
45
|
+
};
|
46
|
+
|
47
|
+
jest.mock('os', () => {
|
48
|
+
const originalModule = jest.requireActual('os');
|
49
|
+
return {
|
50
|
+
__esModule: true,
|
51
|
+
...originalModule,
|
52
|
+
default: {
|
53
|
+
networkInterfaces() {
|
54
|
+
return mockNetworkInterfaces;
|
55
|
+
},
|
56
|
+
},
|
57
|
+
};
|
58
|
+
});
|
59
|
+
|
60
|
+
jest.mock('chalk', () => ({
|
61
|
+
__esModule: true,
|
62
|
+
default: {
|
63
|
+
bold: jest.fn(str => str),
|
64
|
+
green: jest.fn(str => str),
|
65
|
+
red: jest.fn(str => str),
|
66
|
+
yellow: jest.fn(str => str),
|
67
|
+
cyanBright: jest.fn(str => str),
|
68
|
+
},
|
69
|
+
}));
|
70
|
+
|
71
|
+
describe('prettyInstructions', () => {
|
72
|
+
test('basic usage', () => {
|
73
|
+
const mockAppContext = {
|
74
|
+
entrypoints: [
|
75
|
+
{
|
76
|
+
entryName: 'main',
|
77
|
+
entry: '/example/node_modules/.modern-js/main/index.js',
|
78
|
+
isAutoMount: true,
|
79
|
+
customBootstrap: false,
|
80
|
+
},
|
81
|
+
],
|
82
|
+
serverRoutes: [
|
83
|
+
{
|
84
|
+
urlPath: '/',
|
85
|
+
entryName: 'main',
|
86
|
+
entryPath: 'html/main/index.html',
|
87
|
+
isSPA: true,
|
88
|
+
isSSR: false,
|
89
|
+
enableModernMode: false,
|
90
|
+
},
|
91
|
+
{
|
92
|
+
urlPath: '/api',
|
93
|
+
isApi: true,
|
94
|
+
entryPath: '',
|
95
|
+
isSPA: false,
|
96
|
+
isSSR: false,
|
97
|
+
},
|
98
|
+
],
|
99
|
+
port: 8080,
|
100
|
+
existSrc: true,
|
101
|
+
};
|
102
|
+
const mockConfig = {
|
103
|
+
dev: {
|
104
|
+
https: true,
|
105
|
+
},
|
106
|
+
};
|
107
|
+
|
108
|
+
const message = prettyInstructions(mockAppContext, mockConfig);
|
109
|
+
|
110
|
+
expect(message).toMatchSnapshot();
|
111
|
+
});
|
112
|
+
|
113
|
+
test('The src directory does not exist', () => {
|
114
|
+
const mockAppContext = {
|
115
|
+
entrypoints: [],
|
116
|
+
serverRoutes: [
|
117
|
+
{
|
118
|
+
urlPath: '/api',
|
119
|
+
isApi: true,
|
120
|
+
entryPath: '',
|
121
|
+
isSPA: false,
|
122
|
+
isSSR: false,
|
123
|
+
},
|
124
|
+
],
|
125
|
+
port: 8080,
|
126
|
+
existSrc: false,
|
127
|
+
};
|
128
|
+
|
129
|
+
const mockConfig = {
|
130
|
+
dev: {
|
131
|
+
https: true,
|
132
|
+
},
|
133
|
+
};
|
134
|
+
|
135
|
+
const message = prettyInstructions(mockAppContext, mockConfig);
|
136
|
+
|
137
|
+
expect(message).toMatchSnapshot();
|
138
|
+
});
|
139
|
+
});
|
package/tests/wait.ts
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
import { wait } from '../src/wait';
|
2
|
+
|
3
|
+
jest.useRealTimers();
|
4
|
+
|
5
|
+
describe('wait', () => {
|
6
|
+
test('basic usage', async () => {
|
7
|
+
const fn1 = jest.fn();
|
8
|
+
const fn2 = jest.fn();
|
9
|
+
const fn3 = async () => {
|
10
|
+
fn1();
|
11
|
+
await wait();
|
12
|
+
fn2();
|
13
|
+
};
|
14
|
+
|
15
|
+
fn3();
|
16
|
+
expect(fn1).toBeCalled();
|
17
|
+
expect(fn2).not.toBeCalled();
|
18
|
+
await wait();
|
19
|
+
expect(fn2).toBeCalled();
|
20
|
+
});
|
21
|
+
|
22
|
+
test('delay', async () => {
|
23
|
+
const fn1 = jest.fn();
|
24
|
+
const fn2 = jest.fn();
|
25
|
+
const time = 100;
|
26
|
+
const fn3 = async () => {
|
27
|
+
fn1();
|
28
|
+
await wait(time);
|
29
|
+
fn2();
|
30
|
+
};
|
31
|
+
|
32
|
+
fn3();
|
33
|
+
expect(fn1).toBeCalled();
|
34
|
+
expect(fn2).not.toBeCalled();
|
35
|
+
await wait(time);
|
36
|
+
expect(fn2).toBeCalled();
|
37
|
+
});
|
38
|
+
});
|