Socket
Socket
Sign inDemoInstall

@import-meta-env/babel

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@import-meta-env/babel - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

47

dist/index.js

@@ -102,4 +102,2 @@ var __create = Object.create;

// ../shared/constant.ts
var virtualFile = "import-meta-env";
var virtualId = "\0" + virtualFile;
var uniqueVariableName = (() => {

@@ -110,3 +108,2 @@ const uniqueVariableName2 = "import_meta_env_unique_id_";

var envFilePath = ".env";
var envExampleFilePath = ".env.example";

@@ -118,3 +115,3 @@ // ../shared/resolve-env.ts

envFilePath: envFilePath2,
envExampleFilePath: envExampleFilePath2
envExampleFilePath
}) => {

@@ -129,7 +126,8 @@ const parsed = (() => {

const parsedExample = (() => {
const { parsed: parsed2, error } = (0, import_dotenv.config)({ path: envExampleFilePath2 });
const { parsed: parsed2, error } = (0, import_dotenv.config)({ path: envExampleFilePath });
if (error === void 0) {
return parsed2;
}
console.warn((0, import_picocolors.yellow)("[import-meta-env]: .env.example file not found, skip process.\n"));
console.warn((0, import_picocolors.yellow)(`[import-meta-env]: ${envExampleFilePath} file not found, skip process.
`));
return {};

@@ -148,3 +146,3 @@ })();

"",
`The following variables were defined in .env.example file but are not defined in the environment:`,
`The following variables were defined in ${envExampleFilePath} file but are not defined in the environment:`,
"",

@@ -158,3 +156,3 @@ "```",

`- Add them to .env file.`,
`- Remove them from .env.example file.`,
`- Remove them from ${envExampleFilePath} file.`,
""

@@ -174,13 +172,14 @@ ].join("\n");

}) {
const env = resolveEnv({
envFilePath,
envExampleFilePath
});
let env = void 0;
const isVite = process.env.npm_package_devDependencies_vite || process.env.npm_package_dependencies_vite;
const viteSpecificEnv = isVite ? {
NODE_ENV: process.env.NODE_ENV || "test",
MODE: process.env.NODE_ENV || "test",
BASE_URL: "/",
DEV: process.env.NODE_ENV !== "production",
PROD: process.env.NODE_ENV === "production"
} : {};
const replaceEnv = (template2) => template2.expression.ast(`{
...${JSON.stringify(env)},
NODE_ENV: process.env.NODE_ENV || 'test',
MODE: process.env.NODE_ENV || 'test',
BASE_URL: '/',
DEV: process.env.NODE_ENV !== 'production',
PROD: process.env.NODE_ENV === 'production'
...${JSON.stringify(viteSpecificEnv)},
}`);

@@ -190,3 +189,4 @@ return {

visitor: {
MetaProperty(path) {
MetaProperty(path, state) {
var _a, _b;
if (!t.isMemberExpression(path.parentPath.node))

@@ -196,2 +196,13 @@ return;

return;
if (env === void 0) {
let envFilePath2 = ((_a = state.opts) == null ? void 0 : _a.env) || envFilePath;
let envExampleFilePath = (_b = state.opts) == null ? void 0 : _b.example;
if (envExampleFilePath === void 0) {
throw Error(`example option is required. Please specify it in the plugin options.`);
}
env = resolveEnv({
envFilePath: envFilePath2,
envExampleFilePath
});
}
path.parentPath.replaceWith(replaceEnv(template));

@@ -198,0 +209,0 @@ }

{
"name": "@import-meta-env/babel",
"version": "0.1.3",
"version": "0.1.4",
"description": "Load environment variables into import.meta.env object",

@@ -35,3 +35,3 @@ "license": "MIT",

},
"readme": "# @import-meta-env/babel\n\n[![CI](https://github.com/iendeavor/import-meta-env/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/iendeavor/import-meta-env/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/@import-meta-env/babel.svg)](https://www.npmjs.com/package/@import-meta-env/babel)\n[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nThis plugin is intended to provide an approximation of some of [import-meta-env](https://github.com/iendeavor/import-meta-env) specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner.\n\n⚠ The functionality within these transformations should not be relied upon in production.\n\n<br>\n\nThis project use [SemVer](https://semver.org/) for versioning. For the versions available, see the tags on this repository.\n\n## 🚀 Quick Start\n\nInstall and register the plugin:\n\n```sh\n$ npm i @import-meta-env/babel\n```\n\n```js\n// babel.config.js\nmodule.exports = {\n plugins: [\"module:@import-meta-env/babel\"],\n};\n```\n\nAdjust scripts in your package.json or elsewhere:\n\n```json\n{\n \"scripts\": {\n // If you have a `.env` file:\n \"foo\": \"foo\",\n // If you don't have a `.env` file:\n \"foo\": \"cross-env S3_BUCKET=YOURS3BUCKET foo\"\n }\n}\n```\n\nSee also:\n\n- [examples](./examples)\n- [@import-meta-env/cli](https://github.com/iendeavor/import-meta-env/tree/main/packages/cli) - A binary package is used to inject environment variables into those placeholders.\n- [@import-meta-env/unplugin](https://github.com/iendeavor/import-meta-env/tree/main/packages/unplugin) - Inject environment variables into the import.meta.env object after building the application instead of statically replacing it during production.\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details\n"
"readme": "# @import-meta-env/babel\n\n[![CI](https://github.com/iendeavor/import-meta-env/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/iendeavor/import-meta-env/actions/workflows/ci.yml)\n[![NPM version](https://img.shields.io/npm/v/@import-meta-env/babel.svg)](https://www.npmjs.com/package/@import-meta-env/babel)\n[![PRs Welcome](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\nThis plugin is intended to provide an approximation of some of [import-meta-env](https://github.com/iendeavor/import-meta-env) specific transformations when running the code in other environments, for example, running tests with a NodeJS based test runner.\n\n⚠ The functionality within these transformations should not be relied upon in production.\n\n<br>\n\nThis project use [SemVer](https://semver.org/) for versioning. For the versions available, see the tags on this repository.\n\n## Quick Start\n\nInstall and register the plugin:\n\n```sh\n$ npm i @import-meta-env/babel\n```\n\n```js\n// babel.config.js\nmodule.exports = {\n plugins: [[\"module:@import-meta-env/babel\", { example: \".env.example\" }]],\n};\n```\n\nAdjust scripts in your package.json or elsewhere:\n\n```json\n{\n \"scripts\": {\n // If you have a `.env` file:\n \"test\": \"jest\",\n // If you don't have a `.env` file:\n \"test\": \"cross-env S3_BUCKET=YOURS3BUCKET jest\"\n }\n}\n```\n\nSee also:\n\n- [examples](https://github.com/iendeavor/import-meta-env/tree/main/packages/examples)\n- [@import-meta-env/cli](https://github.com/iendeavor/import-meta-env/tree/main/packages/cli) - A binary package is used to inject environment variables into those placeholders.\n- [@import-meta-env/unplugin](https://github.com/iendeavor/import-meta-env/tree/main/packages/unplugin) - Inject environment variables into the import.meta.env object after building the application instead of statically replacing it during production.\n\n## Plugin Options\n\n```js\n// babel.config.js\nmodule.exports = {\n plugins: [\n [\n \"module:@import-meta-env/babel\",\n /* Plugin options goes here */\n {\n env: \".env.example\",\n },\n ],\n ],\n};\n```\n\n```ts\ninterface PluginOptions {\n /**\n * The .env file path to load\n *\n * @default \".env\"\n */\n env?: string;\n\n /**\n * The .env example file path to load\n */\n example: string;\n}\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details\n"
}

@@ -15,3 +15,3 @@ # @import-meta-env/babel

## 🚀 Quick Start
## Quick Start

@@ -27,3 +27,3 @@ Install and register the plugin:

module.exports = {
plugins: ["module:@import-meta-env/babel"],
plugins: [["module:@import-meta-env/babel", { example: ".env.example" }]],
};

@@ -38,5 +38,5 @@ ```

// If you have a `.env` file:
"foo": "foo",
"test": "jest",
// If you don't have a `.env` file:
"foo": "cross-env S3_BUCKET=YOURS3BUCKET foo"
"test": "cross-env S3_BUCKET=YOURS3BUCKET jest"
}

@@ -48,8 +48,41 @@ }

- [examples](./examples)
- [examples](https://github.com/iendeavor/import-meta-env/tree/main/packages/examples)
- [@import-meta-env/cli](https://github.com/iendeavor/import-meta-env/tree/main/packages/cli) - A binary package is used to inject environment variables into those placeholders.
- [@import-meta-env/unplugin](https://github.com/iendeavor/import-meta-env/tree/main/packages/unplugin) - Inject environment variables into the import.meta.env object after building the application instead of statically replacing it during production.
## 📝 License
## Plugin Options
```js
// babel.config.js
module.exports = {
plugins: [
[
"module:@import-meta-env/babel",
/* Plugin options goes here */
{
env: ".env.example",
},
],
],
};
```
```ts
interface PluginOptions {
/**
* The .env file path to load
*
* @default ".env"
*/
env?: string;
/**
* The .env example file path to load
*/
example: string;
}
```
## License
This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc