@adonisjs/assembler 8.0.0-next.6 → 8.0.0-next.7
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/{chunk-MC3FJR62.js → chunk-25Q3N5JR.js} +1 -20
- package/build/{chunk-F4RAGKQN.js → chunk-PORDZS62.js} +5 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +276 -72
- package/build/src/bundler.d.ts +4 -0
- package/build/src/code_scanners/routes_scanner/main.js +1 -1
- package/build/src/dev_server.d.ts +26 -7
- package/build/src/hooks.d.ts +224 -0
- package/build/src/index_generator/main.d.ts +0 -9
- package/build/src/index_generator/main.js +2 -2
- package/build/src/index_generator/source.d.ts +0 -6
- package/build/src/test_runner.d.ts +26 -7
- package/build/src/types/common.d.ts +2 -2
- package/build/src/types/hooks.d.ts +71 -14
- package/build/src/utils.d.ts +2 -5
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
debug_default,
|
|
4
4
|
removeExtension,
|
|
5
5
|
throttle
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-PORDZS62.js";
|
|
7
7
|
|
|
8
8
|
// src/index_generator/source.ts
|
|
9
9
|
import string from "@poppinss/utils/string";
|
|
@@ -172,14 +172,6 @@ var IndexGeneratorSource = class {
|
|
|
172
172
|
glob: this.#config.glob
|
|
173
173
|
});
|
|
174
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
175
|
/**
|
|
184
176
|
* Converts a recursive file tree to a string representation
|
|
185
177
|
*
|
|
@@ -340,17 +332,6 @@ var IndexGenerator = class {
|
|
|
340
332
|
this.#appRoot = appRoot;
|
|
341
333
|
this.#cliLogger = cliLogger;
|
|
342
334
|
}
|
|
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
335
|
/**
|
|
355
336
|
* Add a new index generator source
|
|
356
337
|
*
|
|
@@ -152,7 +152,11 @@ async function loadHooks(rcFileHooks, names) {
|
|
|
152
152
|
const hooks = new Hooks();
|
|
153
153
|
for (const { group, hooks: collection } of groups) {
|
|
154
154
|
for (const item of collection) {
|
|
155
|
-
|
|
155
|
+
if ("run" in item) {
|
|
156
|
+
hooks.add(group, item.run);
|
|
157
|
+
} else {
|
|
158
|
+
hooks.add(group, await importDefault(item));
|
|
159
|
+
}
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
162
|
return hooks;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
IndexGenerator
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-25Q3N5JR.js";
|
|
4
4
|
import {
|
|
5
5
|
copyFiles,
|
|
6
6
|
debug_default,
|
|
@@ -12,15 +12,240 @@ import {
|
|
|
12
12
|
runNode,
|
|
13
13
|
throttle,
|
|
14
14
|
watch
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-PORDZS62.js";
|
|
16
|
+
|
|
17
|
+
// src/hooks.ts
|
|
18
|
+
var hooks = {
|
|
19
|
+
/**
|
|
20
|
+
* Hook called during application initialization. This is the first hook
|
|
21
|
+
* that gets executed when the assembler starts up.
|
|
22
|
+
*
|
|
23
|
+
* @param callback - Function to execute when the init event occurs
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* hooks.init((app) => {
|
|
28
|
+
* console.log('Application is initializing')
|
|
29
|
+
* // Setup global configurations
|
|
30
|
+
* })
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
init(callback) {
|
|
34
|
+
return callback;
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Hook called after routes have been committed to the router.
|
|
38
|
+
* This occurs after all route definitions have been processed.
|
|
39
|
+
*
|
|
40
|
+
* @param callback - Function to execute when routes are committed
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```js
|
|
44
|
+
* hooks.routesCommitted((router) => {
|
|
45
|
+
* console.log('All routes have been committed to the router')
|
|
46
|
+
* // Perform route-based setup
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
routesCommitted(callback) {
|
|
51
|
+
return callback;
|
|
52
|
+
},
|
|
53
|
+
/**
|
|
54
|
+
* Hook called when the assembler starts scanning for route files.
|
|
55
|
+
* This happens before any route files are actually processed.
|
|
56
|
+
*
|
|
57
|
+
* @param callback - Function to execute when route scanning begins
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```js
|
|
61
|
+
* hooks.routesScanning(() => {
|
|
62
|
+
* console.log('Starting to scan for route files')
|
|
63
|
+
* // Setup route scanning configurations
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
routesScanning(callback) {
|
|
68
|
+
return callback;
|
|
69
|
+
},
|
|
70
|
+
/**
|
|
71
|
+
* Hook called after all route files have been scanned and processed.
|
|
72
|
+
* This occurs once the route scanning phase is complete.
|
|
73
|
+
*
|
|
74
|
+
* @param callback - Function to execute when route scanning is finished
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```js
|
|
78
|
+
* hooks.routesScanned((scannedRoutes) => {
|
|
79
|
+
* console.log('Route scanning completed')
|
|
80
|
+
* // Process scanned route information
|
|
81
|
+
* })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
routesScanned(callback) {
|
|
85
|
+
return callback;
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* Hook called when a file is modified during development.
|
|
89
|
+
* This is triggered by the file watcher when changes are detected.
|
|
90
|
+
*
|
|
91
|
+
* @param callback - Function to execute when a file changes
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```js
|
|
95
|
+
* hooks.fileChanged((filePath, stats) => {
|
|
96
|
+
* console.log(`File changed: ${filePath}`)
|
|
97
|
+
* // Handle file change logic
|
|
98
|
+
* })
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
fileChanged(callback) {
|
|
102
|
+
return callback;
|
|
103
|
+
},
|
|
104
|
+
/**
|
|
105
|
+
* Hook called when a new file is added during development.
|
|
106
|
+
* This is triggered by the file watcher when new files are created.
|
|
107
|
+
*
|
|
108
|
+
* @param callback - Function to execute when a file is added
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```js
|
|
112
|
+
* hooks.fileAdded((filePath, stats) => {
|
|
113
|
+
* console.log(`New file added: ${filePath}`)
|
|
114
|
+
* // Handle new file logic
|
|
115
|
+
* })
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
fileAdded(callback) {
|
|
119
|
+
return callback;
|
|
120
|
+
},
|
|
121
|
+
/**
|
|
122
|
+
* Hook called when a file is removed during development.
|
|
123
|
+
* This is triggered by the file watcher when files are deleted.
|
|
124
|
+
*
|
|
125
|
+
* @param callback - Function to execute when a file is removed
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```js
|
|
129
|
+
* hooks.fileRemoved((filePath) => {
|
|
130
|
+
* console.log(`File removed: ${filePath}`)
|
|
131
|
+
* // Handle file removal logic
|
|
132
|
+
* })
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
fileRemoved(callback) {
|
|
136
|
+
return callback;
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Hook called when the development server is about to start.
|
|
140
|
+
* This occurs before the server begins listening for connections.
|
|
141
|
+
*
|
|
142
|
+
* @param callback - Function to execute when dev server is starting
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```js
|
|
146
|
+
* hooks.devServerStarting((server) => {
|
|
147
|
+
* console.log('Development server is starting')
|
|
148
|
+
* // Setup server configurations
|
|
149
|
+
* })
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
devServerStarting(callback) {
|
|
153
|
+
return callback;
|
|
154
|
+
},
|
|
155
|
+
/**
|
|
156
|
+
* Hook called after the development server has successfully started.
|
|
157
|
+
* This occurs once the server is listening and ready to accept requests.
|
|
158
|
+
*
|
|
159
|
+
* @param callback - Function to execute when dev server has started
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```js
|
|
163
|
+
* hooks.devServerStarted((server) => {
|
|
164
|
+
* console.log(`Development server started on port ${server.port}`)
|
|
165
|
+
* // Notify external services or open browser
|
|
166
|
+
* })
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
devServerStarted(callback) {
|
|
170
|
+
return callback;
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Hook called when the build process is about to start.
|
|
174
|
+
* This occurs before any build tasks are executed.
|
|
175
|
+
*
|
|
176
|
+
* @param callback - Function to execute when build is starting
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```js
|
|
180
|
+
* hooks.buildStarting((buildConfig) => {
|
|
181
|
+
* console.log('Build process is starting')
|
|
182
|
+
* // Setup build configurations or clean directories
|
|
183
|
+
* })
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
buildStarting(callback) {
|
|
187
|
+
return callback;
|
|
188
|
+
},
|
|
189
|
+
/**
|
|
190
|
+
* Hook called after the build process has completed.
|
|
191
|
+
* This occurs once all build tasks have finished executing.
|
|
192
|
+
*
|
|
193
|
+
* @param callback - Function to execute when build is finished
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```js
|
|
197
|
+
* hooks.buildFinished((buildResult) => {
|
|
198
|
+
* console.log('Build process completed')
|
|
199
|
+
* // Deploy artifacts or notify build completion
|
|
200
|
+
* })
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
buildFinished(callback) {
|
|
204
|
+
return callback;
|
|
205
|
+
},
|
|
206
|
+
/**
|
|
207
|
+
* Hook called when the test suite is about to start.
|
|
208
|
+
* This occurs before any test files are executed.
|
|
209
|
+
*
|
|
210
|
+
* @param callback - Function to execute when tests are starting
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```js
|
|
214
|
+
* hooks.testsStarting((testConfig) => {
|
|
215
|
+
* console.log('Test suite is starting')
|
|
216
|
+
* // Setup test database or mock services
|
|
217
|
+
* })
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
testsStarting(callback) {
|
|
221
|
+
return callback;
|
|
222
|
+
},
|
|
223
|
+
/**
|
|
224
|
+
* Hook called after the test suite has completed.
|
|
225
|
+
* This occurs once all test files have finished executing.
|
|
226
|
+
*
|
|
227
|
+
* @param callback - Function to execute when tests are finished
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```js
|
|
231
|
+
* hooks.testsFinished((testResults) => {
|
|
232
|
+
* console.log('Test suite completed')
|
|
233
|
+
* // Generate test reports or cleanup test resources
|
|
234
|
+
* })
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
testsFinished(callback) {
|
|
238
|
+
return callback;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
16
241
|
|
|
17
242
|
// src/bundler.ts
|
|
18
243
|
import dedent from "dedent";
|
|
19
244
|
import fs from "fs/promises";
|
|
20
245
|
import { cliui } from "@poppinss/cliui";
|
|
21
246
|
import { fileURLToPath } from "url";
|
|
22
|
-
import { join, relative } from "path";
|
|
23
247
|
import string from "@poppinss/utils/string";
|
|
248
|
+
import { join, relative } from "path/posix";
|
|
24
249
|
import { detectPackageManager } from "@antfu/install-pkg";
|
|
25
250
|
var SUPPORTED_PACKAGE_MANAGERS = {
|
|
26
251
|
"npm": {
|
|
@@ -45,10 +270,6 @@ var SUPPORTED_PACKAGE_MANAGERS = {
|
|
|
45
270
|
}
|
|
46
271
|
};
|
|
47
272
|
var Bundler = class {
|
|
48
|
-
/**
|
|
49
|
-
* The current working project directory path as string
|
|
50
|
-
*/
|
|
51
|
-
#cwdPath;
|
|
52
273
|
/**
|
|
53
274
|
* Reference to the TypeScript module
|
|
54
275
|
*/
|
|
@@ -57,6 +278,10 @@ var Bundler = class {
|
|
|
57
278
|
* Hooks to execute custom actions during the build process
|
|
58
279
|
*/
|
|
59
280
|
#hooks;
|
|
281
|
+
/**
|
|
282
|
+
* Index generator for managing auto-generated index files
|
|
283
|
+
*/
|
|
284
|
+
#indexGenerator;
|
|
60
285
|
/**
|
|
61
286
|
* CLI UI instance for displaying colorful messages and progress information
|
|
62
287
|
*/
|
|
@@ -65,6 +290,10 @@ var Bundler = class {
|
|
|
65
290
|
* The current working directory URL
|
|
66
291
|
*/
|
|
67
292
|
cwd;
|
|
293
|
+
/**
|
|
294
|
+
* The current working project directory path as string
|
|
295
|
+
*/
|
|
296
|
+
cwdPath;
|
|
68
297
|
/**
|
|
69
298
|
* Bundler configuration options including hooks and meta files
|
|
70
299
|
*/
|
|
@@ -79,7 +308,7 @@ var Bundler = class {
|
|
|
79
308
|
constructor(cwd, ts, options) {
|
|
80
309
|
this.cwd = cwd;
|
|
81
310
|
this.options = options;
|
|
82
|
-
this
|
|
311
|
+
this.cwdPath = string.toUnixSlash(fileURLToPath(this.cwd));
|
|
83
312
|
this.#ts = ts;
|
|
84
313
|
}
|
|
85
314
|
/**
|
|
@@ -87,7 +316,7 @@ var Bundler = class {
|
|
|
87
316
|
* file path
|
|
88
317
|
*/
|
|
89
318
|
#getRelativeName(filePath) {
|
|
90
|
-
return string.toUnixSlash(relative(this
|
|
319
|
+
return string.toUnixSlash(relative(this.cwdPath, filePath));
|
|
91
320
|
}
|
|
92
321
|
/**
|
|
93
322
|
* Cleans up the build directory
|
|
@@ -115,13 +344,13 @@ var Bundler = class {
|
|
|
115
344
|
*/
|
|
116
345
|
async #copyMetaFiles(outDir, additionalFilesToCopy) {
|
|
117
346
|
const metaFiles = (this.options.metaFiles || []).map((file) => file.pattern).concat(additionalFilesToCopy);
|
|
118
|
-
await copyFiles(metaFiles, this
|
|
347
|
+
await copyFiles(metaFiles, this.cwdPath, outDir);
|
|
119
348
|
}
|
|
120
349
|
/**
|
|
121
350
|
* Detect the package manager used by the project
|
|
122
351
|
*/
|
|
123
352
|
async #detectPackageManager() {
|
|
124
|
-
const pkgManager = await detectPackageManager(this
|
|
353
|
+
const pkgManager = await detectPackageManager(this.cwdPath);
|
|
125
354
|
if (pkgManager === "deno") {
|
|
126
355
|
return "npm";
|
|
127
356
|
}
|
|
@@ -163,12 +392,18 @@ var Bundler = class {
|
|
|
163
392
|
* const success = await bundler.bundle(true, 'npm')
|
|
164
393
|
*/
|
|
165
394
|
async bundle(stopOnError = true, client) {
|
|
166
|
-
this.#hooks = await loadHooks(this.options.hooks, ["buildStarting", "buildFinished"]);
|
|
167
395
|
this.packageManager = client ?? await this.#detectPackageManager() ?? "npm";
|
|
168
396
|
const config = parseConfig(this.cwd, this.#ts);
|
|
169
397
|
if (!config) {
|
|
170
398
|
return false;
|
|
171
399
|
}
|
|
400
|
+
this.ui.logger.info("loading hooks...");
|
|
401
|
+
this.#hooks = await loadHooks(this.options.hooks, ["init", "buildStarting", "buildFinished"]);
|
|
402
|
+
this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger);
|
|
403
|
+
await this.#hooks.runner("init").run(this, this.#indexGenerator);
|
|
404
|
+
this.#hooks.clear("init");
|
|
405
|
+
this.ui.logger.info("generating indexes...");
|
|
406
|
+
await this.#indexGenerator.generate();
|
|
172
407
|
const outDir = config.options.outDir || fileURLToPath(new URL("build/", this.cwd));
|
|
173
408
|
this.ui.logger.info("cleaning up output directory", { suffix: this.#getRelativeName(outDir) });
|
|
174
409
|
await this.#cleanupBuildDirectory(outDir);
|
|
@@ -649,10 +884,6 @@ var DevServer = class _DevServer {
|
|
|
649
884
|
fullReload: true,
|
|
650
885
|
hotReloaded: false
|
|
651
886
|
};
|
|
652
|
-
/**
|
|
653
|
-
* File path computed from the cwd
|
|
654
|
-
*/
|
|
655
|
-
#cwdPath;
|
|
656
887
|
/**
|
|
657
888
|
* External listeners that are invoked when child process
|
|
658
889
|
* gets an error or closes
|
|
@@ -696,7 +927,7 @@ var DevServer = class _DevServer {
|
|
|
696
927
|
/**
|
|
697
928
|
* CLI UI instance for displaying colorful messages and progress information
|
|
698
929
|
*/
|
|
699
|
-
|
|
930
|
+
ui = cliui2();
|
|
700
931
|
/**
|
|
701
932
|
* Restarts the HTTP server and throttle concurrent calls to
|
|
702
933
|
* ensure we do not end up with a long loop of restarts
|
|
@@ -734,19 +965,6 @@ var DevServer = class _DevServer {
|
|
|
734
965
|
#cleanupKeyboardShortcuts() {
|
|
735
966
|
this.#shortcutsManager?.cleanup();
|
|
736
967
|
}
|
|
737
|
-
/**
|
|
738
|
-
* CLI UI instance to log colorful messages and progress information
|
|
739
|
-
*/
|
|
740
|
-
get ui() {
|
|
741
|
-
return this.#ui;
|
|
742
|
-
}
|
|
743
|
-
/**
|
|
744
|
-
* CLI UI instance to log colorful messages and progress information
|
|
745
|
-
*/
|
|
746
|
-
set ui(ui) {
|
|
747
|
-
this.#ui = ui;
|
|
748
|
-
this.#indexGenerator.setLogger(ui.logger);
|
|
749
|
-
}
|
|
750
968
|
/**
|
|
751
969
|
* The mode in which the DevServer is running.
|
|
752
970
|
*/
|
|
@@ -761,6 +979,10 @@ var DevServer = class _DevServer {
|
|
|
761
979
|
* The current working directory URL
|
|
762
980
|
*/
|
|
763
981
|
cwd;
|
|
982
|
+
/**
|
|
983
|
+
* File path computed from the cwd
|
|
984
|
+
*/
|
|
985
|
+
cwdPath;
|
|
764
986
|
/**
|
|
765
987
|
* Development server configuration options including hooks and environment variables
|
|
766
988
|
*/
|
|
@@ -774,8 +996,7 @@ var DevServer = class _DevServer {
|
|
|
774
996
|
constructor(cwd, options) {
|
|
775
997
|
this.cwd = cwd;
|
|
776
998
|
this.options = options;
|
|
777
|
-
this
|
|
778
|
-
this.#indexGenerator = new IndexGenerator(this.#cwdPath, this.ui.logger);
|
|
999
|
+
this.cwdPath = string3.toUnixSlash(fileURLToPath2(this.cwd));
|
|
779
1000
|
}
|
|
780
1001
|
/**
|
|
781
1002
|
* Type guard to check if child process message is from AdonisJS HTTP server
|
|
@@ -922,8 +1143,9 @@ var DevServer = class _DevServer {
|
|
|
922
1143
|
this.#mode = mode;
|
|
923
1144
|
this.#clearScreen();
|
|
924
1145
|
this.ui.logger.info(`starting server in ${this.#mode} mode...`);
|
|
1146
|
+
this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger);
|
|
925
1147
|
this.#stickyPort = String(await getPort(this.cwd));
|
|
926
|
-
this.#fileSystem = new FileSystem(this
|
|
1148
|
+
this.#fileSystem = new FileSystem(this.cwdPath, tsConfig, this.options);
|
|
927
1149
|
this.ui.logger.info("loading hooks...");
|
|
928
1150
|
this.#hooks = await loadHooks(this.options.hooks, [
|
|
929
1151
|
"init",
|
|
@@ -972,7 +1194,7 @@ var DevServer = class _DevServer {
|
|
|
972
1194
|
} else if (this.#mode === "hmr" && this.#isHotHookMessage(message)) {
|
|
973
1195
|
debug_default("received hot-hook message %O", message);
|
|
974
1196
|
const absolutePath = message.path ? string3.toUnixSlash(message.path) : "";
|
|
975
|
-
const relativePath = relative3(this
|
|
1197
|
+
const relativePath = relative3(this.cwdPath, absolutePath);
|
|
976
1198
|
if (message.type === "hot-hook:file-changed") {
|
|
977
1199
|
const { action } = message;
|
|
978
1200
|
if (action === "add") {
|
|
@@ -1074,7 +1296,7 @@ var DevServer = class _DevServer {
|
|
|
1074
1296
|
await this.#startHTTPServer(this.#stickyPort);
|
|
1075
1297
|
this.#watcher = watch({
|
|
1076
1298
|
usePolling: options?.poll ?? false,
|
|
1077
|
-
cwd: this
|
|
1299
|
+
cwd: this.cwdPath,
|
|
1078
1300
|
ignoreInitial: true,
|
|
1079
1301
|
ignored: (file, stats) => {
|
|
1080
1302
|
if (!stats) {
|
|
@@ -1097,17 +1319,17 @@ var DevServer = class _DevServer {
|
|
|
1097
1319
|
});
|
|
1098
1320
|
this.#watcher.on("add", (filePath) => {
|
|
1099
1321
|
const relativePath = string3.toUnixSlash(filePath);
|
|
1100
|
-
const absolutePath = join2(this
|
|
1322
|
+
const absolutePath = join2(this.cwdPath, relativePath);
|
|
1101
1323
|
this.#hooks.runner("fileAdded").run(relativePath, absolutePath, this);
|
|
1102
1324
|
});
|
|
1103
1325
|
this.#watcher.on("change", (filePath) => {
|
|
1104
1326
|
const relativePath = string3.toUnixSlash(filePath);
|
|
1105
|
-
const absolutePath = join2(this
|
|
1327
|
+
const absolutePath = join2(this.cwdPath, relativePath);
|
|
1106
1328
|
this.#hooks.runner("fileChanged").run(relativePath, absolutePath, _DevServer.#WATCHER_INFO, this);
|
|
1107
1329
|
});
|
|
1108
1330
|
this.#watcher.on("unlink", (filePath) => {
|
|
1109
1331
|
const relativePath = string3.toUnixSlash(filePath);
|
|
1110
|
-
const absolutePath = join2(this
|
|
1332
|
+
const absolutePath = join2(this.cwdPath, relativePath);
|
|
1111
1333
|
this.#hooks.runner("fileRemoved").run(relativePath, absolutePath, this);
|
|
1112
1334
|
});
|
|
1113
1335
|
}
|
|
@@ -1148,10 +1370,6 @@ var TestRunner = class {
|
|
|
1148
1370
|
* Hooks to execute custom actions during the tests runner lifecycle
|
|
1149
1371
|
*/
|
|
1150
1372
|
#hooks;
|
|
1151
|
-
/**
|
|
1152
|
-
* The current working directory path as a string
|
|
1153
|
-
*/
|
|
1154
|
-
#cwdPath;
|
|
1155
1373
|
/**
|
|
1156
1374
|
* Index generator for managing auto-generated index files
|
|
1157
1375
|
*/
|
|
@@ -1159,7 +1377,7 @@ var TestRunner = class {
|
|
|
1159
1377
|
/**
|
|
1160
1378
|
* CLI UI instance for displaying colorful messages and progress information
|
|
1161
1379
|
*/
|
|
1162
|
-
|
|
1380
|
+
ui = cliui3();
|
|
1163
1381
|
/**
|
|
1164
1382
|
* Re-runs the test child process and throttle concurrent calls to
|
|
1165
1383
|
* ensure we do not end up with a long loop of restarts
|
|
@@ -1171,19 +1389,6 @@ var TestRunner = class {
|
|
|
1171
1389
|
}
|
|
1172
1390
|
await this.#runTests(this.#stickyPort, filters);
|
|
1173
1391
|
}, "reRunTests");
|
|
1174
|
-
/**
|
|
1175
|
-
* CLI UI instance to log colorful messages and progress information
|
|
1176
|
-
*/
|
|
1177
|
-
get ui() {
|
|
1178
|
-
return this.#ui;
|
|
1179
|
-
}
|
|
1180
|
-
/**
|
|
1181
|
-
* CLI UI instance to log colorful messages and progress information
|
|
1182
|
-
*/
|
|
1183
|
-
set ui(ui) {
|
|
1184
|
-
this.#ui = ui;
|
|
1185
|
-
this.#indexGenerator.setLogger(ui.logger);
|
|
1186
|
-
}
|
|
1187
1392
|
/**
|
|
1188
1393
|
* The script file to run as a child process
|
|
1189
1394
|
*/
|
|
@@ -1192,6 +1397,10 @@ var TestRunner = class {
|
|
|
1192
1397
|
* The current working directory URL
|
|
1193
1398
|
*/
|
|
1194
1399
|
cwd;
|
|
1400
|
+
/**
|
|
1401
|
+
* The current working directory path as a string
|
|
1402
|
+
*/
|
|
1403
|
+
cwdPath;
|
|
1195
1404
|
/**
|
|
1196
1405
|
* Test runner configuration options including filters, reporters, and hooks
|
|
1197
1406
|
*/
|
|
@@ -1205,8 +1414,7 @@ var TestRunner = class {
|
|
|
1205
1414
|
constructor(cwd, options) {
|
|
1206
1415
|
this.cwd = cwd;
|
|
1207
1416
|
this.options = options;
|
|
1208
|
-
this
|
|
1209
|
-
this.#indexGenerator = new IndexGenerator(this.#cwdPath, this.ui.logger);
|
|
1417
|
+
this.cwdPath = string4.toUnixSlash(fileURLToPath3(this.cwd));
|
|
1210
1418
|
}
|
|
1211
1419
|
/**
|
|
1212
1420
|
* Convert test runner options to the CLI args
|
|
@@ -1419,16 +1627,10 @@ var TestRunner = class {
|
|
|
1419
1627
|
*/
|
|
1420
1628
|
async run() {
|
|
1421
1629
|
this.#stickyPort = String(await getPort(this.cwd));
|
|
1630
|
+
this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger);
|
|
1422
1631
|
this.#clearScreen();
|
|
1423
1632
|
this.ui.logger.info("loading hooks...");
|
|
1424
|
-
this.#hooks = await loadHooks(this.options.hooks, [
|
|
1425
|
-
"init",
|
|
1426
|
-
"testsStarting",
|
|
1427
|
-
"testsFinished",
|
|
1428
|
-
"fileAdded",
|
|
1429
|
-
"fileChanged",
|
|
1430
|
-
"fileRemoved"
|
|
1431
|
-
]);
|
|
1633
|
+
this.#hooks = await loadHooks(this.options.hooks, ["init", "testsStarting", "testsFinished"]);
|
|
1432
1634
|
await this.#hooks.runner("init").run(this, this.#indexGenerator);
|
|
1433
1635
|
this.#hooks.clear("init");
|
|
1434
1636
|
this.ui.logger.info("generating indexes...");
|
|
@@ -1454,7 +1656,8 @@ var TestRunner = class {
|
|
|
1454
1656
|
return;
|
|
1455
1657
|
}
|
|
1456
1658
|
this.#stickyPort = String(await getPort(this.cwd));
|
|
1457
|
-
this.#
|
|
1659
|
+
this.#indexGenerator = new IndexGenerator(this.cwdPath, this.ui.logger);
|
|
1660
|
+
this.#fileSystem = new FileSystem(this.cwdPath, tsConfig, {
|
|
1458
1661
|
...this.options,
|
|
1459
1662
|
suites: this.options.suites?.filter((suite) => {
|
|
1460
1663
|
if (this.options.filters.suites) {
|
|
@@ -1482,7 +1685,7 @@ var TestRunner = class {
|
|
|
1482
1685
|
await this.#runTests(this.#stickyPort);
|
|
1483
1686
|
this.#watcher = watch({
|
|
1484
1687
|
usePolling: options?.poll ?? false,
|
|
1485
|
-
cwd: this
|
|
1688
|
+
cwd: this.cwdPath,
|
|
1486
1689
|
ignoreInitial: true,
|
|
1487
1690
|
ignored: (file, stats) => {
|
|
1488
1691
|
if (!stats) {
|
|
@@ -1505,12 +1708,12 @@ var TestRunner = class {
|
|
|
1505
1708
|
});
|
|
1506
1709
|
this.#watcher.on("add", (filePath) => {
|
|
1507
1710
|
const relativePath = string4.toUnixSlash(filePath);
|
|
1508
|
-
const absolutePath = join3(this
|
|
1711
|
+
const absolutePath = join3(this.cwdPath, filePath);
|
|
1509
1712
|
this.#hooks.runner("fileAdded").run(relativePath, absolutePath, this);
|
|
1510
1713
|
});
|
|
1511
1714
|
this.#watcher.on("change", (filePath) => {
|
|
1512
1715
|
const relativePath = string4.toUnixSlash(filePath);
|
|
1513
|
-
const absolutePath = join3(this
|
|
1716
|
+
const absolutePath = join3(this.cwdPath, filePath);
|
|
1514
1717
|
this.#hooks.runner("fileChanged").run(
|
|
1515
1718
|
relativePath,
|
|
1516
1719
|
absolutePath,
|
|
@@ -1524,7 +1727,7 @@ var TestRunner = class {
|
|
|
1524
1727
|
});
|
|
1525
1728
|
this.#watcher.on("unlink", (filePath) => {
|
|
1526
1729
|
const relativePath = string4.toUnixSlash(filePath);
|
|
1527
|
-
const absolutePath = join3(this
|
|
1730
|
+
const absolutePath = join3(this.cwdPath, filePath);
|
|
1528
1731
|
this.#hooks.runner("fileRemoved").run(relativePath, absolutePath, this);
|
|
1529
1732
|
});
|
|
1530
1733
|
}
|
|
@@ -1533,5 +1736,6 @@ export {
|
|
|
1533
1736
|
Bundler,
|
|
1534
1737
|
DevServer,
|
|
1535
1738
|
SUPPORTED_PACKAGE_MANAGERS,
|
|
1536
|
-
TestRunner
|
|
1739
|
+
TestRunner,
|
|
1740
|
+
hooks
|
|
1537
1741
|
};
|
package/build/src/bundler.d.ts
CHANGED
|
@@ -52,6 +52,10 @@ export declare class Bundler {
|
|
|
52
52
|
* The current working directory URL
|
|
53
53
|
*/
|
|
54
54
|
cwd: URL;
|
|
55
|
+
/**
|
|
56
|
+
* The current working project directory path as string
|
|
57
|
+
*/
|
|
58
|
+
cwdPath: string;
|
|
55
59
|
/**
|
|
56
60
|
* Bundler configuration options including hooks and meta files
|
|
57
61
|
*/
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type tsStatic from 'typescript';
|
|
2
|
-
import { cliui } from '@poppinss/cliui';
|
|
3
2
|
import type { DevServerOptions } from './types/common.ts';
|
|
4
3
|
/**
|
|
5
4
|
* Exposes the API to start the development server in HMR, watch or static mode.
|
|
@@ -18,13 +17,29 @@ import type { DevServerOptions } from './types/common.ts';
|
|
|
18
17
|
export declare class DevServer {
|
|
19
18
|
#private;
|
|
20
19
|
/**
|
|
21
|
-
* CLI UI instance
|
|
20
|
+
* CLI UI instance for displaying colorful messages and progress information
|
|
22
21
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
ui: {
|
|
23
|
+
colors: import("@poppinss/colors/types").Colors;
|
|
24
|
+
logger: import("@poppinss/cliui").Logger;
|
|
25
|
+
table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
|
|
26
|
+
tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
|
|
27
|
+
icons: {
|
|
28
|
+
tick: string;
|
|
29
|
+
cross: string;
|
|
30
|
+
bullet: string;
|
|
31
|
+
nodejs: string;
|
|
32
|
+
pointer: string;
|
|
33
|
+
info: string;
|
|
34
|
+
warning: string;
|
|
35
|
+
squareSmallFilled: string;
|
|
36
|
+
};
|
|
37
|
+
sticker: () => import("@poppinss/cliui").Instructions;
|
|
38
|
+
instructions: () => import("@poppinss/cliui").Instructions;
|
|
39
|
+
switchMode(modeToUse: "raw" | "silent" | "normal"): void;
|
|
40
|
+
useRenderer(rendererToUse: import("@poppinss/cliui/types").RendererContract): void;
|
|
41
|
+
useColors(colorsToUse: import("@poppinss/colors/types").Colors): void;
|
|
42
|
+
};
|
|
28
43
|
/**
|
|
29
44
|
* The mode in which the DevServer is running.
|
|
30
45
|
*/
|
|
@@ -37,6 +52,10 @@ export declare class DevServer {
|
|
|
37
52
|
* The current working directory URL
|
|
38
53
|
*/
|
|
39
54
|
cwd: URL;
|
|
55
|
+
/**
|
|
56
|
+
* File path computed from the cwd
|
|
57
|
+
*/
|
|
58
|
+
cwdPath: string;
|
|
40
59
|
/**
|
|
41
60
|
* Development server configuration options including hooks and environment variables
|
|
42
61
|
*/
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { type AsyncOrSync } from '@poppinss/utils/types';
|
|
2
|
+
import { type HookParams } from './types/hooks.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Collection of hooks that can be used to listen for various events during
|
|
5
|
+
* the application lifecycle. These hooks allow you to execute custom logic
|
|
6
|
+
* at specific points in the development server, build process, and testing.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* const { hooks } = await import('@adonisjs/assembler/hooks')
|
|
11
|
+
*
|
|
12
|
+
* hooks.init((app) => {
|
|
13
|
+
* console.log('Application initialized')
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* hooks.devServerStarted((server) => {
|
|
17
|
+
* console.log('Dev server started on port', server.port)
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const hooks: {
|
|
22
|
+
/**
|
|
23
|
+
* Hook called during application initialization. This is the first hook
|
|
24
|
+
* that gets executed when the assembler starts up.
|
|
25
|
+
*
|
|
26
|
+
* @param callback - Function to execute when the init event occurs
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```js
|
|
30
|
+
* hooks.init((app) => {
|
|
31
|
+
* console.log('Application is initializing')
|
|
32
|
+
* // Setup global configurations
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
init(callback: (...args: HookParams<"init">) => AsyncOrSync<void>): (parent: import("./dev_server.ts").DevServer | import("./test_runner.ts").TestRunner | import("./bundler.ts").Bundler, indexGenerator: import("./index_generator/main.ts").IndexGenerator) => AsyncOrSync<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Hook called after routes have been committed to the router.
|
|
39
|
+
* This occurs after all route definitions have been processed.
|
|
40
|
+
*
|
|
41
|
+
* @param callback - Function to execute when routes are committed
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```js
|
|
45
|
+
* hooks.routesCommitted((router) => {
|
|
46
|
+
* console.log('All routes have been committed to the router')
|
|
47
|
+
* // Perform route-based setup
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
routesCommitted(callback: (...args: HookParams<"routesCommitted">) => AsyncOrSync<void>): (parent: import("./dev_server.ts").DevServer, routes: Record<string, import("./types/code_scanners.ts").RoutesListItem[]>) => AsyncOrSync<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Hook called when the assembler starts scanning for route files.
|
|
54
|
+
* This happens before any route files are actually processed.
|
|
55
|
+
*
|
|
56
|
+
* @param callback - Function to execute when route scanning begins
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```js
|
|
60
|
+
* hooks.routesScanning(() => {
|
|
61
|
+
* console.log('Starting to scan for route files')
|
|
62
|
+
* // Setup route scanning configurations
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
routesScanning(callback: (...args: HookParams<"routesScanning">) => AsyncOrSync<void>): (parent: import("./dev_server.ts").DevServer, routesScanner: import("./code_scanners/routes_scanner/main.ts").RoutesScanner) => AsyncOrSync<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Hook called after all route files have been scanned and processed.
|
|
69
|
+
* This occurs once the route scanning phase is complete.
|
|
70
|
+
*
|
|
71
|
+
* @param callback - Function to execute when route scanning is finished
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```js
|
|
75
|
+
* hooks.routesScanned((scannedRoutes) => {
|
|
76
|
+
* console.log('Route scanning completed')
|
|
77
|
+
* // Process scanned route information
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
routesScanned(callback: (...args: HookParams<"routesScanned">) => AsyncOrSync<void>): (parent: import("./dev_server.ts").DevServer, routesScanner: import("./code_scanners/routes_scanner/main.ts").RoutesScanner) => AsyncOrSync<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Hook called when a file is modified during development.
|
|
84
|
+
* This is triggered by the file watcher when changes are detected.
|
|
85
|
+
*
|
|
86
|
+
* @param callback - Function to execute when a file changes
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```js
|
|
90
|
+
* hooks.fileChanged((filePath, stats) => {
|
|
91
|
+
* console.log(`File changed: ${filePath}`)
|
|
92
|
+
* // Handle file change logic
|
|
93
|
+
* })
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
fileChanged(callback: (...args: HookParams<"fileChanged">) => AsyncOrSync<void>): (relativePath: string, absolutePath: string, info: {
|
|
97
|
+
source: "hot-hook" | "watcher";
|
|
98
|
+
hotReloaded: boolean;
|
|
99
|
+
fullReload: boolean;
|
|
100
|
+
}, parent: import("./dev_server.ts").DevServer | import("./test_runner.ts").TestRunner) => AsyncOrSync<void>;
|
|
101
|
+
/**
|
|
102
|
+
* Hook called when a new file is added during development.
|
|
103
|
+
* This is triggered by the file watcher when new files are created.
|
|
104
|
+
*
|
|
105
|
+
* @param callback - Function to execute when a file is added
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```js
|
|
109
|
+
* hooks.fileAdded((filePath, stats) => {
|
|
110
|
+
* console.log(`New file added: ${filePath}`)
|
|
111
|
+
* // Handle new file logic
|
|
112
|
+
* })
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
fileAdded(callback: (...args: HookParams<"fileAdded">) => AsyncOrSync<void>): (relativePath: string, absolutePath: string, server: import("./dev_server.ts").DevServer | import("./test_runner.ts").TestRunner) => AsyncOrSync<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Hook called when a file is removed during development.
|
|
118
|
+
* This is triggered by the file watcher when files are deleted.
|
|
119
|
+
*
|
|
120
|
+
* @param callback - Function to execute when a file is removed
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```js
|
|
124
|
+
* hooks.fileRemoved((filePath) => {
|
|
125
|
+
* console.log(`File removed: ${filePath}`)
|
|
126
|
+
* // Handle file removal logic
|
|
127
|
+
* })
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
fileRemoved(callback: (...args: HookParams<"fileRemoved">) => AsyncOrSync<void>): (relativePath: string, absolutePath: string, server: import("./dev_server.ts").DevServer | import("./test_runner.ts").TestRunner) => AsyncOrSync<void>;
|
|
131
|
+
/**
|
|
132
|
+
* Hook called when the development server is about to start.
|
|
133
|
+
* This occurs before the server begins listening for connections.
|
|
134
|
+
*
|
|
135
|
+
* @param callback - Function to execute when dev server is starting
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```js
|
|
139
|
+
* hooks.devServerStarting((server) => {
|
|
140
|
+
* console.log('Development server is starting')
|
|
141
|
+
* // Setup server configurations
|
|
142
|
+
* })
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
devServerStarting(callback: (...args: HookParams<"devServerStarting">) => AsyncOrSync<void>): (server: import("./dev_server.ts").DevServer) => AsyncOrSync<void>;
|
|
146
|
+
/**
|
|
147
|
+
* Hook called after the development server has successfully started.
|
|
148
|
+
* This occurs once the server is listening and ready to accept requests.
|
|
149
|
+
*
|
|
150
|
+
* @param callback - Function to execute when dev server has started
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```js
|
|
154
|
+
* hooks.devServerStarted((server) => {
|
|
155
|
+
* console.log(`Development server started on port ${server.port}`)
|
|
156
|
+
* // Notify external services or open browser
|
|
157
|
+
* })
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
devServerStarted(callback: (...args: HookParams<"devServerStarted">) => AsyncOrSync<void>): (server: import("./dev_server.ts").DevServer, info: {
|
|
161
|
+
port: number;
|
|
162
|
+
host: string;
|
|
163
|
+
}, uiInstructions: import("@poppinss/cliui").Instructions) => AsyncOrSync<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Hook called when the build process is about to start.
|
|
166
|
+
* This occurs before any build tasks are executed.
|
|
167
|
+
*
|
|
168
|
+
* @param callback - Function to execute when build is starting
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```js
|
|
172
|
+
* hooks.buildStarting((buildConfig) => {
|
|
173
|
+
* console.log('Build process is starting')
|
|
174
|
+
* // Setup build configurations or clean directories
|
|
175
|
+
* })
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
buildStarting(callback: (...args: HookParams<"buildStarting">) => AsyncOrSync<void>): (server: import("./bundler.ts").Bundler) => AsyncOrSync<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Hook called after the build process has completed.
|
|
181
|
+
* This occurs once all build tasks have finished executing.
|
|
182
|
+
*
|
|
183
|
+
* @param callback - Function to execute when build is finished
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* ```js
|
|
187
|
+
* hooks.buildFinished((buildResult) => {
|
|
188
|
+
* console.log('Build process completed')
|
|
189
|
+
* // Deploy artifacts or notify build completion
|
|
190
|
+
* })
|
|
191
|
+
* ```
|
|
192
|
+
*/
|
|
193
|
+
buildFinished(callback: (...args: HookParams<"buildFinished">) => AsyncOrSync<void>): (server: import("./bundler.ts").Bundler, uiInstructions: import("@poppinss/cliui").Instructions) => AsyncOrSync<void>;
|
|
194
|
+
/**
|
|
195
|
+
* Hook called when the test suite is about to start.
|
|
196
|
+
* This occurs before any test files are executed.
|
|
197
|
+
*
|
|
198
|
+
* @param callback - Function to execute when tests are starting
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* ```js
|
|
202
|
+
* hooks.testsStarting((testConfig) => {
|
|
203
|
+
* console.log('Test suite is starting')
|
|
204
|
+
* // Setup test database or mock services
|
|
205
|
+
* })
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
testsStarting(callback: (...args: HookParams<"testsStarting">) => AsyncOrSync<void>): (server: import("./test_runner.ts").TestRunner) => AsyncOrSync<void>;
|
|
209
|
+
/**
|
|
210
|
+
* Hook called after the test suite has completed.
|
|
211
|
+
* This occurs once all test files have finished executing.
|
|
212
|
+
*
|
|
213
|
+
* @param callback - Function to execute when tests are finished
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```js
|
|
217
|
+
* hooks.testsFinished((testResults) => {
|
|
218
|
+
* console.log('Test suite completed')
|
|
219
|
+
* // Generate test reports or cleanup test resources
|
|
220
|
+
* })
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
testsFinished(callback: (...args: HookParams<"testsFinished">) => AsyncOrSync<void>): (server: import("./test_runner.ts").TestRunner) => AsyncOrSync<void>;
|
|
224
|
+
};
|
|
@@ -26,15 +26,6 @@ export declare class IndexGenerator {
|
|
|
26
26
|
* @param cliLogger - Logger instance for CLI output
|
|
27
27
|
*/
|
|
28
28
|
constructor(appRoot: string, cliLogger: Logger);
|
|
29
|
-
/**
|
|
30
|
-
* Set the logger instance used for CLI output
|
|
31
|
-
*
|
|
32
|
-
* Updates the CLI logger instance for this index generator and all
|
|
33
|
-
* registered sources to use the new logger for output.
|
|
34
|
-
*
|
|
35
|
-
* @param cliLogger - New logger instance to use
|
|
36
|
-
*/
|
|
37
|
-
setLogger(cliLogger: Logger): void;
|
|
38
29
|
/**
|
|
39
30
|
* Add a new index generator source
|
|
40
31
|
*
|
|
@@ -32,12 +32,6 @@ export declare class IndexGeneratorSource {
|
|
|
32
32
|
* @param config - Configuration for this index generator source
|
|
33
33
|
*/
|
|
34
34
|
constructor(name: string, appRoot: string, cliLogger: Logger, config: IndexGeneratorSourceConfig);
|
|
35
|
-
/**
|
|
36
|
-
* Set the logger instance used for CLI output
|
|
37
|
-
*
|
|
38
|
-
* @param cliLogger - New logger instance to use
|
|
39
|
-
*/
|
|
40
|
-
setLogger(cliLogger: Logger): void;
|
|
41
35
|
/**
|
|
42
36
|
* Add a file to the virtual file system and regenerate index if needed
|
|
43
37
|
*
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type tsStatic from 'typescript';
|
|
2
|
-
import { cliui } from '@poppinss/cliui';
|
|
3
2
|
import type { TestRunnerOptions } from './types/common.ts';
|
|
4
3
|
/**
|
|
5
4
|
* Exposes the API to run Japa tests and optionally watch for file
|
|
@@ -27,13 +26,29 @@ import type { TestRunnerOptions } from './types/common.ts';
|
|
|
27
26
|
export declare class TestRunner {
|
|
28
27
|
#private;
|
|
29
28
|
/**
|
|
30
|
-
* CLI UI instance
|
|
29
|
+
* CLI UI instance for displaying colorful messages and progress information
|
|
31
30
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
ui: {
|
|
32
|
+
colors: import("@poppinss/colors/types").Colors;
|
|
33
|
+
logger: import("@poppinss/cliui").Logger;
|
|
34
|
+
table: (tableOptions?: Partial<import("@poppinss/cliui/types").TableOptions>) => import("@poppinss/cliui").Table;
|
|
35
|
+
tasks: (tasksOptions?: Partial<import("@poppinss/cliui/types").TaskManagerOptions>) => import("@poppinss/cliui").TaskManager;
|
|
36
|
+
icons: {
|
|
37
|
+
tick: string;
|
|
38
|
+
cross: string;
|
|
39
|
+
bullet: string;
|
|
40
|
+
nodejs: string;
|
|
41
|
+
pointer: string;
|
|
42
|
+
info: string;
|
|
43
|
+
warning: string;
|
|
44
|
+
squareSmallFilled: string;
|
|
45
|
+
};
|
|
46
|
+
sticker: () => import("@poppinss/cliui").Instructions;
|
|
47
|
+
instructions: () => import("@poppinss/cliui").Instructions;
|
|
48
|
+
switchMode(modeToUse: "raw" | "silent" | "normal"): void;
|
|
49
|
+
useRenderer(rendererToUse: import("@poppinss/cliui/types").RendererContract): void;
|
|
50
|
+
useColors(colorsToUse: import("@poppinss/colors/types").Colors): void;
|
|
51
|
+
};
|
|
37
52
|
/**
|
|
38
53
|
* The script file to run as a child process
|
|
39
54
|
*/
|
|
@@ -42,6 +57,10 @@ export declare class TestRunner {
|
|
|
42
57
|
* The current working directory URL
|
|
43
58
|
*/
|
|
44
59
|
cwd: URL;
|
|
60
|
+
/**
|
|
61
|
+
* The current working directory path as a string
|
|
62
|
+
*/
|
|
63
|
+
cwdPath: string;
|
|
45
64
|
/**
|
|
46
65
|
* Test runner configuration options including filters, reporters, and hooks
|
|
47
66
|
*/
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Logger } from '@poppinss/cliui';
|
|
2
2
|
import { type Prettify } from '@poppinss/utils/types';
|
|
3
|
+
import { type AllHooks } from './hooks.ts';
|
|
3
4
|
import { type FileBuffer } from '../file_buffer.ts';
|
|
4
5
|
import { type VirtualFileSystem } from '../virtual_file_system.ts';
|
|
5
|
-
import { type CommonHooks, type RouterHooks, type BundlerHooks, type WatcherHooks, type DevServerHooks, type TestRunnerHooks } from './hooks.ts';
|
|
6
6
|
/**
|
|
7
7
|
* Recursive file tree structure for representing nested directory hierarchies
|
|
8
8
|
*/
|
|
@@ -121,7 +121,7 @@ export type AssemblerRcFile = {
|
|
|
121
121
|
/**
|
|
122
122
|
* Hooks to execute at different stages of development and build processes
|
|
123
123
|
*/
|
|
124
|
-
hooks?: Partial<
|
|
124
|
+
hooks?: Partial<AllHooks>;
|
|
125
125
|
/**
|
|
126
126
|
* An array of test suites configuration
|
|
127
127
|
*/
|
|
@@ -4,8 +4,27 @@ import { type Bundler } from '../bundler.ts';
|
|
|
4
4
|
import { type DevServer } from '../dev_server.ts';
|
|
5
5
|
import { type TestRunner } from '../test_runner.ts';
|
|
6
6
|
import { type RoutesListItem } from './code_scanners.ts';
|
|
7
|
-
import { type RoutesScanner } from '../code_scanners/routes_scanner/main.ts';
|
|
8
7
|
import { type IndexGenerator } from '../index_generator/main.ts';
|
|
8
|
+
import { type RoutesScanner } from '../code_scanners/routes_scanner/main.ts';
|
|
9
|
+
/**
|
|
10
|
+
* Defines a hook that can be either a lazy import or an object with a run method.
|
|
11
|
+
* This type provides flexibility in how hooks are defined and imported, supporting
|
|
12
|
+
* both dynamic imports for code splitting and direct object definitions.
|
|
13
|
+
*
|
|
14
|
+
* @template Fn - The function signature that the hook must conform to
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Using lazy import
|
|
18
|
+
* const hook: DefineHook<(server: DevServer) => void> = () => import('./my-hook')
|
|
19
|
+
*
|
|
20
|
+
* // Using direct object
|
|
21
|
+
* const hook: DefineHook<(server: DevServer) => void> = {
|
|
22
|
+
* run: (server) => console.log('Hook executed')
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
type DefineHook<Fn extends (...args: any) => any> = LazyImport<Fn> | {
|
|
26
|
+
run: Fn;
|
|
27
|
+
};
|
|
9
28
|
/**
|
|
10
29
|
* Common hooks executed by the dev-server, test runner and the bundler.
|
|
11
30
|
* These hooks are shared across all assembler operations and provide
|
|
@@ -26,7 +45,7 @@ export type CommonHooks = {
|
|
|
26
45
|
*
|
|
27
46
|
* @param parent - The parent instance (DevServer, TestRunner, or Bundler)
|
|
28
47
|
*/
|
|
29
|
-
init:
|
|
48
|
+
init: DefineHook<(parent: DevServer | TestRunner | Bundler, indexGenerator: IndexGenerator) => AsyncOrSync<void>>[];
|
|
30
49
|
};
|
|
31
50
|
/**
|
|
32
51
|
* Hooks executed by the dev server around the router.
|
|
@@ -53,7 +72,7 @@ export type RouterHooks = {
|
|
|
53
72
|
* @param parent - The DevServer instance
|
|
54
73
|
* @param routes - Record of routes grouped by domain or method
|
|
55
74
|
*/
|
|
56
|
-
routesCommitted:
|
|
75
|
+
routesCommitted: DefineHook<(parent: DevServer, routes: Record<string, RoutesListItem[]>) => AsyncOrSync<void>>[];
|
|
57
76
|
/**
|
|
58
77
|
* The hook is executed when dev server begins the routes scanning process.
|
|
59
78
|
* Use this hook to prepare for route scanning or modify scanner configuration.
|
|
@@ -61,7 +80,7 @@ export type RouterHooks = {
|
|
|
61
80
|
* @param parent - The DevServer instance
|
|
62
81
|
* @param routesScanner - The RoutesScanner instance being used
|
|
63
82
|
*/
|
|
64
|
-
routesScanning:
|
|
83
|
+
routesScanning: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
|
|
65
84
|
/**
|
|
66
85
|
* The hook is executed when routes scanning process has finished.
|
|
67
86
|
* Use this hook to process the scanned routes or clean up resources.
|
|
@@ -69,7 +88,7 @@ export type RouterHooks = {
|
|
|
69
88
|
* @param parent - The DevServer instance
|
|
70
89
|
* @param routesScanner - The RoutesScanner instance that was used
|
|
71
90
|
*/
|
|
72
|
-
routesScanned:
|
|
91
|
+
routesScanned: DefineHook<(parent: DevServer, routesScanner: RoutesScanner) => AsyncOrSync<void>>[];
|
|
73
92
|
};
|
|
74
93
|
/**
|
|
75
94
|
* Hooks executed by the file watcher during development and testing.
|
|
@@ -103,7 +122,7 @@ export type WatcherHooks = {
|
|
|
103
122
|
* @param info.fullReload - Whether a full server reload is required
|
|
104
123
|
* @param parent - The parent DevServer or TestRunner instance
|
|
105
124
|
*/
|
|
106
|
-
fileChanged:
|
|
125
|
+
fileChanged: DefineHook<(relativePath: string, absolutePath: string, info: {
|
|
107
126
|
/** Source of the file change notification */
|
|
108
127
|
source: 'hot-hook' | 'watcher';
|
|
109
128
|
/** Whether the file was hot reloaded without server restart */
|
|
@@ -118,7 +137,7 @@ export type WatcherHooks = {
|
|
|
118
137
|
* @param filePath - The absolute path to the added file
|
|
119
138
|
* @param server - The DevServer or TestRunner instance
|
|
120
139
|
*/
|
|
121
|
-
fileAdded:
|
|
140
|
+
fileAdded: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
|
|
122
141
|
/**
|
|
123
142
|
* The hook is executed after a file has been removed from the filesystem.
|
|
124
143
|
* Use this hook to clean up resources or update caches when files are deleted.
|
|
@@ -126,7 +145,7 @@ export type WatcherHooks = {
|
|
|
126
145
|
* @param filePath - The absolute path to the removed file
|
|
127
146
|
* @param server - The DevServer or TestRunner instance
|
|
128
147
|
*/
|
|
129
|
-
fileRemoved:
|
|
148
|
+
fileRemoved: DefineHook<(relativePath: string, absolutePath: string, server: DevServer | TestRunner) => AsyncOrSync<void>>[];
|
|
130
149
|
};
|
|
131
150
|
/**
|
|
132
151
|
* Hooks executed when running the development server.
|
|
@@ -148,7 +167,7 @@ export type DevServerHooks = {
|
|
|
148
167
|
*
|
|
149
168
|
* @param server - The DevServer instance that is about to start
|
|
150
169
|
*/
|
|
151
|
-
devServerStarting:
|
|
170
|
+
devServerStarting: DefineHook<(server: DevServer) => AsyncOrSync<void>>[];
|
|
152
171
|
/**
|
|
153
172
|
* The hook is executed after the child process has been started.
|
|
154
173
|
* Use this hook to display additional information or perform post-startup tasks.
|
|
@@ -159,7 +178,7 @@ export type DevServerHooks = {
|
|
|
159
178
|
* @param info.host - The host address the server is bound to
|
|
160
179
|
* @param uiInstructions - UI instructions for displaying server information
|
|
161
180
|
*/
|
|
162
|
-
devServerStarted:
|
|
181
|
+
devServerStarted: DefineHook<(server: DevServer, info: {
|
|
163
182
|
port: number;
|
|
164
183
|
host: string;
|
|
165
184
|
}, uiInstructions: Instructions) => AsyncOrSync<void>>[];
|
|
@@ -184,7 +203,7 @@ export type BundlerHooks = {
|
|
|
184
203
|
*
|
|
185
204
|
* @param server - The Bundler instance that will create the build
|
|
186
205
|
*/
|
|
187
|
-
buildStarting:
|
|
206
|
+
buildStarting: DefineHook<(server: Bundler) => AsyncOrSync<void>>[];
|
|
188
207
|
/**
|
|
189
208
|
* The hook is executed after the production build has been created.
|
|
190
209
|
* Use this hook to perform post-build tasks or display build statistics.
|
|
@@ -192,7 +211,7 @@ export type BundlerHooks = {
|
|
|
192
211
|
* @param server - The Bundler instance that created the build
|
|
193
212
|
* @param uiInstructions - UI instructions for displaying build information
|
|
194
213
|
*/
|
|
195
|
-
buildFinished:
|
|
214
|
+
buildFinished: DefineHook<(server: Bundler, uiInstructions: Instructions) => AsyncOrSync<void>>[];
|
|
196
215
|
};
|
|
197
216
|
/**
|
|
198
217
|
* Hooks executed when running the test suite.
|
|
@@ -214,12 +233,50 @@ export type TestRunnerHooks = {
|
|
|
214
233
|
*
|
|
215
234
|
* @param server - The TestRunner instance that will execute the tests
|
|
216
235
|
*/
|
|
217
|
-
testsStarting:
|
|
236
|
+
testsStarting: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
|
|
218
237
|
/**
|
|
219
238
|
* The hook is executed after the tests have been executed.
|
|
220
239
|
* Use this hook to clean up resources or generate test reports.
|
|
221
240
|
*
|
|
222
241
|
* @param server - The TestRunner instance that executed the tests
|
|
223
242
|
*/
|
|
224
|
-
testsFinished:
|
|
243
|
+
testsFinished: DefineHook<(server: TestRunner) => AsyncOrSync<void>>[];
|
|
225
244
|
};
|
|
245
|
+
/**
|
|
246
|
+
* Combined type representing all available hooks across the assembler ecosystem.
|
|
247
|
+
* This intersection type merges all hook categories into a single type for
|
|
248
|
+
* comprehensive hook management and type safety.
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```js
|
|
252
|
+
* const allHooks: AllHooks = {
|
|
253
|
+
* init: [() => import('./hooks/init')],
|
|
254
|
+
* fileChanged: [() => import('./hooks/file_changed')],
|
|
255
|
+
* devServerStarted: [() => import('./hooks/dev_server_started')],
|
|
256
|
+
* buildFinished: [() => import('./hooks/build_finished')],
|
|
257
|
+
* testsFinished: [() => import('./hooks/tests_finished')],
|
|
258
|
+
* routesCommitted: [() => import('./hooks/routes_committed')]
|
|
259
|
+
* }
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export type AllHooks = CommonHooks & WatcherHooks & DevServerHooks & BundlerHooks & TestRunnerHooks & RouterHooks;
|
|
263
|
+
/**
|
|
264
|
+
* Utility type that extracts the parameter types for a specific hook.
|
|
265
|
+
* This type helps maintain type safety when working with hook callbacks
|
|
266
|
+
* by providing the exact parameter signature for any given hook name.
|
|
267
|
+
*
|
|
268
|
+
* @template Hook - The name of the hook to extract parameters for
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```js
|
|
272
|
+
* // Get parameters for the fileChanged hook
|
|
273
|
+
* type FileChangedParams = HookParams<'fileChanged'>
|
|
274
|
+
* // Result: [string, string, {...}, DevServer | TestRunner]
|
|
275
|
+
*
|
|
276
|
+
* // Get parameters for the devServerStarted hook
|
|
277
|
+
* type DevServerStartedParams = HookParams<'devServerStarted')
|
|
278
|
+
* // Result: [DevServer, {port: number, host: string}, Instructions]
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export type HookParams<Hook extends keyof AllHooks> = AllHooks[Hook][number] extends DefineHook<infer A> ? Parameters<A> : never;
|
|
282
|
+
export {};
|
package/build/src/utils.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import Hooks from '@poppinss/hooks';
|
|
2
2
|
import type tsStatic from 'typescript';
|
|
3
3
|
import { type ChokidarOptions } from 'chokidar';
|
|
4
|
-
import { type UnWrapLazyImport } from '@poppinss/utils/types';
|
|
5
4
|
import type { RunScriptOptions } from './types/common.ts';
|
|
6
|
-
import { type
|
|
5
|
+
import { type AllHooks, type HookParams } from './types/hooks.ts';
|
|
7
6
|
/**
|
|
8
7
|
* Parses tsconfig.json and prints errors using typescript compiler host
|
|
9
8
|
*
|
|
@@ -145,8 +144,7 @@ export declare function isRelative(pathValue: string): boolean;
|
|
|
145
144
|
* @param names - Array of hook names to load
|
|
146
145
|
* @returns Promise resolving to configured Hooks instance
|
|
147
146
|
*/
|
|
148
|
-
|
|
149
|
-
export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{ [P in K]: [Parameters<UnWrapLazyImport<AllHooks[K][number]>>, Parameters<UnWrapLazyImport<AllHooks[K][number]>>]; }>>;
|
|
147
|
+
export declare function loadHooks<K extends keyof AllHooks>(rcFileHooks: Partial<AllHooks> | undefined, names: K[]): Promise<Hooks<{ [P in K]: [HookParams<P>, HookParams<P>]; }>>;
|
|
150
148
|
/**
|
|
151
149
|
* Wraps a function inside another function that throttles the concurrent
|
|
152
150
|
* executions of a function. If the function is called too quickly, then
|
|
@@ -167,4 +165,3 @@ export declare function throttle<Args extends any[]>(fn: (...args: Args) => Prom
|
|
|
167
165
|
* @returns The file path without extension
|
|
168
166
|
*/
|
|
169
167
|
export declare function removeExtension(filePath: string): string;
|
|
170
|
-
export {};
|
package/package.json
CHANGED