Skip to content

Commit 130688b

Browse files
committed
playing with rollup ordering
1 parent 6c36507 commit 130688b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

rollup.config.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ const moveTypescriptDeclarationsPlugin = (packagePath) => ({
6161
}
6262
});
6363

64-
const files = glob.sync('src/*/assets/src/*controller.ts');
65-
// custom handling for StimulusBundle
66-
files.push('src/StimulusBundle/assets/src/loader.ts');
67-
files.push('src/StimulusBundle/assets/src/controllers.ts');
64+
const files = [
65+
// custom handling for StimulusBundle
66+
'src/StimulusBundle/assets/src/loader.ts',
67+
'src/StimulusBundle/assets/src/controllers.ts',
68+
...glob.sync('src/*/assets/src/*controller.ts'),
69+
]
6870
module.exports = files.map((file) => {
6971
const packageRoot = path.join(file, '..', '..');
7072
const packagePath = path.join(packageRoot, 'package.json');

src/StimulusBundle/assets/dist/loader.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class StimulusLazyControllerHandler {
2525
this.lazyLoadNewControllers(document.documentElement);
2626
}
2727
lazyLoadExistingControllers(element) {
28-
this.queryControllerNamesWithin(element).forEach(controllerName => this.loadLazyController(controllerName));
28+
this.queryControllerNamesWithin(element).forEach((controllerName) => this.loadLazyController(controllerName));
2929
}
3030
async loadLazyController(name) {
3131
if (canRegisterController(name, this.application)) {
3232
if (this.lazyControllers[name] === undefined) {
3333
console.error(`Failed to autoload controller: ${name}`);
3434
}
35-
const controllerModule = await (this.lazyControllers[name]());
35+
const controllerModule = await this.lazyControllers[name]();
3636
registerController(name, controllerModule.default, this.application);
3737
}
3838
}
@@ -41,8 +41,9 @@ class StimulusLazyControllerHandler {
4141
for (const { attributeName, target, type } of mutationsList) {
4242
switch (type) {
4343
case 'attributes': {
44-
if (attributeName === controllerAttribute && target.getAttribute(controllerAttribute)) {
45-
extractControllerNamesFrom(target).forEach(controllerName => this.loadLazyController(controllerName));
44+
if (attributeName === controllerAttribute &&
45+
target.getAttribute(controllerAttribute)) {
46+
extractControllerNamesFrom(target).forEach((controllerName) => this.loadLazyController(controllerName));
4647
}
4748
break;
4849
}
@@ -58,7 +59,9 @@ class StimulusLazyControllerHandler {
5859
});
5960
}
6061
queryControllerNamesWithin(element) {
61-
return Array.from(element.querySelectorAll(`[${controllerAttribute}]`)).map(extractControllerNamesFrom).flat();
62+
return Array.from(element.querySelectorAll(`[${controllerAttribute}]`))
63+
.map(extractControllerNamesFrom)
64+
.flat();
6265
}
6366
}
6467
function registerController(name, controller, application) {
@@ -71,7 +74,7 @@ function extractControllerNamesFrom(element) {
7174
if (!controllerNameValue) {
7275
return [];
7376
}
74-
return controllerNameValue.split(/\s+/).filter(content => content.length);
77+
return controllerNameValue.split(/\s+/).filter((content) => content.length);
7578
}
7679
function canRegisterController(name, application) {
7780
return !application.router.modulesByIdentifier.has(name);

0 commit comments

Comments
 (0)