{"id":13602381,"url":"https://github.com/dennzimm/npmrc-replace-env","last_synced_at":"2025-04-15T04:11:41.290Z","repository":{"id":222798915,"uuid":"758415102","full_name":"dennzimm/npmrc-replace-env","owner":"dennzimm","description":"A utility for generating .npmrc files based on configuration template and environment variables.","archived":false,"fork":false,"pushed_at":"2024-06-25T05:39:23.000Z","size":139,"stargazers_count":18,"open_issues_count":10,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T11:40:32.275Z","etag":null,"topics":["automation","cli","config","config-template","configuration","devops","env","environment-variables","generator","npmrc","npmrc-generator","utility"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/npmrc-replace-env","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dennzimm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-16T09:17:42.000Z","updated_at":"2025-01-13T08:02:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"bc738b95-43f4-4b4e-ab3c-02fb272345a5","html_url":"https://github.com/dennzimm/npmrc-replace-env","commit_stats":{"total_commits":35,"total_committers":5,"mean_commits":7.0,"dds":0.5714285714285714,"last_synced_commit":"2304a66ac3f8b10e25fe17b6a72a90b83a672f59"},"previous_names":["dennzimm/npmrc-replace-env"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennzimm%2Fnpmrc-replace-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennzimm%2Fnpmrc-replace-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennzimm%2Fnpmrc-replace-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dennzimm%2Fnpmrc-replace-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dennzimm","download_url":"https://codeload.github.com/dennzimm/npmrc-replace-env/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003954,"owners_count":21196793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","cli","config","config-template","configuration","devops","env","environment-variables","generator","npmrc","npmrc-generator","utility"],"created_at":"2024-08-01T18:01:21.818Z","updated_at":"2025-04-15T04:11:41.269Z","avatar_url":"https://github.com/dennzimm.png","language":"TypeScript","funding_links":[],"categories":["cli"],"sub_categories":[],"readme":"# npmrc-replace-env\n\n**A utility for dynamically generating .npmrc files based on configuration and environment variables.**\n\nManaging npm registry configurations and authentication tokens across different projects and environments can be cumbersome. This package aims to simplify this process by providing a utility that dynamically generates the `.npmrc` file based on a configuration file (`.npmrc.config`) and corresponding environment variables (`.env`).\n\nThis approach prioritizes security, preventing inadvertent exposure of sensitive information, like auth tokens in your `.npmrc` file, in version control systems.\n\nCheck out my article for a quick overview and insights about this utility [here](https://dev.to/dennzimm/how-to-replace-environment-variables-in-a-npmrc-file-jpg)!\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage](#usage)\n- [Configuration](#configuration)\n  - [Define Environment Variables in .env](#define-environment-variables-in-env)\n- [Command Line Options](#command-line-options)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Installation\n\n```bash\nnpm install npmrc-replace-env\n\nyarn add npmrc-replace-env\n\npnpm add npmrc-replace-env\n```\n\n**Note**: While installing the package is an option, it's important to note that it's not required to use the utility. The utility can be invoked directly with npx without installing the package.\n\n## Usage\n\nRun the utility using npx:\n\n```bash\nnpx npmrc-replace-env\n```\n\nThis will generate a `.npmrc` file (or override any existing `.npmrc` files) based on the configuration provided in a file named `.npmrc.config`.\n\n## Configuration\n\nCreate a file named `.npmrc.config` in the root of your project. This file should contain the configuration for your `.npmrc` file. The utility will replace placeholders in this configuration with corresponding environment variables.\n\nExample `.npmrc.config`:\n\n```plaintext\n# .npmrc.config\n\n# Custom registry for @myorg packages\n@myorg:registry=https://somewhere-else.com/myorg\n//somewhere-else.com/myorg/:_authToken=NPMRC_MYTOKEN1\n\n# Custom registry for @another packages\n@another:registry=https://somewhere-else.com/another\n//somewhere-else.com/another/:_authToken=NPMRC_MYTOKEN2\n\n# Custom registry for @fortawesome packages\n@fortawesome:registry=https://npm.fontawesome.com/\n//npm.fontawesome.com/:_authToken=NPMRC_FA_AUTH_TOKEN\n```\n\nIn this example, the `.npmrc.config` file defines custom registries for @myorg, @another, and @fortawesome. The authentication tokens are provided as environment variables (`NPMRC_MYTOKEN1`, `NPMRC_MYTOKEN2`, and `NPMRC_FA_AUTH_TOKEN`), which will be replaced during the generation process.\n\nIt's important to add `.npmrc` to your `.gitignore` file to prevent accidentally committing sensitive information, such as authentication tokens. Ensure that your `.npmrc` file is listed in `.gitignore` to maintain the security of your project.\n\n## Define Environment Variables in .env\n\nDefine environment variables in your `.env` file to be replaced during the generation process. Ensure that every placeholder and defined environment variable starts with `NPMRC_` to be loaded and replaced correctly.\n\nCreate a file named `.env` in the root of your project. This file will contain the environment variables used in your application. You can also create environment-specific files like `.env.local`, `.env.development`, `.env.development.local`, etc.\n\nExample `.env` file:\n\n```dotenv\nNPMRC_MYTOKEN1=your_myorg_token_value\nNPMRC_MYTOKEN2=your_another_token_value\nNPMRC_FA_AUTH_TOKEN=your_fontawesome_token_value\n```\n\n**Note**: By default, the utility expects environment variables to begin with the prefix `NPMRC_`, as shown in the example above. This default behavior can be customized using command-line options. For more information on customizing the prefix for environment variables, refer to the [Command Line Options](#command-line-options) section below.\n\nFor more detailed configuration options and information about using `.env` files, refer to the [dotenv-flow documentation](https://www.npmjs.com/package/dotenv-flow).\n\n## Command Line Options\n\nThe utility supports the following command-line options for customization:\n\n| Option             | Alias | Description                                     | Default  |\n| ------------------ | ----- | ----------------------------------------------- | -------- |\n| `--prefix`         | `-p`  | Custom environment variable prefix              | `NPMRC_` |\n| `--without-prefix` | `-w`  | Do not use any prefix for environment variables | `false`  |\n\nThese options provide flexibility in configuring environment variables and allow tailoring the utility to your specific needs.\n\n**Note**: To display the help message for command-line options, use the `--help` or `-h` option when invoking the utility:\n\n## Contributing\n\nContributions are welcome! If you encounter issues or have suggestions, please feel free to open an [issue](https://github.com/dennzimm/npmrc-replace-env/issues) or submit a [pull request](https://github.com/dennzimm/npmrc-replace-env/pulls).\n\nThis package uses [Changesets](https://github.com/changesets/changesets/tree/main) for version management. For further information on contributing and working with Changesets, refer to the Changesets Documentation: [Using Changesets](https://github.com/changesets/changesets/blob/main/docs/intro-to-using-changesets.md).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdennzimm%2Fnpmrc-replace-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdennzimm%2Fnpmrc-replace-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdennzimm%2Fnpmrc-replace-env/lists"}