@jeffchi/logger 3.0.1-alpha.6 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +107 -13
  2. package/package.json +58 -1
package/README.md CHANGED
@@ -28,11 +28,11 @@ A log print output javascript tool library that can be used at the front and bac
28
28
  ### 使用 npm 或 yarn 安装
29
29
 
30
30
  ```bash
31
- $ npm install @jeffchi/logger --save
31
+ npm install @jeffchi/logger --save
32
32
  ```
33
33
 
34
34
  ```bash
35
- $ yarn add @jeffchi/logger
35
+ yarn add @jeffchi/logger
36
36
  ```
37
37
 
38
38
  如果你的网络环境不佳,推荐使用 [cnpm](https://github.com/cnpm/cnpm)。
@@ -140,17 +140,111 @@ export interface ILogOptions {
140
140
  npm run name
141
141
  ```
142
142
 
143
- | 脚本名称 | 说明 |
144
- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
145
- | clear | 清理 `lib/` `docs/` `build/`临时目录 |
146
- | doc | 利用 typedoc 生成 api 文档,位于`docs/`目录下 |
147
- | dev | 启动开发模式 |
148
- | build | 执行构建过程 |
149
- | format | 利用 prettier 格式化 |
150
- | lint | 依赖 tslint 对代码检查 |
151
- | test | 依赖 jest 测试代码 |
152
- | push | 用指定 message 提交代码并推送至远程 |
153
- | release [`<verson>`\|`patch`\|`minor`\|`major`] -- [`--alpha`\|`--beta`\|`--rc`] [`--all`] [`--otp code`] | 生成新的 `主`\|`次`\|`批` 版本号,推送远程仓库后,并发布至 npm 仓 <blockquote><li> --alpha: 预发布内部版本</li><li> --beta: 预发布公测版本</li><li> -rc: 预发布候选版本</li><li> -all: 提交全部修改</li><li> -otp `<code>`: 如果指定一次性口令,则直接发布到 npm 中心仓,否则不发布</li></blockquote> |
143
+ | 脚本名称 | 说明 |
144
+ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
145
+ | clear | 清理 `lib/` `docs/` `build/`临时目录 |
146
+ | doc | 利用 typedoc 生成 api 文档,位于`docs/`目录下 |
147
+ | dev | 启动开发模式 |
148
+ | build | 执行构建过程 |
149
+ | format | 利用 prettier 格式化 |
150
+ | lint | 依赖 tslint 对代码检查 |
151
+ | test | 依赖 jest 测试代码 |
152
+ | push | 用指定 message 提交代码并推送至远程 |
153
+ | release [`<verson>`\|`patch`\|`minor`\|`major`] -- [`--alpha`\|`--beta`\|`--rc`] [`--all`] [--dry-run] | 生成新的 `主`\|`次`\|`批` 版本号,推送远程仓库后,并发布至 npm 仓 <blockquote><li> --alpha: 预发布内部版本</li><li> --beta: 预发布公测版本</li><li> --rc: 预发布候选版本</li><li> --all: 提交全部修改</li><li> --dry-runn: 预览操作,指定后不会执行真实的发布,否则后续需要提供 opt 口令</li></blockquote> |
154
+
155
+ ## 已知问题及解决方案
156
+
157
+ ### 1 Webpack5 前端项目报错
158
+
159
+ ```bash
160
+ Failed to compile.
161
+
162
+ Module not found: Error: Can't resolve 'fs' in '/Users/jeff/Desktop/console-x/node_modules/@jeffchi/logger/lib'
163
+ ERROR in ./node_modules/@jeffchi/logger/lib/index.mjs 1252:133-145
164
+ Module not found: Error: Can't resolve 'fs' in '/Users/jeff/Desktop/console-x/node_modules/@jeffchi/logger/lib'
165
+
166
+ ERROR in ./node_modules/@jeffchi/logger/lib/index.mjs 1252:147-161
167
+ Module not found: Error: Can't resolve 'path' in '/Users/jeff/Desktop/console-x/node_modules/@jeffchi/logger/lib'
168
+
169
+ BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
170
+ This is no longer the case. Verify if you need this module and configure a polyfill for it.
171
+
172
+ If you want to include a polyfill, you need to:
173
+ - add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
174
+ - install 'path-browserify'
175
+ If you don't want to include a polyfill, you can use an empty module like this:
176
+ resolve.fallback: { "path": false }
177
+
178
+ webpack compiled with 2 errors
179
+ No issues found.
180
+ ```
181
+
182
+ #### 原因
183
+
184
+ `@jeffchi/logger` 是一个前后端能用的 npm 库,在后端使用时需要写入日志文件,需要依赖于`fs` 和 `path` 两个 node 核心库,在前端,则不需要. 早前 webpack4 会在构建 bundle 为 node.js 核心库附加庞大的 polyfills,对于前端项目,大部分的 polyfills 都不是必须的,webpack5 现在要停止这项工作,在模块构建时不再自动引入 polyfills,以减小打包体积.
185
+
186
+ #### 解决方案
187
+
188
+ ##### ~~1. 安装 path-browserify~~
189
+
190
+ ```bash
191
+ npm install path-browserify --save
192
+ # or
193
+ yarn add path-browserify
194
+ ```
195
+
196
+ > 因为前端项目不需要写放日志文件,所以此处可以跳过这一步
197
+
198
+ ##### 2. 配置 webpack
199
+
200
+ ```js
201
+ // webpack.config.js
202
+ resolve: {
203
+ fallback: {
204
+ // 如果需要,则引入path-browserify
205
+ // path: require.resolve("path-browserify"),
206
+ path: false;
207
+ }
208
+ }
209
+ ```
210
+
211
+ ###### 2.1craco
212
+
213
+ 如果你使用的是 craco:
214
+
215
+ ```js
216
+ module.exports = {
217
+ webpack: {
218
+ alias: {
219
+ // alias...
220
+ },
221
+
222
+ configure: (config) => {
223
+ const { resolve = {} } = config;
224
+ resolve.fallback = { ...(resolve.fallback || {}), fs: false, path: false };
225
+ resolve.fallback.path = false;
226
+ return { ...config, resolve };
227
+ },
228
+ },
229
+ plugins: [
230
+ // plugins...
231
+ ],
232
+ };
233
+ ```
234
+
235
+ ##### 3.修改 package.json
236
+
237
+ ```json
238
+ "browser":{
239
+ "path":false,
240
+ "fs":false
241
+ },
242
+ "dependencies":{
243
+ // ...
244
+ }
245
+ ```
246
+
247
+ > 此步骤非必须
154
248
 
155
249
  ## License
156
250
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeffchi/logger",
3
- "version": "3.0.1-alpha.6",
3
+ "version": "3.1.0",
4
4
  "main": "lib/index.cjs",
5
5
  "module": "lib/index.mjs",
6
6
  "browser": "lib/index.cjs",
@@ -55,6 +55,63 @@
55
55
  "*.d.ts"
56
56
  ],
57
57
  "standard-version": {
58
+ "types": [
59
+ {
60
+ "type": "feat",
61
+ "section": "✨ Features | 新功能"
62
+ },
63
+ {
64
+ "type": "fix",
65
+ "section": "🐛 Bug Fixes | Bug 修复"
66
+ },
67
+ {
68
+ "type": "init",
69
+ "section": "🎉 Init | 初始化"
70
+ },
71
+ {
72
+ "type": "docs",
73
+ "section": "✏️ Documentation | 文档"
74
+ },
75
+ {
76
+ "type": "style",
77
+ "section": "💄 Styles | 风格"
78
+ },
79
+ {
80
+ "type": "refactor",
81
+ "section": "♻️ Code Refactoring | 代码重构"
82
+ },
83
+ {
84
+ "type": "perf",
85
+ "section": "⚡ Performance Improvements | 性能优化"
86
+ },
87
+ {
88
+ "type": "test",
89
+ "section": "✅ Tests | 测试"
90
+ },
91
+ {
92
+ "type": "revert",
93
+ "section": "⏪ Revert | 回退",
94
+ "hidden": true
95
+ },
96
+ {
97
+ "type": "build",
98
+ "section": "📦‍ Build System | 打包构建"
99
+ },
100
+ {
101
+ "type": "chore",
102
+ "section": "🚀 Chore | 构建/工程依赖/工具"
103
+ },
104
+ {
105
+ "type": "ci",
106
+ "section": "👷 Continuous Integration | CI 配置"
107
+ }
108
+ ],
109
+ "skip": {
110
+ "bump": true,
111
+ "changelog": true,
112
+ "commit": true,
113
+ "tag": true
114
+ },
58
115
  "scripts": {
59
116
  "prerelease": "npm run lint && npm run format && git add -A ."
60
117
  }