Skip to content

Commit

Permalink
[uiBundlerEnv] add a method for exporting global import aliases for s…
Browse files Browse the repository at this point in the history
…pecial cases
  • Loading branch information
spalger committed Dec 15, 2016
1 parent b841c91 commit 4969d66
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
7 changes: 2 additions & 5 deletions src/core_plugins/tests_bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@ export default (kibana) => {
});
},

modules: {
__globalImportAliases__: {
ng_mock$: fromRoot('src/core_plugins/dev_mode/public/ng_mock'),
'angular-mocks$': require.resolve('./webpackShims/angular-mocks'),
fixtures: fromRoot('src/fixtures'),
test_utils: fromRoot('src/test_utils'),
'angular-mocks': {
path: require.resolve('angular-mocks'),
imports: 'angular'
},
}
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/core_plugins/tests_bundle/webpackShims/angular-mocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require('angular');
require('../../../../node_modules/angular-mocks/angular-mocks.js');
20 changes: 7 additions & 13 deletions src/ui/ui_bundler_env.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ module.exports = class UiBundlerEnv {
return (plugin, spec) => {
for (const re of arr(spec)) this.addNoParse(re);
};

case '__globalImportAliases__':
return (plugin, spec) => {
for (const key of Object.keys(spec)) {
this.aliases[key] = spec[key];
}
};
}
}

Expand All @@ -91,17 +98,4 @@ module.exports = class UiBundlerEnv {
addNoParse(regExp) {
this.noParse.push(regExp);
}

claim(id, pluginId) {
const owner = pluginId ? `Plugin ${pluginId}` : 'Kibana Server';

// TODO(spalger): we could do a lot more to detect colliding module defs
const existingOwner = this.aliasOwners[id] || this.aliasOwners[`${id}$`];

if (existingOwner) {
throw new TypeError(`${owner} attempted to override export "${id}" from ${existingOwner}`);
}

this.aliasOwners[id] = owner;
}
};

0 comments on commit 4969d66

Please sign in to comment.