@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
@@ -0,0 +1,214 @@
1
+ import useColors from '@poppinss/colors';
2
+ import { Recoverable } from 'node:repl';
3
+ import prettyRepl from 'pretty-repl';
4
+ import stringWidth from 'string-width';
5
+ import { inspect, promisify as utilPromisify } from 'node:util';
6
+ import { colorizer } from './colorizer.js';
7
+ const GLOBAL_NODE_PROPERTIES = [
8
+ 'performance',
9
+ 'global',
10
+ 'clearInterval',
11
+ 'clearTimeout',
12
+ 'setInterval',
13
+ 'setTimeout',
14
+ 'queueMicrotask',
15
+ 'clearImmediate',
16
+ 'setImmediate',
17
+ 'structuredClone',
18
+ 'atob',
19
+ 'btoa',
20
+ 'fetch',
21
+ 'crypto',
22
+ ];
23
+ const TS_UTILS_HELPERS = [
24
+ '__extends',
25
+ '__assign',
26
+ '__rest',
27
+ '__decorate',
28
+ '__param',
29
+ '__esDecorate',
30
+ '__runInitializers',
31
+ '__propKey',
32
+ '__setFunctionName',
33
+ '__metadata',
34
+ '__awaiter',
35
+ '__generator',
36
+ '__exportStar',
37
+ '__createBinding',
38
+ '__values',
39
+ '__read',
40
+ '__spread',
41
+ '__spreadArrays',
42
+ '__spreadArray',
43
+ '__await',
44
+ '__asyncGenerator',
45
+ '__asyncDelegator',
46
+ '__asyncValues',
47
+ '__makeTemplateObject',
48
+ '__importStar',
49
+ '__importDefault',
50
+ '__classPrivateFieldGet',
51
+ '__classPrivateFieldSet',
52
+ '__classPrivateFieldIn',
53
+ ];
54
+ const icons = process.platform === 'win32' && !process.env.WT_SESSION
55
+ ? { tick: '√', pointer: '>' }
56
+ : { tick: '✔', pointer: '❯' };
57
+ export class Repl {
58
+ #longestCustomMethodName = 0;
59
+ #originalEval = null;
60
+ colors = useColors.ansi();
61
+ server;
62
+ #compiler;
63
+ #onReadyCallbacks = [];
64
+ #customMethods = {};
65
+ #historyFilePath;
66
+ constructor(options) {
67
+ this.#compiler = options?.compiler;
68
+ this.#historyFilePath = options?.historyFilePath;
69
+ }
70
+ #printWelcomeMessage() {
71
+ console.log('');
72
+ if (this.#compiler?.supportsTypescript) {
73
+ console.log(`${this.colors.green(icons.tick)} ${this.colors.dim('typescript compilation supported')}`);
74
+ console.log('');
75
+ }
76
+ this.notify('Type ".ls" to a view list of available context methods/properties');
77
+ }
78
+ #setupContext() {
79
+ this.addMethod('clear', function clear(repl, key) {
80
+ if (!key) {
81
+ console.log(repl.colors.red('Define a property name to remove from the context'));
82
+ }
83
+ else {
84
+ delete repl.server.context[key];
85
+ }
86
+ repl.server.displayPrompt();
87
+ }, {
88
+ description: 'Clear a property from the REPL context',
89
+ usage: `clear ${this.colors.gray('(propertyName)')}`,
90
+ });
91
+ this.addMethod('p', function promisify(_, fn) {
92
+ return utilPromisify(fn);
93
+ }, {
94
+ description: 'Promisify a function. Similar to Node.js "util.promisify"',
95
+ usage: `p ${this.colors.gray('(function)')}`,
96
+ });
97
+ this.#registerCustomMethodsWithContext();
98
+ }
99
+ #registerCustomMethodsWithContext() {
100
+ Object.keys(this.#customMethods).forEach((name) => {
101
+ this.#registerCustomMethodWithContext(name);
102
+ });
103
+ }
104
+ #isRecoverableError(error) {
105
+ return /^(Unexpected end of input|Unexpected token|' expected)/.test(error.message);
106
+ }
107
+ #eval(code, context, filename, callback) {
108
+ try {
109
+ const compiled = this.#compiler.compile(code, filename)
110
+ .replace('export { };', '')
111
+ .replace(/\/\/# sourceMappingURL=(.*)$/, '/** sourceMappingURL=$1 */');
112
+ return this.#originalEval(compiled, context, filename, callback);
113
+ }
114
+ catch (error) {
115
+ if (this.#isRecoverableError(error)) {
116
+ callback(new Recoverable(error), null);
117
+ return;
118
+ }
119
+ callback(error, null);
120
+ }
121
+ }
122
+ #setupHistory() {
123
+ if (!this.#historyFilePath) {
124
+ return;
125
+ }
126
+ this.server.setupHistory(this.#historyFilePath, (error) => {
127
+ if (!error) {
128
+ return;
129
+ }
130
+ console.log(this.colors.red('Unable to write to the history file. Exiting'));
131
+ console.error(error);
132
+ process.exit(1);
133
+ });
134
+ }
135
+ #printContextHelp() {
136
+ console.log('');
137
+ console.log(this.colors.green('CONTEXT PROPERTIES/METHODS:'));
138
+ const context = Object.keys(this.server.context).reduce((result, key) => {
139
+ if (!this.#customMethods[key] &&
140
+ !GLOBAL_NODE_PROPERTIES.includes(key) &&
141
+ !TS_UTILS_HELPERS.includes(key)) {
142
+ result[key] = this.server.context[key];
143
+ }
144
+ return result;
145
+ }, {});
146
+ console.log(inspect(context, false, 1, true));
147
+ }
148
+ #printCustomMethodsHelp() {
149
+ console.log('');
150
+ console.log(this.colors.green('GLOBAL METHODS:'));
151
+ Object.keys(this.#customMethods).forEach((method) => {
152
+ const { options } = this.#customMethods[method];
153
+ const spaces = new Array(this.#longestCustomMethodName - options.width + 2).join(' ');
154
+ console.log(`${this.colors.yellow(options.usage || method)}${spaces}${this.colors.dim(options.description || '')}`);
155
+ });
156
+ }
157
+ #registerCustomMethodWithContext(name) {
158
+ const customMethod = this.#customMethods[name];
159
+ if (!customMethod) {
160
+ return;
161
+ }
162
+ const handler = (...args) => customMethod.handler(this, ...args);
163
+ Object.defineProperty(handler, 'name', { value: customMethod.handler.name });
164
+ this.server.context[name] = handler;
165
+ }
166
+ #ls() {
167
+ this.#printCustomMethodsHelp();
168
+ this.#printContextHelp();
169
+ this.server.displayPrompt();
170
+ }
171
+ notify(message) {
172
+ console.log(this.colors.yellow().italic(message));
173
+ if (this.server) {
174
+ this.server.displayPrompt();
175
+ }
176
+ }
177
+ start() {
178
+ this.#printWelcomeMessage();
179
+ this.server = prettyRepl.start({
180
+ prompt: '> ',
181
+ input: process.stdin,
182
+ output: process.stdout,
183
+ terminal: process.stdout.isTTY && !Number.parseInt(process.env.NODE_NO_READLINE, 10),
184
+ useGlobal: true,
185
+ colorize: colorizer(),
186
+ });
187
+ this.server.defineCommand('ls', {
188
+ help: 'View list of available context methods/properties',
189
+ action: this.#ls.bind(this),
190
+ });
191
+ this.#setupContext();
192
+ this.#setupHistory();
193
+ this.#originalEval = this.server.eval;
194
+ this.server.eval = this.#eval.bind(this);
195
+ this.server.displayPrompt();
196
+ this.#onReadyCallbacks.forEach((callback) => callback(this));
197
+ return this;
198
+ }
199
+ ready(callback) {
200
+ this.#onReadyCallbacks.push(callback);
201
+ return this;
202
+ }
203
+ addMethod(name, handler, options) {
204
+ const width = stringWidth(options?.usage || name);
205
+ if (width > this.#longestCustomMethodName) {
206
+ this.#longestCustomMethodName = width;
207
+ }
208
+ this.#customMethods[name] = { handler, options: Object.assign({ width }, options) };
209
+ if (this.server) {
210
+ this.#registerCustomMethodWithContext(name);
211
+ }
212
+ return this;
213
+ }
214
+ }
@@ -0,0 +1,7 @@
1
+ import { Repl } from '../repl.js';
2
+ declare module '@adonisjs/core/types' {
3
+ interface ContainerBindings {
4
+ repl: Repl;
5
+ }
6
+ }
7
+ //# sourceMappingURL=extended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extended.d.ts","sourceRoot":"","sources":["../../../src/types/extended.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAEjC,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,iBAAiB;QAChC,IAAI,EAAE,IAAI,CAAA;KACX;CACF"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ import { Repl } from '../repl.js';
2
+ export type Handler = (repl: Repl, ...args: any[]) => any;
3
+ export type ContextOptions = {
4
+ description?: string;
5
+ usage?: string;
6
+ };
7
+ export type Compiler = {
8
+ compile: (code: string, fileName: string) => string;
9
+ supportsTypescript: boolean;
10
+ };
11
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../../src/types/main.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAKjC,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAA;AAMzD,MAAM,MAAM,cAAc,GAAG;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAMD,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAA;IACnD,kBAAkB,EAAE,OAAO,CAAA;CAC5B,CAAA"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare function isModuleInstalled(moduleName: string): boolean;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAKA,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,WAQnD"}
@@ -0,0 +1,11 @@
1
+ import { createRequire } from 'node:module';
2
+ export function isModuleInstalled(moduleName) {
3
+ const require = createRequire(import.meta.url);
4
+ try {
5
+ require.resolve(moduleName);
6
+ return true;
7
+ }
8
+ catch (error) {
9
+ return false;
10
+ }
11
+ }
@@ -0,0 +1,38 @@
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
+ */
9
+
10
+ import { BaseCommand } from '@adonisjs/core/ace'
11
+ import { CommandOptions } from '@adonisjs/core/types/ace'
12
+
13
+ export default class ReplCommand extends BaseCommand {
14
+ static commandName = 'repl'
15
+ static description = 'Start a new REPL session'
16
+
17
+ static options: CommandOptions = {
18
+ startApp: true,
19
+ staysAlive: true,
20
+ }
21
+
22
+ async run() {
23
+ this.app.container.resolving('router', (router) => router.commit())
24
+
25
+ /**
26
+ * Start the repl
27
+ */
28
+ const repl = await this.app.container.make('repl')
29
+ repl.start()
30
+
31
+ /**
32
+ * Gracefully shutdown the app
33
+ */
34
+ repl.server!.on('exit', async () => {
35
+ await this.app.terminate()
36
+ })
37
+ }
38
+ }
@@ -1,8 +1,12 @@
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
+
10
+ import './src/types/extended.js'
11
+
12
+ export { Repl } from './src/repl.js'
package/package.json CHANGED
@@ -1,103 +1,101 @@
1
1
  {
2
2
  "name": "@adonisjs/repl",
3
- "version": "3.1.10",
4
3
  "description": "REPL for AdonisJS",
5
- "main": "build/providers/ReplProvider.js",
4
+ "version": "4.0.0-0",
5
+ "main": "build/index.js",
6
+ "type": "module",
6
7
  "files": [
7
- "build/adonis-typings",
8
- "build/commands",
9
- "build/providers",
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",
10
21
  "build/src",
11
- "build/standalone.d.ts",
12
- "build/standalone.js"
22
+ "build/services",
23
+ "build/providers",
24
+ "build/commands",
25
+ "build/factories",
26
+ "build/stubs",
27
+ "build/index.d.ts",
28
+ "build/index.d.ts.map",
29
+ "build/index.js"
13
30
  ],
14
- "typings": "./build/adonis-typings/index.d.ts",
31
+ "exports": {
32
+ ".": "./build/index.js",
33
+ "./commands": "./build/commands/main.js",
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"
38
+ },
15
39
  "scripts": {
16
- "mrm": "mrm --preset=@adonisjs/mrm-preset",
17
40
  "pretest": "npm run lint",
18
- "test": "node -r @adonisjs/require-ts/build/register ./bin/test.ts",
41
+ "test": "c8 npm run quick:test",
42
+ "lint": "eslint . --ext=.ts",
19
43
  "clean": "del-cli build",
20
- "compile": "npm run lint && npm run clean && tsc",
44
+ "compile": "npm run lint && npm run clean && tsc && npm run copy:templates && npm run index:commands",
45
+ "copy:templates": "copyfiles \"stubs/**/*.stub\" build",
21
46
  "build": "npm run compile",
22
- "prepublishOnly": "npm run build",
23
- "lint": "eslint . --ext=.ts",
24
- "format": "prettier --write .",
25
- "commit": "git-cz",
26
47
  "release": "np --message=\"chore(release): %s\"",
27
48
  "version": "npm run build",
28
- "sync-labels": "github-label-sync --labels ./node_modules/@adonisjs/mrm-preset/gh-labels.json adonisjs/repl"
29
- },
30
- "keywords": [
31
- "adonisjs",
32
- "repl",
33
- "node-repl"
34
- ],
35
- "author": "virk,adonisjs",
36
- "license": "MIT",
37
- "peerDependencies": {
38
- "@adonisjs/core": "^5.1.0"
49
+ "sync-labels": "github-label-sync --labels .github/labels.json adonisjs/repl",
50
+ "quick:test": "node --loader=ts-node/esm bin/test.ts",
51
+ "format": "prettier --write .",
52
+ "prepublishOnly": "npm run build",
53
+ "index:commands": "adonis-kit index build/commands"
39
54
  },
40
55
  "devDependencies": {
41
- "@adonisjs/core": "^5.6.2",
42
- "@adonisjs/mrm-preset": "^5.0.3",
43
- "@adonisjs/require-ts": "^2.0.11",
44
- "@japa/assert": "^1.3.3",
45
- "@japa/run-failed-tests": "^1.0.7",
46
- "@japa/runner": "^2.0.6",
47
- "@japa/spec-reporter": "^1.1.12",
48
- "@poppinss/dev-utils": "^2.0.3",
49
- "@types/node": "^17.0.23",
50
- "commitizen": "^4.2.4",
51
- "cz-conventional-changelog": "^3.3.0",
52
- "del-cli": "^4.0.1",
53
- "doctoc": "^2.1.0",
54
- "eslint": "^8.12.0",
55
- "eslint-config-prettier": "^8.5.0",
56
- "eslint-plugin-adonis": "^2.1.0",
57
- "eslint-plugin-prettier": "^4.0.0",
58
- "github-label-sync": "^2.2.0",
59
- "husky": "^7.0.4",
60
- "mrm": "^4.0.0",
56
+ "@adonisjs/core": "^6.1.5-4",
57
+ "@adonisjs/eslint-config": "^1.1.2",
58
+ "@adonisjs/prettier-config": "^1.1.2",
59
+ "@adonisjs/tsconfig": "^1.1.2",
60
+ "@japa/assert": "^1.4.1",
61
+ "@japa/file-system": "^1.1.0",
62
+ "@japa/run-failed-tests": "^1.1.1",
63
+ "@japa/runner": "^2.5.1",
64
+ "@japa/spec-reporter": "^1.3.3",
65
+ "@swc/core": "^1.3.66",
66
+ "@types/node": "^20.3.1",
67
+ "c8": "^8.0.0",
68
+ "copyfiles": "^2.4.1",
69
+ "del-cli": "^5.0.0",
70
+ "eslint": "^8.43.0",
71
+ "github-label-sync": "^2.3.1",
72
+ "husky": "^8.0.3",
61
73
  "np": "^7.6.1",
62
- "prettier": "^2.6.2",
63
- "typescript": "^4.6.3"
74
+ "prettier": "^2.8.8",
75
+ "ts-node": "^10.9.1",
76
+ "typescript": "^5.1.3"
64
77
  },
65
- "husky": {
66
- "hooks": {
67
- "commit-msg": "node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js"
68
- }
78
+ "dependencies": {
79
+ "@poppinss/colors": "4.1.0-2",
80
+ "emphasize": "^6.0.0",
81
+ "pretty-repl": "^4.0.0",
82
+ "string-width": "^6.1.0"
69
83
  },
70
- "nyc": {
71
- "exclude": [
72
- "test"
73
- ],
74
- "extension": [
75
- ".ts"
76
- ]
84
+ "peerDependencies": {
85
+ "@adonisjs/core": "^6.1.5-4",
86
+ "ts-node": "^10.4.0"
77
87
  },
78
- "config": {
79
- "commitizen": {
80
- "path": "cz-conventional-changelog"
88
+ "peerDependenciesMeta": {
89
+ "@adonisjs/core": {
90
+ "optional": true
91
+ },
92
+ "ts-node": {
93
+ "optional": true
81
94
  }
82
95
  },
83
- "np": {
84
- "contents": ".",
85
- "anyBranch": false
86
- },
87
- "publishConfig": {
88
- "access": "public",
89
- "tag": "latest"
90
- },
91
- "dependencies": {
92
- "@poppinss/colors": "^3.0.2",
93
- "node-repl-await": "^0.1.2",
94
- "parse-imports": "0.0.5",
95
- "string-width": "^4.2.2"
96
- },
97
- "directories": {
98
- "example": "example",
99
- "test": "test"
100
- },
96
+ "author": "virk,julien-r44,adonisjs",
97
+ "license": "MIT",
98
+ "homepage": "https://github.com/adonisjs/repl#readme",
101
99
  "repository": {
102
100
  "type": "git",
103
101
  "url": "git+https://github.com/adonisjs/repl.git"
@@ -105,57 +103,37 @@
105
103
  "bugs": {
106
104
  "url": "https://github.com/adonisjs/repl/issues"
107
105
  },
108
- "homepage": "https://github.com/adonisjs/repl#readme",
109
- "adonisjs": {
110
- "aceProviders": [
111
- "@adonisjs/repl"
112
- ],
113
- "commands": [
114
- "@adonisjs/repl/build/commands"
115
- ],
116
- "types": "@adonisjs/repl"
117
- },
118
- "mrmConfig": {
119
- "core": true,
120
- "license": "MIT",
121
- "services": [
122
- "github-actions"
123
- ],
124
- "minNodeVersion": "14.15.4",
125
- "probotApps": [
126
- "stale",
127
- "lock"
128
- ],
129
- "runGhActionsOnWindows": true
130
- },
106
+ "keywords": [
107
+ "adonisjs",
108
+ "repl",
109
+ "node-repl"
110
+ ],
131
111
  "eslintConfig": {
112
+ "extends": "@adonisjs/eslint-config/typescript-package"
113
+ },
114
+ "prettier": "@adonisjs/prettier-config",
115
+ "commitlint": {
132
116
  "extends": [
133
- "plugin:adonis/typescriptPackage",
134
- "prettier"
135
- ],
136
- "plugins": [
137
- "prettier"
138
- ],
139
- "rules": {
140
- "prettier/prettier": [
141
- "error",
142
- {
143
- "endOfLine": "auto"
144
- }
145
- ]
146
- }
117
+ "@commitlint/config-conventional"
118
+ ]
147
119
  },
148
- "eslintIgnore": [
149
- "build"
150
- ],
151
- "prettier": {
152
- "trailingComma": "es5",
153
- "semi": false,
154
- "singleQuote": true,
155
- "useTabs": false,
156
- "quoteProps": "consistent",
157
- "bracketSpacing": true,
158
- "arrowParens": "always",
159
- "printWidth": 100
120
+ "publishConfig": {
121
+ "access": "public",
122
+ "tag": "latest"
123
+ },
124
+ "np": {
125
+ "message": "chore(release): %s",
126
+ "tag": "next",
127
+ "branch": "main",
128
+ "anyBranch": false
129
+ },
130
+ "c8": {
131
+ "reporter": [
132
+ "text",
133
+ "html"
134
+ ],
135
+ "exclude": [
136
+ "tests/**"
137
+ ]
160
138
  }
161
139
  }
@@ -0,0 +1,61 @@
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
+ */
9
+
10
+ import { join } from 'node:path'
11
+ import { homedir } from 'node:os'
12
+ import { ApplicationService } from '@adonisjs/core/types'
13
+ import { isModuleInstalled } from '../src/utils.js'
14
+ import { fileURLToPath } from 'node:url'
15
+ import { defineReplBindings } from '../src/adonis_bindings.js'
16
+
17
+ export default class ReplProvider {
18
+ constructor(protected app: ApplicationService) {}
19
+
20
+ /**
21
+ * Create the typescript compiler to be used for compiling
22
+ * the user code inside the REPL
23
+ */
24
+ async #createCompiler() {
25
+ const { create } = await import('ts-node')
26
+
27
+ const tsConfigPath = new URL('./tsconfig.json', this.app.appRoot)
28
+
29
+ const tsNode = create({
30
+ project: fileURLToPath(tsConfigPath),
31
+ compilerOptions: { module: 'ESNext' },
32
+ })
33
+
34
+ return {
35
+ supportsTypescript: true,
36
+ compile(code: string, fileName: string) {
37
+ return tsNode.compile(code, fileName)
38
+ },
39
+ }
40
+ }
41
+
42
+ register() {
43
+ this.app.container.singleton('repl', async () => {
44
+ const { Repl } = await import('../src/repl.js')
45
+
46
+ let compiler
47
+ if (isModuleInstalled('ts-node')) {
48
+ compiler = await this.#createCompiler()
49
+ }
50
+
51
+ const repl = new Repl({
52
+ compiler,
53
+ historyFilePath: join(homedir(), '.adonis_repl_history'),
54
+ })
55
+
56
+ defineReplBindings(this.app, repl)
57
+
58
+ return repl
59
+ })
60
+ }
61
+ }