Using this lib with Deno
oskarkivra opened this issue · comments
Support Deno
It is possible to use this lib with Deno:
import { LokaliseApi } from "npm:@lokalise/node-api";
new LokaliseApi({ apiKey });
However, since you are importing package.json
to get the current version. E.g. here:
package.json
file next to the Deno script to get this working.
It would be awesome to support Deno. Is it possible to get the version number in some other way?
I don't think there's any other way really except for writing the version manually but it's quite tedious. Theoretically, we can simply check if the package.json
file is present and if not, set the version to unknown or something like that. If that would work for you, I can release a new version
Correct me if I'm wrong but will readFile("./package.json")
not read the package.json
that exists in the same dir as cwd
? Do this work as intended? Should it not be:
const pkg = JSON.parse((await readFile(new URL("../../package.json", import.meta.url))).toString());
That's a good question. Currently everything works fine with regular setups: I don't observe any issues with tests or trying to run this locally. I'm doing some fixes at the moment to check whether the package.json actually exists and I'll also try your solution
@oskarkivra The latest commit should hopefully fix this 747ab8c. Could you please try installing directly from GH and let me know if it works now?
Thanks for the fast reply.
I don't know if I can test this with deno in an easy way. When importing npm:@lokalise/node-api
deno will run the code in compatible mode to support node.js-code, but when pointing out a URL to github I do not think I can tell deno to run in compatible mode.
But I can close this issue and test it once it is publish to npm. No rush.
Sure, I'll release a new version now. Please let me know how it goes
Thnaks! It worked. It is not perfect but now I don't need to create a package.json file anymore:
cat test.ts
import { LokaliseApi } from "npm:@lokalise/node-api";
const api = new LokaliseApi({
apiKey: "...",
});
api.keys().get(123, {
project_id: "...",
});
➜ deno run test.ts
✅ Granted read access to "Library/Caches/deno/npm/registry.npmjs.org/@lokalise/node-api/9.4.0/package.json".
✅ Granted net access to "api.lokalise.com".
error: Uncaught { message: "Not Found", code: 404 }
➜ deno run test.ts
❌ Denied read access to "Library/Caches/deno/npm/registry.npmjs.org/@lokalise/node-api/9.4.0/package.json".
✅ Granted net access to "api.lokalise.com".
error: Uncaught { message: "Not Found", code: 404 }
Good! Any other suggestions on how to make things even better? :)
No, not really. I think this is the best way for now. Thanks for your work!
Thank you for the feedback and have a happy New Year 🥳