Skip to content

Commit 0e55627

Browse files
authored
fix: resolve absolute outDir paths correctly (#6)
1 parent 176dc80 commit 0e55627

3 files changed

Lines changed: 43 additions & 7 deletions

File tree

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "srcpack",
3-
"version": "0.1.10",
3+
"version": "0.1.13",
44
"description": "Zero-config CLI for bundling code into LLM-optimized context files",
55
"keywords": [
66
"llm",
@@ -54,7 +54,8 @@
5454
"files": [
5555
"dist",
5656
"src",
57-
"schema.json"
57+
"LICENSE",
58+
"README.md"
5859
],
5960
"scripts": {
6061
"build": "bun build ./src/cli.ts ./src/index.ts --outdir ./dist --target node && tsc",

src/cli.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Options:
197197
for (const { name, outfile, result } of outputs) {
198198
const fileCount = result.index.length;
199199
const lineCount = sumLines(result);
200-
const outPath = join(root, outfile);
200+
const outPath = resolve(root, outfile);
201201

202202
const nameCol = name.padEnd(maxNameLen);
203203
const filesCol = formatNumber(fileCount).padStart(maxFilesLen);
@@ -213,8 +213,9 @@ Options:
213213
} else {
214214
await mkdir(dirname(outPath), { recursive: true });
215215
await writeFile(outPath, result.content);
216+
const displayPath = relative(process.cwd(), outPath);
216217
console.log(
217-
` ${nameCol} ${filesCol} ${plural(fileCount, "file")} ${linesCol} ${plural(lineCount, "line")}${outfile}`,
218+
` ${nameCol} ${filesCol} ${plural(fileCount, "file")} ${linesCol} ${plural(lineCount, "line")}${displayPath}`,
218219
);
219220
}
220221
}
@@ -358,7 +359,7 @@ async function handleGdriveUpload(
358359

359360
for (let i = 0; i < toUpload.length; i++) {
360361
const output = toUpload[i]!;
361-
const filePath = join(root, output.outfile);
362+
const filePath = resolve(root, output.outfile);
362363
uploadSpinner.text = `Uploading ${output.name}... (${i + 1}/${toUpload.length})`;
363364
const result = await uploadFile(filePath, uploadConfig);
364365
results.push(result);

tests/e2e/cli.test.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { join } from "node:path";
2-
import { describe, expect, test } from "bun:test";
1+
import { mkdir, rm, writeFile } from "node:fs/promises";
2+
import { join, resolve } from "node:path";
3+
import { tmpdir } from "node:os";
4+
import { describe, expect, test, afterEach } from "bun:test";
35

46
const CLI_PATH = join(import.meta.dir, "../../src/cli.ts");
57
const FIXTURE_PATH = join(import.meta.dir, "../fixtures/sample-project");
@@ -114,4 +116,36 @@ describe("cli", () => {
114116
expect(result.stderr).toContain("Unknown bundle: unknown");
115117
});
116118
});
119+
120+
describe("absolute outDir with custom root", () => {
121+
const tempRoot = join(tmpdir(), `srcpack-test-${Date.now()}`);
122+
const tempOutDir = join(tmpdir(), `srcpack-out-${Date.now()}`);
123+
124+
afterEach(async () => {
125+
await rm(tempRoot, { recursive: true, force: true });
126+
await rm(tempOutDir, { recursive: true, force: true });
127+
});
128+
129+
test("should write to absolute outDir when root is also specified", async () => {
130+
// Setup: create temp project with config using absolute outDir
131+
await mkdir(join(tempRoot, "src"), { recursive: true });
132+
await writeFile(join(tempRoot, "src/index.ts"), "export const x = 1;");
133+
await writeFile(
134+
join(tempRoot, "srcpack.config.ts"),
135+
`export default {
136+
outDir: ${JSON.stringify(tempOutDir)},
137+
bundles: { app: "src/**/*" },
138+
};`,
139+
);
140+
141+
const result = await runCli([], { cwd: tempRoot });
142+
143+
expect(result.exitCode).toBe(0);
144+
expect(result.stdout).toContain("app");
145+
146+
// Verify file was written to absolute outDir, not joined with root
147+
const outFile = Bun.file(join(tempOutDir, "app.txt"));
148+
expect(await outFile.exists()).toBe(true);
149+
});
150+
});
117151
});

0 commit comments

Comments
 (0)