tolgee / tolgee-cli

The Tolgee CLI
MIT License
15 stars 11 forks source link

Custom extractor on Windows #75

Open EtienneGuilletPackative opened 5 months ago

EtienneGuilletPackative commented 5 months ago

Hello, Whille running the following command on a Windows env tolgee sync -e './libraries/common/react-emails/scripts/extractor.ts' './libraries/common/react-emails/**/*.ts?(x)'

I get the following error

🐭🔴     Analyzing code...
🔴 An unexpected error occurred while running the command.
🔴 Please report this to our issue tracker: https://github.com/tolgee/tolgee-cli/issues
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for /mnt/c/Users/etienne_packative/Dev/coreboard/libraries/common/react-emails/scripts/extractor.ts
    at new NodeError (node:internal/errors:399:5)
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:79:11)
    at defaultGetFormat (node:internal/modules/esm/get_format:121:38)
    at defaultLoad (node:internal/modules/esm/load:81:20)
    at nextLoad (node:internal/modules/esm/loader:163:28)
    at ESMLoader.load (node:internal/modules/esm/loader:605:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:457:22)
    at new ModuleJob (node:internal/modules/esm/module_job:64:26)
    at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:480:17)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:434:34)

I don't have any problem with the CLI on Windows otherwise

cyyynthia commented 5 months ago

It seems TypeScript file support is in a broken stage at this time and would need some changes (and potential redesign of how it is handled)

For future reference: ts-node seems to not be able to properly hook into Node and the Node docs seem to indicate the proper hooks to bring things back is 20.6.x only, so that option is no longer viable.

The direction to take is probably to do something similar to how Vite loads its config file: simply bundle the file ourselves using typescript and write it to a temporary location so we can import it as a plain mjs file - essentially what ts-node was doing but this time it should be way more stable and future proof

OrenChapo commented 5 months ago

I'm not sure this issue is limited to TypeScript. Seems broken on Windows with a .js extractor as well.

MathisBarre commented 5 months ago

Broken on MacOS too ts-node v10.9.2 node.js v20.6.1 tolgee-cli v1.4.0

nikolap commented 3 months ago

Also ran into issue on macos and linux. Was able to work around this mess by converting the custom extractor to commonjs (note not ES module, so module.exports = ..., etc.).

Only ran into this problem because the way to programatically delete keys is through running the sync command or writing our own script (not there yet thankfully). Quite a run around 🥴