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