@adonisjs/repl 3.1.10 → 4.0.0-0

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.
Files changed (59) hide show
  1. package/LICENSE.md +9 -9
  2. package/README.md +21 -201
  3. package/build/commands/adonis_repl.d.ts +9 -0
  4. package/build/commands/adonis_repl.d.ts.map +1 -0
  5. package/build/commands/adonis_repl.js +17 -0
  6. package/build/commands/commands.json +1 -0
  7. package/build/commands/main.js +36 -0
  8. package/build/index.d.ts +3 -0
  9. package/build/index.d.ts.map +1 -0
  10. package/build/index.js +2 -0
  11. package/build/providers/repl_provider.d.ts +8 -0
  12. package/build/providers/repl_provider.d.ts.map +1 -0
  13. package/build/providers/repl_provider.js +40 -0
  14. package/build/src/adonis_bindings.d.ts +4 -0
  15. package/build/src/adonis_bindings.d.ts.map +1 -0
  16. package/build/src/adonis_bindings.js +26 -0
  17. package/build/src/colorizer.d.ts +5 -0
  18. package/build/src/colorizer.d.ts.map +1 -0
  19. package/build/src/colorizer.js +39 -0
  20. package/build/src/repl.d.ts +17 -0
  21. package/build/src/repl.d.ts.map +1 -0
  22. package/build/src/repl.js +214 -0
  23. package/build/src/types/extended.d.ts +7 -0
  24. package/build/src/types/extended.d.ts.map +1 -0
  25. package/build/src/types/extended.js +1 -0
  26. package/build/src/types/main.d.ts +11 -0
  27. package/build/src/types/main.d.ts.map +1 -0
  28. package/build/src/types/main.js +1 -0
  29. package/build/src/utils.d.ts +2 -0
  30. package/build/src/utils.d.ts.map +1 -0
  31. package/build/src/utils.js +11 -0
  32. package/commands/adonis_repl.ts +38 -0
  33. package/{build/adonis-typings/repl.js → index.ts} +5 -1
  34. package/package.json +107 -129
  35. package/providers/repl_provider.ts +61 -0
  36. package/src/adonis_bindings.ts +63 -0
  37. package/src/colorizer.ts +62 -0
  38. package/src/repl.ts +423 -0
  39. package/{build/adonis-typings/container.js → src/types/extended.ts} +9 -1
  40. package/src/types/main.ts +33 -0
  41. package/src/utils.ts +14 -0
  42. package/build/adonis-typings/container.d.ts +0 -6
  43. package/build/adonis-typings/index.d.ts +0 -2
  44. package/build/adonis-typings/index.js +0 -10
  45. package/build/adonis-typings/repl.d.ts +0 -46
  46. package/build/commands/AdonisRepl.d.ts +0 -11
  47. package/build/commands/AdonisRepl.js +0 -33
  48. package/build/commands/index.d.ts +0 -2
  49. package/build/commands/index.js +0 -11
  50. package/build/providers/ReplProvider.d.ts +0 -7
  51. package/build/providers/ReplProvider.js +0 -26
  52. package/build/src/Compiler/index.d.ts +0 -29
  53. package/build/src/Compiler/index.js +0 -68
  54. package/build/src/ImportsParser/index.d.ts +0 -51
  55. package/build/src/ImportsParser/index.js +0 -137
  56. package/build/src/Repl/index.d.ts +0 -91
  57. package/build/src/Repl/index.js +0 -358
  58. package/build/standalone.d.ts +0 -3
  59. package/build/standalone.js +0 -17
@@ -1,33 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/repl
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const standalone_1 = require("@adonisjs/core/build/standalone");
12
- class ReplCommand extends standalone_1.BaseCommand {
13
- async run() {
14
- this.application.container.withBindings(['Adonis/Core/Route'], (Route) => {
15
- Route.commit();
16
- });
17
- this.application.container.use('Adonis/Addons/Repl').start();
18
- /**
19
- * Gracefully shutdown the application
20
- */
21
- this.application.container.use('Adonis/Addons/Repl').server.on('exit', async () => {
22
- await this.application.shutdown();
23
- });
24
- }
25
- }
26
- exports.default = ReplCommand;
27
- ReplCommand.commandName = 'repl';
28
- ReplCommand.description = 'Start a new REPL session';
29
- ReplCommand.settings = {
30
- loadApp: true,
31
- environment: 'repl',
32
- stayAlive: true,
33
- };
@@ -1,2 +0,0 @@
1
- declare const _default: string[];
2
- export default _default;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/repl
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.default = ['@adonisjs/repl/build/commands/AdonisRepl'];
@@ -1,7 +0,0 @@
1
- import { ApplicationContract } from '@ioc:Adonis/Core/Application';
2
- export default class ReplProvider {
3
- protected app: ApplicationContract;
4
- constructor(app: ApplicationContract);
5
- static needsApplication: boolean;
6
- register(): void;
7
- }
@@ -1,26 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/repl
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- const path_1 = require("path");
12
- const os_1 = require("os");
13
- class ReplProvider {
14
- constructor(app) {
15
- this.app = app;
16
- }
17
- register() {
18
- this.app.container.singleton('Adonis/Addons/Repl', () => {
19
- const compiler = global[Symbol.for('REQUIRE_TS_COMPILER')];
20
- const { Repl } = require('../src/Repl');
21
- return new Repl(compiler, (0, path_1.join)((0, os_1.homedir)(), '.adonis_repl_history'));
22
- });
23
- }
24
- }
25
- exports.default = ReplProvider;
26
- ReplProvider.needsApplication = true;
@@ -1,29 +0,0 @@
1
- import { Compiler as TsCompiler } from '@adonisjs/require-ts/build/src/Compiler';
2
- /**
3
- * Exposes the API to compile the user land code to be executed
4
- * inside Node.JS REPL.
5
- */
6
- export declare class Compiler {
7
- private tsCompiler?;
8
- compilesTs: boolean;
9
- constructor(tsCompiler?: TsCompiler | undefined);
10
- /**
11
- * Process the await keywords in the code
12
- */
13
- private processAwait;
14
- /**
15
- * Compiles code using typescript
16
- */
17
- private compileTypescript;
18
- /**
19
- * Compiles the code to be executed in the Node.js REPL. Under
20
- * the hood
21
- *
22
- * - Typescript code is compiled
23
- * - Await keywords are wrapped in async IIFE
24
- */
25
- compile(statement: string, filename: string): Promise<{
26
- compiled: string;
27
- awaitPromise: boolean;
28
- }>;
29
- }
@@ -1,68 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/repl
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Compiler = void 0;
12
- const node_repl_await_1 = require("node-repl-await");
13
- const ImportsParser_1 = require("../ImportsParser");
14
- /**
15
- * Exposes the API to compile the user land code to be executed
16
- * inside Node.JS REPL.
17
- */
18
- class Compiler {
19
- constructor(tsCompiler) {
20
- this.tsCompiler = tsCompiler;
21
- this.compilesTs = !!this.tsCompiler;
22
- }
23
- /**
24
- * Process the await keywords in the code
25
- */
26
- processAwait(statement) {
27
- const potentialWrappedCode = (0, node_repl_await_1.processTopLevelAwait)(statement);
28
- if (!potentialWrappedCode) {
29
- return { compiled: statement, awaitPromise: false };
30
- }
31
- return { compiled: potentialWrappedCode, awaitPromise: true };
32
- }
33
- /**
34
- * Compiles code using typescript
35
- */
36
- async compileTypescript(statement, filename) {
37
- const lines = statement.split(/\n|\r\n/);
38
- let compiledOutput = statement;
39
- /**
40
- * In case of a single line, we process the import
41
- * keywords and define local variables to hold
42
- * the import reference
43
- */
44
- if (lines.length <= 2) {
45
- compiledOutput = await new ImportsParser_1.ImportsParser().parse(statement);
46
- }
47
- /**
48
- * Compile using typescript compiler and patch the
49
- * `sourceMappingUrl` comment to be a block level comment.
50
- */
51
- compiledOutput = this.tsCompiler.compile(filename, compiledOutput, true);
52
- return `${compiledOutput.replace('//# sourceMappingURL=', '/**# sourceMappingURL=')} */`;
53
- }
54
- /**
55
- * Compiles the code to be executed in the Node.js REPL. Under
56
- * the hood
57
- *
58
- * - Typescript code is compiled
59
- * - Await keywords are wrapped in async IIFE
60
- */
61
- async compile(statement, filename) {
62
- if (this.tsCompiler) {
63
- statement = await this.compileTypescript(statement, filename);
64
- }
65
- return this.processAwait(statement);
66
- }
67
- }
68
- exports.Compiler = Compiler;
@@ -1,51 +0,0 @@
1
- /**
2
- * This is a crazy attempt to hack around the Typescript behavior around un-used
3
- * imports. Writing half baked parsers is something I want to avoid everytime.
4
- * However, there isn't any other way (atleast I don't know about it).
5
- *
6
- * In REPL, you usually write one line of code at a time. For example:
7
- * - You write 2 + 2 and then press enter. The REPL prints 4
8
- * - You write `await Database.query().first()` and it prints the query result.
9
- *
10
- * However, when you write `import User from 'App/Models/User'` and expect to
11
- * access User variable then you are out of luck.
12
- *
13
- * - The import statement will go to the typescript compiler
14
- * - It will compile the code and sees that no one is using this import.
15
- * And hence it will just remove it from the compiled output.
16
- *
17
- * Bang! No import/require exists and hence no `User` variable exists.
18
- *
19
- * To hack around it, we need to monitor and parse import statements and hold
20
- * a reference to them so that the compiler doesn't remove. For example:
21
- *
22
- * Converting
23
- * ```ts
24
- * import User from 'App/Models/User'
25
- * ```
26
- *
27
- * To
28
- * ```ts
29
- * import repl_User from 'App/Models/User'; var User = repl_User
30
- * ```
31
- *
32
- * Now you can access the `User` variable.
33
- *
34
- * The tough part is attempting to parse all styles in which an import
35
- * statement can be written. Lucikly, there are 4 different ways to
36
- * do that as per the spec http://www.ecma-international.org/ecma-262/6.0/#table-40
37
- *
38
- * import v from "mod"; (Import default)
39
- * import * as ns from "mod"; (Import alias)
40
- * import {x} from "mod"; (Import named)
41
- * import {x as v} from "mod"; (Import named + aliases)
42
- *
43
- * However, we have to be tolerant to the white spaces.
44
- */
45
- export declare class ImportsParser {
46
- private parseImport;
47
- /**
48
- * Parse a given line of code
49
- */
50
- parse(line: string): Promise<string>;
51
- }
@@ -1,137 +0,0 @@
1
- "use strict";
2
- /*
3
- * @adonisjs/repl
4
- *
5
- * (c) Harminder Virk <virk@adonisjs.com>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- var __importDefault = (this && this.__importDefault) || function (mod) {
11
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.ImportsParser = void 0;
15
- const parse_imports_1 = __importDefault(require("parse-imports"));
16
- /**
17
- * This is a crazy attempt to hack around the Typescript behavior around un-used
18
- * imports. Writing half baked parsers is something I want to avoid everytime.
19
- * However, there isn't any other way (atleast I don't know about it).
20
- *
21
- * In REPL, you usually write one line of code at a time. For example:
22
- * - You write 2 + 2 and then press enter. The REPL prints 4
23
- * - You write `await Database.query().first()` and it prints the query result.
24
- *
25
- * However, when you write `import User from 'App/Models/User'` and expect to
26
- * access User variable then you are out of luck.
27
- *
28
- * - The import statement will go to the typescript compiler
29
- * - It will compile the code and sees that no one is using this import.
30
- * And hence it will just remove it from the compiled output.
31
- *
32
- * Bang! No import/require exists and hence no `User` variable exists.
33
- *
34
- * To hack around it, we need to monitor and parse import statements and hold
35
- * a reference to them so that the compiler doesn't remove. For example:
36
- *
37
- * Converting
38
- * ```ts
39
- * import User from 'App/Models/User'
40
- * ```
41
- *
42
- * To
43
- * ```ts
44
- * import repl_User from 'App/Models/User'; var User = repl_User
45
- * ```
46
- *
47
- * Now you can access the `User` variable.
48
- *
49
- * The tough part is attempting to parse all styles in which an import
50
- * statement can be written. Lucikly, there are 4 different ways to
51
- * do that as per the spec http://www.ecma-international.org/ecma-262/6.0/#table-40
52
- *
53
- * import v from "mod"; (Import default)
54
- * import * as ns from "mod"; (Import alias)
55
- * import {x} from "mod"; (Import named)
56
- * import {x as v} from "mod"; (Import named + aliases)
57
- *
58
- * However, we have to be tolerant to the white spaces.
59
- */
60
- class ImportsParser {
61
- async parseImport(statement) {
62
- statement = statement.trim();
63
- /**
64
- * Return the value as it is when doesn't include the import
65
- * keyword
66
- */
67
- if (!statement.startsWith('import')) {
68
- return statement;
69
- }
70
- /**
71
- * Parse all imports in the current line
72
- */
73
- const imports = await (0, parse_imports_1.default)(statement);
74
- const importsAsArray = [...imports];
75
- return importsAsArray
76
- .map(({ moduleSpecifier, importClause }) => {
77
- const tokens = [];
78
- const localVariables = [];
79
- /**
80
- * Has `* as` namespace import
81
- */
82
- if (importClause && importClause.namespace) {
83
- const identifier = `repl_${importClause.namespace}`;
84
- tokens.push(`* as ${identifier}`);
85
- localVariables.push(`var ${importClause.namespace} = ${identifier}`);
86
- }
87
- /**
88
- * Has default namespace import
89
- */
90
- if (importClause && importClause.default) {
91
- const identifier = `repl_${importClause.default}`;
92
- tokens.push(identifier);
93
- localVariables.push(`var ${importClause.default} = ${identifier}`);
94
- }
95
- /**
96
- * Has named imports
97
- */
98
- if (importClause && importClause.named.length) {
99
- importClause.named.forEach((name, index) => {
100
- const identifier = `repl_${name.binding}`;
101
- let expression = '';
102
- /**
103
- * Add starting curly brace to named aliases
104
- */
105
- if (index === 0) {
106
- expression += '{';
107
- }
108
- /**
109
- * Setup expression
110
- */
111
- expression += `${name.specifier} as ${identifier}`;
112
- /**
113
- * Add ending curly brace to named aliases
114
- */
115
- if (index + 1 === importClause.named.length) {
116
- expression += '}';
117
- }
118
- tokens.push(expression);
119
- localVariables.push(`var ${name.binding} = ${identifier}`);
120
- });
121
- }
122
- const localVariablesDeclaration = `${localVariables.join('; ')}`;
123
- return `import ${tokens.join(',')} from ${moduleSpecifier.code}; ${localVariablesDeclaration}`;
124
- })
125
- .join('');
126
- }
127
- /**
128
- * Parse a given line of code
129
- */
130
- async parse(line) {
131
- const parsedStatement = await Promise.all(line.split(';').map((statement) => {
132
- return this.parseImport(statement);
133
- }));
134
- return parsedStatement.join('; ');
135
- }
136
- }
137
- exports.ImportsParser = ImportsParser;
@@ -1,91 +0,0 @@
1
- /// <reference types="node" />
2
- import { REPLServer } from 'repl';
3
- import { ReplContract, Handler, ContextOptions } from '@ioc:Adonis/Addons/Repl';
4
- import { Compiler as TsCompiler } from '@adonisjs/require-ts/build/src/Compiler';
5
- /**
6
- * Exposes the API to work the REPL server
7
- */
8
- export declare class Repl implements ReplContract {
9
- private tsCompiler?;
10
- private historyFilePath?;
11
- /**
12
- * Compiler to compile REPL input
13
- */
14
- private compiler;
15
- /**
16
- * Length of the longest custom method name. We need to show a
17
- * symmetric view of custom methods and their description
18
- */
19
- private longestCustomMethodName;
20
- /**
21
- * Set of registered ready callbacks
22
- */
23
- private onReadyCallbacks;
24
- /**
25
- * A set of registered custom methods
26
- */
27
- private customMethods;
28
- /**
29
- * Reference to the underlying REPL server. Available
30
- * after `start` is invoked.
31
- */
32
- server: REPLServer;
33
- /**
34
- * Reference to the colors to print colorful messages
35
- */
36
- colors: import("@poppinss/colors/build/src/Base").Colors;
37
- constructor(tsCompiler?: TsCompiler | undefined, historyFilePath?: string | undefined);
38
- /**
39
- * Find if the error is recoverable or not
40
- */
41
- private isRecoverableError;
42
- /**
43
- * Custom eval method to execute the user code
44
- */
45
- private eval;
46
- private registerCustomMethodWithContext;
47
- /**
48
- * Register custom methods with the server context
49
- */
50
- private registerCustomMethodsWithContext;
51
- /**
52
- * Setup context with default globals
53
- */
54
- private setupContext;
55
- /**
56
- * Setup history file
57
- */
58
- private setupHistory;
59
- /**
60
- * Prints the welcome message
61
- */
62
- private printWelcomeMessage;
63
- /**
64
- * Prints the help for the custom methods
65
- */
66
- private printCustomMethodsHelp;
67
- /**
68
- * Prints the help for the context properties
69
- */
70
- private printContextHelp;
71
- /**
72
- * Prints the context to the console
73
- */
74
- private ls;
75
- /**
76
- * Notify by writing to the console
77
- */
78
- notify(message: string): void;
79
- /**
80
- * Start the REPL session
81
- */
82
- start(): this;
83
- /**
84
- * Register a callback to be invoked once the server is ready
85
- */
86
- ready(callback: (repl: ReplContract) => void): this;
87
- /**
88
- * Register a custom loader function to be added to the context
89
- */
90
- addMethod(name: string, handler: Handler, options?: ContextOptions): this;
91
- }