Skip to content

Commit

Permalink
fix: fix copyfiles error
Browse files Browse the repository at this point in the history
  • Loading branch information
zanminkian committed Apr 23, 2024
1 parent 00b6fc1 commit 0a2f8df
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-radios-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnm/tscx": minor
---

fix: fix copyfiles error
19 changes: 19 additions & 0 deletions packages/tscx/src/cmd/copyfiles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const TMP2 = path.resolve(os.tmpdir(), "tscx_tmp_for_copy2");
const scrDirPath2 = path.resolve(TMP2, "src");
const distDirPath2 = path.resolve(TMP2, "dist");

const TMP3 = path.resolve(os.tmpdir(), "tscx_tmp_for_copy3");
const scrDirPath3 = path.resolve(TMP3, "src");
const distDirPath3 = path.resolve(TMP3, "dist");

describe("copyfiles", () => {
beforeEach(async () => {
await fs.mkdir(TMP1);
Expand All @@ -20,10 +24,14 @@ describe("copyfiles", () => {
await fs.mkdir(TMP2);
await fs.mkdir(scrDirPath2);
await fs.mkdir(distDirPath2);
await fs.mkdir(TMP3);
await fs.mkdir(scrDirPath3);
await fs.mkdir(distDirPath3);
});
afterEach(async () => {
await fs.rm(TMP1, { force: true, recursive: true });
await fs.rm(TMP2, { force: true, recursive: true });
await fs.rm(TMP3, { force: true, recursive: true });
});

it("should copy files when src and dist are peers", async () => {
Expand Down Expand Up @@ -103,4 +111,15 @@ describe("copyfiles", () => {
await fs.readFile(path.resolve(distDirPath2, "src", "a"), "utf8"),
).toBe("foo");
});

it("should copy if destination folder is empty", async () => {
await fs.mkdir(path.resolve(scrDirPath3, "foo"));
await fs.writeFile(path.resolve(scrDirPath3, "foo", "bar.txt"), "bar");

await copyfiles(scrDirPath3, distDirPath3);

expect(
await fs.readFile(path.resolve(distDirPath3, "foo", "bar.txt"), "utf8"),
).toBe("bar");
});
});
1 change: 1 addition & 0 deletions packages/tscx/src/cmd/copyfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export async function copyfiles(rootDir: string, outDir: string) {
await walkDir(rootDir, async (filepath) => {
const dest = filepath.replace(rootDir, outDir);
console.log("Copy", filepath, "=>", dest);
await fs.mkdir(path.dirname(dest), { recursive: true });
await fs.copyFile(filepath, dest);
});
}
11 changes: 6 additions & 5 deletions packages/tscx/src/compiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Compiler } from "./compiler.js";

describe("compiler", () => {
it("should get include", () => {
const exec = vi
.spyOn(childProcess, "execSync")
.mockReturnValue(
JSON.stringify({ include: ["foo"], compilerOptions: { strict: true } }),
);
const exec = vi.spyOn(childProcess, "execSync").mockReturnValue(
JSON.stringify({
include: ["foo"],
compilerOptions: { strict: true, rootDir: ".", outDir: "dist" },
}),
);
const compiler = new Compiler({
project: "tsconfig.json",
remove: false,
Expand Down

0 comments on commit 0a2f8df

Please sign in to comment.