-
Notifications
You must be signed in to change notification settings - Fork 667
Allow overriding the active plugin list #1875
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
Merged
openshift-merge-robot
merged 2 commits into
openshift:master
from
vojtechszocs:override-plugin-list
Jul 4, 2019
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| window.matchMedia = () => ({matches: true}); | ||
| window.matchMedia = () => ({ matches: true }); |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -11,6 +11,9 @@ const consoleAppName = '@console/app'; | |
| // glob that matches all the monorepo packages | ||
| const consolePkgGlob = 'packages/*/package.json'; | ||
|
|
||
| // env. variable used to override the active plugin list | ||
| const consolePluginOverrideEnvVar = 'CONSOLE_PLUGINS'; | ||
|
|
||
| /** | ||
| * Return `true` if the given package represents a Console plugin. | ||
| */ | ||
|
|
@@ -40,14 +43,19 @@ export const readPackages = (packageFiles: string[]) => { | |
| }; | ||
| }; | ||
|
|
||
| const sortPluginPackages: PluginPackageFilter = (appPackage, pluginPackages) => { | ||
| // if appPackage is in the list, make sure it's the first element | ||
| return _.sortBy(pluginPackages, (pkg) => (appPackage === pkg ? 0 : 1)); | ||
| }; | ||
|
|
||
| export const filterActivePluginPackages: PluginPackageFilter = (appPackage, pluginPackages) => { | ||
| // include dependencies of the appPackage or the appPackage itself | ||
| const list = pluginPackages.filter( | ||
| (pkg) => appPackage === pkg || appPackage.dependencies[pkg.name] === pkg.version, | ||
| return sortPluginPackages( | ||
| appPackage, | ||
| pluginPackages.filter( | ||
| (pkg) => appPackage === pkg || appPackage.dependencies[pkg.name] === pkg.version, | ||
| ), | ||
| ); | ||
|
|
||
| // if appPackage is in the list, make sure it's the first element | ||
| return _.sortBy(list, (pkg) => (appPackage === pkg ? 0 : 1)); | ||
| }; | ||
|
|
||
| /** | ||
|
|
@@ -59,7 +67,21 @@ export const resolvePluginPackages = ( | |
| ) => { | ||
| const packageFiles = glob.sync(consolePkgGlob, { cwd: monorepoRootDir, absolute: true }); | ||
| const { appPackage, pluginPackages } = readPackages(packageFiles); | ||
| return appPackage ? pluginFilter(appPackage, pluginPackages) : []; | ||
|
|
||
| if (!appPackage) { | ||
| throw new Error(`Cannot detect Console application package ${consoleAppName}`); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this check was added to reflect the expectation that Console (app) itself is a plugin, i.e. |
||
| } | ||
|
|
||
| // provide the ability to override the active plugin list | ||
| if (_.isString(process.env[consolePluginOverrideEnvVar])) { | ||
| const pluginPackageNames = process.env[consolePluginOverrideEnvVar].split(','); | ||
| return sortPluginPackages( | ||
| appPackage, | ||
| pluginPackages.filter((pkg) => pluginPackageNames.includes(pkg.name)), | ||
| ); | ||
| } | ||
|
|
||
| return pluginFilter(appPackage, pluginPackages); | ||
| }; | ||
|
|
||
| export type Package = readPkg.NormalizedPackageJson; | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
| /* eslint-env node */ | ||
|
|
||
| // https://github.com/airbnb/enzyme/blob/master/docs/guides/jsdom.md | ||
|
|
||
| import { JSDOM } from 'jsdom'; | ||
|
|
||
| const jsdom = new JSDOM('<!doctype html><html><body></body></html>'); | ||
| const { window } = jsdom; | ||
|
|
||
| function copyProps(src, target) { | ||
| Object.defineProperties(target, { | ||
| ...Object.getOwnPropertyDescriptors(src), | ||
| ...Object.getOwnPropertyDescriptors(target), | ||
| }); | ||
| } | ||
|
|
||
| global.window = window; | ||
| global.document = window.document; | ||
| global.navigator = { | ||
| userAgent: 'node.js', | ||
| }; | ||
| global.requestAnimationFrame = (callback) => setTimeout(callback, 0); | ||
| global.cancelAnimationFrame = (id) => { | ||
| clearTimeout(id); | ||
| }; | ||
|
|
||
| copyProps(window, global); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess this does adhere to the real web API. But the existing way is what it should be (in a FP world).
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.
Yup, the web storage API could be better 😃 the above change just reflects the method signature in
node_modules/typescript/lib/lib.dom.d.ts