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: dont override set pkg.json props #4017

Merged
merged 4 commits into from
Jan 19, 2024
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
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 @@
* @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");

Check warning on line 181 in packages/generators/src/handlers/default.ts

View check run for this annotation

Codecov / codecov/patch

packages/generators/src/handlers/default.ts#L180-L181

Added lines #L180 - L181 were not covered by tests
// eslint-disable-next-line @typescript-eslint/no-var-requires
const sourcePkgJson = require(sourcePkgJsonPath);

Check warning on line 183 in packages/generators/src/handlers/default.ts

View check run for this annotation

Codecov / codecov/patch

packages/generators/src/handlers/default.ts#L183

Added line #L183 was not covered by tests
// Make sure that we do not override set metadata
if (sourcePkgJson.name) {
delete destPkgJson.name;

Check warning on line 186 in packages/generators/src/handlers/default.ts

View check run for this annotation

Codecov / codecov/patch

packages/generators/src/handlers/default.ts#L186

Added line #L186 was not covered by tests
}
if (sourcePkgJson.description) {
delete destPkgJson.description;

Check warning on line 189 in packages/generators/src/handlers/default.ts

View check run for this annotation

Codecov / codecov/patch

packages/generators/src/handlers/default.ts#L189

Added line #L189 was not covered by tests
}
if (sourcePkgJson.version) {
delete destPkgJson.version;

Check warning on line 192 in packages/generators/src/handlers/default.ts

View check run for this annotation

Codecov / codecov/patch

packages/generators/src/handlers/default.ts#L192

Added line #L192 was not covered by tests
}
self.fs.extendJSON(sourcePkgJsonPath, destPkgJson);

Check warning on line 194 in packages/generators/src/handlers/default.ts

View check run for this annotation

Codecov / codecov/patch

packages/generators/src/handlers/default.ts#L194

Added line #L194 was not covered by tests

// 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
Loading