-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(v2): Collect plugin versions to allow them to be inspected in de…
…bug plugin (#3050)
- Loading branch information
1 parent
a384986
commit 3ebe245
Showing
11 changed files
with
193 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,11 @@ | |
|
||
.Container { | ||
display: flex; | ||
flex-wrap: wrap; | ||
justify-content: center; | ||
margin: 1em; | ||
} | ||
|
||
.Section { | ||
width: 500px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// triple slash is important to keep, | ||
// see https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html | ||
// eslint-disable-next-line | ||
/// <reference types="@docusaurus/module-type-aliases" /> |
Empty file.
3 changes: 3 additions & 0 deletions
3
packages/docusaurus/src/server/versions/__fixtures__/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "random-version" | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/docusaurus/src/server/versions/__tests/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {getPluginVersion} from '..'; | ||
import {join} from 'path'; | ||
|
||
describe('getPluginVersion', () => { | ||
it('Can detect external packages plugins versions of correctly.', () => { | ||
expect( | ||
getPluginVersion( | ||
join(__dirname, '..', '__fixtures__', 'dummy-plugin.js'), | ||
// Make the plugin appear external. | ||
join(__dirname, '..', '..', '..', '..', '..', '..', 'website'), | ||
), | ||
).toEqual({type: 'package', version: 'random-version'}); | ||
}); | ||
|
||
it('Can detect project plugins versions correctly.', () => { | ||
expect( | ||
getPluginVersion( | ||
join(__dirname, '..', '__fixtures__', 'dummy-plugin.js'), | ||
// Make the plugin appear project local. | ||
join(__dirname, '..', '__fixtures__'), | ||
), | ||
).toEqual({type: 'project'}); | ||
}); | ||
|
||
it('Can detect local packages versions correctly.', () => { | ||
expect(getPluginVersion('/', '/')).toEqual({type: 'local'}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import {PluginVersionInformation} from '@generated/site-metadata'; | ||
import {existsSync, lstatSync} from 'fs-extra'; | ||
import {dirname, join} from 'path'; | ||
|
||
export function getPackageJsonVersion( | ||
packageJsonPath: string, | ||
): string | undefined { | ||
if (existsSync(packageJsonPath)) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/no-dynamic-require, global-require | ||
const {version} = require(packageJsonPath); | ||
return typeof version === 'string' ? version : undefined; | ||
} | ||
return undefined; | ||
} | ||
|
||
export function getPluginVersion( | ||
pluginPath: string, | ||
siteDir: string, | ||
): PluginVersionInformation { | ||
let potentialPluginPackageJsonDirectory = dirname(pluginPath); | ||
while (potentialPluginPackageJsonDirectory !== '/') { | ||
const packageJsonPath = join( | ||
potentialPluginPackageJsonDirectory, | ||
'package.json', | ||
); | ||
if (existsSync(packageJsonPath) && lstatSync(packageJsonPath).isFile()) { | ||
if (potentialPluginPackageJsonDirectory === siteDir) { | ||
// If the plugin belongs to the same docusaurus project, we classify it as local plugin. | ||
return {type: 'project'}; | ||
} | ||
return { | ||
type: 'package', | ||
version: getPackageJsonVersion(packageJsonPath), | ||
}; | ||
} | ||
potentialPluginPackageJsonDirectory = dirname( | ||
potentialPluginPackageJsonDirectory, | ||
); | ||
} | ||
// In rare cases where a plugin is a path where no parent directory contains package.json, we can only classify it as local. | ||
return {type: 'local'}; | ||
} |