Skip to content
18 changes: 2 additions & 16 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,25 +411,11 @@ module.exports = function (grunt) {
stdout: false,
},
fixCryptoApiImports: {
command: function () {
switch (process.platform) {
case "darwin":
return `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 sed -i '' -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'`;
default:
return `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 sed -i -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'`;
}
},
command: `node ${nodeFlags} src/core/config/scripts/fixCryptoApiImports.mjs`,
stdout: false
},
fixSnackbarMarkup: {
command: function () {
switch (process.platform) {
case "darwin":
return `sed -i '' 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`;
default:
return `sed -i 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js`;
}
},
command: `node ${nodeFlags} src/core/config/scripts/fixSnackBarMarkup.mjs`,
stdout: false
},
},
Expand Down
54 changes: 54 additions & 0 deletions src/core/config/scripts/fixCryptoApiImports.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* This script updates crypto-api package
* It adds .mjs to local imports where its missing
*
* before:
* import foo from "./bar";
* after
* import foo from "./bar.mjs";
*
*/

/* eslint no-console: ["off"] */

import { readdirSync, readFileSync, writeFileSync } from "fs";
import { join } from "path";

// Base directory of crypto-api source
const baseDir = join(process.cwd(), "node_modules/crypto-api/src");

/**
* Recursively walk a directory, updating import statements
* to include ".mjs" if missing
*/
function walk(dir) {
const entries = readdirSync(dir, { withFileTypes: true });

for (const entry of entries) {
if (entry.name === ".git") continue;

const fullPath = join(dir, entry.name);

if (entry.isDirectory()) {
walk(fullPath);
} else if (entry.isFile()) {
const content = readFileSync(fullPath, "utf8");

// Add .mjs to imports if not present
const updated = content.replace(
/from "(\.[^"]*)";/g,
(match, p1) => {
if (p1.endsWith(".mjs")) return match;
return `from "${p1}.mjs";`;
}
);

if (updated !== content) {
writeFileSync(fullPath, updated, "utf8");
}
}
}
}

// Run the walker
walk(baseDir);
28 changes: 28 additions & 0 deletions src/core/config/scripts/fixSnackBarMarkup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* This script updates snackbarjs package
* Replaces self-closing div with standard opening div
*
* before:
* <div id=snackbar-container/>
* after:
* <div id=snackbar-container>
*
*/

/* eslint no-console: ["off"] */

import { readFileSync, writeFileSync } from "fs";
import { join } from "path";

// Base directory of snackbarjs source
const filePath = join(process.cwd(), "node_modules/snackbarjs/src/snackbar.js");

const content = readFileSync(filePath, "utf8");

// Replace self-closing div with standard opening div
const updated = content.replace(
/<div id=snackbar-container\/>/g,
"<div id=snackbar-container>"
);

writeFileSync(filePath, updated, "utf8");
Loading