@adonisjs/repl 5.0.0-next.0 → 5.0.0-next.2
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/build/index.d.ts +1 -1
- package/build/index.js +198 -300
- package/build/src/repl.d.ts +74 -1
- package/build/src/types.d.ts +1 -1
- package/build/src/types.js +1 -0
- package/package.json +21 -17
package/build/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Repl } from './src/repl.
|
|
1
|
+
export { Repl } from './src/repl.ts';
|
package/build/index.js
CHANGED
|
@@ -1,306 +1,204 @@
|
|
|
1
|
-
// src/repl.ts
|
|
2
1
|
import stringWidth from "string-width";
|
|
3
2
|
import useColors from "@poppinss/colors";
|
|
4
|
-
import { inspect, promisify
|
|
5
|
-
import { Recoverable, start
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
import { inspect, promisify } from "node:util";
|
|
4
|
+
import { Recoverable, start } from "node:repl";
|
|
5
|
+
const GLOBAL_NODE_PROPERTIES = [
|
|
6
|
+
"performance",
|
|
7
|
+
"global",
|
|
8
|
+
"clearInterval",
|
|
9
|
+
"clearTimeout",
|
|
10
|
+
"setInterval",
|
|
11
|
+
"setTimeout",
|
|
12
|
+
"queueMicrotask",
|
|
13
|
+
"clearImmediate",
|
|
14
|
+
"setImmediate",
|
|
15
|
+
"structuredClone",
|
|
16
|
+
"atob",
|
|
17
|
+
"btoa",
|
|
18
|
+
"fetch",
|
|
19
|
+
"crypto",
|
|
20
|
+
"navigator",
|
|
21
|
+
"localStorage",
|
|
22
|
+
"sessionStorage"
|
|
22
23
|
];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
24
|
+
const TS_UTILS_HELPERS = [
|
|
25
|
+
"__extends",
|
|
26
|
+
"__assign",
|
|
27
|
+
"__rest",
|
|
28
|
+
"__decorate",
|
|
29
|
+
"__param",
|
|
30
|
+
"__esDecorate",
|
|
31
|
+
"__runInitializers",
|
|
32
|
+
"__propKey",
|
|
33
|
+
"__setFunctionName",
|
|
34
|
+
"__metadata",
|
|
35
|
+
"__awaiter",
|
|
36
|
+
"__generator",
|
|
37
|
+
"__exportStar",
|
|
38
|
+
"__createBinding",
|
|
39
|
+
"__values",
|
|
40
|
+
"__read",
|
|
41
|
+
"__spread",
|
|
42
|
+
"__spreadArrays",
|
|
43
|
+
"__spreadArray",
|
|
44
|
+
"__await",
|
|
45
|
+
"__asyncGenerator",
|
|
46
|
+
"__asyncDelegator",
|
|
47
|
+
"__asyncValues",
|
|
48
|
+
"__makeTemplateObject",
|
|
49
|
+
"__importStar",
|
|
50
|
+
"__importDefault",
|
|
51
|
+
"__classPrivateFieldGet",
|
|
52
|
+
"__classPrivateFieldSet",
|
|
53
|
+
"__classPrivateFieldIn"
|
|
53
54
|
];
|
|
54
55
|
var Repl = class {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
{}
|
|
203
|
-
);
|
|
204
|
-
console.log(inspect(context, false, 1, true));
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Prints the help for the custom methods
|
|
208
|
-
*/
|
|
209
|
-
#printCustomMethodsHelp() {
|
|
210
|
-
console.log("");
|
|
211
|
-
console.log(this.colors.green("GLOBAL METHODS:"));
|
|
212
|
-
Object.keys(this.#customMethods).forEach((method) => {
|
|
213
|
-
const { options } = this.#customMethods[method];
|
|
214
|
-
const usage = this.colors.yellow(options.usage || method);
|
|
215
|
-
const spaces = " ".repeat(this.#longestCustomMethodName - options.width + 2);
|
|
216
|
-
const description = this.colors.dim(options.description || "");
|
|
217
|
-
console.log(`${usage}${spaces}${description}`);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Prints the context to the console
|
|
222
|
-
*/
|
|
223
|
-
#ls() {
|
|
224
|
-
this.#printCustomMethodsHelp();
|
|
225
|
-
this.#printContextHelp();
|
|
226
|
-
this.server.displayPrompt();
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Notify by writing to the console
|
|
230
|
-
*/
|
|
231
|
-
notify(message) {
|
|
232
|
-
console.log(this.colors.yellow().italic(message));
|
|
233
|
-
if (this.server) {
|
|
234
|
-
this.server.displayPrompt();
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Register a callback to be invoked once the server is ready
|
|
239
|
-
*/
|
|
240
|
-
ready(callback) {
|
|
241
|
-
this.#onReadyCallbacks.push(callback);
|
|
242
|
-
return this;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Register a custom loader function to be added to the context
|
|
246
|
-
*/
|
|
247
|
-
addMethod(name, handler, options) {
|
|
248
|
-
const width = stringWidth(options?.usage || name);
|
|
249
|
-
if (width > this.#longestCustomMethodName) {
|
|
250
|
-
this.#longestCustomMethodName = width;
|
|
251
|
-
}
|
|
252
|
-
this.#customMethods[name] = { handler, options: Object.assign({ width }, options) };
|
|
253
|
-
if (this.server) {
|
|
254
|
-
this.#registerCustomMethodWithContext(name);
|
|
255
|
-
}
|
|
256
|
-
return this;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Returns the collection of registered methods
|
|
260
|
-
*/
|
|
261
|
-
getMethods() {
|
|
262
|
-
return this.#customMethods;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Register a compiler. Make sure register the compiler before
|
|
266
|
-
* calling the start method
|
|
267
|
-
*/
|
|
268
|
-
useCompiler(compiler) {
|
|
269
|
-
this.#compiler = compiler;
|
|
270
|
-
return this;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Start the REPL server
|
|
274
|
-
*/
|
|
275
|
-
start(context) {
|
|
276
|
-
console.log("");
|
|
277
|
-
this.notify('Type ".ls" to a view list of available context methods/properties');
|
|
278
|
-
this.server = startRepl({
|
|
279
|
-
prompt: `> ${this.#compiler?.supportsTypescript ? "(ts) " : "(js) "}`,
|
|
280
|
-
input: process.stdin,
|
|
281
|
-
output: process.stdout,
|
|
282
|
-
terminal: process.stdout.isTTY && !Number.parseInt(process.env.NODE_NO_READLINE, 10),
|
|
283
|
-
useGlobal: true,
|
|
284
|
-
...this.#replOptions
|
|
285
|
-
});
|
|
286
|
-
if (context) {
|
|
287
|
-
Object.keys(context).forEach((key) => {
|
|
288
|
-
this.server.context[key] = context[key];
|
|
289
|
-
});
|
|
290
|
-
}
|
|
291
|
-
this.server.defineCommand("ls", {
|
|
292
|
-
help: "View list of available context methods/properties",
|
|
293
|
-
action: this.#ls.bind(this)
|
|
294
|
-
});
|
|
295
|
-
this.#setupContext();
|
|
296
|
-
this.#setupHistory();
|
|
297
|
-
this.#originalEval = this.server.eval;
|
|
298
|
-
this.server.eval = this.#eval.bind(this);
|
|
299
|
-
this.server.displayPrompt();
|
|
300
|
-
this.#onReadyCallbacks.forEach((callback) => callback(this));
|
|
301
|
-
return this;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
export {
|
|
305
|
-
Repl
|
|
56
|
+
#replOptions;
|
|
57
|
+
#longestCustomMethodName = 0;
|
|
58
|
+
#originalEval;
|
|
59
|
+
#compiler;
|
|
60
|
+
#historyFilePath;
|
|
61
|
+
#onReadyCallbacks = [];
|
|
62
|
+
#customMethods = {};
|
|
63
|
+
colors = useColors.ansi();
|
|
64
|
+
server;
|
|
65
|
+
constructor(options) {
|
|
66
|
+
const { compiler, historyFilePath, ...rest } = options || {};
|
|
67
|
+
this.#compiler = compiler;
|
|
68
|
+
this.#historyFilePath = historyFilePath;
|
|
69
|
+
this.#replOptions = rest;
|
|
70
|
+
}
|
|
71
|
+
#registerCustomMethodWithContext(name) {
|
|
72
|
+
const customMethod = this.#customMethods[name];
|
|
73
|
+
if (!customMethod) return;
|
|
74
|
+
const handler = (...args) => customMethod.handler(this, ...args);
|
|
75
|
+
Object.defineProperty(handler, "name", { value: customMethod.handler.name });
|
|
76
|
+
this.server.context[name] = handler;
|
|
77
|
+
}
|
|
78
|
+
#setupContext() {
|
|
79
|
+
this.addMethod("clear", function clear(repl, key) {
|
|
80
|
+
if (!key) console.log(repl.colors.red("Define a property name to remove from the context"));
|
|
81
|
+
else delete repl.server.context[key];
|
|
82
|
+
repl.server.displayPrompt();
|
|
83
|
+
}, {
|
|
84
|
+
description: "Clear a property from the REPL context",
|
|
85
|
+
usage: `clear ${this.colors.gray("(propertyName)")}`
|
|
86
|
+
});
|
|
87
|
+
this.addMethod("p", function promisify$1(_, fn) {
|
|
88
|
+
return promisify(fn);
|
|
89
|
+
}, {
|
|
90
|
+
description: "Promisify a function. Similar to Node.js \"util.promisify\"",
|
|
91
|
+
usage: `p ${this.colors.gray("(function)")}`
|
|
92
|
+
});
|
|
93
|
+
Object.keys(this.#customMethods).forEach((name) => {
|
|
94
|
+
this.#registerCustomMethodWithContext(name);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
#isRecoverableError(error) {
|
|
98
|
+
return /^(Unexpected end of input|Unexpected token|' expected)/.test(error.message);
|
|
99
|
+
}
|
|
100
|
+
#eval(code, context, filename, callback) {
|
|
101
|
+
try {
|
|
102
|
+
const compiled = this.#compiler ? this.#compiler.compile(code, filename) : code;
|
|
103
|
+
return this.#originalEval(compiled, context, filename, callback);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
if (this.#isRecoverableError(error)) {
|
|
106
|
+
callback(new Recoverable(error), null);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
callback(error, null);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
#setupHistory() {
|
|
113
|
+
if (!this.#historyFilePath) return;
|
|
114
|
+
this.server.setupHistory(this.#historyFilePath, (error) => {
|
|
115
|
+
if (!error) return;
|
|
116
|
+
console.log(this.colors.red("Unable to write to the history file. Exiting"));
|
|
117
|
+
console.error(error);
|
|
118
|
+
process.exit(1);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
#printContextHelp() {
|
|
122
|
+
console.log("");
|
|
123
|
+
console.log(this.colors.green("CONTEXT PROPERTIES/METHODS:"));
|
|
124
|
+
const context = Object.keys(this.server.context).reduce((result, key) => {
|
|
125
|
+
if (!this.#customMethods[key] && !GLOBAL_NODE_PROPERTIES.includes(key) && !TS_UTILS_HELPERS.includes(key)) result[key] = this.server.context[key];
|
|
126
|
+
return result;
|
|
127
|
+
}, {});
|
|
128
|
+
console.log(inspect(context, false, 1, true));
|
|
129
|
+
}
|
|
130
|
+
#printCustomMethodsHelp() {
|
|
131
|
+
console.log("");
|
|
132
|
+
console.log(this.colors.green("GLOBAL METHODS:"));
|
|
133
|
+
Object.keys(this.#customMethods).forEach((method) => {
|
|
134
|
+
const { options } = this.#customMethods[method];
|
|
135
|
+
const usage = this.colors.yellow(options.usage || method);
|
|
136
|
+
const spaces = " ".repeat(this.#longestCustomMethodName - options.width + 2);
|
|
137
|
+
const description = this.colors.dim(options.description || "");
|
|
138
|
+
console.log(`${usage}${spaces}${description}`);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
#ls() {
|
|
142
|
+
this.#printCustomMethodsHelp();
|
|
143
|
+
this.#printContextHelp();
|
|
144
|
+
this.server.displayPrompt();
|
|
145
|
+
}
|
|
146
|
+
notify(message) {
|
|
147
|
+
console.log(this.colors.yellow().italic(message));
|
|
148
|
+
if (this.server) this.server.displayPrompt();
|
|
149
|
+
}
|
|
150
|
+
ready(callback) {
|
|
151
|
+
this.#onReadyCallbacks.push(callback);
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
addMethod(name, handler, options) {
|
|
155
|
+
const width = stringWidth(options?.usage || name);
|
|
156
|
+
if (width > this.#longestCustomMethodName) this.#longestCustomMethodName = width;
|
|
157
|
+
this.#customMethods[name] = {
|
|
158
|
+
handler,
|
|
159
|
+
options: Object.assign({ width }, options)
|
|
160
|
+
};
|
|
161
|
+
if (this.server) this.#registerCustomMethodWithContext(name);
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
getMethods() {
|
|
165
|
+
return this.#customMethods;
|
|
166
|
+
}
|
|
167
|
+
useCompiler(compiler) {
|
|
168
|
+
this.#compiler = compiler;
|
|
169
|
+
return this;
|
|
170
|
+
}
|
|
171
|
+
start(context) {
|
|
172
|
+
console.log("");
|
|
173
|
+
this.notify("Type \".ls\" to a view list of available context methods/properties");
|
|
174
|
+
this.server = start({
|
|
175
|
+
prompt: `> ${this.#compiler?.supportsTypescript ? "(ts) " : "(js) "}`,
|
|
176
|
+
input: process.stdin,
|
|
177
|
+
output: process.stdout,
|
|
178
|
+
terminal: process.stdout.isTTY && !Number.parseInt(process.env.NODE_NO_READLINE, 10),
|
|
179
|
+
useGlobal: true,
|
|
180
|
+
writer(output) {
|
|
181
|
+
return inspect(output, {
|
|
182
|
+
showProxy: false,
|
|
183
|
+
colors: true
|
|
184
|
+
});
|
|
185
|
+
},
|
|
186
|
+
...this.#replOptions
|
|
187
|
+
});
|
|
188
|
+
if (context) Object.keys(context).forEach((key) => {
|
|
189
|
+
this.server.context[key] = context[key];
|
|
190
|
+
});
|
|
191
|
+
this.server.defineCommand("ls", {
|
|
192
|
+
help: "View list of available context methods/properties",
|
|
193
|
+
action: this.#ls.bind(this)
|
|
194
|
+
});
|
|
195
|
+
this.#setupContext();
|
|
196
|
+
this.#setupHistory();
|
|
197
|
+
this.#originalEval = this.server.eval;
|
|
198
|
+
this.server.eval = this.#eval.bind(this);
|
|
199
|
+
this.server.displayPrompt();
|
|
200
|
+
this.#onReadyCallbacks.forEach((callback) => callback(this));
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
306
203
|
};
|
|
204
|
+
export { Repl };
|
package/build/src/repl.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import type { Colors } from '@poppinss/colors/types';
|
|
2
2
|
import { type REPLServer, type ReplOptions } from 'node:repl';
|
|
3
|
-
import type { MethodCallback, MethodOptions, Compiler } from './types.
|
|
3
|
+
import type { MethodCallback, MethodOptions, Compiler } from './types.ts';
|
|
4
|
+
/**
|
|
5
|
+
* A REPL (Read-Eval-Print Loop) server implementation that provides an interactive
|
|
6
|
+
* command line interface for executing JavaScript/TypeScript code with custom methods
|
|
7
|
+
* and context management.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const repl = new Repl({ historyFilePath: '.repl_history' })
|
|
11
|
+
*
|
|
12
|
+
* repl.addMethod('greet', (repl, name) => `Hello ${name}!`, {
|
|
13
|
+
* description: 'Greets a person',
|
|
14
|
+
* usage: 'greet (name)'
|
|
15
|
+
* })
|
|
16
|
+
*
|
|
17
|
+
* repl.start({ myVar: 'Hello World' })
|
|
18
|
+
*/
|
|
4
19
|
export declare class Repl {
|
|
5
20
|
#private;
|
|
6
21
|
/**
|
|
@@ -12,24 +27,65 @@ export declare class Repl {
|
|
|
12
27
|
* is invoked
|
|
13
28
|
*/
|
|
14
29
|
server?: REPLServer;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new REPL instance with optional configuration
|
|
32
|
+
*
|
|
33
|
+
* @param options - Configuration options for the REPL
|
|
34
|
+
* @param options.compiler - Custom compiler for transforming user input
|
|
35
|
+
* @param options.historyFilePath - Path to store command history
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const repl = new Repl({
|
|
39
|
+
* historyFilePath: '.repl_history',
|
|
40
|
+
* compiler: myTypeScriptCompiler
|
|
41
|
+
* })
|
|
42
|
+
*/
|
|
15
43
|
constructor(options?: {
|
|
16
44
|
compiler?: Compiler;
|
|
17
45
|
historyFilePath?: string;
|
|
18
46
|
} & ReplOptions);
|
|
19
47
|
/**
|
|
20
48
|
* Notify by writing to the console
|
|
49
|
+
*
|
|
50
|
+
* @param message - The message to display
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* repl.notify('Server connected successfully')
|
|
21
54
|
*/
|
|
22
55
|
notify(message: string): void;
|
|
23
56
|
/**
|
|
24
57
|
* Register a callback to be invoked once the server is ready
|
|
58
|
+
*
|
|
59
|
+
* @param callback - Function to call when the REPL is ready
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* repl.ready((repl) => {
|
|
63
|
+
* repl.notify('REPL is ready!')
|
|
64
|
+
* })
|
|
25
65
|
*/
|
|
26
66
|
ready(callback: (repl: Repl) => void): this;
|
|
27
67
|
/**
|
|
28
68
|
* Register a custom loader function to be added to the context
|
|
69
|
+
*
|
|
70
|
+
* @param name - The name of the method
|
|
71
|
+
* @param handler - The function to execute
|
|
72
|
+
* @param options - Optional configuration for the method
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* repl.addMethod('greet', (repl, name) => {
|
|
76
|
+
* return `Hello ${name}!`
|
|
77
|
+
* }, {
|
|
78
|
+
* description: 'Greets a person by name',
|
|
79
|
+
* usage: 'greet (name)'
|
|
80
|
+
* })
|
|
29
81
|
*/
|
|
30
82
|
addMethod(name: string, handler: MethodCallback, options?: MethodOptions): this;
|
|
31
83
|
/**
|
|
32
84
|
* Returns the collection of registered methods
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* const methods = repl.getMethods()
|
|
88
|
+
* console.log(Object.keys(methods)) // ['clear', 'p', 'myCustomMethod']
|
|
33
89
|
*/
|
|
34
90
|
getMethods(): {
|
|
35
91
|
[name: string]: {
|
|
@@ -42,10 +98,27 @@ export declare class Repl {
|
|
|
42
98
|
/**
|
|
43
99
|
* Register a compiler. Make sure register the compiler before
|
|
44
100
|
* calling the start method
|
|
101
|
+
*
|
|
102
|
+
* @param compiler - The compiler instance to use for transforming code
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* const tsCompiler = {
|
|
106
|
+
* compile: (code, filename) => ts.transpile(code),
|
|
107
|
+
* supportsTypescript: true
|
|
108
|
+
* }
|
|
109
|
+
* repl.useCompiler(tsCompiler)
|
|
45
110
|
*/
|
|
46
111
|
useCompiler(compiler: Compiler): this;
|
|
47
112
|
/**
|
|
48
113
|
* Start the REPL server
|
|
114
|
+
*
|
|
115
|
+
* @param context - Optional initial context to populate the REPL with
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* repl.start({
|
|
119
|
+
* db: databaseConnection,
|
|
120
|
+
* utils: myUtilities
|
|
121
|
+
* })
|
|
49
122
|
*/
|
|
50
123
|
start(context?: Record<string, any>): this;
|
|
51
124
|
}
|
package/build/src/types.d.ts
CHANGED
package/build/src/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/repl",
|
|
3
3
|
"description": "REPL for AdonisJS",
|
|
4
|
-
"version": "5.0.0-next.
|
|
4
|
+
"version": "5.0.0-next.2",
|
|
5
5
|
"engines": {
|
|
6
|
-
"node": ">=
|
|
6
|
+
"node": ">=24.0.0"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
@@ -23,29 +23,30 @@
|
|
|
23
23
|
"typecheck": "tsc --noEmit",
|
|
24
24
|
"clean": "del-cli build",
|
|
25
25
|
"precompile": "npm run lint && npm run clean",
|
|
26
|
-
"compile": "
|
|
26
|
+
"compile": "tsdown && tsc --emitDeclarationOnly --declaration",
|
|
27
27
|
"build": "npm run compile",
|
|
28
28
|
"version": "npm run build",
|
|
29
29
|
"prepublishOnly": "npm run build",
|
|
30
30
|
"release": "release-it"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@adonisjs/eslint-config": "^3.0.0-next.
|
|
33
|
+
"@adonisjs/eslint-config": "^3.0.0-next.5",
|
|
34
34
|
"@adonisjs/prettier-config": "^1.4.5",
|
|
35
|
-
"@adonisjs/tsconfig": "^2.0.0-next.
|
|
35
|
+
"@adonisjs/tsconfig": "^2.0.0-next.3",
|
|
36
36
|
"@poppinss/ts-exec": "^1.4.1",
|
|
37
|
-
"@release-it/conventional-changelog": "^10.0.
|
|
38
|
-
"@types/node": "^
|
|
39
|
-
"del-cli": "^
|
|
40
|
-
"eslint": "^9.
|
|
41
|
-
"prettier": "^3.
|
|
42
|
-
"release-it": "^19.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
37
|
+
"@release-it/conventional-changelog": "^10.0.4",
|
|
38
|
+
"@types/node": "^25.0.8",
|
|
39
|
+
"del-cli": "^7.0.0",
|
|
40
|
+
"eslint": "^9.39.2",
|
|
41
|
+
"prettier": "^3.8.0",
|
|
42
|
+
"release-it": "^19.2.3",
|
|
43
|
+
"tsdown": "^0.19.0",
|
|
44
|
+
"typedoc": "^0.28.16",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
45
46
|
},
|
|
46
47
|
"dependencies": {
|
|
47
|
-
"@poppinss/colors": "^4.1.
|
|
48
|
-
"string-width": "^
|
|
48
|
+
"@poppinss/colors": "^4.1.6",
|
|
49
|
+
"string-width": "^8.1.0"
|
|
49
50
|
},
|
|
50
51
|
"homepage": "https://github.com/adonisjs/repl#readme",
|
|
51
52
|
"repository": {
|
|
@@ -66,7 +67,7 @@
|
|
|
66
67
|
"access": "public",
|
|
67
68
|
"provenance": true
|
|
68
69
|
},
|
|
69
|
-
"
|
|
70
|
+
"tsdown": {
|
|
70
71
|
"entry": [
|
|
71
72
|
"./index.ts",
|
|
72
73
|
"./src/types.ts"
|
|
@@ -74,8 +75,11 @@
|
|
|
74
75
|
"outDir": "./build",
|
|
75
76
|
"clean": true,
|
|
76
77
|
"format": "esm",
|
|
78
|
+
"minify": "dce-only",
|
|
79
|
+
"fixedExtension": false,
|
|
77
80
|
"dts": false,
|
|
78
|
-
"
|
|
81
|
+
"treeshake": false,
|
|
82
|
+
"sourcemaps": false,
|
|
79
83
|
"target": "esnext"
|
|
80
84
|
},
|
|
81
85
|
"release-it": {
|