diff --git a/package-lock.json b/package-lock.json index 5f252ad87..021a7bb38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46,7 +46,7 @@ "autoprefixer": "^10.4.19", "babel-loader": "^9.1.3", "com.foxdebug.acode.exec": "file:src/plugins/Executor", - "cordova-android": "^14.0.1", + "cordova-android": "^13.0.0", "cordova-clipboard": "^1.3.0", "cordova-plugin-advanced-http": "^3.3.1", "cordova-plugin-browser": "file:src/plugins/browser", @@ -4231,37 +4231,28 @@ } }, "node_modules/cordova-android": { - "version": "14.0.1", - "resolved": "https://registry.npmjs.org/cordova-android/-/cordova-android-14.0.1.tgz", - "integrity": "sha512-HMBMdGu/JlSQtmBuDEpKWf/pE75SpF3FksxZ+mqYuL3qSIN8lN/QsNurwYaPAP7zWXN2DNpvwlpOJItS5VhdLg==", + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/cordova-android/-/cordova-android-13.0.0.tgz", + "integrity": "sha512-uQG+cSyrB1NMi2aIzihldIupHB9WGpZVvrMMMAAtnyc6tDlEk7gweSSaFsEONyGAnteRYpIvrzg/YwDW08PcUg==", "dev": true, "license": "Apache-2.0", "dependencies": { - "android-versions": "^2.1.0", - "cordova-common": "^5.0.1", + "android-versions": "^2.0.0", + "cordova-common": "^5.0.0", "dedent": "^1.5.3", "execa": "^5.1.1", - "fast-glob": "^3.3.3", + "fast-glob": "^3.3.2", + "fs-extra": "^11.2.0", "is-path-inside": "^3.0.3", - "nopt": "^8.1.0", + "nopt": "^7.2.1", "properties-parser": "^0.6.0", - "semver": "^7.7.1", + "semver": "^7.6.2", "string-argv": "^0.3.1", "untildify": "^4.0.0", - "which": "^5.0.0" + "which": "^4.0.0" }, "engines": { - "node": ">=20.5.0" - } - }, - "node_modules/cordova-android/node_modules/abbrev": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-3.0.1.tgz", - "integrity": "sha512-AO2ac6pjRB3SJmGJo+v5/aK6Omggp6fsLrs6wN9bd35ulu4cCwaAU9+7ZhXjeqHVkaHThLuzH0nZr0YpCDhygg==", - "dev": true, - "license": "ISC", - "engines": { - "node": "^18.17.0 || >=20.5.0" + "node": ">=16.13.0" } }, "node_modules/cordova-android/node_modules/dedent": { @@ -4289,22 +4280,6 @@ "node": ">=16" } }, - "node_modules/cordova-android/node_modules/nopt": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-8.1.0.tgz", - "integrity": "sha512-ieGu42u/Qsa4TFktmaKEwM6MQH0pOWnaB3htzh0JRtx84+Mebc0cbZYN5bC+6WTZ4+77xrL9Pn5m7CV6VIkV7A==", - "dev": true, - "license": "ISC", - "dependencies": { - "abbrev": "^3.0.0" - }, - "bin": { - "nopt": "bin/nopt.js" - }, - "engines": { - "node": "^18.17.0 || >=20.5.0" - } - }, "node_modules/cordova-android/node_modules/semver": { "version": "7.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.2.tgz", @@ -4319,9 +4294,9 @@ } }, "node_modules/cordova-android/node_modules/which": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/which/-/which-5.0.0.tgz", - "integrity": "sha512-JEdGzHwwkrbWoGOlIHqQ5gtprKGOenpDHpxE9zVR1bWbOtYRyPPHMe9FaP6x61CmNaTThSkb0DAJte5jD+DmzQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz", + "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==", "dev": true, "license": "ISC", "dependencies": { @@ -4331,7 +4306,7 @@ "node-which": "bin/which.js" }, "engines": { - "node": "^18.17.0 || >=20.5.0" + "node": "^16.13.0 || >=18.0.0" } }, "node_modules/cordova-app-hello-world": { diff --git a/package.json b/package.json index 565b34aef..c3c31c4f5 100644 --- a/package.json +++ b/package.json @@ -115,4 +115,4 @@ "yargs": "^17.7.2" }, "browserslist": "cover 100%,not android < 5" -} +} \ No newline at end of file diff --git a/src/lib/run.js b/src/lib/run.js index 81b032c01..a38a554a8 100644 --- a/src/lib/run.js +++ b/src/lib/run.js @@ -599,12 +599,33 @@ async function run( // Get the project url const projectFolder = addedFolder[0]; - // Set the root folder to the file parent if no project folder is set + // FIXED: Better root folder determination for Termux URIs let rootFolder = pathName; - if (projectFolder !== undefined && pathName.includes(projectFolder)) { + + // Special handling for Termux URIs - extract the actual root from the URI structure + if ( + activeFile && + activeFile.uri && + activeFile.uri.includes("com.termux.documents") && + activeFile.uri.includes("tree/") + ) { + // Extract the tree part and decode it to get the actual root path + const treeMatch = activeFile.uri.match(/tree\/([^:]+)/); + if (treeMatch) { + try { + const decodedRoot = decodeURIComponent(treeMatch[1]); + rootFolder = decodedRoot; + console.log(`DEBUG - Termux root folder set to: ${rootFolder}`); + } catch (e) { + console.error("Error decoding Termux root:", e); + } + } + } else if ( + projectFolder !== undefined && + pathName && + pathName.includes(projectFolder.url) + ) { rootFolder = projectFolder.url; - } else { - rootFolder = pathName; } //make the uri absolute if necessary @@ -634,30 +655,25 @@ async function run( try { const [, realPath] = temp.split("::"); - // Determine root folder inside :: path - let rootPath = rootFolder; - if (rootFolder.includes("::")) { - rootPath = rootFolder.split("::")[1]; - } + console.log(`DEBUG - realPath: ${realPath}`); + console.log(`DEBUG - rootFolder: ${rootFolder}`); - // Normalize both paths to arrays - const realParts = realPath.split("/").filter(Boolean); - const rootParts = rootPath.split("/").filter(Boolean); + // Ensure rootFolder doesn't have trailing slash for comparison + const normalizedRoot = rootFolder.replace(/\/+$/, ""); - // Find where the paths start to differ - let diffIndex = 0; - while ( - diffIndex < realParts.length && - diffIndex < rootParts.length && - realParts[diffIndex] === rootParts[diffIndex] - ) { - diffIndex++; - } + // Check if realPath starts with rootFolder + if (realPath.startsWith(normalizedRoot)) { + // Remove the rootFolder from the beginning of realPath + let relativePath = realPath.substring(normalizedRoot.length); - // Return everything after the common root - const relativeParts = realParts.slice(diffIndex); - if (relativeParts.length > 0) { - return relativeParts.join("/"); + // Remove leading slash if present + relativePath = relativePath.replace(/^\/+/, ""); + + console.log(`DEBUG - relativePath: ${relativePath}`); + + if (relativePath) { + return relativePath; + } } } catch (e) { console.error("Error handling Termux URI:", e); @@ -697,26 +713,17 @@ async function run( } } - // Now find this rootFolderPath in the afterDoubleColon string - if (afterDoubleColon.includes(rootFolderPath)) { - // Find where to start the relative path - const parts = afterDoubleColon.split("/"); - - // Find the index of the part that matches or contains rootFolderPath - let startIndex = -1; - for (let i = 0; i < parts.length; i++) { - if ( - parts[i].includes(rootFolderPath) || - rootFolderPath.includes(parts[i]) - ) { - startIndex = i; - break; - } - } - - // If we found a matching part, get everything after it - if (startIndex >= 0 && startIndex < parts.length - 1) { - return parts.slice(startIndex + 1).join("/"); + // Use direct string replacement instead of path component comparison + const normalizedRoot = rootFolderPath.replace(/\/+$/, ""); + if (afterDoubleColon.startsWith(normalizedRoot)) { + let relativePath = afterDoubleColon.substring( + normalizedRoot.length, + ); + // Remove leading slash if present + relativePath = relativePath.replace(/^\/+/, ""); + + if (relativePath) { + return relativePath; } } } @@ -761,6 +768,7 @@ async function run( * Opens the preview in browser */ function openBrowser() { + console.log(`Running ${Url.join(pathName, filename)}`); let url = ""; if (pathName === null && !activeFile.location) { url = `http://localhost:${port}/__unsaved_file__`;