Skip to content

Commit

Permalink
getParentDirectory -> getDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed Dec 10, 2024
1 parent 153e463 commit 8b5abdd
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
10 changes: 10 additions & 0 deletions .changeset/chatty-fireants-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'renoun': minor
---

Renames `Directory` and `File` `getParentDirectory` methods to `getParent` to better align with `getSiblings`. This also aligns more closely with the web File System API's [getParent}(https://developer.mozilla.org/en-US/docs/Web/API/FileSystemEntry/getParent) method.

### Breaking Changes

- `Directory.getParentDirectory` is now `Directory.getParent`
- `File.getParentDirectory` is now `File.getParent`
2 changes: 1 addition & 1 deletion apps/site/app/(site)/components/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default async function Component({
const Content = await mdxFile?.getExportValue('default')
const componentDirectory = isDirectory(componentEntry)
? componentEntry
: componentEntry.getParentDirectory()
: componentEntry.getParent()
const mainExport = await componentEntry.getExport<any>(slug)
const description = mainExport ? mainExport.getDescription() : null
const examplesEntry = await componentDirectory.getEntry('examples')
Expand Down
2 changes: 1 addition & 1 deletion examples/design-system/app/components/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function Component({

const componentDirectory = isDirectory(componentEntry)
? componentEntry
: componentEntry.getParentDirectory()
: componentEntry.getParent()
const mainEntry =
(await componentDirectory.getFile(slug, ['ts', 'tsx'])) ||
(await componentDirectory.getFile('index', ['ts', 'tsx']))
Expand Down
4 changes: 1 addition & 3 deletions packages/renoun/src/file-system/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,7 @@ describe('file system', () => {
>()
}

const normalizedDirectory = isFile(entry)
? entry.getParentDirectory()
: entry
const normalizedDirectory = isFile(entry) ? entry.getParent() : entry

expect(isDirectory(normalizedDirectory)).toBe(true)

Expand Down
14 changes: 7 additions & 7 deletions packages/renoun/src/file-system/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class File<
}

/** Get the directory containing this file. */
getParentDirectory(): Directory<Types, HasModule> {
getParent(): Directory<Types, HasModule> {
return this.#directory
}

Expand Down Expand Up @@ -286,7 +286,7 @@ export class JavaScriptFileExport<
return undefined
}

const fileSystem = this.#file.getParentDirectory().getFileSystem()
const fileSystem = this.#file.getParent().getFileSystem()

this.#metadata = await fileSystem.getFileExportMetadata(
this.#name,
Expand Down Expand Up @@ -376,7 +376,7 @@ export class JavaScriptFileExport<
)
}

const fileSystem = this.#file.getParentDirectory().getFileSystem()
const fileSystem = this.#file.getParent().getFileSystem()

return fileSystem.resolveTypeAtLocation(
this.#file.getAbsolutePath(),
Expand Down Expand Up @@ -531,7 +531,7 @@ export class JavaScriptFile<Exports extends ExtensionType> extends File {

/** Get all export names and positions from the JavaScript file. */
async #getExports() {
const fileSystem = this.getParentDirectory().getFileSystem()
const fileSystem = this.getParent().getFileSystem()
return fileSystem.getFileExports(this.getAbsolutePath())
}

Expand Down Expand Up @@ -1150,7 +1150,7 @@ export class Directory<
}

/** Get the directory containing this directory. */
getParentDirectory() {
getParent() {
return this.#directory
}

Expand Down Expand Up @@ -1537,13 +1537,13 @@ export class Directory<
return false
}

let directory = entry.getParentDirectory()
let directory = entry.getParent()

while (directory) {
if (directory === this) {
return true
}
directory = directory.getParentDirectory()
directory = directory.getParent()
}

return false
Expand Down

0 comments on commit 8b5abdd

Please sign in to comment.