## Problem
The file list in an Edge Function's code view is shown in the order the
Management API returns it (roughly `created_at` order), not sorted by
name. Users expect name order, as in VS Code.
Resolves FE-2799
## Solution
- `formatFunctionBodyToFiles` now sorts files by their displayed name
before assigning ids, using a case-insensitive numeric comparison
(`file2` before `file10`). The list is flat, so there is no folder
grouping.
- Sorting would have changed which file opens first, so the code page
now selects the function's entrypoint file by default.
`getDefaultSelectedFileId` matches the entrypoint's basename, then falls
back to `index.ts`, then to the first file. The entrypoint isn't always
`index.ts`: the docs allow any `.ts`, `.js`, `.tsx`, `.jsx` or `.mjs`
file.
- The shared `FileExplorerAndEditor` and the new-function page are
unchanged. The code page passes the selection through the explorer's
existing `selectedFileId` / `setSelectedFileId` props.
- Files added or renamed in the editor keep their position until the
next load.
Before:
<img width="259" height="370" alt="Screenshot 2026-10-15 at 16 44 50"
src="https://github.com/user-attachments/assets/611fe2b9-5676-496a-85a9-e50032708c7a"
/>
After:
<img width="259" height="371" alt="Screenshot 2026-10-15 at 16 35 19"
src="https://github.com/user-attachments/assets/7f433661-ef34-4e3f-9143-afc67be1b30a"
/>
## Review instructions
1. Open an Edge Function's Code tab for a function with several files,
for example `utils.ts`, `index.ts`, `deno.json`.
2. Confirm the files are listed alphabetically and that `index.ts` is
selected on load.
3. For a function with a custom entrypoint (for example `main.ts`),
confirm that file is selected on load.
4. Run `pnpm test:studio -- components/interfaces/EdgeFunctions`.
## Context
Drops the `@std/path` dependency which is used in `EdgeFunctions.utils`
as `npm.jsr.io` was putting up a Cloudflare bot challenge on some
connections which blocks `pnpm install`. Instead, opting to directly
port the exact required methods as self-contained functions. Also added
some unit tests to check that UI behaviour remains status quo.
## To test:
Important to test that everything in the edge functions UI remains
status quo
- [ ] Open an existing edge function with a single root-level file -
should load as expected
<img width="310" height="176" alt="image"
src="https://github.com/user-attachments/assets/4d724ab0-33bb-4093-a574-52984b2743fd"
/>
- [ ] Open (or create) an edge function with nested folders - confirm
file paths in the editor are shown correctly
- Can create nested folders by using `../` as such
<img width="319" height="228" alt="image"
src="https://github.com/user-attachments/assets/dd345b1f-7c45-47e9-975c-f2f2e53a0106"
/>
- [ ] Similarly, download the edge function as ZIP to verify that the
nested folders are all correctly located
- [ ] Open a function with `import_map.json` - confirm still detected as
import map through the network tab GET request for the edge function
code (Examples here with and without import map)
<img width="333" height="245" alt="image"
src="https://github.com/user-attachments/assets/90fc90e3-4a62-493b-9246-ed7e3b662e96"
/>
<img width="290" height="237" alt="image"
src="https://github.com/user-attachments/assets/2f692362-c9d4-4394-bc5a-4f84ab5fb6f1"
/>
- [ ] Deploy a new function via the editor
- [ ] Update an existing function via the editor (Test adding new files
etc)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Bug Fixes**
- Improved Edge Functions file path handling across supported
application environments.
- Nested entrypoints, URL-based entrypoints, root-level files, and
unmatched paths are now handled consistently.
- Generated files retain their content and receive sequential
identifiers reliably.
- Improved compatibility when processing and displaying files in
different application environments.
- **Tests**
- Added coverage for entrypoint path formatting, relative paths,
fallback behavior, unchanged paths, and identifier assignment.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->