@zgeoff/testing 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createStubSudo(directory: string, record: string): Promise<void>;
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createBlockingStubKit } from './create-blocking-stub-kit.ts';
|
|
2
2
|
export { createGitCommit } from './create-git-commit.ts';
|
|
3
|
+
export { createStubSudo } from './create-stub-sudo.ts';
|
|
3
4
|
export { makeAnswerQueue } from './make-answer-queue.ts';
|
|
4
5
|
export { makeRepeatingAnswerQueue } from './make-repeating-answer-queue.ts';
|
|
5
6
|
export { makeRejectingStub } from './make-rejecting-stub.ts';
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { chmod, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
|
|
4
|
+
// Writes a stand-in for sudo into the folder. It answers the probe `sudo -n true` with success. Any
|
|
5
|
+
// other call appends a line per argument to the record, `file <argument>` when the argument names a
|
|
6
|
+
// file that exists and `text <argument>` otherwise, then fails as a command that never starts does.
|
|
7
|
+
export async function createStubSudo(directory: string, record: string): Promise<void> {
|
|
8
|
+
const path = join(directory, 'sudo');
|
|
9
|
+
|
|
10
|
+
await writeFile(
|
|
11
|
+
path,
|
|
12
|
+
[
|
|
13
|
+
'#!/bin/bash',
|
|
14
|
+
`[ "$*" = '-n true' ] && exit 0`,
|
|
15
|
+
'for argument in "$@"; do',
|
|
16
|
+
' if [ -f "$argument" ]; then kind=file; else kind=text; fi',
|
|
17
|
+
` printf '%s %s\\n' "$kind" "$argument" >> '${record.replaceAll("'", String.raw`'\''`)}'`,
|
|
18
|
+
'done',
|
|
19
|
+
'exit 1',
|
|
20
|
+
'',
|
|
21
|
+
].join('\n'),
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
await chmod(path, 0o755);
|
|
25
|
+
}
|
package/src/helpers/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { createBlockingStubKit } from './create-blocking-stub-kit.ts';
|
|
2
2
|
export { createGitCommit } from './create-git-commit.ts';
|
|
3
|
+
export { createStubSudo } from './create-stub-sudo.ts';
|
|
3
4
|
export { makeAnswerQueue } from './make-answer-queue.ts';
|
|
4
5
|
export { makeRepeatingAnswerQueue } from './make-repeating-answer-queue.ts';
|
|
5
6
|
export { makeRejectingStub } from './make-rejecting-stub.ts';
|