@adonisjs/assembler 8.0.0 → 8.1.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.
@@ -0,0 +1,9 @@
1
+ import "node:module";
2
+ Object.create;
3
+ Object.defineProperty;
4
+ Object.getOwnPropertyDescriptor;
5
+ Object.getOwnPropertyNames;
6
+ Object.getPrototypeOf;
7
+ Object.prototype.hasOwnProperty;
8
+ //#endregion
9
+ export {};
@@ -1,5 +1,23 @@
1
+ //#region src/exceptions/codemod_exception.ts
2
+ /**
3
+ * Custom exception for codemod errors that provides helpful instructions
4
+ * to the user when automatic code transformation fails.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * throw CodemodException.missingEnvFile('start/env.ts', {
9
+ * variables: { MY_VAR: 'Env.schema.string()' }
10
+ * })
11
+ * ```
12
+ */
1
13
  var CodemodException = class CodemodException extends Error {
14
+ /**
15
+ * Instructions for the user to manually perform the codemod action
16
+ */
2
17
  instructions;
18
+ /**
19
+ * The file path that was being modified
20
+ */
3
21
  filePath;
4
22
  constructor(message, options) {
5
23
  super(message);
@@ -7,6 +25,9 @@ var CodemodException = class CodemodException extends Error {
7
25
  this.instructions = options?.instructions;
8
26
  this.filePath = options?.filePath;
9
27
  }
28
+ /**
29
+ * Format env validations as code string
30
+ */
10
31
  static #formatEnvValidations(definition) {
11
32
  const lines = [];
12
33
  if (definition.leadingComment) {
@@ -19,19 +40,37 @@ var CodemodException = class CodemodException extends Error {
19
40
  for (const [variable, validation] of Object.entries(definition.variables)) lines.push(`${variable}: ${validation},`);
20
41
  return lines.join("\n");
21
42
  }
43
+ /**
44
+ * Format middleware as code string
45
+ */
22
46
  static #formatMiddleware(stack, middleware) {
23
47
  if (stack === "named") return `export const middleware = router.named({\n ${middleware.filter((m) => m.name).map((m) => `${m.name}: () => import('${m.path}')`).join(",\n ")}\n})`;
24
48
  return `${stack}.use([\n ${middleware.map((m) => `() => import('${m.path}')`).join(",\n ")}\n])`;
25
49
  }
50
+ /**
51
+ * Format policies as code string
52
+ */
26
53
  static #formatPolicies(policies) {
27
54
  return `export const policies = {\n ${policies.map((p) => `${p.name}: () => import('${p.path}')`).join(",\n ")}\n}`;
28
55
  }
56
+ /**
57
+ * Format Vite plugin as code string
58
+ */
29
59
  static #formatVitePlugin(pluginCall, importDeclarations) {
30
60
  return `${importDeclarations.map((decl) => decl.isNamed ? `import { ${decl.identifier} } from '${decl.module}'` : `import ${decl.identifier} from '${decl.module}'`).join("\n")}\n\nexport default defineConfig({\n plugins: [${pluginCall}]\n})`;
31
61
  }
62
+ /**
63
+ * Format Japa plugin as code string
64
+ */
32
65
  static #formatJapaPlugin(pluginCall, importDeclarations) {
33
66
  return `${importDeclarations.map((decl) => decl.isNamed ? `import { ${decl.identifier} } from '${decl.module}'` : `import ${decl.identifier} from '${decl.module}'`).join("\n")}\n\nexport const plugins: Config['plugins'] = [\n ${pluginCall}\n]`;
34
67
  }
68
+ /**
69
+ * Creates an exception when start/env.ts file is missing
70
+ *
71
+ * @param filePath - The path to the missing file
72
+ * @param definition - The environment validation definition that was being added
73
+ */
35
74
  static missingEnvFile(filePath, definition) {
36
75
  const code = this.#formatEnvValidations(definition);
37
76
  return new CodemodException(`Could not find source file at path: "${filePath}"`, {
@@ -39,18 +78,37 @@ var CodemodException = class CodemodException extends Error {
39
78
  instructions: `Add the following code to "${filePath}":\n\n${code}`
40
79
  });
41
80
  }
81
+ /**
82
+ * Creates an exception when Env.create is not found in the file
83
+ *
84
+ * @param filePath - The path to the file being modified
85
+ * @param definition - The environment validation definition that was being added
86
+ */
42
87
  static missingEnvCreate(filePath, definition) {
43
88
  return new CodemodException(`Cannot find Env.create statement in the file.`, {
44
89
  filePath,
45
90
  instructions: `Add the following code inside Env.create() in "${filePath}":\n\n${this.#formatEnvValidations(definition)}`
46
91
  });
47
92
  }
93
+ /**
94
+ * Creates an exception when Env.create has invalid structure
95
+ *
96
+ * @param filePath - The path to the file being modified
97
+ * @param definition - The environment validation definition that was being added
98
+ */
48
99
  static invalidEnvCreate(filePath, definition) {
49
100
  return new CodemodException(`The second argument of Env.create is not an object literal.`, {
50
101
  filePath,
51
102
  instructions: `Add the following code inside Env.create() in "${filePath}":\n\n${this.#formatEnvValidations(definition)}`
52
103
  });
53
104
  }
105
+ /**
106
+ * Creates an exception when start/kernel.ts file is missing
107
+ *
108
+ * @param filePath - The path to the missing file
109
+ * @param stack - The middleware stack that was being modified
110
+ * @param middleware - The middleware entries that were being added
111
+ */
54
112
  static missingKernelFile(filePath, stack, middleware) {
55
113
  const code = this.#formatMiddleware(stack, middleware);
56
114
  return new CodemodException(`Could not find source file at path: "${filePath}"`, {
@@ -58,6 +116,13 @@ var CodemodException = class CodemodException extends Error {
58
116
  instructions: `Add the following code to "${filePath}":\n\n${code}`
59
117
  });
60
118
  }
119
+ /**
120
+ * Creates an exception when server.use/router.use is not found
121
+ *
122
+ * @param filePath - The path to the file being modified
123
+ * @param stack - The middleware stack that was being modified
124
+ * @param middleware - The middleware entries that were being added
125
+ */
61
126
  static missingMiddlewareStack(filePath, stack, middleware) {
62
127
  const code = this.#formatMiddleware(stack, middleware);
63
128
  return new CodemodException(`Cannot find ${stack === "named" ? "middleware variable" : `${stack}.use`} statement in the file.`, {
@@ -65,12 +130,26 @@ var CodemodException = class CodemodException extends Error {
65
130
  instructions: `Add the following code to "${filePath}":\n\n${code}`
66
131
  });
67
132
  }
133
+ /**
134
+ * Creates an exception when middleware array structure is invalid
135
+ *
136
+ * @param filePath - The path to the file being modified
137
+ * @param stack - The middleware stack that was being modified
138
+ * @param middleware - The middleware entries that were being added
139
+ * @param reason - The reason why the structure is invalid
140
+ */
68
141
  static invalidMiddlewareStack(filePath, stack, middleware, reason) {
69
142
  return new CodemodException(reason, {
70
143
  filePath,
71
144
  instructions: `Add the following code to "${filePath}":\n\n${this.#formatMiddleware(stack, middleware)}`
72
145
  });
73
146
  }
147
+ /**
148
+ * Creates an exception when app/policies/main.ts file is missing
149
+ *
150
+ * @param filePath - The path to the missing file
151
+ * @param policies - The policies that were being added
152
+ */
74
153
  static missingPoliciesFile(filePath, policies) {
75
154
  const code = this.#formatPolicies(policies);
76
155
  return new CodemodException(`Could not find source file at path: "${filePath}"`, {
@@ -78,24 +157,53 @@ var CodemodException = class CodemodException extends Error {
78
157
  instructions: `Add the following code to "${filePath}":\n\n${code}`
79
158
  });
80
159
  }
160
+ /**
161
+ * Creates an exception when policies structure is invalid
162
+ *
163
+ * @param filePath - The path to the file being modified
164
+ * @param policies - The policies that were being added
165
+ * @param reason - The reason why the structure is invalid
166
+ */
81
167
  static invalidPoliciesFile(filePath, policies, reason) {
82
168
  return new CodemodException(reason, {
83
169
  filePath,
84
170
  instructions: `Add the following code to "${filePath}":\n\n${this.#formatPolicies(policies)}`
85
171
  });
86
172
  }
173
+ /**
174
+ * Creates an exception when vite.config.ts file is missing
175
+ *
176
+ * @param filePath - The path to the missing file
177
+ * @param pluginCall - The plugin call that was being added
178
+ * @param importDeclarations - The import declarations needed for the plugin
179
+ */
87
180
  static missingViteConfig(filePath, pluginCall, importDeclarations) {
88
181
  return new CodemodException(`Cannot find vite.config.ts file. Make sure to rename vite.config.js to vite.config.ts`, {
89
182
  filePath,
90
183
  instructions: `Add the following code to "${filePath}":\n\n${this.#formatVitePlugin(pluginCall, importDeclarations)}`
91
184
  });
92
185
  }
186
+ /**
187
+ * Creates an exception when vite.config.ts structure is invalid
188
+ *
189
+ * @param filePath - The path to the file being modified
190
+ * @param pluginCall - The plugin call that was being added
191
+ * @param importDeclarations - The import declarations needed for the plugin
192
+ * @param reason - The reason why the structure is invalid
193
+ */
93
194
  static invalidViteConfig(filePath, pluginCall, importDeclarations, reason) {
94
195
  return new CodemodException(reason, {
95
196
  filePath,
96
197
  instructions: `Add the following code to "${filePath}":\n\n${this.#formatVitePlugin(pluginCall, importDeclarations)}`
97
198
  });
98
199
  }
200
+ /**
201
+ * Creates an exception when tests/bootstrap.ts file is missing
202
+ *
203
+ * @param filePath - The path to the missing file
204
+ * @param pluginCall - The plugin call that was being added
205
+ * @param importDeclarations - The import declarations needed for the plugin
206
+ */
99
207
  static missingJapaBootstrap(filePath, pluginCall, importDeclarations) {
100
208
  const code = this.#formatJapaPlugin(pluginCall, importDeclarations);
101
209
  return new CodemodException(`Could not find source file at path: "${filePath}"`, {
@@ -103,30 +211,64 @@ var CodemodException = class CodemodException extends Error {
103
211
  instructions: `Add the following code to "${filePath}":\n\n${code}`
104
212
  });
105
213
  }
214
+ /**
215
+ * Creates an exception when tests/bootstrap.ts structure is invalid
216
+ *
217
+ * @param filePath - The path to the file being modified
218
+ * @param pluginCall - The plugin call that was being added
219
+ * @param importDeclarations - The import declarations needed for the plugin
220
+ * @param reason - The reason why the structure is invalid
221
+ */
106
222
  static invalidJapaBootstrap(filePath, pluginCall, importDeclarations, reason) {
107
223
  return new CodemodException(reason, {
108
224
  filePath,
109
225
  instructions: `Add the following code to "${filePath}":\n\n${this.#formatJapaPlugin(pluginCall, importDeclarations)}`
110
226
  });
111
227
  }
228
+ /**
229
+ * Creates an exception when adonisrc.ts file is missing
230
+ *
231
+ * @param filePath - The path to the missing file
232
+ * @param codeToAdd - The code that should be added manually
233
+ */
112
234
  static missingRcFile(filePath, codeToAdd) {
113
235
  return new CodemodException(`Could not find source file at path: "${filePath}"`, {
114
236
  filePath,
115
237
  instructions: `Add the following code to "${filePath}":\n\n${codeToAdd}`
116
238
  });
117
239
  }
240
+ /**
241
+ * Creates an exception when adonisrc.ts structure is invalid
242
+ *
243
+ * @param filePath - The path to the file being modified
244
+ * @param codeToAdd - The code that should be added manually
245
+ * @param reason - The reason why the structure is invalid
246
+ */
118
247
  static invalidRcFile(filePath, codeToAdd, reason) {
119
248
  return new CodemodException(reason, {
120
249
  filePath,
121
250
  instructions: `Add the following code to "${filePath}":\n\n${codeToAdd}`
122
251
  });
123
252
  }
253
+ /**
254
+ * Creates an exception when a file required for transformation is not found.
255
+ *
256
+ * @param filePath - The path to the missing file
257
+ * @param codeToAdd - The code that should be added manually
258
+ */
124
259
  static E_CODEMOD_FILE_NOT_FOUND(filePath, codeToAdd) {
125
260
  return new CodemodException(`Could not find source file at path: "${filePath}"`, {
126
261
  filePath,
127
262
  instructions: `Add the following code to "${filePath}":\n\n${codeToAdd}`
128
263
  });
129
264
  }
265
+ /**
266
+ * Creates an exception when the file structure doesn't match expected patterns.
267
+ *
268
+ * @param message - Description of what structure was expected
269
+ * @param filePath - The path to the file being modified
270
+ * @param codeToAdd - The code that should be added manually
271
+ */
130
272
  static E_CODEMOD_INVALID_STRUCTURE(message, filePath, codeToAdd) {
131
273
  return new CodemodException(message, {
132
274
  filePath,
@@ -134,4 +276,5 @@ var CodemodException = class CodemodException extends Error {
134
276
  });
135
277
  }
136
278
  };
279
+ //#endregion
137
280
  export { CodemodException as t };