Skip to content

angular: drop browser-sync-webpack-plugin support for non microfrontends #28337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions generators/angular/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,13 @@ exports[`generator - angular gateway-jwt-skipUserManagement(true)-withAdminUi(fa
"dependencies": {},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
Expand Down Expand Up @@ -1645,7 +1643,6 @@ exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDepend
},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"folder-hash": null,
Expand All @@ -1655,7 +1652,6 @@ exports[`generator - angular gateway-oauth2-withAdminUi(true)-skipJhipsterDepend
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
Expand Down Expand Up @@ -2349,18 +2345,24 @@ exports[`generator - angular microservice-jwt-skipUserManagement(false)-withAdmi
"dependencies": {},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
{
"devDependencies": {
"browser-sync-webpack-plugin": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
},
},
],
}
`;
Expand Down Expand Up @@ -3059,7 +3061,6 @@ exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterD
},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"folder-hash": null,
Expand All @@ -3069,10 +3070,17 @@ exports[`generator - angular microservice-oauth2-withAdminUi(true)-skipJhipsterD
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
{
"devDependencies": {
"browser-sync-webpack-plugin": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
},
},
],
}
`;
Expand Down Expand Up @@ -4172,7 +4180,6 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(
},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"folder-hash": null,
Expand All @@ -4182,7 +4189,6 @@ exports[`generator - angular monolith-jwt-skipUserManagement(false)-withAdminUi(
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
Expand Down Expand Up @@ -4862,15 +4868,13 @@ exports[`generator - angular monolith-oauth2-withAdminUi(false)-skipJhipsterDepe
"dependencies": {},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
Expand Down Expand Up @@ -5559,15 +5563,13 @@ exports[`generator - angular monolith-session-skipUserManagement(true)-withAdmin
"dependencies": {},
"devDependencies": {
"@angular-builders/custom-webpack": null,
"browser-sync-webpack-plugin": null,
"copy-webpack-plugin": null,
"eslint-webpack-plugin": null,
"webpack-bundle-analyzer": null,
"webpack-merge": null,
"webpack-notifier": null,
},
"overrides": {
"browser-sync": "BROWSER_SYNC_VERSION",
"webpack": "WEBPACK_VERSION",
},
},
Expand Down
15 changes: 12 additions & 3 deletions generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class AngularGenerator extends BaseApplicationGenerator<DefaultTa
};
}

if (application.clientRootDir) {
if (application.clientRootDir && application.microfrontend) {
// Overrides only works if added in root package.json
this.packageJson.merge({
overrides: {
Expand Down Expand Up @@ -324,7 +324,6 @@ export default class AngularGenerator extends BaseApplicationGenerator<DefaultTa
: {},
devDependencies: {
'@angular-builders/custom-webpack': null,
'browser-sync-webpack-plugin': null,
'copy-webpack-plugin': null,
'eslint-webpack-plugin': null,
'webpack-bundle-analyzer': null,
Expand All @@ -333,10 +332,20 @@ export default class AngularGenerator extends BaseApplicationGenerator<DefaultTa
...(enableTranslation ? { 'folder-hash': null, 'merge-jsons-webpack-plugin': null } : {}),
},
overrides: {
'browser-sync': nodeDependencies['browser-sync'],
webpack: nodeDependencies.webpack,
},
});

if (application.microfrontend) {
source.mergeClientPackageJson!({
devDependencies: {
'browser-sync-webpack-plugin': null,
},
overrides: {
'browser-sync': nodeDependencies['browser-sync'],
},
});
}
}
},
addWebsocketDependencies({ application, source }) {
Expand Down
5 changes: 5 additions & 0 deletions generators/angular/templates/webpack/webpack.custom.js.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const path = require('path');
const { hashElement } = require('folder-hash');
const MergeJsonWebpackPlugin = require('merge-jsons-webpack-plugin');
<%_ } _%>
<%_ if (microfrontend) { _%>
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
<%_ } _%>
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const WebpackNotifierPlugin = require('webpack-notifier');
const CopyWebpackPlugin = require('copy-webpack-plugin');
Expand All @@ -32,6 +34,7 @@ const ESLintPlugin = require('eslint-webpack-plugin');
const environment = require('./environment');
const proxyConfig = require('./proxy.conf');

// eslint-disable-next-line no-unused-vars
module.exports = async (config, options, targetOptions) => {
<%_ if (enableTranslation) { _%>
const languagesHash = await hashElement(path.resolve(__dirname, '<%= this.relativeDir(clientRootDir + 'webpack/', clientSrcDir) %>i18n'), {
Expand Down Expand Up @@ -60,6 +63,7 @@ module.exports = async (config, options, targetOptions) => {
if (config.devServer) {
config.devServer.proxy = proxyConfig({ tls });
}
<%_ if (microfrontend) { _%>

if (targetOptions.target === 'serve' || config.watch) {
config.plugins.push(
Expand Down Expand Up @@ -102,6 +106,7 @@ module.exports = async (config, options, targetOptions) => {
),
);
}
<%_ } _%>

if (config.mode === 'production') {
config.plugins.push(
Expand Down
4 changes: 2 additions & 2 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ exports[`generator - app with default config should match snapshot 1`] = `
"devLiquibaseUrl": "jdbc:postgresql://localhost:5432/jhipster",
"devR2dbcUrl": undefined,
"devServerPort": 4200,
"devServerPortProxy": 9000,
"devServerPortProxy": undefined,
"dockerContainers": {
"apache/kafka-native": "apache-kafka-native-placeholder",
"apachepulsar/pulsar": "apachepulsar-pulsar-placeholder",
Expand Down Expand Up @@ -998,7 +998,7 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"devLiquibaseUrl": "jdbc:postgresql://localhost:5432/jhipster",
"devR2dbcUrl": "r2dbc:postgresql://localhost:5432/jhipster",
"devServerPort": 4200,
"devServerPortProxy": 9000,
"devServerPortProxy": undefined,
"dockerContainers": {
"apache/kafka-native": "apache-kafka-native-placeholder",
"apachepulsar/pulsar": "apachepulsar-pulsar-placeholder",
Expand Down
8 changes: 4 additions & 4 deletions generators/kubernetes/__snapshots__/kubernetes.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3536,15 +3536,15 @@ data:
"redirectUris": [
"http://jhgate.default.example.com/*",
"https://jhgate.default.example.com/*", "http://localhost:8080/*",
"https://localhost:8080/*","http://localhost:4200/*", "http://localhost:9000/*",
"https://localhost:8080/*","http://localhost:4200/*",
"http://localhost:8100/*",
"http://127.0.0.1:8761/*",
"dev.localhost.ionic:*"
],
"webOrigins": [
"http://jhgate.default.example.com",
"https://jhgate.default.example.com", "http://localhost:8080",
"https://localhost:8080","http://localhost:4200", "http://localhost:9000",
"https://localhost:8080","http://localhost:4200",
"http://localhost:8100",
"http://127.0.0.1:8761"
],
Expand Down Expand Up @@ -6969,15 +6969,15 @@ data:
"redirectUris": [
"http://jhgate.default.example.com/*",
"https://jhgate.default.example.com/*", "http://localhost:8080/*",
"https://localhost:8080/*","http://localhost:4200/*", "http://localhost:9000/*",
"https://localhost:8080/*","http://localhost:4200/*",
"http://localhost:8100/*",
"http://127.0.0.1:8761/*",
"dev.localhost.ionic:*"
],
"webOrigins": [
"http://jhgate.default.example.com",
"https://jhgate.default.example.com", "http://localhost:8080",
"https://localhost:8080","http://localhost:4200", "http://localhost:9000",
"https://localhost:8080","http://localhost:4200",
"http://localhost:8100",
"http://127.0.0.1:8761"
],
Expand Down
13 changes: 8 additions & 5 deletions generators/workspaces/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,22 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator {

if (applications.some(app => app.clientFrameworkAngular)) {
const {
dependencies: { rxjs },
devDependencies: { webpack: webpackVersion, 'browser-sync': browserSyncVersion },
} = this.fs.readJSON(this.fetchFromInstalledJHipster(GENERATOR_ANGULAR, 'resources', 'package.json'));

this.packageJson.merge({
devDependencies: {
rxjs, // Set version to workaround https://github.com/npm/cli/issues/4437
},
overrides: {
'browser-sync': browserSyncVersion,
webpack: webpackVersion,
},
});

if (applications.some(app => app.microfrontend)) {
this.packageJson.merge({
overrides: {
'browser-sync': browserSyncVersion,
},
});
}
}

if (applications.some(app => app.backendTypeJavaAny)) {
Expand Down
5 changes: 3 additions & 2 deletions lib/jhipster/default-application-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function getConfigForClientApplication(options: ApplicationDefaults = {})
return options;
}
if (options[OptionNames.MICROFRONTEND] === undefined) {
options[OptionNames.MICROFRONTEND] = Boolean(options[OptionNames.MICROFRONTENDS]?.length);
options[OptionNames.MICROFRONTEND] = Boolean(options[OptionNames.MICROFRONTENDS]?.length) || options.applicationType === 'microservice';
}
if (!options[CLIENT_THEME]) {
options[CLIENT_THEME] = OptionValues[CLIENT_THEME];
Expand All @@ -130,7 +130,8 @@ export function getConfigForClientApplication(options: ApplicationDefaults = {})
} else {
options.devServerPort ??= 9060;
}
options.devServerPortProxy ??= options.clientBundler === 'webpack' ? 9000 : undefined;
options.devServerPortProxy ??=
options.clientBundler === 'webpack' && (clientFramework !== 'angular' || options.microfrontend) ? 9000 : undefined;

return options;
}
Expand Down
Loading