Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@taskworld/typescript-custom-transformer-l10n
Advanced tools
A TypeScript Custom AST transformer that inlines localization strings into the source code
A TypeScript Custom AST transformer that inlines localization strings into the source code.
Our localization file is several megabytes large now. It doesn’t play well with webpack’s code splitting. This custom AST transformer inlines the calls to localization routines with the data from localization file.
Given a source code:
function Tutorial() {
return (
<section>
<h1>{__('tutorial.welcome.headline')}</h1>
<p>{__('tutorial.welcome.paragraph')}</p>
</section>
)
}
…and a localization file:
{
"en": {
"tutorial.welcome.headline": "Welcome to %{workspace_name}",
"tutorial.welcome.paragraph": "Your team will have all that you need to get work done."
},
"th": {
"tutorial.welcome.headline": "ยินดีต้อนรับเข้าสู่ %{workspace_name}",
"tutorial.welcome.paragraph": "บริหารจัดการงานได้อย่างครบถ้วนและมีประสิทธิภาพ"
}
}
…when transpiled with this custom AST transformer, the output will look like this:
function Tutorial() {
return (
<section>
<h1>
{__(
__.$('tutorial.welcome.headline', {
en: 'Welcome to %{workspace_name}',
th: 'ยินดีต้อนรับเข้าสู่ %{workspace_name}',
})
)}
</h1>
<p>
{__(
__.$('tutorial.welcome.paragraph', {
en: 'Your team will have all that you need to get work done.',
th: 'บริหารจัดการงานได้อย่างครบถ้วนและมีประสิทธิภาพ',
})
)}
</p>
</section>
)
}
See the article How to Write a TypeScript Transform (Plugin) for how to use it in, e.g., webpack.
Important: If you use build caching, e.g. cache-loader
, make sure to set it up so that changes to the localization data would invalidate the cached build output.
FAQs
A TypeScript Custom AST transformer that inlines localization strings into the source code
We found that @taskworld/typescript-custom-transformer-l10n demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.