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

feat(remix-dev): use auto-detected package manager #2562

Merged
merged 10 commits into from
Apr 12, 2022
Prev Previous commit
Next Next commit
Merge branch 'dev' into feat/pm-detection
  • Loading branch information
illright committed Apr 12, 2022
commit 7d462b272b18fbea2aba9d36271808797858186e
43 changes: 43 additions & 0 deletions packages/remix-dev/__tests__/cli-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,49 @@ describe("remix CLI", () => {
"💿 You've opted out of installing dependencies so we won't run the remix.init/index.js script for you just yet. Once you've installed dependencies, you can run it manually with `pnpm exec remix init`"
);
});

it("allows you to go through the prompts and convert to JS", async () => {
let projectDir = path.join(TEMP_DIR, "my-js-app");

let proc = childProcess.spawn(
"node",
[
"--require",
require.resolve("esbuild-register"),
"--require",
path.join(__dirname, "./msw.ts"),
path.resolve(__dirname, "../cli.ts"),
"create",
],
{ stdio: [null, null, null] }
);

await interactWithShell(proc, [
{ question: /Where.*create.*app/i, type: [projectDir, ENTER] },
{ question: /What type of app/i, answer: /basics/i },
{ question: /Where.*deploy/i, answer: /express/i },
{ question: /install/i, type: ["n", ENTER] },
{ question: /typescript or javascript/i, answer: /javascript/i },
]);

expect(
fse.existsSync(path.join(projectDir, "package.json"))
).toBeTruthy();
expect(
fse.existsSync(path.join(projectDir, "app/root.jsx"))
).toBeTruthy();
expect(fse.existsSync(path.join(projectDir, "app/root.tsx"))).toBeFalsy();
expect(
fse.existsSync(path.join(projectDir, "tsconfig.json"))
).toBeFalsy();
expect(
fse.existsSync(path.join(projectDir, "jsconfig.json"))
).toBeTruthy();
let pkgJSON = JSON.parse(
fse.readFileSync(path.join(projectDir, "package.json"), "utf-8")
);
expect(Object.keys(pkgJSON.devDependencies)).not.toContain("typescript");
});
});
});

Expand Down
39 changes: 0 additions & 39 deletions packages/remix-dev/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ import { setupRemix, isSetupPlatform, SetupPlatform } from "./setup";

export * as migrate from "./migrate";

const npxInterop = {
npm: "npx",
yarn: "yarn",
pnpm: "pnpm exec",
};

export async function create({
appTemplate,
projectDir,
Expand Down Expand Up @@ -59,39 +53,6 @@ export async function create({
});
spinner.stop();
spinner.clear();

if (hasInitScript) {
if (installDeps) {
console.log("💿 Running remix.init script");
await init(projectDir, packageManager);
await fse.remove(initScriptDir);
} else {
console.log();
console.log(
colors.warning(
"💿 You've opted out of installing dependencies so we won't run the " +
"remix.init/index.js script for you just yet. Once you've installed " +
`dependencies, you can run it manually with \`${npxInterop[packageManager]} remix init\``
)
);
console.log();
}
}

let relProjectDir = path.relative(process.cwd(), projectDir);
let projectDirIsCurrentDir = relProjectDir === "";

if (projectDirIsCurrentDir) {
console.log(
`💿 That's it! Check the README for development and deploy instructions!`
);
} else {
console.log(
"💿 That's it! `cd` into " +
colors.logoGreen(path.resolve(process.cwd(), projectDir)) +
" and check the README for development and deploy instructions!"
);
}
}

export async function init(
Expand Down
15 changes: 10 additions & 5 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ const templateChoices = [
{ name: "Cloudflare Workers", value: "cloudflare-workers" },
];

const npxInterop = {
npm: "npx",
yarn: "yarn",
pnpm: "pnpm exec",
};

/**
* Programmatic interface for running the Remix CLI with the given command line
* arguments.
Expand Down Expand Up @@ -335,10 +341,9 @@ export async function run(argv: string[] = process.argv.slice(2)) {
appTemplate: flags.template || answers.appTemplate,
projectDir,
remixVersion: flags.remixVersion,
installDeps: flags.install !== false && answers.install !== false,
installDeps,
packageManager: pm,
useTypeScript:
flags.typescript !== false && answers.useTypeScript !== false,
useTypeScript: flags.typescript !== false,
githubToken: process.env.GITHUB_TOKEN,
});

Expand Down Expand Up @@ -372,15 +377,15 @@ export async function run(argv: string[] = process.argv.slice(2)) {
if (hasInitScript) {
if (installDeps) {
console.log("💿 Running remix.init script");
await commands.init(projectDir);
await commands.init(projectDir, pm);
await fse.remove(initScriptDir);
} else {
console.log();
console.log(
colors.warning(
"💿 You've opted out of installing dependencies so we won't run the " +
"remix.init/index.js script for you just yet. Once you've installed " +
"dependencies, you can run it manually with `npx remix init`"
`dependencies, you can run it manually with \`${npxInterop[pm]} remix init\``
)
);
console.log();
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.