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

Fix: JSON Schema Docgen doesn't work on Windows OS #66414

Merged
merged 3 commits into from
Oct 25, 2024
Merged

Conversation

t-hamano
Copy link
Contributor

@t-hamano t-hamano commented Oct 24, 2024

Related to #63868

Reported in this comment on Slack

Original report

Since yesterday I am having problems passing the pre-commit check when I use Windows 11. (Yes I have ran npm run distclean and npm ci)
There seems to be something wrong with the paths used in the json-schema-ref-parser or gen-theme-reference.mjs:
I don't think it should be D:\D:\ one should be correct.
stack: 'JSONParserError: Error opening file "D:\D:\LocalSites\67\app\public\wp-content\plugins\gutenberg\schemas\json\theme.json"
ENOENT: no such file or directory (edited)

What?

This PR fixes the docs:theme-ref command so that it works on Windows OS.

Why?

When running the docs:theme-ref command on Windows OS, the following error occurs:

{
  stack: 'JSONParserError: Error opening file "D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json" \n' +
    "ENOENT: no such file or directory, open 'D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json'\n" +
    '    at Object.read (D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\node_modules\\@apidevtools\\json-schema-ref-parser\\dist\\lib\\resolvers\\file.js:61:19)',
  code: 'ERESOLVER',
  name: 'ResolverError',
  message: 'Error opening file "D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json" \n' +
    "ENOENT: no such file or directory, open 'D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json'",
  source: 'D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json',
  path: null,
  toJSON: [Function: toJSON],
  ioErrorCode: 'ENOENT',
  footprint: 'null+D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json+ERESOLVER+Error opening file "D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json" \n' +
    "ENOENT: no such file or directory, open 'D:\\D:\\Desktop\\wp_dev\\WordPress\\gutenberg\\schemas\\json\\theme.json'",
  toString: [Function: toString]
}

When we investigated this issue, we found that THEME_JSON_SCHEMA_URL.pathname has an invalid path like the following:

/D:/Desktop/wp_dev/WordPress/gutenberg/schemas/json/theme.json

I found a similar report about this path in the node project: nodejs/node#37845

How?

According to the comment, this path is a valid URL, but it seems that the URL needs to be converted to a path:

This is the correct output. URLs are not paths. You should convert the url to a path and then perform resolution using that: https://nodejs.org/api/url.html#url_url_fileurltopath_url

Testing Instructions

  • Make some changes to the schemas/json/theme.json file.
  • Run npm run docs:theme-ref.
  • The theme-json-living.md file should be updated.

@t-hamano t-hamano added [Type] Developer Documentation Documentation for developers OS Issues Issues or PRs that are related to OS specific problems labels Oct 24, 2024
@t-hamano t-hamano self-assigned this Oct 24, 2024
@t-hamano t-hamano marked this pull request as ready for review October 24, 2024 12:59
Copy link

github-actions bot commented Oct 24, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@gziolo gziolo requested a review from sirreal October 24, 2024 13:00
Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a windows setup to test, but this makes sense to me 👍

bin/api-docs/gen-theme-reference.mjs Outdated Show resolved Hide resolved
t-hamano and others added 2 commits October 25, 2024 10:30
Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>
@t-hamano t-hamano merged commit 187ef63 into trunk Oct 25, 2024
62 checks passed
@t-hamano t-hamano deleted the fix/docgen-windows branch October 25, 2024 02:26
@github-actions github-actions bot added this to the Gutenberg 19.6 milestone Oct 25, 2024
swissspidy pushed a commit that referenced this pull request Oct 25, 2024
* Fix: JSON Schema Docgen doesn't work on Windows OS

* Update bin/api-docs/gen-theme-reference.mjs

Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>

* Lint

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
karthick-murugan pushed a commit to karthick-murugan/gutenberg that referenced this pull request Nov 13, 2024
* Fix: JSON Schema Docgen doesn't work on Windows OS

* Update bin/api-docs/gen-theme-reference.mjs

Co-authored-by: Jon Surrell <sirreal@users.noreply.github.com>

* Lint

---------

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: sirreal <jonsurrell@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS Issues Issues or PRs that are related to OS specific problems [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants