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

chore: use Inputs from create #1759

Merged
merged 1 commit into from
Dec 11, 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
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
Loading