@modern-js/utils 1.3.1 → 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 CHANGED
@@ -1,5 +1,11 @@
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
+
3
9
  ## 1.3.1
4
10
 
5
11
  ### 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',
@@ -269,6 +267,18 @@ export const PLUGIN_SCHEMAS = {
269
267
  type: ['boolean', 'object']
270
268
  }
271
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
+ }],
272
282
  '@modern-js/plugin-router': [{
273
283
  target: 'runtime.router',
274
284
  schema: {
@@ -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";
@@ -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',
@@ -288,6 +286,18 @@ const PLUGIN_SCHEMAS = {
288
286
  type: ['boolean', 'object']
289
287
  }
290
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
+ }],
291
301
  '@modern-js/plugin-router': [{
292
302
  target: 'runtime.router',
293
303
  schema: {
@@ -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
  });
@@ -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',
@@ -269,6 +267,18 @@ export var PLUGIN_SCHEMAS = {
269
267
  type: ['boolean', 'object']
270
268
  }
271
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
+ }],
272
282
  '@modern-js/plugin-router': [{
273
283
  target: 'runtime.router',
274
284
  schema: {
@@ -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";
@@ -161,6 +161,19 @@ export declare const PLUGIN_SCHEMAS: {
161
161
  type: string[];
162
162
  };
163
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
+ })[];
164
177
  '@modern-js/plugin-router': {
165
178
  target: string;
166
179
  schema: {
@@ -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';
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.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
- "./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.3"
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
+ });