-
Notifications
You must be signed in to change notification settings - Fork 272
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
Blueprints: Directory Resources #1793
Conversation
…e of that type: `git-directory`
I think the proposal is the right call to make as a step for evolving the plugin file source. I am not sure I am sold on the data-URL like syntax although I don't have a better proposal at this point. Regarding backwards compatibility: I think at this point there are already a lot of blueprints in circulation that use |
Absolutely |
Technically this PR is ready for merging – the build errors are related to #1766. Practically, I'll wait a bit more for feedback on the API shape. |
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.
Great PR description!
680cd19
to
2e376d2
Compare
84c713d
to
a77ce5a
Compare
Related to #1787, Follows up on #1793 Implements GitDirectoryResource to enable loading files directly from git repositories as follows: ```ts { "landingPage": "/guides/for-plugin-developers.md", "steps": [ { "step": "writeFiles", "writeToPath": "/wordpress/guides", "filesTree": { "resource": "git:directory", "url": "https://github.com/WordPress/wordpress-playground.git", "ref": "trunk", "path": "packages/docs/site/docs/main/guides" } } ] } ``` ## Implementation details Uses git client functions merged in #1764 to sparse checkout the requested files. It also leans on the PHP CORS proxy which is now started as a part of the `npm run dev` command. The CORS proxy URL is configurable per `compileBlueprint()` call so that each Playground runtime may choose to either use it or not. For example, it wouldn't be very useful in the CLI version of Playground. ## Testing plan Go to `http://localhost:5400/website-server/#{%20%22landingPage%22:%20%22/guides/for-plugin-developers.md%22,%20%22steps%22:%20[%20{%20%22step%22:%20%22writeFiles%22,%20%22writeToPath%22:%20%22/wordpress/guides%22,%20%22filesTree%22:%20{%20%22resource%22:%20%22git:directory%22,%20%22url%22:%20%22https://github.com/WordPress/wordpress-playground.git%22,%20%22ref%22:%20%22trunk%22,%20%22path%22:%20%22packages/docs/site/docs/main/guides%22%20}%20}%20]%20}` and confirm Playground loads a markdown file.
Related to #1787, Follows up on #1793 Implements GitDirectoryResource to enable loading files directly from git repositories as follows: ```ts { "landingPage": "/guides/for-plugin-developers.md", "steps": [ { "step": "writeFiles", "writeToPath": "/wordpress/guides", "filesTree": { "resource": "git:directory", "url": "https://github.com/WordPress/wordpress-playground.git", "ref": "trunk", "path": "packages/docs/site/docs/main/guides" } } ] } ``` ## Implementation details Uses git client functions merged in #1764 to sparse checkout the requested files. It also leans on the PHP CORS proxy which is now started as a part of the `npm run dev` command. The CORS proxy URL is configurable per `compileBlueprint()` call so that each Playground runtime may choose to either use it or not. For example, it wouldn't be very useful in the CLI version of Playground. ## Testing plan Go to ``` http://localhost:5400/website-server/#{%20%22landingPage%22:%20%22/guides/for-plugin-developers.md%22,%20%22steps%22:%20[%20{%20%22step%22:%20%22writeFiles%22,%20%22writeToPath%22:%20%22/wordpress/guides%22,%20%22filesTree%22:%20{%20%22resource%22:%20%22git:directory%22,%20%22url%22:%20%22https://github.com/WordPress/wordpress-playground.git%22,%20%22ref%22:%20%22trunk%22,%20%22path%22:%20%22packages/docs/site/docs/main/guides%22%20}%20}%20]%20} ``` And confirm the Playground loads a markdown file.
#1793 introduced a directory resource type and changed the name of a few required parameters. Among others, the `themeZipFile` parameter in the `installTheme` changed to `themeData`. Unfortunately, the `compile()` function had a type and did not backfill the new required parameter using the older, well known `themeZipFile` parameter which caused Blueprint execution errors.
Follows up on d0cec49 to fix the check in an `if` statement. More context: #1793 introduced a directory resource type and changed the name of a few required parameters. Among others, the `themeZipFile` parameter in the `installTheme` changed to `themeData`. Unfortunately, the `compile()` function had a type and did not backfill the new required parameter using the older, well known `themeZipFile` parameter which caused Blueprint execution errors.
Excellent improvement. |
Description
Adds a Directory resource type to enable loading file trees from git repositories, local hard drive, deeply nested zip archives etc:
Motivation
This PR opens the door to:
--resource-override=GUTENBERG:./gutenberg.zip
in CLI to test a Blueprint with a my local version of Gutenberg. The same logic would be used by the Blueprints builder to use files selected via<input type="file">
controls.Schema
Every step can declare which kinds of resources it accepts (file-based resources vs directory-based resources). Using a single
pluginData
property in theinstallPlugin
step means less choices for the developer. It also makes local resource overrides easy, e.g. we could tell Playground CLI to load a local Gutenberg directory instead of a remote Gutenberg zip. This wouldn't be as easy had we used separate options for passing ZIP-based and directory-based resources.On one hand,
pluginData
is less informative thanpluginZipFile
. On the other, the name accommodates for non-zip resources such as directories.Developer notes about specific API changes introduced in this PR
This PR changes introduces a new
literal:directory
resource that can be used in Blueprints as follows:Or via the JS API:
It also introduces a new
writeFiles
step:Specific changes:
Resource<Directory>
resource type that provides aname: string
andfiles: FileTree
.pluginZipFile
topluginData
in theinstallPlugin
stepthemeZipFile
tothemeData
in theinstallPlugin
stepwriteFiles
step for writing entire directory treesliteral:directory
resource type where an entire file tree can be specified inlinegit:directory
resource type that throws an error for now, but will load arbitrary directories from git repositories once Native git support: lsRefs(), sparseCheckout(), GitPathControl #1764 landsRemaining work
installPlugin
andinstallTheme
step for compatibility with it's former signature. Ensure the existing packages consuming those functions from the@wp-playground/blueprints
package will continue to work.DirectoryStream
resource type producing anAsyncDirectoryIterator
with streamableFile
orBlob
objects as its leafs. It would work nicely with remote APIs or the ZIP streaming plumbing in@php-wasm/stream-compression
. Any existing code expecting aDirectoryResource
should be relatively easily adaptable to use these async iterators instead.Follow-up work
git:directory
resource, expand the developer notes from this PR and other related PRs and write a post on https://make.wp.org/playgroundTangent – Streaming and a shorthand URL notation
Without streaming, the entire directory must be loaded into memory. Our git sparse checkout implementation buffers everything anyway, but we will want to stream-read directory resources in the future. For example:
That's extremely verbose, I'd love to explore a shorthand notation. One idea would be to make it a valid URI shaped after the data URL syntax:
It wouldn't allow easy composition of the resources, e.g. a directory inside a zip sourced from a GitHub repo. Maybe that's for the best, though, since such a string would be extremely dense and difficult for humans to read. The object-based syntax might still be the most convenient way of to declare those.