Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions npm-packages/convex/src/bundler/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect, test, afterEach, vi } from "vitest";
import { oneoffContext } from "./context.js";
import { normalizeModulePath } from "./index.js";

// Although these tests are run as ESM by ts-lint, this file is built as both
// CJS and ESM by TypeScript so normal recipes like `__dirname` for getting the
Expand Down Expand Up @@ -180,3 +181,14 @@ test("must use isolate", () => {
expect(mustBeIsolate("schema2.js")).not.toBeTruthy();
expect(mustBeIsolate("schema/http.js")).not.toBeTruthy();
});

test("normalizeModulePath removes Windows drive letter and normalizes slashes", () => {
// Windows drive letter with forward slashes
expect(normalizeModulePath("C:/Users/test/out/convex/foo.js")).toBe("Users/test/out/convex/foo.js");
// Windows drive letter with backslashes
expect(normalizeModulePath("D:\\project\\out\\convex\\bar.js")).toBe("project/out/convex/bar.js");
// Already relative path
expect(normalizeModulePath("convex/foo.js")).toBe("convex/foo.js");
// No drive letter, just slashes
expect(normalizeModulePath("/convex/foo.js")).toBe("/convex/foo.js");
});
10 changes: 9 additions & 1 deletion npm-packages/convex/src/bundler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ export async function bundle(
continue;
}
const posixRelPath = relPath.split(path.sep).join(path.posix.sep);
modules.push({ path: posixRelPath, source: outputFile.text, environment });
const normalizedPath = normalizeModulePath(posixRelPath);
modules.push({ path: normalizedPath, source: outputFile.text, environment });
}
for (const module of modules) {
const sourceMapPath = module.path + ".map";
Expand Down Expand Up @@ -437,6 +438,13 @@ export async function entryPoints(
// A fallback regex in case we fail to parse the AST.
export const useNodeDirectiveRegex = /^\s*("|')use node("|');?\s*$/;

export function normalizeModulePath(posixRelPath: string): string {
// Remove Windows drive letter (e.g., "C:/" or "D:/") if present
let noDrive = posixRelPath.replace(/^[A-Za-z]:\\|^[A-Za-z]:\//, "");
// Convert all backslashes to forward slashes
return noDrive.replace(/\\/g, "/");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suspect we're going to want to use standard libraries rather than doing our own custom string crunching like this.

Windows paths are incredibly complex and there are a lot of ways they can be represented - sticking to standard libraries rather than writing custom will be worthwhile.

https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats

Would also appreciate if you could look into where the module path is used and why it's sent up to the server. That may help us understand what the right solution is. In general, having OS-specific paths sent to the server is probably not the right architecture since the same convex backend can be developed with from multiple OSes.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks @nipunn1313 , i will take a look at standard libraries for that, also will check usage & why it is sent up to server. Thanks for the input


function hasUseNodeDirective(ctx: Context, fpath: string): boolean {
// Do a quick check for the exact string. If it doesn't exist, don't
// bother parsing.
Expand Down