Skip to content

Commit 2ea1d2f

Browse files
committed
bug #863 fix(stimulus): don't require an optional dependency if it's not used (Kocal)
This PR was merged into the main branch. Discussion ---------- fix(stimulus): don't require an optional dependency if it's not used Fix #861 Testing my modification on a new Symfony repository but removing `@symfony/stimulus-bridge` and `stimulus` dependencies. If you try to use `.useStimulusBridge()` without those depdendencies installed, you now have this friendly error message: ![image](https://user-images.githubusercontent.com/2103975/101016415-082df580-3569-11eb-850d-e49115d8b621.png) When you install the dependencies, everything is okay: ![image](https://user-images.githubusercontent.com/2103975/101016826-930ef000-3569-11eb-8e05-b80dc8f19458.png) When you don't use `.useStimulusBridge()` and don't have installed Stimulus dependencies, you have no errors anymore about those missing deps, since they are not required. Here, the errors are coming from the app code (from the Symfony recipe) I didn't have update, but it's fine: ![image](https://user-images.githubusercontent.com/2103975/101017128-f731b400-3569-11eb-8302-d2d120119884.png) cc @fabpot @weaverryan Commits ------- 7b95a1d fix(stimulus): don't require an optional dependency if it's not used
2 parents cd00778 + 7b95a1d commit 2ea1d2f

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/features.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ const features = {
147147
{ name: 'handlebars-loader', enforce_version: true }
148148
],
149149
description: 'load Handlebars files'
150+
},
151+
stimulus: {
152+
method: 'enableStimulusBridge()',
153+
packages: [
154+
{ name: '@symfony/stimulus-bridge' },
155+
{ name: 'stimulus' }
156+
],
157+
description: 'enable Stimulus bridge'
150158
}
151159
};
152160

lib/plugins/stimulus-bridge.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'use strict';
1111

1212
const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars
13-
const createPlugin = require('@symfony/stimulus-bridge/webpack-helper');
13+
const loaderFeatures = require('../features');
1414
const fs = require('fs');
1515

1616
/**
@@ -20,6 +20,10 @@ const fs = require('fs');
2020
*/
2121
module.exports = function(plugins, webpackConfig) {
2222
if (webpackConfig.useStimulusBridge) {
23+
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('stimulus');
24+
25+
const createPlugin = require('@symfony/stimulus-bridge/webpack-helper');
26+
2327
plugins.push({
2428
plugin: createPlugin(JSON.parse(fs.readFileSync(webpackConfig.stimulusOptions.controllersJsonPath))),
2529
});

0 commit comments

Comments
 (0)