mdevils / html-entities

Fastest HTML entities encode/decode library
MIT License
630 stars 85 forks source link

Build fails #94

Open markg85 opened 1 month ago

markg85 commented 1 month ago
❯ npm run build

> html-entities@2.5.2 build
> rm -Rf lib/* && tsc && npm run remove-unused-declarations && npm run flow-type-gen && npm run minimize-lib-files && npm run test:lib

src/surrogate-pairs.ts:10:29 - error TS2774: This condition will always return true since the function is always defined. Did you mean to call it instead?

10 export const getCodePoint = String.prototype.codePointAt
                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Found 1 error.

Nodejs version:

❯ node --version
v22.5.1

This is with the current git version of this library. I haven't tried other versions.

markg85 commented 1 month ago

This fix seems to work though.

❯ git diff
diff --git a/src/surrogate-pairs.ts b/src/surrogate-pairs.ts
index 7d77744..69976f0 100644
--- a/src/surrogate-pairs.ts
+++ b/src/surrogate-pairs.ts
@@ -7,7 +7,7 @@ export const fromCodePoint =
         );
     };

-export const getCodePoint = String.prototype.codePointAt
+export const getCodePoint = typeof String.prototype.codePointAt === 'function'
     ? function (input: string, position: number) {
           return input.codePointAt(position);
       }

Disclaimer, I did not try anything except making it compile.

mdevils commented 1 month ago

Hello Mark,

How do I reproduce this issue?

This is what I tried:

$ git clone git@github.com:mdevils/html-entities.git
$ cd html-entities
$ node -v
v22.7.0
$ npm i
$ npm run build

And got no problems.

markg85 commented 1 month ago

Ah, found the "issue".

I did yarn install instead of npm install Often this doesn't matter much and both work just fine.

In this case... the resulting yarn install will give (when running npm run build) the above error. Using npm for the install and run works just fine.

Could be not a bug, could still be an issue. I don't know, up to you :)