Skip to content

Commit

Permalink
fix: change access to fs/promises lib (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-gilin committed Jun 30, 2021
1 parent 7217f97 commit 2dd4a36
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@sap/cf-tools",
"displayName": "cf-tools",
"version": "2.0.0",
"version": "2.0.1",
"description": "Cloud Foundry API tools",
"bugs": {
"url": "https://github.com/sap-staging/cloud-foundry-tools-api.git/issues"
Expand Down
6 changes: 3 additions & 3 deletions src/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import * as fs from "fs/promises";
import * as fs from "fs";
import * as path from "path";
import * as _ from "lodash";
import { parse, stringify } from "comment-json";
Expand All @@ -12,7 +12,7 @@ const DEFAULT_TASKS_JSON_CONTENT: any = { version: "2.0.0", tasks: [] };

async function getTaskJsonContentAsJsonObject(taskJsonFilePath: string): Promise<any> {
try {
const tasksJsonString = await fs.readFile(taskJsonFilePath, { encoding: "utf8" });
const tasksJsonString = await fs.promises.readFile(taskJsonFilePath, { encoding: "utf8" });
const tasksJson: any = parse(tasksJsonString);
return _.assign(DEFAULT_TASKS_JSON_CONTENT, tasksJson);
} catch (e) {
Expand All @@ -32,5 +32,5 @@ export async function saveTaskConfiguration(wsFolderPath: string, configuration:
tasksJson.tasks.push(configuration);
}

await fs.writeFile(taskJsonFilePath, stringify(tasksJson, undefined, " "));
await fs.promises.writeFile(taskJsonFilePath, stringify(tasksJson, undefined, " "));
}
6 changes: 3 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
/* eslint-disable @typescript-eslint/no-unsafe-return */
import * as _ from "lodash";
import * as os from "os";
import * as fs from "fs/promises";
import * as fs from "fs";
import * as path from "path";
import { parse } from "comment-json";
import { messages } from "./messages";
import { IServiceQuery, CF_PAGE_SIZE, IServiceFilters, eFilters, eServiceTypes } from "./types";

export async function dataContentAsObject(filePath: string) {
try {
return _.reduce(_.split(await fs.readFile(filePath, { encoding: "utf8" }), os.EOL), (data: any, line: string) => {
return _.reduce(_.split(await fs.promises.readFile(filePath, { encoding: "utf8" }), os.EOL), (data: any, line: string) => {
const parts = _.split(line, '=');
if (_.size(parts) > 1) {
data[_.trim(parts[0])] = _.trim(parts[1]);
Expand Down Expand Up @@ -93,7 +93,7 @@ export function isUpsType(resource: any): boolean {
*/
export async function cfGetConfigFileJson(target?: string): Promise<unknown> {
try {
return parse(await fs.readFile(cfGetConfigFilePath(target), { encoding: "utf8" }));
return parse(await fs.promises.readFile(cfGetConfigFilePath(target), { encoding: "utf8" }));
} catch (error) {
// empty or non existing file
}
Expand Down
4 changes: 2 additions & 2 deletions tests/cf-local-a.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { expect, assert } from "chai";
import * as _ from "lodash";
import { SinonSandbox, SinonMock, createSandbox } from "sinon";
import * as fs from "fs/promises";
import * as fs from "fs";
import * as cfLocal from "../src/cf-local";
import * as cli from "../src/cli";
import { fail } from "assert";
Expand All @@ -28,7 +28,7 @@ describe("cf-local-a unit tests", () => {

beforeEach(() => {
cliMock = sandbox.mock(cli.Cli);
fsMock = sandbox.mock(fs);
fsMock = sandbox.mock(fs.promises);
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions tests/cf-local-b.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { expect, assert } from "chai";
import * as _ from "lodash";
import { SinonSandbox, SinonMock, createSandbox } from "sinon";
import * as fs from "fs/promises";
import * as fs from "fs";
import * as cfLocal from "../src/cf-local";
import * as cli from "../src/cli";
import { fail } from "assert";
Expand All @@ -27,7 +27,7 @@ describe("cf-local-b unit tests", () => {

beforeEach(() => {
cliMock = sandbox.mock(cli.Cli);
fsMock = sandbox.mock(fs);
fsMock = sandbox.mock(fs.promises);
});

afterEach(() => {
Expand Down
6 changes: 3 additions & 3 deletions tests/cf-local.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { expect, assert } from "chai";
import * as _ from "lodash";
import { SinonSandbox, SinonMock, createSandbox } from "sinon";
import * as fs from "fs/promises";
import * as fs from "fs";
import * as cfLocal from "../src/cf-local";
import * as cli from "../src/cli";
import { messages } from "../src/messages";
Expand Down Expand Up @@ -32,7 +32,7 @@ describe("cf-local unit tests", () => {

beforeEach(() => {
cliMock = sandbox.mock(cli.Cli);
fsMock = sandbox.mock(fs);
fsMock = sandbox.mock(fs.promises);
});

afterEach(() => {
Expand Down Expand Up @@ -163,7 +163,7 @@ describe("cf-local unit tests", () => {
it("exception:: cf space GUID not specified and default is undefined", async () => {
instanceName = `${baseInstanceName}161`;
sandbox.restore();
fsMock = sandbox.mock(fs);
fsMock = sandbox.mock(fs.promises);
fsMock.expects("readFile").withExactArgs(configFilePath, { encoding: "utf8" }).resolves(`{}`);
try {
await cfLocal.cfCreateService(planGuid, instanceName, {}, [], null);
Expand Down
4 changes: 2 additions & 2 deletions tests/task.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stringify } from "comment-json";
import { SinonSandbox, SinonMock, createSandbox } from "sinon";
import * as fs from "fs/promises";
import * as fs from "fs";
import * as path from "path";
import { saveTaskConfiguration } from "../src/task";

Expand All @@ -18,7 +18,7 @@ describe('task unit tests', () => {
});

beforeEach(() => {
fsMock = sandbox.mock(fs);
fsMock = sandbox.mock(fs.promises);
});

afterEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { expect, assert } from "chai";
import * as fs from "fs/promises";
import * as fs from "fs";
import { SinonSandbox, SinonMock, createSandbox } from "sinon";
import * as os from "os";
import * as path from "path";
Expand All @@ -24,7 +24,7 @@ describe("Util unit tests", () => {
});

beforeEach(() => {
fsMock = sandbox.mock(fs);
fsMock = sandbox.mock(fs.promises);
});

afterEach(() => {
Expand Down

0 comments on commit 2dd4a36

Please sign in to comment.