bini-env 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +253 -0
- package/dist/index.d.mts +37 -0
- package/dist/index.d.ts +18 -22
- package/dist/index.js +206 -102
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +235 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +53 -20
- package/Readme.md +0 -135
- package/dist/index.cjs +0 -178
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -41
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAuCA,IAAM,SAAA,GAAY,MAAA;AAClB,IAAM,kBAAA,GAA+B,CAAC,OAAA,EAAS,OAAO,CAAA;AAEtD,IAAM,eAAA,GAAkD,OAAO,MAAA,CAAO;AAAA,EACpE,OAAA,EAAS,IAAA;AAAA,EACT,eAAA,EAAiB,IAAA;AAAA,EACjB,IAAA,EAAM,SAAA;AAAA,EACN,SAAA,EAAW;AACb,CAAC,CAAA;AAUD,IAAM,QAAA,uBAAe,GAAA,EAAgC;AAU9C,SAAS,OAAO,GAAA,EAAiC;AAEtD,EAAA,IAAI,QAAA,CAAS,GAAA,CAAI,GAAG,CAAA,EAAG;AACrB,IAAA,OAAO,QAAA,CAAS,IAAI,GAAG,CAAA;AAAA,EACzB;AAEA,EAAA,IAAI,KAAA;AAGJ,EAAA,MAAM,OAAQ,UAAA,CAAmD,IAAA;AACjE,EAAA,IAAI,IAAA,EAAM;AACR,IAAA,IAAI;AACF,MAAA,KAAA,GAAQ,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,GAAG,CAAA;AACxB,MAAA,IAAI,UAAU,KAAA,CAAA,EAAW;AACvB,QAAA,QAAA,CAAS,GAAA,CAAI,KAAK,KAAK,CAAA;AACvB,QAAA,OAAO,KAAA;AAAA,MACT;AAAA,IACF,CAAA,CAAA,M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B,CAAA,MAAO;AACL,YAAA,iBAAA,CAAkB,OAAO,YAAY,CAAA;AAAA,UACvC;AAAA,QACF,CAAA;AAAA,MACF;AAAA,IACF;AAAA,GACF;AACF","file":"index.mjs","sourcesContent":["// src/index.ts\nimport fs from 'fs';\nimport path from 'path';\nimport type { Plugin, ResolvedConfig, UserConfig } from 'vite';\n\n/* ==========================================================================\n Global type declarations for cross-runtime compatibility\n ========================================================================== */\n\ninterface DenoEnv {\n get(key: string): string | undefined;\n toObject(): Record<string, string>;\n}\ninterface DenoNamespace {\n env: DenoEnv;\n}\n\n/// <reference types=\"vite/client\" />\n\n/* ==========================================================================\n Types\n ========================================================================== */\n\nexport interface BiniEnvPluginOptions {\n readonly enabled?: boolean;\n readonly clearViteHeader?: boolean;\n readonly logo?: string;\n readonly envPrefix?: string | string[];\n}\n\nexport interface DetectedEnvFile {\n readonly name: string;\n readonly path: string;\n}\n\n/* ==========================================================================\n Constants - Optimized with Object.freeze for immutability\n ========================================================================== */\n\nconst BINI_LOGO = 'ß';\nconst DEFAULT_ENV_PREFIX: string[] = ['BINI_', 'VITE_'];\n\nconst DEFAULT_OPTIONS: Required<BiniEnvPluginOptions> = Object.freeze({\n enabled: true,\n clearViteHeader: true,\n logo: BINI_LOGO,\n envPrefix: DEFAULT_ENV_PREFIX,\n});\n\n// ANSI color codes - using const enum for better performance\nconst enum COLORS {\n CYAN = '\\x1b[36m',\n RESET = '\\x1b[0m',\n GREEN = '\\x1b[32m',\n}\n\n// Cache for environment variables to avoid repeated lookups\nconst envCache = new Map<string, string | undefined>();\n\n/* ==========================================================================\n Optimized getEnv with caching\n ========================================================================== */\n\n/**\n * Read an environment variable with caching for performance.\n * Cache is cleared on module reload in development only.\n */\nexport function getEnv(key: string): string | undefined {\n // Check cache first for frequent access patterns\n if (envCache.has(key)) {\n return envCache.get(key);\n }\n\n let value: string | undefined;\n\n // 1. Deno runtime (edge functions)\n const deno = (globalThis as unknown as { Deno?: DenoNamespace }).Deno;\n if (deno) {\n try {\n value = deno.env.get(key);\n if (value !== undefined) {\n envCache.set(key, value);\n return value;\n }\n } catch {\n // Silently fall through\n }\n }\n\n // 2. Node.js / Bun runtime\n if (typeof process !== 'undefined' && process.env) {\n value = process.env[key];\n if (value !== undefined) {\n envCache.set(key, value);\n return value;\n }\n }\n\n // 3. Vite client environment (with prefix fallback)\n try {\n const metaEnv = import.meta.env as Record<string, string | undefined> | undefined;\n if (metaEnv) {\n // Direct match\n if (metaEnv[key] !== undefined) {\n envCache.set(key, metaEnv[key]);\n return metaEnv[key];\n }\n \n // Try BINI_ prefix\n const biniKey = `BINI_${key}`;\n if (metaEnv[biniKey] !== undefined) {\n envCache.set(key, metaEnv[biniKey]);\n return metaEnv[biniKey];\n }\n \n // Try VITE_ prefix\n const viteKey = `VITE_${key}`;\n if (metaEnv[viteKey] !== undefined) {\n envCache.set(key, metaEnv[viteKey]);\n return metaEnv[viteKey];\n }\n }\n } catch {\n // import.meta.env not available\n }\n\n // Cache undefined to prevent repeated lookups\n envCache.set(key, undefined);\n return undefined;\n}\n\n/**\n * Optimized requireEnv with cached error messages\n */\nexport function requireEnv(key: string): string {\n const val = getEnv(key);\n if (!val) {\n // Create error message once\n const errorMsg = `[bini-env] Missing required environment variable: \"${key}\".\\n` +\n ` → In development: add it to your .env file.\\n` +\n ` → In production: add it to your hosting dashboard environment variables.`;\n throw new Error(errorMsg);\n }\n return val;\n}\n\n/* ==========================================================================\n Optimized loadEnv with production checks\n ========================================================================== */\n\nlet _envLoaded = false;\nlet _loadPromise: Promise<void> | null = null;\n\n/**\n * Load .env file with memoization and race condition prevention\n */\nexport async function loadEnv(projectRoot?: string): Promise<void> {\n // Fast path: already loaded\n if (_envLoaded) return;\n \n // Prevent concurrent loads\n if (_loadPromise) {\n return _loadPromise;\n }\n\n _loadPromise = (async () => {\n try {\n // Deno runtime check - fast path\n if ((globalThis as unknown as { Deno?: DenoNamespace }).Deno) {\n _envLoaded = true;\n return;\n }\n\n // Node.js runtime check\n if (typeof process === 'undefined' || !process.env) {\n _envLoaded = true;\n return;\n }\n\n // Production optimization - skip file system operations entirely\n if (process.env.NODE_ENV === 'production') {\n _envLoaded = true;\n return;\n }\n\n const root = projectRoot ?? process.cwd();\n const envPath = path.join(root, '.env');\n\n // Check file existence with fs.promises for better performance\n try {\n await fs.promises.access(envPath, fs.constants.R_OK);\n } catch {\n _envLoaded = true;\n return;\n }\n\n // Dynamic import with caching\n const dotenv = await import('dotenv');\n dotenv.config({ path: envPath });\n \n // Clear cache after loading new env vars\n envCache.clear();\n } catch {\n // Silent fail - requireEnv will handle missing vars\n } finally {\n _envLoaded = true;\n _loadPromise = null;\n }\n })();\n\n return _loadPromise;\n}\n\n/* ==========================================================================\n Optimized detectEnvFiles with caching\n ========================================================================== */\n\nlet _envFilesCache: DetectedEnvFile[] | null = null;\nlet _cachedRoot: string = '';\n\nexport function detectEnvFiles(projectRoot: string = process.cwd()): DetectedEnvFile[] {\n // Cache results for the same root directory\n if (_envFilesCache && _cachedRoot === projectRoot) {\n return _envFilesCache;\n }\n\n const nodeEnv = process.env.NODE_ENV ?? 'development';\n const candidates = [\n '.env.local',\n `.env.${nodeEnv}.local`,\n `.env.${nodeEnv}`,\n '.env',\n ];\n\n const found: DetectedEnvFile[] = [];\n\n // Use for...of with early break if needed\n for (const file of candidates) {\n const filePath = path.join(projectRoot, file);\n try {\n if (fs.existsSync(filePath)) {\n found.push({ name: file, path: filePath });\n }\n } catch {\n // Skip files that can't be accessed\n }\n }\n\n // Cache the result\n _envFilesCache = found;\n _cachedRoot = projectRoot;\n \n return found;\n}\n\n/* ==========================================================================\n Optimized Vite plugin with minimal overhead\n ========================================================================== */\n\nfunction clearLine(): void {\n // Only write if stdout is a TTY (performance optimization)\n if (process.stdout.isTTY) {\n process.stdout.write('\\x1b[2K\\r');\n }\n}\n\nfunction printResolvedUrls(urls: { local: string[]; network: string[] } | null | undefined): void {\n if (!urls) return;\n if (urls.local.length > 0) {\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Local: ${COLORS.CYAN}${urls.local[0]}${COLORS.RESET}`);\n }\n if (urls.network.length > 0) {\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Network: ${COLORS.CYAN}${urls.network[0]}${COLORS.RESET}`);\n }\n}\n\n/**\n * Production-ready Vite plugin with performance optimizations:\n * - Lazy loading\n * - Caching\n * - Minimal bundle impact\n * - No runtime overhead in production\n */\nexport function biniEnv(options: Readonly<BiniEnvPluginOptions> = {}): Plugin {\n // Fast path: disabled plugin returns no-op\n if (options.enabled === false) {\n return {\n name: 'vite-plugin-bini-env',\n // Minimal plugin that does nothing\n };\n }\n\n const resolvedOptions = { ...DEFAULT_OPTIONS, ...options };\n const { clearViteHeader, logo, envPrefix } = resolvedOptions;\n\n let resolvedConfig: ResolvedConfig;\n\n return {\n name: 'vite-plugin-bini-env',\n \n // Optimized config merge\n config(): UserConfig {\n return { envPrefix };\n },\n\n configResolved(cfg: ResolvedConfig) {\n resolvedConfig = cfg;\n },\n\n // Optimized server configuration with lazy loading\n configureServer(server) {\n // Defer env loading to avoid blocking server start\n const loadEnvTask = () => {\n void loadEnv(resolvedConfig?.root ?? process.cwd());\n };\n\n if (server.httpServer) {\n server.httpServer.once('listening', loadEnvTask);\n } else {\n // Use setImmediate for non-blocking execution\n setImmediate(loadEnvTask);\n }\n\n let serverStarted = false;\n const originalPrintUrls = server.printUrls.bind(server);\n\n // Only override printUrls if needed\n if (clearViteHeader || logo !== BINI_LOGO) {\n server.printUrls = () => {\n if (serverStarted) return;\n serverStarted = true;\n\n if (clearViteHeader) clearLine();\n console.log(`\\n ${COLORS.CYAN}${logo} Bini.js${COLORS.RESET} (dev)`);\n\n // Only detect env files in development\n if (process.env.NODE_ENV !== 'production') {\n const found = detectEnvFiles(resolvedConfig?.root);\n if (found.length > 0) {\n const envString = found.map((f) => f.name).join(', ');\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Environments: ${envString}`);\n }\n }\n\n if (!clearViteHeader) {\n originalPrintUrls();\n } else {\n printResolvedUrls(server.resolvedUrls);\n }\n };\n }\n },\n\n // Preview server with same optimizations\n configurePreviewServer(server) {\n let previewStarted = false;\n const originalPrintUrls = server.printUrls.bind(server);\n\n if (clearViteHeader || logo !== BINI_LOGO) {\n server.printUrls = () => {\n if (previewStarted) return;\n previewStarted = true;\n\n if (clearViteHeader) clearLine();\n console.log(`\\n ${COLORS.CYAN}${logo} Bini.js${COLORS.RESET} (preview)`);\n\n if (process.env.NODE_ENV !== 'production') {\n const found = detectEnvFiles(resolvedConfig?.root);\n if (found.length > 0) {\n const envString = found.map((f) => f.name).join(', ');\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Environments: ${envString}`);\n }\n }\n\n if (!clearViteHeader) {\n originalPrintUrls();\n } else {\n printResolvedUrls(server.resolvedUrls);\n }\n };\n }\n },\n };\n}\n\nexport type { Plugin } from 'vite';"]}
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bini-env",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Vite plugin for Bini.js
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Universal environment variable loader and Vite plugin for Bini.js — works in Node.js, Deno, Bun, and Vite edge functions",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"type": "module",
|
|
9
8
|
"exports": {
|
|
10
9
|
".": {
|
|
11
10
|
"types": "./dist/index.d.ts",
|
|
@@ -15,47 +14,81 @@
|
|
|
15
14
|
},
|
|
16
15
|
"files": [
|
|
17
16
|
"dist",
|
|
18
|
-
"README.md"
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
19
|
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"prepublishOnly": "npm run build",
|
|
25
|
+
"test": "node --test",
|
|
26
|
+
"type-check": "tsc --noEmit"
|
|
27
|
+
},
|
|
20
28
|
"keywords": [
|
|
21
29
|
"vite",
|
|
22
30
|
"vite-plugin",
|
|
23
|
-
"bini.js",
|
|
24
31
|
"bini",
|
|
32
|
+
"bini-js",
|
|
33
|
+
"bini.js",
|
|
25
34
|
"environment",
|
|
26
35
|
"env",
|
|
27
|
-
"dotenv"
|
|
36
|
+
"dotenv",
|
|
37
|
+
"deno",
|
|
38
|
+
"edge-functions",
|
|
39
|
+
"cross-runtime",
|
|
40
|
+
"env-loader"
|
|
28
41
|
],
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/Binidu01/Bini-Env.git"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/Binidu01/Bini-Env#readme",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/Binidu01/Bini-Env/issues"
|
|
49
|
+
},
|
|
29
50
|
"author": "Bini.js Team",
|
|
30
51
|
"license": "MIT",
|
|
31
52
|
"peerDependencies": {
|
|
32
|
-
"vite": "
|
|
53
|
+
"vite": ">=8.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"vite": {
|
|
57
|
+
"optional": false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"dotenv": "^17.3.1"
|
|
33
62
|
},
|
|
34
63
|
"devDependencies": {
|
|
35
64
|
"@types/node": "^22.15.3",
|
|
36
65
|
"tsup": "^8.4.0",
|
|
37
66
|
"typescript": "^5.8.3",
|
|
38
|
-
"vite": "^
|
|
67
|
+
"vite": "^8.0.0"
|
|
39
68
|
},
|
|
40
69
|
"tsup": {
|
|
41
|
-
"entry": [
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
"format": [
|
|
45
|
-
"cjs",
|
|
46
|
-
"esm"
|
|
47
|
-
],
|
|
70
|
+
"entry": ["src/index.ts"],
|
|
71
|
+
"format": ["cjs", "esm"],
|
|
48
72
|
"dts": true,
|
|
49
73
|
"clean": true,
|
|
50
74
|
"splitting": false,
|
|
51
75
|
"sourcemap": true,
|
|
52
|
-
"minify": false
|
|
76
|
+
"minify": false,
|
|
77
|
+
"treeshake": true,
|
|
78
|
+
"shims": true,
|
|
79
|
+
"external": [
|
|
80
|
+
"vite",
|
|
81
|
+
"dotenv"
|
|
82
|
+
],
|
|
83
|
+
"noExternal": [],
|
|
84
|
+
"platform": "node",
|
|
85
|
+
"target": "node20"
|
|
53
86
|
},
|
|
54
87
|
"engines": {
|
|
55
|
-
"node": ">=
|
|
88
|
+
"node": ">=20.19.0 || >=22.12.0"
|
|
56
89
|
},
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
90
|
+
"publishConfig": {
|
|
91
|
+
"access": "public",
|
|
92
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
93
|
}
|
|
61
94
|
}
|
package/Readme.md
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
# bini-env
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-

|
|
6
|
-

|
|
7
|
-

|
|
8
|
-
|
|
9
|
-
A lightweight Vite plugin that enhances your dev and preview server output with a clean startup banner and detected `.env` files.
|
|
10
|
-
|
|
11
|
-
## Features
|
|
12
|
-
|
|
13
|
-
- Replaces Vite's default header with a clean custom banner
|
|
14
|
-
- Automatically detects and displays active `.env` files
|
|
15
|
-
- Supports `dev` and `preview` modes
|
|
16
|
-
- Fully customizable logo and behavior
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
19
|
-
```bash
|
|
20
|
-
npm install bini-env --save-dev
|
|
21
|
-
# or
|
|
22
|
-
pnpm add -D bini-env
|
|
23
|
-
# or
|
|
24
|
-
yarn add -D bini-env
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## Usage
|
|
28
|
-
```ts
|
|
29
|
-
// vite.config.ts
|
|
30
|
-
import { defineConfig } from 'vite';
|
|
31
|
-
import biniEnv from 'bini-env';
|
|
32
|
-
|
|
33
|
-
export default defineConfig({
|
|
34
|
-
plugins: [biniEnv()]
|
|
35
|
-
});
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
## Output Example
|
|
39
|
-
|
|
40
|
-
**Dev mode**
|
|
41
|
-
```
|
|
42
|
-
ß Bini.js (dev)
|
|
43
|
-
➜ Environments: .env.local, .env
|
|
44
|
-
➜ Local: http://localhost:5173/
|
|
45
|
-
➜ Network: http://192.168.1.10:5173/
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
**Preview mode**
|
|
49
|
-
```
|
|
50
|
-
ß Bini.js (preview)
|
|
51
|
-
➜ Environments: .env.local, .env
|
|
52
|
-
➜ Local: http://localhost:4173/
|
|
53
|
-
➜ Network: http://192.168.1.10:4173/
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Options
|
|
57
|
-
|
|
58
|
-
| Option | Type | Default | Description |
|
|
59
|
-
|--------|------|---------|-------------|
|
|
60
|
-
| `enabled` | `boolean` | `true` | Enable or disable the plugin |
|
|
61
|
-
| `clearViteHeader` | `boolean` | `true` | Replace Vite's default startup header |
|
|
62
|
-
| `logo` | `string` | `'ß'` | Custom logo or text shown in the banner |
|
|
63
|
-
|
|
64
|
-
### Example with options
|
|
65
|
-
```ts
|
|
66
|
-
biniEnv({
|
|
67
|
-
logo: '🚀',
|
|
68
|
-
clearViteHeader: true,
|
|
69
|
-
})
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## Detected `.env` Files
|
|
73
|
-
|
|
74
|
-
The plugin checks for the following files in your project root (in priority order):
|
|
75
|
-
|
|
76
|
-
1. `.env.local`
|
|
77
|
-
2. `.env.[NODE_ENV].local`
|
|
78
|
-
3. `.env.[NODE_ENV]`
|
|
79
|
-
4. `.env`
|
|
80
|
-
|
|
81
|
-
Any files found are displayed in the banner on startup.
|
|
82
|
-
|
|
83
|
-
## Modes
|
|
84
|
-
|
|
85
|
-
| Mode | Trigger | Banner |
|
|
86
|
-
|------|---------|--------|
|
|
87
|
-
| Development | `vite dev` | `ß Bini.js (dev)` |
|
|
88
|
-
| Preview | `vite preview` | `ß Bini.js (preview)` |
|
|
89
|
-
|
|
90
|
-
> **Note:** `bini-env` is a server-only plugin (`apply: 'serve'`) and does not run during `vite build`.
|
|
91
|
-
|
|
92
|
-
## API
|
|
93
|
-
|
|
94
|
-
The following utilities are exported for use outside of the plugin if needed.
|
|
95
|
-
|
|
96
|
-
### `detectEnvFiles(projectRoot?: string): DetectedEnvFile[]`
|
|
97
|
-
|
|
98
|
-
Scans a directory for `.env` files and returns an array of matches.
|
|
99
|
-
```ts
|
|
100
|
-
import { detectEnvFiles } from 'bini-env';
|
|
101
|
-
|
|
102
|
-
const files = detectEnvFiles('/my/project');
|
|
103
|
-
// [{ name: '.env.local', path: '/my/project/.env.local' }, ...]
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
Defaults to `process.cwd()` if no path is provided.
|
|
107
|
-
|
|
108
|
-
### `formatEnvFilesForDisplay(envFiles: DetectedEnvFile[]): string`
|
|
109
|
-
|
|
110
|
-
Formats a list of detected env files into a display-ready console string.
|
|
111
|
-
```ts
|
|
112
|
-
import { detectEnvFiles, formatEnvFilesForDisplay } from 'bini-env';
|
|
113
|
-
|
|
114
|
-
const files = detectEnvFiles();
|
|
115
|
-
console.log(formatEnvFilesForDisplay(files));
|
|
116
|
-
// ➜ Environments: .env
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## Types
|
|
120
|
-
```ts
|
|
121
|
-
interface BiniEnvPluginOptions {
|
|
122
|
-
enabled?: boolean;
|
|
123
|
-
clearViteHeader?: boolean;
|
|
124
|
-
logo?: string;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
interface DetectedEnvFile {
|
|
128
|
-
name: string;
|
|
129
|
-
path: string;
|
|
130
|
-
}
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
## License
|
|
134
|
-
|
|
135
|
-
MIT
|
package/dist/index.cjs
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
default: () => biniEnvPlugin,
|
|
34
|
-
detectEnvFiles: () => detectEnvFiles,
|
|
35
|
-
formatEnvFilesForDisplay: () => formatEnvFilesForDisplay
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(index_exports);
|
|
38
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
39
|
-
var import_path = __toESM(require("path"), 1);
|
|
40
|
-
var BINI_LOGO = "\xDF";
|
|
41
|
-
var DEFAULT_OPTIONS = {
|
|
42
|
-
enabled: true,
|
|
43
|
-
clearViteHeader: true,
|
|
44
|
-
logo: BINI_LOGO
|
|
45
|
-
};
|
|
46
|
-
var COLORS = {
|
|
47
|
-
CYAN: "\x1B[36m",
|
|
48
|
-
RESET: "\x1B[0m",
|
|
49
|
-
GREEN: "\x1B[32m",
|
|
50
|
-
YELLOW: "\x1B[33m",
|
|
51
|
-
DIM: "\x1B[2m"
|
|
52
|
-
};
|
|
53
|
-
function detectEnvFiles(projectRoot = process.cwd()) {
|
|
54
|
-
const nodeEnv = process.env.NODE_ENV || "development";
|
|
55
|
-
const envFiles = [
|
|
56
|
-
".env.local",
|
|
57
|
-
`.env.${nodeEnv}.local`,
|
|
58
|
-
`.env.${nodeEnv}`,
|
|
59
|
-
".env"
|
|
60
|
-
];
|
|
61
|
-
const found = [];
|
|
62
|
-
for (const file of envFiles) {
|
|
63
|
-
const filePath = import_path.default.join(projectRoot, file);
|
|
64
|
-
if (import_fs.default.existsSync(filePath)) {
|
|
65
|
-
found.push({
|
|
66
|
-
name: file,
|
|
67
|
-
path: filePath
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return found;
|
|
72
|
-
}
|
|
73
|
-
function formatEnvFilesForDisplay(envFiles) {
|
|
74
|
-
if (envFiles.length === 0) {
|
|
75
|
-
return "";
|
|
76
|
-
}
|
|
77
|
-
const envString = envFiles.map((f) => f.name).join(", ");
|
|
78
|
-
return `${COLORS.GREEN}\u279C${COLORS.RESET} Environments: ${envString}`;
|
|
79
|
-
}
|
|
80
|
-
function clearLine() {
|
|
81
|
-
process.stdout.write("\x1B[2K\r");
|
|
82
|
-
}
|
|
83
|
-
function biniEnvPlugin(options = {}) {
|
|
84
|
-
const resolvedOptions = Object.freeze({
|
|
85
|
-
...DEFAULT_OPTIONS,
|
|
86
|
-
...options
|
|
87
|
-
});
|
|
88
|
-
const { enabled, clearViteHeader, logo } = resolvedOptions;
|
|
89
|
-
let config;
|
|
90
|
-
let isPreviewMode = false;
|
|
91
|
-
let serverStarted = false;
|
|
92
|
-
let previewStarted = false;
|
|
93
|
-
return {
|
|
94
|
-
name: "vite-plugin-bini-env",
|
|
95
|
-
apply: "serve",
|
|
96
|
-
configResolved(resolvedConfig) {
|
|
97
|
-
config = resolvedConfig;
|
|
98
|
-
if (resolvedConfig.command === "serve") {
|
|
99
|
-
isPreviewMode = process.env.VITE_PREVIEW === "true" || process.argv.includes("preview") || false;
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
configureServer(server) {
|
|
103
|
-
if (!enabled) return;
|
|
104
|
-
const originalPrintUrls = server.printUrls;
|
|
105
|
-
server.printUrls = () => {
|
|
106
|
-
if (!serverStarted) {
|
|
107
|
-
serverStarted = true;
|
|
108
|
-
if (clearViteHeader) {
|
|
109
|
-
clearLine();
|
|
110
|
-
}
|
|
111
|
-
console.log(`
|
|
112
|
-
${COLORS.CYAN}${logo} Bini.js${COLORS.RESET} (dev)`);
|
|
113
|
-
const found = detectEnvFiles(config.root);
|
|
114
|
-
if (found.length > 0) {
|
|
115
|
-
const envString = found.map((f) => f.name).join(", ");
|
|
116
|
-
console.log(` ${COLORS.GREEN}\u279C${COLORS.RESET} Environments: ${envString}`);
|
|
117
|
-
}
|
|
118
|
-
if (!clearViteHeader) {
|
|
119
|
-
originalPrintUrls.call(server);
|
|
120
|
-
} else {
|
|
121
|
-
const urls = server.resolvedUrls;
|
|
122
|
-
if (urls) {
|
|
123
|
-
if (urls.local.length > 0) {
|
|
124
|
-
console.log(` ${COLORS.GREEN}\u279C${COLORS.RESET} Local: ${COLORS.CYAN}${urls.local[0]}${COLORS.RESET}`);
|
|
125
|
-
}
|
|
126
|
-
if (urls.network.length > 0) {
|
|
127
|
-
console.log(` ${COLORS.GREEN}\u279C${COLORS.RESET} Network: ${COLORS.CYAN}${urls.network[0]}${COLORS.RESET}`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
configurePreviewServer(server) {
|
|
135
|
-
if (!enabled) return;
|
|
136
|
-
isPreviewMode = true;
|
|
137
|
-
const originalPrintUrls = server.printUrls;
|
|
138
|
-
server.printUrls = () => {
|
|
139
|
-
if (!previewStarted) {
|
|
140
|
-
previewStarted = true;
|
|
141
|
-
if (clearViteHeader) {
|
|
142
|
-
clearLine();
|
|
143
|
-
}
|
|
144
|
-
console.log(`
|
|
145
|
-
${COLORS.CYAN}${logo} Bini.js${COLORS.RESET} (preview)`);
|
|
146
|
-
const found = detectEnvFiles(config.root);
|
|
147
|
-
if (found.length > 0) {
|
|
148
|
-
const envString = found.map((f) => f.name).join(", ");
|
|
149
|
-
console.log(` ${COLORS.GREEN}\u279C${COLORS.RESET} Environments: ${envString}`);
|
|
150
|
-
}
|
|
151
|
-
if (!clearViteHeader) {
|
|
152
|
-
originalPrintUrls.call(server);
|
|
153
|
-
} else {
|
|
154
|
-
const urls = server.resolvedUrls;
|
|
155
|
-
if (urls) {
|
|
156
|
-
if (urls.local.length > 0) {
|
|
157
|
-
console.log(` ${COLORS.GREEN}\u279C${COLORS.RESET} Local: ${COLORS.CYAN}${urls.local[0]}${COLORS.RESET}`);
|
|
158
|
-
}
|
|
159
|
-
if (urls.network.length > 0) {
|
|
160
|
-
console.log(` ${COLORS.GREEN}\u279C${COLORS.RESET} Network: ${COLORS.CYAN}${urls.network[0]}${COLORS.RESET}`);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
},
|
|
167
|
-
buildEnd() {
|
|
168
|
-
serverStarted = false;
|
|
169
|
-
previewStarted = false;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
174
|
-
0 && (module.exports = {
|
|
175
|
-
detectEnvFiles,
|
|
176
|
-
formatEnvFilesForDisplay
|
|
177
|
-
});
|
|
178
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// src/index.ts\r\nimport fs from 'fs';\r\nimport path from 'path';\r\nimport type { Plugin, ResolvedConfig } from 'vite';\r\n\r\n// Types\r\nexport interface BiniEnvPluginOptions {\r\n /**\r\n * Enable/disable the plugin\r\n * @default true\r\n * @readonly\r\n */\r\n readonly enabled?: boolean;\r\n \r\n /**\r\n * Remove Vite's default header\r\n * @default true\r\n * @readonly\r\n */\r\n readonly clearViteHeader?: boolean;\r\n \r\n /**\r\n * Custom logo/text to display\r\n * @default 'ß'\r\n * @readonly\r\n */\r\n readonly logo?: string;\r\n}\r\n\r\nexport interface DetectedEnvFile {\r\n readonly name: string;\r\n readonly path: string;\r\n}\r\n\r\n// Constants\r\nconst BINI_LOGO = 'ß' as const;\r\nconst DEFAULT_OPTIONS = {\r\n enabled: true,\r\n clearViteHeader: true,\r\n logo: BINI_LOGO,\r\n} as const;\r\n\r\n// Color definitions\r\nconst COLORS = {\r\n CYAN: '\\x1b[36m',\r\n RESET: '\\x1b[0m',\r\n GREEN: '\\x1b[32m',\r\n YELLOW: '\\x1b[33m',\r\n DIM: '\\x1b[2m'\r\n} as const;\r\n\r\n/**\r\n * Detect which .env files exist in project root\r\n */\r\nexport function detectEnvFiles(projectRoot: string = process.cwd()): DetectedEnvFile[] {\r\n const nodeEnv = process.env.NODE_ENV || 'development';\r\n\r\n const envFiles = [\r\n '.env.local',\r\n `.env.${nodeEnv}.local`,\r\n `.env.${nodeEnv}`,\r\n '.env'\r\n ] as const;\r\n\r\n const found: DetectedEnvFile[] = [];\r\n\r\n for (const file of envFiles) {\r\n const filePath = path.join(projectRoot, file);\r\n if (fs.existsSync(filePath)) {\r\n found.push({\r\n name: file,\r\n path: filePath\r\n });\r\n }\r\n }\r\n\r\n return found;\r\n}\r\n\r\n/**\r\n * Format environment files for console display\r\n */\r\nexport function formatEnvFilesForDisplay(envFiles: DetectedEnvFile[]): string {\r\n if (envFiles.length === 0) {\r\n return '';\r\n }\r\n\r\n const envString = envFiles.map(f => f.name).join(', ');\r\n return `${COLORS.GREEN}➜${COLORS.RESET} Environments: ${envString}`;\r\n}\r\n\r\n/**\r\n * Clear the current line in console\r\n */\r\nfunction clearLine(): void {\r\n process.stdout.write('\\x1b[2K\\r');\r\n}\r\n\r\n/**\r\n * Main plugin function\r\n */\r\nexport default function biniEnvPlugin(options: Readonly<BiniEnvPluginOptions> = {}): Plugin {\r\n // Merge with defaults — user cannot override core behaviour\r\n const resolvedOptions = Object.freeze({\r\n ...DEFAULT_OPTIONS,\r\n ...options,\r\n });\r\n\r\n const { enabled, clearViteHeader, logo } = resolvedOptions;\r\n\r\n let config: ResolvedConfig;\r\n let isPreviewMode = false;\r\n let serverStarted = false;\r\n let previewStarted = false;\r\n\r\n return {\r\n name: 'vite-plugin-bini-env',\r\n \r\n apply: 'serve',\r\n \r\n configResolved(resolvedConfig: ResolvedConfig) {\r\n config = resolvedConfig;\r\n \r\n if (resolvedConfig.command === 'serve') {\r\n isPreviewMode = process.env.VITE_PREVIEW === 'true' || \r\n process.argv.includes('preview') ||\r\n false;\r\n }\r\n },\r\n\r\n configureServer(server) {\r\n if (!enabled) return;\r\n\r\n const originalPrintUrls = server.printUrls;\r\n \r\n server.printUrls = () => {\r\n if (!serverStarted) {\r\n serverStarted = true;\r\n \r\n if (clearViteHeader) {\r\n clearLine();\r\n }\r\n \r\n console.log(`\\n ${COLORS.CYAN}${logo} Bini.js${COLORS.RESET} (dev)`);\r\n\r\n const found = detectEnvFiles(config.root);\r\n if (found.length > 0) {\r\n const envString = found.map(f => f.name).join(', ');\r\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Environments: ${envString}`);\r\n }\r\n \r\n if (!clearViteHeader) {\r\n originalPrintUrls.call(server);\r\n } else {\r\n const urls = server.resolvedUrls;\r\n if (urls) {\r\n if (urls.local.length > 0) {\r\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Local: ${COLORS.CYAN}${urls.local[0]}${COLORS.RESET}`);\r\n }\r\n if (urls.network.length > 0) {\r\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Network: ${COLORS.CYAN}${urls.network[0]}${COLORS.RESET}`);\r\n }\r\n }\r\n }\r\n }\r\n };\r\n },\r\n\r\n configurePreviewServer(server) {\r\n if (!enabled) return;\r\n \r\n isPreviewMode = true;\r\n \r\n const originalPrintUrls = server.printUrls;\r\n \r\n server.printUrls = () => {\r\n if (!previewStarted) {\r\n previewStarted = true;\r\n \r\n if (clearViteHeader) {\r\n clearLine();\r\n }\r\n \r\n console.log(`\\n ${COLORS.CYAN}${logo} Bini.js${COLORS.RESET} (preview)`);\r\n\r\n const found = detectEnvFiles(config.root);\r\n if (found.length > 0) {\r\n const envString = found.map(f => f.name).join(', ');\r\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Environments: ${envString}`);\r\n }\r\n \r\n if (!clearViteHeader) {\r\n originalPrintUrls.call(server);\r\n } else {\r\n const urls = server.resolvedUrls;\r\n if (urls) {\r\n if (urls.local.length > 0) {\r\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Local: ${COLORS.CYAN}${urls.local[0]}${COLORS.RESET}`);\r\n }\r\n if (urls.network.length > 0) {\r\n console.log(` ${COLORS.GREEN}➜${COLORS.RESET} Network: ${COLORS.CYAN}${urls.network[0]}${COLORS.RESET}`);\r\n }\r\n }\r\n }\r\n }\r\n };\r\n },\r\n\r\n buildEnd() {\r\n serverStarted = false;\r\n previ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}
|
package/dist/index.d.cts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
2
|
-
export { Plugin } from 'vite';
|
|
3
|
-
|
|
4
|
-
interface BiniEnvPluginOptions {
|
|
5
|
-
/**
|
|
6
|
-
* Enable/disable the plugin
|
|
7
|
-
* @default true
|
|
8
|
-
* @readonly
|
|
9
|
-
*/
|
|
10
|
-
readonly enabled?: boolean;
|
|
11
|
-
/**
|
|
12
|
-
* Remove Vite's default header
|
|
13
|
-
* @default true
|
|
14
|
-
* @readonly
|
|
15
|
-
*/
|
|
16
|
-
readonly clearViteHeader?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Custom logo/text to display
|
|
19
|
-
* @default 'ß'
|
|
20
|
-
* @readonly
|
|
21
|
-
*/
|
|
22
|
-
readonly logo?: string;
|
|
23
|
-
}
|
|
24
|
-
interface DetectedEnvFile {
|
|
25
|
-
readonly name: string;
|
|
26
|
-
readonly path: string;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Detect which .env files exist in project root
|
|
30
|
-
*/
|
|
31
|
-
declare function detectEnvFiles(projectRoot?: string): DetectedEnvFile[];
|
|
32
|
-
/**
|
|
33
|
-
* Format environment files for console display
|
|
34
|
-
*/
|
|
35
|
-
declare function formatEnvFilesForDisplay(envFiles: DetectedEnvFile[]): string;
|
|
36
|
-
/**
|
|
37
|
-
* Main plugin function
|
|
38
|
-
*/
|
|
39
|
-
declare function biniEnvPlugin(options?: Readonly<BiniEnvPluginOptions>): Plugin;
|
|
40
|
-
|
|
41
|
-
export { type BiniEnvPluginOptions, type DetectedEnvFile, biniEnvPlugin as default, detectEnvFiles, formatEnvFilesForDisplay };
|