Skip to content

Commit 42aab44

Browse files
committed
feature #888 updating stimulus-bridge plugin to work with proposed new loader (weaverryan)
This PR was squashed before being merged into the main branch. Discussion ---------- updating stimulus-bridge plugin to work with proposed new loader Partner to symfony/stimulus-bridge#14 * [x] Wait for partner PR to be merged Commits ------- 5640760 updating stimulus-bridge plugin to work with proposed new loader
2 parents 46a8c59 + 5640760 commit 42aab44

File tree

12 files changed

+60
-36
lines changed

12 files changed

+60
-36
lines changed

fixtures/stimulus/assets/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import { startStimulusApp } from '@symfony/stimulus-bridge';
2-
import '@symfony/autoimport';
32

43
export const app = startStimulusApp(require.context('./controllers', true, /\.(j|t)sx?$/));

fixtures/stimulus/autoimport/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

fixtures/stimulus/autoimport/package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

fixtures/stimulus/controllers/index.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

fixtures/stimulus/controllers/package.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/WebpackConfig.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class WebpackConfig {
131131
resolveUrlLoader: true,
132132
resolveUrlLoaderOptions: {}
133133
};
134+
/** @deprecated */
134135
this.stimulusOptions = {
135136
controllerJsonPath: null,
136137
};
@@ -686,6 +687,9 @@ class WebpackConfig {
686687
}
687688

688689
this.stimulusOptions.controllersJsonPath = controllerJsonPath;
690+
this.addAliases({
691+
'@symfony/stimulus-bridge/controllers.json': path.resolve(controllerJsonPath),
692+
});
689693
}
690694

691695
enableBuildCache(buildDependencies, callback = (cache) => {}) {

lib/features.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const features = {
151151
stimulus: {
152152
method: 'enableStimulusBridge()',
153153
packages: [
154-
{ name: '@symfony/stimulus-bridge' },
154+
{ name: '@symfony/stimulus-bridge', enforce_version: true },
155155
{ name: 'stimulus' }
156156
],
157157
description: 'enable Stimulus bridge'

lib/plugins/stimulus-bridge.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,28 @@
1212
const WebpackConfig = require('../WebpackConfig'); //eslint-disable-line no-unused-vars
1313
const loaderFeatures = require('../features');
1414
const fs = require('fs');
15+
const packageHelper = require('../package-helper');
16+
const semver = require('semver');
1517

1618
/**
19+
* Support for @symfony/stimulus-bridge 1.1 or lower.
20+
*
1721
* @param {Array} plugins
1822
* @param {WebpackConfig} webpackConfig
23+
* @deprecated
1924
* @return {void}
2025
*/
2126
module.exports = function(plugins, webpackConfig) {
2227
if (webpackConfig.useStimulusBridge) {
2328
loaderFeatures.ensurePackagesExistAndAreCorrectVersion('stimulus');
2429

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+
2537
const createPlugin = require('@symfony/stimulus-bridge/webpack-helper'); // eslint-disable-line node/no-unpublished-require
2638

2739
plugins.push({

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@
5858
"@babel/plugin-transform-react-jsx": "^7.0.0",
5959
"@babel/preset-react": "^7.0.0",
6060
"@babel/preset-typescript": "^7.0.0",
61-
"@symfony/autoimport": "file:fixtures/stimulus/autoimport",
62-
"@symfony/controllers": "file:fixtures/stimulus/controllers",
6361
"@symfony/mock-module": "file:fixtures/stimulus/mock-module",
64-
"@symfony/stimulus-bridge": "^1.0.0",
62+
"@symfony/stimulus-bridge": "^1.1.0",
6563
"@vue/babel-helper-vue-jsx-merge-props": "^1.0.0",
6664
"@vue/babel-preset-jsx": "^1.0.0",
6765
"@vue/compiler-sfc": "^3.0.2",

test/functional.js

Lines changed: 17 additions & 6 deletions
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(
@@ -427,15 +429,15 @@ describe('Functional tests using webpack', function() {
427429
]);
428430

429431
webpackAssert.assertOutputFileContains(
430-
'styles.79943add.css',
432+
'styles.[hash:8].css',
431433
'font-size: 50px;'
432434
);
433435
webpackAssert.assertManifestPathDoesNotExist(
434436
'styles.js'
435437
);
436438
webpackAssert.assertManifestPath(
437439
'styles.css',
438-
'/styles.79943add.css'
440+
'/styles.[hash:8].css'
439441
);
440442

441443
done();
@@ -466,7 +468,7 @@ describe('Functional tests using webpack', function() {
466468
);
467469
webpackAssert.assertManifestPath(
468470
'styles.css',
469-
'/styles.css?79943addbc894efe'
471+
'/styles.css?[hash:16]'
470472
);
471473

472474
done();
@@ -535,7 +537,7 @@ describe('Functional tests using webpack', function() {
535537
]);
536538

537539
webpackAssert.assertOutputFileContains(
538-
'bg.2eff0999.css',
540+
'bg.[hash:8].css',
539541
'/build/images/symfony_logo.91beba37.png'
540542
);
541543

@@ -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');
@@ -1930,13 +1940,14 @@ module.exports = {
19301940
'main.js',
19311941
'main.css',
19321942
'manifest.json',
1943+
'node_modules_symfony_mock-module_dist_controller_js.js',
19331944
'entrypoints.json',
19341945
'runtime.js',
19351946
]);
19361947

19371948
// test controllers and style are shipped
19381949
webpackAssert.assertOutputFileContains('main.js', 'app-controller');
1939-
webpackAssert.assertOutputFileContains('main.js', 'mock-module-controller');
1950+
webpackAssert.assertOutputFileContains('node_modules_symfony_mock-module_dist_controller_js.js', 'mock-module-controller');
19401951
webpackAssert.assertOutputFileContains('main.css', 'body {}');
19411952

19421953
done();

0 commit comments

Comments
 (0)