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

Blueprints: add support for NodeJS #576

Closed
wants to merge 6 commits into from

Conversation

sejas
Copy link
Collaborator

@sejas sejas commented Jun 21, 2023

What?

Blueprint steps use some classes available only on Browser and not NodeJS.
This PR is an approach to make it possible to import the blueprints and make most of them work by declaring those classes when they are undefined.

Why?

How?

I declare File and CustomEvent when they are undefined.
The File implementation is empty, so we will need a second PR to make the steps to install themes and plugins work.

Testing Instructions

  • Build this branch nvm use && npm run build
  • Checkout the wp-now PR: wp-now: execute blueprint steps given a file path playground-tools#82
  • Access that folder in your terminal cd playground-tools
  • Run: nvm use && npm run build
  • Follow the testing instructions in the mentioned PR and run a simple blueprint in wp-now: `
  • Observe the error about File or CustomEvent is undefined.
  • Remove the folder node_modules/@wp-playground
  • Create a symbolic link from wordpress-playground dist to playground-tools/node_modules/@wp-playground: ln -s path/to/wordpress-playground/dist/packages/playground node_modules/@wp-playground
  • Follow the testing instructions in the mentioned PR and run a simple blueprint in wp-now: node dist/packages/wp-now/main.js start --blueprint=foo.json --port=80
  • Observe wp-now has started correctly and the blueprint was executed too.

@sejas
Copy link
Collaborator Author

sejas commented Jun 21, 2023

@adamziel , could you take a look at this PR?
I've found some errors running the blueprints in wp-now.

@eliot-akira
Copy link
Collaborator

For reference, the CustomEvent class became available (no longer experimental) in Node.js v19.0.0.

https://nodejs.org/api/globals.html#customevent

The File class was added in v20.

https://nodejs.org/api/buffer.html#class-file

@eliot-akira
Copy link
Collaborator

For the File polyfill for Node versions below v20, this one looks good:

Web API compatible File for nodejs - https://github.com/web-std/io/tree/main/packages/file

@adamziel
Copy link
Collaborator

adamziel commented Jun 22, 2023

@sejas would bumping the minimal required Node.js version to 20 solve it without the polyfills? Are there any blockers for that?

The File implementation is empty, so we will need a second PR to make the steps to install themes and plugins work.

If node 20 is a no-go for any reason then let's bring the File polyfill into this PR so we can see if anything else breaks

@sejas
Copy link
Collaborator Author

sejas commented Jun 22, 2023

@eliot-akira , @adamziel Thank you for your suggestions.

Nice!, Using Node version 20 fixes the error with File and CustomEvent. Yay! I'll close this PR.
WordPress/playground-tools@f0e91f1

Some Blueprint steps like installPlugin are still not working due to a different error. DOMParser in this case. So I'll probably create a PR on this repo to support these steps on NodeJS.

Thank you!

Proceeding without the Coblocks theme. Could not install it in wp-admin. The original error was: ReferenceError: DOMParser is not defined
ReferenceError: DOMParser is not defined
    at S (playground-tools/node_modules/@wp-playground/blueprints/index.js:35:3)

@sejas sejas closed this Jun 22, 2023
@sejas sejas deleted the update/node-support-blueprints branch June 22, 2023 16:49
@adamziel
Copy link
Collaborator

adamziel commented Jun 22, 2023

@sejas DOMParser is no longer used in trunk and I think the appropriate npm packages were released – try updating Playground dependencies. Also, would you please open a PR to bump Node to 20 in the engines section of package.json for @wp-playground/blueprints and @wp-playground/client?

@sejas
Copy link
Collaborator Author

sejas commented Jun 23, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants