-
Notifications
You must be signed in to change notification settings - Fork 813
fix(docs): add overwriteExisting option for flexible README overwrite behaviour #6249
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
fix(docs): add overwriteExisting option for flexible README overwrite behaviour #6249
Conversation
… behaviour On the `docs-readme` output target, a new `overwriteExisting` option allows developers to control how existing README files are handled when writing to a custom path. This adds flexibility to either: - Always overwrite the full README (`true`), - Only write the full README if no file exists (`'if-missing'`), or - Preserve existing custom content (**default** `false`). Now, `docs-readme` treats the component `readme.md` files as the canonical source for manually-entered custom content when overwriting READMEs. This ensures that custom content is preserved unless explicitly overwritten. For example, when using the `'if-missing'` flag, a project that writes component readmes into a documentation library folder can maintain consistent, idempotent output across local builds and CI environments. Custom edits to the destination files will be maintained, while files without customisation will be fully exported. Fixes stenciljs#6248
Adds tests covering all `overwriteExisting` modes on the `docs-readme` output target: - Always overwrite (`true`) - Overwrite if missing (`'if-missing'`) with and without a destination file - Never overwrite (`false`) - Default behaviour (`undefined`), which treats missing values as `false` Tests confirm that manual content is preserved when appropriate, new files are correctly generated when missing, and behaviour matches the original fix for stenciljs#5400. Also validates idempotent output across multiple overwriting scenarios. Related to the fix for stenciljs#6248.
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.
LGTM 👍
Great change set!
Thanks, @christian-bromann! I just noticed a bunch of tests failing, any advice on looking into them? |
You can ignore the failing Component Starter Tests but definitely take a look at the failing docs test which seem to cause changes when running them |
Looking a the docs tests, it looks like it is an issue with Git being dirty after the file that is expected to be overwritten is overwritten. One of the tests replaces one of the readmes with the one that exists within the component, I'm purposefully making sure the file gets overwritten, but this breaks Git. Any thoughts? |
One idea that comes to mind. Perhaps I can commit the intended result, and add a step before the |
@smorrisods I think that makes sense |
c352e61
to
686e9c1
Compare
Added `copy-readme.js` to copy the supplemental README over the known README result to ensure the file is in a consistent state before the test begins. This approach verifies whether the `docs-readme` output target correctly overwrites the file as expected during the test process.
686e9c1
to
d889c08
Compare
@christian-bromann, I've made my changes and introduced a script that takes an informational The intended output is also committed, providing a baseline for what to expect and leveraging the behaviour of the test suite. If the file is successfully overwritten, the checked-in result is restored, and there is no dirty state in Git. However, if the overwrite fails, Git will detect a dirty state, indicating that the operation to overwrite failed, and the test will fail as expected. |
@smorrisods it seems like there is a remaining prettier issue with |
@christian-bromann, good catch! I've prettierified the file and it looks better now. Good catch <3 |
This PR updates Stencil.js and Docusuaus: ### 1. Stencil.js Upgrade - Upgrades Stencil.js to [v4.33.1](https://github.com/stenciljs/core/releases/tag/v4.33.1). - Adds `overwriteExisting: true` to ensure component readme files are exported to Docusaurus, keeping documentation in sync. - **Note**: This fixes our component readme documentation generation, restoring full copies of our component readmes to Docusuaus for publishing. (Reported via stenciljs/core#6248, fixed via stenciljs/core#6249 and released in Stencil.js [v4.31.0](https://github.com/stenciljs/core/releases/tag/v4.31.0)) - Updates all component readmes to reflect changes introduced by the new Stencil.js version. - Updates `components.d.ts` to include `@default` values for improved type safety and documentation clarity. ### 2. Docusaurus Upgrade - Upgrades Docusaurus to v3.5.0. - Fixes JSDoc comment formatting in `ontario-hint-text` to resolve build/runtime issues with Docusaurus v3. - Cleans up the `prism-react-renderer` import in `docusaurus.config.js` for compatibility and maintainability. _With this PR we can now publish production releases again and not clobber all our documentation!_
The
docs-readme
output target has long supported writing README files to custom locations using thedir
property, helping teams structure their documentation workflows to suit project needs.As part of evolving those workflows, I've introduced the
overwriteExisting
property to give developers precise control over how README files are handled. This addition supports common scenarios like always overwriting, only writing when files are missing, or preserving existing content:true
),'if-missing'
), orfalse
).These options aim to better support workflows where documentation is closely tied to source code, while also offering flexibility for varied project structures.
What is the current behaviour?
By default, the docs-readme output target preserves any manually-entered content in destination README files, but it does not offer flexible controls for different overwrite behaviours. This made it difficult to manage workflows where documentation is expected to be tightly coupled with source code, while also needing different customisation strategies for various parts of a project.
Link to relevant issues/PRs: #5648 #6248
What is the new behaviour?
This PR introduces documentation for the new
overwriteExisting
propertyon the
docs-readme
output target.The documentation includes:
overwriteExisting
configuration option.true
,false
, and'if-missing'
).stencil.config.ts
file.as the canonical source of truth for custom content.
Documentation
A documentation update has been made in stenciljs/site#1521.
Does this introduce a breaking change?
Testing
overwriteExisting
property ondocs-readme
as described in bug: docs-readme output target no longer copies full content to dir path #6248.Other information
See #6248 for a detailed explanation of the use case this PR is covering.