@adonisjs/assembler 8.0.0-next.8 → 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 +3 -1
  4. package/build/index.js +927 -1720
  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 +22 -2
  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-N6H4XTTC.js +0 -405
  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,405 +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
- 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
- toImportPath: this.#createBarrelFileImportGenerator(
148
- this.#source,
149
- this.#outputDirname,
150
- this.#config
151
- )
152
- });
153
- }
154
- await mkdir(dirname(this.#output), { recursive: true });
155
- await writeFile(this.#output, buffer.flush());
156
- });
157
- /**
158
- * Unique name for this index generator source
159
- */
160
- name;
161
- /**
162
- * Create a new IndexGeneratorSource instance
163
- *
164
- * @param name - Unique name for this index generator source
165
- * @param appRoot - The application root directory path
166
- * @param cliLogger - Logger instance for CLI output
167
- * @param config - Configuration for this index generator source
168
- */
169
- constructor(name, appRoot, cliLogger, config) {
170
- this.name = name;
171
- this.#config = config;
172
- this.#appRoot = appRoot;
173
- this.#cliLogger = cliLogger;
174
- this.#source = join(this.#appRoot, this.#config.source);
175
- this.#output = join(this.#appRoot, this.#config.output);
176
- this.#outputDirname = dirname(this.#output);
177
- this.#vfs = new VirtualFileSystem(this.#source, {
178
- glob: this.#config.glob
179
- });
180
- }
181
- /**
182
- * Converts a recursive file tree to a string representation
183
- *
184
- * This method recursively processes a file tree structure and writes
185
- * it as JavaScript object notation to the provided buffer.
186
- *
187
- * @param input - The recursive file tree to convert
188
- * @param buffer - The file buffer to write the output to
189
- */
190
- #treeToString(input, buffer) {
191
- Object.keys(input).forEach((key) => {
192
- const value = input[key];
193
- if (typeof value === "string") {
194
- buffer.write(`${key}: ${value},`);
195
- } else {
196
- buffer.write(`${key}: {`).indent();
197
- this.#treeToString(value, buffer);
198
- buffer.dedent().write(`},`);
199
- }
200
- });
201
- }
202
- /**
203
- * Transforms the barrel file index key. Converts basename to PascalCase
204
- * and all other paths to camelCase
205
- *
206
- * @param config - Configuration containing suffix removal options
207
- * @returns Function that transforms file paths to appropriate keys
208
- */
209
- #createBarrelFileKeyGenerator(config) {
210
- return function(key) {
211
- const paths = key.split("/");
212
- let baseName = new StringBuilder(paths.pop());
213
- if (config.computeBaseName) {
214
- baseName = config.computeBaseName(baseName);
215
- } else {
216
- baseName = baseName.removeSuffix(config.removeSuffix ?? "").pascalCase();
217
- }
218
- return [...paths.map((p) => string.camelCase(p)), baseName.toString()].join("/");
219
- };
220
- }
221
- /**
222
- * Converts the file path to a lazy import. In case of an alias, the source
223
- * path is replaced with the alias, otherwise a relative import is created
224
- * from the output dirname.
225
- *
226
- * @param source - The source directory path
227
- * @param outputDirname - The output directory path
228
- * @param config - Configuration containing import alias options
229
- * @returns Function that converts file paths to import statements
230
- */
231
- #createBarrelFileImportGenerator(source, outputDirname, config) {
232
- return function(filePath) {
233
- if (config.importAlias) {
234
- debug_default('converting "%s" to import alias, source "%s"', filePath, source);
235
- return removeExtension(filePath.replace(source, config.importAlias));
236
- }
237
- debug_default('converting "%s" to relative import, source "%s"', filePath, outputDirname);
238
- return relative(outputDirname, filePath);
239
- };
240
- }
241
- /**
242
- * Generate a barrel file export structure
243
- *
244
- * This method creates a nested object structure that represents all
245
- * discovered files as lazy imports, organized by directory structure.
246
- *
247
- * @param vfs - Virtual file system containing the scanned files
248
- * @param buffer - File buffer to write the barrel exports to
249
- * @param exportName - Name for the main export object
250
- */
251
- #asBarrelFile(vfs, buffer, exportName) {
252
- const keyGenerator = this.#createBarrelFileKeyGenerator(this.#config);
253
- const importGenerator = this.#createBarrelFileImportGenerator(
254
- this.#source,
255
- this.#outputDirname,
256
- this.#config
257
- );
258
- const tree = vfs.asTree({
259
- transformKey: keyGenerator,
260
- transformValue: (filePath) => {
261
- return `() => import('${importGenerator(filePath)}')`;
262
- }
263
- });
264
- buffer.write(`export const ${exportName} = {`).indent();
265
- this.#treeToString(tree, buffer);
266
- buffer.dedent().write(`}`);
267
- }
268
- /**
269
- * Create a log action for tracking file generation progress
270
- *
271
- * @example
272
- * const action = this.#createLogAction()
273
- * // ... perform operations
274
- * action.displayDuration().succeeded()
275
- */
276
- #createLogAction() {
277
- return this.#cliLogger.action(`create ${this.#config.output}`);
278
- }
279
- /**
280
- * Add a file to the virtual file system and regenerate index if needed
281
- *
282
- * If the file matches the configured glob patterns, it will be added
283
- * to the virtual file system and the index file will be regenerated.
284
- *
285
- * @param filePath - Absolute path of the file to add
286
- */
287
- async addFile(filePath) {
288
- const added = this.#vfs.add(filePath);
289
- if (added) {
290
- debug_default('file added, re-generating "%s" index', this.name);
291
- const action = this.#createLogAction();
292
- await this.#generateOutput();
293
- action.displayDuration().succeeded();
294
- }
295
- }
296
- /**
297
- * Remove a file from the virtual file system and regenerate index if needed
298
- *
299
- * If the file was previously tracked, it will be removed from the
300
- * virtual file system and the index file will be regenerated.
301
- *
302
- * @param filePath - Absolute path of the file to remove
303
- */
304
- async removeFile(filePath) {
305
- const removed = this.#vfs.remove(filePath);
306
- if (removed) {
307
- debug_default('file removed, re-generating "%s" index', this.name);
308
- const action = this.#createLogAction();
309
- await this.#generateOutput();
310
- action.displayDuration().succeeded();
311
- }
312
- }
313
- /**
314
- * Generate the index file
315
- *
316
- * This method scans the source directory, processes files according to
317
- * the configuration, and writes the generated index file to disk.
318
- */
319
- async generate() {
320
- const action = this.#createLogAction();
321
- await this.#vfs.scan();
322
- await this.#generateOutput();
323
- action.displayDuration().succeeded();
324
- }
325
- };
326
-
327
- // src/index_generator/main.ts
328
- var IndexGenerator = class {
329
- /**
330
- * The application root directory path
331
- */
332
- appRoot;
333
- /**
334
- * Collection of registered index generator sources
335
- */
336
- #sources = {};
337
- #cliLogger;
338
- /**
339
- * Create a new IndexGenerator instance
340
- *
341
- * @param appRoot - The application root directory path
342
- * @param cliLogger - Logger instance for CLI output
343
- */
344
- constructor(appRoot, cliLogger) {
345
- this.appRoot = appRoot;
346
- this.#cliLogger = cliLogger;
347
- }
348
- /**
349
- * Add a new index generator source
350
- *
351
- * @param name - Unique name for the source
352
- * @param config - Configuration for the index generator source
353
- * @returns This IndexGenerator instance for method chaining
354
- */
355
- add(name, config) {
356
- this.#sources[name] = new IndexGeneratorSource(name, this.appRoot, this.#cliLogger, config);
357
- return this;
358
- }
359
- /**
360
- * Add a file to all registered index generator sources
361
- *
362
- * This method propagates the file addition to all registered sources,
363
- * allowing them to regenerate their index files if the new file matches
364
- * their glob patterns.
365
- *
366
- * @param filePath - Absolute path of the file to add
367
- */
368
- async addFile(filePath) {
369
- const sources = Object.values(this.#sources);
370
- for (let source of sources) {
371
- await source.addFile(filePath);
372
- }
373
- }
374
- /**
375
- * Remove a file from all registered index generator sources
376
- *
377
- * This method propagates the file removal to all registered sources,
378
- * allowing them to regenerate their index files if the removed file
379
- * was previously tracked.
380
- *
381
- * @param filePath - Absolute path of the file to remove
382
- */
383
- async removeFile(filePath) {
384
- const sources = Object.values(this.#sources);
385
- for (let source of sources) {
386
- await source.removeFile(filePath);
387
- }
388
- }
389
- /**
390
- * Generate all registered index files
391
- *
392
- * Iterates through all registered sources and generates their
393
- * corresponding index files.
394
- */
395
- async generate() {
396
- const sources = Object.values(this.#sources);
397
- for (let source of sources) {
398
- await source.generate();
399
- }
400
- }
401
- };
402
-
403
- export {
404
- IndexGenerator
405
- };