Skip to content

test(core): remove FsAdapter#2979

Closed
iuioiua wants to merge 21 commits intodenoland:mainfrom
iuioiua:remove-FsAdapter
Closed

test(core): remove FsAdapter#2979
iuioiua wants to merge 21 commits intodenoland:mainfrom
iuioiua:remove-FsAdapter

Conversation

@iuioiua
Copy link
Contributor

@iuioiua iuioiua commented May 19, 2025

These changes simplify implementation logic and mock FS APIs in a more direct manner, making things easier to reason about.

Comment on lines +82 to +127
try {
for await (
const entry of walk(islandDir, {
includeDirs: false,
exts: ["tsx", "jsx", "ts", "js"],
skip,
})
) {
islandPaths.push(entry.path);
}
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}

try {
for await (
const entry of internals.walk(routesDir, {
includeDirs: false,
exts: ["tsx", "jsx", "ts", "js"],
skip,
})
) {
const relative = path.relative(routesDir, entry.path);

// A `(_islands)` path segment is a local island folder.
// Any route path segment wrapped in `(_...)` is ignored
// during route collection.
const match = relative.match(GROUP_REG);
if (match && match[2][0] === "_") {
if (match[2] === "_islands") {
islandPaths.push(entry.path);
}
continue;
}

const url = new URL(relative, "http://localhost/");
relRoutePaths.push(url.pathname.slice(1));
},
ignore,
fs,
),
]);
const url = new URL(relative, "http://localhost/");
relRoutePaths.push(url.pathname.slice(1));
}
} catch (error) {
// `islandDir` or `routesDir` does not exist, so we can skip it
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, instead of checking whether the first argument passed to walk() is a directory, we just simply try to walk it. If it's not a directory, a Deno.errors.NotFound error is thrown and we ignore it. This has the same functionality as before, but just without having to use some isDirectory() function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any performance gain from avoiding the isDirectory function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a slight performance benefit. But that's not the goal of the change. It just avoids the potential for hitting a (very unlikely) race condition by just attempting the operation and catching if it fails instead of checking if the operation can be performed then doing the operation if it can be. Does that make sense?

This was the exact topic of discussion for fs.exists() within the Standard Library. See the note in https://jsr.io/@std/fs/doc/~/exists.

Comment on lines -110 to -112
async isDirectory(dir) {
return Object.keys(files).some((file) => file.startsWith(dir + "/"));
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this mock is no longer exists, but that seems fine as tests pass.

@iuioiua iuioiua marked this pull request as ready for review May 20, 2025 00:11
Copy link
Contributor

@Mrashes Mrashes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall change makes sense - as I'm not a contributor I don't feel confident in approving but good job on this!

"foo.txt": "foo",
});
const transformer = new FreshFileTransformer();
using _denoReadFileStub = stubDenoReadFile("foo");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first time seeing the using keyword, neat!

Comment on lines +82 to +127
try {
for await (
const entry of walk(islandDir, {
includeDirs: false,
exts: ["tsx", "jsx", "ts", "js"],
skip,
})
) {
islandPaths.push(entry.path);
}
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}

try {
for await (
const entry of internals.walk(routesDir, {
includeDirs: false,
exts: ["tsx", "jsx", "ts", "js"],
skip,
})
) {
const relative = path.relative(routesDir, entry.path);

// A `(_islands)` path segment is a local island folder.
// Any route path segment wrapped in `(_...)` is ignored
// during route collection.
const match = relative.match(GROUP_REG);
if (match && match[2][0] === "_") {
if (match[2] === "_islands") {
islandPaths.push(entry.path);
}
continue;
}

const url = new URL(relative, "http://localhost/");
relRoutePaths.push(url.pathname.slice(1));
},
ignore,
fs,
),
]);
const url = new URL(relative, "http://localhost/");
relRoutePaths.push(url.pathname.slice(1));
}
} catch (error) {
// `islandDir` or `routesDir` does not exist, so we can skip it
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any performance gain from avoiding the isDirectory function?

@iuioiua
Copy link
Contributor Author

iuioiua commented Jun 1, 2025

@marvinhagemeister PTAL

@iuioiua
Copy link
Contributor Author

iuioiua commented Sep 2, 2025

While this makes testing and implementation much simpler, closing as stale.

@iuioiua iuioiua closed this Sep 2, 2025
@iuioiua iuioiua deleted the remove-FsAdapter branch September 2, 2025 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants