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: preserve existing package.json scripts #1252

Merged
merged 2 commits into from
Jan 16, 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
23 changes: 0 additions & 23 deletions script/__snapshots__/migrate-test-e2e.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,3 @@ exports[`expected file changes > knip.json 1`] = `
+ "project": ["src/**/*.ts!"]
}"
`;

exports[`expected file changes > package.json 1`] = `
"--- a/package.json
+++ b/package.json
@@ ... @@
"scripts": {
"build": "tsup",
"format": "prettier .",
- "initialize": "tsx ./bin/index.js --mode initialize",
"lint": "eslint . .*js --max-warnings 0",
"lint:knip": "knip",
"lint:md": "markdownlint \\"**/*.md\\" \\".github/**/*.md\\" --rules sentences-per-line",
@@ ... @@
"prepare": "husky install",
"should-semantic-release": "should-semantic-release --verbose",
"test": "vitest",
- "test:create": "node script/create-test-e2e.js",
- "test:initialize": "node script/initialize-test-e2e.js",
- "test:migrate": "vitest run -r script/",
"tsc": "tsc"
},
"lint-staged": {"
`;
1 change: 0 additions & 1 deletion script/migrate-test-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import packageData from "../package.json" assert { type: "json" };
const filesExpectedToBeChanged = [
"README.md",
"knip.json",
"package.json",
".eslintignore",
".eslintrc.cjs",
".github/workflows/test.yml",
Expand Down
7 changes: 5 additions & 2 deletions src/steps/writing/creation/writePackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readFileSafeAsJson } from "../../../shared/readFileSafeAsJson.js";
import { Options } from "../../../shared/types.js";
import { Options, PartialPackageData } from "../../../shared/types.js";
import { formatJson } from "./formatters/formatJson.js";

const devDependenciesToRemove = [
Expand Down Expand Up @@ -31,7 +31,9 @@ const devDependenciesToRemove = [

export async function writePackageJson(options: Options) {
const existingPackageJson =
((await readFileSafeAsJson("./package.json")) as null | object) ?? {};
((await readFileSafeAsJson(
"./package.json",
)) as PartialPackageData | null) ?? {};

return await formatJson({
// If we didn't already have a version, set it to 0.0.0
Expand Down Expand Up @@ -82,6 +84,7 @@ export async function writePackageJson(options: Options) {
url: `https://github.com/${options.owner}/${options.repository}`,
},
scripts: {
...existingPackageJson.scripts,
build: "tsup",
format: "prettier .",
lint: "eslint . .*js --max-warnings 0",
Expand Down