Skip to content

Commit

Permalink
fix: 'ms-enable-electron-run-as-node' is not in the list of known opt…
Browse files Browse the repository at this point in the history
…ions (#1156)

Signed-off-by: Dominik Jelinek <[email protected]>
  • Loading branch information
djelinek authored Feb 27, 2024
1 parent 9fe6aed commit 8a43ce7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/extester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ExTester {
await this.downloadChromeDriver(vscodeParsedVersion);
} else {
console.log('Attempting Setup in offline mode');
const expectedChromeVersion = (await this.code.checkOfflineRequirements()).split('.')[0];
const expectedChromeVersion = (this.code.checkOfflineRequirements()).split('.')[0];
const actualChromeVersion = (await this.chrome.checkDriverVersionOffline(vscodeParsedVersion)).split('.')[0];
if (expectedChromeVersion !== actualChromeVersion) {
console.log('\x1b[33m%s\x1b[0m', `WARNING: Local copy of VS Code runs Chromium version ${expectedChromeVersion}, the installed ChromeDriver is version ${actualChromeVersion}.`)
Expand Down
46 changes: 28 additions & 18 deletions src/util/codeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class CodeUtil {
}

console.log(`Downloading VS Code: ${literalVersion} / ${this.releaseType}`);
if (!fs.existsSync(this.executablePath) || await this.getExistingCodeVersion() !== literalVersion) {
if (!fs.existsSync(this.executablePath) || this.getExistingCodeVersion() !== literalVersion) {
fs.mkdirpSync(this.downloadFolder);

const url = ['https://update.code.visualstudio.com', version, this.downloadPlatform, this.releaseType].join('/');
Expand Down Expand Up @@ -159,8 +159,17 @@ export class CodeUtil {
}
}

private getCliInitCommand(): string {
let cli = `${this.cliEnv} "${this.executablePath}" "${this.cliPath}"`;
if(this.getExistingCodeVersion() >= '1.86.0') {
return cli;
} else {
return `${cli} --ms-enable-electron-run-as-node`
}
}

private installExt(pathOrID: string): void {
let command = `${this.cliEnv} "${this.executablePath}" "${this.cliPath}" --ms-enable-electron-run-as-node --force --install-extension "${pathOrID}"`;
let command = `${this.getCliInitCommand()} --force --install-extension "${pathOrID}"`;
if (this.extensionsFolder) {
command += ` --extensions-dir=${this.extensionsFolder}`;
}
Expand All @@ -173,7 +182,7 @@ export class CodeUtil {
*/
open(...paths: string[]): void {
const segments = paths.map(f => `"${f}"`).join(' ');
let command = `${this.cliEnv} "${this.executablePath}" "${this.cliPath}" --ms-enable-electron-run-as-node -r ${segments} --user-data-dir="${path.join(this.downloadFolder, 'settings')}"`;
let command = `${this.getCliInitCommand()} -r ${segments} --user-data-dir="${path.join(this.downloadFolder, 'settings')}"`;
child_process.execSync(command);
}

Expand Down Expand Up @@ -215,7 +224,7 @@ export class CodeUtil {
const extension = `${pjson.publisher}.${pjson.name}`;

if (cleanup) {
let command = `${this.cliEnv} "${this.executablePath}" "${this.cliPath}" --ms-enable-electron-run-as-node --uninstall-extension "${extension}"`;
let command = `${this.getCliInitCommand()} --uninstall-extension "${extension}"`;
if (this.extensionsFolder) {
command += ` --extensions-dir=${this.extensionsFolder}`;
}
Expand All @@ -235,7 +244,7 @@ export class CodeUtil {
if (!runOptions.offline) {
await this.checkCodeVersion(runOptions.vscodeVersion ?? DEFAULT_RUN_OPTIONS.vscodeVersion);
} else {
this.availableVersions = [await this.getExistingCodeVersion()];
this.availableVersions = [this.getExistingCodeVersion()];
}
const literalVersion = runOptions.vscodeVersion === undefined || runOptions.vscodeVersion === 'latest' ? this.availableVersions[0] : runOptions.vscodeVersion;

Expand Down Expand Up @@ -284,7 +293,7 @@ export class CodeUtil {
} catch (err) {
let version = '';
if (await fs.pathExists(this.codeFolder)) {
version = await this.getChromiumVersionOffline();
version = this.getChromiumVersionOffline();
}
if (version === '') {
throw new Error('Unable to determine required ChromeDriver version');
Expand All @@ -297,9 +306,9 @@ export class CodeUtil {
* Check if VS Code exists in local cache along with an appropriate version of chromedriver
* without internet connection
*/
async checkOfflineRequirements(): Promise<string> {
checkOfflineRequirements(): string {
try {
await this.getExistingCodeVersion();
this.getExistingCodeVersion();
} catch (err) {
console.log('ERROR: Cannot find a local copy of VS Code in offline mode, exiting.');
throw (err);
Expand All @@ -310,9 +319,9 @@ export class CodeUtil {
/**
* Attempt to get chromium version from a downloaded copy of vs code
*/
async getChromiumVersionOffline(): Promise<string> {
getChromiumVersionOffline(): string {
const manifestPath = path.join(this.codeFolder, 'resources', 'app', 'ThirdPartyNotices.txt');
const text = (await fs.readFile(manifestPath)).toString();
const text = (fs.readFileSync(manifestPath)).toString();
const matches = text.match(/chromium\sversion\s(.*)\s\(/);
if (matches && matches[1]) {
return matches[1];
Expand Down Expand Up @@ -342,14 +351,15 @@ export class CodeUtil {
/**
* Check what VS Code version is present in the testing folder
*/
private getExistingCodeVersion(): Promise<string> {
const command = [this.cliEnv, `"${this.executablePath}"`, `"${this.cliPath}"`, '--ms-enable-electron-run-as-node', '-v'].join(' ');
return new Promise<string>((resolve, reject) => {
child_process.exec(command, (err, stdout) => {
if (err) return reject(err);
resolve(stdout.split('\n')[0]);
});
});
private getExistingCodeVersion(): string {
let command = `${this.cliEnv} "${this.executablePath}" "${this.cliPath}"`;
let out: Buffer;
try {
out = child_process.execSync(`${command} -v`);
} catch (error) {
out = child_process.execSync(`${command} --ms-enable-electron-run-as-node -v`);
}
return out.toString().split('\n')[0];
}

/**
Expand Down

0 comments on commit 8a43ce7

Please sign in to comment.