Skip to content

Commit 4849839

Browse files
chore: use Inputs from create (#1759)
## PR Checklist - [x] Addresses an existing open issue: fixes #1758 - [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 Swaps the internal files over to taking from the packages. The provided Inputs return `| Error`, but I think the error cases weren't being handled before. So 🤷 they're just swallowed for now. 💖
1 parent c5d60d7 commit 4849839

File tree

8 files changed

+51
-40
lines changed

8 files changed

+51
-40
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
"get-github-auth-token": "^0.1.0",
5151
"git-remote-origin-url": "^4.0.0",
5252
"git-url-parse": "^16.0.0",
53+
"input-from-file": "0.1.0-alpha.0",
54+
"input-from-file-json": "0.1.0-alpha.1",
5355
"js-yaml": "^4.1.0",
5456
"lazy-value": "^3.0.0",
5557
"npm-user": "^6.1.1",

pnpm-lock.yaml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/next/base.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { BaseOptionsFor, createBase } from "create";
22
import { execaCommand } from "execa";
33
import gitRemoteOriginUrl from "git-remote-origin-url";
44
import gitUrlParse from "git-url-parse";
5+
import { inputFromFile } from "input-from-file";
6+
import { inputFromFileJSON } from "input-from-file-json";
57
import lazyValue from "lazy-value";
68
import npmUser from "npm-user";
79
import { z } from "zod";
@@ -14,8 +16,7 @@ import { readGuide } from "../shared/options/createOptionDefaults/readGuide.js";
1416
import { readPackageData } from "../shared/packages.js";
1517
import { tryCatchLazyValueAsync } from "../shared/tryCatchLazyValueAsync.js";
1618
import { AllContributorsData } from "../shared/types.js";
17-
import { inputJSONFile } from "./inputs/inputJSONFile.js";
18-
import { inputTextFile } from "./inputs/inputTextFile.js";
19+
import { swallowError } from "./utils/swallowError.js";
1920

2021
export const base = createBase({
2122
options: {
@@ -83,23 +84,24 @@ export const base = createBase({
8384
},
8485
produce({ options, take }) {
8586
const allContributors = lazyValue(async () => {
86-
const contributions = (await take(inputJSONFile, {
87+
const contributions = (await take(inputFromFileJSON, {
8788
filePath: ".all-contributorsrc",
88-
})) as AllContributorsData | undefined;
89+
})) as AllContributorsData;
8990

90-
return contributions?.contributors;
91+
return contributions.contributors;
9192
});
9293

93-
const documentation = lazyValue(
94-
async () =>
95-
await take(inputTextFile, {
94+
const documentation = lazyValue(async () =>
95+
swallowError(
96+
await take(inputFromFile, {
9697
filePath: ".github/DEVELOPMENT.md",
9798
}),
99+
),
98100
);
99101

100102
const nvmrc = lazyValue(
101103
async () =>
102-
await take(inputTextFile, {
104+
await take(inputFromFile, {
103105
filePath: ".nvmrc",
104106
}),
105107
);
@@ -134,7 +136,7 @@ export const base = createBase({
134136
return {
135137
minimum:
136138
(engines?.node && /[\d+.]+/.exec(engines.node))?.[0] ?? "18.3.0",
137-
pinned: (await nvmrc()) ?? "20.18.0",
139+
pinned: swallowError(await nvmrc()) ?? "20.18.0",
138140
};
139141
});
140142

src/next/inputs/inputJSONFile.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/next/inputs/inputTextFile.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/next/utils/swallowError.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// TODO: What to do about errors? I think this is correct, but ...?
2+
export function swallowError<T>(value: Error | T) {
3+
return value instanceof Error ? undefined : value;
4+
}

src/steps/uninstallPackages.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export async function uninstallPackages(offline: boolean | undefined) {
1616
"get-github-auth-token",
1717
"git-remote-origin-url",
1818
"git-url-parse",
19+
"input-from-file",
20+
"input-from-file-json",
1921
"js-yaml",
2022
"lazy-value",
2123
"npm-user",

src/steps/writing/creation/index.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ describe("createStructure", () => {
209209
"get-github-auth-token",
210210
"git-remote-origin-url",
211211
"git-url-parse",
212+
"input-from-file",
213+
"input-from-file-json",
212214
"js-yaml",
213215
"lazy-value",
214216
"npm-user",

0 commit comments

Comments
 (0)