-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: infer base from package json scripts during migration (#993)
<!-- 👋 Hi, thanks for sending a PR to create-typescript-app! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [x] Addresses an existing open issue: fixes #933 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md) were taken ## Overview Add a naive solution for checking the existing `package.json` during migration to infer the base. 🐸 --------- Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
- Loading branch information
1 parent
c7217b7
commit 20afaf4
Showing
5 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { describe, expect, it, vi } from "vitest"; | ||
|
||
import { getBase } from "./getBase.js"; | ||
|
||
const mockReadPackageData = vi.fn(); | ||
vi.mock("../packages.js", () => ({ | ||
get readPackageData() { | ||
return mockReadPackageData; | ||
}, | ||
})); | ||
|
||
describe("getBase", () => { | ||
it("should return minimum with minimum scripts", async () => { | ||
mockReadPackageData.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
scripts: { | ||
build: "build", | ||
lint: "lint", | ||
test: "test", | ||
}, | ||
}), | ||
); | ||
|
||
expect(await getBase()).toBe("minimum"); | ||
}); | ||
it("should return common with common scripts", async () => { | ||
mockReadPackageData.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
scripts: { | ||
build: "build", | ||
lint: "lint", | ||
"lint:knip": "knip", | ||
test: "test", | ||
}, | ||
}), | ||
); | ||
|
||
expect(await getBase()).toBe("common"); | ||
}); | ||
it("should return everything with everything scripts", async () => { | ||
mockReadPackageData.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
scripts: { | ||
build: "build", | ||
lint: "lint", | ||
"lint:knip": "knip", | ||
"lint:md": "md", | ||
"lint:package-json": "package-json", | ||
"lint:packages": "packages", | ||
test: "test", | ||
}, | ||
}), | ||
); | ||
|
||
expect(await getBase()).toBe("everything"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { readPackageData } from "../packages.js"; | ||
import { OptionsBase } from "../types.js"; | ||
|
||
const commonScripts = new Set(["lint:knip", "should-semantic-release", "test"]); | ||
|
||
const everythingScripts = new Set([ | ||
"lint:md", | ||
"lint:package-json", | ||
"lint:packages", | ||
"lint:spelling", | ||
]); | ||
export async function getBase(): Promise<OptionsBase> { | ||
const scripts = Object.keys((await readPackageData()).scripts ?? {}); | ||
|
||
if ( | ||
scripts.reduce( | ||
(acc, curr) => (everythingScripts.has(curr) ? acc + 1 : acc), | ||
0, | ||
) >= 3 | ||
) { | ||
return "everything"; | ||
} | ||
|
||
if ( | ||
scripts.reduce( | ||
(acc, curr) => (commonScripts.has(curr) ? acc + 1 : acc), | ||
0, | ||
) >= 2 | ||
) { | ||
return "common"; | ||
} | ||
|
||
return "minimum"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters