@modern-js/utils 1.3.1 → 1.3.4

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 CHANGED
@@ -1,5 +1,26 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 1.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - db43dce6: expose plugin-unbundle configs
8
+
9
+ ## 1.3.3
10
+
11
+ ### Patch Changes
12
+
13
+ - 4c792f68: feat(plugin-garfish): Sub-applications automatically increment basename
14
+ feat(plugin-garfish): export common generate code function
15
+ fix(plugin-garfish): modify plugin-garfish schema config
16
+ - a7f42f48: new user config for plugin-unbundle
17
+
18
+ ## 1.3.2
19
+
20
+ ### Patch Changes
21
+
22
+ - deeaa602: support svg/proxy/multi-version in unbundled
23
+
3
24
  ## 1.3.1
4
25
 
5
26
  ### Patch Changes
@@ -151,6 +151,9 @@ export const INTERNAL_PLUGINS = {
151
151
  },
152
152
  '@modern-js/plugin-nocode': {
153
153
  cli: '@modern-js/plugin-nocode/cli'
154
+ },
155
+ '@modern-js/plugin-design-token': {
156
+ cli: '@modern-js/plugin-design-token/cli'
154
157
  }
155
158
  };
156
159
  /**
@@ -222,11 +225,6 @@ export const PLUGIN_SCHEMAS = {
222
225
  schema: {
223
226
  typeof: ['object', 'function']
224
227
  }
225
- }, {
226
- target: 'source.designSystem',
227
- schema: {
228
- typeof: ['object']
229
- }
230
228
  }],
231
229
  '@modern-js/plugin-proxy': [{
232
230
  target: 'dev.proxy',
@@ -244,6 +242,28 @@ export const PLUGIN_SCHEMAS = {
244
242
  schema: {
245
243
  type: 'boolean'
246
244
  }
245
+ }, {
246
+ target: 'dev.unbundle',
247
+ schema: {
248
+ type: 'object',
249
+ properties: {
250
+ ignore: {
251
+ type: ['string', 'array'],
252
+ items: {
253
+ type: 'string'
254
+ }
255
+ },
256
+ ignoreModuleCache: {
257
+ type: 'boolean'
258
+ },
259
+ clearPdnCache: {
260
+ type: 'boolean'
261
+ },
262
+ pdnHost: {
263
+ type: 'string'
264
+ }
265
+ }
266
+ }
247
267
  }],
248
268
  '@modern-js/plugin-ssg': [{
249
269
  target: 'output.ssg',
@@ -269,6 +289,18 @@ export const PLUGIN_SCHEMAS = {
269
289
  type: ['boolean', 'object']
270
290
  }
271
291
  }],
292
+ '@modern-js/plugin-design-token': [// Legacy Features
293
+ {
294
+ target: 'source.designSystem',
295
+ schema: {
296
+ typeof: ['object']
297
+ }
298
+ }, {
299
+ target: 'source.designSystem.supportStyledComponents',
300
+ schema: {
301
+ type: ['boolean']
302
+ }
303
+ }],
272
304
  '@modern-js/plugin-router': [{
273
305
  target: 'runtime.router',
274
306
  schema: {
@@ -289,13 +321,18 @@ export const PLUGIN_SCHEMAS = {
289
321
  '@modern-js/plugin-garfish': [{
290
322
  target: 'runtime.masterApp',
291
323
  schema: {
292
- type: ['object']
324
+ type: ['boolean', 'object']
293
325
  }
294
326
  }, {
295
327
  target: 'dev.withMasterApp',
296
328
  schema: {
297
329
  type: ['object']
298
330
  }
331
+ }, {
332
+ target: 'deploy.microFrontend',
333
+ schema: {
334
+ type: ['boolean', 'object']
335
+ }
299
336
  }],
300
337
  '@modern-js/plugin-nocode': []
301
338
  };
@@ -0,0 +1,6 @@
1
+ import fs from 'fs-extra';
2
+ export const emptyDir = async dir => {
3
+ if (await fs.pathExists(dir)) {
4
+ await fs.emptyDir(dir);
5
+ }
6
+ };
@@ -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 };
@@ -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 "./formatWebpackMessages";
4
+ export * from "./format";
5
5
  export * from "./FileSizeReporter";
6
6
  export * from "./printBuildError";
7
7
  export * from "./debug";
@@ -30,4 +30,5 @@ export * from "./alias";
30
30
  export * from "./import";
31
31
  export * from "./watch";
32
32
  export * from "./nodeEnv";
33
- export * from "./wait";
33
+ export * from "./wait";
34
+ export * from "./emptyDir";
@@ -37,5 +37,4 @@ export function printBuildError(err) {
37
37
 
38
38
  logger.log();
39
39
  }
40
- ;
41
40
  /* eslint-enable */
@@ -169,6 +169,9 @@ const INTERNAL_PLUGINS = {
169
169
  },
170
170
  '@modern-js/plugin-nocode': {
171
171
  cli: '@modern-js/plugin-nocode/cli'
172
+ },
173
+ '@modern-js/plugin-design-token': {
174
+ cli: '@modern-js/plugin-design-token/cli'
172
175
  }
173
176
  };
174
177
  /**
@@ -241,11 +244,6 @@ const PLUGIN_SCHEMAS = {
241
244
  schema: {
242
245
  typeof: ['object', 'function']
243
246
  }
244
- }, {
245
- target: 'source.designSystem',
246
- schema: {
247
- typeof: ['object']
248
- }
249
247
  }],
250
248
  '@modern-js/plugin-proxy': [{
251
249
  target: 'dev.proxy',
@@ -263,6 +261,28 @@ const PLUGIN_SCHEMAS = {
263
261
  schema: {
264
262
  type: 'boolean'
265
263
  }
264
+ }, {
265
+ target: 'dev.unbundle',
266
+ schema: {
267
+ type: 'object',
268
+ properties: {
269
+ ignore: {
270
+ type: ['string', 'array'],
271
+ items: {
272
+ type: 'string'
273
+ }
274
+ },
275
+ ignoreModuleCache: {
276
+ type: 'boolean'
277
+ },
278
+ clearPdnCache: {
279
+ type: 'boolean'
280
+ },
281
+ pdnHost: {
282
+ type: 'string'
283
+ }
284
+ }
285
+ }
266
286
  }],
267
287
  '@modern-js/plugin-ssg': [{
268
288
  target: 'output.ssg',
@@ -288,6 +308,18 @@ const PLUGIN_SCHEMAS = {
288
308
  type: ['boolean', 'object']
289
309
  }
290
310
  }],
311
+ '@modern-js/plugin-design-token': [// Legacy Features
312
+ {
313
+ target: 'source.designSystem',
314
+ schema: {
315
+ typeof: ['object']
316
+ }
317
+ }, {
318
+ target: 'source.designSystem.supportStyledComponents',
319
+ schema: {
320
+ type: ['boolean']
321
+ }
322
+ }],
291
323
  '@modern-js/plugin-router': [{
292
324
  target: 'runtime.router',
293
325
  schema: {
@@ -308,13 +340,18 @@ const PLUGIN_SCHEMAS = {
308
340
  '@modern-js/plugin-garfish': [{
309
341
  target: 'runtime.masterApp',
310
342
  schema: {
311
- type: ['object']
343
+ type: ['boolean', 'object']
312
344
  }
313
345
  }, {
314
346
  target: 'dev.withMasterApp',
315
347
  schema: {
316
348
  type: ['object']
317
349
  }
350
+ }, {
351
+ target: 'deploy.microFrontend',
352
+ schema: {
353
+ type: ['boolean', 'object']
354
+ }
318
355
  }],
319
356
  '@modern-js/plugin-nocode': []
320
357
  };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.emptyDir = void 0;
7
+
8
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
+
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+
12
+ const emptyDir = async dir => {
13
+ if (await _fsExtra.default.pathExists(dir)) {
14
+ await _fsExtra.default.emptyDir(dir);
15
+ }
16
+ };
17
+
18
+ exports.emptyDir = emptyDir;
@@ -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
+ }
@@ -26,16 +26,16 @@ Object.keys(_chalk).forEach(function (key) {
26
26
  });
27
27
  });
28
28
 
29
- var _formatWebpackMessages = require("./formatWebpackMessages");
29
+ var _format = require("./format");
30
30
 
31
- Object.keys(_formatWebpackMessages).forEach(function (key) {
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] === _formatWebpackMessages[key]) return;
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 _formatWebpackMessages[key];
38
+ return _format[key];
39
39
  }
40
40
  });
41
41
  });
@@ -446,6 +446,20 @@ Object.keys(_wait).forEach(function (key) {
446
446
  });
447
447
  });
448
448
 
449
+ var _emptyDir = require("./emptyDir");
450
+
451
+ Object.keys(_emptyDir).forEach(function (key) {
452
+ if (key === "default" || key === "__esModule") return;
453
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
454
+ if (key in exports && exports[key] === _emptyDir[key]) return;
455
+ Object.defineProperty(exports, key, {
456
+ enumerable: true,
457
+ get: function () {
458
+ return _emptyDir[key];
459
+ }
460
+ });
461
+ });
462
+
449
463
  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); }
450
464
 
451
465
  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; }
@@ -49,6 +49,4 @@ function printBuildError(err) {
49
49
 
50
50
  _logger.logger.log();
51
51
  }
52
-
53
- ;
54
52
  /* eslint-enable */
@@ -153,6 +153,9 @@ export var INTERNAL_PLUGINS = {
153
153
  },
154
154
  '@modern-js/plugin-nocode': {
155
155
  cli: '@modern-js/plugin-nocode/cli'
156
+ },
157
+ '@modern-js/plugin-design-token': {
158
+ cli: '@modern-js/plugin-design-token/cli'
156
159
  }
157
160
  };
158
161
  /**
@@ -222,11 +225,6 @@ export var PLUGIN_SCHEMAS = {
222
225
  schema: {
223
226
  "typeof": ['object', 'function']
224
227
  }
225
- }, {
226
- target: 'source.designSystem',
227
- schema: {
228
- "typeof": ['object']
229
- }
230
228
  }],
231
229
  '@modern-js/plugin-proxy': [{
232
230
  target: 'dev.proxy',
@@ -244,6 +242,28 @@ export var PLUGIN_SCHEMAS = {
244
242
  schema: {
245
243
  type: 'boolean'
246
244
  }
245
+ }, {
246
+ target: 'dev.unbundle',
247
+ schema: {
248
+ type: 'object',
249
+ properties: {
250
+ ignore: {
251
+ type: ['string', 'array'],
252
+ items: {
253
+ type: 'string'
254
+ }
255
+ },
256
+ ignoreModuleCache: {
257
+ type: 'boolean'
258
+ },
259
+ clearPdnCache: {
260
+ type: 'boolean'
261
+ },
262
+ pdnHost: {
263
+ type: 'string'
264
+ }
265
+ }
266
+ }
247
267
  }],
248
268
  '@modern-js/plugin-ssg': [{
249
269
  target: 'output.ssg',
@@ -269,6 +289,18 @@ export var PLUGIN_SCHEMAS = {
269
289
  type: ['boolean', 'object']
270
290
  }
271
291
  }],
292
+ '@modern-js/plugin-design-token': [// Legacy Features
293
+ {
294
+ target: 'source.designSystem',
295
+ schema: {
296
+ "typeof": ['object']
297
+ }
298
+ }, {
299
+ target: 'source.designSystem.supportStyledComponents',
300
+ schema: {
301
+ type: ['boolean']
302
+ }
303
+ }],
272
304
  '@modern-js/plugin-router': [{
273
305
  target: 'runtime.router',
274
306
  schema: {
@@ -289,13 +321,18 @@ export var PLUGIN_SCHEMAS = {
289
321
  '@modern-js/plugin-garfish': [{
290
322
  target: 'runtime.masterApp',
291
323
  schema: {
292
- type: ['object']
324
+ type: ['boolean', 'object']
293
325
  }
294
326
  }, {
295
327
  target: 'dev.withMasterApp',
296
328
  schema: {
297
329
  type: ['object']
298
330
  }
331
+ }, {
332
+ target: 'deploy.microFrontend',
333
+ schema: {
334
+ type: ['boolean', 'object']
335
+ }
299
336
  }],
300
337
  '@modern-js/plugin-nocode': []
301
338
  };
@@ -0,0 +1,37 @@
1
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+
7
+ import fs from 'fs-extra';
8
+ export var emptyDir = /*#__PURE__*/function () {
9
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(dir) {
10
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
11
+ while (1) {
12
+ switch (_context.prev = _context.next) {
13
+ case 0:
14
+ _context.next = 2;
15
+ return fs.pathExists(dir);
16
+
17
+ case 2:
18
+ if (!_context.sent) {
19
+ _context.next = 5;
20
+ break;
21
+ }
22
+
23
+ _context.next = 5;
24
+ return fs.emptyDir(dir);
25
+
26
+ case 5:
27
+ case "end":
28
+ return _context.stop();
29
+ }
30
+ }
31
+ }, _callee);
32
+ }));
33
+
34
+ return function emptyDir(_x) {
35
+ return _ref.apply(this, arguments);
36
+ };
37
+ }();
@@ -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 "./formatWebpackMessages";
4
+ export * from "./format";
5
5
  export * from "./FileSizeReporter";
6
6
  export * from "./printBuildError";
7
7
  export * from "./debug";
@@ -30,4 +30,5 @@ export * from "./alias";
30
30
  export * from "./import";
31
31
  export * from "./watch";
32
32
  export * from "./nodeEnv";
33
- export * from "./wait";
33
+ export * from "./wait";
34
+ export * from "./emptyDir";
@@ -37,5 +37,4 @@ export function printBuildError(err) {
37
37
 
38
38
  logger.log();
39
39
  }
40
- ;
41
40
  /* eslint-enable */
@@ -131,12 +131,35 @@ export declare const PLUGIN_SCHEMAS: {
131
131
  typeof: string[];
132
132
  };
133
133
  }[];
134
- '@modern-js/plugin-unbundle': {
134
+ '@modern-js/plugin-unbundle': ({
135
135
  target: string;
136
136
  schema: {
137
137
  type: string;
138
+ properties?: undefined;
138
139
  };
139
- }[];
140
+ } | {
141
+ target: string;
142
+ schema: {
143
+ type: string;
144
+ properties: {
145
+ ignore: {
146
+ type: string[];
147
+ items: {
148
+ type: string;
149
+ };
150
+ };
151
+ ignoreModuleCache: {
152
+ type: string;
153
+ };
154
+ clearPdnCache: {
155
+ type: string;
156
+ };
157
+ pdnHost: {
158
+ type: string;
159
+ };
160
+ };
161
+ };
162
+ })[];
140
163
  '@modern-js/plugin-ssg': {
141
164
  target: string;
142
165
  schema: {
@@ -161,6 +184,19 @@ export declare const PLUGIN_SCHEMAS: {
161
184
  type: string[];
162
185
  };
163
186
  }[];
187
+ '@modern-js/plugin-design-token': ({
188
+ target: string;
189
+ schema: {
190
+ typeof: string[];
191
+ type?: undefined;
192
+ };
193
+ } | {
194
+ target: string;
195
+ schema: {
196
+ type: string[];
197
+ typeof?: undefined;
198
+ };
199
+ })[];
164
200
  '@modern-js/plugin-router': {
165
201
  target: string;
166
202
  schema: {
@@ -0,0 +1 @@
1
+ export declare const emptyDir: (dir: string) => Promise<void>;
@@ -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 };
@@ -1,6 +1,6 @@
1
1
  export * as fs from 'fs-extra';
2
2
  export * from './chalk';
3
- export * from './formatWebpackMessages';
3
+ export * from './format';
4
4
  export * from './FileSizeReporter';
5
5
  export * from './printBuildError';
6
6
  export * from './debug';
@@ -29,4 +29,5 @@ export * from './alias';
29
29
  export * from './import';
30
30
  export * from './watch';
31
31
  export * from './nodeEnv';
32
- export * from './wait';
32
+ export * from './wait';
33
+ export * from './emptyDir';
package/jest.config.js CHANGED
@@ -5,4 +5,8 @@ module.exports = {
5
5
  // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
6
  ...sharedConfig,
7
7
  rootDir: __dirname,
8
+ modulePathIgnorePatterns: [
9
+ // TODO: 很容易超时导致失败,暂时先绕过
10
+ 'tests/index.test.ts',
11
+ ],
8
12
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.1",
14
+ "version": "1.3.4",
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
- "./formatWebpackMessages": {
30
- "jsnext:source": "./src/formatWebpackMessages.ts",
31
- "default": "./dist/js/treeshaking/formatWebpackMessages.js"
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
- "formatWebpackMessages": [
41
- "./dist/types/formatWebpackMessages.d.ts"
40
+ "format": [
41
+ "./dist/types/format.d.ts"
42
42
  ],
43
43
  "constants": [
44
44
  "./dist/types/constants.d.ts"
@@ -75,7 +75,8 @@
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.4"
79
80
  },
80
81
  "sideEffects": false,
81
82
  "publishConfig": {
@@ -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
+ });
@@ -1,5 +1,7 @@
1
1
  import { canUseNpm, canUsePnpm, canUseYarn } from '../src';
2
2
 
3
+ jest.setTimeout(40000);
4
+
3
5
  describe('test generator utils', () => {
4
6
  test('test canUseNpm', async () => {
5
7
  const npmAbility = await canUseNpm();
@@ -0,0 +1,17 @@
1
+ import { isString, isUndefined } from '../src/is/type';
2
+
3
+ describe('validate type', () => {
4
+ it('should validate string correctly', () => {
5
+ expect(isString('')).toBeTruthy();
6
+ expect(isString('foo')).toBeTruthy();
7
+ expect(isString(null)).toBeFalsy();
8
+ expect(isString(123)).toBeFalsy();
9
+ });
10
+
11
+ it('should validate undeinfed correctly', () => {
12
+ expect(isUndefined(undefined)).toBeTruthy();
13
+ expect(isUndefined(null)).toBeFalsy();
14
+ expect(isUndefined('')).toBeFalsy();
15
+ expect(isUndefined(123)).toBeFalsy();
16
+ });
17
+ });