goke 6.4.0 → 6.5.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.
- package/README.md +261 -59
- package/dist/__test__/index.test.js +80 -0
- package/dist/__test__/just-bash.test.js +128 -0
- package/dist/__test__/types.test-d.js +9 -3
- package/dist/goke-fs.d.ts +25 -0
- package/dist/goke-fs.d.ts.map +1 -0
- package/dist/goke-fs.js +4 -0
- package/dist/goke.d.ts +22 -1
- package/dist/goke.d.ts.map +1 -1
- package/dist/goke.js +25 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/just-bash.d.ts +3 -1
- package/dist/just-bash.d.ts.map +1 -1
- package/dist/just-bash.js +163 -1
- package/dist/picocolors.d.ts +55 -0
- package/dist/picocolors.d.ts.map +1 -0
- package/dist/picocolors.js +78 -0
- package/dist/runtime-browser.d.ts +5 -1
- package/dist/runtime-browser.d.ts.map +1 -1
- package/dist/runtime-browser.js +28 -1
- package/dist/runtime-node.d.ts +3 -1
- package/dist/runtime-node.d.ts.map +1 -1
- package/dist/runtime-node.js +3 -1
- package/package.json +3 -4
- package/src/__test__/index.test.ts +93 -0
- package/src/__test__/just-bash.test.ts +171 -3
- package/src/__test__/types.test-d.ts +9 -3
- package/src/goke-fs.ts +26 -0
- package/src/goke.ts +40 -5
- package/src/index.ts +1 -1
- package/src/just-bash.ts +187 -2
- package/src/picocolors.ts +140 -0
- package/src/runtime-browser.ts +35 -1
- package/src/runtime-node.ts +4 -1
|
@@ -79,6 +79,134 @@ describe('createJustBashCommand', () => {
|
|
|
79
79
|
exitCode: 0,
|
|
80
80
|
});
|
|
81
81
|
});
|
|
82
|
+
test('works through real just-bash exec with a goke custom command', async () => {
|
|
83
|
+
const { Bash } = await import('just-bash');
|
|
84
|
+
const cli = gokeTestable('parent');
|
|
85
|
+
cli
|
|
86
|
+
.command('child commandwithspaces', 'Run nested command')
|
|
87
|
+
.option('--name <name>', z.string().describe('Name'))
|
|
88
|
+
.action((options, { console }) => {
|
|
89
|
+
console.log(`hello ${options.name}`);
|
|
90
|
+
});
|
|
91
|
+
const bash = new Bash({
|
|
92
|
+
customCommands: [await cli.createJustBashCommand()],
|
|
93
|
+
});
|
|
94
|
+
const result = await bash.exec('parent child commandwithspaces --name Tommy');
|
|
95
|
+
expect(result.stdout).toBe('hello Tommy\n');
|
|
96
|
+
expect(result.stderr).toBe('');
|
|
97
|
+
expect(result.exitCode).toBe(0);
|
|
98
|
+
});
|
|
99
|
+
test('maps injected fs to the just-bash virtual filesystem', async () => {
|
|
100
|
+
const { Bash } = await import('just-bash');
|
|
101
|
+
const cli = gokeTestable('parent');
|
|
102
|
+
cli
|
|
103
|
+
.command('login', 'Persist login state')
|
|
104
|
+
.option('--token <token>', z.string().describe('Token'))
|
|
105
|
+
.action(async (options, { fs, console }) => {
|
|
106
|
+
await fs.mkdir('.mycli', { recursive: true });
|
|
107
|
+
await fs.writeFile('.mycli/auth.json', JSON.stringify({ token: options.token }), 'utf8');
|
|
108
|
+
console.log('saved credentials');
|
|
109
|
+
});
|
|
110
|
+
const bash = new Bash({
|
|
111
|
+
customCommands: [await cli.createJustBashCommand()],
|
|
112
|
+
});
|
|
113
|
+
const loginResult = await bash.exec('mkdir project && cd project && parent login --token Tommy');
|
|
114
|
+
const catResult = await bash.exec('cd project && cat .mycli/auth.json');
|
|
115
|
+
expect(loginResult.stdout).toBe('saved credentials\n');
|
|
116
|
+
expect(loginResult.stderr).toBe('');
|
|
117
|
+
expect(loginResult.exitCode).toBe(0);
|
|
118
|
+
expect(catResult.stdout).toBe('{"token":"Tommy"}');
|
|
119
|
+
expect(catResult.stderr).toBe('');
|
|
120
|
+
expect(catResult.exitCode).toBe(0);
|
|
121
|
+
});
|
|
122
|
+
test('real just-bash exec passes the configured in-memory fs to the goke command', async () => {
|
|
123
|
+
const { Bash, InMemoryFs } = await import('just-bash');
|
|
124
|
+
const cli = gokeTestable('parent');
|
|
125
|
+
cli
|
|
126
|
+
.command('login', 'Persist login state')
|
|
127
|
+
.option('--token <token>', z.string().describe('Token'))
|
|
128
|
+
.action(async (options, { fs, console }) => {
|
|
129
|
+
await fs.mkdir('.mycli', { recursive: true });
|
|
130
|
+
await fs.writeFile('.mycli/auth.json', JSON.stringify({ token: options.token }), 'utf8');
|
|
131
|
+
console.log('saved credentials');
|
|
132
|
+
});
|
|
133
|
+
const virtualFs = new InMemoryFs();
|
|
134
|
+
await virtualFs.mkdir('/project', { recursive: true });
|
|
135
|
+
const bash = new Bash({
|
|
136
|
+
fs: virtualFs,
|
|
137
|
+
cwd: '/project',
|
|
138
|
+
customCommands: [await cli.createJustBashCommand()],
|
|
139
|
+
});
|
|
140
|
+
const result = await bash.exec('parent login --token Tommy');
|
|
141
|
+
expect(result.stdout).toBe('saved credentials\n');
|
|
142
|
+
expect(result.stderr).toBe('');
|
|
143
|
+
expect(result.exitCode).toBe(0);
|
|
144
|
+
expect(await virtualFs.readFile('/project/.mycli/auth.json', 'utf8')).toBe('{"token":"Tommy"}');
|
|
145
|
+
});
|
|
146
|
+
test('real just-bash exec passes sandbox cwd, stdin, and env through process context', async () => {
|
|
147
|
+
const { Bash, InMemoryFs } = await import('just-bash');
|
|
148
|
+
const cli = gokeTestable('parent');
|
|
149
|
+
cli
|
|
150
|
+
.command('context', 'Inspect process context')
|
|
151
|
+
.action((options, { console, process }) => {
|
|
152
|
+
console.log(JSON.stringify({
|
|
153
|
+
cwd: process.cwd,
|
|
154
|
+
stdin: process.stdin,
|
|
155
|
+
token: process.env.TOKEN,
|
|
156
|
+
}));
|
|
157
|
+
});
|
|
158
|
+
const virtualFs = new InMemoryFs();
|
|
159
|
+
await virtualFs.mkdir('/project', { recursive: true });
|
|
160
|
+
const bash = new Bash({
|
|
161
|
+
fs: virtualFs,
|
|
162
|
+
cwd: '/project',
|
|
163
|
+
env: { TOKEN: 'Tommy' },
|
|
164
|
+
customCommands: [await cli.createJustBashCommand()],
|
|
165
|
+
});
|
|
166
|
+
const result = await bash.exec('parent context', { stdin: 'hello from stdin' });
|
|
167
|
+
expect(result.stdout).toBe(`${JSON.stringify({ cwd: '/project', stdin: 'hello from stdin', token: 'Tommy' })}\n`);
|
|
168
|
+
expect(result.stderr).toBe('');
|
|
169
|
+
expect(result.exitCode).toBe(0);
|
|
170
|
+
});
|
|
171
|
+
test('explicit just-bash context exposes a mutable env object backed by the sandbox env', async () => {
|
|
172
|
+
const { InMemoryFs } = await import('just-bash');
|
|
173
|
+
const cli = gokeTestable('parent');
|
|
174
|
+
cli
|
|
175
|
+
.command('mutate-env', 'Mutate sandbox env')
|
|
176
|
+
.action((options, { console, process }) => {
|
|
177
|
+
process.env.TOKEN = 'updated';
|
|
178
|
+
console.log(process.env.TOKEN);
|
|
179
|
+
});
|
|
180
|
+
const virtualFs = new InMemoryFs();
|
|
181
|
+
await virtualFs.mkdir('/project', { recursive: true });
|
|
182
|
+
const env = new Map([['TOKEN', 'before']]);
|
|
183
|
+
const customCommand = await cli.createJustBashCommand();
|
|
184
|
+
const result = await customCommand.execute(['mutate-env'], { fs: virtualFs, cwd: '/project', env, stdin: '' });
|
|
185
|
+
expect(result.stdout).toBe('updated\n');
|
|
186
|
+
expect(result.stderr).toBe('');
|
|
187
|
+
expect(result.exitCode).toBe(0);
|
|
188
|
+
expect(env.get('TOKEN')).toBe('updated');
|
|
189
|
+
});
|
|
190
|
+
test('accepts an explicit just-bash fs context when executing the custom command', async () => {
|
|
191
|
+
const { InMemoryFs } = await import('just-bash');
|
|
192
|
+
const cli = gokeTestable('parent');
|
|
193
|
+
cli
|
|
194
|
+
.command('login', 'Persist login state')
|
|
195
|
+
.option('--token <token>', z.string().describe('Token'))
|
|
196
|
+
.action(async (options, { fs, console }) => {
|
|
197
|
+
await fs.mkdir('.mycli', { recursive: true });
|
|
198
|
+
await fs.writeFile('.mycli/auth.json', JSON.stringify({ token: options.token }), 'utf8');
|
|
199
|
+
console.log('saved credentials');
|
|
200
|
+
});
|
|
201
|
+
const customCommand = await cli.createJustBashCommand();
|
|
202
|
+
const virtualFs = new InMemoryFs();
|
|
203
|
+
await virtualFs.mkdir('/project', { recursive: true });
|
|
204
|
+
const result = await customCommand.execute(['login', '--token', 'Tommy'], { fs: virtualFs, cwd: '/project', env: new Map(), stdin: '' });
|
|
205
|
+
expect(result.stdout).toBe('saved credentials\n');
|
|
206
|
+
expect(result.stderr).toBe('');
|
|
207
|
+
expect(result.exitCode).toBe(0);
|
|
208
|
+
expect(await virtualFs.readFile('/project/.mycli/auth.json', 'utf8')).toBe('{"token":"Tommy"}');
|
|
209
|
+
});
|
|
82
210
|
test('maps injected process.exit to a command exit code', async () => {
|
|
83
211
|
const cli = gokeTestable('parent');
|
|
84
212
|
cli
|
|
@@ -73,10 +73,14 @@ describe('type-level: middleware use() callback inference', () => {
|
|
|
73
73
|
goke('test')
|
|
74
74
|
.option('--port <port>', schema1)
|
|
75
75
|
.option('--host <host>', schema2)
|
|
76
|
-
.use((options, { console, process }) => {
|
|
76
|
+
.use((options, { console, fs, process }) => {
|
|
77
77
|
expectTypeOf(options.port).toEqualTypeOf();
|
|
78
78
|
expectTypeOf(options.host).toEqualTypeOf();
|
|
79
|
+
expectTypeOf(fs.mkdir).toBeFunction();
|
|
79
80
|
expectTypeOf(process.argv).toEqualTypeOf();
|
|
81
|
+
expectTypeOf(process.cwd).toEqualTypeOf();
|
|
82
|
+
expectTypeOf(process.env).toEqualTypeOf();
|
|
83
|
+
expectTypeOf(process.stdin).toEqualTypeOf();
|
|
80
84
|
expectTypeOf(process.stdout.write).toEqualTypeOf();
|
|
81
85
|
expectTypeOf(console.log).toBeFunction();
|
|
82
86
|
});
|
|
@@ -86,8 +90,9 @@ describe('type-level: middleware use() callback inference', () => {
|
|
|
86
90
|
const schema2 = {};
|
|
87
91
|
goke('test')
|
|
88
92
|
.option('--verbose', schema1)
|
|
89
|
-
.use((options, { process }) => {
|
|
93
|
+
.use((options, { fs, process }) => {
|
|
90
94
|
expectTypeOf(options.verbose).toEqualTypeOf();
|
|
95
|
+
expectTypeOf(fs.writeFile).toBeFunction();
|
|
91
96
|
expectTypeOf(process.exit).toEqualTypeOf();
|
|
92
97
|
// @ts-expect-error port is not declared yet
|
|
93
98
|
options.port;
|
|
@@ -104,7 +109,8 @@ describe('type-level: middleware use() callback inference', () => {
|
|
|
104
109
|
const schema = {};
|
|
105
110
|
goke('test')
|
|
106
111
|
.option('--port <port>', schema)
|
|
107
|
-
.use((options, { process }) => {
|
|
112
|
+
.use((options, { fs, process }) => {
|
|
113
|
+
expectTypeOf(fs.readFile).toBeFunction();
|
|
108
114
|
expectTypeOf(process.stderr.write).toEqualTypeOf();
|
|
109
115
|
// @ts-expect-error nonExistent was never defined
|
|
110
116
|
options.nonExistent;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-like filesystem types used by injected goke execution contexts.
|
|
3
|
+
*/
|
|
4
|
+
import type { MakeDirectoryOptions, Mode, PathLike, RmOptions, TimeLike } from 'node:fs';
|
|
5
|
+
type GokeFsFileContent = string | NodeJS.ArrayBufferView;
|
|
6
|
+
type GokeFsEncodingOption = BufferEncoding | {
|
|
7
|
+
encoding?: BufferEncoding | null;
|
|
8
|
+
};
|
|
9
|
+
interface GokeFs {
|
|
10
|
+
appendFile(path: PathLike, data: GokeFsFileContent, options?: GokeFsEncodingOption): Promise<void>;
|
|
11
|
+
chmod(path: PathLike, mode: Mode): Promise<void>;
|
|
12
|
+
copyFile(src: PathLike, dest: PathLike): Promise<void>;
|
|
13
|
+
link(existingPath: PathLike, newPath: PathLike): Promise<void>;
|
|
14
|
+
mkdir(path: PathLike, options?: MakeDirectoryOptions): Promise<string | undefined>;
|
|
15
|
+
readFile(path: PathLike, options?: GokeFsEncodingOption): Promise<string | Uint8Array>;
|
|
16
|
+
readlink(path: PathLike): Promise<string>;
|
|
17
|
+
realpath(path: PathLike): Promise<string>;
|
|
18
|
+
rename(oldPath: PathLike, newPath: PathLike): Promise<void>;
|
|
19
|
+
rm(path: PathLike, options?: RmOptions): Promise<void>;
|
|
20
|
+
symlink(target: PathLike, path: PathLike): Promise<void>;
|
|
21
|
+
utimes(path: PathLike, atime: TimeLike, mtime: TimeLike): Promise<void>;
|
|
22
|
+
writeFile(path: PathLike, data: GokeFsFileContent, options?: GokeFsEncodingOption): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export type { GokeFs, GokeFsEncodingOption, GokeFsFileContent };
|
|
25
|
+
//# sourceMappingURL=goke-fs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goke-fs.d.ts","sourceRoot":"","sources":["../src/goke-fs.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAExF,KAAK,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC,eAAe,CAAA;AACxD,KAAK,oBAAoB,GAAG,cAAc,GAAG;IAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;CAAE,CAAA;AAEjF,UAAU,MAAM;IACd,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClG,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAChD,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtD,IAAI,CAAC,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9D,KAAK,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;IAClF,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,GAAG,UAAU,CAAC,CAAA;IACtF,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACzC,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IACzC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC3D,EAAE,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtD,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,MAAM,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACvE,SAAS,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAClG;AAED,YAAY,EAAE,MAAM,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,CAAA"}
|
package/dist/goke-fs.js
ADDED
package/dist/goke.d.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* - Utility functions: string helpers, bracket parsing, dot-prop access
|
|
11
11
|
*/
|
|
12
12
|
import type { StandardJSONSchemaV1 } from "./coerce.js";
|
|
13
|
+
import type { GokeFs } from './goke-fs.js';
|
|
13
14
|
import { EventEmitter, openInBrowser } from '#runtime';
|
|
14
15
|
declare class Option {
|
|
15
16
|
rawName: string;
|
|
@@ -185,12 +186,16 @@ interface GokeConsole {
|
|
|
185
186
|
}
|
|
186
187
|
interface GokeProcess {
|
|
187
188
|
argv: string[];
|
|
189
|
+
cwd: string;
|
|
190
|
+
env: Record<string, string | undefined>;
|
|
191
|
+
stdin: string;
|
|
188
192
|
stdout: GokeOutputStream;
|
|
189
193
|
stderr: GokeOutputStream;
|
|
190
194
|
exit(code: number): never | void;
|
|
191
195
|
}
|
|
192
196
|
interface GokeExecutionContext {
|
|
193
197
|
console: GokeConsole;
|
|
198
|
+
fs: GokeFs;
|
|
194
199
|
process: GokeProcess;
|
|
195
200
|
}
|
|
196
201
|
declare class GokeProcessExit extends Error {
|
|
@@ -201,6 +206,14 @@ declare class GokeProcessExit extends Error {
|
|
|
201
206
|
* Options for configuring a Goke CLI instance.
|
|
202
207
|
*/
|
|
203
208
|
interface GokeOptions {
|
|
209
|
+
/** Custom cwd value exposed through the injected process context. */
|
|
210
|
+
cwd?: string;
|
|
211
|
+
/** Custom environment exposed through the injected process context. */
|
|
212
|
+
env?: Record<string, string | undefined>;
|
|
213
|
+
/** Custom fs implementation. Defaults to node:fs/promises in Node runtimes. */
|
|
214
|
+
fs?: GokeFs;
|
|
215
|
+
/** Custom stdin content exposed through the injected process context. */
|
|
216
|
+
stdin?: string;
|
|
204
217
|
/** Custom stdout stream. Defaults to process.stdout */
|
|
205
218
|
stdout?: GokeOutputStream;
|
|
206
219
|
/** Custom stderr stream. Defaults to process.stderr */
|
|
@@ -255,6 +268,14 @@ declare class Goke<Opts extends Record<string, any> = {}> extends EventEmitter {
|
|
|
255
268
|
options: ParsedArgv['options'];
|
|
256
269
|
showHelpOnExit?: boolean;
|
|
257
270
|
showVersionOnExit?: boolean;
|
|
271
|
+
/** Working directory exposed through the injected process context. */
|
|
272
|
+
readonly cwd?: string;
|
|
273
|
+
/** Environment exposed through the injected process context. */
|
|
274
|
+
readonly env?: Record<string, string | undefined>;
|
|
275
|
+
/** Output stream for normal output (help, version, etc.) */
|
|
276
|
+
readonly fs: GokeFs;
|
|
277
|
+
/** Standard input exposed through the injected process context. */
|
|
278
|
+
readonly stdin?: string;
|
|
258
279
|
/** Output stream for normal output (help, version, etc.) */
|
|
259
280
|
readonly stdout: GokeOutputStream;
|
|
260
281
|
/** Output stream for error output */
|
|
@@ -374,7 +395,7 @@ declare class Goke<Opts extends Record<string, any> = {}> extends EventEmitter {
|
|
|
374
395
|
private mri;
|
|
375
396
|
runMatchedCommand(): any;
|
|
376
397
|
}
|
|
377
|
-
export type { GokeOutputStream, GokeConsole, GokeOptions, GokeProcess, GokeExecutionContext };
|
|
398
|
+
export type { GokeOutputStream, GokeConsole, GokeOptions, GokeProcess, GokeExecutionContext, GokeFs };
|
|
378
399
|
export { createConsole, Command, GokeProcessExit, openInBrowser };
|
|
379
400
|
export default Goke;
|
|
380
401
|
//# sourceMappingURL=goke.d.ts.map
|
package/dist/goke.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"goke.d.ts","sourceRoot":"","sources":["../src/goke.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"goke.d.ts","sourceRoot":"","sources":["../src/goke.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,YAAY,EAAmB,aAAa,EAAW,MAAM,UAAU,CAAA;AAmNhF,cAAM,MAAM;IAwBD,OAAO,EAAE,MAAM;IAvBxB,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,8BAA8B;IAC9B,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB,QAAQ,CAAC,EAAE,OAAO,CAAA;I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sole: factory for console-like objects from output streams
|
|
10
10
|
* - Utility functions: string helpers, bracket parsing, dot-prop access
|
|
11
11
|
*/
|
|
12
|
-
import pc from 'picocolors';
|
|
12
|
+
import pc from './picocolors.js';
|
|
13
13
|
import mri from "./mri.js";
|
|
14
14
|
import { GokeError, coerceBySchema, extractJsonSchema, extractSchemaMetadata, isStandardSchema } from "./coerce.js";
|
|
15
15
|
import { createJustBashCommand as createJustBashCommandBridge } from './just-bash.js';
|
|
16
|
-
import { EventEmitter, openInBrowser, process } from '#runtime';
|
|
16
|
+
import { EventEmitter, fs as runtimeFs, openInBrowser, process } from '#runtime';
|
|
17
17
|
// ─── Node.js platform constants ───
|
|
18
18
|
const processArgs = process.argv;
|
|
19
19
|
const platformInfo = `${process.platform}-${process.arch} node-${process.version}`;
|
|
@@ -163,6 +163,7 @@ const getFileName = (input) => {
|
|
|
163
163
|
};
|
|
164
164
|
const isPromiseLike = (value) => value != null
|
|
165
165
|
&& (typeof value === 'object' || typeof value === 'function')
|
|
166
|
+
&& 'then' in value
|
|
166
167
|
&& typeof value.then === 'function';
|
|
167
168
|
const camelcaseOptionName = (name) => {
|
|
168
169
|
// Camelcase the option name
|
|
@@ -642,6 +643,14 @@ class Goke extends EventEmitter {
|
|
|
642
643
|
options;
|
|
643
644
|
showHelpOnExit;
|
|
644
645
|
showVersionOnExit;
|
|
646
|
+
/** Working directory exposed through the injected process context. */
|
|
647
|
+
cwd;
|
|
648
|
+
/** Environment exposed through the injected process context. */
|
|
649
|
+
env;
|
|
650
|
+
/** Output stream for normal output (help, version, etc.) */
|
|
651
|
+
fs;
|
|
652
|
+
/** Standard input exposed through the injected process context. */
|
|
653
|
+
stdin;
|
|
645
654
|
/** Output stream for normal output (help, version, etc.) */
|
|
646
655
|
stdout;
|
|
647
656
|
/** Output stream for error output */
|
|
@@ -665,6 +674,10 @@ class Goke extends EventEmitter {
|
|
|
665
674
|
this.rawArgs = [];
|
|
666
675
|
this.args = [];
|
|
667
676
|
this.options = {};
|
|
677
|
+
this.cwd = options?.cwd;
|
|
678
|
+
this.env = options?.env;
|
|
679
|
+
this.fs = options?.fs ?? runtimeFs;
|
|
680
|
+
this.stdin = options?.stdin;
|
|
668
681
|
this.stdout = options?.stdout ?? process.stdout;
|
|
669
682
|
this.stderr = options?.stderr ?? process.stderr;
|
|
670
683
|
this.console = createConsole(this.stdout, this.stderr);
|
|
@@ -676,6 +689,10 @@ class Goke extends EventEmitter {
|
|
|
676
689
|
}
|
|
677
690
|
clone(options) {
|
|
678
691
|
const cloned = new Goke(this.name, {
|
|
692
|
+
cwd: options?.cwd ?? this.cwd,
|
|
693
|
+
env: options?.env ?? this.env,
|
|
694
|
+
fs: options?.fs ?? this.fs,
|
|
695
|
+
stdin: options?.stdin ?? this.stdin,
|
|
679
696
|
stdout: options?.stdout ?? this.stdout,
|
|
680
697
|
stderr: options?.stderr ?? this.stderr,
|
|
681
698
|
argv: options?.argv ?? this.#defaultArgv,
|
|
@@ -700,8 +717,12 @@ class Goke extends EventEmitter {
|
|
|
700
717
|
createExecutionContext(argv = this.rawArgs) {
|
|
701
718
|
return {
|
|
702
719
|
console: this.console,
|
|
720
|
+
fs: this.fs,
|
|
703
721
|
process: {
|
|
704
722
|
argv,
|
|
723
|
+
cwd: this.cwd ?? process.cwd(),
|
|
724
|
+
env: this.env ?? process.env,
|
|
725
|
+
stdin: this.stdin ?? '',
|
|
705
726
|
stdout: this.stdout,
|
|
706
727
|
stderr: this.stderr,
|
|
707
728
|
exit: (code) => {
|
|
@@ -733,7 +754,8 @@ class Goke extends EventEmitter {
|
|
|
733
754
|
return command;
|
|
734
755
|
}
|
|
735
756
|
option(rawName, descriptionOrSchema) {
|
|
736
|
-
|
|
757
|
+
const option = new Option(rawName, descriptionOrSchema);
|
|
758
|
+
this.globalCommand.options.push(option);
|
|
737
759
|
return this;
|
|
738
760
|
}
|
|
739
761
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare const goke: (name?: string, options?: GokeOptions) => Goke<{}>;
|
|
|
9
9
|
export default goke;
|
|
10
10
|
export { goke, Goke, Command };
|
|
11
11
|
export { createConsole, GokeProcessExit, openInBrowser } from "./goke.js";
|
|
12
|
-
export type { GokeOutputStream, GokeConsole, GokeExecutionContext, GokeOptions, GokeProcess } from "./goke.js";
|
|
12
|
+
export type { GokeOutputStream, GokeConsole, GokeExecutionContext, GokeFs, GokeOptions, GokeProcess } from "./goke.js";
|
|
13
13
|
export type { StandardTypedV1, StandardJSONSchemaV1, JsonSchema } from "./coerce.js";
|
|
14
14
|
export { GokeError, coerceBySchema, extractJsonSchema, wrapJsonSchema, isStandardSchema, extractSchemaMetadata } from "./coerce.js";
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,aAAS,EAAE,UAAU,WAAW,aAA4B,CAAA;AAE1E,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,oBAAoB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC;;;GAGG;AACH,QAAA,MAAM,IAAI,GAAI,aAAS,EAAE,UAAU,WAAW,aAA4B,CAAA;AAE1E,eAAe,IAAI,CAAA;AACnB,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAC9B,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AACzE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AACtH,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACpF,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/just-bash.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* - https://github.com/vercel-labs/just-bash/blob/main/src/custom-commands.ts
|
|
6
6
|
* - https://github.com/vercel-labs/just-bash/blob/main/src/types.ts
|
|
7
7
|
*/
|
|
8
|
+
import type { CommandContext } from 'just-bash';
|
|
8
9
|
import Goke from './goke.js';
|
|
9
10
|
interface JustBashExecResult {
|
|
10
11
|
stdout: string;
|
|
@@ -14,8 +15,9 @@ interface JustBashExecResult {
|
|
|
14
15
|
interface JustBashCommand {
|
|
15
16
|
name: string;
|
|
16
17
|
trusted: true;
|
|
17
|
-
execute(args: string[]): Promise<JustBashExecResult>;
|
|
18
|
+
execute(args: string[], context?: JustBashExecutionContext): Promise<JustBashExecResult>;
|
|
18
19
|
}
|
|
20
|
+
type JustBashExecutionContext = Pick<CommandContext, 'cwd' | 'env' | 'fs' | 'stdin'>;
|
|
19
21
|
export declare function createJustBashCommand(cli: Goke<any>, options?: {
|
|
20
22
|
name?: string;
|
|
21
23
|
}): JustBashCommand;
|
package/dist/just-bash.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"just-bash.d.ts","sourceRoot":"","sources":["../src/just-bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;
|
|
1
|
+
{"version":3,"file":"just-bash.d.ts","sourceRoot":"","sources":["../src/just-bash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAe,MAAM,WAAW,CAAA;AAC5D,OAAO,IAAyB,MAAM,WAAW,CAAA;AAIjD,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,UAAU,eAAe;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,IAAI,CAAA;IACb,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;CACzF;AAED,KAAK,wBAAwB,GAAG,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,GAAG,OAAO,CAAC,CAAA;AA4LpF,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EACd,OAAO,CAAC,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1B,eAAe,CAqDjB;AAED,YAAY,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAA"}
|
package/dist/just-bash.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* - https://github.com/vercel-labs/just-bash/blob/main/src/custom-commands.ts
|
|
6
6
|
* - https://github.com/vercel-labs/just-bash/blob/main/src/types.ts
|
|
7
7
|
*/
|
|
8
|
+
import { Buffer } from 'node:buffer';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
8
10
|
import { GokeProcessExit } from './goke.js';
|
|
9
11
|
function createTextCaptureStream() {
|
|
10
12
|
const chunks = [];
|
|
@@ -17,6 +19,162 @@ function createTextCaptureStream() {
|
|
|
17
19
|
},
|
|
18
20
|
};
|
|
19
21
|
}
|
|
22
|
+
const resolveJustBashPath = (fs, cwd, path) => {
|
|
23
|
+
if (path instanceof URL) {
|
|
24
|
+
return fileURLToPath(path);
|
|
25
|
+
}
|
|
26
|
+
return fs.resolvePath(cwd, path.toString());
|
|
27
|
+
};
|
|
28
|
+
const getEncoding = (options) => {
|
|
29
|
+
if (typeof options === 'string' || options == null) {
|
|
30
|
+
return options;
|
|
31
|
+
}
|
|
32
|
+
return options.encoding;
|
|
33
|
+
};
|
|
34
|
+
const toJustBashEncoding = (encoding) => {
|
|
35
|
+
if (encoding == null) {
|
|
36
|
+
return encoding;
|
|
37
|
+
}
|
|
38
|
+
switch (encoding) {
|
|
39
|
+
case 'utf8':
|
|
40
|
+
case 'utf-8':
|
|
41
|
+
case 'ascii':
|
|
42
|
+
case 'binary':
|
|
43
|
+
case 'base64':
|
|
44
|
+
case 'hex':
|
|
45
|
+
case 'latin1':
|
|
46
|
+
return encoding;
|
|
47
|
+
default:
|
|
48
|
+
throw new Error(`Encoding ${encoding} is not supported by the JustBash fs adapter`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const toJustBashContent = (content) => {
|
|
52
|
+
if (typeof content === 'string' || content instanceof Uint8Array) {
|
|
53
|
+
return content;
|
|
54
|
+
}
|
|
55
|
+
return new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
|
|
56
|
+
};
|
|
57
|
+
const toDate = (value) => {
|
|
58
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
59
|
+
if (Number.isNaN(date.getTime())) {
|
|
60
|
+
throw new Error(`Invalid time value: ${String(value)}`);
|
|
61
|
+
}
|
|
62
|
+
return date;
|
|
63
|
+
};
|
|
64
|
+
function createJustBashEnvProxy(env) {
|
|
65
|
+
return new Proxy(Object.create(null), {
|
|
66
|
+
deleteProperty(_target, property) {
|
|
67
|
+
if (typeof property === 'string') {
|
|
68
|
+
env.delete(property);
|
|
69
|
+
}
|
|
70
|
+
return true;
|
|
71
|
+
},
|
|
72
|
+
get(_target, property) {
|
|
73
|
+
if (typeof property !== 'string')
|
|
74
|
+
return undefined;
|
|
75
|
+
return env.get(property);
|
|
76
|
+
},
|
|
77
|
+
getOwnPropertyDescriptor(_target, property) {
|
|
78
|
+
if (typeof property !== 'string')
|
|
79
|
+
return undefined;
|
|
80
|
+
const value = env.get(property);
|
|
81
|
+
if (value === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
return {
|
|
84
|
+
configurable: true,
|
|
85
|
+
enumerable: true,
|
|
86
|
+
value,
|
|
87
|
+
writable: true,
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
has(_target, property) {
|
|
91
|
+
return typeof property === 'string' && env.has(property);
|
|
92
|
+
},
|
|
93
|
+
ownKeys() {
|
|
94
|
+
return [...env.keys()];
|
|
95
|
+
},
|
|
96
|
+
set(_target, property, value) {
|
|
97
|
+
if (typeof property === 'string') {
|
|
98
|
+
if (value === undefined) {
|
|
99
|
+
env.delete(property);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
env.set(property, String(value));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function createJustBashFs(fs, cwd) {
|
|
110
|
+
const readFile = async (path, options) => {
|
|
111
|
+
const resolvedPath = resolveJustBashPath(fs, cwd, path);
|
|
112
|
+
const encoding = toJustBashEncoding(getEncoding(options));
|
|
113
|
+
if (encoding == null) {
|
|
114
|
+
return Buffer.from(await fs.readFileBuffer(resolvedPath));
|
|
115
|
+
}
|
|
116
|
+
return fs.readFile(resolvedPath, encoding);
|
|
117
|
+
};
|
|
118
|
+
const writeFile = async (path, content, options) => {
|
|
119
|
+
const resolvedPath = resolveJustBashPath(fs, cwd, path);
|
|
120
|
+
const encoding = toJustBashEncoding(getEncoding(options)) ?? undefined;
|
|
121
|
+
await fs.writeFile(resolvedPath, toJustBashContent(content), encoding);
|
|
122
|
+
};
|
|
123
|
+
const appendFile = async (path, content, options) => {
|
|
124
|
+
const resolvedPath = resolveJustBashPath(fs, cwd, path);
|
|
125
|
+
const encoding = toJustBashEncoding(getEncoding(options)) ?? undefined;
|
|
126
|
+
await fs.appendFile(resolvedPath, toJustBashContent(content), encoding);
|
|
127
|
+
};
|
|
128
|
+
const mkdir = async (path, options) => {
|
|
129
|
+
await fs.mkdir(resolveJustBashPath(fs, cwd, path), { recursive: typeof options === 'object' ? options.recursive : undefined });
|
|
130
|
+
return undefined;
|
|
131
|
+
};
|
|
132
|
+
const rm = async (path, options) => {
|
|
133
|
+
await fs.rm(resolveJustBashPath(fs, cwd, path), {
|
|
134
|
+
recursive: options?.recursive,
|
|
135
|
+
force: options?.force,
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
const rename = async (oldPath, newPath) => {
|
|
139
|
+
await fs.mv(resolveJustBashPath(fs, cwd, oldPath), resolveJustBashPath(fs, cwd, newPath));
|
|
140
|
+
};
|
|
141
|
+
const copyFile = async (src, dest) => {
|
|
142
|
+
await fs.cp(resolveJustBashPath(fs, cwd, src), resolveJustBashPath(fs, cwd, dest));
|
|
143
|
+
};
|
|
144
|
+
const chmod = async (path, mode) => {
|
|
145
|
+
await fs.chmod(resolveJustBashPath(fs, cwd, path), Number(mode));
|
|
146
|
+
};
|
|
147
|
+
const link = async (existingPath, newPath) => {
|
|
148
|
+
await fs.link(resolveJustBashPath(fs, cwd, existingPath), resolveJustBashPath(fs, cwd, newPath));
|
|
149
|
+
};
|
|
150
|
+
const readlink = async (path) => {
|
|
151
|
+
return fs.readlink(resolveJustBashPath(fs, cwd, path));
|
|
152
|
+
};
|
|
153
|
+
const realpath = async (path) => {
|
|
154
|
+
return fs.realpath(resolveJustBashPath(fs, cwd, path));
|
|
155
|
+
};
|
|
156
|
+
const symlink = async (target, path) => {
|
|
157
|
+
await fs.symlink(target.toString(), resolveJustBashPath(fs, cwd, path));
|
|
158
|
+
};
|
|
159
|
+
const utimes = async (path, atime, mtime) => {
|
|
160
|
+
await fs.utimes(resolveJustBashPath(fs, cwd, path), toDate(atime), toDate(mtime));
|
|
161
|
+
};
|
|
162
|
+
return {
|
|
163
|
+
appendFile,
|
|
164
|
+
chmod,
|
|
165
|
+
copyFile,
|
|
166
|
+
link,
|
|
167
|
+
mkdir,
|
|
168
|
+
readFile,
|
|
169
|
+
readlink,
|
|
170
|
+
realpath,
|
|
171
|
+
rename,
|
|
172
|
+
rm,
|
|
173
|
+
symlink,
|
|
174
|
+
utimes,
|
|
175
|
+
writeFile,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
20
178
|
export function createJustBashCommand(cli, options) {
|
|
21
179
|
const name = options?.name ?? cli.name;
|
|
22
180
|
if (!name) {
|
|
@@ -28,11 +186,15 @@ export function createJustBashCommand(cli, options) {
|
|
|
28
186
|
return {
|
|
29
187
|
name,
|
|
30
188
|
trusted: true,
|
|
31
|
-
async execute(args) {
|
|
189
|
+
async execute(args, context) {
|
|
32
190
|
const stdout = createTextCaptureStream();
|
|
33
191
|
const stderr = createTextCaptureStream();
|
|
34
192
|
const argv = ['node', name, ...args];
|
|
35
193
|
const cloned = cli.clone({
|
|
194
|
+
cwd: context?.cwd,
|
|
195
|
+
env: context ? createJustBashEnvProxy(context.env) : cli.env,
|
|
196
|
+
fs: context ? createJustBashFs(context.fs, context.cwd) : cli.fs,
|
|
197
|
+
stdin: context?.stdin,
|
|
36
198
|
stdout,
|
|
37
199
|
stderr,
|
|
38
200
|
argv,
|