Add ForwardSlashPath branded type and forward-slash path utilities#1853
Open
Add ForwardSlashPath branded type and forward-slash path utilities#1853
ForwardSlashPath branded type and forward-slash path utilities#1853Conversation
Copilot
AI
changed the title
[WIP] Add branded string utility for replacing backslashes in paths
Add Apr 14, 2026
ForwardSlashPath branded type and toForwardSlashPath utility
pmcelhaney
requested changes
Apr 14, 2026
Collaborator
pmcelhaney
left a comment
There was a problem hiding this comment.
The new function is mostly used to fix the output of nodePath.join() or nodePath.relative()
Create two new utility functions that wrap the nodePath functions so we can eliminate duplication.
Contributor
Author
Done in commit
All call sites updated; several files no longer import |
pmcelhaney
approved these changes
Apr 14, 2026
Copilot
AI
changed the title
Add
Add Apr 14, 2026
ForwardSlashPath branded type and toForwardSlashPath utilityForwardSlashPath branded type and forward-slash path utilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Centralizes all
replaceAll("\\", "/")path normalization behind a suite of utility functions that return a brandedForwardSlashPathtype, enabling static enforcement that backslash-to-forward-slash conversion has occurred before a path is used in contexts that require it (chokidar watchers, ES module specifiers, URL routing).New utility (
src/util/forward-slash-path.ts):ForwardSlashPath— branded type (string & { readonly [__forwardSlashPath]: never }) using aunique symbolto prevent accidental assignment of un-normalized stringstoForwardSlashPath(path: string): ForwardSlashPath— the core normalization functionpathJoin(...paths: string[]): ForwardSlashPath— wrapsnodePath.join, returning a forward-slash pathpathRelative(from: string, to: string): ForwardSlashPath— wrapsnodePath.relative, returning a forward-slash pathpathDirname(path: string): ForwardSlashPath— wrapsnodePath.dirname, returning a forward-slash pathpathResolve(...paths: string[]): ForwardSlashPath— wrapsnodePath.resolve, returning a forward-slash pathUpdated call sites — 13 files replaced inline
.replaceAll("\\", "/")andtoForwardSlashPath(nodePath.xxx(...))patterns with the new utilities:src/server/—file-discovery.ts,module-loader.ts,transpiler.tssrc/typescript-generator/—repository.ts,script.ts,generate.ts,operation-coder.ts,operation-type-coder.ts,parameters-type-coder.ts,prune.tssrc/migrate/update-route-types.ts,src/app.ts,bin/counterfact.jsSeveral files (
transpiler.ts,script.ts,operation-coder.ts,operation-type-coder.ts,parameters-type-coder.ts,file-discovery.ts,app.ts) no longer importnodePathat all.Test updates:
test/server/transpiler.test.ts— removed localforwardSlashhelper; now importstoForwardSlashPathtest/util/forward-slash-path.test.ts— 14 unit tests covering all exported functionsOriginal Prompt
Create a utility function to replace replaceAll("\", "/") throughout the code.
Return a branded string and use that branded string wherever a path without backslashes is needed.
Manual acceptance tests
toForwardSlashPath("C:\\Users\\foo\\bar")returns"C:/Users/foo/bar"with no backslashes remainingpathJoin("routes", "pets.ts")returns"routes/pets.ts"(forward slashes, cross-platform)pathRelative("/a/b", "/a/b/c")returns"c"(forward slashes, cross-platform)stringto aForwardSlashPath-typed variable without going through one of the utility functionsTasks
src/util/forward-slash-path.tswithForwardSlashPathbranded type,toForwardSlashPath, and fournodePath-wrapping helpers (pathJoin,pathRelative,pathDirname,pathResolve).replaceAll("\\", "/")occurrences across 13 source files withtoForwardSlashPathor the appropriate wrappertoForwardSlashPath(nodePath.xxx(...))call-site patterns with the corresponding wrapper functiontest/server/transpiler.test.tsto importtoForwardSlashPathinstead of using a local helpertest/util/forward-slash-path.test.tswith 14 unit tests covering all exported functions