Rewriting fixCryptoApiImports and fixSnackbarMarkup to js to make it OS agnostic (#2298)
This commit is contained in:
parent
2eb8810bf6
commit
f646065c36
18
Gruntfile.js
18
Gruntfile.js
@ -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
|
||||
},
|
||||
},
|
||||
|
||||
54
src/core/config/scripts/fixCryptoApiImports.mjs
Normal file
54
src/core/config/scripts/fixCryptoApiImports.mjs
Normal file
@ -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
src/core/config/scripts/fixSnackBarMarkup.mjs
Normal file
28
src/core/config/scripts/fixSnackBarMarkup.mjs
Normal file
@ -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…
x
Reference in New Issue
Block a user