Skip to content

Commit

Permalink
chore: use Inputs from create (#1759)
Browse files Browse the repository at this point in the history
## 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.

💖
  • Loading branch information
JoshuaKGoldberg authored Dec 11, 2024
1 parent c5d60d7 commit 4849839
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 40 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"get-github-auth-token": "^0.1.0",
"git-remote-origin-url": "^4.0.0",
"git-url-parse": "^16.0.0",
"input-from-file": "0.1.0-alpha.0",
"input-from-file-json": "0.1.0-alpha.1",
"js-yaml": "^4.1.0",
"lazy-value": "^3.0.0",
"npm-user": "^6.1.1",
Expand Down
29 changes: 29 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src/next/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { BaseOptionsFor, createBase } from "create";
import { execaCommand } from "execa";
import gitRemoteOriginUrl from "git-remote-origin-url";
import gitUrlParse from "git-url-parse";
import { inputFromFile } from "input-from-file";
import { inputFromFileJSON } from "input-from-file-json";
import lazyValue from "lazy-value";
import npmUser from "npm-user";
import { z } from "zod";
Expand All @@ -14,8 +16,7 @@ import { readGuide } from "../shared/options/createOptionDefaults/readGuide.js";
import { readPackageData } from "../shared/packages.js";
import { tryCatchLazyValueAsync } from "../shared/tryCatchLazyValueAsync.js";
import { AllContributorsData } from "../shared/types.js";
import { inputJSONFile } from "./inputs/inputJSONFile.js";
import { inputTextFile } from "./inputs/inputTextFile.js";
import { swallowError } from "./utils/swallowError.js";

export const base = createBase({
options: {
Expand Down Expand Up @@ -83,23 +84,24 @@ export const base = createBase({
},
produce({ options, take }) {
const allContributors = lazyValue(async () => {
const contributions = (await take(inputJSONFile, {
const contributions = (await take(inputFromFileJSON, {
filePath: ".all-contributorsrc",
})) as AllContributorsData | undefined;
})) as AllContributorsData;

return contributions?.contributors;
return contributions.contributors;
});

const documentation = lazyValue(
async () =>
await take(inputTextFile, {
const documentation = lazyValue(async () =>
swallowError(
await take(inputFromFile, {
filePath: ".github/DEVELOPMENT.md",
}),
),
);

const nvmrc = lazyValue(
async () =>
await take(inputTextFile, {
await take(inputFromFile, {
filePath: ".nvmrc",
}),
);
Expand Down Expand Up @@ -134,7 +136,7 @@ export const base = createBase({
return {
minimum:
(engines?.node && /[\d+.]+/.exec(engines.node))?.[0] ?? "18.3.0",
pinned: (await nvmrc()) ?? "20.18.0",
pinned: swallowError(await nvmrc()) ?? "20.18.0",
};
});

Expand Down
15 changes: 0 additions & 15 deletions src/next/inputs/inputJSONFile.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/next/inputs/inputTextFile.ts

This file was deleted.

4 changes: 4 additions & 0 deletions src/next/utils/swallowError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// TODO: What to do about errors? I think this is correct, but ...?
export function swallowError<T>(value: Error | T) {
return value instanceof Error ? undefined : value;
}
2 changes: 2 additions & 0 deletions src/steps/uninstallPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function uninstallPackages(offline: boolean | undefined) {
"get-github-auth-token",
"git-remote-origin-url",
"git-url-parse",
"input-from-file",
"input-from-file-json",
"js-yaml",
"lazy-value",
"npm-user",
Expand Down
2 changes: 2 additions & 0 deletions src/steps/writing/creation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ describe("createStructure", () => {
"get-github-auth-token",
"git-remote-origin-url",
"git-url-parse",
"input-from-file",
"input-from-file-json",
"js-yaml",
"lazy-value",
"npm-user",
Expand Down

0 comments on commit 4849839

Please sign in to comment.