From a89d4cf348f7edc0a52b8ab9aacf96f2de939de4 Mon Sep 17 00:00:00 2001 From: Kai Vandivier <49666798+KaiVandivier@users.noreply.github.com> Date: Mon, 3 Jun 2024 20:30:29 +0200 Subject: [PATCH 1/2] fix: don't start plugins for apps without a plugin entrypoint (#850) * fix: don't start plugins for apps without a plugin entrypoint * fix: don't start app when there's just a plugin entrypoint * fix: implement feedback * fix: simplify boolean logic * fix: improve message again --- cli/src/commands/start.js | 34 ++++++++++++++++++++------- cli/src/lib/generateManifests.js | 23 +----------------- cli/src/lib/getOriginalEntrypoints.js | 26 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 cli/src/lib/getOriginalEntrypoints.js diff --git a/cli/src/commands/start.js b/cli/src/commands/start.js index 6370b7651..3924f5b41 100644 --- a/cli/src/commands/start.js +++ b/cli/src/commands/start.js @@ -3,6 +3,7 @@ const detectPort = require('detect-port') const { compile } = require('../lib/compiler') const exitOnCatch = require('../lib/exitOnCatch') const generateManifests = require('../lib/generateManifests') +const { getOriginalEntrypoints } = require('../lib/getOriginalEntrypoints') const i18n = require('../lib/i18n') const loadEnvFiles = require('../lib/loadEnvFiles') const parseConfig = require('../lib/parseConfig') @@ -129,13 +130,28 @@ const handler = async ({ reporter.info('Starting development server...') // start app and/or plugin, depending on flags - const shouldStartBoth = - (!shouldStartOnlyApp && !shouldStartOnlyPlugin) || - // it would be weird to use both flags, but start both if so - (shouldStartOnlyApp && shouldStartOnlyPlugin) - const startPromises = [] - if (shouldStartBoth || shouldStartOnlyApp) { + // entryPoints.app is populated by default -- get the app's raw + // entry points from the d2.config.js file to tell if there is an + // app entrypoint configured (and fall back to the whatever we do + // have available) + const entryPoints = + getOriginalEntrypoints(paths) || config.entryPoints + + const noFlagsPassed = !shouldStartOnlyApp && !shouldStartOnlyPlugin + const shouldStartApp = + entryPoints.app && (noFlagsPassed || shouldStartOnlyApp) + const shouldStartPlugin = + entryPoints.plugin && (noFlagsPassed || shouldStartOnlyPlugin) + + if (!shouldStartApp && !shouldStartPlugin) { + throw new Error( + 'The requested app/plugin is not configured to start. Check the flags passed to the start script and the entrypoints configured in d2.config.js, then try again.' + ) + } + + const startPromises = [] + if (shouldStartApp) { reporter.print( `The app ${chalk.bold( config.name @@ -145,12 +161,12 @@ const handler = async ({ startPromises.push(shell.start({ port: newPort })) } - if (shouldStartBoth || shouldStartOnlyPlugin) { + if (shouldStartPlugin) { + const pluginPort = shouldStartApp ? newPort + 1 : newPort reporter.print( - `The plugin is now available on port ${newPort} at /${paths.pluginLaunchPath}` + `The plugin is now available on port ${pluginPort} at /${paths.pluginLaunchPath}` ) reporter.print('') - const pluginPort = shouldStartBoth ? newPort + 1 : newPort startPromises.push(plugin.start({ port: pluginPort })) } diff --git a/cli/src/lib/generateManifests.js b/cli/src/lib/generateManifests.js index 6ba6db624..21287b25f 100644 --- a/cli/src/lib/generateManifests.js +++ b/cli/src/lib/generateManifests.js @@ -1,28 +1,7 @@ const { reporter, chalk } = require('@dhis2/cli-helpers-engine') const fs = require('fs-extra') +const { getOriginalEntrypoints } = require('./getOriginalEntrypoints') -/** - * Gets the original `entrypoints` property in d2.config.js - * without applying defaults. Used to detect if there is actually - * supposed to be an app entrypoint for this... app. Temporary until - * the build process is redesigned to allow building plugins without - * apps (LIBS-479) - */ -const getOriginalEntrypoints = (paths) => { - try { - if (fs.existsSync(paths.config)) { - reporter.debug('Loading d2 config at', paths.config) - // NB: this import can be confounded by previous object mutations - const originalConfig = require(paths.config) - reporter.debug('loaded', originalConfig) - return originalConfig.entryPoints // may be undefined - } - } catch (e) { - reporter.error('Failed to load d2 config!') - reporter.error(e) - process.exit(1) - } -} const parseCustomAuthorities = (authorities) => { if (!authorities) { return undefined diff --git a/cli/src/lib/getOriginalEntrypoints.js b/cli/src/lib/getOriginalEntrypoints.js new file mode 100644 index 000000000..5efa0a48d --- /dev/null +++ b/cli/src/lib/getOriginalEntrypoints.js @@ -0,0 +1,26 @@ +const { reporter } = require('@dhis2/cli-helpers-engine') +const fs = require('fs-extra') + +/** + * Gets the original `entrypoints` property in d2.config.js + * without applying defaults. Used to detect if there is actually + * supposed to be an app entrypoint for this... app. Temporary until + * the build process is redesigned to allow building plugins without + * apps (LIBS-479) + */ +const getOriginalEntrypoints = (paths) => { + try { + if (fs.existsSync(paths.config)) { + reporter.debug('Loading d2 config at', paths.config) + // NB: this import can be confounded by previous object mutations + const originalConfig = require(paths.config) + reporter.debug('loaded', originalConfig) + return originalConfig.entryPoints // may be undefined + } + } catch (e) { + reporter.error('Failed to load d2 config!') + reporter.error(e) + process.exit(1) + } +} +exports.getOriginalEntrypoints = getOriginalEntrypoints From b672fb1bc34fc3c4598b453c2b2586de71f42cfa Mon Sep 17 00:00:00 2001 From: "@dhis2-bot" Date: Mon, 3 Jun 2024 18:44:51 +0000 Subject: [PATCH 2/2] chore(release): cut 11.3.1 [skip release] ## [11.3.1](https://github.com/dhis2/app-platform/compare/v11.3.0...v11.3.1) (2024-06-03) ### Bug Fixes * don't start plugins for apps without a plugin entrypoint ([#850](https://github.com/dhis2/app-platform/issues/850)) ([a89d4cf](https://github.com/dhis2/app-platform/commit/a89d4cf348f7edc0a52b8ab9aacf96f2de939de4)) --- CHANGELOG.md | 7 +++++++ adapter/package.json | 6 +++--- cli/package.json | 4 ++-- examples/pwa-app/package.json | 2 +- examples/simple-app/package.json | 2 +- package.json | 2 +- pwa/package.json | 4 ++-- shell/package.json | 6 +++--- 8 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5950cc81e..c3a00df95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [11.3.1](https://github.com/dhis2/app-platform/compare/v11.3.0...v11.3.1) (2024-06-03) + + +### Bug Fixes + +* don't start plugins for apps without a plugin entrypoint ([#850](https://github.com/dhis2/app-platform/issues/850)) ([a89d4cf](https://github.com/dhis2/app-platform/commit/a89d4cf348f7edc0a52b8ab9aacf96f2de939de4)) + # [11.3.0](https://github.com/dhis2/app-platform/compare/v11.2.2...v11.3.0) (2024-05-30) diff --git a/adapter/package.json b/adapter/package.json index 733c6fae1..f2c5a1d33 100644 --- a/adapter/package.json +++ b/adapter/package.json @@ -1,6 +1,6 @@ { "name": "@dhis2/app-adapter", - "version": "11.3.0", + "version": "11.3.1", "repository": { "type": "git", "url": "https://github.com/amcgee/dhis2-app-platform", @@ -21,11 +21,11 @@ "build" ], "dependencies": { - "@dhis2/pwa": "11.3.0", + "@dhis2/pwa": "11.3.1", "moment": "^2.24.0" }, "devDependencies": { - "@dhis2/cli-app-scripts": "11.3.0", + "@dhis2/cli-app-scripts": "11.3.1", "@testing-library/react": "^12.0.0", "@testing-library/react-hooks": "^8.0.1", "enzyme": "^3.11.0", diff --git a/cli/package.json b/cli/package.json index 207000953..e41b55777 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@dhis2/cli-app-scripts", - "version": "11.3.0", + "version": "11.3.1", "engines": { "node": ">=14" }, @@ -28,7 +28,7 @@ "@babel/preset-env": "^7.14.7", "@babel/preset-react": "^7.0.0", "@babel/preset-typescript": "^7.6.0", - "@dhis2/app-shell": "11.3.0", + "@dhis2/app-shell": "11.3.1", "@dhis2/cli-helpers-engine": "^3.2.0", "@jest/core": "^27.0.6", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.4", diff --git a/examples/pwa-app/package.json b/examples/pwa-app/package.json index a509a7ef1..369ee7e76 100644 --- a/examples/pwa-app/package.json +++ b/examples/pwa-app/package.json @@ -1,6 +1,6 @@ { "name": "pwa-app", - "version": "11.3.0", + "version": "11.3.1", "description": "", "license": "BSD-3-Clause", "private": true, diff --git a/examples/simple-app/package.json b/examples/simple-app/package.json index b144a72cf..83642b95f 100644 --- a/examples/simple-app/package.json +++ b/examples/simple-app/package.json @@ -1,6 +1,6 @@ { "name": "simple-app", - "version": "11.3.0", + "version": "11.3.1", "repository": "https://github.com/amcgee/dhis2-app-platform", "author": "Austin McGee ", "license": "BSD-3-Clause", diff --git a/package.json b/package.json index b808378ca..4b8f90bec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "root", - "version": "11.3.0", + "version": "11.3.1", "private": true, "repository": { "type": "git", diff --git a/pwa/package.json b/pwa/package.json index 05eb364e4..93f36ed1e 100644 --- a/pwa/package.json +++ b/pwa/package.json @@ -1,6 +1,6 @@ { "name": "@dhis2/pwa", - "version": "11.3.0", + "version": "11.3.1", "description": "", "license": "BSD-3-Clause", "publishConfig": { @@ -13,7 +13,7 @@ "deploy": "d2-app-scripts deploy" }, "devDependencies": { - "@dhis2/cli-app-scripts": "11.3.0" + "@dhis2/cli-app-scripts": "11.3.1" }, "dependencies": { "idb": "^6.0.0", diff --git a/shell/package.json b/shell/package.json index fd94e8c92..7807752aa 100644 --- a/shell/package.json +++ b/shell/package.json @@ -1,6 +1,6 @@ { "name": "@dhis2/app-shell", - "version": "11.3.0", + "version": "11.3.1", "engines": { "node": ">=14" }, @@ -15,10 +15,10 @@ "access": "public" }, "dependencies": { - "@dhis2/app-adapter": "11.3.0", + "@dhis2/app-adapter": "11.3.1", "@dhis2/app-runtime": "^3.10.4", "@dhis2/d2-i18n": "^1.1.1", - "@dhis2/pwa": "11.3.0", + "@dhis2/pwa": "11.3.1", "@dhis2/ui": "^9.4.4", "classnames": "^2.2.6", "moment": "^2.29.1",