@adonisjs/assembler 6.1.3-20 → 6.1.3-22
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.
- package/build/src/bundler.js +1 -18
- package/build/src/code_transformer/main.js +46 -34
- package/package.json +1 -1
package/build/src/bundler.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import slash from 'slash';
|
|
10
10
|
import fs from 'node:fs/promises';
|
|
11
|
+
import { relative } from 'node:path';
|
|
11
12
|
import { fileURLToPath } from 'node:url';
|
|
12
|
-
import { join, relative } from 'node:path';
|
|
13
13
|
import { cliui } from '@poppinss/cliui';
|
|
14
14
|
import { run, parseConfig, copyFiles } from './helpers.js';
|
|
15
15
|
/**
|
|
@@ -105,18 +105,6 @@ export class Bundler {
|
|
|
105
105
|
.concat(additionalFilesToCopy);
|
|
106
106
|
await this.#copyFiles(metaFiles, outDir);
|
|
107
107
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Copies .adonisrc.json file to the destination
|
|
110
|
-
*/
|
|
111
|
-
async #copyAdonisRcFile(outDir) {
|
|
112
|
-
const existingContents = JSON.parse(await fs.readFile(join(this.#cwdPath, '.adonisrc.json'), 'utf-8'));
|
|
113
|
-
const compiledContents = Object.assign({}, existingContents, {
|
|
114
|
-
typescript: false,
|
|
115
|
-
lastCompiledAt: new Date().toISOString(),
|
|
116
|
-
});
|
|
117
|
-
await fs.mkdir(outDir, { recursive: true });
|
|
118
|
-
await fs.writeFile(join(outDir, '.adonisrc.json'), JSON.stringify(compiledContents, null, 2) + '\n');
|
|
119
|
-
}
|
|
120
108
|
/**
|
|
121
109
|
* Returns the lock file name for a given packages client
|
|
122
110
|
*/
|
|
@@ -200,11 +188,6 @@ export class Bundler {
|
|
|
200
188
|
const pkgFiles = ['package.json', this.#getClientLockFile(client)];
|
|
201
189
|
this.#logger.info('copying meta files to the output directory');
|
|
202
190
|
await this.#copyMetaFiles(outDir, pkgFiles);
|
|
203
|
-
/**
|
|
204
|
-
* Step 6: Copy .adonisrc.json file to the build directory
|
|
205
|
-
*/
|
|
206
|
-
this.#logger.info('copying .adonisrc.json file to the output directory');
|
|
207
|
-
await this.#copyAdonisRcFile(outDir);
|
|
208
191
|
this.#logger.success('build completed');
|
|
209
192
|
this.#logger.log('');
|
|
210
193
|
/**
|
|
@@ -63,28 +63,28 @@ export class CodeTransformer {
|
|
|
63
63
|
/**
|
|
64
64
|
* Delete the existing middleware if it exists
|
|
65
65
|
*/
|
|
66
|
-
const
|
|
66
|
+
const existingMiddlewareIndex = arrayLiteralExpression
|
|
67
67
|
.getElements()
|
|
68
68
|
.findIndex((element) => element.getText() === middleware);
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
arrayLiteralExpression.addElement(middleware);
|
|
69
|
+
if (existingMiddlewareIndex === -1) {
|
|
70
|
+
/**
|
|
71
|
+
* Add the middleware to the top or bottom of the array
|
|
72
|
+
*/
|
|
73
|
+
if (middlewareEntry.position === 'before') {
|
|
74
|
+
arrayLiteralExpression.insertElement(0, middleware);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
arrayLiteralExpression.addElement(middleware);
|
|
78
|
+
}
|
|
80
79
|
}
|
|
81
80
|
}
|
|
82
81
|
/**
|
|
83
82
|
* Add a new middleware to the named middleware of the given file
|
|
84
83
|
*/
|
|
85
84
|
#addToNamedMiddleware(file, middlewareEntry) {
|
|
86
|
-
if (!middlewareEntry.name)
|
|
85
|
+
if (!middlewareEntry.name) {
|
|
87
86
|
throw new Error('Named middleware requires a name.');
|
|
87
|
+
}
|
|
88
88
|
const callArguments = file
|
|
89
89
|
.getVariableDeclarationOrThrow('middleware')
|
|
90
90
|
.getInitializerIfKindOrThrow(SyntaxKind.CallExpression)
|
|
@@ -100,20 +100,21 @@ export class CodeTransformer {
|
|
|
100
100
|
* Check if property is already defined. If so, remove it
|
|
101
101
|
*/
|
|
102
102
|
const existingProperty = namedMiddlewareObject.getProperty(middlewareEntry.name);
|
|
103
|
-
if (existingProperty)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
103
|
+
if (!existingProperty) {
|
|
104
|
+
/**
|
|
105
|
+
* Add the named middleware
|
|
106
|
+
*/
|
|
107
|
+
const middleware = `${middlewareEntry.name}: () => import('${middlewareEntry.path}')`;
|
|
108
|
+
namedMiddlewareObject.insertProperty(0, middleware);
|
|
109
|
+
}
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Write a leading comment
|
|
113
113
|
*/
|
|
114
114
|
#addLeadingComment(writer, comment) {
|
|
115
|
-
if (!comment)
|
|
115
|
+
if (!comment) {
|
|
116
116
|
return writer.blankLine();
|
|
117
|
+
}
|
|
117
118
|
return writer
|
|
118
119
|
.blankLine()
|
|
119
120
|
.writeLine('/*')
|
|
@@ -173,7 +174,7 @@ export class CodeTransformer {
|
|
|
173
174
|
if (!Node.isObjectLiteralExpression(objectLiteralExpression)) {
|
|
174
175
|
throw new Error(`The second argument of Env.create is not an object literal.`);
|
|
175
176
|
}
|
|
176
|
-
let
|
|
177
|
+
let shouldAddComment = true;
|
|
177
178
|
/**
|
|
178
179
|
* Add each variable validation
|
|
179
180
|
*/
|
|
@@ -182,18 +183,29 @@ export class CodeTransformer {
|
|
|
182
183
|
* Check if the variable is already defined. If so, remove it
|
|
183
184
|
*/
|
|
184
185
|
const existingProperty = objectLiteralExpression.getProperty(variable);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Do not add leading comment if one or more properties
|
|
188
|
+
* already exists
|
|
189
|
+
*/
|
|
190
|
+
if (existingProperty) {
|
|
191
|
+
shouldAddComment = false;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Add property only when the property does not exist
|
|
195
|
+
*/
|
|
196
|
+
if (!existingProperty) {
|
|
197
|
+
objectLiteralExpression.addPropertyAssignment({
|
|
198
|
+
name: variable,
|
|
199
|
+
initializer: validation,
|
|
200
|
+
leadingTrivia: (writer) => {
|
|
201
|
+
if (!shouldAddComment) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
shouldAddComment = false;
|
|
205
|
+
return this.#addLeadingComment(writer, definition.leadingComment);
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
}
|
|
197
209
|
}
|
|
198
210
|
file.formatText(this.#editorSettings);
|
|
199
211
|
await file.save();
|