Skip to content

Commit ab73bf7

Browse files
authored
chore(void): drop no-op backslash normalization on pathe relative() paths (#252)
## What This removes the `.replace(/\\/g, '/')` calls that were applied to the results of pathe `relative()` and `join()` across seven files. The source files are codegen/env-types.ts, codegen/project-tsconfig.ts, drizzle/config.ts, drizzle/discover.ts, ssr/entry.ts, and sveltekit.ts, and the same no-op appeared in a test/unit/prerender.test.ts assertion, for nine occurrences in total. ## Why pathe returns POSIX forward slash paths on every platform, including Windows, so calling `.replace(/\\/g, '/')` on a pathe `relative()` or `join()` result can never match anything. It is dead defensive code. codegen/route-types.ts and codegen/queue-types.ts already follow this convention and omit the call, so this brings the rest of the package in line. ## Safety There is no behavior change. It was verified empirically that pathe `relative()` returns forward slashes for both POSIX and Windows backslash inputs, so `relative('C:\\a\\b\\.void', 'C:\\a\\b\\src\\env.ts')` returns `../src/env.ts`. The six other `.replace(/\\/g, '/')` calls in the package operate on raw path parameters rather than pathe output. Those live in shared/utils.ts (the slash helper), router/parse-filename.ts, router/websocket.ts, cli/package.ts, and prerender.ts, and they are intentionally left untouched because they normalize real OS separators. ## Verification The void package typechecks cleanly with tsgo and passes oxlint. The net change is nine insertions and nine deletions across seven files with no functional effect.
1 parent 9284ea2 commit ab73bf7

7 files changed

Lines changed: 9 additions & 9 deletions

File tree

‎packages/void/src/codegen/env-types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export type EnvTypesResult = {
4747
* @param outDir Absolute path to the project's `.void/` directory.
4848
*/
4949
export function generateEnvTypes(envFileAbs: string, outDir: string): EnvTypesResult {
50-
const importPath = relative(outDir, envFileAbs).replace(/\\/g, '/');
50+
const importPath = relative(outDir, envFileAbs);
5151
const lines: Array<string> = [];
5252

5353
lines.push('// Auto-generated by void — do not edit');

‎packages/void/src/codegen/project-tsconfig.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export function createProjectTsconfig(
6464
const isDir = existsSync(pathsConfig.schemaDir) && !existsSync(pathsConfig.schemaFile);
6565

6666
// Paths are relative to .void/ (where this tsconfig lives), so use ../
67-
const schemaRel = relative(outDir, pathsConfig.schemaDir).replace(/\\/g, '/');
68-
const schemaFileRel = relative(outDir, pathsConfig.schemaFile).replace(/\\/g, '/');
67+
const schemaRel = relative(outDir, pathsConfig.schemaDir);
68+
const schemaFileRel = relative(outDir, pathsConfig.schemaFile);
6969
paths['@schema'] = [isDir ? `${schemaRel}/index.ts` : schemaFileRel];
7070
paths['@schema/*'] = [`${schemaRel}/*`];
7171
}

‎packages/void/src/drizzle/config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export function writeDrizzleConfig(
3131
? {
3232
dialect: 'postgresql',
3333
schema: schemaSpecifier(schema, root),
34-
out: `./${relative(root, paths.migrationsDir).replace(/\\/g, '/')}`,
34+
out: `./${relative(root, paths.migrationsDir)}`,
3535
migrations: { prefix: 'timestamp' },
3636
dbCredentials: { url: dbPath },
3737
}
3838
: {
3939
dialect: 'sqlite',
4040
schema: schemaSpecifier(schema, root),
41-
out: `./${relative(root, paths.migrationsDir).replace(/\\/g, '/')}`,
41+
out: `./${relative(root, paths.migrationsDir)}`,
4242
migrations: { prefix: 'timestamp' },
4343
dbCredentials: { url: dbPath },
4444
};

‎packages/void/src/drizzle/discover.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ export function schemaSpecifier(location: SchemaLocation, root?: string): string
3939
if (!root) {
4040
return location.type === 'file' ? './db/schema.ts' : './db/schema/*.ts';
4141
}
42-
const rel = relative(root, location.path).replace(/\\/g, '/');
42+
const rel = relative(root, location.path);
4343
return location.type === 'file' ? `./${rel}` : `./${rel}/*.ts`;
4444
}

‎packages/void/src/ssr/entry.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function resolveSingleEntry(
3939
): ResolvedEntry | null {
4040
const matches = entries
4141
.map((entryName) => ({
42-
relativePath: relative(root, join(paths.ssrDir, entryName)).replace(/\\/g, '/'),
42+
relativePath: relative(root, join(paths.ssrDir, entryName)),
4343
absolutePath: join(paths.ssrDir, entryName),
4444
}))
4545
.filter((entry) => existsSync(entry.absolutePath));

‎packages/void/src/sveltekit.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function resolveTsconfigEntry(baseDir: string, entry: string): string {
104104
}
105105

106106
function relativeFrom(fromDir: string, target: string): string {
107-
const value = relative(fromDir, target).replace(/\\/g, '/');
107+
const value = relative(fromDir, target);
108108
return value.startsWith('.') ? value : `./${value}`;
109109
}
110110

‎packages/void/test/unit/prerender.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('collectPrerenderWorkerModules', () => {
8181

8282
expect(
8383
modules.map(({ path, type }) => ({
84-
path: relative(workerDir, path).replace(/\\/g, '/'),
84+
path: relative(workerDir, path),
8585
type,
8686
})),
8787
).toEqual([

0 commit comments

Comments
 (0)