Skip to content
Closed
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
22 changes: 5 additions & 17 deletions packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { glob } from "tinyglobby";
import ignore from "ignore";
import "./environments";
import { isBinaryFile } from "isbinaryfile";
import { writePackageJSON, type PackageJson } from "pkg-types";
import type { PackageJson } from "pkg-types";
import pkg from "./package.json" with { type: "json" };
import { createDefaultTemplate } from "./template";

Expand Down Expand Up @@ -251,13 +251,7 @@ const main = defineCommand({

console.warn("preparing template:", pJson.name);

const restore = await writeDeps(
templateDir,
pJsonContents,
pJson,
deps,
realDeps,
);
const restore = writeDeps(templateDir, pJson, deps, realDeps);

const gitignorePath = path.join(templateDir, ".gitignore");
const ig = ignore().add("node_modules").add(".git");
Expand Down Expand Up @@ -334,10 +328,7 @@ const main = defineCommand({
continue;
}

restoreMap.set(
p,
await writeDeps(p, pJsonContents, pJson, deps, realDeps),
);
restoreMap.set(p, await writeDeps(p, pJson, deps, realDeps));
}

const shasums: Record<string, string> = {};
Expand Down Expand Up @@ -552,9 +543,8 @@ async function resolveTarball(pm: "npm" | "pnpm", p: string) {
return { filename, shasum };
}

async function writeDeps(
function writeDeps(
p: string,
pJsonContents: string,
pJson: PackageJson,
deps: Map<string, string>,
realDeps: Map<string, string> | null,
Expand All @@ -569,9 +559,7 @@ async function writeDeps(
hijackDeps(realDeps, pJson.peerDependencies);
}

await writePackageJSON(pJsonPath, pJson);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a mistake? it means writeDeps will no longer write the package.json, which is the whole point of this function 😬

the line below is a restore function, i.e. it shouldn't be doing any reformatting as its meant to restore the original raw contents

this line is meant to write the formatted new JSON


return () => fs.writeFile(pJsonPath, pJsonContents);
return () => fs.writeFile(pJsonPath, JSON.stringify(pJson, null, 2));
}

function hijackDeps(
Expand Down
Loading