Skip to content

WP-NOW: add crypto dependency globally available in node#153

Closed
sejas wants to merge 1 commit into
trunkfrom
add/wp-now-inject-crypto-globally
Closed

WP-NOW: add crypto dependency globally available in node#153
sejas wants to merge 1 commit into
trunkfrom
add/wp-now-inject-crypto-globally

Conversation

@sejas
Copy link
Copy Markdown
Collaborator

@sejas sejas commented Feb 5, 2024

What?

@adamziel fixed the polyfills to run the flag --blueprint without any issues, but installing a plugin throws an error:

ReferenceError: crypto is not defined

Starting the server......
directory: /Users/macbookpro/proyectos/a8c/playground-tools
mode: playground
php: 8.0
wp: latest
WordPress latest folder already exists. Skipping download.
SQLite folder already exists. Skipping download.
blueprint steps: 2
Blueprint step completed: login
Proceeding without the Notification plugin. Could not install it in wp-admin. The original error was: ReferenceError: crypto is not defined
ReferenceError: crypto is not defined
    at yi (file:///Users/macbookpro/proyectos/a8c/playground-tools/node_modules/@wp-playground/blueprints/index.js:1323:104)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Module.ia [as installPlugin] (file:///Users/macbookpro/proyectos/a8c/playground-tools/node_modules/@wp-playground/blueprints/index.js:1361:36)
    at async a (file:///Users/macbookpro/proyectos/a8c/playground-tools/node_modules/@wp-playground/blueprints/index.js:9339:30)
    at async Object.run (file:///Users/macbookpro/proyectos/a8c/playground-tools/node_modules/@wp-playground/blueprints/index.js:9273:21)
    at async sp (file:///Users/macbookpro/proyectos/a8c/playground-tools/node_modules/@wp-playground/blueprints/index.js:9374:3)
    at async startWPNow (file:///Users/macbookpro/proyectos/a8c/playground-tools/dist/packages/wp-now/main.js:597:5)
    at async startServer (file:///Users/macbookpro/proyectos/a8c/playground-tools/dist/packages/wp-now/main.js:866:42)
    at async Object.handler (file:///Users/macbookpro/proyectos/a8c/playground-tools/dist/packages/wp-now/main.js:1058:25)
Blueprint step completed: installPlugin
Server running at http://localhost:8881

Why?

The blueprints use crypto.randomUUID, but in node we need to import crypto.

How?

In this PR I inject the default node library to be globally available.
Other alternatives could be adding the import directly on @wp-playground/blueprints, or replace the randomUUID for another function.

Testing Instructions

  • nvm use && npm install
  • npx nx build wp-now
  • Create a file b.json with a blueprint that installs a plugin.
  • node dist/packages/wp-now/cli.js start --blueprint=b.json
  • Observe wp-now has started correctly and displays the the notification plugin already installed.

b.json

{
	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
	"landingPage": "/wp-admin/plugins.php",
	"preferredVersions": {
		"php": "8.0",
		"wp": "latest"
	},
	"steps": [
		{
			"step": "login",
			"username": "admin",
			"password": "password"
		},
		{
			"step": "installPlugin",
			"pluginZipFile": {
				"resource": "wordpress.org/plugins",
				"slug": "notification"
			},
			"options": {
				"activate": true
			}
		}
	]
}

@adamziel
Copy link
Copy Markdown
Collaborator

adamziel commented Feb 5, 2024

@sejas this PR would nicely fit Playground core, as every Node.js Playground consumer will experience this problem. Would you mind starting one to update the node-polyfills package and make crypto one of the polyfills?

@sejas sejas closed this Feb 5, 2024
@sejas sejas deleted the add/wp-now-inject-crypto-globally branch February 5, 2024 12:54
@sejas
Copy link
Copy Markdown
Collaborator Author

sejas commented Feb 5, 2024

@adamziel , moved the PR here: WordPress/wordpress-playground#1000

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wp-now: ReferenceError: DOMParser is not defined while installing the plugin

2 participants