Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: spfx scaffolding #12173

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DependencyValidateError } from "../error";
import { Constants } from "../utils/constants";
import { telemetryHelper } from "../utils/telemetry-helper";
import { TelemetryEvents, TelemetryProperty } from "../utils/telemetryEvents";
import { getExecCommand, Utils } from "../utils/utils";
import { getExecCommand, getShellOptionValue, Utils } from "../utils/utils";
import { DependencyChecker } from "./dependencyChecker";

const name = Constants.GeneratorPackageName;
Expand Down Expand Up @@ -177,7 +177,7 @@ export class GeneratorChecker implements DependencyChecker {
await cpUtils.executeCommand(
undefined,
this._logger,
{ timeout: timeout, shell: false },
{ timeout: timeout, shell: getShellOptionValue() },
getExecCommand("npm"),
"install",
`${name}@${version}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { telemetryHelper } from "../utils/telemetry-helper";
import { TelemetryEvents, TelemetryProperty } from "../utils/telemetryEvents";
import { DependencyValidateError } from "../error";
import { cpUtils } from "../../../deps-checker/util/cpUtils";
import { getExecCommand, Utils } from "../utils/utils";
import { getExecCommand, getShellOptionValue, Utils } from "../utils/utils";
import { Constants } from "../utils/constants";
import { NpmInstallError } from "../../../../error";

Expand Down Expand Up @@ -181,7 +181,7 @@ export class YoChecker implements DependencyChecker {
await cpUtils.executeCommand(
undefined,
this._logger,
{ timeout: timeout, shell: false },
{ timeout: timeout, shell: getShellOptionValue() },
getExecCommand("npm"),
"install",
`${name}@${version}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { Constants, ManifestTemplate } from "./utils/constants";
import { ProgressHelper } from "./utils/progress-helper";
import { telemetryHelper } from "./utils/telemetry-helper";
import { TelemetryEvents, TelemetryProperty } from "./utils/telemetryEvents";
import { Utils } from "./utils/utils";
import { getShellOptionValue, Utils } from "./utils/utils";

export class SPFxGenerator {
@hooks([
Expand Down Expand Up @@ -350,6 +350,7 @@ export class SPFxGenerator {
{
timeout: 2 * 60 * 1000,
env: yoEnv,
shell: getShellOptionValue(),
},
"yo",
...args
Expand Down
14 changes: 9 additions & 5 deletions packages/fx-core/src/component/generator/spfx/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { exec, execSync } from "child_process";
import { LogProvider } from "@microsoft/teamsfx-api";
import axios, { AxiosInstance } from "axios";
import { cpUtils, DebugLogger } from "../../../deps-checker/util/cpUtils";
import * as os from "os";
import os from "os";
import { Constants } from "./constants";

export class Utils {
Expand Down Expand Up @@ -103,7 +103,7 @@ export class Utils {
const output = await cpUtils.executeCommand(
undefined,
logger,
{ shell: true },
{ shell: getShellOptionValue() },
"npm",
"--version"
);
Expand All @@ -125,7 +125,7 @@ export class Utils {
const output = await cpUtils.executeCommand(
undefined,
undefined,
undefined,
{ shell: getShellOptionValue() },
"node",
"--version"
);
Expand Down Expand Up @@ -153,7 +153,7 @@ export class Utils {
const output = await cpUtils.executeCommand(
undefined,
logger,
{ timeout: timeout, shell: false },
{ timeout: timeout, shell: getShellOptionValue() },
getExecCommand("npm"),
"ls",
`${packageName}`,
Expand Down Expand Up @@ -186,7 +186,7 @@ export class Utils {
const output = await cpUtils.executeCommand(
undefined,
logger,
{ timeout: timeout, shell: false },
{ timeout: timeout, shell: getShellOptionValue() },
getExecCommand("npm"),
"view",
`${packageName}`,
Expand Down Expand Up @@ -235,6 +235,10 @@ export function getExecCommand(command: string): string {
return isWindows() ? `${command}.cmd` : command;
}

export function getShellOptionValue(): boolean | string {
return isWindows() ? "cmd.exe" : true;
}

function isWindows(): boolean {
return os.type() === "Windows_NT";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
SPFxGeneratorImport,
SPFxGeneratorNew,
} from "../../../src/component/generator/spfx/spfxGenerator";
import { Utils } from "../../../src/component/generator/spfx/utils/utils";
import { getShellOptionValue, Utils } from "../../../src/component/generator/spfx/utils/utils";
import { envUtil } from "../../../src/component/utils/envUtil";
import { FileNotFoundError, UserCancelError } from "../../../src/error";
import {
Expand All @@ -31,6 +31,7 @@ import {
SPFxVersionOptionIds,
} from "../../../src/question";
import { MockTools } from "../../core/utils";
import os from "os";

describe("SPFxGenerator", function () {
const testFolder = path.resolve("./tmp");
Expand Down Expand Up @@ -1197,6 +1198,27 @@ describe("Utils", () => {
const res = Utils.truncateAppShortName(appName);
chai.expect(res).equals("appNameWithoutSuffix");
});

describe("getShellOptionValue", () => {
const sandbox = sinon.createSandbox();
afterEach(() => {
sandbox.restore();
});

it("windows", () => {
sandbox.stub(os, "type").returns("Windows_NT");
const res = getShellOptionValue();

chai.expect(res).equal("cmd.exe");
});

it("non windowns", () => {
sandbox.stub(os, "type").returns("Linux");
const res = getShellOptionValue();

chai.expect(res).true;
});
});
});

describe("SPFxGeneratorNew", () => {
Expand Down
Loading