[uiBundlerEnv] add a method for exporting global import aliases for special cases

This commit is contained in:
spalger 2016-12-15 11:38:52 -07:00
parent b841c917f9
commit 4969d660df
3 changed files with 11 additions and 18 deletions

View file

@ -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'
},
}
}
});

View file

@ -0,0 +1,2 @@
require('angular');
require('../../../../node_modules/angular-mocks/angular-mocks.js');

View file

@ -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];
}
};
}
}
@ -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;
}
};