Skip to content

Commit

Permalink
fix: don't override package.json properties (#4017)
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg authored Jan 19, 2024
1 parent 145a10f commit 47924bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
21 changes: 16 additions & 5 deletions packages/generators/src/handlers/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,22 @@ export async function questions(
* @param self Generator values
*/
export function generate(self: CustomGenerator): void {
self.fs.extendJSON(
self.destinationPath("package.json"),
// eslint-disable-next-line @typescript-eslint/no-var-requires
require(resolveFile("package.json.js"))(self.answers.devServer),
);
// eslint-disable-next-line @typescript-eslint/no-var-requires
const destPkgJson = require(resolveFile("package.json.js"))(self.answers.devServer);
const sourcePkgJsonPath = self.destinationPath("package.json");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sourcePkgJson = require(sourcePkgJsonPath);
// Make sure that we do not override set metadata
if (sourcePkgJson.name) {
delete destPkgJson.name;
}
if (sourcePkgJson.description) {
delete destPkgJson.description;
}
if (sourcePkgJson.version) {
delete destPkgJson.version;
}
self.fs.extendJSON(sourcePkgJsonPath, destPkgJson);

// Generate entry file
let entry = "./src/index.";
Expand Down
17 changes: 15 additions & 2 deletions test/utils/test-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,24 @@ describe("runAndGetWatchProc function", () => {

it("writes to stdin", async () => {
const assetsPath = await uniqueDirectoryForTest();
const { stdout } = await runAndGetProcess(assetsPath, ["init", "--force", "--template=mango"], {
const proc = runAndGetProcess(assetsPath, ["init", "--force", "--template=mango"], {
input: ENTER,
timeout: 60000,
});

expect(stdout).toContain("Project has been initialised with webpack!");
let found = false;

await new Promise((resolve) => {
proc.stdout.on("data", (data) => {
if (data.includes("Project has been initialised with webpack!")) {
found = true;

resolve();
}
});
});

expect(found).toBe(true);
});
});

Expand Down

0 comments on commit 47924bf

Please sign in to comment.