@adonisjs/assembler 6.1.3-19 → 6.1.3-20
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.
|
@@ -60,6 +60,18 @@ export class CodeTransformer {
|
|
|
60
60
|
throw new Error(`Cannot find middleware array in ${target} statement.`);
|
|
61
61
|
}
|
|
62
62
|
const middleware = `() => import('${middlewareEntry.path}')`;
|
|
63
|
+
/**
|
|
64
|
+
* Delete the existing middleware if it exists
|
|
65
|
+
*/
|
|
66
|
+
const existingMiddleware = arrayLiteralExpression
|
|
67
|
+
.getElements()
|
|
68
|
+
.findIndex((element) => element.getText() === middleware);
|
|
69
|
+
if (existingMiddleware !== -1) {
|
|
70
|
+
arrayLiteralExpression.removeElement(existingMiddleware);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Add the middleware to the top or bottom of the array
|
|
74
|
+
*/
|
|
63
75
|
if (middlewareEntry.position === 'before') {
|
|
64
76
|
arrayLiteralExpression.insertElement(0, middleware);
|
|
65
77
|
}
|
|
@@ -84,6 +96,15 @@ export class CodeTransformer {
|
|
|
84
96
|
if (!Node.isObjectLiteralExpression(namedMiddlewareObject)) {
|
|
85
97
|
throw new Error('The argument of the named middleware call is not an object literal.');
|
|
86
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if property is already defined. If so, remove it
|
|
101
|
+
*/
|
|
102
|
+
const existingProperty = namedMiddlewareObject.getProperty(middlewareEntry.name);
|
|
103
|
+
if (existingProperty)
|
|
104
|
+
existingProperty.remove();
|
|
105
|
+
/**
|
|
106
|
+
* Add the named middleware
|
|
107
|
+
*/
|
|
87
108
|
const middleware = `${middlewareEntry.name}: () => import('${middlewareEntry.path}')`;
|
|
88
109
|
namedMiddlewareObject.insertProperty(0, middleware);
|
|
89
110
|
}
|
|
@@ -157,6 +178,12 @@ export class CodeTransformer {
|
|
|
157
178
|
* Add each variable validation
|
|
158
179
|
*/
|
|
159
180
|
for (const [variable, validation] of Object.entries(definition.variables)) {
|
|
181
|
+
/**
|
|
182
|
+
* Check if the variable is already defined. If so, remove it
|
|
183
|
+
*/
|
|
184
|
+
const existingProperty = objectLiteralExpression.getProperty(variable);
|
|
185
|
+
if (existingProperty)
|
|
186
|
+
existingProperty.remove();
|
|
160
187
|
objectLiteralExpression.addPropertyAssignment({
|
|
161
188
|
name: variable,
|
|
162
189
|
initializer: validation,
|