bun-types-no-globals 1.2.21-canary.20250822T140708 → 1.2.21-canary.20250824T140615

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/README.md CHANGED
@@ -1,8 +1,63 @@
1
+ <img src="https://bun.com/logo.png" height="36" />
2
+
1
3
  # bun-types-no-globals
2
4
 
3
- Publishes the Bun types with no globals, useful for library authors that need to consume parts of Bun's APIs with versions of @types/bun, but without loading the globals which can cause conflicts
5
+ TypeScript type definitions for Bun's APIs without global namespace pollution. This package provides clean, isolated Bun types that won't interfere with other environments or type systems.
6
+
7
+ > **Note:** This package is for advanced use cases only. You are probably looking for [`@types/bun`](https://www.npmjs.com/package/@types/bun) instead.
8
+
9
+ ## Why does this exist?
10
+
11
+ When building universal tools or libraries that support multiple runtimes (Node.js, Bun, browsers, etc.), importing `@types/bun` causes problems:
12
+
13
+ - **Global type pollution**: Regular Bun types modify global interfaces and add global variables that conflict with Node.js or browser types
14
+ - **Transitive type leakage**: If your library uses `@types/bun`, everyone who installs your library gets Bun's global types too - even if they're not using Bun
15
+ - **Multi-bundler compatibility issues**: Tools like [unplugin](https://github.com/unjs/unplugin) that support webpack, Vite, Rollup, esbuild, AND Bun can't use regular Bun types without forcing them on all users
16
+
17
+ This package solves these issues by providing Bun's type definitions in an isolated, non-global way.
18
+
19
+ ## Common Use Cases
20
+
21
+ ### 🔧 Multi-Runtime Libraries
22
+
23
+ Libraries that work across Node.js, Bun, and browsers can safely import Bun-specific APIs without breaking TypeScript for other runtimes:
24
+
25
+ ```ts
26
+ import type { BunFile } from 'bun';
27
+
28
+ export function processFile(file: BunFile | Buffer) {
29
+ // Implementation that works with both Bun and Node.js
30
+ }
31
+ ```
32
+
33
+ ### 🛠️ Build Tool Plugins
34
+
35
+ Build tools and bundler plugins (like unplugin) can add Bun support without forcing Bun types on webpack, Vite, or Rollup users:
36
+
37
+ ```ts
38
+ import type { BunPlugin } from 'bun';
39
+
40
+ export function createPlugin(): BunPlugin | WebpackPlugin | VitePlugin {
41
+ // Plugin implementation
42
+ }
43
+ ```
44
+
45
+ ### 🛠️ [Re-\]declaring the Bun namespace
46
+
47
+ Sometimes you'll still want the Bun namespace to globally exist - this is most helpful in situations where actually including a runtime import from `bun` is more inconvenient than using the Bun namespace itself. You can tell TypeScript about the namespace by including this code somewhere in your program:
48
+
49
+ ```ts
50
+ // File could be called `bun.ns.d.ts` for example
51
+ import * as BunModule from 'bun';
52
+
53
+ declare global {
54
+ export import Bun = BunModule;
55
+ }
56
+ ```
57
+
58
+ I wrote a little about the above syntax [on my blog about Ambient Declarations](https://alistair.sh/ambient-declarations).
4
59
 
5
- ### Requiring these
60
+ ## Usage
6
61
 
7
62
  We recommend you require these types with a triple slash reference anywhere in your program
8
63
 
package/lib/bun.d.ts CHANGED
@@ -1844,6 +1844,10 @@ declare module "bun" {
1844
1844
  hideConsole?: boolean;
1845
1845
  icon?: string;
1846
1846
  title?: string;
1847
+ publisher?: string;
1848
+ version?: string;
1849
+ description?: string;
1850
+ copyright?: string;
1847
1851
  };
1848
1852
  }
1849
1853
 
@@ -2120,6 +2124,287 @@ declare module "bun" {
2120
2124
  ): string;
2121
2125
  };
2122
2126
 
2127
+ /**
2128
+ * Securely store and retrieve sensitive credentials using the operating system's native credential storage.
2129
+ *
2130
+ * Uses platform-specific secure storage:
2131
+ * - **macOS**: Keychain Services
2132
+ * - **Linux**: libsecret (GNOME Keyring, KWallet, etc.)
2133
+ * - **Windows**: Windows Credential Manager
2134
+ *
2135
+ * @category Security
2136
+ *
2137
+ * @example
2138
+ * ```ts
2139
+ * import { secrets } from "bun";
2140
+ *
2141
+ * // Store a credential
2142
+ * await secrets.set({
2143
+ * service: "my-cli-tool",
2144
+ * name: "github-token",
2145
+ * value: "ghp_xxxxxxxxxxxxxxxxxxxx"
2146
+ * });
2147
+ *
2148
+ * // Retrieve a credential
2149
+ * const token = await secrets.get({
2150
+ * service: "my-cli-tool",
2151
+ * name: "github-token"
2152
+ * });
2153
+ *
2154
+ * if (token) {
2155
+ * console.log("Token found:", token);
2156
+ * } else {
2157
+ * console.log("Token not found");
2158
+ * }
2159
+ *
2160
+ * // Delete a credential
2161
+ * const deleted = await secrets.delete({
2162
+ * service: "my-cli-tool",
2163
+ * name: "github-token"
2164
+ * });
2165
+ * console.log("Deleted:", deleted); // true if deleted, false if not found
2166
+ * ```
2167
+ *
2168
+ * @example
2169
+ * ```ts
2170
+ * // Replace plaintext config files
2171
+ * import { secrets } from "bun";
2172
+ *
2173
+ * // Instead of storing in ~/.npmrc
2174
+ * await secrets.set({
2175
+ * service: "npm-registry",
2176
+ * name: "https://registry.npmjs.org",
2177
+ * value: "npm_xxxxxxxxxxxxxxxxxxxx"
2178
+ * });
2179
+ *
2180
+ * // Instead of storing in ~/.aws/credentials
2181
+ * await secrets.set({
2182
+ * service: "aws-cli",
2183
+ * name: "default",
2184
+ * value: process.env.AWS_SECRET_ACCESS_KEY
2185
+ * });
2186
+ *
2187
+ * // Load at runtime with fallback
2188
+ * const apiKey = await secrets.get({
2189
+ * service: "my-app",
2190
+ * name: "api-key"
2191
+ * }) || process.env.API_KEY;
2192
+ * ```
2193
+ */
2194
+ const secrets: {
2195
+ /**
2196
+ * Retrieve a stored credential from the operating system's secure storage.
2197
+ *
2198
+ * @param options - The service and name identifying the credential
2199
+ * @returns The stored credential value, or null if not found
2200
+ *
2201
+ * @example
2202
+ * ```ts
2203
+ * const password = await Bun.secrets.get({
2204
+ * service: "my-database",
2205
+ * name: "admin"
2206
+ * });
2207
+ *
2208
+ * if (password) {
2209
+ * await connectToDatabase(password);
2210
+ * }
2211
+ * ```
2212
+ *
2213
+ * @example
2214
+ * ```ts
2215
+ * // Check multiple possible locations
2216
+ * const token =
2217
+ * await Bun.secrets.get({ service: "github", name: "token" }) ||
2218
+ * await Bun.secrets.get({ service: "gh-cli", name: "github.com" }) ||
2219
+ * process.env.GITHUB_TOKEN;
2220
+ * ```
2221
+ */
2222
+ get(options: {
2223
+ /**
2224
+ * The service or application name.
2225
+ *
2226
+ * Use a unique identifier for your application to avoid conflicts.
2227
+ * Consider using reverse domain notation for production apps (e.g., "com.example.myapp").
2228
+ */
2229
+ service: string;
2230
+
2231
+ /**
2232
+ * The account name, username, or resource identifier.
2233
+ *
2234
+ * This identifies the specific credential within the service.
2235
+ * Common patterns include usernames, email addresses, or resource URLs.
2236
+ */
2237
+ name: string;
2238
+ }): Promise<string | null>;
2239
+
2240
+ /**
2241
+ * Store or update a credential in the operating system's secure storage.
2242
+ *
2243
+ * If a credential already exists for the given service/name combination, it will be replaced.
2244
+ * The credential is encrypted by the operating system and only accessible to the current user.
2245
+ *
2246
+ * @param options - The service and name identifying the credential
2247
+ * @param value - The secret value to store (e.g., password, API key, token)
2248
+ *
2249
+ * @example
2250
+ * ```ts
2251
+ * // Store an API key
2252
+ * await Bun.secrets.set({
2253
+ * service: "openai-api",
2254
+ * name: "production",
2255
+ * value: "sk-proj-xxxxxxxxxxxxxxxxxxxx"
2256
+ * });
2257
+ * ```
2258
+ *
2259
+ * @example
2260
+ * ```ts
2261
+ * // Update an existing credential
2262
+ * const newPassword = generateSecurePassword();
2263
+ * await Bun.secrets.set({
2264
+ * service: "email-server",
2265
+ * name: "admin@example.com",
2266
+ * value: newPassword
2267
+ * });
2268
+ * ```
2269
+ *
2270
+ * @example
2271
+ * ```ts
2272
+ * // Store credentials from environment variables
2273
+ * if (process.env.DATABASE_PASSWORD) {
2274
+ * await Bun.secrets.set({
2275
+ * service: "postgres",
2276
+ * name: "production",
2277
+ * value: process.env.DATABASE_PASSWORD
2278
+ * });
2279
+ * delete process.env.DATABASE_PASSWORD; // Remove from memory
2280
+ * }
2281
+ * ```
2282
+ *
2283
+ * @example
2284
+ * ```ts
2285
+ * // Delete a credential using empty string (equivalent to delete())
2286
+ * await Bun.secrets.set({
2287
+ * service: "my-service",
2288
+ * name: "api-key",
2289
+ * value: "" // Empty string deletes the credential
2290
+ * });
2291
+ * ```
2292
+ *
2293
+ * @example
2294
+ * ```ts
2295
+ * // Store credential with unrestricted access for CI environments
2296
+ * await Bun.secrets.set({
2297
+ * service: "github-actions",
2298
+ * name: "deploy-token",
2299
+ * value: process.env.DEPLOY_TOKEN,
2300
+ * allowUnrestrictedAccess: true // Allows access without user interaction on macOS
2301
+ * });
2302
+ * ```
2303
+ */
2304
+ set(options: {
2305
+ /**
2306
+ * The service or application name.
2307
+ *
2308
+ * Use a unique identifier for your application to avoid conflicts.
2309
+ * Consider using reverse domain notation for production apps (e.g., "com.example.myapp").
2310
+ */
2311
+ service: string;
2312
+
2313
+ /**
2314
+ * The account name, username, or resource identifier.
2315
+ *
2316
+ * This identifies the specific credential within the service.
2317
+ * Common patterns include usernames, email addresses, or resource URLs.
2318
+ */
2319
+ name: string;
2320
+
2321
+ /**
2322
+ * The secret value to store.
2323
+ *
2324
+ * This should be a sensitive credential like a password, API key, or token.
2325
+ * The value is encrypted by the operating system before storage.
2326
+ *
2327
+ * Note: To delete a credential, use the delete() method or pass an empty string.
2328
+ * An empty string value will delete the credential if it exists.
2329
+ */
2330
+ value: string;
2331
+
2332
+ /**
2333
+ * Allow unrestricted access to stored credentials on macOS.
2334
+ *
2335
+ * When true, allows all applications to access this keychain item without user interaction.
2336
+ * This is useful for CI environments but reduces security.
2337
+ *
2338
+ * @default false
2339
+ * @platform macOS - Only affects macOS keychain behavior. Ignored on other platforms.
2340
+ */
2341
+ allowUnrestrictedAccess?: boolean;
2342
+ }): Promise<void>;
2343
+
2344
+ /**
2345
+ * Delete a stored credential from the operating system's secure storage.
2346
+ *
2347
+ * @param options - The service and name identifying the credential
2348
+ * @returns true if a credential was deleted, false if not found
2349
+ *
2350
+ * @example
2351
+ * ```ts
2352
+ * // Delete a single credential
2353
+ * const deleted = await Bun.secrets.delete({
2354
+ * service: "my-app",
2355
+ * name: "api-key"
2356
+ * });
2357
+ *
2358
+ * if (deleted) {
2359
+ * console.log("Credential removed successfully");
2360
+ * } else {
2361
+ * console.log("Credential was not found");
2362
+ * }
2363
+ * ```
2364
+ *
2365
+ * @example
2366
+ * ```ts
2367
+ * // Clean up multiple credentials
2368
+ * const services = ["github", "npm", "docker"];
2369
+ * for (const service of services) {
2370
+ * await Bun.secrets.delete({
2371
+ * service,
2372
+ * name: "token"
2373
+ * });
2374
+ * }
2375
+ * ```
2376
+ *
2377
+ * @example
2378
+ * ```ts
2379
+ * // Clean up on uninstall
2380
+ * if (process.argv.includes("--uninstall")) {
2381
+ * const deleted = await Bun.secrets.delete({
2382
+ * service: "my-cli-tool",
2383
+ * name: "config"
2384
+ * });
2385
+ * process.exit(deleted ? 0 : 1);
2386
+ * }
2387
+ * ```
2388
+ */
2389
+ delete(options: {
2390
+ /**
2391
+ * The service or application name.
2392
+ *
2393
+ * Use a unique identifier for your application to avoid conflicts.
2394
+ * Consider using reverse domain notation for production apps (e.g., "com.example.myapp").
2395
+ */
2396
+ service: string;
2397
+
2398
+ /**
2399
+ * The account name, username, or resource identifier.
2400
+ *
2401
+ * This identifies the specific credential within the service.
2402
+ * Common patterns include usernames, email addresses, or resource URLs.
2403
+ */
2404
+ name: string;
2405
+ }): Promise<boolean>;
2406
+ };
2407
+
2123
2408
  /**
2124
2409
  * A build artifact represents a file that was generated by the bundler @see {@link Bun.build}
2125
2410
  *
@@ -8,6 +8,16 @@ declare module "*.toml" {
8
8
  export = contents;
9
9
  }
10
10
 
11
+ declare module "*.yaml" {
12
+ var contents: any;
13
+ export = contents;
14
+ }
15
+
16
+ declare module "*.yml" {
17
+ var contents: any;
18
+ export = contents;
19
+ }
20
+
11
21
  declare module "*.jsonc" {
12
22
  var contents: any;
13
23
  export = contents;
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "bun-types-no-globals",
3
- "version": "1.2.21-canary.20250822T140708",
3
+ "version": "1.2.21-canary.20250824T140615",
4
4
  "main": "./generator/index.ts",
5
5
  "types": "./lib/index.d.ts",
6
- "license": "MIT",
6
+ "description": "TypeScript type definitions for Bun without global types pollution",
7
+ "homepage": "https://bun.com",
8
+ "bugs": {
9
+ "url": "https://github.com/alii/bun-types-no-globals/issues"
10
+ },
7
11
  "repository": {
8
12
  "type": "git",
9
13
  "url": "https://github.com/alii/bun-types-no-globals"
10
14
  },
15
+ "license": "MIT",
16
+ "author": "Alistair Smith <hi@alistair.sh>",
11
17
  "files": [
12
18
  "lib",
13
19
  "package.json"
@@ -18,5 +24,18 @@
18
24
  "typescript": "^5.9.2",
19
25
  "oxc-parser": "^0.82.3",
20
26
  "oxc-walker": "^0.4.0"
21
- }
27
+ },
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "keywords": [
32
+ "bun",
33
+ "types",
34
+ "typescript",
35
+ "type-definitions",
36
+ "no-globals",
37
+ "runtime",
38
+ "javascript",
39
+ "typings"
40
+ ]
22
41
  }