@adonisjs/repl 4.0.0-0 → 4.0.0-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 +0 -1
- package/build/index.js +8 -0
- package/build/src/repl.d.ts +23 -4
- package/build/src/repl.js +139 -7
- package/build/src/{types/main.d.ts → types.d.ts} +12 -2
- package/{index.ts → build/src/types.js} +1 -4
- package/package.json +20 -56
- package/build/commands/adonis_repl.d.ts +0 -9
- package/build/commands/adonis_repl.d.ts.map +0 -1
- package/build/commands/adonis_repl.js +0 -17
- package/build/commands/commands.json +0 -1
- package/build/commands/main.js +0 -36
- package/build/index.d.ts.map +0 -1
- package/build/providers/repl_provider.d.ts +0 -8
- package/build/providers/repl_provider.d.ts.map +0 -1
- package/build/providers/repl_provider.js +0 -40
- package/build/src/adonis_bindings.d.ts +0 -4
- package/build/src/adonis_bindings.d.ts.map +0 -1
- package/build/src/adonis_bindings.js +0 -26
- package/build/src/colorizer.d.ts +0 -5
- package/build/src/colorizer.d.ts.map +0 -1
- package/build/src/colorizer.js +0 -39
- package/build/src/repl.d.ts.map +0 -1
- package/build/src/types/extended.d.ts +0 -7
- package/build/src/types/extended.d.ts.map +0 -1
- package/build/src/types/extended.js +0 -1
- package/build/src/types/main.d.ts.map +0 -1
- package/build/src/types/main.js +0 -1
- package/build/src/utils.d.ts +0 -2
- package/build/src/utils.d.ts.map +0 -1
- package/build/src/utils.js +0 -11
- package/commands/adonis_repl.ts +0 -38
- package/providers/repl_provider.ts +0 -61
- package/src/adonis_bindings.ts +0 -63
- package/src/colorizer.ts +0 -62
- package/src/repl.ts +0 -423
- package/src/types/extended.ts +0 -16
- package/src/types/main.ts +0 -33
- package/src/utils.ts +0 -14
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
package/build/src/repl.d.ts
CHANGED
|
@@ -1,17 +1,36 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
1
|
+
/// <reference types="@types/node" resolution-mode="require"/>
|
|
2
|
+
import type { Colors } from '@poppinss/colors/types';
|
|
2
3
|
import { REPLServer } from 'node:repl';
|
|
3
|
-
import { Handler, ContextOptions, Compiler } from './types
|
|
4
|
+
import { Handler, ContextOptions, Compiler } from './types.js';
|
|
4
5
|
export declare class Repl {
|
|
5
6
|
#private;
|
|
6
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Colors reference
|
|
9
|
+
*/
|
|
10
|
+
colors: Colors;
|
|
11
|
+
/**
|
|
12
|
+
* Reference to the repl server. Available after the `start` method
|
|
13
|
+
* is invoked
|
|
14
|
+
*/
|
|
7
15
|
server?: REPLServer;
|
|
8
16
|
constructor(options?: {
|
|
9
17
|
compiler?: Compiler;
|
|
10
18
|
historyFilePath?: string;
|
|
11
19
|
});
|
|
20
|
+
/**
|
|
21
|
+
* Notify by writing to the console
|
|
22
|
+
*/
|
|
12
23
|
notify(message: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* Start the REPL server
|
|
26
|
+
*/
|
|
13
27
|
start(): this;
|
|
28
|
+
/**
|
|
29
|
+
* Register a callback to be invoked once the server is ready
|
|
30
|
+
*/
|
|
14
31
|
ready(callback: (repl: Repl) => void): this;
|
|
32
|
+
/**
|
|
33
|
+
* Register a custom loader function to be added to the context
|
|
34
|
+
*/
|
|
15
35
|
addMethod(name: string, handler: Handler, options?: ContextOptions): this;
|
|
16
36
|
}
|
|
17
|
-
//# sourceMappingURL=repl.d.ts.map
|
package/build/src/repl.js
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @adonisjs/repl
|
|
3
|
+
*
|
|
4
|
+
* (c) AdonisJS
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
1
9
|
import useColors from '@poppinss/colors';
|
|
2
|
-
import { Recoverable } from 'node:repl';
|
|
3
|
-
import prettyRepl from 'pretty-repl';
|
|
10
|
+
import { Recoverable, start as startRepl } from 'node:repl';
|
|
4
11
|
import stringWidth from 'string-width';
|
|
5
12
|
import { inspect, promisify as utilPromisify } from 'node:util';
|
|
6
|
-
|
|
13
|
+
/**
|
|
14
|
+
* List of node global properties to remove from the
|
|
15
|
+
* ls inspect
|
|
16
|
+
*/
|
|
7
17
|
const GLOBAL_NODE_PROPERTIES = [
|
|
8
18
|
'performance',
|
|
9
19
|
'global',
|
|
@@ -55,27 +65,71 @@ const icons = process.platform === 'win32' && !process.env.WT_SESSION
|
|
|
55
65
|
? { tick: '√', pointer: '>' }
|
|
56
66
|
: { tick: '✔', pointer: '❯' };
|
|
57
67
|
export class Repl {
|
|
68
|
+
/**
|
|
69
|
+
* Length of the longest custom method name. We need to show a
|
|
70
|
+
* symmetric view of custom methods and their description
|
|
71
|
+
*/
|
|
58
72
|
#longestCustomMethodName = 0;
|
|
73
|
+
/**
|
|
74
|
+
* Reference to the original `eval` method of the repl server.
|
|
75
|
+
* Since we are monkey patching it, we need a reference to it
|
|
76
|
+
* to call it after our custom logic
|
|
77
|
+
*/
|
|
59
78
|
#originalEval = null;
|
|
60
|
-
|
|
61
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Compiler that will transform the user input just
|
|
81
|
+
* before evaluation
|
|
82
|
+
*/
|
|
62
83
|
#compiler;
|
|
84
|
+
/**
|
|
85
|
+
* Set of registered ready callbacks
|
|
86
|
+
*/
|
|
63
87
|
#onReadyCallbacks = [];
|
|
88
|
+
/**
|
|
89
|
+
* A set of registered custom methods
|
|
90
|
+
*/
|
|
64
91
|
#customMethods = {};
|
|
92
|
+
/**
|
|
93
|
+
* Path to the history file
|
|
94
|
+
*/
|
|
65
95
|
#historyFilePath;
|
|
96
|
+
/**
|
|
97
|
+
* Colors reference
|
|
98
|
+
*/
|
|
99
|
+
colors = useColors.ansi();
|
|
100
|
+
/**
|
|
101
|
+
* Reference to the repl server. Available after the `start` method
|
|
102
|
+
* is invoked
|
|
103
|
+
*/
|
|
104
|
+
server;
|
|
66
105
|
constructor(options) {
|
|
67
106
|
this.#compiler = options?.compiler;
|
|
68
107
|
this.#historyFilePath = options?.historyFilePath;
|
|
69
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Prints the welcome message
|
|
111
|
+
*/
|
|
70
112
|
#printWelcomeMessage() {
|
|
71
113
|
console.log('');
|
|
114
|
+
/**
|
|
115
|
+
* Log about typescript support
|
|
116
|
+
*/
|
|
72
117
|
if (this.#compiler?.supportsTypescript) {
|
|
73
118
|
console.log(`${this.colors.green(icons.tick)} ${this.colors.dim('typescript compilation supported')}`);
|
|
74
119
|
console.log('');
|
|
75
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Log about help command
|
|
123
|
+
*/
|
|
76
124
|
this.notify('Type ".ls" to a view list of available context methods/properties');
|
|
77
125
|
}
|
|
126
|
+
/**
|
|
127
|
+
* Setup context with default globals
|
|
128
|
+
*/
|
|
78
129
|
#setupContext() {
|
|
130
|
+
/**
|
|
131
|
+
* Register "clear" method
|
|
132
|
+
*/
|
|
79
133
|
this.addMethod('clear', function clear(repl, key) {
|
|
80
134
|
if (!key) {
|
|
81
135
|
console.log(repl.colors.red('Define a property name to remove from the context'));
|
|
@@ -88,22 +142,43 @@ export class Repl {
|
|
|
88
142
|
description: 'Clear a property from the REPL context',
|
|
89
143
|
usage: `clear ${this.colors.gray('(propertyName)')}`,
|
|
90
144
|
});
|
|
145
|
+
/**
|
|
146
|
+
* Register "p" method
|
|
147
|
+
*/
|
|
91
148
|
this.addMethod('p', function promisify(_, fn) {
|
|
92
149
|
return utilPromisify(fn);
|
|
93
150
|
}, {
|
|
94
151
|
description: 'Promisify a function. Similar to Node.js "util.promisify"',
|
|
95
152
|
usage: `p ${this.colors.gray('(function)')}`,
|
|
96
153
|
});
|
|
154
|
+
/**
|
|
155
|
+
* Register all custom methods with the context
|
|
156
|
+
*/
|
|
97
157
|
this.#registerCustomMethodsWithContext();
|
|
98
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Register custom methods with the server context
|
|
161
|
+
*/
|
|
99
162
|
#registerCustomMethodsWithContext() {
|
|
100
163
|
Object.keys(this.#customMethods).forEach((name) => {
|
|
101
164
|
this.#registerCustomMethodWithContext(name);
|
|
102
165
|
});
|
|
103
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Find if the error is recoverable or not
|
|
169
|
+
*/
|
|
104
170
|
#isRecoverableError(error) {
|
|
105
171
|
return /^(Unexpected end of input|Unexpected token|' expected)/.test(error.message);
|
|
106
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Custom eval method to execute the user code
|
|
175
|
+
*
|
|
176
|
+
* Basically we are monkey patching the original eval method.
|
|
177
|
+
* The reason why we need to do that is because we want :
|
|
178
|
+
* - to compile the user code before executing it
|
|
179
|
+
* - and also benefit from the original eval method that supports
|
|
180
|
+
* cool features like top level await.
|
|
181
|
+
*/
|
|
107
182
|
#eval(code, context, filename, callback) {
|
|
108
183
|
try {
|
|
109
184
|
const compiled = this.#compiler.compile(code, filename)
|
|
@@ -119,6 +194,9 @@ export class Repl {
|
|
|
119
194
|
callback(error, null);
|
|
120
195
|
}
|
|
121
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Setup history file
|
|
199
|
+
*/
|
|
122
200
|
#setupHistory() {
|
|
123
201
|
if (!this.#historyFilePath) {
|
|
124
202
|
return;
|
|
@@ -132,7 +210,13 @@ export class Repl {
|
|
|
132
210
|
process.exit(1);
|
|
133
211
|
});
|
|
134
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Prints the help for the context properties
|
|
215
|
+
*/
|
|
135
216
|
#printContextHelp() {
|
|
217
|
+
/**
|
|
218
|
+
* Print context properties
|
|
219
|
+
*/
|
|
136
220
|
console.log('');
|
|
137
221
|
console.log(this.colors.green('CONTEXT PROPERTIES/METHODS:'));
|
|
138
222
|
const context = Object.keys(this.server.context).reduce((result, key) => {
|
|
@@ -145,7 +229,13 @@ export class Repl {
|
|
|
145
229
|
}, {});
|
|
146
230
|
console.log(inspect(context, false, 1, true));
|
|
147
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* Prints the help for the custom methods
|
|
234
|
+
*/
|
|
148
235
|
#printCustomMethodsHelp() {
|
|
236
|
+
/**
|
|
237
|
+
* Print loader methods
|
|
238
|
+
*/
|
|
149
239
|
console.log('');
|
|
150
240
|
console.log(this.colors.green('GLOBAL METHODS:'));
|
|
151
241
|
Object.keys(this.#customMethods).forEach((method) => {
|
|
@@ -159,53 +249,95 @@ export class Repl {
|
|
|
159
249
|
if (!customMethod) {
|
|
160
250
|
return;
|
|
161
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* Wrap handler
|
|
254
|
+
*/
|
|
162
255
|
const handler = (...args) => customMethod.handler(this, ...args);
|
|
256
|
+
/**
|
|
257
|
+
* Re-define the function name to be more description
|
|
258
|
+
*/
|
|
163
259
|
Object.defineProperty(handler, 'name', { value: customMethod.handler.name });
|
|
260
|
+
/**
|
|
261
|
+
* Register with the context
|
|
262
|
+
*/
|
|
164
263
|
this.server.context[name] = handler;
|
|
165
264
|
}
|
|
265
|
+
/**
|
|
266
|
+
* Prints the context to the console
|
|
267
|
+
*/
|
|
166
268
|
#ls() {
|
|
167
269
|
this.#printCustomMethodsHelp();
|
|
168
270
|
this.#printContextHelp();
|
|
169
271
|
this.server.displayPrompt();
|
|
170
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Notify by writing to the console
|
|
275
|
+
*/
|
|
171
276
|
notify(message) {
|
|
172
277
|
console.log(this.colors.yellow().italic(message));
|
|
173
278
|
if (this.server) {
|
|
174
279
|
this.server.displayPrompt();
|
|
175
280
|
}
|
|
176
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Start the REPL server
|
|
284
|
+
*/
|
|
177
285
|
start() {
|
|
178
286
|
this.#printWelcomeMessage();
|
|
179
|
-
this.server =
|
|
287
|
+
this.server = startRepl({
|
|
180
288
|
prompt: '> ',
|
|
181
289
|
input: process.stdin,
|
|
182
290
|
output: process.stdout,
|
|
183
291
|
terminal: process.stdout.isTTY && !Number.parseInt(process.env.NODE_NO_READLINE, 10),
|
|
184
292
|
useGlobal: true,
|
|
185
|
-
colorize: colorizer(),
|
|
186
293
|
});
|
|
294
|
+
/**
|
|
295
|
+
* Define the `ls` command
|
|
296
|
+
*/
|
|
187
297
|
this.server.defineCommand('ls', {
|
|
188
298
|
help: 'View list of available context methods/properties',
|
|
189
299
|
action: this.#ls.bind(this),
|
|
190
300
|
});
|
|
301
|
+
/**
|
|
302
|
+
* Setup context and history
|
|
303
|
+
*/
|
|
191
304
|
this.#setupContext();
|
|
192
305
|
this.#setupHistory();
|
|
306
|
+
/**
|
|
307
|
+
* Monkey patch the eval method
|
|
308
|
+
*/
|
|
193
309
|
this.#originalEval = this.server.eval;
|
|
310
|
+
// @ts-ignore
|
|
194
311
|
this.server.eval = this.#eval.bind(this);
|
|
312
|
+
/**
|
|
313
|
+
* Display prompt
|
|
314
|
+
*/
|
|
195
315
|
this.server.displayPrompt();
|
|
316
|
+
/**
|
|
317
|
+
* Execute onReady callbacks
|
|
318
|
+
*/
|
|
196
319
|
this.#onReadyCallbacks.forEach((callback) => callback(this));
|
|
197
320
|
return this;
|
|
198
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Register a callback to be invoked once the server is ready
|
|
324
|
+
*/
|
|
199
325
|
ready(callback) {
|
|
200
326
|
this.#onReadyCallbacks.push(callback);
|
|
201
327
|
return this;
|
|
202
328
|
}
|
|
329
|
+
/**
|
|
330
|
+
* Register a custom loader function to be added to the context
|
|
331
|
+
*/
|
|
203
332
|
addMethod(name, handler, options) {
|
|
204
333
|
const width = stringWidth(options?.usage || name);
|
|
205
334
|
if (width > this.#longestCustomMethodName) {
|
|
206
335
|
this.#longestCustomMethodName = width;
|
|
207
336
|
}
|
|
208
337
|
this.#customMethods[name] = { handler, options: Object.assign({ width }, options) };
|
|
338
|
+
/**
|
|
339
|
+
* Register method right away when server has been started
|
|
340
|
+
*/
|
|
209
341
|
if (this.server) {
|
|
210
342
|
this.#registerCustomMethodWithContext(name);
|
|
211
343
|
}
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import { Repl } from '
|
|
1
|
+
import { Repl } from './repl.js';
|
|
2
|
+
/**
|
|
3
|
+
* Custom method handler
|
|
4
|
+
*/
|
|
2
5
|
export type Handler = (repl: Repl, ...args: any[]) => any;
|
|
6
|
+
/**
|
|
7
|
+
* Options that can be set when defining a loader
|
|
8
|
+
* method
|
|
9
|
+
*/
|
|
3
10
|
export type ContextOptions = {
|
|
4
11
|
description?: string;
|
|
5
12
|
usage?: string;
|
|
6
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Shape of the Compiler that must be passed to the
|
|
16
|
+
* repl constructor
|
|
17
|
+
*/
|
|
7
18
|
export type Compiler = {
|
|
8
19
|
compile: (code: string, fileName: string) => string;
|
|
9
20
|
supportsTypescript: boolean;
|
|
10
21
|
};
|
|
11
|
-
//# sourceMappingURL=main.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,98 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adonisjs/repl",
|
|
3
3
|
"description": "REPL for AdonisJS",
|
|
4
|
-
"version": "4.0.0-
|
|
4
|
+
"version": "4.0.0-2",
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=18.16.0"
|
|
7
|
+
},
|
|
5
8
|
"main": "build/index.js",
|
|
6
9
|
"type": "module",
|
|
7
10
|
"files": [
|
|
8
|
-
"commands",
|
|
9
|
-
"index.ts",
|
|
10
|
-
"configure.ts",
|
|
11
|
-
"src",
|
|
12
|
-
"services",
|
|
13
|
-
"providers",
|
|
14
|
-
"factories",
|
|
15
|
-
"build/configure.js",
|
|
16
|
-
"build/configure.d.ts",
|
|
17
|
-
"build/configure.d.ts.map",
|
|
18
|
-
"build/index.js",
|
|
19
|
-
"build/index.d.ts",
|
|
20
|
-
"build/index.d.ts.map",
|
|
21
11
|
"build/src",
|
|
22
|
-
"build/services",
|
|
23
|
-
"build/providers",
|
|
24
|
-
"build/commands",
|
|
25
12
|
"build/factories",
|
|
26
|
-
"build/stubs",
|
|
27
13
|
"build/index.d.ts",
|
|
28
|
-
"build/index.d.ts.map",
|
|
29
14
|
"build/index.js"
|
|
30
15
|
],
|
|
31
16
|
"exports": {
|
|
32
17
|
".": "./build/index.js",
|
|
33
|
-
"./
|
|
34
|
-
"./commands/*": "./build/commands/*.js",
|
|
35
|
-
"./providers/repl_provider": "./build/providers/repl_provider.js",
|
|
36
|
-
"./services/main": "./build/services/main.js",
|
|
37
|
-
"./types": "./build/src/types/main.js"
|
|
18
|
+
"./types": "./build/src/types.js"
|
|
38
19
|
},
|
|
39
20
|
"scripts": {
|
|
40
21
|
"pretest": "npm run lint",
|
|
41
22
|
"test": "c8 npm run quick:test",
|
|
42
23
|
"lint": "eslint . --ext=.ts",
|
|
43
24
|
"clean": "del-cli build",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"compile": "npm run lint && npm run clean && tsc",
|
|
46
27
|
"build": "npm run compile",
|
|
47
28
|
"release": "np --message=\"chore(release): %s\"",
|
|
48
29
|
"version": "npm run build",
|
|
49
30
|
"sync-labels": "github-label-sync --labels .github/labels.json adonisjs/repl",
|
|
50
|
-
"quick:test": "node --loader=ts-node/esm bin/test.ts",
|
|
31
|
+
"quick:test": "node --enable-source-maps --loader=ts-node/esm bin/test.ts",
|
|
51
32
|
"format": "prettier --write .",
|
|
52
|
-
"prepublishOnly": "npm run build"
|
|
53
|
-
"index:commands": "adonis-kit index build/commands"
|
|
33
|
+
"prepublishOnly": "npm run build"
|
|
54
34
|
},
|
|
55
35
|
"devDependencies": {
|
|
56
36
|
"@adonisjs/core": "^6.1.5-4",
|
|
57
|
-
"@adonisjs/eslint-config": "^1.1.
|
|
58
|
-
"@adonisjs/prettier-config": "^1.1.
|
|
59
|
-
"@adonisjs/tsconfig": "^1.1.
|
|
60
|
-
"@japa/assert": "^
|
|
61
|
-
"@japa/file-system": "^
|
|
62
|
-
"@japa/
|
|
63
|
-
"@
|
|
64
|
-
"@
|
|
65
|
-
"@swc/core": "^1.3.66",
|
|
66
|
-
"@types/node": "^20.3.1",
|
|
37
|
+
"@adonisjs/eslint-config": "^1.1.7",
|
|
38
|
+
"@adonisjs/prettier-config": "^1.1.7",
|
|
39
|
+
"@adonisjs/tsconfig": "^1.1.7",
|
|
40
|
+
"@japa/assert": "^2.0.0-1",
|
|
41
|
+
"@japa/file-system": "^2.0.0-1",
|
|
42
|
+
"@japa/runner": "^3.0.0-2",
|
|
43
|
+
"@swc/core": "^1.3.67",
|
|
44
|
+
"@types/node": "^20.3.3",
|
|
67
45
|
"c8": "^8.0.0",
|
|
68
46
|
"copyfiles": "^2.4.1",
|
|
69
47
|
"del-cli": "^5.0.0",
|
|
70
|
-
"eslint": "^8.
|
|
48
|
+
"eslint": "^8.44.0",
|
|
71
49
|
"github-label-sync": "^2.3.1",
|
|
72
50
|
"husky": "^8.0.3",
|
|
73
|
-
"np": "^
|
|
51
|
+
"np": "^8.0.4",
|
|
74
52
|
"prettier": "^2.8.8",
|
|
75
53
|
"ts-node": "^10.9.1",
|
|
76
54
|
"typescript": "^5.1.3"
|
|
77
55
|
},
|
|
78
56
|
"dependencies": {
|
|
79
57
|
"@poppinss/colors": "4.1.0-2",
|
|
80
|
-
"emphasize": "^6.0.0",
|
|
81
|
-
"pretty-repl": "^4.0.0",
|
|
82
58
|
"string-width": "^6.1.0"
|
|
83
59
|
},
|
|
84
|
-
"peerDependencies": {
|
|
85
|
-
"@adonisjs/core": "^6.1.5-4",
|
|
86
|
-
"ts-node": "^10.4.0"
|
|
87
|
-
},
|
|
88
|
-
"peerDependenciesMeta": {
|
|
89
|
-
"@adonisjs/core": {
|
|
90
|
-
"optional": true
|
|
91
|
-
},
|
|
92
|
-
"ts-node": {
|
|
93
|
-
"optional": true
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
60
|
"author": "virk,julien-r44,adonisjs",
|
|
97
61
|
"license": "MIT",
|
|
98
62
|
"homepage": "https://github.com/adonisjs/repl#readme",
|
|
@@ -109,7 +73,7 @@
|
|
|
109
73
|
"node-repl"
|
|
110
74
|
],
|
|
111
75
|
"eslintConfig": {
|
|
112
|
-
"extends": "@adonisjs/eslint-config/
|
|
76
|
+
"extends": "@adonisjs/eslint-config/package"
|
|
113
77
|
},
|
|
114
78
|
"prettier": "@adonisjs/prettier-config",
|
|
115
79
|
"commitlint": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
-
import { CommandOptions } from '@adonisjs/core/types/ace';
|
|
3
|
-
export default class ReplCommand extends BaseCommand {
|
|
4
|
-
static commandName: string;
|
|
5
|
-
static description: string;
|
|
6
|
-
static options: CommandOptions;
|
|
7
|
-
run(): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=adonis_repl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adonis_repl.d.ts","sourceRoot":"","sources":["../../commands/adonis_repl.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEzD,MAAM,CAAC,OAAO,OAAO,WAAY,SAAQ,WAAW;IAClD,MAAM,CAAC,WAAW,SAAS;IAC3B,MAAM,CAAC,WAAW,SAA6B;IAE/C,MAAM,CAAC,OAAO,EAAE,cAAc,CAG7B;IAEK,GAAG;CAgBV"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from '@adonisjs/core/ace';
|
|
2
|
-
export default class ReplCommand extends BaseCommand {
|
|
3
|
-
static commandName = 'repl';
|
|
4
|
-
static description = 'Start a new REPL session';
|
|
5
|
-
static options = {
|
|
6
|
-
startApp: true,
|
|
7
|
-
staysAlive: true,
|
|
8
|
-
};
|
|
9
|
-
async run() {
|
|
10
|
-
this.app.container.resolving('router', (router) => router.commit());
|
|
11
|
-
const repl = await this.app.container.make('repl');
|
|
12
|
-
repl.start();
|
|
13
|
-
repl.server.on('exit', async () => {
|
|
14
|
-
await this.app.terminate();
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"commands":[{"commandName":"repl","description":"Start a new REPL session","help":"","namespace":null,"aliases":[],"flags":[],"args":[],"options":{"startApp":true,"staysAlive":true},"filePath":"adonis_repl.js"}],"version":1}
|
package/build/commands/main.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'node:fs/promises'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory cache of commands after they have been loaded
|
|
5
|
-
*/
|
|
6
|
-
let commandsMetaData
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Reads the commands from the "./commands.json" file. Since, the commands.json
|
|
10
|
-
* file is generated automatically, we do not have to validate its contents
|
|
11
|
-
*/
|
|
12
|
-
export async function getMetaData() {
|
|
13
|
-
if (commandsMetaData) {
|
|
14
|
-
return commandsMetaData
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const commandsIndex = await readFile(new URL('./commands.json', import.meta.url), 'utf-8')
|
|
18
|
-
commandsMetaData = JSON.parse(commandsIndex).commands
|
|
19
|
-
|
|
20
|
-
return commandsMetaData
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Imports the command by lookingup its path from the commands
|
|
25
|
-
* metadata
|
|
26
|
-
*/
|
|
27
|
-
export async function getCommand(metaData) {
|
|
28
|
-
const commands = await getMetaData()
|
|
29
|
-
const command = commands.find(({ commandName }) => metaData.commandName === commandName)
|
|
30
|
-
if (!command) {
|
|
31
|
-
return null
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const { default: commandConstructor } = await import(new URL(command.filePath, import.meta.url).href)
|
|
35
|
-
return commandConstructor
|
|
36
|
-
}
|
package/build/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AASA,OAAO,yBAAyB,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"repl_provider.d.ts","sourceRoot":"","sources":["../../providers/repl_provider.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAKzD,MAAM,CAAC,OAAO,OAAO,YAAY;;IACnB,SAAS,CAAC,GAAG,EAAE,kBAAkB;gBAAvB,GAAG,EAAE,kBAAkB;IAwB7C,QAAQ;CAmBT"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { join } from 'node:path';
|
|
2
|
-
import { homedir } from 'node:os';
|
|
3
|
-
import { isModuleInstalled } from '../src/utils.js';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { defineReplBindings } from '../src/adonis_bindings.js';
|
|
6
|
-
export default class ReplProvider {
|
|
7
|
-
app;
|
|
8
|
-
constructor(app) {
|
|
9
|
-
this.app = app;
|
|
10
|
-
}
|
|
11
|
-
async #createCompiler() {
|
|
12
|
-
const { create } = await import('ts-node');
|
|
13
|
-
const tsConfigPath = new URL('./tsconfig.json', this.app.appRoot);
|
|
14
|
-
const tsNode = create({
|
|
15
|
-
project: fileURLToPath(tsConfigPath),
|
|
16
|
-
compilerOptions: { module: 'ESNext' },
|
|
17
|
-
});
|
|
18
|
-
return {
|
|
19
|
-
supportsTypescript: true,
|
|
20
|
-
compile(code, fileName) {
|
|
21
|
-
return tsNode.compile(code, fileName);
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
register() {
|
|
26
|
-
this.app.container.singleton('repl', async () => {
|
|
27
|
-
const { Repl } = await import('../src/repl.js');
|
|
28
|
-
let compiler;
|
|
29
|
-
if (isModuleInstalled('ts-node')) {
|
|
30
|
-
compiler = await this.#createCompiler();
|
|
31
|
-
}
|
|
32
|
-
const repl = new Repl({
|
|
33
|
-
compiler,
|
|
34
|
-
historyFilePath: join(homedir(), '.adonis_repl_history'),
|
|
35
|
-
});
|
|
36
|
-
defineReplBindings(this.app, repl);
|
|
37
|
-
return repl;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adonis_bindings.d.ts","sourceRoot":"","sources":["../../src/adonis_bindings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAShC,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,kBAAkB,EAAE,WAAW,EAAE,IAAI,QAoDpF"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
function setupReplState(repl, key, value) {
|
|
2
|
-
repl.server.context[key] = value;
|
|
3
|
-
repl.notify(`Loaded ${key} module. You can access it using the "${repl.colors.underline(key)}" variable`);
|
|
4
|
-
}
|
|
5
|
-
export function defineReplBindings(application, replService) {
|
|
6
|
-
replService.addMethod('loadEncryption', async (repl) => {
|
|
7
|
-
setupReplState(repl, 'encryption', await application.container.make('encryption'));
|
|
8
|
-
}, {
|
|
9
|
-
description: 'Load encryption provider and save reference to the "encryption" variable',
|
|
10
|
-
});
|
|
11
|
-
replService.addMethod('loadHash', async (repl) => {
|
|
12
|
-
setupReplState(repl, 'hash', await application.container.make('hash'));
|
|
13
|
-
}, {
|
|
14
|
-
description: 'Load hash provider and save reference to the "hash" variable',
|
|
15
|
-
});
|
|
16
|
-
replService.addMethod('loadRouter', async (repl) => {
|
|
17
|
-
setupReplState(repl, 'router', await application.container.make('router'));
|
|
18
|
-
}, {
|
|
19
|
-
description: 'Load router and save reference to the "router" variable',
|
|
20
|
-
});
|
|
21
|
-
replService.addMethod('loadConfig', async (repl) => {
|
|
22
|
-
setupReplState(repl, 'config', await application.container.make('config'));
|
|
23
|
-
}, {
|
|
24
|
-
description: 'Load config and save reference to the "config" variable',
|
|
25
|
-
});
|
|
26
|
-
}
|
package/build/src/colorizer.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"colorizer.d.ts","sourceRoot":"","sources":["../../src/colorizer.ts"],"names":[],"mappings":"AAqDA,wBAAgB,SAAS;QAID,MAAM;+BACY,MAAM;EAG/C"}
|