@adonisjs/repl 3.1.11 → 4.0.0-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/LICENSE.md CHANGED
@@ -1,9 +1,9 @@
1
- # The MIT License
2
-
3
- Copyright 2022 Harminder Virk, contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ # The MIT License
2
+
3
+ Copyright 2022 Harminder Virk, contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,216 +1,36 @@
1
- <div align="center">
2
- <h1> AdonisJS REPL </h1>
3
- <p>A slick <strong>framework agnostic REPL for Node.js</strong> with first class support for <br /> <code>top level await</code>, <code>typescript compilation</code>, <code>accurate stack traces</code> and a lot more.</p>
4
- </div>
1
+ # @adonisjs/repl
5
2
 
6
3
  <br />
7
4
 
8
- <div align="center">
5
+ [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![snyk-image]][snyk-url]
9
6
 
10
- [![gh-workflow-image]][gh-workflow-url] [![npm-image]][npm-url] ![][typescript-image] [![license-image]][license-url] [![synk-image]][synk-url]
7
+ ## Introduction
8
+ REPL for AdonisJS applications. Syntax highlighting, bracket matching, ESM and TypeScript support out of the box.
11
9
 
12
- </div>
10
+ ## Official Documentation
11
+ The documentation is available on the [AdonisJS website](https://docs.adonisjs.com/guides/repl)
13
12
 
14
- <div align="center">
15
- <h3>
16
- <a href="#installation">
17
- Usage
18
- </a>
19
- <span> | </span>
20
- <a href="CONTRIBUTING.md">
21
- Contributing
22
- </a>
23
- <span> | </span>
24
- <a href="https://preview.adonisjs.com">
25
- Checkout AdonisJS
26
- </a>
27
- </h3>
28
- </div>
13
+ ## Contributing
14
+ One of the primary goals of AdonisJS is to have a vibrant community of users and contributors who believes in the principles of the framework.
29
15
 
30
- <div align="center">
31
- <sub>Built with ❤︎ by <a href="https://github.com/thetutlage">Harminder Virk</a>
32
- </div>
16
+ We encourage you to read the [contribution guide](https://github.com/adonisjs/.github/blob/main/docs/CONTRIBUTING.md) before contributing to the framework.
33
17
 
34
- <br />
35
-
36
- ![](./assets/imports_and_await.png)
37
-
38
- <hr />
39
-
40
- AdonisJS REPL is a standalone and framework agnostic package to create custom Node.js REPL with first class support for:
41
-
42
- <p>
43
- 👉 <strong>Execute typescript code with in-memory compilation.</strong> <br />
44
- 👉 <strong> Support for top level await keyword. </strong><br />
45
- 👉 <strong> Ability to define custom method with a help description. </strong><br />
46
- </p>
47
-
48
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
49
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
50
- ## Table of contents
51
-
52
- - [Table of contents](#table-of-contents)
53
- - [Installation](#installation)
54
- - [Usage](#usage)
55
- - [Typescript support](#typescript-support)
56
- - [History file](#history-file)
57
- - [Accurate Stack Trace](#accurate-stack-trace)
58
- - [The `.ls` command](#the-ls-command)
59
- - [Adding custom properties](#adding-custom-properties)
60
- - [Global methods](#global-methods)
61
-
62
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
63
-
64
- ## Installation
65
-
66
- Install the package from the npm registry as follows:
67
-
68
- ```sh
69
- npm i @adonisjs/repl
70
-
71
- # Yarn
72
- yarn add @adonisjs/repl
73
- ```
74
-
75
- ## Usage
76
-
77
- Import the `Repl` class from the standalone module.
78
-
79
- ```ts
80
- import { Repl } from '@adonisjs/repl/build/standalone'
81
- const repl = new Repl()
82
-
83
- repl.start()
84
- ```
85
-
86
- ### Typescript support
87
-
88
- You will have to make use of [@adonisjs/require-ts](https://npm.im/@adonisjs/require-ts) in order for the REPL to compile and run the typescript code. For example:
89
-
90
- ```ts
91
- import { loadCompiler } from '@adonisjs/require-ts'
92
- import { Repl } from '@adonisjs/repl/build/standalone'
93
-
94
- const compilerOptions = {
95
- target: 'es2019',
96
- module: 'commonjs',
97
- allowSyntheticDefaultImports: true,
98
- esModuleInterop: true,
99
- }
100
-
101
- const repl = new Repl(loadCompiler(compilerOptions))
102
- ```
103
-
104
- If you are using `@adonisjs/require-ts` as a require hook, then there is no need to instantiate another instance of the compiler as you can reference the compiler instance from the global object.
105
-
106
- ```ts
107
- const compiler = global[Symbol.for('REQUIRE_TS_COMPILER')]
108
- const repl = new Repl(compiler)
109
- ```
110
-
111
- And now run the file containing the above code as follows:
112
-
113
- ```ts
114
- node -r @adonisjs/require-ts/build/register repl.ts
115
- ```
116
-
117
- ![](./assets/typescript.png)
118
-
119
- ### History file
120
-
121
- AdonisJS REPL allows you store the commands history inside a file so that the subsequent sessions can reference the commands executed in an earlier session.
18
+ ## Code of Conduct
19
+ In order to ensure that the AdonisJS community is welcoming to all, please review and abide by the [Code of Conduct](https://github.com/adonisjs/.github/blob/main/docs/CODE_OF_CONDUCT.md).
122
20
 
123
- You need to just pass the path to the history file and rest is taken care for you.
21
+ ## License
22
+ AdonisJS Repl is open-sourced software licensed under the [MIT license](LICENSE.md).
124
23
 
125
- ```ts
126
- import { join } from 'path'
127
- import { homedir } from 'os'
128
- import { Repl } from '@adonisjs/repl/build/standalone'
129
-
130
- const repl = new Repl(compiler, join(homedir(), '.adonis_repl_history'))
131
-
132
- repl.start()
133
- ```
134
-
135
- ![](./assets/history.gif)
136
-
137
- ## Accurate Stack Trace
138
-
139
- The stack trace for the Typescript files points back to the correct file, line and the column number.
140
-
141
- ![](./assets/stack-trace.png)
142
-
143
- ## The `.ls` command
144
-
145
- The `.ls` command prints the REPL session context. The output is divided to two sections.
146
-
147
- ![](./assets/ls-command.png)
148
-
149
- - **Global Methods** are the methods in the repl context object, but has some description associated with them.
150
- - **Context properties**: are the properties/methods in the context object. Only the first level of properties are printed on the console (to avoid noisy output).
151
-
152
- ## Adding custom properties
153
-
154
- If you are aware about the [Node.js repl context](https://nodejs.org/dist/latest-v14.x/docs/api/repl.html#repl_global_and_local_scope), then you would know that you can add properties to the context as follows:
155
-
156
- ```ts
157
- // NODE.JS EXAMPLE
158
- const { start } = require('repl')
159
-
160
- const server = start({})
161
- server.context.foo = 'bar'
162
- ```
163
-
164
- Similarly, you can add properties to the AdonisJS repl `context` by referencing the underlying `server` property.
165
-
166
- ```ts
167
- import { Repl } from '@adonisjs/repl/build/standalone'
168
-
169
- const repl = new Repl().start()
170
- repl.server.context.foo = 'bar'
171
- ```
172
-
173
- ### Global methods
174
-
175
- In addition to adding properties to the `context` directly. You can also define custom methods with a description and its usage text. For example:
176
-
177
- ```ts
178
- import { Repl } from '@adonisjs/repl/build/standalone'
179
- const repl = new Repl()
180
-
181
- repl.addMethod(
182
- 'getUsers',
183
- () => {
184
- return [
185
- { id: 1, name: 'virk' },
186
- { id: 2, name: 'romain' },
187
- ]
188
- },
189
- {
190
- description: 'Returns a list of users',
191
- }
192
- )
193
-
194
- repl.start()
195
- ```
196
-
197
- There is no technical advantage for using `addMethod` over adding properties to the `context` directly. It's just that `addMethod` properties are given special treatment during the [.ls command](#ls-command).
198
-
199
- Checkout the following example
200
-
201
- ![](./assets/context-behavior.png)
202
-
203
- [gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/repl/test?style=for-the-badge
24
+ [gh-workflow-image]: https://img.shields.io/github/actions/workflow/status/adonisjs/repl/test.yml?style=for-the-badge
204
25
  [gh-workflow-url]: https://github.com/adonisjs/repl/actions/workflows/test.yml "Github action"
205
26
 
206
- [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
207
- [typescript-url]: "typescript"
27
+ [npm-image]: https://img.shields.io/npm/v/@adonisjs/repl/latest.svg?style=for-the-badge&logo=npm
28
+ [npm-url]: https://www.npmjs.com/package/@adonisjs/repl/v/latest "npm"
208
29
 
209
- [npm-image]: https://img.shields.io/npm/v/@adonisjs/repl.svg?style=for-the-badge&logo=npm
210
- [npm-url]: https://npmjs.org/package/@adonisjs/repl 'npm'
30
+ [typescript-image]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
211
31
 
212
- [license-image]: https://img.shields.io/npm/l/@adonisjs/repl?color=blueviolet&style=for-the-badge
213
- [license-url]: LICENSE.md 'license'
32
+ [license-url]: LICENSE.md
33
+ [license-image]: https://img.shields.io/github/license/adonisjs/repl?style=for-the-badge
214
34
 
215
- [synk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/repl?label=Synk%20Vulnerabilities&style=for-the-badge
216
- [synk-url]: https://snyk.io/test/github/adonisjs/repl?targetFile=package.json "synk"
35
+ [snyk-image]: https://img.shields.io/snyk/vulnerabilities/github/adonisjs/repl?label=Snyk%20Vulnerabilities&style=for-the-badge
36
+ [snyk-url]: https://snyk.io/test/github/adonisjs/repl?targetFile=package.json "snyk"
@@ -0,0 +1,2 @@
1
+ import './src/types/extended.js';
2
+ export { Repl } from './src/repl.js';
@@ -1,8 +1,10 @@
1
1
  /*
2
2
  * @adonisjs/repl
3
3
  *
4
- * (c) Harminder Virk <virk@adonisjs.com>
4
+ * (c) AdonisJS
5
5
  *
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
+ import './src/types/extended.js';
10
+ export { Repl } from './src/repl.js';
@@ -0,0 +1,36 @@
1
+ /// <reference types="@types/node" resolution-mode="require"/>
2
+ import type { Colors } from '@poppinss/colors/types';
3
+ import { REPLServer } from 'node:repl';
4
+ import { Handler, ContextOptions, Compiler } from './types.js';
5
+ export declare class Repl {
6
+ #private;
7
+ /**
8
+ * Colors reference
9
+ */
10
+ colors: Colors;
11
+ /**
12
+ * Reference to the repl server. Available after the `start` method
13
+ * is invoked
14
+ */
15
+ server?: REPLServer;
16
+ constructor(options?: {
17
+ compiler?: Compiler;
18
+ historyFilePath?: string;
19
+ });
20
+ /**
21
+ * Notify by writing to the console
22
+ */
23
+ notify(message: string): void;
24
+ /**
25
+ * Start the REPL server
26
+ */
27
+ start(): this;
28
+ /**
29
+ * Register a callback to be invoked once the server is ready
30
+ */
31
+ ready(callback: (repl: Repl) => void): this;
32
+ /**
33
+ * Register a custom loader function to be added to the context
34
+ */
35
+ addMethod(name: string, handler: Handler, options?: ContextOptions): this;
36
+ }