Skip to content

Commit 8b77e37

Browse files
committed
re-add old version support
1 parent 4d28ca2 commit 8b77e37

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

lib/WebpackConfig.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ class WebpackConfig {
131131
resolveUrlLoader: true,
132132
resolveUrlLoaderOptions: {}
133133
};
134+
/** @deprecated */
135+
this.stimulusOptions = {
136+
controllerJsonPath: null,
137+
};
134138
this.preactOptions = {
135139
preactCompat: false
136140
};
@@ -682,6 +686,7 @@ class WebpackConfig {
682686
this.addEntry(name, rootDir + '/' + controllersData.entrypoints[name]);
683687
}
684688

689+
this.stimulusOptions.controllersJsonPath = controllerJsonPath;
685690
this.addAliases({
686691
'@symfony/stimulus-bridge/controllers.json': path.resolve(controllerJsonPath),
687692
});

lib/config-generator.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const friendlyErrorPluginUtil = require('./plugins/friendly-errors');
3838
const assetOutputDisplay = require('./plugins/asset-output-display');
3939
const notifierPluginUtil = require('./plugins/notifier');
4040
const PluginPriorities = require('./plugins/plugin-priorities');
41+
const stimulusBridge = require('./plugins/stimulus-bridge');
4142
const applyOptionsCallback = require('./utils/apply-options-callback');
4243
const copyEntryTmpName = require('./utils/copyEntryTmpName');
4344
const getVueVersion = require('./utils/get-vue-version');
@@ -422,6 +423,8 @@ class ConfigGenerator {
422423

423424
variableProviderPluginUtil(plugins, this.webpackConfig);
424425

426+
stimulusBridge(plugins, this.webpackConfig);
427+
425428
cleanPluginUtil(plugins, this.webpackConfig);
426429

427430
definePluginUtil(plugins, this.webpackConfig);

lib/plugins/stimulus-bridge.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of the Symfony Webpack Encore package.
3+
*
4+
* (c) Fabien Potencier <[email protected]>
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
'use strict';
11+
12+
const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars
13+
const loaderFeatures = require('../features');
14+
const fs = require('fs');
15+
const packageHelper = require('../package-helper');
16+
const semver = require('semver');
17+
18+
/**
19+
* Support for @symfony/stimulus-bridge 1.1 or lower.
20+
*
21+
* @param {Array} plugins
22+
* @param {WebpackConfig} webpackConfig
23+
* @deprecated
24+
* @return {void}
25+
*/
26+
module.exports = function(plugins, webpackConfig) {
27+
if (webpackConfig.useStimulusBridge) {
28+
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('stimulus');
29+
30+
const version = packageHelper.getPackageVersion('@symfony/stimulus-bridge');
31+
if (semver.satisfies(version, '^1.2.0')) {
32+
// package is new and doesn't require this plugin
33+
34+
return;
35+
}
36+
37+
const createPlugin = require('@symfony/stimulus-bridge/webpack-helper'); // eslint-disable-line node/no-unpublished-require
38+
39+
plugins.push({
40+
plugin: createPlugin(JSON.parse(fs.readFileSync(webpackConfig.stimulusOptions.controllersJsonPath))),
41+
});
42+
}
43+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"@babel/preset-react": "^7.0.0",
6060
"@babel/preset-typescript": "^7.0.0",
6161
"@symfony/mock-module": "file:fixtures/stimulus/mock-module",
62-
"@symfony/stimulus-bridge": "git://github.com/symfony/stimulus-bridge#main",
62+
"@symfony/stimulus-bridge": "^1.1.0",
6363
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
6464
"@vue/babel-preset-jsx": "^1.0.0",
6565
"@vue/compiler-sfc": "^3.0.2",

test/functional.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const path = require('path');
1818
const testSetup = require('./helpers/setup');
1919
const fs = require('fs-extra');
2020
const getVueVersion = require('../lib/utils/get-vue-version');
21+
const packageHelper = require('../lib/package-helper');
22+
const semver = require('semver');
2123

2224
function createWebpackConfig(outputDirName = '', command, argv = {}) {
2325
const webpackConfig = testSetup.createWebpackConfig(
@@ -1913,9 +1915,17 @@ module.exports = {
19131915
});
19141916
});
19151917

1916-
it('Symfony - Stimulus standard app is built correctly', (done) => {
1918+
it('Symfony - Stimulus standard app is built correctly', function (done) {
19171919
const appDir = testSetup.createTestAppDir();
19181920

1921+
const version = packageHelper.getPackageVersion('@symfony/stimulus-bridge');
1922+
if (!semver.satisfies(version, '^1.2.0')) {
1923+
// we support the old version, but it's not tested
1924+
this.skip();
1925+
1926+
return;
1927+
}
1928+
19191929
const config = testSetup.createWebpackConfig(appDir, 'www/build', 'dev');
19201930
config.enableSingleRuntimeChunk();
19211931
config.setPublicPath('/build');

yarn.lock

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,12 @@
973973
"@symfony/mock-module@file:fixtures/stimulus/mock-module":
974974
version "1.0.0"
975975

976-
"@symfony/stimulus-bridge@git://github.com/symfony/stimulus-bridge#main":
976+
"@symfony/stimulus-bridge@^1.1.0":
977977
version "1.1.0"
978-
resolved "git://github.com/symfony/stimulus-bridge#a720035de8c3d6f4dac6af097364ba4f92bf187f"
978+
resolved "https://registry.yarnpkg.com/@symfony/stimulus-bridge/-/stimulus-bridge-1.1.0.tgz#34548c633fe49bcda84cc812939f63640e698af7"
979+
integrity sha512-Sz8iwKQHBjrgCnxCGwH87S/J/Min0gX3EuXJaHi4vpibY3BjVm+WYuP8+OYPkMIROPyNZKYgTffFfJLBAFLwFQ==
979980
dependencies:
980-
"@babel/plugin-proposal-class-properties" "^7.12.1"
981+
webpack-virtual-modules "^0.3.2"
981982

982983
"@types/anymatch@*":
983984
version "1.3.1"
@@ -8234,6 +8235,13 @@ webpack-virtual-modules@^0.2.2:
82348235
dependencies:
82358236
debug "^3.0.0"
82368237

8238+
webpack-virtual-modules@^0.3.2:
8239+
version "0.3.2"
8240+
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.3.2.tgz#b7baa30971a22d99451f897db053af48ec29ad2c"
8241+
integrity sha512-RXQXioY6MhzM4CNQwmBwKXYgBs6ulaiQ8bkNQEl2J6Z+V+s7lgl/wGvaI/I0dLnYKB8cKsxQc17QOAVIphPLDw==
8242+
dependencies:
8243+
debug "^3.0.0"
8244+
82378245
webpack@^5.12:
82388246
version "5.12.2"
82398247
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.12.2.tgz#f79574cdb7a4ef711c5f47f3d189e045a14217e5"

0 commit comments

Comments
 (0)