From 182100f8bf91580ebf2fcaef83edc9d788f0515f Mon Sep 17 00:00:00 2001 From: Diana Catalina Olarte Date: Sun, 4 Aug 2024 20:18:32 +1000 Subject: [PATCH] fix: allow processing edx and openedx brand scope --- README.md | 2 +- config/data/paragonUtils.js | 15 +++++++++++++-- config/webpack.common.config.js | 4 ++-- config/webpack.dev.config.js | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3a03890a3..32895f41d 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ frontend-platform: dist: The sub-directory of the source code where it puts its build artifact. Often "dist". */ localModules: [ - { moduleName: '@openedx/brand', dir: '../src/brand-openedx' }, // replace with your brand checkout + { moduleName: '@edx/brand', dir: '../src/brand-openedx' }, // replace with your brand checkout { moduleName: '@openedx/paragon/scss/core', dir: '../src/paragon', dist: 'scss/core' }, { moduleName: '@openedx/paragon/icons', dir: '../src/paragon', dist: 'icons' }, { moduleName: '@openedx/paragon', dir: '../src/paragon', dist: 'dist' }, diff --git a/config/data/paragonUtils.js b/config/data/paragonUtils.js index 26253997e..c48f6c3e8 100644 --- a/config/data/paragonUtils.js +++ b/config/data/paragonUtils.js @@ -1,6 +1,17 @@ const path = require('path'); const fs = require('fs'); +/** + * Retrieves the name of the brand package from the given directory. + * + * @param {string} dir - The directory path containing the package.json file. + * @return {string} The name of the brand package, or an empty string if not found. + */ +function getBrandPackageName(dir) { + const appDependencies = JSON.parse(fs.readFileSync(path.resolve(dir, 'package.json'), 'utf-8')).dependencies; + return Object.keys(appDependencies).find((key) => key.match(/@(open)?edx\/brand/)) || ''; +} + /** * Attempts to extract the Paragon version from the `node_modules` of * the consuming application. @@ -9,7 +20,7 @@ const fs = require('fs'); * @returns {string} Paragon dependency version of the consuming application */ function getParagonVersion(dir, { isBrandOverride = false } = {}) { - const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon'; + const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon'; const pathToPackageJson = `${dir}/node_modules/${npmPackageName}/package.json`; if (!fs.existsSync(pathToPackageJson)) { return undefined; @@ -44,7 +55,7 @@ function getParagonVersion(dir, { isBrandOverride = false } = {}) { * @returns {ParagonThemeCss} */ function getParagonThemeCss(dir, { isBrandOverride = false } = {}) { - const npmPackageName = isBrandOverride ? '@openedx/brand' : '@openedx/paragon'; + const npmPackageName = isBrandOverride ? getBrandPackageName(dir) : '@openedx/paragon'; const pathToParagonThemeOutput = path.resolve(dir, 'node_modules', npmPackageName, 'dist', 'theme-urls.json'); if (!fs.existsSync(pathToParagonThemeOutput)) { diff --git a/config/webpack.common.config.js b/config/webpack.common.config.js index 38f2152df..ab72d9136 100644 --- a/config/webpack.common.config.js +++ b/config/webpack.common.config.js @@ -25,8 +25,8 @@ module.exports = { /** * The entry points for the brand theme CSS. Example: ``` * { - * "paragon.theme.core": "/path/to/node_modules/@openedx/brand/dist/core.min.css", - * "paragon.theme.variants.light": "/path/to/node_modules/@openedx/brand/dist/light.min.css" + * "paragon.theme.core": "/path/to/node_modules/@(open)edx/brand/dist/core.min.css", + * "paragon.theme.variants.light": "/path/to/node_modules/@(open)edx/brand/dist/light.min.css" * } */ ...getParagonEntryPoints(brandThemeCss), diff --git a/config/webpack.dev.config.js b/config/webpack.dev.config.js index 4acb69dde..eb7eac230 100644 --- a/config/webpack.dev.config.js +++ b/config/webpack.dev.config.js @@ -109,7 +109,7 @@ module.exports = merge(commonConfig, { test: /(.scss|.css)$/, oneOf: [ { - resource: /(@openedx\/paragon|@openedx\/brand)/, + resource: /(@openedx\/paragon|@(open)?edx\/brand)/, use: [ MiniCssExtractPlugin.loader, ...getStyleUseConfig(),