@adonisjs/assembler 8.0.0-next.4 → 8.0.0-next.6

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.
Files changed (35) hide show
  1. package/README.md +87 -59
  2. package/build/chunk-F4RAGKQN.js +387 -0
  3. package/build/chunk-MC3FJR62.js +411 -0
  4. package/build/chunk-TIKQQRMX.js +116 -0
  5. package/build/index.d.ts +1 -0
  6. package/build/index.js +606 -410
  7. package/build/src/bundler.d.ts +40 -3
  8. package/build/src/code_scanners/routes_scanner/main.d.ts +49 -9
  9. package/build/src/code_scanners/routes_scanner/main.js +445 -0
  10. package/build/src/code_scanners/routes_scanner/validator_extractor.d.ts +12 -4
  11. package/build/src/code_transformer/main.d.ts +44 -43
  12. package/build/src/code_transformer/main.js +123 -101
  13. package/build/src/code_transformer/rc_file_transformer.d.ts +56 -4
  14. package/build/src/debug.d.ts +12 -0
  15. package/build/src/dev_server.d.ts +40 -30
  16. package/build/src/file_buffer.d.ts +67 -0
  17. package/build/src/file_system.d.ts +45 -7
  18. package/build/src/helpers.d.ts +79 -4
  19. package/build/src/helpers.js +16 -0
  20. package/build/src/index_generator/main.d.ts +73 -0
  21. package/build/src/index_generator/main.js +7 -0
  22. package/build/src/index_generator/source.d.ts +66 -0
  23. package/build/src/paths_resolver.d.ts +27 -2
  24. package/build/src/shortcuts_manager.d.ts +42 -4
  25. package/build/src/test_runner.d.ts +58 -31
  26. package/build/src/types/code_scanners.d.ts +138 -24
  27. package/build/src/types/code_transformer.d.ts +61 -19
  28. package/build/src/types/common.d.ts +199 -55
  29. package/build/src/types/hooks.d.ts +173 -17
  30. package/build/src/types/main.d.ts +13 -0
  31. package/build/src/utils.d.ts +88 -10
  32. package/build/src/virtual_file_system.d.ts +112 -0
  33. package/package.json +9 -3
  34. package/build/chunk-RR4HCA4M.js +0 -7
  35. package/build/src/ast_file_system.d.ts +0 -17
@@ -0,0 +1,411 @@
1
+ import {
2
+ VirtualFileSystem,
3
+ debug_default,
4
+ removeExtension,
5
+ throttle
6
+ } from "./chunk-F4RAGKQN.js";
7
+
8
+ // src/index_generator/source.ts
9
+ import string from "@poppinss/utils/string";
10
+ import { mkdir, writeFile } from "fs/promises";
11
+ import { dirname, join, relative } from "path/posix";
12
+ import StringBuilder from "@poppinss/utils/string_builder";
13
+
14
+ // src/file_buffer.ts
15
+ var FileBuffer = class _FileBuffer {
16
+ /**
17
+ * Collected lines
18
+ */
19
+ #buffer = [];
20
+ /**
21
+ * Current indentation size. Each call to indent will increment
22
+ * it by 2
23
+ */
24
+ #identationSize = 0;
25
+ /**
26
+ * Cached compiled output. Once this value is set, the `flush`
27
+ * method will become a noop
28
+ */
29
+ #compiledOutput;
30
+ /**
31
+ * Creates a new child buffer instance
32
+ *
33
+ * @returns A new FileBuffer instance
34
+ */
35
+ create() {
36
+ return new _FileBuffer();
37
+ }
38
+ /**
39
+ * Returns the size of buffer text
40
+ *
41
+ * @returns The number of lines in the buffer
42
+ */
43
+ get size() {
44
+ return this.#buffer.length;
45
+ }
46
+ /**
47
+ * Write a new line to the output with current indentation
48
+ *
49
+ * @param text - The text to write as a new line
50
+ * @returns This FileBuffer instance for method chaining
51
+ */
52
+ writeLine(text) {
53
+ this.#buffer.push(`${" ".repeat(this.#identationSize)}${text}
54
+ `);
55
+ return this;
56
+ }
57
+ /**
58
+ * Write text to the output without adding a new line
59
+ *
60
+ * @param text - The text to write without a newline
61
+ * @returns This FileBuffer instance for method chaining
62
+ */
63
+ write(text) {
64
+ this.#buffer.push(`${" ".repeat(this.#identationSize)}${text}`);
65
+ return this;
66
+ }
67
+ /**
68
+ * Increase indentation by 2 spaces
69
+ *
70
+ * @returns This FileBuffer instance for method chaining
71
+ */
72
+ indent() {
73
+ this.#identationSize += 2;
74
+ return this;
75
+ }
76
+ /**
77
+ * Decrease indentation by 2 spaces (minimum of 0)
78
+ *
79
+ * @returns This FileBuffer instance for method chaining
80
+ */
81
+ dedent() {
82
+ this.#identationSize -= 2;
83
+ if (this.#identationSize < 0) {
84
+ this.#identationSize = 0;
85
+ }
86
+ return this;
87
+ }
88
+ /**
89
+ * Return template as a string, joining all buffer lines
90
+ *
91
+ * Once called, the output is cached and subsequent calls return the same result.
92
+ * The flush method becomes a no-op after the first call.
93
+ *
94
+ * @returns The complete buffer content as a string
95
+ */
96
+ flush() {
97
+ if (this.#compiledOutput !== void 0) {
98
+ return this.#compiledOutput;
99
+ }
100
+ this.#compiledOutput = this.#buffer.join("\n");
101
+ return this.#compiledOutput;
102
+ }
103
+ };
104
+
105
+ // src/index_generator/source.ts
106
+ var IndexGeneratorSource = class {
107
+ /**
108
+ * The application root directory path
109
+ */
110
+ #appRoot;
111
+ /**
112
+ * The absolute path to the output file
113
+ */
114
+ #output;
115
+ /**
116
+ * The absolute path to the source directory
117
+ */
118
+ #source;
119
+ /**
120
+ * The directory containing the output file
121
+ */
122
+ #outputDirname;
123
+ /**
124
+ * Virtual file system for scanning source files
125
+ */
126
+ #vfs;
127
+ /**
128
+ * Configuration for this index generator source
129
+ */
130
+ #config;
131
+ /**
132
+ * CLI logger instance for output messages
133
+ */
134
+ #cliLogger;
135
+ /**
136
+ * Generate the output content and write it to the output file
137
+ *
138
+ * This method creates the file buffer, populates it with the generated
139
+ * content based on configuration, and writes it to disk.
140
+ */
141
+ #generateOutput = throttle(async () => {
142
+ const buffer = new FileBuffer();
143
+ if (this.#config.as === "barrelFile") {
144
+ this.#asBarrelFile(this.#vfs, buffer, this.#config.exportName);
145
+ } else {
146
+ this.#config.as(this.#vfs, buffer, this.#config);
147
+ }
148
+ await mkdir(dirname(this.#output), { recursive: true });
149
+ await writeFile(this.#output, buffer.flush());
150
+ });
151
+ /**
152
+ * Unique name for this index generator source
153
+ */
154
+ name;
155
+ /**
156
+ * Create a new IndexGeneratorSource instance
157
+ *
158
+ * @param name - Unique name for this index generator source
159
+ * @param appRoot - The application root directory path
160
+ * @param cliLogger - Logger instance for CLI output
161
+ * @param config - Configuration for this index generator source
162
+ */
163
+ constructor(name, appRoot, cliLogger, config) {
164
+ this.name = name;
165
+ this.#config = config;
166
+ this.#appRoot = appRoot;
167
+ this.#cliLogger = cliLogger;
168
+ this.#source = join(this.#appRoot, this.#config.source);
169
+ this.#output = join(this.#appRoot, this.#config.output);
170
+ this.#outputDirname = dirname(this.#output);
171
+ this.#vfs = new VirtualFileSystem(this.#source, {
172
+ glob: this.#config.glob
173
+ });
174
+ }
175
+ /**
176
+ * Set the logger instance used for CLI output
177
+ *
178
+ * @param cliLogger - New logger instance to use
179
+ */
180
+ setLogger(cliLogger) {
181
+ this.#cliLogger = cliLogger;
182
+ }
183
+ /**
184
+ * Converts a recursive file tree to a string representation
185
+ *
186
+ * This method recursively processes a file tree structure and writes
187
+ * it as JavaScript object notation to the provided buffer.
188
+ *
189
+ * @param input - The recursive file tree to convert
190
+ * @param buffer - The file buffer to write the output to
191
+ */
192
+ #treeToString(input, buffer) {
193
+ Object.keys(input).forEach((key) => {
194
+ const value = input[key];
195
+ if (typeof value === "string") {
196
+ buffer.write(`'${key}': ${value},`);
197
+ } else {
198
+ buffer.write(`'${key}': {`).indent();
199
+ this.#treeToString(value, buffer);
200
+ buffer.dedent().write(`},`);
201
+ }
202
+ });
203
+ }
204
+ /**
205
+ * Transforms the barrel file index key. Converts basename to PascalCase
206
+ * and all other paths to camelCase
207
+ *
208
+ * @param config - Configuration containing suffix removal options
209
+ * @returns Function that transforms file paths to appropriate keys
210
+ */
211
+ #createBarrelFileKeyGenerator(config) {
212
+ return function(key) {
213
+ const paths = key.split("/");
214
+ const baseName = new StringBuilder(paths.pop()).removeSuffix(config.removeSuffix ?? "").pascalCase().toString();
215
+ return [...paths.map((p) => string.camelCase(p)), baseName].join("/");
216
+ };
217
+ }
218
+ /**
219
+ * Converts the file path to a lazy import. In case of an alias, the source
220
+ * path is replaced with the alias, otherwise a relative import is created
221
+ * from the output dirname.
222
+ *
223
+ * @param source - The source directory path
224
+ * @param outputDirname - The output directory path
225
+ * @param config - Configuration containing import alias options
226
+ * @returns Function that converts file paths to import statements
227
+ */
228
+ #createBarrelFileImportGenerator(source, outputDirname, config) {
229
+ return function(filePath) {
230
+ if (config.importAlias) {
231
+ debug_default('converting "%s" to import alias, source "%s"', filePath, source);
232
+ return `() => import('${removeExtension(filePath.replace(source, config.importAlias))}')`;
233
+ }
234
+ debug_default('converting "%s" to relative import, source "%s"', filePath, outputDirname);
235
+ return `() => import('${relative(outputDirname, filePath)}')`;
236
+ };
237
+ }
238
+ /**
239
+ * Generate a barrel file export structure
240
+ *
241
+ * This method creates a nested object structure that represents all
242
+ * discovered files as lazy imports, organized by directory structure.
243
+ *
244
+ * @param vfs - Virtual file system containing the scanned files
245
+ * @param buffer - File buffer to write the barrel exports to
246
+ * @param exportName - Name for the main export object
247
+ */
248
+ #asBarrelFile(vfs, buffer, exportName) {
249
+ const keyGenerator = this.#createBarrelFileKeyGenerator(this.#config);
250
+ const importGenerator = this.#createBarrelFileImportGenerator(
251
+ this.#source,
252
+ this.#outputDirname,
253
+ this.#config
254
+ );
255
+ const tree = vfs.asTree({
256
+ transformKey: keyGenerator,
257
+ transformValue: importGenerator
258
+ });
259
+ buffer.write(`export const ${exportName} = {`).indent();
260
+ this.#treeToString(tree, buffer);
261
+ buffer.dedent().write(`}`);
262
+ }
263
+ /**
264
+ * Create a log action for tracking file generation progress
265
+ *
266
+ * @example
267
+ * const action = this.#createLogAction()
268
+ * // ... perform operations
269
+ * action.displayDuration().succeeded()
270
+ */
271
+ #createLogAction() {
272
+ return this.#cliLogger.action(`create ${this.#config.output}`);
273
+ }
274
+ /**
275
+ * Add a file to the virtual file system and regenerate index if needed
276
+ *
277
+ * If the file matches the configured glob patterns, it will be added
278
+ * to the virtual file system and the index file will be regenerated.
279
+ *
280
+ * @param filePath - Absolute path of the file to add
281
+ */
282
+ async addFile(filePath) {
283
+ const added = this.#vfs.add(filePath);
284
+ if (added) {
285
+ debug_default('file added, re-generating "%s" index', this.name);
286
+ const action = this.#createLogAction();
287
+ await this.#generateOutput();
288
+ action.displayDuration().succeeded();
289
+ }
290
+ }
291
+ /**
292
+ * Remove a file from the virtual file system and regenerate index if needed
293
+ *
294
+ * If the file was previously tracked, it will be removed from the
295
+ * virtual file system and the index file will be regenerated.
296
+ *
297
+ * @param filePath - Absolute path of the file to remove
298
+ */
299
+ async removeFile(filePath) {
300
+ const removed = this.#vfs.remove(filePath);
301
+ if (removed) {
302
+ debug_default('file removed, re-generating "%s" index', this.name);
303
+ const action = this.#createLogAction();
304
+ await this.#generateOutput();
305
+ action.displayDuration().succeeded();
306
+ }
307
+ }
308
+ /**
309
+ * Generate the index file
310
+ *
311
+ * This method scans the source directory, processes files according to
312
+ * the configuration, and writes the generated index file to disk.
313
+ */
314
+ async generate() {
315
+ const action = this.#createLogAction();
316
+ await this.#vfs.scan();
317
+ await this.#generateOutput();
318
+ action.displayDuration().succeeded();
319
+ }
320
+ };
321
+
322
+ // src/index_generator/main.ts
323
+ var IndexGenerator = class {
324
+ /**
325
+ * The application root directory path
326
+ */
327
+ #appRoot;
328
+ /**
329
+ * Collection of registered index generator sources
330
+ */
331
+ #sources = {};
332
+ #cliLogger;
333
+ /**
334
+ * Create a new IndexGenerator instance
335
+ *
336
+ * @param appRoot - The application root directory path
337
+ * @param cliLogger - Logger instance for CLI output
338
+ */
339
+ constructor(appRoot, cliLogger) {
340
+ this.#appRoot = appRoot;
341
+ this.#cliLogger = cliLogger;
342
+ }
343
+ /**
344
+ * Set the logger instance used for CLI output
345
+ *
346
+ * Updates the CLI logger instance for this index generator and all
347
+ * registered sources to use the new logger for output.
348
+ *
349
+ * @param cliLogger - New logger instance to use
350
+ */
351
+ setLogger(cliLogger) {
352
+ this.#cliLogger = cliLogger;
353
+ }
354
+ /**
355
+ * Add a new index generator source
356
+ *
357
+ * @param name - Unique name for the source
358
+ * @param config - Configuration for the index generator source
359
+ * @returns This IndexGenerator instance for method chaining
360
+ */
361
+ add(name, config) {
362
+ this.#sources[name] = new IndexGeneratorSource(name, this.#appRoot, this.#cliLogger, config);
363
+ return this;
364
+ }
365
+ /**
366
+ * Add a file to all registered index generator sources
367
+ *
368
+ * This method propagates the file addition to all registered sources,
369
+ * allowing them to regenerate their index files if the new file matches
370
+ * their glob patterns.
371
+ *
372
+ * @param filePath - Absolute path of the file to add
373
+ */
374
+ async addFile(filePath) {
375
+ const sources = Object.values(this.#sources);
376
+ for (let source of sources) {
377
+ await source.addFile(filePath);
378
+ }
379
+ }
380
+ /**
381
+ * Remove a file from all registered index generator sources
382
+ *
383
+ * This method propagates the file removal to all registered sources,
384
+ * allowing them to regenerate their index files if the removed file
385
+ * was previously tracked.
386
+ *
387
+ * @param filePath - Absolute path of the file to remove
388
+ */
389
+ async removeFile(filePath) {
390
+ const sources = Object.values(this.#sources);
391
+ for (let source of sources) {
392
+ await source.removeFile(filePath);
393
+ }
394
+ }
395
+ /**
396
+ * Generate all registered index files
397
+ *
398
+ * Iterates through all registered sources and generates their
399
+ * corresponding index files.
400
+ */
401
+ async generate() {
402
+ const sources = Object.values(this.#sources);
403
+ for (let source of sources) {
404
+ await source.generate();
405
+ }
406
+ }
407
+ };
408
+
409
+ export {
410
+ IndexGenerator
411
+ };
@@ -0,0 +1,116 @@
1
+ // src/helpers.ts
2
+ import { parseImports } from "parse-imports";
3
+ async function findImport(code, importReference) {
4
+ const importIdentifier = importReference.split(".")[0];
5
+ for (const $import of await parseImports(code, {})) {
6
+ if (!$import.importClause) {
7
+ continue;
8
+ }
9
+ if (!$import.moduleSpecifier.value) {
10
+ continue;
11
+ }
12
+ if ($import.importClause.default === importIdentifier) {
13
+ return {
14
+ specifier: $import.moduleSpecifier.value,
15
+ isConstant: $import.moduleSpecifier.isConstant,
16
+ clause: {
17
+ type: "default",
18
+ value: importIdentifier
19
+ }
20
+ };
21
+ }
22
+ if ($import.importClause.namespace === importIdentifier) {
23
+ return {
24
+ specifier: $import.moduleSpecifier.value,
25
+ isConstant: $import.moduleSpecifier.isConstant,
26
+ clause: {
27
+ type: "namespace",
28
+ value: importIdentifier
29
+ }
30
+ };
31
+ }
32
+ const namedImport = $import.importClause.named.find(({ binding }) => {
33
+ return binding === importIdentifier;
34
+ });
35
+ if (namedImport) {
36
+ return {
37
+ specifier: $import.moduleSpecifier.value,
38
+ isConstant: $import.moduleSpecifier.isConstant,
39
+ clause: {
40
+ type: "named",
41
+ value: namedImport.specifier,
42
+ ...namedImport.binding !== namedImport.specifier ? {
43
+ alias: namedImport.binding
44
+ } : {}
45
+ }
46
+ };
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ function inspectClass(node) {
52
+ return node.find({
53
+ rule: {
54
+ kind: "class_declaration"
55
+ }
56
+ });
57
+ }
58
+ function inspectClassMethods(node) {
59
+ return node.findAll({
60
+ rule: {
61
+ kind: "method_definition"
62
+ }
63
+ });
64
+ }
65
+ function nodeToPlainText(node) {
66
+ let out = [];
67
+ function toText(one) {
68
+ const children = one.children();
69
+ if (!children.length) {
70
+ out.push(one.text());
71
+ } else {
72
+ children.forEach((child) => toText(child));
73
+ }
74
+ }
75
+ toText(node);
76
+ return out.join("");
77
+ }
78
+ function inspectMethodArguments(node, methodCalls) {
79
+ const matchingExpressions = node.findAll({
80
+ rule: {
81
+ any: methodCalls.map((methodCall) => {
82
+ return {
83
+ pattern: {
84
+ context: `${methodCall}($$$ARGUMENTS)`,
85
+ selector: "call_expression"
86
+ }
87
+ };
88
+ })
89
+ }
90
+ });
91
+ return matchingExpressions.flatMap((matchingExpression) => {
92
+ return matchingExpression.findAll({ rule: { kind: "arguments" } });
93
+ });
94
+ }
95
+ function searchValidatorDirectUsage(node) {
96
+ const matchingExpressions = node.findAll({
97
+ rule: {
98
+ pattern: {
99
+ context: "$$$VALIDATOR.validate($$$)",
100
+ selector: "call_expression"
101
+ }
102
+ }
103
+ });
104
+ return matchingExpressions.flatMap((expression) => {
105
+ return expression.getMultipleMatches("VALIDATOR");
106
+ });
107
+ }
108
+
109
+ export {
110
+ findImport,
111
+ inspectClass,
112
+ inspectClassMethods,
113
+ nodeToPlainText,
114
+ inspectMethodArguments,
115
+ searchValidatorDirectUsage
116
+ };
package/build/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { Bundler } from './src/bundler.ts';
2
2
  export { DevServer } from './src/dev_server.ts';
3
3
  export { TestRunner } from './src/test_runner.ts';
4
+ export { SUPPORTED_PACKAGE_MANAGERS } from './src/bundler.ts';