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

[uiExports] migrate uiApp "uses" to explicit imports in apps #17828

Merged
merged 11 commits into from
May 3, 2018

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Apr 20, 2018

Fixes #17481

Rather that defining the uiExports that an app "uses" in its uiExport spec, apps will now need to import the uiExports in their main/entry file.

This allows us to move closer to the notion of an app only existing on the client side, as the optimizer no longer needs to know what uiExports to include in each bundle.

Before you ask 😁: I had a version of this PR that moved the import/require calls into the registries so that apps wouldn't need to know what uiExports they should load to populate the registries they want to use. While I made promising progress towards this goal, the changes necessary were pretty large and I started to realize it wasn't worth the risk for a change that will be made obsolete by the work I'm doing on the new platform.

cc @timroes @nreese @w33ble @weltenwort

@spalger spalger added review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.0.0 v6.4.0 labels Apr 20, 2018
@spalger spalger requested review from epixa and azasypkin April 20, 2018 18:55
@spalger spalger force-pushed the implement/uiExports-modules branch 2 times, most recently from 343f067 to 7261884 Compare April 20, 2018 20:09
@elastic elastic deleted a comment from elasticmachine Apr 20, 2018
@elastic elastic deleted a comment from elasticmachine Apr 20, 2018
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@azasypkin
Copy link
Member

@spalger could you please rebase PR on the latest master (it doesn't block review though, already on it)?

Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

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

LGTM. I don't know this code very well, but haven't noticed any issues while testing.

@@ -93,7 +80,7 @@ export class UiApp {
}

getModules() {
Copy link
Member

Choose a reason for hiding this comment

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

question: are we going to get rid of this method any time soon? If no, maybe it'd make sense to rename getModules to getMain/getMainModule or something like this and return just this._main.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, they'll be gone soon which I why I kept the clean up minimal.

@@ -67,5 +67,6 @@ afterEach(function () {

// Kick off mocha, called at the end of test entry files
export function bootstrap() {
require('uiExports/hacks');
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe you can add comment here, why we need this new require like you did in chrome.js (unless it's obvious for everyone else except me :))?

// what require() calls it will execute within the bundle
JSON.stringify({
type,
modules: [].concat(extensions[type] || [])
Copy link
Member

Choose a reason for hiding this comment

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

question: why not just extensions[type] || []? Do we support non-arrays in extensions[type]?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, the values in appExtensions will always be arrays.

const { type, modules } = JSON.parse(module.id.slice(module.id.indexOf('?') + 1));

const requires = modules
.sort((a, b) => a.localeCompare(b))
Copy link
Member

Choose a reason for hiding this comment

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

question: just curious, what is value of localeCompare in this particular use case? Is there cases when default comparison won't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just a habit when comparing strings.

}

export default function () {
if (module.id.indexOf('?') === -1) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: includes('?') or maybe indexOf but put result into variable and reuse below?

.sort((a, b) => a.localeCompare(b))
.map(m => {
const req = normalizePath(m);
return `{ req: '${req}', module: require('${req}') },`;
Copy link
Member

Choose a reason for hiding this comment

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

nit: would be great if you can add a comment to clarify why we use this format exactly ({ req, module}) and where it's consumed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That format was beneficial for the approach I alluded to in the description, where uiExport modules were being pulled in by the registries rather than being pulled in to decorate the registries... No need for it now.

@spalger spalger force-pushed the implement/uiExports-modules branch from f9f1543 to ce4e7b0 Compare April 26, 2018 19:03
@spalger
Copy link
Contributor Author

spalger commented Apr 26, 2018

@azasypkin @epixa updated to address review feedback and include the x-pack pr (sorry for the rebase)

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@azasypkin
Copy link
Member

Still LGTM :)

Copy link
Contributor

@epixa epixa left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@spalger spalger merged commit e1a2fcb into elastic:master May 3, 2018
spalger added a commit that referenced this pull request May 3, 2018
* [uiExports] migrate uiApp "uses" to explicit imports in apps

* [uiApp] update tests for getModules() method

* [optimize/uiExports] improve naming and comments

* [uiExports] sort imports so they load in the same order as before

* [testHarness] load hacks when testing in the browser

* [x-pack/uiExports] use new uiExports modules

* [testHarness] describe why we import uiExports/hacks

* [optimize] remove needless [].concat()

* [optimize/createUiExportsModule] string.includes > string.indexOf

* [uiExports/createUiExportsModule] remove needless capture of module exports

(cherry picked from commit e1a2fcb)
@spalger
Copy link
Contributor Author

spalger commented May 3, 2018

6.4/6.x: a6c0c62

@spalger spalger deleted the implement/uiExports-modules branch May 3, 2018 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Plugins review Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v6.4.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ui/apps] Move "uses" config into bundle source
4 participants