Skip to content

Commit

Permalink
JNG-4613 fix missing importmaps and sourcemaps (#23)
Browse files Browse the repository at this point in the history
* JNG-4613 add missing import maps

* JNG-4613 add copy missing source maps

* JNG-4613 tidy rollup util code
  • Loading branch information
noherczeg authored Mar 9, 2023
1 parent 4ecb42e commit 295e7c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions judo-ui-react/src/main/resources/actor/inventory.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const template = async ({ attributes, files, meta, publicPath, title, inv
<html${makeHtmlAttributes(attributes.html)}>
<head>
${metas}
<base href="/">
<link rel="icon" href="favicon.ico" />
<link rel="apple-touch-icon" href="logo192.png" />
<title>${title}</title>
Expand Down
27 changes: 18 additions & 9 deletions judo-ui-react/src/main/resources/actor/rollup/utils.mjs
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down Expand Up @@ -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 });
}
}
}
}
Expand Down

0 comments on commit 295e7c1

Please sign in to comment.