-
Notifications
You must be signed in to change notification settings - Fork 42
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
Download exact WordPress version when passing an alias #324
Conversation
cc @sejas |
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.
@zaguiini , thank you for creating the PR. It looks good, working as expected.
I was thinking if it would be possible to remove isDeveloperBuild
in favor of a more simple check, like directly using the provided alias.
Let me know if you want me to update the tests as well.
Thank you!
I tested it and I confirm that after building the project npx nx build wp-now
, I could run wp-now start with the following results:
node dist/packages/wp-now/cli.js start
node dist/packages/wp-now/cli.js start --wp=latest
It downloaded and used ~/.wp-now/wordpress-versions/6.5.5
node dist/packages/wp-now/cli.js start --wp=6.6-beta2
It downloaded and used ~/.wp-now/wordpress-versions/6.6-beta2
node dist/packages/wp-now/cli.js start --wp=trunk
node dist/packages/wp-now/cli.js start --wp=nightly
It downloaded and used ~/.wp-now/wordpress-versions/6.7-alpha-58716
Starting the server......
directory: /Users/macbookpro/proyectos/a8c/playground-tools
mode: playground
php: 8.0
wp: 6.7-alpha-58716 (resolved from alias: trunk)
Downloading WordPress 6.7-alpha-58716...
SQLite folder already exists. Skipping download.
Server running at http://localhost:8881
Passing an invented version returned a correct error:
node dist/packages/wp-now/cli.js start --wp=foo
wp-now start
Start the server
Options:
--version Show version number [boolean]
--path Path to the PHP or WordPress project. Defaults to the cu
rrent working directory. [string]
--php PHP version to use. [string]
--wp WordPress version to use: e.g. '--wp=6.2' [string]
--port Server port [number]
--blueprint Path to a blueprint file to be executed [string]
--reset Create a new project environment, destroying the old pro
ject environment. [boolean]
--skip-browser Do not launch the default browser
[boolean] [default: false]
--inspect Use Node debugging client. [number]
--inspect-brk Use Node debugging client. Break immediately on script e
xecution start. [number]
--trace-exit Prints a stack trace whenever an environment is exited p
roactively, i.e. invoking process.exit(). [number]
--trace-uncaught Print stack traces for uncaught exceptions; usually, the
stack trace associated with the creation of an Error is
printed, whereas this makes Node.js also print the stac
k trace associated with throwing the value (which does n
ot need to be an Error instance). [number]
--trace-warnings Print stack traces for process warnings (including depre
cations). [number]
-h, --help Show help [boolean]
Unrecognized WordPress version. Please use "latest" or numeric versions such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"
if (!isValidWordPressVersion(version)) { | ||
throw new Error( | ||
'Unrecognized WordPress version. Please use "latest", "trunk", "nightly", or numeric versions such as "6.2", "6.0.1", "6.2-beta1", or "6.2-RC1"' | ||
); | ||
} |
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.
I've found this check is already on:
https://github.com/zaguiini/playground-tools/blob/f8e1c1e15767ae0e391317afffbf61964e7fad7b/packages/wp-now/src/config.ts#L146-L150
It's possible. I just wanted to stick as much as possible to the "a function should do one thing" principle. Also if we move the alias resolver within But let me know if you have other ideas.
That'd be great 🙌 |
I've fixed the tests here e727b2e @zaguiini, I've also realized that this PR was breaking the ability to use wp-now while offline. I used a file to cache the resolutions and use it in case the request to the server fails. Let me know what you think. Test instructions:
|
Fantastic, @sejas! All good to me. We're not handling the error when there is no downloaded corresponding WP version and it also fails to fetch from the internet: But that's a small issue. Great job 🚀 |
Great suggestion. I've decided to terminate the process and displaying an error for that case: aa9cde2 |
What?
Resolves to an actual WordPress version when starting
wp-now
with--wp=latest|trunk|nightly
.It keeps working while offline by caching the version aliases in a file:
~/.wp-now/wp-version-offline-alias.json
Why?
In #214, it was reported that running
--wp=latest
might start the server with an outdated version of WordPress because we're caching the version locally by the alias (which changes between published versions) and not the version number.How?
Instead of having
latest
,trunk
andnightly
folders, we're resolving these aliases using theapi.wordpress.org
endpoint to actual versions, and caching the version number instead of the alias.After confirmation this is the approach we want to move forward with, I'll add/update tests.
Testing Instructions
Build it locally and verify that following commands produce the following outputs:
start
wp: 6.5.5 (resolved from alias: latest)
start --wp=latest
wp: 6.5.5 (resolved from alias: latest)
start --wp=trunk
wp: 6.7-alpha-xxxx (resolved from alias: trunk)
start --wp=nightly
wp: 6.7-alpha-xxxx (resolved from alias: nightly)
start --wp=6.3
wp: 6.3