-
Notifications
You must be signed in to change notification settings - Fork 0
fix(npm): make ext-content-mdx an optional peer, not a runtime dependency #3783
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c915dcb
fix(npm): make ext-content-mdx an optional peer, not a runtime depend…
kwakayama fd1dfe9
fix(cli): declare ext-content-mdx from the assembled project, not the…
kwakayama 069d4f6
fix(cli): warn when generate writes .mdx into a project without the e…
kwakayama cfc2807
docs(api-reference): regenerate scaffold.md after the MDX declaration…
kwakayama 0bea8bd
fix(cli): use the project's package manager in the MDX install warning
kwakayama 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
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,109 @@ | ||
| import { assertEquals, assertRejects, assertStringIncludes } from "#veryfront/testing/assert.ts"; | ||
| import { describe, it } from "#veryfront/testing/bdd.ts"; | ||
| import { resolve, tryResolve, unregister } from "../../src/extensions/contracts.ts"; | ||
| import type { ContentProcessor } from "veryfront/extensions/content"; | ||
| import { ensureBuiltinContentProcessor } from "./ensure-content-processor.ts"; | ||
|
|
||
| /** The error Node raises for an uninstalled optional peer dependency. */ | ||
| function missingPackageError(): Error { | ||
| return Object.assign( | ||
| new Error( | ||
| "Cannot find package '@veryfront/ext-content-mdx' imported from " + | ||
| "/app/node_modules/veryfront/esm/cli/shared/ensure-content-processor.js", | ||
| ), | ||
| { code: "ERR_MODULE_NOT_FOUND" }, | ||
| ); | ||
| } | ||
|
|
||
| class StubContentProcessor { | ||
| compileMdx() { | ||
| return Promise.reject(new Error("unused")); | ||
| } | ||
| compileMarkdown() { | ||
| return Promise.reject(new Error("unused")); | ||
| } | ||
| getRemarkPlugins() { | ||
| return []; | ||
| } | ||
| getRehypePlugins() { | ||
| return []; | ||
| } | ||
| } | ||
|
|
||
| describe("cli/shared/ensure-content-processor", () => { | ||
| it("registers the MDX processor when the extension is installed", async () => { | ||
| try { | ||
| await ensureBuiltinContentProcessor(() => | ||
| Promise.resolve({ MdxContentProcessor: StubContentProcessor }) | ||
| ); | ||
|
|
||
| assertEquals( | ||
| tryResolve<ContentProcessor>("ContentProcessor") instanceof StubContentProcessor, | ||
| true, | ||
| ); | ||
| } finally { | ||
| unregister("ContentProcessor"); | ||
| } | ||
| }); | ||
|
|
||
| // @veryfront/ext-content-mdx is an optional peer, so a plain | ||
| // `npm install veryfront` does not install it. Server startup calls this | ||
| // unconditionally (cli/shared/server-startup.ts), so throwing here would | ||
| // break `npx veryfront dev` for every project — including the ones with no | ||
| // .mdx file at all. | ||
| it("does not fail startup when the MDX extension is not installed", async () => { | ||
| await ensureBuiltinContentProcessor(() => Promise.reject(missingPackageError())); | ||
|
|
||
| assertEquals(tryResolve<ContentProcessor>("ContentProcessor"), undefined); | ||
| }); | ||
|
|
||
| // With no processor registered, the compile path is what reports the | ||
| // problem, and it names the package to install. | ||
| it("leaves the actionable install message to the content compile path", async () => { | ||
| await ensureBuiltinContentProcessor(() => Promise.reject(missingPackageError())); | ||
|
|
||
| let message = ""; | ||
| try { | ||
| resolve<ContentProcessor>("ContentProcessor"); | ||
| } catch (error) { | ||
| message = error instanceof Error ? error.message : String(error); | ||
| } | ||
|
|
||
| assertStringIncludes(message, "@veryfront/ext-content-mdx"); | ||
| }); | ||
|
|
||
| // What importFirstPartyExtensionModule actually throws: the raw resolution | ||
| // error is wrapped, its message gains an install hint, and the original pair | ||
| // (package + workspace source) lands on `cause` as an AggregateError. The | ||
| // classifier's message patterns are anchored, so the wrapper itself never | ||
| // matches — only the cause chain does. | ||
| it("tolerates the wrapped install-hint error the real loader throws", async () => { | ||
| const packageError = new Error( | ||
| "Cannot find package '@veryfront/ext-content-mdx' imported from " + | ||
| "/app/node_modules/veryfront/esm/src/extensions/first-party-import.js", | ||
| ); | ||
| const sourceError = new Error( | ||
| "Cannot find module " + | ||
| "'/app/node_modules/veryfront/esm/extensions/ext-content-mdx/src/index.ts'", | ||
| ); | ||
| const wrapped = new Error( | ||
| `${packageError.message} First-party extension "ext-content-mdx" is not ` + | ||
| "installed; install @veryfront/ext-content-mdx alongside veryfront to enable it.", | ||
| { cause: new AggregateError([packageError, sourceError], packageError.message) }, | ||
| ); | ||
|
|
||
| await ensureBuiltinContentProcessor(() => Promise.reject(wrapped)); | ||
|
|
||
| assertEquals(tryResolve<ContentProcessor>("ContentProcessor"), undefined); | ||
| }); | ||
|
|
||
| // A broken transitive dependency inside an *installed* extension must not be | ||
| // mistaken for "not installed" and silently swallowed. | ||
| it("rethrows real load failures from an installed extension", async () => { | ||
| await assertRejects( | ||
| () => ensureBuiltinContentProcessor(() => Promise.reject(new Error("boom"))), | ||
| Error, | ||
| "boom", | ||
| ); | ||
| }); | ||
| }); |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an npm project configured for the pages router,
veryfront generate page ...andveryfront generate layout ...still create.mdxfiles incli/scaffold/engine.ts, but the generate command neither adds@veryfront/ext-content-mdxtopackage.jsonnor tells the user to install it. After this missing-package path returns successfully,veryfront devreports the generated route as unusable even though the command reported that it was created successfully. Update the MDX-generating flow to install or declare the newly optional peer.Useful? React with 👍 / 👎.