-
-
Notifications
You must be signed in to change notification settings - Fork 129
Verify runtime version in fedify init
#981
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
Merged
2chanhaeng
merged 13 commits into
fedify-dev:main
from
userjmmm:issue-964-verify-runtime-version
Aug 14, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9b6f43f
Verify runtime version in `fedify init`
userjmmm 497f798
Add tests for runtime version verification
userjmmm 718ae8d
Add changelog entry for runtime version check
userjmmm c48415d
Add PR Reference to init changelog
userjmmm 7c5e02f
Remove unnecessary export and reuse RuntimeCheck type
userjmmm 8440cac
Extract and reuse package-manager choices
userjmmm a98e404
Use a loop for the package-manager prompt retry
userjmmm 9063ab2
Simplify the runtime version check chain
userjmmm 4274475
Remove redundant package-manager checks
userjmmm 759954e
Show detected version in disabled PM message
userjmmm 10567c1
Catch dax's missing command in isNotFoundError
userjmmm 01775ec
Make `outputPattern` match pre-release versions
userjmmm 766524b
Add links to verify-runtime-version.md
userjmmm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,11 @@ | ||
| --- | ||
| links: | ||
| '#964': https://github.com/fedify-dev/fedify/issues/964 | ||
| '#981': https://github.com/fedify-dev/fedify/pull/981 | ||
| --- | ||
| - Added runtime version verification to `fedify init`. It checks that the | ||
| selected Deno, Bun, or Node.js meets Fedify's minimum version, or a higher | ||
| version required by a framework (such as Astro's Node.js 22.12), before | ||
| generating a project. A missing, malformed, or unsupported runtime now | ||
| produces a clear error in non-interactive mode and disables the affected | ||
| package managers in interactive mode. [[#964], [#981] by Lee Jeongmin] |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,78 +1,107 @@ | ||
| import { pipe, when } from "@fxts/core"; | ||
| import { select } from "@inquirer/prompts"; | ||
| import { message } from "@optique/core/message"; | ||
| import { message, optionName, text } from "@optique/core/message"; | ||
| import { print } from "@optique/run"; | ||
| import process from "node:process"; | ||
| import { PACKAGE_MANAGER } from "../const.ts"; | ||
| import { | ||
| checkAllRuntimes, | ||
| getInstallUrl, | ||
| isPackageManagerAvailable, | ||
| kvStores, | ||
| messageQueues, | ||
| packageManagers, | ||
| isTest, | ||
| runtimes, | ||
| } from "../lib.ts"; | ||
| import type { PackageManager, WebFramework } from "../types.ts"; | ||
| import type { | ||
| PackageManager, | ||
| Runtime, | ||
| RuntimeCheck, | ||
| WebFramework, | ||
| } from "../types.ts"; | ||
| import { printErrorMessage } from "../utils.ts"; | ||
| import webFrameworks from "../webframeworks/mod.ts"; | ||
| import { pmToRt } from "../webframeworks/utils.ts"; | ||
|
|
||
| /** | ||
| * Fills in the package manager by prompting the user if not provided. | ||
| * Ensures the selected package manager is compatible with the chosen web framework. | ||
| * If the selected package manager is not installed, informs the user and prompts again. | ||
| * Ensures the selected package manager is compatible with the chosen web | ||
| * framework and installed on the system. When an explicitly requested package | ||
| * manager is unavailable, informs the user and prompts again. | ||
| * | ||
| * @param options - Initialization options possibly containing a packageManager and webFramework | ||
| * @returns A promise resolving to options with a guaranteed packageManager | ||
| */ | ||
| const fillPackageManager: // | ||
| <T extends { packageManager?: PackageManager; webFramework: WebFramework }> // | ||
| < | ||
| T extends { | ||
| packageManager?: PackageManager; | ||
| webFramework: WebFramework; | ||
| testMode: boolean; | ||
| }, | ||
| > // | ||
| (options: T) => // | ||
| Promise<Omit<T, "packageManager"> & { packageManager: PackageManager }> = // | ||
| async ({ packageManager, ...options }) => { | ||
| const pm = packageManager ?? await askPackageManager(options.webFramework); | ||
| if (await isPackageManagerAvailable(pm)) { | ||
| return ({ ...options, packageManager: pm }); | ||
| const choices = await calculateChoices(options.webFramework); | ||
| if (packageManager != null) { | ||
| const choice = choices.find(({ value }) => value === packageManager)!; | ||
| if (choice.disabled == null) { | ||
| return { ...options, packageManager }; | ||
| } | ||
| print(message`${optionName(choice.name)} ${text(choice.disabled)}`); | ||
| if (isTest(options)) process.exit(1); | ||
| } | ||
| noticeInstallUrl(pm); | ||
| return await fillPackageManager(options) as // | ||
| typeof options & { packageManager: PackageManager }; | ||
| return { ...options, packageManager: await askPackageManager(choices) }; | ||
|
2chanhaeng marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| export default fillPackageManager; | ||
|
|
||
| const askPackageManager = (wf: WebFramework) => | ||
| const calculateChoices = async (wf: WebFramework) => { | ||
| const runtimeChecks = await checkAllRuntimes( | ||
| webFrameworks[wf].minRuntimeVersions, | ||
| ); | ||
| const choices = await Promise.all( | ||
| PACKAGE_MANAGER.map(choicePackageManager(wf, runtimeChecks)), | ||
| ); | ||
| if (choices.every((choice) => choice.disabled)) { | ||
| printErrorMessage`No package manager with a supported runtime is available for ${ | ||
| webFrameworks[wf].label | ||
| }.`; | ||
| process.exit(1); | ||
| } | ||
|
userjmmm marked this conversation as resolved.
|
||
| return choices; | ||
| }; | ||
|
|
||
| const askPackageManager = ( | ||
| choices: Awaited<ReturnType<typeof calculateChoices>>, | ||
| ) => | ||
| select<PackageManager>({ | ||
| message: "Choose the package manager to use", | ||
| choices: PACKAGE_MANAGER.map(choicePackageManager(wf)), | ||
| choices, | ||
| }); | ||
|
|
||
| const choicePackageManager = (wf: WebFramework) => (value: PackageManager) => ({ | ||
| name: isWfSupportsPm(wf, value) | ||
| ? value | ||
| : `${value} (not supported with ${webFrameworks[wf].label})`, | ||
| value, | ||
| disabled: !isWfSupportsPm(wf, value), | ||
| }); | ||
| const choicePackageManager = | ||
| (wf: WebFramework, runtimeChecks: Record<Runtime, RuntimeCheck>) => | ||
| async (value: PackageManager) => { | ||
| const check = runtimeChecks[pmToRt(value)]; | ||
| const label = runtimes[pmToRt(value)].label; | ||
| const disabled = !isWfSupportsPm(wf, value) | ||
| ? `not supported with ${webFrameworks[wf].label}` | ||
| : check.status === "unsupported" | ||
| ? `requires ${label} ${check.required} or later (detected: ${check.detected})` | ||
| : check.status === "missing" | ||
| ? `requires ${label} which is not installed` | ||
| : check.status === "malformed" | ||
| ? `could not detect ${label} version` | ||
| : pmToRt(value) === "node" && !await isPackageManagerAvailable(value) | ||
| ? `is not installed; install it from ${getInstallUrl(value)}` | ||
| : ""; | ||
| return disabled === "" ? { name: value, value } : { | ||
| name: value, | ||
| value, | ||
| disabled, | ||
| }; | ||
| }; | ||
|
|
||
| const isWfSupportsPm = ( | ||
| wf: WebFramework, | ||
| pm: PackageManager, | ||
| ) => webFrameworks[wf].packageManagers.includes(pm); | ||
|
|
||
| const noticeInstallUrl = (pm: PackageManager) => { | ||
| const label = getLabel(pm); | ||
| const url = getInstallUrl(pm); | ||
| print(message` Package manager ${label} is not installed.`); | ||
| print(message` You can install it from following link: ${url}`); | ||
| print(message` or choose another package manager:`); | ||
| }; | ||
|
|
||
| const getLabel = (name: string) => | ||
| pipe( | ||
| name, | ||
| whenHasLabel(webFrameworks), | ||
| whenHasLabel(packageManagers), | ||
| whenHasLabel(messageQueues), | ||
| whenHasLabel(kvStores), | ||
| whenHasLabel(runtimes), | ||
| ); | ||
| const whenHasLabel = <T extends Record<string, { label: string }>>(desc: T) => | ||
| when((name: string) => name in desc, (name) => desc[name as keyof T].label); | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.