hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
38.83k stars 4.75k forks source link

hexo build failed due to type issue #5326

Closed uiolee closed 8 months ago

uiolee commented 8 months ago

~The former one should be fixed in https://github.com/hexojs/hexo-front-matter/pull/67, but since hexo-front-matter hasn't released a new version to include this change yet, we should still stick to v4.0.0 here to prevent type error.~

~Originally posted by @Pcrab in https://github.com/hexojs/hexo/issues/5202#issuecomment-1544052137~

in #5202, we lock hexo-front-matter version to 4.0.0

https://github.com/hexojs/hexo/blob/2a2cc9a89f3f291d2ba93e3a4d7eeb3b8ba98bbe/package.json#L47

hexo build failed

after hexojs/hexo-front-matter#67, hexo still have another types issue, which leads build failed.

> hexo@7.0.0-rc2 build D:\hexojs\hexo
> tsc -b

lib/hexo/post.ts:359:36 - error TS2345: Argument of type 'string | Buffer' is not assignable to parameter of type 'string'.
  Type 'Buffer' is not assignable to type 'string'.

359       Object.assign(data, yfmParse(content));
                                       ~~~~~~~

Found 1 error.

 ELIFECYCLE  Command failed with exit code 1.
D-Sketon commented 8 months ago

It's time to release a new version of hexo-front-matter

yoshinorin commented 8 months ago

Ready for release hexo-front-matter v4.2.0.

uiolee commented 8 months ago

still exists another types issue. It leads hexo build fail. (see above)

I think it need time to investigate and update.

we could postpone this issue and release v7 first.

D-Sketon commented 8 months ago

still exists another types issue. It leads hexo build fail

I think it need time to investigate.

we could postpone this issue and release v7 first.

maybe we can fix it in https://github.com/hexojs/hexo/pull/5271 ?

D-Sketon commented 8 months ago

still exists another types issue. It leads hexo build fail. (see above)

I think it need time to investigate.

we could postpone this issue and release v7 first.

https://github.com/hexojs/hexo-fs/blob/72f16b383bce2a438aed3076e47be352f9e41d1c/lib/fs.ts#L236-L237

The file encoding defaults to utf-8, so the type is basically string

uiolee commented 8 months ago

~It seems that hexo-fs will only return string, maybe hexo-fs should be modified.~

https://nodejs.org/docs/latest-v18.x/api/fs.html#fspromisesreadfilepath-options

~https://github.com/hexojs/hexo-fs/blob/72f16b383bce2a438aed3076e47be352f9e41d1c/lib/fs.ts#L235-L246~

uiolee commented 8 months ago

The file encoding defaults to utf-8, so the type is basically string

yes

D-Sketon commented 8 months ago

Besides, I found that fs.readFile(target, null) will cause

TypeError: Cannot convert undefined or null to object

However, The signature of the writeFile function is

function readFile(path: string, options?: ReadFileOptions | null): BlueBirdPromise<string | Buffer>

null is allowed to be passed in is this a bug?

D-Sketon commented 8 months ago

still exists another types issue. It leads hexo build fail. (see above)

I think it need time to investigate and update.

we could postpone this issue and release v7 first.

fix in #5271

uiolee commented 8 months ago

fix in #5271

thanks! test passed.