@@ -9,14 +9,21 @@ const cp = require("node:child_process");
9
9
10
10
const nodeFlags = "--experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings --no-deprecation" ;
11
11
12
- // Prepare platform-dependent commands
12
+ // Define platform-dependent commands
13
+ const pcmd = {
14
+ // Older MacOS versions don't come with `sha256sum`, but they all come with `shasum`
15
+ sha256sum : process . platform === "darwin" ? "shasum -a 256" : "sha256sum" ,
13
16
14
- // Older MacOS versions don't come with `sha256sum`, but they all come with `shasum`
15
- const sha256sumCmd = process . platform === "darwin" ? "shasum -a 256" : "sha256sum" ;
16
-
17
- // MacOS (and FreeBSD, but not OpenBSD) require an argument to `-i`.
18
- // However, users may have installed GNU sed, so let's check what `sed` says itself.
19
- const sedCmd = cp . execSync ( "sed -i 2>&1 | head -n1" ) . toString ( ) . includes ( "option requires an argument" ) ? "sed -i ''" : "sed -i" ;
17
+ // MacOS (and FreeBSD, but not OpenBSD) require an argument to `-i`.
18
+ // However, users may have installed GNU sed, so let's check what `sed` says itself.
19
+ // NB: using a lazy, memoized getter so this is only executed at most once, upon first access.
20
+ get sed ( ) {
21
+ delete this . sed ;
22
+ return this . sed = (
23
+ cp . execSync ( "sed -i 2>&1 | head -n1" ) . toString ( ) . includes ( "option requires an argument" ) ? "sed -i ''" : "sed -i"
24
+ ) ;
25
+ }
26
+ } ;
20
27
21
28
/**
22
29
* Grunt configuration for building the app in various formats.
@@ -340,8 +347,8 @@ module.exports = function (grunt) {
340
347
exec : {
341
348
calcDownloadHash : {
342
349
command : chainCommands ( [
343
- `${ sha256sumCmd } build/prod/CyberChef_v${ pkg . version } .zip | awk '{print $1;}' > build/prod/sha256digest.txt` ,
344
- `${ sedCmd } -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html` ,
350
+ `${ pcmd . sha256sum } build/prod/CyberChef_v${ pkg . version } .zip | awk '{print $1;}' > build/prod/sha256digest.txt` ,
351
+ `${ pcmd . sed } -e "s/DOWNLOAD_HASH_PLACEHOLDER/$(cat build/prod/sha256digest.txt)/" build/prod/index.html` ,
345
352
] ) ,
346
353
} ,
347
354
repoSize : {
@@ -411,15 +418,15 @@ module.exports = function (grunt) {
411
418
stdout : false ,
412
419
} ,
413
420
fixCryptoApiImports : {
414
- command : `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 ${ sedCmd } -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'` ,
421
+ command : `find ./node_modules/crypto-api/src/ \\( -type d -name .git -prune \\) -o -type f -print0 | xargs -0 ${ pcmd . sed } -e '/\\.mjs/!s/\\(from "\\.[^"]*\\)";/\\1.mjs";/g'` ,
415
422
stdout : false
416
423
} ,
417
424
fixSnackbarMarkup : {
418
- command : `${ sedCmd } 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js` ,
425
+ command : `${ pcmd . sed } 's/<div id=snackbar-container\\/>/<div id=snackbar-container>/g' ./node_modules/snackbarjs/src/snackbar.js` ,
419
426
stdout : false
420
427
} ,
421
428
fixJimpModule : {
422
- command : `${ sedCmd } 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json` ,
429
+ command : `${ pcmd . sed } 's/"es\\/index.js",/"es\\/index.js" ,\\n "type": "module",/' ./node_modules/jimp/package.json` ,
423
430
stdout : false
424
431
}
425
432
} ,
0 commit comments