Skip to content

Commit c54aeec

Browse files
fix(cli): run project path validation checks (#2985)
* feat: add Windows path length check to prevent build issues This update introduces a function to warn users about long project paths on Windows, which can lead to failures in Android CMake/Ninja builds due to MAX_PATH limitations. * fix: formatting fix * feat: move project path checks to validators and add check for macOS space in path * Update src/tools/validations.ts Co-authored-by: Frank Calise <[email protected]> --------- Co-authored-by: Frank Calise <[email protected]>
1 parent 23225ec commit c54aeec

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/commands/new.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ module.exports = {
507507
p()
508508
// #endregion
509509

510+
// #region Validate Project Path
511+
const { validateProjectPath } = require("../tools/validations") as ValidationsExports
512+
validateProjectPath(targetPath, toolbox)
513+
// #endregion
514+
510515
// #region Overwrite
511516
if (exists(targetPath) === "dir" && overwrite === true) {
512517
const msg = ` Tossing that old app like it's hot`

src/tools/validations.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,45 @@ export function validateBundleIdentifier(
9797
return bundleID
9898
}
9999

100+
/**
101+
* Check for project path issues (Windows length, macOS spaces)
102+
*
103+
*/
104+
105+
export function validateProjectPath(absPath: string, toolbox: GluegunToolbox) {
106+
const { print } = toolbox
107+
const normalized = absPath.replace(/[\\/]+$/, "")
108+
const len = normalized.length
109+
110+
// Check for spaces in path on macOS (Xcode build issues)
111+
if (process.platform === "darwin" && normalized.includes(" ")) {
112+
print.warning(`Project path contains spaces, which can cause Xcode build failures.`)
113+
print.warning(`Tip: use a path without spaces, e.g. "/Users/username/MyApp"`)
114+
print.warning(`Why: Xcode build scripts and CI systems can fail when paths contain spaces.`)
115+
print.warning(" ")
116+
}
117+
118+
if (process.platform === "win32") {
119+
// Threshold for warning about long paths on Windows
120+
const PATH_WARN_THRESHOLD = 120
121+
122+
// Warn if the path is too long: https://github.com/expo/expo/issues/36274
123+
if (len > PATH_WARN_THRESHOLD) {
124+
print.warning(
125+
`Windows project path is quite long (${len} chars). Android native builds can fail on very long paths.`,
126+
)
127+
print.warning(`Path: ${normalized}`)
128+
print.warning(`Tip: move your project closer to the drive root, e.g. ${"C:\\src\\MyApp"}`)
129+
print.warning(
130+
`Why: CMake/Ninja can generate very long object file paths that hit Windows limits.`,
131+
)
132+
print.warning(" ")
133+
}
134+
}
135+
}
136+
100137
export type ValidationsExports = {
101138
validateProjectName: typeof validateProjectName
102139
validateBundleIdentifier: typeof validateBundleIdentifier
140+
validateProjectPath: typeof validateProjectPath
103141
}

0 commit comments

Comments
 (0)