Skip to content

Commit

Permalink
Respond to PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jculvey committed Nov 7, 2023
1 parent d539ad4 commit ece618d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .changeset/dirty-bobcats-eat.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
"create-cloudflare": patch
---

Fixes c3 usage with yarn
Changes c3 to use `npx` for running framework creation tools when it is invoked with `yarn`. This is
needed since yarn can't `yarn create some-package@some-particular-version`.
33 changes: 19 additions & 14 deletions packages/create-cloudflare/src/helpers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,17 +253,33 @@ export const installPackages = async (
});
};

export const npmInstall = async () => {
// Resets the package manager context for a project by clearing out existing dependencies
// and lock files then re-installing.
// This is needed in situations where npm is automatically used by framework creators for the initial
// install, since using other package managers in a folder with an existing npm install will cause failures
// when installing subsequent packages
export const resetPackageManager = async (ctx: PagesGeneratorContext) => {
const { npm } = detectPackageManager();

if (!needsPackageManagerReset(ctx)) {
return;
}

const nodeModulesPath = path.join(ctx.project.path, "node_modules");
if (existsSync(nodeModulesPath)) rmSync(nodeModulesPath, { recursive: true });

const lockfilePath = path.join(ctx.project.path, "package-lock.json");
if (existsSync(lockfilePath)) rmSync(lockfilePath);

await runCommand(`${npm} install`, {
silent: true,
cwd: ctx.project.path,
startText: "Installing dependencies",
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
});
};

const needsReset = (ctx: PagesGeneratorContext) => {
const needsPackageManagerReset = (ctx: PagesGeneratorContext) => {
const { npm } = detectPackageManager();
const projectPath = ctx.project.path;

Expand All @@ -279,22 +295,11 @@ const needsReset = (ctx: PagesGeneratorContext) => {
}
};

// Resets the package manager context for a project by clearing out existing dependencies
// and lock files then re-installing.
export const resetPackageManager = async (ctx: PagesGeneratorContext) => {
export const npmInstall = async () => {
const { npm } = detectPackageManager();

if (!needsReset(ctx)) return;

const nodeModulesPath = path.join(ctx.project.path, "node_modules");
if (existsSync(nodeModulesPath)) rmSync(nodeModulesPath, { recursive: true });

const lockfilePath = path.join(ctx.project.path, "package-lock.json");
if (existsSync(lockfilePath)) rmSync(lockfilePath);

await runCommand(`${npm} install`, {
silent: true,
cwd: ctx.project.path,
startText: "Installing dependencies",
doneText: `${brandColor("installed")} ${dim(`via \`${npm} install\``)}`,
});
Expand Down

0 comments on commit ece618d

Please sign in to comment.