Skip to content

Commit

Permalink
Checks for RNW environment (#1733)
Browse files Browse the repository at this point in the history
* Added env checks: DeveloperMode, .NET Core, LongPathSupport, Compilers, build tools, SDKs and Visual Studio, Windows

Co-authored-by: AndreiLobanovich <andrei.lobanovich@akvelon.com>
Co-authored-by: RedMickey <33267199+RedMickey@users.noreply.github.com>
Co-authored-by: Heniker <Heniker@mail.ru>
  • Loading branch information
4 people committed Feb 1, 2022
1 parent 68c2947 commit 62af5fc
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/extension/appLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
generateRandomPortNumber,
} from "../common/extensionHelper";
import { ReactNativeCDPProxy } from "../cdp-proxy/reactNativeCDPProxy";

import { MultipleLifetimesAppWorker } from "../debugger/appWorker";
import { ProjectsStorage } from "./projectsStorage";
import { PlatformResolver } from "./platformResolver";
Expand Down
18 changes: 18 additions & 0 deletions src/extension/commandPaletteHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { isWorkspaceTrusted } from "../common/extensionHelper";
import { ErrorHelper } from "../common/error/errorHelper";
import { InternalErrorCode } from "../common/error/internalErrorCode";
import { CONTEXT_VARIABLES_NAMES } from "../common/contextVariablesNames";
import { RNProjectObserver } from "./rnProjectObserver";
import { TipNotificationService } from "./services/tipsNotificationsService/tipsNotificationService";
import * as XDL from "./exponent/xdlInterface";
import { SettingsHelper } from "./settingsHelper";
Expand Down Expand Up @@ -545,14 +546,31 @@ export class CommandPaletteHandler {
}

public static async testDevEnvironment(): Promise<void> {
const createRNProjectObserver = async (
project: AppLauncher,
): Promise<RNProjectObserver> => {
const nodeModulesRoot = project.getOrUpdateNodeModulesRoot();
const projectRootPath = SettingsHelper.getReactNativeProjectRoot(
project.getWorkspaceFolderUri().fsPath,
);
const versions =
await ProjectVersionHelper.getReactNativePackageVersionsFromNodeModules(
nodeModulesRoot,
[REACT_NATIVE_PACKAGES.REACT_NATIVE_WINDOWS],
);
return new RNProjectObserver(projectRootPath, versions);
};
const project = await this.selectProject().catch(() => undefined);
const projectObserver =
project && (await createRNProjectObserver(project).catch(() => undefined));
const shouldCheck = {
[ValidationCategoryE.Expo]:
(await project
?.getPackager()
.getExponentHelper()
.isExpoManagedApp(false)
.catch(() => false)) || false,
[ValidationCategoryE.Windows]: projectObserver?.isRNWindowsProject || false,
} as const;

await runChecks(shouldCheck);
Expand Down
44 changes: 44 additions & 0 deletions src/extension/services/validationService/checks/devmode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as nls from "vscode-nls";
import { executeCommand } from "../util";
import { IValidation, ValidationCategoryE, ValidationResultT } from "./types";

nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const toLocale = nls.loadMessageBundle();

const label = "DeveloperMode";

async function test(): Promise<ValidationResultT> {
const command =
"reg query HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AppModelUnlock /v AllowDevelopmentWithoutDevLicense";
const data = await executeCommand(command);
if (data.stdout) {
if (data.stdout.includes(" 0x1"))
return {
status: "success",
};
}

return {
status: "failure",
comment: "Developer mode is disabled",
};
}

const main: IValidation = {
label,
platform: ["win32"],
description: toLocale(
"DeveloperModeTestDescription",
"Required for launching and debugging RNW apps",
),
category: ValidationCategoryE.Windows,
exec: test,
};

export default main;
43 changes: 43 additions & 0 deletions src/extension/services/validationService/checks/dotnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as nls from "vscode-nls";
import { createNotFoundMessage, createVersionErrorMessage, executeCommand } from "../util";
import { IValidation, ValidationCategoryE, ValidationResultT } from "./types";

nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const toLocale = nls.loadMessageBundle();

const label = ".NET Core 3.1";

async function test(): Promise<ValidationResultT> {
const command = "dotnet --info";
const data = await executeCommand(command);
if (data.stdout) {
if (data.stdout.includes("Microsoft.NETCore.App 3.1"))
return {
status: "success",
};
return {
status: "failure",
comment: createVersionErrorMessage(label),
};
}
return {
status: "failure",
comment: createNotFoundMessage(label),
};
}

const main: IValidation = {
label,
platform: ["win32"],
description: toLocale("DotNetTestDescription", "Required for building RNW apps"),
category: ValidationCategoryE.Windows,
exec: test,
};

export default main;
11 changes: 11 additions & 0 deletions src/extension/services/validationService/checks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import watchman from "./watchman";
import iosDeploy from "./iosDeploy";
import xcodebuild from "./xcodebuild";
import expoCli from "./expoCli";
import devmode from "./devmode";
import visualStudio from "./visualStudio";
import longPath from "./longPath";
import windows from "./windows";
import dotnet from "./dotnet";

import { IValidation } from "./types";

export const getChecks = (): IValidation[] => {
Expand All @@ -36,6 +42,11 @@ export const getChecks = (): IValidation[] => {
watchman,
xcodebuild,
expoCli,
devmode,
visualStudio,
longPath,
windows,
dotnet,
] as const;

return checks.filter(it => (it.platform ? it.platform.includes(process.platform) : true));
Expand Down
2 changes: 1 addition & 1 deletion src/extension/services/validationService/checks/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function test(): Promise<ValidationResultT> {
if (result.versionCompare === -1) {
return {
status: "partial-success",
comment: `Detected version is older than 1.8.0. Please install ${label} 8 in case of errors`,
comment: `Detected version is older than 1.8.0. Please install ${label} 8 or 11 in case of errors`,
};
}

Expand Down
40 changes: 40 additions & 0 deletions src/extension/services/validationService/checks/longPath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as nls from "vscode-nls";
import { executeCommand } from "../util";
import { IValidation, ValidationCategoryE, ValidationResultT } from "./types";

nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const toLocale = nls.loadMessageBundle();

const label = "LongPathSupport";

async function test(): Promise<ValidationResultT> {
const command =
"reg query HKLM\\SYSTEM\\CurrentControlSet\\Control\\FileSystem /v LongPathsEnabled";
const data = await executeCommand(command);
if (data.stdout) {
if (data.stdout.includes(" 0x1"))
return {
status: "success",
};
}
return {
status: "failure",
comment: "Long path support is disabled",
};
}

const main: IValidation = {
label,
platform: ["win32"],
description: toLocale("LongPathSupportTestDescription", "Required for building RNW apps"),
category: ValidationCategoryE.Windows,
exec: test,
};

export default main;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum ValidationCategoryE {
Android = "Android",
iOS = "iOS",
Expo = "Expo",
Windows = "Windows",
}

export type ValidationResultT = {
Expand Down
73 changes: 73 additions & 0 deletions src/extension/services/validationService/checks/visualStudio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as nls from "vscode-nls";
import * as semver from "semver";
import { createNotFoundMessage, executeCommand, normizeStr } from "../util";
import { IValidation, ValidationCategoryE, ValidationResultT } from "./types";

nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const toLocale = nls.loadMessageBundle();

const label = "Compilers, build tools, SDKs and Visual Studio";

async function test(): Promise<ValidationResultT> {
let vswherePath = ``;
if (process.env["ProgramFiles(x86)"]) {
vswherePath = `"${process.env["ProgramFiles(x86)"]}\\Microsoft Visual Studio\\Installer\\vswhere.exe"`;
} else {
vswherePath = `"C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe"`;
}
const components = [
"Microsoft.Component.MSBuild",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.ComponentGroup.UWP.Support",
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Core",
"Microsoft.VisualStudio.Component.Windows10SDK.19041",
];
const command = `${vswherePath} -property catalog_productDisplayVersion`;
const result = await executeCommand(command);
if (result.stdout) {
const versions = normizeStr(result.stdout).split("\n");
const valid = (version: string) => semver.gtr(version, "16.5");
if (versions.some(valid)) {
for (const comp of components) {
const pathToComponent = await executeCommand(
`${vswherePath} -requires ${comp} -property productPath`,
);
if (!pathToComponent.stdout) {
return {
status: "failure",
comment: `Please check if ${comp} is installed`,
};
}
}
return {
status: "success",
};
}
return {
status: "partial-success",
comment:
"Detected version is older than 16.5. " +
"Please update Visual Studio in case of errors",
};
}
return {
status: "failure",
comment: createNotFoundMessage(label),
};
}

const main: IValidation = {
label,
platform: ["win32"],
description: toLocale("VisualStudioCheckDescription", "Required for building RNW apps"),
category: ValidationCategoryE.Windows,
exec: test,
};

export default main;
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function test(): Promise<ValidationResultT> {

const main: IValidation = {
label,
platform: ["darwin", "android"],
platform: ["darwin"],
description: toLocale("WatchmanTestDescription", "Required for watching file changes"),
category: ValidationCategoryE.Common,
exec: test,
Expand Down
39 changes: 39 additions & 0 deletions src/extension/services/validationService/checks/windows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as os from "os";
import * as nls from "vscode-nls";
import * as semver from "semver";
import { IValidation, ValidationCategoryE, ValidationResultT } from "./types";

nls.config({
messageFormat: nls.MessageFormat.bundle,
bundleFormat: nls.BundleFormat.standalone,
})();
const toLocale = nls.loadMessageBundle();

const label = "Windows version > 10.0.16299.0";

async function test(): Promise<ValidationResultT> {
const version = os.release();

if (semver.gte(version, "10.0.16299")) {
return {
status: "success",
};
}
return {
status: "failure",
comment: `Unsupported version of Windows detected - ${version}. Please, update Windows in case of errors.`,
};
}

const main: IValidation = {
label,
platform: ["win32"],
description: toLocale("RNWBuildTestDescription", "Required for running RNW apps"),
category: ValidationCategoryE.Windows,
exec: test,
};

export default main;

0 comments on commit 62af5fc

Please sign in to comment.