Skip to content

Commit 2f8bc55

Browse files
committed
🐛 Fix: ts error
1 parent e65703f commit 2f8bc55

File tree

8 files changed

+5205
-3936
lines changed

8 files changed

+5205
-3936
lines changed

.vscode/settings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"editor.codeActionsOnSave": {
3-
"source.fixAll.eslint": true
4-
},
3+
"source.fixAll.eslint": "explicit"
4+
},
55
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"build": "tsc -p .",
1313
"dev": "tsc -w -p .",
1414
"cz": "git-cz",
15-
"release": "bump-version"
15+
"release": "bump-version",
16+
"lint": "tsc --noEmit"
1617
},
1718
"keywords": [
1819
"picgo",
@@ -55,7 +56,7 @@
5556
"eslint-plugin-node": "^11.1.0",
5657
"eslint-plugin-promise": "^6.0.0",
5758
"husky": "^2.7.0",
58-
"picgo": "1.5.0-alpha.15",
59+
"picgo": "1.5.11",
5960
"typescript": "^4.7.4"
6061
},
6162
"dependencies": {

pnpm-lock.yaml

Lines changed: 5180 additions & 3913 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const replaceAll = (content: string, originText: string, replaceText: string): s
1616
}
1717
const checkVersion = (ctx: PicGo, guiApi: any): void => {
1818
if (guiApi) {
19-
const picgoVersion = ctx.GUI_VERSION || '1.0.0'
19+
const picgoVersion = ctx.GUI_VERSION ?? '1.0.0'
2020
if (compare(picgoVersion, '2.3.0', '<')) {
2121
ctx.emit('notification', {
2222
title: 'PicGo version is lower than 2.3.0',
@@ -199,7 +199,7 @@ const config = (ctx: PicGo): IPluginConfig[] => {
199199
return $T('PIC_MIGRATER_CONFIG_TIPS')
200200
},
201201
type: 'input',
202-
default: userConfig.include || '',
202+
default: userConfig.include ?? '',
203203
required: false
204204
},
205205
{
@@ -211,7 +211,7 @@ const config = (ctx: PicGo): IPluginConfig[] => {
211211
return $T('PIC_MIGRATER_CONFIG_TIPS')
212212
},
213213
type: 'input',
214-
default: userConfig.exclude || '',
214+
default: userConfig.exclude ?? '',
215215
required: false
216216
},
217217
{
@@ -244,7 +244,7 @@ export = (ctx: PicGo) => {
244244
return
245245
}
246246
files = files.map((item) => path.resolve(item))
247-
let inputFiles = []
247+
let inputFiles: string[] = []
248248
for (const filePath of files) {
249249
// make sure filePath exists
250250
if (fs.existsSync(filePath)) {

src/lib/FileHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ class FileHandler {
2525

2626
getUrlListFromFileContent (file: string): void {
2727
const content = this.fileList[file] || ''
28-
const markdownURLList = (content.match(/\!\[.*\]\(.*\)/g) || []).map((item: string) => {
28+
const markdownURLList = (content.match(/\!\[.*\]\(.*\)/g) ?? []).map((item: string) => {
2929
const res = item.match(/\!\[.*\]\((.*?)( ".*")?\)/)
3030
if (res) {
3131
return res[1]
3232
}
3333
return null
34-
}).filter(item => item)
35-
const imageTagURLList = (content.match(/<img.*?(?:>|\/>)/gi) || []).map((item: string) => {
34+
}).filter(item => item) as string[]
35+
const imageTagURLList = (content.match(/<img.*?(?:>|\/>)/gi) ?? []).map((item: string) => {
3636
const res = item.match(/src=[\'\"]?([^\'\"]*)[\'\"]?/i)
3737
if (res) {
3838
return res[1]
3939
}
4040
return null
41-
}).filter(item => item)
41+
}).filter(item => item) as string[]
4242
const urls = markdownURLList.concat(imageTagURLList)
4343
this.urlList[file] = {}
4444
for (const url of urls) {

src/lib/Migrater.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class Migrater {
2626
'picBed.transformer': 'base64'
2727
})
2828
this.ctx.output = [] // a bug before picgo v1.2.2
29-
const include: string | null = this.ctx.getConfig('picgo-plugin-pic-migrater.include') || null
30-
const exclude: string | null = this.ctx.getConfig('picgo-plugin-pic-migrater.exclude') || null
29+
const include: string | null = this.ctx.getConfig('picgo-plugin-pic-migrater.include') ?? 'null'
30+
const exclude: string | null = this.ctx.getConfig('picgo-plugin-pic-migrater.exclude') ?? 'null'
3131
const includesReg = new RegExp(include)
3232
const excludesReg = new RegExp(exclude)
3333

@@ -42,11 +42,11 @@ class Migrater {
4242
}
4343

4444
const toUploadURLs = this.urlArray.filter(url => ((!include || includesReg.test(url)) && (!exclude || !excludesReg.test(url)))).map(async url => {
45-
return await new Promise<IImgInfo>(async (resolve, reject): Promise<void> => {
45+
return await new Promise<IImgInfo | undefined>(async (resolve, reject): Promise<void> => {
4646
result.total += 1
4747

4848
try {
49-
let imgInfo: IImgInfo
49+
let imgInfo: IImgInfo | undefined
5050
const isUrlPath = isUrl(url)
5151
if (isUrlPath) {
5252
imgInfo = await this.handlePicFromURL(url)
@@ -70,7 +70,7 @@ class Migrater {
7070
const toUploadImgs = await Promise.all(toUploadURLs).then(imgs => imgs.filter(img => img !== undefined))
7171

7272
// upload
73-
let output = []
73+
let output: IImgInfo[] = []
7474
if (toUploadImgs && toUploadImgs.length > 0) {
7575
if (this.guiApi) {
7676
output = await this.guiApi.upload(toUploadImgs)
@@ -91,7 +91,7 @@ class Migrater {
9191
result.urls = output.filter(item => item.imgUrl && item.imgUrl !== item.origin).map(item => {
9292
return {
9393
original: item.origin,
94-
new: item.imgUrl
94+
new: item.imgUrl as string
9595
}
9696
})
9797
result.success = result.urls.length
@@ -166,7 +166,7 @@ class Migrater {
166166
fileName,
167167
width: imgSize.width,
168168
height: imgSize.height,
169-
extname: `.${imgSize.type || 'png'}`,
169+
extname: `.${imgSize.type ?? 'png'}`,
170170
origin: url
171171
}
172172
} catch (e) {

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ interface IImgSizeInfo extends IImgSize {
77

88
export const getImageSize = (buffer: Buffer): IImgSizeInfo => {
99
try {
10-
const size = sizeOf(buffer)
10+
const size = sizeOf(buffer as Uint8Array)
1111
return {
1212
real: true,
13-
width: size.width,
14-
height: size.height,
13+
width: size.width ?? 0,
14+
height: size.height ?? 0,
1515
type: size.type
1616
}
1717
} catch (e) {

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"resolveJsonModule": true,
66
"esModuleInterop": true,
77
"allowSyntheticDefaultImports": true,
8+
"strictNullChecks": true,
89
"sourceMap": false,
910
"target": "es2017",
1011
"declaration": true,
@@ -30,4 +31,4 @@
3031
"include": [
3132
"./src/**/*"
3233
]
33-
}
34+
}

0 commit comments

Comments
 (0)