Skip to content

Commit

Permalink
Split Wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
ta-Hirose committed Sep 28, 2022
1 parent dd18a05 commit 8537edf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions libs/deno_wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class DenoWrapper {
static build = {
os: Deno.build.os,
};
}
9 changes: 2 additions & 7 deletions libs/postprocess/unzipper.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Colors, decompress } from "../../deps.ts";
import { BasePostprocess } from "./base_postprocess.ts";
import DenoWrapper from "../deno_wrapper.ts";

export class Unzipper extends BasePostprocess {
async execute(_: string[], targetPath: string): Promise<string> {
const splitedPath = targetPath.split("/");
const targetDir = splitedPath.slice(0, splitedPath.length - 1).join("/");
if (getBuild.getOs() === "darwin") {
if (DenoWrapper.build.os === "darwin") {
const process = Deno.run({
cmd: ["ditto", "-xk", "--sequesterRsrc", targetPath, targetDir],
stdout: "piped",
Expand All @@ -30,9 +31,3 @@ export class Unzipper extends BasePostprocess {
return true;
}
}

function getOs(): string {
return Deno.build.os;
}

export const getBuild = { getOs };
10 changes: 5 additions & 5 deletions tests/libs/actions.install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { afterEach, beforeEach, describe, it } from "https://deno.land/std@0.152
import { Colors, encoding } from "../../deps.ts";
import { InstallAction } from "../../libs/actions.ts";
import { DimJSON, DimLockJSON } from "../../libs/types.ts";
import { getBuild } from "../../libs/postprocess/unzipper.ts";
import DenoWrapper from "../../libs/deno_wrapper.ts";
import {
createEmptyDimJson,
createKyGetStub,
Expand All @@ -21,6 +21,7 @@ describe("InstallAction", () => {
let denoStdoutStub: Stub;
let fakeTime: FakeTime;
let originalDirectory: string;
let originalOS: "darwin" | "linux" | "windows";

beforeEach(() => {
consoleLogStub = stub(console, "log");
Expand All @@ -29,6 +30,7 @@ describe("InstallAction", () => {
denoStdoutStub = stub(Deno.stdout, "write");
fakeTime = new FakeTime("2022-01-02T03:04:05.678Z");
originalDirectory = Deno.cwd();
originalOS = DenoWrapper.build.os;
Deno.chdir(temporaryDirectory);
});

Expand All @@ -39,6 +41,7 @@ describe("InstallAction", () => {
denoExitStub.restore();
consoleErrorStub.restore();
consoleLogStub.restore();
DenoWrapper.build.os = originalOS;
Deno.chdir(originalDirectory);
});

Expand Down Expand Up @@ -405,9 +408,7 @@ describe("InstallAction", () => {
status: () => Promise.resolve({ success: true }),
rid: 1,
} as Deno.Process));
const osStub = stub(getBuild, "getOs", () => {
return "darwin";
});
DenoWrapper.build.os = "darwin";
try {
await new InstallAction().execute(
{ name: "unzip", postProcesses: ["unzip"] },
Expand All @@ -428,7 +429,6 @@ describe("InstallAction", () => {
}],
});
} finally {
osStub.restore();
denoRunStub.restore();
kyGetStub.restore();
}
Expand Down

0 comments on commit 8537edf

Please sign in to comment.