@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
@@ -0,0 +1,166 @@
1
+ import { f as throttle, l as removeExtension, m as debug_default, t as VirtualFileSystem } from "./virtual_file_system-bGeoWsK-.js";
2
+ import { mkdir, writeFile } from "node:fs/promises";
3
+ import string from "@poppinss/utils/string";
4
+ import { dirname, join, relative } from "node:path/posix";
5
+ import StringBuilder from "@poppinss/utils/string_builder";
6
+ var FileBuffer = class FileBuffer {
7
+ #eol = false;
8
+ #buffer = [];
9
+ #identationSize = 0;
10
+ #compiledOutput;
11
+ create() {
12
+ return new FileBuffer();
13
+ }
14
+ get size() {
15
+ return this.#buffer.length;
16
+ }
17
+ eol(enabled) {
18
+ this.#eol = enabled;
19
+ return this;
20
+ }
21
+ writeLine(text) {
22
+ if (typeof text === "string") this.#buffer.push(`${" ".repeat(this.#identationSize)}${text}\n`);
23
+ else {
24
+ this.#buffer.push(text);
25
+ this.#buffer.push("");
26
+ }
27
+ return this;
28
+ }
29
+ write(text) {
30
+ if (typeof text === "string") this.#buffer.push(`${" ".repeat(this.#identationSize)}${text}`);
31
+ else this.#buffer.push(text);
32
+ return this;
33
+ }
34
+ indent() {
35
+ this.#identationSize += 2;
36
+ return this;
37
+ }
38
+ dedent() {
39
+ this.#identationSize -= 2;
40
+ if (this.#identationSize < 0) this.#identationSize = 0;
41
+ return this;
42
+ }
43
+ toString() {
44
+ return this.flush();
45
+ }
46
+ flush() {
47
+ if (this.#compiledOutput !== void 0) return this.#compiledOutput;
48
+ this.#compiledOutput = this.#buffer.join("\n");
49
+ return this.#eol ? `${this.#compiledOutput}\n` : this.#compiledOutput;
50
+ }
51
+ };
52
+ var IndexGeneratorSource = class {
53
+ #appRoot;
54
+ #output;
55
+ #source;
56
+ #outputDirname;
57
+ #vfs;
58
+ #config;
59
+ #cliLogger;
60
+ #generateOutput = throttle(async () => {
61
+ const buffer = new FileBuffer().eol(true);
62
+ if (this.#config.comment) buffer.writeLine(this.#textToComment(typeof this.#config.comment === "string" ? this.#config.comment : `This file is automatically generated.\nDO NOT EDIT manually`));
63
+ if (this.#config.as === "barrelFile") this.#asBarrelFile(this.#vfs, buffer, this.#config.exportName, this.#config.disableLazyImports);
64
+ else this.#config.as(this.#vfs, buffer, this.#config, { toImportPath: this.#createBarrelFileImportGenerator(this.#source, this.#outputDirname, this.#config) });
65
+ await mkdir(dirname(this.#output), { recursive: true });
66
+ await writeFile(this.#output, buffer.flush());
67
+ });
68
+ name;
69
+ constructor(name, appRoot, cliLogger, config) {
70
+ this.name = name;
71
+ this.#config = config;
72
+ this.#appRoot = appRoot;
73
+ this.#cliLogger = cliLogger;
74
+ this.#source = join(this.#appRoot, this.#config.source);
75
+ this.#output = join(this.#appRoot, this.#config.output);
76
+ this.#outputDirname = dirname(this.#output);
77
+ this.#vfs = new VirtualFileSystem(this.#source, {
78
+ glob: this.#config.glob,
79
+ filter: this.#config.filter
80
+ });
81
+ }
82
+ #treeToString(input, buffer) {
83
+ Object.keys(input).forEach((key) => {
84
+ const value = input[key];
85
+ if (typeof value === "string") buffer.write(`${key}: ${value},`);
86
+ else {
87
+ buffer.write(`${key}: {`).indent();
88
+ this.#treeToString(value, buffer);
89
+ buffer.dedent().write(`},`);
90
+ }
91
+ });
92
+ }
93
+ #textToComment(text) {
94
+ return `/**\n * ${text.split("\n").join("\n * ")}\n */`;
95
+ }
96
+ #createBarrelFileKeyGenerator(config) {
97
+ return function(key) {
98
+ let paths = key.split("/");
99
+ let baseName = new StringBuilder(paths.pop());
100
+ if (config.skipSegments?.length) paths = paths.filter((p) => !config.skipSegments.includes(p));
101
+ if (config.computeBaseName) baseName = config.computeBaseName(baseName);
102
+ else baseName = baseName.removeSuffix(config.removeSuffix ?? "").pascalCase();
103
+ return [...paths.map((p) => string.camelCase(p)), baseName.toString()].join("/");
104
+ };
105
+ }
106
+ #createBarrelFileImportGenerator(source, outputDirname, config) {
107
+ return function(filePath) {
108
+ if (config.importAlias) {
109
+ debug_default("converting \"%s\" to import alias, source \"%s\"", filePath, source);
110
+ return removeExtension(filePath.replace(source, config.importAlias));
111
+ }
112
+ debug_default("converting \"%s\" to relative import, source \"%s\"", filePath, outputDirname);
113
+ return relative(outputDirname, filePath);
114
+ };
115
+ }
116
+ #asBarrelFile(vfs, buffer, exportName, disableLazyImports) {
117
+ const useEagerImports = disableLazyImports === true ? true : false;
118
+ const keyGenerator = this.#createBarrelFileKeyGenerator(this.#config);
119
+ const importsBuffer = buffer.create();
120
+ const importGenerator = this.#createBarrelFileImportGenerator(this.#source, this.#outputDirname, this.#config);
121
+ const tree = vfs.asTree({
122
+ transformKey: keyGenerator,
123
+ transformValue: (filePath, key) => {
124
+ if (useEagerImports) {
125
+ const importKey = new StringBuilder(key).pascalCase().toString();
126
+ importsBuffer.write(`import ${importKey} from '${importGenerator(filePath)}'`);
127
+ return importKey;
128
+ }
129
+ return `() => import('${importGenerator(filePath)}')`;
130
+ }
131
+ });
132
+ if (!Object.keys(tree).length) {
133
+ buffer.write(`export const ${exportName} = {}`);
134
+ return;
135
+ }
136
+ if (useEagerImports) buffer.writeLine(importsBuffer);
137
+ buffer.write(`export const ${exportName} = {`).indent();
138
+ this.#treeToString(tree, buffer);
139
+ buffer.dedent().write(`}`);
140
+ }
141
+ #logCreation(startTime) {
142
+ this.#cliLogger.info(`created ${this.#config.output}`, { startTime });
143
+ }
144
+ async addFile(filePath) {
145
+ if (this.#vfs.add(filePath)) {
146
+ debug_default("file added, re-generating \"%s\" index", this.name);
147
+ const startTime = process.hrtime();
148
+ await this.#generateOutput();
149
+ this.#logCreation(startTime);
150
+ }
151
+ }
152
+ async removeFile(filePath) {
153
+ if (this.#vfs.remove(filePath)) {
154
+ debug_default("file removed, re-generating \"%s\" index", this.name);
155
+ const startTime = process.hrtime();
156
+ await this.#generateOutput();
157
+ this.#logCreation(startTime);
158
+ }
159
+ }
160
+ async generate() {
161
+ debug_default("generating \"%s\" index", this.name);
162
+ await this.#vfs.scan();
163
+ await this.#generateOutput();
164
+ }
165
+ };
166
+ export { FileBuffer as n, IndexGeneratorSource as t };
@@ -28,6 +28,7 @@ export declare class Bundler {
28
28
  logger: import("@poppinss/cliui").Logger;
29
29
  table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
30
30
  tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
31
+ steps: () => import("@poppinss/cliui").Steps;
31
32
  icons: {
32
33
  tick: string;
33
34
  cross: string;
@@ -37,6 +38,7 @@ export declare class Bundler {
37
38
  info: string;
38
39
  warning: string;
39
40
  squareSmallFilled: string;
41
+ borderVertical: string;
40
42
  };
41
43
  sticker: () => import("@poppinss/cliui").Instructions;
42
44
  instructions: () => import("@poppinss/cliui").Instructions;
@@ -1,6 +1,6 @@
1
1
  import { type AsyncOrSync } from '@poppinss/utils/types';
2
2
  import { PathsResolver } from '../../paths_resolver.ts';
3
- import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules } from '../../types/code_scanners.ts';
3
+ import { type ScannedRoute, type RoutesListItem, type ScannedController, type RoutesScannerRules, type RoutesScannerFilterFn } from '../../types/code_scanners.ts';
4
4
  /**
5
5
  * RoutesScanner is responsible for scanning application routes,
6
6
  * extracting their controllers, validators, request and response types.
@@ -27,6 +27,7 @@ export declare class RoutesScanner {
27
27
  logger: import("@poppinss/cliui").Logger;
28
28
  table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
29
29
  tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
30
+ steps: () => import("@poppinss/cliui").Steps;
30
31
  icons: {
31
32
  tick: string;
32
33
  cross: string;
@@ -36,6 +37,7 @@ export declare class RoutesScanner {
36
37
  info: string;
37
38
  warning: string;
38
39
  squareSmallFilled: string;
40
+ borderVertical: string;
39
41
  };
40
42
  sticker: () => import("@poppinss/cliui").Instructions;
41
43
  instructions: () => import("@poppinss/cliui").Instructions;
@@ -105,7 +107,19 @@ export declare class RoutesScanner {
105
107
  *
106
108
  * @param controllerPath - Path to the controller file to invalidate
107
109
  */
108
- invalidate(controllerPath: string): Promise<void>;
110
+ invalidate(controllerPath: string): Promise<boolean>;
111
+ /**
112
+ * Sets a filter function to selectively include routes during scanning.
113
+ *
114
+ * @param filterFn - Function that returns true for routes to include
115
+ * @returns This RoutesScanner instance for method chaining
116
+ *
117
+ * @example
118
+ * scanner.filter((route) => {
119
+ * return route.pattern.startsWith('/api')
120
+ * })
121
+ */
122
+ filter(filterFn: RoutesScannerFilterFn): this;
109
123
  /**
110
124
  * Scans an array of Route list items and fetches their validators,
111
125
  * controllers, and request/response types.