Coder Social home page Coder Social logo

ssssota / typedotenv Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 1.0 173 KB

dotenv utility for TypeScript

Home Page: https://ssssota.github.io/typedotenv/

License: Apache License 2.0

TypeScript 92.42% HTML 1.70% CSS 5.88%
cli code-generation dotenv typescript unplugin vite webpack

typedotenv's Introduction

typedotenv

dotenv utility for TypeScript

Example

.env

API_KEY=qwertyuiop
NEXT_PUBLIC_API_BASE_URL=http://example.com/

env.ts (generated TypeScript code)

/* Auto generated by typedotenv */
if (typeof process.env.API_KEY !== 'string') throw new Error('API_KEY is not defined in .env');
export const API_KEY = process.env.API_KEY;
if (typeof process.env.NEXT_PUBLIC_API_BASE_URL !== 'string') throw new Error('NEXT_PUBLIC_API_BASE_URL is not defined in .env');
export const NEXT_PUBLIC_API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL;

disableRuntimeTypeCheck:true & enableTypeAssetion:true & envObject:'import.meta.env'

/* Auto generated by typedotenv */
export const API_KEY = import.meta.env.API_KEY as string;
export const NEXT_PUBLIC_API_BASE_URL = import.meta.env.NEXT_PUBLIC_API_BASE_URL as string;

Usage

typedotenv's People

Contributors

github-actions[bot] avatar ssssota avatar tobigumo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tobigumo

typedotenv's Issues

CLI error with process.env

cliを使うと以下のようなエラーが出ました

****/@typedotenv/cli/dist/index.cjs:3142
var command = createCommand("typedotenv").version(process2.env.npm_package_version).description(process2.env.npm_package_description).addCommand(generateCommand).addCommand(checkCommand).action((_, cmd) => {
                                                                                                                                      ^

TypeError: createCommand(...).version(...).description(...).addCommand is not a function
    at Object.<anonymous> (/Users/akindo/Documents/develop/akindoline/node_modules/@typedotenv/cli/dist/index.cjs:3142:135)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47

Node.js v18.16.1

コードの以下の部分かと思いますが、process.envの中身がundefinedになっているのを確認しました。

const command = createCommand("typedotenv")
.version(process.env.npm_package_version!)
.description(process.env.npm_package_description!)
.addCommand(generateCommand)

いろいろ試してみた結果、import * as process from "process";を削除すると、@typedotenv/cli のpackage.jsonのversionとdescriptionがビルド時に埋め込まれる形になりました。
こちらが期待する動作で良いでしょうか
もしくは使い方や環境の問題でしょうか

Optimize for bundle

バンドルする際にimportを介しているとtree shakingの文脈で不利になることがある

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.