-
Notifications
You must be signed in to change notification settings - Fork 384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compileNamespace
should take package.json "type" into account
#1704
Comments
In the meantime, just posting the script I'm using as a workaround in {
"scripts":
"i18n:compile": "lingui compile && for file in locales/*/messages.js; do sed -i 's/module.exports={messages:\\(.*\\)};$/export const messages = \\1;/' $file ; done",
} It changes from |
@lukescott i think it would be more straightforward and easy to understand/use if we add a bunch of new parameters instead of one
What do you think? |
I'd also rather make this explicitly configurable, as opposed to trying to infer from package.json file. In monorepos with multiple package.json files that approach would be problematic. |
Thanks, this slight variation works for me: "compile": "lingui compile && for file in locales/*/messages.js; do sed -i '' 's/module.exports=\\({messages:.*}\\);/export const messages = \\1;/' $file; done" Would be great to have a |
When you set
"type": "module"
in your JSON both.js
and.ts
files (if you are using TypeScript) are considered modules. You only need to use the.m[jt]s
or.c[jt]s
extensions as an override.I bring this up because it also applies to TypeScript, not just vanilla JavaScript. And both can have
module.exports =
orexport const
depending on the combination of package type and extension used.I'm running into issues with babel when compiling code with a mix of
.ts
and.cts
extensions. Babel just compiles everything to.js
. There doesn't seem to be a way to solve this.Also, newer node versions unfortunately are extremely strict about this, so if you don't use the right syntax it just fails.
I would like to propose reading the package.json type and use the following logic:
compileNamespace
is"cjs"
, writemodule.exports =
to a.cjs
filecompileNamespace
is"es"
, writeexport const messages =
to a.js
filecompileNamespace
is"ts"
, writeexport const messages: AllMessages =
to a.ts
filecompileNamespace
is"cjs"
, writemodule.exports =
to a.js
filecompileNamespace
is"es"
, writeexport const messages =
to a.mjs
filecompileNamespace
is"ts"
, writeexport const messages: AllMessages =
to a.mts
fileIf this is too complicated I understand. Ideally Lingui would just have a "typescript" option and just detect the package.json type. And optionally be able to provide a custom compilation function.
The text was updated successfully, but these errors were encountered: