Skip to content

Commit

Permalink
BREAKING: Map-like interface for Deno.env (denoland/deno#4942)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyrupThinker authored and denobot committed Feb 1, 2021
1 parent f2b6446 commit 1204b3d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/gist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function pathBase(p: string): string {
return parts[parts.length - 1];
}

const token = Deno.env()["GIST_TOKEN"];
const token = Deno.env.get("GIST_TOKEN");
if (!token) {
console.error("GIST_TOKEN environmental variable not set.");
console.error("Get a token here: https://github.com/settings/tokens");
Expand Down
4 changes: 2 additions & 2 deletions node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ class Module {
}

static _initPaths(): void {
const homeDir = Deno.env("HOME");
const nodePath = Deno.env("NODE_PATH");
const homeDir = Deno.env.get("HOME");
const nodePath = Deno.env.get("NODE_PATH");

// Removed $PREFIX/bin/node case

Expand Down
2 changes: 1 addition & 1 deletion node/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const process = {
on,
get env(): { [index: string]: string } {
// using getter to avoid --allow-env unless it's used
return Deno.env();
return Deno.env.toObject();
},
get argv(): string[] {
// Deno.execPath() also requires --allow-env
Expand Down
2 changes: 1 addition & 1 deletion node/process_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
import { process } from "./process.ts";

// NOTE: Deno.execPath() (and thus process.argv) currently requires --allow-env
// (Also Deno.env() (and process.env) requires --allow-env but it's more obvious)
// (Also Deno.env.toObject() (and process.env) requires --allow-env but it's more obvious)

test({
name: "process.cwd and process.chdir success",
Expand Down
2 changes: 1 addition & 1 deletion path/win32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function resolve(...pathSegments: string[]): string {
// absolute path, get cwd for that drive, or the process cwd if
// the drive cwd is not available. We're sure the device is not
// a UNC path at this points, because UNC paths are always absolute.
path = env()[`=${resolvedDevice}`] || cwd();
path = env.get(`=${resolvedDevice}`) || cwd();

// Verify that a cwd was found and that it actually points
// to our drive. If not, default to the drive's root.
Expand Down

0 comments on commit 1204b3d

Please sign in to comment.