Skip to content

Commit b2a7540

Browse files
authored
chore: Better accommodate non-GNU sed (#10482)
## Description Always use `sed -i …` vs. `sed -i ''` as appropriate, with a `sedi` function or alias where possible. ### Security Considerations n/a ### Scaling Considerations n/a ### Documentation Considerations n/a ### Testing Considerations I haven't found a practical way to test this, so it might go stale—but if so, it's only in development/build tooling so it can be fixed again if that happens. ### Upgrade Considerations n/a
1 parent 1682675 commit b2a7540

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

MAINTAINERS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ For each set of changes to include after the base branch point:
9595
- If encountering a commit with conflicts that do not have a straightforward resolution, check if picking any prior commit would help resolve the conflicts.
9696
- Abort the rebase, update the authored `rebase-todo`, and restart the interactive rebase.
9797
- Avoid authoring manual changes unless absolutely necessary. If authoring changes, keep them as separate commits and indicate them as such on the authored rebase todo (insert either a `pick` instruction with the id of the commit you just authored or an `exec` instruction that makes the modifications and ends with `git commit -m $message`, in either case prefixing with an explanatory `##` comment).
98-
- For `exec`, make portable in-place edits with either `ed` or `alias sed-i="sed -i $(sed --help 2>&1 | sed 2q | grep -qe '-i ' && echo "''")"`, e.g. `printf 'H\n/\( *\)foo/ s##\\1// prettier-ignore\\\n&#\nw\n' | ed -s packages/path/to/file'` or `sed-i -E "$(printf 's#( *)foo#\\1// prettier-ignore\\\n&#')" packages/path/to/file`.
98+
- For `exec`, make portable in-place edits with either `ed` or `alias sedi="sed -i $(sed --help 2>&1 | sed 2q | grep -qe '-i ' && echo "''")"`, e.g. `printf 'H\n/\( *\)foo/ s##\\1// prettier-ignore\\\n&#\nw\n' | ed -s packages/path/to/file'` or `sedi -E "$(printf 's#( *)foo#\\1// prettier-ignore\\\n&#')" packages/path/to/file`.
9999
- If a commit is empty, skip it and comment it out in the rebase todo.
100100
- [ ] Verify that tests pass. In particular:
101101
- Linting locally can catch incompatibilities in the cherry-pick, often requiring some changes to be reverted or more commits from `master` to be included. In those cases, update the authored `rebase-todo`, and redo the interactive rebase as necessary.

packages/cosmic-proto/scripts/codegen.cjs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22
/* eslint-env node */
3-
const { exec, spawnSync } = require('child_process');
3+
const { exec, execSync, spawnSync } = require('child_process');
44
const path = require('path');
55
const process = require('process');
66
const telescope = require('@cosmology/telescope').default;
@@ -14,11 +14,12 @@ rimraf(outPath);
1414
* Make the JsonSafe type import compatible with TS verbatimImportSyntax
1515
*
1616
* @param {string} directory
17+
* @param {boolean} gnuSed
1718
*/
18-
function fixTypeImport(directory) {
19+
function fixTypeImport(directory, gnuSed) {
1920
const fullPath = path.resolve(directory);
2021
const command = `
21-
find ${fullPath} -type f -exec sed -i '' \
22+
find ${fullPath} -type f -exec ${gnuSed ? 'sed -i' : 'sed -i ""'} \
2223
-e 's/import { JsonSafe/import {type JsonSafe/g' \
2324
-e 's/\\([{,]\\) \\([[:alnum:]_]*SDKType\\)/\\1 type \\2/g' {} +
2425
`;
@@ -127,7 +128,11 @@ telescope({
127128
console.log('🔨 code generated by Telescope');
128129

129130
// for all files under codegen/ replace "import { JsonSafe" with "import type { JsonSafe"
130-
fixTypeImport('./src/codegen');
131+
const gnuSed =
132+
execSync(`sed --help 2>&1 | sed 2q | grep -qe '-i ' || printf gnu`, {
133+
encoding: 'utf8',
134+
}) === 'gnu';
135+
fixTypeImport('./src/codegen', gnuSed);
131136
console.log('🔧 type keyword added');
132137

133138
spawnSync('yarn', ['prettier', '--write', 'src'], {

packages/cosmic-swingset/scripts/single-node.sh

+1-12
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,7 @@ $DAEMON gentx --name validator $STAKE --keyring-backend="test"
2929
$DAEMON collect-gentxs
3030

3131
# Silly old Darwin
32-
case $(sed --help 2>&1 | sed -n 2p) in
33-
"usage: sed script"*"[-i extension]"*)
34-
sedi() {
35-
sed -i '' ${1+"$@"}
36-
}
37-
;;
38-
*)
39-
sedi() {
40-
sed -i ${1+"$@"}
41-
}
42-
;;
43-
esac
32+
alias sedi="sed -i $(sed --help 2>&1 | sed 2q | grep -qe '-i ' && echo "''")"
4433

4534
case $DAEMON in
4635
ag-chain-cosmos)

0 commit comments

Comments
 (0)