Repository: alloy-framework/alloy
Pull request #23 (2024-09-14 22:25:57)

Fix: @alloy-js/java `PackageDirectory` recursivley defining path
Recent changes to `SourceDirectory` automatically append the parent path to the complete path of the `SourceDirectory`. The `PackageDirectory` was already doing this, so when `SourceDirectory` changed it was appending the parent path twice causing incorrect directory to be emitted.

This removes the parent path appending from `PackageDirectory` so it works as normal.

pkg-pr-new[bot]: 
[Open in Stackblitz](https://pkg.pr.new/template/6e996a2b-4a7d-4244-bae0-36ffdcfa6263)


<details><summary><b>@alloy-js/babel-plugin-alloy</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/babel-plugin-alloy@23
```

</p></details>
      
    

<details><summary><b>@alloy-js/babel-plugin-jsx-dom-expressions</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/babel-plugin-jsx-dom-expressions@23
```

</p></details>
      
    

<details><summary><b>babel-preset-alloy</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/babel-preset-alloy@23
```

</p></details>
      
    

<details><summary><b>@alloy-js/core</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/core@23
```

</p></details>
      
    

<details><summary><b>@alloy-js/csharp</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/csharp@23
```

</p></details>
      
    

<details><summary><b>@alloy-js/java</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/java@23
```

</p></details>
      
    

<details><summary><b>@alloy-js/prettier-plugin-alloy</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/prettier-plugin-alloy@23
```

</p></details>
      
    

<details><summary><b>@alloy-js/typescript</b></summary><p>

```
pnpm add https://pkg.pr.new/alloy-framework/alloy/@alloy-js/typescript@23
```

</p></details>
      
    

_commit: <a href="https://github.com/alloy-framework/alloy/runs/30152967959"><code>7e2f48a</code></a>_


Patch:
diff --git a/packages/java/src/components/PackageDirectory.tsx b/packages/java/src/components/PackageDirectory.tsx
index 8b272e8..19d5767 100644
--- a/packages/java/src/components/PackageDirectory.tsx
+++ b/packages/java/src/components/PackageDirectory.tsx
@@ -76,7 +76,7 @@ export function PackageDirectory(props: PackageDirectoryProps) {
 
   return <PackageDirectoryContext.Provider value={packageContext}>
       <Scope value={scope}>
-        <SourceDirectory path={packagePath}>
+        <SourceDirectory path={packageName}>
           <ChildPackageDirectory />
         </SourceDirectory>
       </Scope>


Test patch:
diff --git a/packages/java/test/package.test.tsx b/packages/java/test/package.test.tsx
new file mode 100644
index 0000000..fc54597
--- /dev/null
+++ b/packages/java/test/package.test.tsx
@@ -0,0 +1,18 @@
+import { expect, it } from "vitest";
+import * as jv from "../src/components/index.js";
+import { findFile, testRender } from "./utils.js";
+
+it("emits correct package directory", () => {
+  const res = testRender(
+    <>
+      <jv.PackageDirectory package='my.emit.package'>
+        <jv.SourceFile path="Test.java">
+        </jv.SourceFile>
+      </jv.PackageDirectory>
+    </>,
+  );
+
+  // Assert directory file is in is correct
+  const testFile = findFile(res, "Test.java");
+  expect(testFile.path).toBe("me/test/code/my/emit/package/Test.java");
+});