From 295e7c136845273a12df6bacf288f8eb134b2d87 Mon Sep 17 00:00:00 2001 From: Norbert Csaba Herczeg Date: Thu, 9 Mar 2023 12:51:38 +0100 Subject: [PATCH] JNG-4613 fix missing importmaps and sourcemaps (#23) * JNG-4613 add missing import maps * JNG-4613 add copy missing source maps * JNG-4613 tidy rollup util code --- .../src/main/resources/actor/inventory.json | 3 +++ .../resources/actor/rollup/html-template.mjs | 1 + .../src/main/resources/actor/rollup/utils.mjs | 27 ++++++++++++------- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/judo-ui-react/src/main/resources/actor/inventory.json b/judo-ui-react/src/main/resources/actor/inventory.json index 6f500b1f..b4317621 100644 --- a/judo-ui-react/src/main/resources/actor/inventory.json +++ b/judo-ui-react/src/main/resources/actor/inventory.json @@ -89,6 +89,9 @@ "react-is": { "umd/react-is.min.js": {"tags": ["importMap", "external"], "exports": "react-is"} }, + "react-oidc-context": { + "umd/react-oidc-context.min.js": {"tags": ["importMap", "external"], "exports": "react-oidc-context"} + }, "react-router": { "dist/umd/react-router.production.min.js": {"tags": ["importMap", "npm"], "exports": "react-router"} }, diff --git a/judo-ui-react/src/main/resources/actor/rollup/html-template.mjs b/judo-ui-react/src/main/resources/actor/rollup/html-template.mjs index 14d71014..2f09316a 100644 --- a/judo-ui-react/src/main/resources/actor/rollup/html-template.mjs +++ b/judo-ui-react/src/main/resources/actor/rollup/html-template.mjs @@ -49,6 +49,7 @@ export const template = async ({ attributes, files, meta, publicPath, title, inv ${metas} + ${title} diff --git a/judo-ui-react/src/main/resources/actor/rollup/utils.mjs b/judo-ui-react/src/main/resources/actor/rollup/utils.mjs index 123a275d..f168f553 100644 --- a/judo-ui-react/src/main/resources/actor/rollup/utils.mjs +++ b/judo-ui-react/src/main/resources/actor/rollup/utils.mjs @@ -1,4 +1,4 @@ -import {readFileSync, readdirSync} from 'node:fs'; +import {readFileSync, readdirSync, existsSync} from 'node:fs'; import {normalize, join} from 'node:path'; const dependencyCache = {}; @@ -61,22 +61,31 @@ export function createImportMap(inventory) { export function copyTasks(inventory, prefix = 'dist/externals/') { const tasks = []; + const mapSuffix = '.map'; + const isMinifiedJS = /\.min\.[m|c]?js$/; for (const packageName in inventory) { for (const fileName in inventory[packageName]) { const f = inventory[packageName][fileName]; const targetSuffix = fileName.includes('/') ? '/' + fileName.substring(0, fileName.lastIndexOf('/')) : ''; + const dest = `${prefix}${packageName}@${f.version}${targetSuffix}`; + if (f.tags.includes('npm')) { - tasks.push({ - src: `node_modules/${packageName}/${fileName}`, - dest: `${prefix}${packageName}@${f.version}${targetSuffix}`, - }); + const src = `node_modules/${packageName}/${fileName}`; + tasks.push({ src, dest }); + + if (fileName.match(isMinifiedJS) && existsSync(src + mapSuffix)) { + tasks.push({ src: src + mapSuffix, dest }); + } } + if (f.tags.includes('external')) { - tasks.push({ - src: `externals/` + packageName + '@' + f.version + '/' + fileName, - dest: `${prefix}${packageName}@${f.version}${targetSuffix}`, - }); + const src = `externals/${packageName}@${f.version}/${fileName}`; + tasks.push({ src, dest }); + + if (fileName.match(isMinifiedJS) && existsSync(src + mapSuffix)) { + tasks.push({ src: src + mapSuffix, dest }); + } } } }