Skip to content

Commit

Permalink
fix: add special case for geoip-lite (#446)
Browse files Browse the repository at this point in the history
Currently, nft can not handle data assets of `geoip-lite` package
properly. Error message like below ⬇️

<img width="1333" alt="image"
src="https://github.com/user-attachments/assets/3fe76911-33e2-4b3d-8a20-245c1e79567c">

Test Code

```js
const geoip = require('geoip-lite');

const ip = "207.97.227.239";
const geo = geoip.lookup(ip);
```

This PR adds essential data files as assets for `geoip-lite` in
special-case to solve it.
  • Loading branch information
kongmoumou authored Oct 22, 2024
1 parent 7471794 commit b3d2da0
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
76 changes: 76 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"firebase-admin": "^12.0.0",
"fluent-ffmpeg": "^2.1.2",
"geo-tz": "^7.0.1",
"geoip-lite": "^1.4.10",
"graphql": "^14.4.2",
"highlights": "^3.1.6",
"hot-shots": "^6.3.0",
Expand Down
9 changes: 9 additions & 0 deletions src/utils/special-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ const specialCases: Record<string, (o: SpecialCaseOpts) => void> = {
emitDependency(resolve(dirname(id), 'bin/pixelmatch'));
}
},
'geoip-lite'({ id, emitAsset }) {
if (id.endsWith('geoip-lite/lib/geoip.js')) {
emitAsset(resolve(dirname(id), '../data/geoip-city.dat'));
emitAsset(resolve(dirname(id), '../data/geoip-city6.dat'));
emitAsset(resolve(dirname(id), '../data/geoip-city-names.dat'));
emitAsset(resolve(dirname(id), '../data/geoip-country.dat'));
emitAsset(resolve(dirname(id), '../data/geoip-country6.dat'));
}
},
};

interface SpecialCaseOpts {
Expand Down
4 changes: 4 additions & 0 deletions test/integration/geoip-lite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const geoip = require('geoip-lite');

const ip = "207.97.227.239";
const geo = geoip.lookup(ip);

0 comments on commit b3d2da0

Please sign in to comment.