diff --git a/bin/helpers/capabilityHelper.js b/bin/helpers/capabilityHelper.js index 425f7e43..f380b981 100644 --- a/bin/helpers/capabilityHelper.js +++ b/bin/helpers/capabilityHelper.js @@ -183,11 +183,17 @@ const getAccessibilityPlatforms = (bsConfig) => { const addCypressZipStartLocation = (runSettings) => { let resolvedHomeDirectoryPath = path.resolve(runSettings.home_directory); let resolvedCypressConfigFilePath = path.resolve(runSettings.cypressConfigFilePath); - runSettings.cypressZipStartLocation = path.dirname(resolvedCypressConfigFilePath.split(resolvedHomeDirectoryPath)[1]); + + // Convert to POSIX style paths for consistent behavior + let posixHomePath = resolvedHomeDirectoryPath.split(path.sep).join(path.posix.sep); + let posixConfigPath = resolvedCypressConfigFilePath.split(path.sep).join(path.posix.sep); + + runSettings.cypressZipStartLocation = path.posix.dirname(posixConfigPath.split(posixHomePath)[1]); runSettings.cypressZipStartLocation = runSettings.cypressZipStartLocation.substring(1); logger.debug(`Setting cypress zip start location = ${runSettings.cypressZipStartLocation}`); } + const validate = (bsConfig, args) => { return new Promise(function (resolve, reject) { logger.info(Constants.userMessages.VALIDATING_CONFIG); diff --git a/bin/helpers/readCypressConfigUtil.js b/bin/helpers/readCypressConfigUtil.js index bdf556bc..efc60edc 100644 --- a/bin/helpers/readCypressConfigUtil.js +++ b/bin/helpers/readCypressConfigUtil.js @@ -13,6 +13,48 @@ exports.detectLanguage = (cypress_config_filename) => { return constants.CYPRESS_V10_AND_ABOVE_CONFIG_FILE_EXTENSIONS.includes(extension) ? extension : 'js' } +function generateTscCommandAndTempTsConfig(bsConfig, bstack_node_modules_path, complied_js_dir, cypress_config_filepath) { + const working_dir = path.dirname(cypress_config_filepath); + const typescript_path = path.join(bstack_node_modules_path, 'typescript', 'bin', 'tsc'); + const tsc_alias_path = path.join(bstack_node_modules_path, 'tsc-alias', 'dist', 'bin', 'index.js'); + const tsConfigFilePath = path.resolve(bsConfig.run_settings.ts_config_file_path); + + // Prepare base temp tsconfig + const tempTsConfig = { + extends: tsConfigFilePath, // Use a base tsconfig if available + compilerOptions: { + "outDir": `${path.basename(complied_js_dir)}`, // Add ./ prefix for consistency + "listEmittedFiles": true, + }, + include: [cypress_config_filepath] + }; + + // Write the temporary tsconfig + const tempTsConfigPath = path.join(working_dir, 'tsconfig.singlefile.tmp.json'); + fs.writeFileSync(tempTsConfigPath, JSON.stringify(tempTsConfig, null, 2)); + logger.info(`Temporary tsconfig created at: ${tempTsConfigPath}`); + + // Platform-specific command generation + const isWindows = /^win/.test(process.platform); + + if (isWindows) { + // Windows: Use && to chain commands, no space after SET + const setNodePath = isWindows + ? `set NODE_PATH=${bstack_node_modules_path}` + : `NODE_PATH="${bstack_node_modules_path}"`; + + const tscCommand = `${setNodePath} && node "${typescript_path}" --project "${tempTsConfigPath}" && ${setNodePath} && node "${tsc_alias_path}" --project "${tempTsConfigPath}" --verbose`; + logger.info(`TypeScript compilation command: ${tscCommand}`); + return { tscCommand, tempTsConfigPath }; + } else { + // Unix/Linux/macOS: Use ; to separate commands or && to chain + const nodePathPrefix = `NODE_PATH=${bsConfig.run_settings.bstack_node_modules_path}`; + const tscCommand = `${nodePathPrefix} node "${typescript_path}" --project "${tempTsConfigPath}" && ${nodePathPrefix} node "${tsc_alias_path}" --project "${tempTsConfigPath}" --verbose`; + logger.info(`TypeScript compilation command: ${tscCommand}`); + return { tscCommand, tempTsConfigPath }; + } +} + exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_modules_path) => { const cypress_config_filename = bsConfig.run_settings.cypress_config_filename const working_dir = path.dirname(cypress_config_filepath); @@ -22,19 +64,13 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module } fs.mkdirSync(complied_js_dir, { recursive: true }) - const typescript_path = path.join(bstack_node_modules_path, 'typescript', 'bin', 'tsc') + const { tscCommand, tempTsConfigPath } = generateTscCommandAndTempTsConfig(bsConfig, bstack_node_modules_path, complied_js_dir, cypress_config_filepath); - let tsc_command = `NODE_PATH=${bstack_node_modules_path} node "${typescript_path}" --outDir "${complied_js_dir}" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false "${cypress_config_filepath}"` - - if (/^win/.test(process.platform)) { - tsc_command = `set NODE_PATH=${bstack_node_modules_path}&& node "${typescript_path}" --outDir "${complied_js_dir}" --listEmittedFiles true --allowSyntheticDefaultImports --module commonjs --declaration false "${cypress_config_filepath}"` - } - - let tsc_output try { - logger.debug(`Running: ${tsc_command}`) - tsc_output = cp.execSync(tsc_command, { cwd: working_dir }) + logger.debug(`Running: ${tscCommand}`) + tsc_output = cp.execSync(tscCommand, { cwd: working_dir }) + cp.execSync(tscCommand, { cwd: working_dir }) } catch (err) { // error while compiling ts files logger.debug(err.message); @@ -44,6 +80,14 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module logger.debug(`Saved compiled js output at: ${complied_js_dir}`); logger.debug(`Finding compiled cypress config file in: ${complied_js_dir}`); + // Clean up the temporary tsconfig file + if (fs.existsSync(tempTsConfigPath)) { + fs.unlinkSync(tempTsConfigPath); + logger.info(`Temporary tsconfig file removed: ${tempTsConfigPath}`); + } + + logger.info(tsc_output.toString()); + const lines = tsc_output.toString().split('\n'); let foundLine = null; for (let i = 0; i < lines.length; i++) { @@ -53,7 +97,7 @@ exports.convertTsConfig = (bsConfig, cypress_config_filepath, bstack_node_module } } if (foundLine === null) { - logger.error(`No compiled cypress config found. There might some error running ${tsc_command} command`) + logger.error(`No compiled cypress config found. There might some error running ${tscCommand} command`) return null } else { const compiled_cypress_config_filepath = foundLine.split('TSFILE: ').pop() @@ -113,4 +157,4 @@ exports.readCypressConfigFile = (bsConfig) => { fs.rmdirSync(complied_js_dir, { recursive: true }) } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 719e663d..0cc5fe2d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "browserstack-local": "1.5.4", "chalk": "4.1.2", "cli-progress": "^3.10.0", + "decompress": "4.2.1", "form-data": "^4.0.0", "fs-extra": "8.1.0", "getmac": "5.20.0", @@ -26,17 +27,16 @@ "git-repo-info": "^2.1.1", "gitconfiglocal": "^2.1.0", "glob": "^7.2.0", - "mocha": "^10.2.0", "mkdirp": "1.0.4", + "mocha": "^10.2.0", "node-ipc": "9.1.1", "table": "5.4.6", + "unzipper": "^0.12.3", "update-notifier": "7.0.0", "uuid": "8.3.2", "windows-release": "^5.1.0", "winston": "2.4.4", - "yargs": "14.2.3", - "decompress": "4.2.1", - "unzipper": "^0.12.3" + "yargs": "14.2.3" }, "repository": { "type": "git",