Skip to content

Commit 25a3529

Browse files
fix(plugins): preserve built-in plugin load order
1 parent dd2547f commit 25a3529

File tree

6 files changed

+198
-303
lines changed

6 files changed

+198
-303
lines changed

dist/amd/aurelia-framework.js

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -69,78 +69,56 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
6969
return this;
7070
};
7171

72-
Plugins.prototype.defaultBindingLanguage = function defaultBindingLanguage() {
72+
Plugins.prototype._addNormalizedPlugin = function _addNormalizedPlugin(name, config) {
7373
var _this2 = this;
7474

75-
this.aurelia.addPreStartTask(function () {
76-
return System.normalize('aurelia-templating-binding', _this2.bootstrapperName).then(function (name) {
77-
_this2.aurelia.use.plugin(name);
78-
});
79-
});
75+
var plugin = { moduleId: name, resourcesRelativeTo: name, config: config || {} };
8076

81-
return this;
82-
};
83-
84-
Plugins.prototype.router = function router() {
85-
var _this3 = this;
77+
this.plugin(plugin);
8678

8779
this.aurelia.addPreStartTask(function () {
88-
return System.normalize('aurelia-templating-router', _this3.bootstrapperName).then(function (name) {
89-
_this3.aurelia.use.plugin(name);
80+
return System.normalize(name, _this2.bootstrapperName).then(function (normalizedName) {
81+
normalizedName = normalizedName.endsWith('.js') || normalizedName.endsWith('.ts') ? normalizedName.substring(0, normalizedName.length - 3) : normalizedName;
82+
83+
plugin.moduleId = normalizedName;
84+
plugin.resourcesRelativeTo = normalizedName;
85+
System.map[name] = normalizedName;
9086
});
9187
});
9288

9389
return this;
9490
};
9591

96-
Plugins.prototype.history = function history() {
97-
var _this4 = this;
92+
Plugins.prototype.defaultBindingLanguage = function defaultBindingLanguage() {
93+
return this._addNormalizedPlugin('aurelia-templating-binding');
94+
};
9895

99-
this.aurelia.addPreStartTask(function () {
100-
return System.normalize('aurelia-history-browser', _this4.bootstrapperName).then(function (name) {
101-
_this4.aurelia.use.plugin(name);
102-
});
103-
});
96+
Plugins.prototype.router = function router() {
97+
return this._addNormalizedPlugin('aurelia-templating-router');
98+
};
10499

105-
return this;
100+
Plugins.prototype.history = function history() {
101+
return this._addNormalizedPlugin('aurelia-history-browser');
106102
};
107103

108104
Plugins.prototype.defaultResources = function defaultResources() {
109-
var _this5 = this;
110-
111-
this.aurelia.addPreStartTask(function () {
112-
return System.normalize('aurelia-templating-resources', _this5.bootstrapperName).then(function (name) {
113-
System.map['aurelia-templating-resources'] = name;
114-
_this5.aurelia.use.plugin(name);
115-
});
116-
});
117-
118-
return this;
105+
return this._addNormalizedPlugin('aurelia-templating-resources');
119106
};
120107

121108
Plugins.prototype.eventAggregator = function eventAggregator() {
122-
var _this6 = this;
123-
124-
this.aurelia.addPreStartTask(function () {
125-
return System.normalize('aurelia-event-aggregator', _this6.bootstrapperName).then(function (name) {
126-
System.map['aurelia-event-aggregator'] = name;
127-
_this6.aurelia.use.plugin(name);
128-
});
129-
});
130-
131-
return this;
109+
return this._addNormalizedPlugin('aurelia-event-aggregator');
132110
};
133111

134112
Plugins.prototype.standardConfiguration = function standardConfiguration() {
135113
return this.aurelia.use.defaultBindingLanguage().defaultResources().history().router().eventAggregator();
136114
};
137115

138116
Plugins.prototype.developmentLogging = function developmentLogging() {
139-
var _this7 = this;
117+
var _this3 = this;
140118

141119
this.aurelia.addPreStartTask(function () {
142-
return System.normalize('aurelia-logging-console', _this7.bootstrapperName).then(function (name) {
143-
return _this7.aurelia.loader.loadModule(name).then(function (m) {
120+
return System.normalize('aurelia-logging-console', _this3.bootstrapperName).then(function (name) {
121+
return _this3.aurelia.loader.loadModule(name).then(function (m) {
144122
_aureliaLogging.addAppender(new m.ConsoleAppender());
145123
_aureliaLogging.setLevel(_aureliaLogging.logLevel.debug);
146124
});
@@ -151,7 +129,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
151129
};
152130

153131
Plugins.prototype._process = function _process() {
154-
var _this8 = this;
132+
var _this4 = this;
155133

156134
var aurelia = this.aurelia,
157135
loader = aurelia.loader,
@@ -167,7 +145,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
167145
return loadPlugin(aurelia, loader, current).then(next);
168146
}
169147

170-
_this8.processed = true;
148+
_this4.processed = true;
171149
return Promise.resolve();
172150
};
173151

@@ -308,7 +286,7 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
308286
};
309287

310288
Aurelia.prototype.start = function start() {
311-
var _this9 = this;
289+
var _this5 = this;
312290

313291
if (this.started) {
314292
return Promise.resolve(this);
@@ -320,48 +298,48 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
320298
preventActionlessFormSubmit();
321299

322300
return runTasks(this, this.preStartTasks).then(function () {
323-
return _this9.use._process().then(function () {
324-
if (!_this9.container.hasHandler(_aureliaTemplating.BindingLanguage)) {
301+
return _this5.use._process().then(function () {
302+
if (!_this5.container.hasHandler(_aureliaTemplating.BindingLanguage)) {
325303
var message = 'You must configure Aurelia with a BindingLanguage implementation.';
326304
logger.error(message);
327305
throw new Error(message);
328306
}
329307

330-
if (!_this9.container.hasHandler(_aureliaTemplating.Animator)) {
331-
_aureliaTemplating.Animator.configureDefault(_this9.container);
308+
if (!_this5.container.hasHandler(_aureliaTemplating.Animator)) {
309+
_aureliaTemplating.Animator.configureDefault(_this5.container);
332310
}
333311

334-
return loadResources(_this9.container, _this9.resourcesToLoad, _this9.resources);
312+
return loadResources(_this5.container, _this5.resourcesToLoad, _this5.resources);
335313
}).then(function () {
336-
return runTasks(_this9, _this9.postStartTasks).then(function () {
314+
return runTasks(_this5, _this5.postStartTasks).then(function () {
337315
logger.info('Aurelia Started');
338316
var evt = new window.CustomEvent('aurelia-started', { bubbles: true, cancelable: true });
339317
document.dispatchEvent(evt);
340-
return _this9;
318+
return _this5;
341319
});
342320
});
343321
});
344322
};
345323

346324
Aurelia.prototype.enhance = function enhance() {
347-
var _this10 = this;
325+
var _this6 = this;
348326

349327
var bindingContext = arguments[0] === undefined ? {} : arguments[0];
350328
var applicationHost = arguments[1] === undefined ? null : arguments[1];
351329

352330
this._configureHost(applicationHost);
353331

354332
return new Promise(function (resolve) {
355-
var viewEngine = _this10.container.get(_aureliaTemplating.ViewEngine);
356-
_this10.root = viewEngine.enhance(_this10.container, _this10.host, _this10.resources, bindingContext);
357-
_this10.root.attached();
358-
_this10._onAureliaComposed();
359-
return _this10;
333+
var viewEngine = _this6.container.get(_aureliaTemplating.ViewEngine);
334+
_this6.root = viewEngine.enhance(_this6.container, _this6.host, _this6.resources, bindingContext);
335+
_this6.root.attached();
336+
_this6._onAureliaComposed();
337+
return _this6;
360338
});
361339
};
362340

363341
Aurelia.prototype.setRoot = function setRoot() {
364-
var _this11 = this;
342+
var _this7 = this;
365343

366344
var root = arguments[0] === undefined ? 'app' : arguments[0];
367345
var applicationHost = arguments[1] === undefined ? null : arguments[1];
@@ -379,10 +357,10 @@ define(['exports', 'core-js', 'aurelia-logging', 'aurelia-metadata', 'aurelia-de
379357
instruction.host = this.host;
380358

381359
return compositionEngine.compose(instruction).then(function (root) {
382-
_this11.root = root;
360+
_this7.root = root;
383361
instruction.viewSlot.attached();
384-
_this11._onAureliaComposed();
385-
return _this11;
362+
_this7._onAureliaComposed();
363+
return _this7;
386364
});
387365
};
388366

dist/aurelia-framework.js

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,33 @@ export class Plugins {
7777
return this;
7878
}
7979

80+
_addNormalizedPlugin(name, config){
81+
var plugin = { moduleId: name, resourcesRelativeTo: name, config: config || {} };
82+
83+
this.plugin(plugin);
84+
85+
this.aurelia.addPreStartTask(() => {
86+
return System.normalize(name, this.bootstrapperName).then(normalizedName => {
87+
normalizedName = normalizedName.endsWith('.js') || normalizedName.endsWith('.ts')
88+
? normalizedName.substring(0, normalizedName.length - 3) : normalizedName;
89+
90+
plugin.moduleId = normalizedName;
91+
plugin.resourcesRelativeTo = normalizedName;
92+
System.map[name] = normalizedName;
93+
});
94+
});
95+
96+
return this;
97+
}
98+
8099
/**
81100
* Plugs in the default binding language from aurelia-templating-binding.
82101
*
83102
* @method defaultBindingLanguage
84103
* @return {Plugins} Returns the current Plugins instance.
85104
*/
86105
defaultBindingLanguage():Plugins{
87-
this.aurelia.addPreStartTask(() => {
88-
return System.normalize('aurelia-templating-binding', this.bootstrapperName).then(name => {
89-
this.aurelia.use.plugin(name);
90-
});
91-
});
92-
93-
return this;
106+
return this._addNormalizedPlugin('aurelia-templating-binding');
94107
};
95108

96109
/**
@@ -100,13 +113,7 @@ export class Plugins {
100113
* @return {Plugins} Returns the current Plugins instance.
101114
*/
102115
router():Plugins{
103-
this.aurelia.addPreStartTask(() => {
104-
return System.normalize('aurelia-templating-router', this.bootstrapperName).then(name => {
105-
this.aurelia.use.plugin(name);
106-
});
107-
});
108-
109-
return this;
116+
return this._addNormalizedPlugin('aurelia-templating-router');
110117
}
111118

112119
/**
@@ -116,13 +123,7 @@ export class Plugins {
116123
* @return {Plugins} Returns the current Plugins instance.
117124
*/
118125
history():Plugins{
119-
this.aurelia.addPreStartTask(() => {
120-
return System.normalize('aurelia-history-browser', this.bootstrapperName).then(name => {
121-
this.aurelia.use.plugin(name);
122-
});
123-
});
124-
125-
return this;
126+
return this._addNormalizedPlugin('aurelia-history-browser');
126127
}
127128

128129
/**
@@ -132,14 +133,7 @@ export class Plugins {
132133
* @return {Plugins} Returns the current Plugins instance.
133134
*/
134135
defaultResources():Plugins{
135-
this.aurelia.addPreStartTask(() => {
136-
return System.normalize('aurelia-templating-resources', this.bootstrapperName).then(name => {
137-
System.map['aurelia-templating-resources'] = name;
138-
this.aurelia.use.plugin(name);
139-
});
140-
});
141-
142-
return this;
136+
return this._addNormalizedPlugin('aurelia-templating-resources');
143137
}
144138

145139
/**
@@ -149,14 +143,7 @@ export class Plugins {
149143
* @return {Plugins} Returns the current Plugins instance.
150144
*/
151145
eventAggregator():Plugins{
152-
this.aurelia.addPreStartTask(() => {
153-
return System.normalize('aurelia-event-aggregator', this.bootstrapperName).then(name => {
154-
System.map['aurelia-event-aggregator'] = name;
155-
this.aurelia.use.plugin(name);
156-
});
157-
});
158-
159-
return this;
146+
return this._addNormalizedPlugin('aurelia-event-aggregator');
160147
}
161148

162149
/**

0 commit comments

Comments
 (0)