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

feat(v2): Collect plugin versions to allow them to be inspected in debug plugin #3050

Merged
merged 1 commit into from
Jul 13, 2020
Merged

feat(v2): Collect plugin versions to allow them to be inspected in debug plugin #3050

merged 1 commit into from
Jul 13, 2020

Conversation

SamChou19815
Copy link
Contributor

Motivation

Implements the proposal in #3042.

@docusaurus/core will collect and generate all the plugin version at start time, and put them into .docusaurus/site-metadata.json. To find the version of the plugin, I choose to walked up the directory of the resolved path until it hits a directory with package.json.

The version information has 4 possible categories:

  • package: plugin is external to the current docusaurus project, with will be attached with a version string if it can be found in package.json
  • project: plugin is inside the same docusaurus project
  • local: some random place on the filesystem that doesn't have any package.json in its ancestor directories.
  • synthetic: only used to workaround the synthetic docusaurus-bootstrap-plugin:
    plugins.push({
    name: 'docusaurus-bootstrap-plugin',
    configureWebpack: () => ({
    resolve: {
    alias,
    },
    }),
    injectHtmlTags: () => {
    const stylesheetsTags = stylesheets.map((source) =>
    typeof source === 'string'
    ? `<link rel="stylesheet" href="${source}">`
    : {
    tagName: 'link',
    attributes: {
    rel: 'stylesheet',
    ...source,
    },
    },
    );
    const scriptsTags = scripts.map((source) =>
    typeof source === 'string'
    ? `<script type="text/javascript" src="${source}"></script>`
    : {
    tagName: 'script',
    attributes: {
    type: 'text/javascript',
    ...source,
    },
    },
    );
    return {
    headTags: [...stylesheetsTags, ...scriptsTags],
    };
    },
    });

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  • Added unit test to test the version resolution behavior.
  • works on debug page:

Screen Shot 2020-07-11 at 15 48 37

  • generated site-metadata.json for v2 website:
{
  "docusaurusVersion": "2.0.0-alpha.58",
  "siteVersion": "2.0.0-alpha.58",
  "pluginVersions": {
    "docusaurus-plugin-content-docs": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-plugin-content-blog": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-plugin-content-pages": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-plugin-debug": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-theme-classic": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-theme-search-algolia": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-plugin-client-redirects": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-plugin-ideal-image": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-plugin-pwa": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    },
    "docusaurus-theme-live-codeblock": {
      "type": "package",
      "version": "2.0.0-alpha.58"
    }
  }
}

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 11, 2020
@docusaurus-bot
Copy link
Contributor

Deploy preview for docusaurus-2 ready!

Built with commit 0669fe4

https://deploy-preview-3050--docusaurus-2.netlify.app

@SamChou19815 SamChou19815 marked this pull request as ready for review July 11, 2020 21:07
@slorber
Copy link
Collaborator

slorber commented Jul 13, 2020

Awesome, seems to work fine!

@slorber slorber merged commit 3ebe245 into facebook:master Jul 13, 2020
@slorber slorber added the pr: new feature This PR adds a new API or behavior. label Jul 13, 2020
@SamChou19815 SamChou19815 deleted the versions-debug branch July 13, 2020 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants