@adonisjs/assembler
Advanced tools
Comparing version 6.1.3-21 to 6.1.3-22
@@ -66,17 +66,16 @@ /* | ||
*/ | ||
const existingMiddleware = arrayLiteralExpression | ||
const existingMiddlewareIndex = arrayLiteralExpression | ||
.getElements() | ||
.findIndex((element) => element.getText() === middleware); | ||
if (existingMiddleware !== -1) { | ||
arrayLiteralExpression.removeElement(existingMiddleware); | ||
if (existingMiddlewareIndex === -1) { | ||
/** | ||
* Add the middleware to the top or bottom of the array | ||
*/ | ||
if (middlewareEntry.position === 'before') { | ||
arrayLiteralExpression.insertElement(0, middleware); | ||
} | ||
else { | ||
arrayLiteralExpression.addElement(middleware); | ||
} | ||
} | ||
/** | ||
* Add the middleware to the top or bottom of the array | ||
*/ | ||
if (middlewareEntry.position === 'before') { | ||
arrayLiteralExpression.insertElement(0, middleware); | ||
} | ||
else { | ||
arrayLiteralExpression.addElement(middleware); | ||
} | ||
} | ||
@@ -87,4 +86,5 @@ /** | ||
#addToNamedMiddleware(file, middlewareEntry) { | ||
if (!middlewareEntry.name) | ||
if (!middlewareEntry.name) { | ||
throw new Error('Named middleware requires a name.'); | ||
} | ||
const callArguments = file | ||
@@ -105,9 +105,9 @@ .getVariableDeclarationOrThrow('middleware') | ||
const existingProperty = namedMiddlewareObject.getProperty(middlewareEntry.name); | ||
if (existingProperty) | ||
existingProperty.remove(); | ||
/** | ||
* Add the named middleware | ||
*/ | ||
const middleware = `${middlewareEntry.name}: () => import('${middlewareEntry.path}')`; | ||
namedMiddlewareObject.insertProperty(0, middleware); | ||
if (!existingProperty) { | ||
/** | ||
* Add the named middleware | ||
*/ | ||
const middleware = `${middlewareEntry.name}: () => import('${middlewareEntry.path}')`; | ||
namedMiddlewareObject.insertProperty(0, middleware); | ||
} | ||
} | ||
@@ -118,4 +118,5 @@ /** | ||
#addLeadingComment(writer, comment) { | ||
if (!comment) | ||
if (!comment) { | ||
return writer.blankLine(); | ||
} | ||
return writer | ||
@@ -180,3 +181,3 @@ .blankLine() | ||
} | ||
let firstAdded = false; | ||
let shouldAddComment = true; | ||
/** | ||
@@ -190,14 +191,25 @@ * Add each variable validation | ||
const existingProperty = objectLiteralExpression.getProperty(variable); | ||
if (existingProperty) | ||
existingProperty.remove(); | ||
objectLiteralExpression.addPropertyAssignment({ | ||
name: variable, | ||
initializer: validation, | ||
leadingTrivia: (writer) => { | ||
if (firstAdded) | ||
return; | ||
firstAdded = true; | ||
return this.#addLeadingComment(writer, definition.leadingComment); | ||
}, | ||
}); | ||
/** | ||
* Do not add leading comment if one or more properties | ||
* already exists | ||
*/ | ||
if (existingProperty) { | ||
shouldAddComment = false; | ||
} | ||
/** | ||
* Add property only when the property does not exist | ||
*/ | ||
if (!existingProperty) { | ||
objectLiteralExpression.addPropertyAssignment({ | ||
name: variable, | ||
initializer: validation, | ||
leadingTrivia: (writer) => { | ||
if (!shouldAddComment) { | ||
return; | ||
} | ||
shouldAddComment = false; | ||
return this.#addLeadingComment(writer, definition.leadingComment); | ||
}, | ||
}); | ||
} | ||
} | ||
@@ -204,0 +216,0 @@ file.formatText(this.#editorSettings); |
{ | ||
"name": "@adonisjs/assembler", | ||
"description": "Provides utilities to run AdonisJS development server and build project for production", | ||
"version": "6.1.3-21", | ||
"version": "6.1.3-22", | ||
"engines": { | ||
@@ -6,0 +6,0 @@ "node": ">=18.16.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71968
2034