@modern-js/utils 1.19.0 → 1.20.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 1.20.0
4
+
5
+ ### Patch Changes
6
+
7
+ - d5d570b: feat: optimize the logger of @modern-js/utils, remove builder logger
8
+
9
+ feat: 优化 @modern-js/utils 的 logger 格式, 移除 builder 内置的 logger
10
+
11
+ - 4ddc185: chore(builder): bump webpack to 5.74.0
12
+
13
+ chore(builder): 升级 webpack 到 5.74.0 版本
14
+
15
+ - df8ee7e: fix(utils): failed to resolve execa
16
+
17
+ fix(utils): 修复找不到 execa 模块的问题
18
+
19
+ - 8c05089: fix: support monorepo deploy in pnpm 7
20
+ fix: 修复 monorepo deploy 命令在 pnpm 7 下的问题
21
+
3
22
  ## 1.19.0
4
23
 
5
24
  ## 1.18.1
@@ -18,8 +37,8 @@
18
37
 
19
38
  ### Minor Changes
20
39
 
21
- - 5227370: feat: add webpack-builder plugin subresource-integrity
22
- feat: 新增 webpack-builder 插件 subresource-integrity
40
+ - 5227370: feat: add builder plugin subresource-integrity
41
+ feat: 新增 builder 插件 subresource-integrity
23
42
 
24
43
  ### Patch Changes
25
44
 
@@ -124,7 +143,7 @@
124
143
 
125
144
  ### Minor Changes
126
145
 
127
- - 7b9067f: add babel plugin for webpack-builder
146
+ - 7b9067f: add babel plugin for builder
128
147
 
129
148
  ### Patch Changes
130
149
 
package/dist/getPort.d.ts CHANGED
@@ -2,6 +2,10 @@
2
2
  * Get available free port.
3
3
  * @param port - Current port want to use.
4
4
  * @param tryLimits - Maximum number of retries.
5
+ * @param strictPort - Whether to throw an error when the port is occupied.
5
6
  * @returns Available port number.
6
7
  */
7
- export declare const getPort: (port: string | number, tryLimits?: number) => Promise<number>;
8
+ export declare const getPort: (port: string | number, { tryLimits, strictPort, }?: {
9
+ tryLimits?: number | undefined;
10
+ strictPort?: boolean | undefined;
11
+ }) => Promise<number>;
package/dist/getPort.js CHANGED
@@ -11,13 +11,17 @@ const logger_1 = require("./logger");
11
11
  * Get available free port.
12
12
  * @param port - Current port want to use.
13
13
  * @param tryLimits - Maximum number of retries.
14
+ * @param strictPort - Whether to throw an error when the port is occupied.
14
15
  * @returns Available port number.
15
16
  */
16
17
  /* eslint-disable no-param-reassign, @typescript-eslint/no-loop-func */
17
- const getPort = async (port, tryLimits = 20) => {
18
+ const getPort = async (port, { tryLimits = 20, strictPort = false, } = {}) => {
18
19
  if (typeof port === 'string') {
19
20
  port = parseInt(port, 10);
20
21
  }
22
+ if (strictPort) {
23
+ tryLimits = 1;
24
+ }
21
25
  const original = port;
22
26
  let found = false;
23
27
  let attempts = 0;
@@ -45,7 +49,12 @@ const getPort = async (port, tryLimits = 20) => {
45
49
  }
46
50
  }
47
51
  if (port !== original) {
48
- logger_1.logger.info(compiled_1.chalk.red(`Something is already running on port ${original}. ${compiled_1.chalk.yellow(`Use port ${port} instead.`)}`));
52
+ if (strictPort) {
53
+ throw new Error(`Port "${original}" is occupied, please choose another one.`);
54
+ }
55
+ else {
56
+ logger_1.logger.info(`Something is already running on port ${original}. ${compiled_1.chalk.yellow(`Use port ${port} instead.`)}`);
57
+ }
49
58
  }
50
59
  return port;
51
60
  };
package/dist/index.d.ts CHANGED
@@ -34,4 +34,4 @@ export * from './ssr';
34
34
  export * from './tryResolve';
35
35
  export * from './analyzeProject';
36
36
  export * from './chainId';
37
- export * from './reactVersion';
37
+ export * from './version';
package/dist/index.js CHANGED
@@ -50,4 +50,4 @@ __exportStar(require("./ssr"), exports);
50
50
  __exportStar(require("./tryResolve"), exports);
51
51
  __exportStar(require("./analyzeProject"), exports);
52
52
  __exportStar(require("./chainId"), exports);
53
- __exportStar(require("./reactVersion"), exports);
53
+ __exportStar(require("./version"), exports);
package/dist/logger.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Color } from '../compiled/chalk';
2
2
  declare type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ declare type LogMsg = number | string | Error | null;
3
4
  interface LoggerConfiguration {
4
5
  color?: typeof Color;
5
6
  label?: string;
@@ -7,7 +8,6 @@ interface LoggerConfiguration {
7
8
  }
8
9
  interface InstanceConfiguration {
9
10
  displayLabel?: boolean;
10
- underlineLabel?: boolean;
11
11
  uppercaseLabel?: boolean;
12
12
  }
13
13
  interface ConstructorOptions {
@@ -15,7 +15,7 @@ interface ConstructorOptions {
15
15
  level?: string;
16
16
  types?: Record<string, LoggerConfiguration>;
17
17
  }
18
- declare type LoggerFunction = (message?: number | string | Error, ...args: any[]) => void;
18
+ declare type LoggerFunction = (message?: LogMsg, ...args: any[]) => void;
19
19
  declare const LOG_TYPES: {
20
20
  error: {
21
21
  color: string;
@@ -42,20 +42,14 @@ declare const LOG_TYPES: {
42
42
  };
43
43
  };
44
44
  declare class Logger {
45
- private readonly logCount;
46
45
  private readonly level;
47
- private history;
48
46
  private readonly config;
49
47
  private readonly types;
50
48
  private readonly longestLabel;
51
49
  [key: string]: any;
52
50
  constructor(options?: ConstructorOptions);
53
- private retainLog;
54
51
  private _log;
55
52
  private getLongestLabel;
56
- private get longestUnderlinedLabel();
57
- getRetainedLogs(type: string): string[];
58
- clearRetainedLogs(type: string): void;
59
53
  }
60
54
  declare type LoggerInterface = {
61
55
  [key in keyof typeof LOG_TYPES]: LoggerFunction;
package/dist/logger.js CHANGED
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.logger = exports.Logger = void 0;
7
7
  const chalk_1 = __importDefault(require("../compiled/chalk"));
8
- const { grey, underline } = chalk_1.default;
9
8
  const LOG_LEVEL = {
10
9
  error: 0,
11
10
  warn: 1,
@@ -20,13 +19,13 @@ const LOG_TYPES = {
20
19
  level: 'error',
21
20
  },
22
21
  info: {
23
- color: 'blue',
22
+ color: 'cyan',
24
23
  label: 'info',
25
24
  level: 'info',
26
25
  },
27
26
  warn: {
28
27
  color: 'yellow',
29
- label: 'warning',
28
+ label: 'warn',
30
29
  level: 'warn',
31
30
  },
32
31
  debug: {
@@ -38,13 +37,10 @@ const LOG_TYPES = {
38
37
  };
39
38
  const DEFAULT_CONFIG = {
40
39
  displayLabel: true,
41
- underlineLabel: true,
42
40
  uppercaseLabel: false,
43
41
  };
44
42
  class Logger {
45
43
  constructor(options = {}) {
46
- this.logCount = 200;
47
- this.history = {};
48
44
  this.level = options.level || LOG_TYPES.log.level;
49
45
  this.config = { ...DEFAULT_CONFIG, ...(options.config || {}) };
50
46
  this.types = {
@@ -56,17 +52,8 @@ class Logger {
56
52
  this[type] = this._log.bind(this, type);
57
53
  });
58
54
  }
59
- retainLog(type, message) {
60
- if (!this.history[type]) {
61
- this.history[type] = [];
62
- }
63
- this.history[type].push(message);
64
- while (this.history[type].length > this.logCount) {
65
- this.history[type].shift();
66
- }
67
- }
68
55
  _log(type, message, ...args) {
69
- if (message === undefined) {
56
+ if (message === undefined || message === null) {
70
57
  // eslint-disable-next-line no-console
71
58
  console.log();
72
59
  return;
@@ -81,18 +68,13 @@ class Logger {
81
68
  label = this.config.uppercaseLabel
82
69
  ? logType.label.toUpperCase()
83
70
  : logType.label;
84
- if (this.config.underlineLabel) {
85
- label = underline(label).padEnd(this.longestUnderlinedLabel.length + 1);
86
- }
87
- else {
88
- label = label.padEnd(this.longestLabel.length + 1);
89
- }
90
- label = logType.color ? chalk_1.default[logType.color](label) : label;
71
+ label = label.padEnd(this.longestLabel.length);
72
+ label = chalk_1.default.bold(logType.color ? chalk_1.default[logType.color](label) : label);
91
73
  }
92
74
  if (message instanceof Error) {
93
75
  if (message.stack) {
94
76
  const [name, ...rest] = message.stack.split('\n');
95
- text = `${name}\n${grey(rest.join('\n'))}`;
77
+ text = `${name}\n${chalk_1.default.grey(rest.join('\n'))}`;
96
78
  }
97
79
  else {
98
80
  text = message.message;
@@ -101,12 +83,7 @@ class Logger {
101
83
  else {
102
84
  text = `${message}`;
103
85
  }
104
- // only retain logs of warn/error level
105
- if (logType.level === 'warn' || logType.level === 'error') {
106
- // retain log text without label
107
- this.retainLog(type, text);
108
- }
109
- const log = label.length > 0 ? `${label} ${text}` : text;
86
+ const log = label.length > 0 ? `${label} ${text}` : text;
110
87
  // eslint-disable-next-line no-console
111
88
  console.log(log, ...args);
112
89
  }
@@ -120,22 +97,6 @@ class Logger {
120
97
  });
121
98
  return longestLabel;
122
99
  }
123
- get longestUnderlinedLabel() {
124
- return underline(this.longestLabel);
125
- }
126
- getRetainedLogs(type) {
127
- return this.history[type] || [];
128
- }
129
- clearRetainedLogs(type) {
130
- if (type) {
131
- if (this.history[type]) {
132
- this.history[type] = [];
133
- }
134
- }
135
- else {
136
- this.history = {};
137
- }
138
- }
139
100
  }
140
101
  exports.Logger = Logger;
141
102
  const logger = new Logger();
@@ -0,0 +1,2 @@
1
+ export declare function getPnpmVersion(): Promise<string>;
2
+ export declare const isReact18: (cwd: string) => boolean;
@@ -3,9 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isReact18 = void 0;
6
+ exports.isReact18 = exports.getPnpmVersion = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const compiled_1 = require("./compiled");
9
+ async function getPnpmVersion() {
10
+ const { stdout } = await (0, compiled_1.execa)('pnpm', ['--version']);
11
+ return stdout;
12
+ }
13
+ exports.getPnpmVersion = getPnpmVersion;
9
14
  const isReact18 = (cwd) => {
10
15
  const pkgPath = path_1.default.join(cwd, 'package.json');
11
16
  if (!compiled_1.fs.existsSync(pkgPath)) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.19.0",
14
+ "version": "1.20.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -20,9 +20,10 @@
20
20
  "_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
21
21
  "exports": {
22
22
  ".": "./dist/index.js",
23
+ "./ssr": "./dist/ssr.js",
23
24
  "./format": "./dist/format.js",
25
+ "./logger": "./dist/logger.js",
24
26
  "./constants": "./dist/constants.js",
25
- "./ssr": "./dist/ssr.js",
26
27
  "./ajv": "./compiled/ajv/index.js",
27
28
  "./glob": "./compiled/glob/index.js",
28
29
  "./chalk": "./compiled/chalk/index.js",
@@ -49,15 +50,18 @@
49
50
  },
50
51
  "typesVersions": {
51
52
  "*": {
53
+ "ssr": [
54
+ "./dist/ssr.d.ts"
55
+ ],
52
56
  "format": [
53
57
  "./dist/format.d.ts"
54
58
  ],
59
+ "logger": [
60
+ "./dist/logger.d.ts"
61
+ ],
55
62
  "constants": [
56
63
  "./dist/constants.d.ts"
57
64
  ],
58
- "ssr": [
59
- "./dist/ssr.d.ts"
60
- ],
61
65
  "ajv": [
62
66
  "./compiled/ajv/types/ajv.d.ts"
63
67
  ],
@@ -125,14 +129,14 @@
125
129
  "lodash": "^4.17.21"
126
130
  },
127
131
  "devDependencies": {
128
- "@modern-js/types": "1.19.0",
129
- "@scripts/build": "1.19.0",
130
- "@scripts/jest-config": "1.19.0",
132
+ "@modern-js/types": "1.20.0",
133
+ "@scripts/build": "1.20.0",
134
+ "@scripts/jest-config": "1.20.0",
131
135
  "@types/jest": "^27",
132
136
  "@types/node": "^14",
133
137
  "typescript": "^4",
134
138
  "jest": "^27",
135
- "webpack": "^5.71.0"
139
+ "webpack": "^5.74.0"
136
140
  },
137
141
  "sideEffects": false,
138
142
  "wireit": {
@@ -1 +0,0 @@
1
- export declare const isReact18: (cwd: string) => boolean;