-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Problem Description
When using npm run switch nodejs (or other backends) to switch PuerTS backends, the script fails to locate the OneJS Unity package path, resulting in the following error:
OneJS.Runtime.csproj file does not exist.
Error: The "path" argument must be of type string. Received null
Steps to Reproduce
-
Install OneJS using Git URL method (in
Packages/manifest.json):"com.singtaa.onejs": "https://github.com/Singtaa/OneJS.git"
-
Execute in the
Appdirectory:npm run switch nodejs
-
Observe the error output
Error Message
Local .tgz found: tmp\PuerTS_Nodejs_2.2.2.tgz
Extraction completed.
OneJS.Runtime.csproj file does not exist.
Error: The "path" argument must be of type string. Received null
Problem Analysis
The getOneJSUnityDir() function in node_modules/onejs-core/scripts/switch.cjs has the following issues:
-
Only supports local paths: The script only checks for local paths with
file:prefix (line 120), and cannot handle Git URL type package dependencies -
Fallback is unreliable: When the path cannot be found from
manifest.json, the script attempts to find theOneJS.Runtime.csprojfile (line 131), but this file does not exist -
Missing error handling: When
getOneJSUnityDir()returnsnull, the subsequent code directly usespath.join(null, ...)causing a crash (line 68)
Relevant Code Locations
- File:
node_modules/onejs-core/scripts/switch.cjs - Function:
getOneJSUnityDir()(lines 100-176) - Call site:
Process()function (line 68)
// Line 68 - Missing null check
const onejsDir = await getOneJSUnityDir()
const a = path.join(onejsDir, 'Puerts/Editor/com.tencent.puerts.core.Editor.asmdef')
// ...// Lines 115-126 - Only supports file: paths
if (v.startsWith("file:")) {
oneJSPath = path.resolve(projectDir, v.substring(5))
return oneJSPath
}
// Git URL is ignored// Lines 129-172 - Fallback searches for csproj file
const csprojPath = path.join(projectDir, 'OneJS.Runtime.csproj')
if (fs.existsSync(csprojPath)) {
// ...
} else {
console.error('OneJS.Runtime.csproj file does not exist.')
return null // Returns null but caller doesn't handle it
}Expected Behavior
The script should be able to:
- Support Git URL type package dependencies (look for Unity's
Library/PackageCachedirectory) - Provide clearer error messages and usage instructions when the path cannot be found
- Gracefully handle errors when
getOneJSUnityDir()returnsnull, instead of crashing