
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@lifebyspot/ts-transform-inject-environment-variables
Advanced tools
Injects hardcodede environment variables at compile time
This ttsc
compliant transformer allows you to inject environment variables on your code at compile time.
This is done by replacing the initializers of variable declarations. You can learn how to do that, too!
Run npm install
to save the package in your project.
npm install -D @lifebyspot/ts-transform-inject-environment-variables
Basically, there's two main scenarios you can use to inject variables using this plugin.
First, the variables defined using process.env
as initializer.
export const API_BASE_URL = process.env.API_BASE_URL;
export let ASDASDASDASD = process.env.ASDASDASDASD;
or
export const API_BASE_URL = process.env['API_BASE_URL'];
Will be converted into:
export const API_BASE_URL = 'https://api.example.com';
export let ASDASDASDASD;
Second, the variables defined using a destructuring syntax.
export const { API_BASE_URL } = process.env;
Will be converted into:
export const { API_BASE_URL = 'https://api.example.com' } = {};
Bonus: If no environment variable is found, the variable will be uninitialized. However, it's possible to use the nullish coalescing operator or object destructuring default values to define a default value to assign when this happens.
const { HOME = '/root' } = process.env;
const PATH = process.env.PATH ?? '/bin:/usr/bin';
Will be converted to:
const { HOME = '/root' } = {};
const PATH = '/bin:/usr/bin';
Note: Do not define variables that might be undefined as
const
.
export const ASDASDASDASD = process.env.ASDASDASDASD;
This is because, when running the compiled version, would end up with an uninitialized
const
variable, which is basically a violation of Javascript's rules.
export const ASDASDASDASD; // Not valid
Add the plugin to the plugins
list on tsconfig.json
.
{
// ...
"compilerOptions": {
"plugins": [
{
"transform": "@lifebyspot/ts-transform-inject-environment-variables",
"type": "config"
}
]
}
// ...
}
Just run ttsc
against your project working directory. That it.
Just send an issue or a PR! ;)
FAQs
Injects hardcodede environment variables at compile time
We found that @lifebyspot/ts-transform-inject-environment-variables demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.