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(remix-dev): fix package manager detection #3109

Merged
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
37 changes: 17 additions & 20 deletions packages/remix-dev/__tests__/create-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,8 @@ describe("the create command", () => {
});

it("recognizes when Yarn was used to run the command", async () => {
let originalUserAgent = process.env.npm_user_agent;
process.env.npm_user_agent = yarnUserAgent;
let originalUserAgent = process.env.npm_config_user_agent;
process.env.npm_config_user_agent = yarnUserAgent;

let projectDir = await getProjectDir("yarn-create");
await run([
Expand All @@ -464,12 +464,12 @@ describe("the create command", () => {
]);

expect(execSync).toBeCalledWith("yarn install", expect.anything());
process.env.npm_user_agent = originalUserAgent;
process.env.npm_config_user_agent = originalUserAgent;
});

it("recognizes when pnpm was used to run the command", async () => {
let originalUserAgent = process.env.npm_user_agent;
process.env.npm_user_agent = pnpmUserAgent;
let originalUserAgent = process.env.npm_config_user_agent;
process.env.npm_config_user_agent = pnpmUserAgent;

let projectDir = await getProjectDir("pnpm-create");
await run([
Expand All @@ -482,12 +482,12 @@ describe("the create command", () => {
]);

expect(execSync).toBeCalledWith("pnpm install", expect.anything());
process.env.npm_user_agent = originalUserAgent;
process.env.npm_config_user_agent = originalUserAgent;
});

it("prompts to run the install command for the preferred package manager", async () => {
let originalUserAgent = process.env.npm_user_agent;
process.env.npm_user_agent = pnpmUserAgent;
let originalUserAgent = process.env.npm_config_user_agent;
process.env.npm_config_user_agent = pnpmUserAgent;

let projectDir = await getProjectDir("pnpm-prompt-install");
let mockPrompt = jest.mocked(inquirer.prompt);
Expand All @@ -512,12 +512,12 @@ describe("the create command", () => {
"message",
"Do you want me to run `pnpm install`?"
);
process.env.npm_user_agent = originalUserAgent;
process.env.npm_config_user_agent = originalUserAgent;
});

it("suggests to run the init command with the preferred package manager", async () => {
let originalUserAgent = process.env.npm_user_agent;
process.env.npm_user_agent = pnpmUserAgent;
let originalUserAgent = process.env.npm_config_user_agent;
process.env.npm_config_user_agent = pnpmUserAgent;

let projectDir = await getProjectDir("pnpm-suggest-install");
let mockPrompt = jest.mocked(inquirer.prompt);
Expand All @@ -537,7 +537,7 @@ describe("the create command", () => {
]);

expect(output).toContain(getOptOutOfInstallMessage("pnpm exec remix init"));
process.env.npm_user_agent = originalUserAgent;
process.env.npm_config_user_agent = originalUserAgent;
});

describe("errors", () => {
Expand Down Expand Up @@ -702,14 +702,11 @@ function getSuccessMessage(projectDirectory: string) {
return `💿 That's it! \`cd\` into "${projectDirectory}" and check the README for development and deploy instructions!`;
}

function getOptOutOfInstallMessage(command = "npx remix init") {
return (
"💿 You've opted out of installing dependencies so we won't run the " +
path.join("remix.init", "index.js") +
" script for you just yet. Once you've installed dependencies, you can run " +
`it manually with \`${command}\``
);
}
const getOptOutOfInstallMessage = (command = "yarn remix init") =>
"💿 You've opted out of installing dependencies so we won't run the " +
path.join("remix.init", "index.js") +
" script for you just yet. Once you've installed dependencies, you can run " +
`it manually with \`${command}\``;

/*
eslint
Expand Down
5 changes: 2 additions & 3 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ import { validateNewProjectPath, validateTemplate } from "./create";
* that can be used to determine which package manager ran
* the command.
*/
function getPreferredPackageManager() {
return ((process.env.npm_user_agent ?? "").split("/")[0] || "npm") as
const getPreferredPackageManager = () =>
((process.env.npm_config_user_agent ?? "").split("/")[0] || "npm") as
| "npm"
| "yarn"
| "pnpm";
}

const helpText = `
${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
Expand Down