summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/move.ts7
-rw-r--r--fs/read_json.ts3
-rw-r--r--fs/read_json_test.ts20
-rw-r--r--fs/write_json.ts5
4 files changed, 16 insertions, 19 deletions
diff --git a/fs/move.ts b/fs/move.ts
index 007e4520b..190f88609 100644
--- a/fs/move.ts
+++ b/fs/move.ts
@@ -1,5 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as path from "./path/mod.ts";
import { exists, existsSync } from "./exists.ts";
import { isSubdir } from "./utils.ts";
@@ -13,9 +12,6 @@ export async function move(
dest: string,
options?: MoveOptions
): Promise<void> {
- src = path.resolve(src);
- dest = path.resolve(dest);
-
const srcStat = await Deno.stat(src);
if (srcStat.isDirectory() && isSubdir(src, dest)) {
@@ -43,9 +39,6 @@ export function moveSync(
dest: string,
options?: MoveOptions
): void {
- src = path.resolve(src);
- dest = path.resolve(dest);
-
const srcStat = Deno.statSync(src);
if (srcStat.isDirectory() && isSubdir(src, dest)) {
diff --git a/fs/read_json.ts b/fs/read_json.ts
index 1bed75078..8979c24e8 100644
--- a/fs/read_json.ts
+++ b/fs/read_json.ts
@@ -1,9 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as path from "./path/mod.ts";
/** Reads a JSON file and then parses it into an object */
export async function readJson(filePath: string): Promise<any> {
- filePath = path.resolve(filePath);
const decoder = new TextDecoder("utf-8");
const content = decoder.decode(await Deno.readFile(filePath));
@@ -18,7 +16,6 @@ export async function readJson(filePath: string): Promise<any> {
/** Reads a JSON file and then parses it into an object */
export function readJsonSync(filePath: string): any {
- filePath = path.resolve(filePath);
const decoder = new TextDecoder("utf-8");
const content = decoder.decode(Deno.readFileSync(filePath));
diff --git a/fs/read_json_test.ts b/fs/read_json_test.ts
index 46ce1ec08..ca32ee053 100644
--- a/fs/read_json_test.ts
+++ b/fs/read_json_test.ts
@@ -34,7 +34,7 @@ test(async function readInvalidJsonFile() {
});
});
-test(async function readValidJsonFile() {
+test(async function readValidArrayJsonFile() {
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
const json = await readJson(invalidJsonFile);
@@ -42,7 +42,7 @@ test(async function readValidJsonFile() {
assertEquals(json, ["1", "2", "3"]);
});
-test(async function readValidJsonFile() {
+test(async function readValidObjJsonFile() {
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
const json = await readJson(invalidJsonFile);
@@ -50,6 +50,12 @@ test(async function readValidJsonFile() {
assertEquals(json, { key1: "value1", key2: "value2" });
});
+test(async function readValidObjJsonFileWithRelativePath() {
+ const json = await readJson("./fs/testdata/json_valid_obj.json");
+
+ assertEquals(json, { key1: "value1", key2: "value2" });
+});
+
test(function readJsonFileNotExistsSync() {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
@@ -74,7 +80,7 @@ test(function readInvalidJsonFile() {
});
});
-test(function readValidJsonFile() {
+test(function readValidArrayJsonFileSync() {
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
const json = readJsonSync(invalidJsonFile);
@@ -82,10 +88,16 @@ test(function readValidJsonFile() {
assertEquals(json, ["1", "2", "3"]);
});
-test(function readValidJsonFile() {
+test(function readValidObjJsonFileSync() {
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
const json = readJsonSync(invalidJsonFile);
assertEquals(json, { key1: "value1", key2: "value2" });
});
+
+test(function readValidObjJsonFileSyncWithRelativePath() {
+ const json = readJsonSync("./fs/testdata/json_valid_obj.json");
+
+ assertEquals(json, { key1: "value1", key2: "value2" });
+});
diff --git a/fs/write_json.ts b/fs/write_json.ts
index f94489095..c5936d3f8 100644
--- a/fs/write_json.ts
+++ b/fs/write_json.ts
@@ -1,6 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
/* eslint-disable @typescript-eslint/no-explicit-any */
-import * as path from "./path/mod.ts";
type Replacer = (key: string, value: any) => any;
export interface WriteJsonOptions {
@@ -14,8 +13,6 @@ export async function writeJson(
object: any,
options: WriteJsonOptions = {}
): Promise<void> {
- filePath = path.resolve(filePath);
-
let contentRaw = "";
try {
@@ -38,8 +35,6 @@ export function writeJsonSync(
object: any,
options: WriteJsonOptions = {}
): void {
- filePath = path.resolve(filePath);
-
let contentRaw = "";
try {