@adonisjs/core 6.1.5-17 → 6.1.5-18

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.
@@ -1,5 +1,6 @@
1
+ import type { AddMiddlewareEntry, EnvValidationDefinition } from '@adonisjs/assembler/types';
2
+ import type { CodeTransformer } from '@adonisjs/assembler/code_transformer';
1
3
  import { BaseCommand } from '../modules/ace/main.js';
2
- import { RcFileEditor } from '@adonisjs/application/rc_file_editor';
3
4
  /**
4
5
  * The configure command is used to configure packages after installation
5
6
  */
@@ -22,10 +23,18 @@ export default class Configure extends BaseCommand {
22
23
  * Define one or more environment variables
23
24
  */
24
25
  defineEnvVariables(environmentVariables: Record<string, number | string | boolean>): Promise<void>;
26
+ /**
27
+ * Define validations for the environment variables
28
+ */
29
+ defineEnvValidations(validations: EnvValidationDefinition): Promise<void>;
30
+ /**
31
+ * Define validations for the environment variables
32
+ */
33
+ registerMiddleware(stack: 'server' | 'router' | 'named', middleware: AddMiddlewareEntry[]): Promise<void>;
25
34
  /**
26
35
  * Update rcFile
27
36
  */
28
- updateRcFile(callback: (rcFileEditor: RcFileEditor) => Promise<void> | void): Promise<void>;
37
+ updateRcFile(...params: Parameters<CodeTransformer['updateRcFile']>): Promise<void>;
29
38
  /**
30
39
  * Install packages using the correct package manager
31
40
  * You can specify version of each package by setting it in the
@@ -13,16 +13,24 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
13
13
  return c > 3 && r && Object.defineProperty(target, key, r), r;
14
14
  };
15
15
  import { slash } from '@poppinss/utils';
16
- import { installPackage, detectPackageManager } from '@antfu/install-pkg';
17
16
  import { EnvEditor } from '@adonisjs/env/editor';
17
+ import { installPackage, detectPackageManager } from '@antfu/install-pkg';
18
18
  import { args, BaseCommand, flags } from '../modules/ace/main.js';
19
- import { RcFileEditor } from '@adonisjs/application/rc_file_editor';
20
19
  /**
21
20
  * The configure command is used to configure packages after installation
22
21
  */
23
22
  export default class Configure extends BaseCommand {
24
23
  static commandName = 'configure';
25
24
  static description = 'Configure a package post installation';
25
+ /**
26
+ * Flag to know if assembler is installed as a
27
+ * peer dependency or not.
28
+ */
29
+ #isAssemblerInstalled;
30
+ /**
31
+ * Reference to lazily imported assembler code transformer
32
+ */
33
+ #codeTransformer;
26
34
  /**
27
35
  * Returns the package main exports
28
36
  */
@@ -47,6 +55,15 @@ export default class Configure extends BaseCommand {
47
55
  return `${this.colors.yellow(`pnpm add${devFlag}`)} ${packages.join(' ')}`;
48
56
  }
49
57
  }
58
+ /**
59
+ * Lazily installs assembler
60
+ */
61
+ async #installAssembler() {
62
+ if (this.#isAssemblerInstalled === undefined) {
63
+ this.#codeTransformer = await import('@adonisjs/assembler/code_transformer');
64
+ this.#isAssemblerInstalled = !!this.#codeTransformer;
65
+ }
66
+ }
50
67
  /**
51
68
  * Publish a stub file to the user project
52
69
  */
@@ -69,26 +86,70 @@ export default class Configure extends BaseCommand {
69
86
  * Define one or more environment variables
70
87
  */
71
88
  async defineEnvVariables(environmentVariables) {
72
- const logs = [];
73
89
  const editor = new EnvEditor(this.app.appRoot);
74
90
  await editor.load();
75
91
  Object.keys(environmentVariables).forEach((key) => {
76
92
  const value = environmentVariables[key];
77
93
  editor.add(key, value);
78
- logs.push(` ${this.colors.dim(`${key}=${value}`)}`);
79
94
  });
80
95
  await editor.save();
81
96
  this.logger.action('update .env file').succeeded();
82
- this.logger.log(logs.join('\n'));
97
+ }
98
+ /**
99
+ * Define validations for the environment variables
100
+ */
101
+ async defineEnvValidations(validations) {
102
+ await this.#installAssembler();
103
+ if (!this.#codeTransformer) {
104
+ this.logger.warning('Cannot update "start/env.ts" file. Install "@adonisjs/assembler" to modify source files');
105
+ return;
106
+ }
107
+ const transformer = new this.#codeTransformer.CodeTransformer(this.app.appRoot);
108
+ const action = this.logger.action('update start/env.ts file');
109
+ try {
110
+ await transformer.defineEnvValidations(validations);
111
+ action.succeeded();
112
+ }
113
+ catch (error) {
114
+ action.failed(error.message);
115
+ }
116
+ }
117
+ /**
118
+ * Define validations for the environment variables
119
+ */
120
+ async registerMiddleware(stack, middleware) {
121
+ await this.#installAssembler();
122
+ if (!this.#codeTransformer) {
123
+ this.logger.warning('Cannot update "start/kernel.ts" file. Install "@adonisjs/assembler" to modify source files');
124
+ return;
125
+ }
126
+ const transformer = new this.#codeTransformer.CodeTransformer(this.app.appRoot);
127
+ const action = this.logger.action('update start/kernel.ts file');
128
+ try {
129
+ await transformer.addMiddlewareToStack(stack, middleware);
130
+ action.succeeded();
131
+ }
132
+ catch (error) {
133
+ action.failed(error.message);
134
+ }
83
135
  }
84
136
  /**
85
137
  * Update rcFile
86
138
  */
87
- async updateRcFile(callback) {
88
- const rcFileEditor = new RcFileEditor(this.app.makeURL('.adonisrc.json'), this.app.rcFile.raw);
89
- await callback(rcFileEditor);
90
- await rcFileEditor.save();
91
- this.logger.action('update .adonisrc.json file').succeeded();
139
+ async updateRcFile(...params) {
140
+ await this.#installAssembler();
141
+ if (!this.#codeTransformer) {
142
+ this.logger.warning('Cannot update "adonisrc.ts" file. Install "@adonisjs/assembler" to modify source files');
143
+ return;
144
+ }
145
+ const action = this.logger.action('update adonisrc.ts file');
146
+ try {
147
+ await new this.#codeTransformer.CodeTransformer(this.app.appRoot).updateRcFile(...params);
148
+ action.succeeded();
149
+ }
150
+ catch (error) {
151
+ action.failed(error.message);
152
+ }
92
153
  }
93
154
  /**
94
155
  * Install packages using the correct package manager
@@ -1,7 +1,4 @@
1
- import type { ApplicationService } from '../src/types.js';
2
1
  import '../src/bindings/vinejs.js';
3
2
  import '../modules/http/request_validator.js';
4
3
  export default class VineJSServiceProvider {
5
- protected app: ApplicationService;
6
- constructor(app: ApplicationService);
7
4
  }
@@ -9,8 +9,4 @@
9
9
  import '../src/bindings/vinejs.js';
10
10
  import '../modules/http/request_validator.js';
11
11
  export default class VineJSServiceProvider {
12
- app;
13
- constructor(app) {
14
- this.app = app;
15
- }
16
12
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/core",
3
3
  "description": "Core of AdonisJS",
4
- "version": "6.1.5-17",
4
+ "version": "6.1.5-18",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -76,7 +76,7 @@
76
76
  "index:commands": "node --loader=ts-node/esm toolkit/main.js index build/commands"
77
77
  },
78
78
  "devDependencies": {
79
- "@adonisjs/assembler": "^6.1.3-17",
79
+ "@adonisjs/assembler": "^6.1.3-18",
80
80
  "@adonisjs/eslint-config": "^1.1.8",
81
81
  "@adonisjs/prettier-config": "^1.1.8",
82
82
  "@adonisjs/tsconfig": "^1.1.8",
@@ -138,7 +138,7 @@
138
138
  "youch-terminal": "^2.2.2"
139
139
  },
140
140
  "peerDependencies": {
141
- "@adonisjs/assembler": "^6.1.3-17",
141
+ "@adonisjs/assembler": "^6.1.3-18",
142
142
  "@vinejs/vine": "^1.6.0",
143
143
  "argon2": "^0.30.3",
144
144
  "bcrypt": "^5.0.1",