@adonisjs/vite 5.1.1 → 6.0.0-next.1

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.
@@ -1,6 +1,13 @@
1
1
  import { t as addTrailingSlash } from "../../utils-CdZpa_tV.js";
2
- import { join } from "node:path";
3
- import PluginRestart from "vite-plugin-restart";
2
+ import { normalizePath } from "vite";
3
+ import path, { basename, isAbsolute, join, resolve } from "node:path";
4
+ import { readFileSync, statSync } from "node:fs";
5
+ import picomatch from "picomatch";
6
+ import * as nativeFs from "fs";
7
+ import { readdir, readdirSync, realpath, realpathSync, stat, statSync as statSync$1 } from "fs";
8
+ import { basename as basename$1, dirname, isAbsolute as isAbsolute$1, normalize, posix, relative, resolve as resolve$1, sep } from "path";
9
+ import { fileURLToPath } from "url";
10
+ import { createRequire } from "module";
4
11
  //#region src/client/config.ts
5
12
  /**
6
13
  * Resolves the base URL for Vite configuration based on command and options
@@ -29,7 +36,7 @@ function resolveBase(config, options, command) {
29
36
  * const mergedConfig = configHook(pluginOptions, userViteConfig, { command: 'build' })
30
37
  */
31
38
  function configHook(options, userConfig, { command }) {
32
- return {
39
+ const config = {
33
40
  publicDir: userConfig.publicDir ?? false,
34
41
  base: resolveBase(userConfig, options, command),
35
42
  /**
@@ -44,9 +51,31 @@ function configHook(options, userConfig, { command }) {
44
51
  manifest: userConfig.build?.manifest ?? true,
45
52
  outDir: userConfig.build?.outDir ?? options.buildDirectory,
46
53
  assetsInlineLimit: userConfig.build?.assetsInlineLimit ?? 0,
47
- rollupOptions: { input: options.entrypoints.map((entrypoint) => join(userConfig.root || "", entrypoint)) }
54
+ rolldownOptions: { input: userConfig.build?.rolldownOptions?.input ?? userConfig.build?.rollupOptions?.input ?? options.entrypoints }
48
55
  }
49
56
  };
57
+ /**
58
+ * When server-side entrypoints are declared, configure the SSR build
59
+ * environment so it mirrors the client setup: raw array input, manifest
60
+ * emitted alongside the output. `loadServerModule` reads that manifest
61
+ * at runtime to resolve a source path to the bundled file.
62
+ *
63
+ * Each field defers to a user/plugin-supplied value when present so
64
+ * other plugins contributing to `environments.ssr` cooperate rather
65
+ * than collide.
66
+ */
67
+ if (options.serverEntrypoints.length > 0) {
68
+ const userSsrBuild = userConfig.environments?.ssr?.build;
69
+ config.environments = { ssr: { build: {
70
+ ssr: userSsrBuild?.ssr ?? true,
71
+ emptyOutDir: userSsrBuild?.emptyOutDir ?? true,
72
+ emitAssets: userSsrBuild?.emitAssets ?? false,
73
+ manifest: userSsrBuild?.manifest ?? true,
74
+ outDir: userSsrBuild?.outDir ?? join(options.buildDirectory, "server"),
75
+ rolldownOptions: { input: userSsrBuild?.rolldownOptions?.input ?? userSsrBuild?.rollupOptions?.input ?? options.serverEntrypoints }
76
+ } } };
77
+ }
78
+ return config;
50
79
  }
51
80
  /**
52
81
  * Update the user vite config to match the Adonis requirements
@@ -59,6 +88,902 @@ const config = (options) => {
59
88
  };
60
89
  };
61
90
  //#endregion
91
+ //#region src/client/reload.ts
92
+ /**
93
+ * Compute the longest leading directory of a glob (everything up to the first
94
+ * segment containing a glob char). Returns the glob unchanged when no glob
95
+ * chars are present.
96
+ */
97
+ function baseDir(glob) {
98
+ const match = glob.search(/[*?[{]/);
99
+ if (match === -1) return glob;
100
+ const slash = glob.lastIndexOf("/", match);
101
+ return slash === -1 ? "." : glob.slice(0, slash);
102
+ }
103
+ /**
104
+ * Returns a Vite plugin that triggers a full browser reload whenever any file
105
+ * matching the supplied glob patterns changes. Patterns are resolved relative
106
+ * to the Vite project root.
107
+ *
108
+ * Replaces the previous `vite-plugin-restart` dependency. Only the reload
109
+ * (browser refresh) feature is implemented — server restart is not.
110
+ */
111
+ function reload(patterns, options = {}) {
112
+ const delay = options.delay ?? 100;
113
+ const patternList = Array.isArray(patterns) ? patterns : [patterns];
114
+ let timer;
115
+ return {
116
+ name: "adonisjs:reload",
117
+ apply: "serve",
118
+ configureServer(server) {
119
+ /**
120
+ * Vite's `normalizePath` converts platform-native separators to
121
+ * POSIX so glob patterns and chokidar-emitted file paths line up
122
+ * on Windows.
123
+ */
124
+ const root = normalizePath(server.config.root);
125
+ const absolutePatterns = patternList.map((pattern) => path.posix.join(root, normalizePath(pattern)));
126
+ const isMatch = picomatch(absolutePatterns);
127
+ /**
128
+ * Watch the longest non-glob prefix of each pattern so newly created
129
+ * files inside watched directories are picked up.
130
+ */
131
+ const baseDirs = absolutePatterns.map(baseDir);
132
+ server.watcher.add(baseDirs);
133
+ const trigger = (file) => {
134
+ if (!isMatch(normalizePath(file))) return;
135
+ if (timer) clearTimeout(timer);
136
+ timer = setTimeout(() => {
137
+ server.ws.send({
138
+ type: "full-reload",
139
+ path: "*"
140
+ });
141
+ timer = void 0;
142
+ }, delay);
143
+ };
144
+ server.watcher.on("add", trigger);
145
+ server.watcher.on("change", trigger);
146
+ server.watcher.on("unlink", trigger);
147
+ }
148
+ };
149
+ }
150
+ //#endregion
151
+ //#region node_modules/fdir/dist/index.mjs
152
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
153
+ function cleanPath(path) {
154
+ let normalized = normalize(path);
155
+ if (normalized.length > 1 && normalized[normalized.length - 1] === sep) normalized = normalized.substring(0, normalized.length - 1);
156
+ return normalized;
157
+ }
158
+ const SLASHES_REGEX = /[\\/]/g;
159
+ function convertSlashes(path, separator) {
160
+ return path.replace(SLASHES_REGEX, separator);
161
+ }
162
+ const WINDOWS_ROOT_DIR_REGEX = /^[a-z]:[\\/]$/i;
163
+ function isRootDirectory(path) {
164
+ return path === "/" || WINDOWS_ROOT_DIR_REGEX.test(path);
165
+ }
166
+ function normalizePath$2(path, options) {
167
+ const { resolvePaths, normalizePath: normalizePath$1, pathSeparator } = options;
168
+ const pathNeedsCleaning = process.platform === "win32" && path.includes("/") || path.startsWith(".");
169
+ if (resolvePaths) path = resolve$1(path);
170
+ if (normalizePath$1 || pathNeedsCleaning) path = cleanPath(path);
171
+ if (path === ".") return "";
172
+ return convertSlashes(path[path.length - 1] !== pathSeparator ? path + pathSeparator : path, pathSeparator);
173
+ }
174
+ function joinPathWithBasePath(filename, directoryPath) {
175
+ return directoryPath + filename;
176
+ }
177
+ function joinPathWithRelativePath(root, options) {
178
+ return function(filename, directoryPath) {
179
+ if (directoryPath.startsWith(root)) return directoryPath.slice(root.length) + filename;
180
+ else return convertSlashes(relative(root, directoryPath), options.pathSeparator) + options.pathSeparator + filename;
181
+ };
182
+ }
183
+ function joinPath(filename) {
184
+ return filename;
185
+ }
186
+ function joinDirectoryPath(filename, directoryPath, separator) {
187
+ return directoryPath + filename + separator;
188
+ }
189
+ function build$7(root, options) {
190
+ const { relativePaths, includeBasePath } = options;
191
+ return relativePaths && root ? joinPathWithRelativePath(root, options) : includeBasePath ? joinPathWithBasePath : joinPath;
192
+ }
193
+ function pushDirectoryWithRelativePath(root) {
194
+ return function(directoryPath, paths) {
195
+ paths.push(directoryPath.substring(root.length) || ".");
196
+ };
197
+ }
198
+ function pushDirectoryFilterWithRelativePath(root) {
199
+ return function(directoryPath, paths, filters) {
200
+ const relativePath = directoryPath.substring(root.length) || ".";
201
+ if (filters.every((filter) => filter(relativePath, true))) paths.push(relativePath);
202
+ };
203
+ }
204
+ const pushDirectory = (directoryPath, paths) => {
205
+ paths.push(directoryPath || ".");
206
+ };
207
+ const pushDirectoryFilter = (directoryPath, paths, filters) => {
208
+ const path = directoryPath || ".";
209
+ if (filters.every((filter) => filter(path, true))) paths.push(path);
210
+ };
211
+ const empty$2 = () => {};
212
+ function build$6(root, options) {
213
+ const { includeDirs, filters, relativePaths } = options;
214
+ if (!includeDirs) return empty$2;
215
+ if (relativePaths) return filters && filters.length ? pushDirectoryFilterWithRelativePath(root) : pushDirectoryWithRelativePath(root);
216
+ return filters && filters.length ? pushDirectoryFilter : pushDirectory;
217
+ }
218
+ const pushFileFilterAndCount = (filename, _paths, counts, filters) => {
219
+ if (filters.every((filter) => filter(filename, false))) counts.files++;
220
+ };
221
+ const pushFileFilter = (filename, paths, _counts, filters) => {
222
+ if (filters.every((filter) => filter(filename, false))) paths.push(filename);
223
+ };
224
+ const pushFileCount = (_filename, _paths, counts, _filters) => {
225
+ counts.files++;
226
+ };
227
+ const pushFile = (filename, paths) => {
228
+ paths.push(filename);
229
+ };
230
+ const empty$1 = () => {};
231
+ function build$5(options) {
232
+ const { excludeFiles, filters, onlyCounts } = options;
233
+ if (excludeFiles) return empty$1;
234
+ if (filters && filters.length) return onlyCounts ? pushFileFilterAndCount : pushFileFilter;
235
+ else if (onlyCounts) return pushFileCount;
236
+ else return pushFile;
237
+ }
238
+ const getArray = (paths) => {
239
+ return paths;
240
+ };
241
+ const getArrayGroup = () => {
242
+ return [""].slice(0, 0);
243
+ };
244
+ function build$4(options) {
245
+ return options.group ? getArrayGroup : getArray;
246
+ }
247
+ const groupFiles = (groups, directory, files) => {
248
+ groups.push({
249
+ directory,
250
+ files,
251
+ dir: directory
252
+ });
253
+ };
254
+ const empty = () => {};
255
+ function build$3(options) {
256
+ return options.group ? groupFiles : empty;
257
+ }
258
+ const resolveSymlinksAsync = function(path, state, callback$1) {
259
+ const { queue, fs, options: { suppressErrors } } = state;
260
+ queue.enqueue();
261
+ fs.realpath(path, (error, resolvedPath) => {
262
+ if (error) return queue.dequeue(suppressErrors ? null : error, state);
263
+ fs.stat(resolvedPath, (error$1, stat) => {
264
+ if (error$1) return queue.dequeue(suppressErrors ? null : error$1, state);
265
+ if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return queue.dequeue(null, state);
266
+ callback$1(stat, resolvedPath);
267
+ queue.dequeue(null, state);
268
+ });
269
+ });
270
+ };
271
+ const resolveSymlinks = function(path, state, callback$1) {
272
+ const { queue, fs, options: { suppressErrors } } = state;
273
+ queue.enqueue();
274
+ try {
275
+ const resolvedPath = fs.realpathSync(path);
276
+ const stat = fs.statSync(resolvedPath);
277
+ if (stat.isDirectory() && isRecursive(path, resolvedPath, state)) return;
278
+ callback$1(stat, resolvedPath);
279
+ } catch (e) {
280
+ if (!suppressErrors) throw e;
281
+ }
282
+ };
283
+ function build$2(options, isSynchronous) {
284
+ if (!options.resolveSymlinks || options.excludeSymlinks) return null;
285
+ return isSynchronous ? resolveSymlinks : resolveSymlinksAsync;
286
+ }
287
+ function isRecursive(path, resolved, state) {
288
+ if (state.options.useRealPaths) return isRecursiveUsingRealPaths(resolved, state);
289
+ let parent = dirname(path);
290
+ let depth = 1;
291
+ while (parent !== state.root && depth < 2) {
292
+ const resolvedPath = state.symlinks.get(parent);
293
+ if (!!resolvedPath && (resolvedPath === resolved || resolvedPath.startsWith(resolved) || resolved.startsWith(resolvedPath))) depth++;
294
+ else parent = dirname(parent);
295
+ }
296
+ state.symlinks.set(path, resolved);
297
+ return depth > 1;
298
+ }
299
+ function isRecursiveUsingRealPaths(resolved, state) {
300
+ return state.visited.includes(resolved + state.options.pathSeparator);
301
+ }
302
+ const onlyCountsSync = (state) => {
303
+ return state.counts;
304
+ };
305
+ const groupsSync = (state) => {
306
+ return state.groups;
307
+ };
308
+ const defaultSync = (state) => {
309
+ return state.paths;
310
+ };
311
+ const limitFilesSync = (state) => {
312
+ return state.paths.slice(0, state.options.maxFiles);
313
+ };
314
+ const onlyCountsAsync = (state, error, callback$1) => {
315
+ report(error, callback$1, state.counts, state.options.suppressErrors);
316
+ return null;
317
+ };
318
+ const defaultAsync = (state, error, callback$1) => {
319
+ report(error, callback$1, state.paths, state.options.suppressErrors);
320
+ return null;
321
+ };
322
+ const limitFilesAsync = (state, error, callback$1) => {
323
+ report(error, callback$1, state.paths.slice(0, state.options.maxFiles), state.options.suppressErrors);
324
+ return null;
325
+ };
326
+ const groupsAsync = (state, error, callback$1) => {
327
+ report(error, callback$1, state.groups, state.options.suppressErrors);
328
+ return null;
329
+ };
330
+ function report(error, callback$1, output, suppressErrors) {
331
+ if (error && !suppressErrors) callback$1(error, output);
332
+ else callback$1(null, output);
333
+ }
334
+ function build$1(options, isSynchronous) {
335
+ const { onlyCounts, group, maxFiles } = options;
336
+ if (onlyCounts) return isSynchronous ? onlyCountsSync : onlyCountsAsync;
337
+ else if (group) return isSynchronous ? groupsSync : groupsAsync;
338
+ else if (maxFiles) return isSynchronous ? limitFilesSync : limitFilesAsync;
339
+ else return isSynchronous ? defaultSync : defaultAsync;
340
+ }
341
+ const readdirOpts = { withFileTypes: true };
342
+ const walkAsync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
343
+ state.queue.enqueue();
344
+ if (currentDepth < 0) return state.queue.dequeue(null, state);
345
+ const { fs } = state;
346
+ state.visited.push(crawlPath);
347
+ state.counts.directories++;
348
+ fs.readdir(crawlPath || ".", readdirOpts, (error, entries = []) => {
349
+ callback$1(entries, directoryPath, currentDepth);
350
+ state.queue.dequeue(state.options.suppressErrors ? null : error, state);
351
+ });
352
+ };
353
+ const walkSync = (state, crawlPath, directoryPath, currentDepth, callback$1) => {
354
+ const { fs } = state;
355
+ if (currentDepth < 0) return;
356
+ state.visited.push(crawlPath);
357
+ state.counts.directories++;
358
+ let entries = [];
359
+ try {
360
+ entries = fs.readdirSync(crawlPath || ".", readdirOpts);
361
+ } catch (e) {
362
+ if (!state.options.suppressErrors) throw e;
363
+ }
364
+ callback$1(entries, directoryPath, currentDepth);
365
+ };
366
+ function build(isSynchronous) {
367
+ return isSynchronous ? walkSync : walkAsync;
368
+ }
369
+ /**
370
+ * This is a custom stateless queue to track concurrent async fs calls.
371
+ * It increments a counter whenever a call is queued and decrements it
372
+ * as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
373
+ */
374
+ var Queue = class {
375
+ count = 0;
376
+ constructor(onQueueEmpty) {
377
+ this.onQueueEmpty = onQueueEmpty;
378
+ }
379
+ enqueue() {
380
+ this.count++;
381
+ return this.count;
382
+ }
383
+ dequeue(error, output) {
384
+ if (this.onQueueEmpty && (--this.count <= 0 || error)) {
385
+ this.onQueueEmpty(error, output);
386
+ if (error) {
387
+ output.controller.abort();
388
+ this.onQueueEmpty = void 0;
389
+ }
390
+ }
391
+ }
392
+ };
393
+ var Counter = class {
394
+ _files = 0;
395
+ _directories = 0;
396
+ set files(num) {
397
+ this._files = num;
398
+ }
399
+ get files() {
400
+ return this._files;
401
+ }
402
+ set directories(num) {
403
+ this._directories = num;
404
+ }
405
+ get directories() {
406
+ return this._directories;
407
+ }
408
+ /**
409
+ * @deprecated use `directories` instead
410
+ */
411
+ /* c8 ignore next 3 */
412
+ get dirs() {
413
+ return this._directories;
414
+ }
415
+ };
416
+ /**
417
+ * AbortController is not supported on Node 14 so we use this until we can drop
418
+ * support for Node 14.
419
+ */
420
+ var Aborter = class {
421
+ aborted = false;
422
+ abort() {
423
+ this.aborted = true;
424
+ }
425
+ };
426
+ var Walker = class {
427
+ root;
428
+ isSynchronous;
429
+ state;
430
+ joinPath;
431
+ pushDirectory;
432
+ pushFile;
433
+ getArray;
434
+ groupFiles;
435
+ resolveSymlink;
436
+ walkDirectory;
437
+ callbackInvoker;
438
+ constructor(root, options, callback$1) {
439
+ this.isSynchronous = !callback$1;
440
+ this.callbackInvoker = build$1(options, this.isSynchronous);
441
+ this.root = normalizePath$2(root, options);
442
+ this.state = {
443
+ root: isRootDirectory(this.root) ? this.root : this.root.slice(0, -1),
444
+ paths: [""].slice(0, 0),
445
+ groups: [],
446
+ counts: new Counter(),
447
+ options,
448
+ queue: new Queue((error, state) => this.callbackInvoker(state, error, callback$1)),
449
+ symlinks: /* @__PURE__ */ new Map(),
450
+ visited: [""].slice(0, 0),
451
+ controller: new Aborter(),
452
+ fs: options.fs || nativeFs
453
+ };
454
+ this.joinPath = build$7(this.root, options);
455
+ this.pushDirectory = build$6(this.root, options);
456
+ this.pushFile = build$5(options);
457
+ this.getArray = build$4(options);
458
+ this.groupFiles = build$3(options);
459
+ this.resolveSymlink = build$2(options, this.isSynchronous);
460
+ this.walkDirectory = build(this.isSynchronous);
461
+ }
462
+ start() {
463
+ this.pushDirectory(this.root, this.state.paths, this.state.options.filters);
464
+ this.walkDirectory(this.state, this.root, this.root, this.state.options.maxDepth, this.walk);
465
+ return this.isSynchronous ? this.callbackInvoker(this.state, null) : null;
466
+ }
467
+ walk = (entries, directoryPath, depth) => {
468
+ const { paths, options: { filters, resolveSymlinks: resolveSymlinks$1, excludeSymlinks, exclude, maxFiles, signal, useRealPaths, pathSeparator }, controller } = this.state;
469
+ if (controller.aborted || signal && signal.aborted || maxFiles && paths.length > maxFiles) return;
470
+ const files = this.getArray(this.state.paths);
471
+ for (let i = 0; i < entries.length; ++i) {
472
+ const entry = entries[i];
473
+ if (entry.isFile() || entry.isSymbolicLink() && !resolveSymlinks$1 && !excludeSymlinks) {
474
+ const filename = this.joinPath(entry.name, directoryPath);
475
+ this.pushFile(filename, files, this.state.counts, filters);
476
+ } else if (entry.isDirectory()) {
477
+ let path = joinDirectoryPath(entry.name, directoryPath, this.state.options.pathSeparator);
478
+ if (exclude && exclude(entry.name, path)) continue;
479
+ this.pushDirectory(path, paths, filters);
480
+ this.walkDirectory(this.state, path, path, depth - 1, this.walk);
481
+ } else if (this.resolveSymlink && entry.isSymbolicLink()) {
482
+ let path = joinPathWithBasePath(entry.name, directoryPath);
483
+ this.resolveSymlink(path, this.state, (stat, resolvedPath) => {
484
+ if (stat.isDirectory()) {
485
+ resolvedPath = normalizePath$2(resolvedPath, this.state.options);
486
+ if (exclude && exclude(entry.name, useRealPaths ? resolvedPath : path + pathSeparator)) return;
487
+ this.walkDirectory(this.state, resolvedPath, useRealPaths ? resolvedPath : path + pathSeparator, depth - 1, this.walk);
488
+ } else {
489
+ resolvedPath = useRealPaths ? resolvedPath : path;
490
+ const filename = basename$1(resolvedPath);
491
+ const directoryPath$1 = normalizePath$2(dirname(resolvedPath), this.state.options);
492
+ resolvedPath = this.joinPath(filename, directoryPath$1);
493
+ this.pushFile(resolvedPath, files, this.state.counts, filters);
494
+ }
495
+ });
496
+ }
497
+ }
498
+ this.groupFiles(this.state.groups, directoryPath, files);
499
+ };
500
+ };
501
+ function promise(root, options) {
502
+ return new Promise((resolve$1, reject) => {
503
+ callback(root, options, (err, output) => {
504
+ if (err) return reject(err);
505
+ resolve$1(output);
506
+ });
507
+ });
508
+ }
509
+ function callback(root, options, callback$1) {
510
+ new Walker(root, options, callback$1).start();
511
+ }
512
+ function sync(root, options) {
513
+ return new Walker(root, options).start();
514
+ }
515
+ var APIBuilder = class {
516
+ constructor(root, options) {
517
+ this.root = root;
518
+ this.options = options;
519
+ }
520
+ withPromise() {
521
+ return promise(this.root, this.options);
522
+ }
523
+ withCallback(cb) {
524
+ callback(this.root, this.options, cb);
525
+ }
526
+ sync() {
527
+ return sync(this.root, this.options);
528
+ }
529
+ };
530
+ let pm = null;
531
+ /* c8 ignore next 6 */
532
+ try {
533
+ __require.resolve("picomatch");
534
+ pm = __require("picomatch");
535
+ } catch {}
536
+ var Builder = class {
537
+ globCache = {};
538
+ options = {
539
+ maxDepth: Infinity,
540
+ suppressErrors: true,
541
+ pathSeparator: sep,
542
+ filters: []
543
+ };
544
+ globFunction;
545
+ constructor(options) {
546
+ this.options = {
547
+ ...this.options,
548
+ ...options
549
+ };
550
+ this.globFunction = this.options.globFunction;
551
+ }
552
+ group() {
553
+ this.options.group = true;
554
+ return this;
555
+ }
556
+ withPathSeparator(separator) {
557
+ this.options.pathSeparator = separator;
558
+ return this;
559
+ }
560
+ withBasePath() {
561
+ this.options.includeBasePath = true;
562
+ return this;
563
+ }
564
+ withRelativePaths() {
565
+ this.options.relativePaths = true;
566
+ return this;
567
+ }
568
+ withDirs() {
569
+ this.options.includeDirs = true;
570
+ return this;
571
+ }
572
+ withMaxDepth(depth) {
573
+ this.options.maxDepth = depth;
574
+ return this;
575
+ }
576
+ withMaxFiles(limit) {
577
+ this.options.maxFiles = limit;
578
+ return this;
579
+ }
580
+ withFullPaths() {
581
+ this.options.resolvePaths = true;
582
+ this.options.includeBasePath = true;
583
+ return this;
584
+ }
585
+ withErrors() {
586
+ this.options.suppressErrors = false;
587
+ return this;
588
+ }
589
+ withSymlinks({ resolvePaths = true } = {}) {
590
+ this.options.resolveSymlinks = true;
591
+ this.options.useRealPaths = resolvePaths;
592
+ return this.withFullPaths();
593
+ }
594
+ withAbortSignal(signal) {
595
+ this.options.signal = signal;
596
+ return this;
597
+ }
598
+ normalize() {
599
+ this.options.normalizePath = true;
600
+ return this;
601
+ }
602
+ filter(predicate) {
603
+ this.options.filters.push(predicate);
604
+ return this;
605
+ }
606
+ onlyDirs() {
607
+ this.options.excludeFiles = true;
608
+ this.options.includeDirs = true;
609
+ return this;
610
+ }
611
+ exclude(predicate) {
612
+ this.options.exclude = predicate;
613
+ return this;
614
+ }
615
+ onlyCounts() {
616
+ this.options.onlyCounts = true;
617
+ return this;
618
+ }
619
+ crawl(root) {
620
+ return new APIBuilder(root || ".", this.options);
621
+ }
622
+ withGlobFunction(fn) {
623
+ this.globFunction = fn;
624
+ return this;
625
+ }
626
+ /**
627
+ * @deprecated Pass options using the constructor instead:
628
+ * ```ts
629
+ * new fdir(options).crawl("/path/to/root");
630
+ * ```
631
+ * This method will be removed in v7.0
632
+ */
633
+ /* c8 ignore next 4 */
634
+ crawlWithOptions(root, options) {
635
+ this.options = {
636
+ ...this.options,
637
+ ...options
638
+ };
639
+ return new APIBuilder(root || ".", this.options);
640
+ }
641
+ glob(...patterns) {
642
+ if (this.globFunction) return this.globWithOptions(patterns);
643
+ return this.globWithOptions(patterns, ...[{ dot: true }]);
644
+ }
645
+ globWithOptions(patterns, ...options) {
646
+ const globFn = this.globFunction || pm;
647
+ /* c8 ignore next 5 */
648
+ if (!globFn) throw new Error("Please specify a glob function to use glob matching.");
649
+ var isMatch = this.globCache[patterns.join("\0")];
650
+ if (!isMatch) {
651
+ isMatch = globFn(patterns, ...options);
652
+ this.globCache[patterns.join("\0")] = isMatch;
653
+ }
654
+ this.options.filters.push((path) => isMatch(path));
655
+ return this;
656
+ }
657
+ };
658
+ //#endregion
659
+ //#region node_modules/tinyglobby/dist/index.mjs
660
+ const isReadonlyArray = Array.isArray;
661
+ const BACKSLASHES = /\\/g;
662
+ const isWin = process.platform === "win32";
663
+ const ONLY_PARENT_DIRECTORIES = /^(\/?\.\.)+$/;
664
+ function getPartialMatcher(patterns, options = {}) {
665
+ const patternsCount = patterns.length;
666
+ const patternsParts = Array(patternsCount);
667
+ const matchers = Array(patternsCount);
668
+ let i, j;
669
+ for (i = 0; i < patternsCount; i++) {
670
+ const parts = splitPattern(patterns[i]);
671
+ patternsParts[i] = parts;
672
+ const partsCount = parts.length;
673
+ const partMatchers = Array(partsCount);
674
+ for (j = 0; j < partsCount; j++) partMatchers[j] = picomatch(parts[j], options);
675
+ matchers[i] = partMatchers;
676
+ }
677
+ return (input) => {
678
+ const inputParts = input.split("/");
679
+ if (inputParts[0] === ".." && ONLY_PARENT_DIRECTORIES.test(input)) return true;
680
+ for (i = 0; i < patternsCount; i++) {
681
+ const patternParts = patternsParts[i];
682
+ const matcher = matchers[i];
683
+ const inputPatternCount = inputParts.length;
684
+ const minParts = Math.min(inputPatternCount, patternParts.length);
685
+ j = 0;
686
+ while (j < minParts) {
687
+ const part = patternParts[j];
688
+ if (part.includes("/")) return true;
689
+ if (!matcher[j](inputParts[j])) break;
690
+ if (!options.noglobstar && part === "**") return true;
691
+ j++;
692
+ }
693
+ if (j === inputPatternCount) return true;
694
+ }
695
+ return false;
696
+ };
697
+ }
698
+ /* node:coverage ignore next 2 */
699
+ const WIN32_ROOT_DIR = /^[A-Z]:\/$/i;
700
+ const isRoot = isWin ? (p) => WIN32_ROOT_DIR.test(p) : (p) => p === "/";
701
+ function buildFormat(cwd, root, absolute) {
702
+ if (cwd === root || root.startsWith(`${cwd}/`)) {
703
+ if (absolute) {
704
+ const start = cwd.length + +!isRoot(cwd);
705
+ return (p, isDir) => p.slice(start, isDir ? -1 : void 0) || ".";
706
+ }
707
+ const prefix = root.slice(cwd.length + 1);
708
+ if (prefix) return (p, isDir) => {
709
+ if (p === ".") return prefix;
710
+ const result = `${prefix}/${p}`;
711
+ return isDir ? result.slice(0, -1) : result;
712
+ };
713
+ return (p, isDir) => isDir && p !== "." ? p.slice(0, -1) : p;
714
+ }
715
+ if (absolute) return (p) => posix.relative(cwd, p) || ".";
716
+ return (p) => posix.relative(cwd, `${root}/${p}`) || ".";
717
+ }
718
+ function buildRelative(cwd, root) {
719
+ if (root.startsWith(`${cwd}/`)) {
720
+ const prefix = root.slice(cwd.length + 1);
721
+ return (p) => `${prefix}/${p}`;
722
+ }
723
+ return (p) => {
724
+ const result = posix.relative(cwd, `${root}/${p}`);
725
+ return p[p.length - 1] === "/" && result !== "" ? `${result}/` : result || ".";
726
+ };
727
+ }
728
+ const splitPatternOptions = { parts: true };
729
+ function splitPattern(path) {
730
+ var _result$parts;
731
+ const result = picomatch.scan(path, splitPatternOptions);
732
+ return ((_result$parts = result.parts) === null || _result$parts === void 0 ? void 0 : _result$parts.length) ? result.parts : [path];
733
+ }
734
+ const POSIX_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}*?|]|^!|[!+@](?=\()|\\(?![()[\]{}!*+?@|]))/g;
735
+ const WIN32_UNESCAPED_GLOB_SYMBOLS = /(?<!\\)([()[\]{}]|^!|[!+@](?=\())/g;
736
+ const escapePosixPath = (path) => path.replace(POSIX_UNESCAPED_GLOB_SYMBOLS, "\\$&");
737
+ const escapeWin32Path = (path) => path.replace(WIN32_UNESCAPED_GLOB_SYMBOLS, "\\$&");
738
+ /**
739
+ * Escapes a path's special characters depending on the platform.
740
+ * @see {@link https://superchupu.dev/tinyglobby/documentation#escapePath}
741
+ */
742
+ /* node:coverage ignore next */
743
+ const escapePath = isWin ? escapeWin32Path : escapePosixPath;
744
+ /**
745
+ * Checks if a pattern has dynamic parts.
746
+ *
747
+ * Has a few minor differences with [`fast-glob`](https://github.com/mrmlnc/fast-glob) for better accuracy:
748
+ *
749
+ * - Doesn't necessarily return `false` on patterns that include `\`.
750
+ * - Returns `true` if the pattern includes parentheses, regardless of them representing one single pattern or not.
751
+ * - Returns `true` for unfinished glob extensions i.e. `(h`, `+(h`.
752
+ * - Returns `true` for unfinished brace expansions as long as they include `,` or `..`.
753
+ *
754
+ * @see {@link https://superchupu.dev/tinyglobby/documentation#isDynamicPattern}
755
+ */
756
+ function isDynamicPattern(pattern, options) {
757
+ if ((options === null || options === void 0 ? void 0 : options.caseSensitiveMatch) === false) return true;
758
+ const scan = picomatch.scan(pattern);
759
+ return scan.isGlob || scan.negated;
760
+ }
761
+ function log(...tasks) {
762
+ console.log(`[tinyglobby ${(/* @__PURE__ */ new Date()).toLocaleTimeString("es")}]`, ...tasks);
763
+ }
764
+ function ensureStringArray(value) {
765
+ return typeof value === "string" ? [value] : value !== null && value !== void 0 ? value : [];
766
+ }
767
+ const PARENT_DIRECTORY = /^(\/?\.\.)+/;
768
+ const ESCAPING_BACKSLASHES = /\\(?=[()[\]{}!*+?@|])/g;
769
+ function normalizePattern(pattern, opts, props, isIgnore) {
770
+ var _PARENT_DIRECTORY$exe;
771
+ const cwd = opts.cwd;
772
+ let result = pattern;
773
+ if (pattern[pattern.length - 1] === "/") result = pattern.slice(0, -1);
774
+ if (result[result.length - 1] !== "*" && opts.expandDirectories) result += "/**";
775
+ const escapedCwd = escapePath(cwd);
776
+ result = isAbsolute$1(result.replace(ESCAPING_BACKSLASHES, "")) ? posix.relative(escapedCwd, result) : posix.normalize(result);
777
+ const parentDir = (_PARENT_DIRECTORY$exe = PARENT_DIRECTORY.exec(result)) === null || _PARENT_DIRECTORY$exe === void 0 ? void 0 : _PARENT_DIRECTORY$exe[0];
778
+ const parts = splitPattern(result);
779
+ if (parentDir) {
780
+ const n = (parentDir.length + 1) / 3;
781
+ let i = 0;
782
+ const cwdParts = escapedCwd.split("/");
783
+ while (i < n && parts[i + n] === cwdParts[cwdParts.length + i - n]) {
784
+ result = result.slice(0, (n - i - 1) * 3) + result.slice((n - i) * 3 + parts[i + n].length + 1) || ".";
785
+ i++;
786
+ }
787
+ const potentialRoot = posix.join(cwd, parentDir.slice(i * 3));
788
+ if (potentialRoot[0] !== "." && props.root.length > potentialRoot.length) {
789
+ props.root = potentialRoot;
790
+ props.depthOffset = -n + i;
791
+ }
792
+ }
793
+ if (!isIgnore && props.depthOffset >= 0) {
794
+ var _props$commonPath;
795
+ (_props$commonPath = props.commonPath) !== null && _props$commonPath !== void 0 || (props.commonPath = parts);
796
+ const newCommonPath = [];
797
+ const length = Math.min(props.commonPath.length, parts.length);
798
+ for (let i = 0; i < length; i++) {
799
+ const part = parts[i];
800
+ if (part === "**" && !parts[i + 1]) {
801
+ newCommonPath.pop();
802
+ break;
803
+ }
804
+ if (i === parts.length - 1 || part !== props.commonPath[i] || isDynamicPattern(part)) break;
805
+ newCommonPath.push(part);
806
+ }
807
+ props.depthOffset = newCommonPath.length;
808
+ props.commonPath = newCommonPath;
809
+ props.root = newCommonPath.length > 0 ? posix.join(cwd, ...newCommonPath) : cwd;
810
+ }
811
+ return result;
812
+ }
813
+ function processPatterns(options, patterns, props) {
814
+ const matchPatterns = [];
815
+ const ignorePatterns = [];
816
+ for (const pattern of options.ignore) {
817
+ if (!pattern) continue;
818
+ if (pattern[0] !== "!" || pattern[1] === "(") ignorePatterns.push(normalizePattern(pattern, options, props, true));
819
+ }
820
+ for (const pattern of patterns) {
821
+ if (!pattern) continue;
822
+ if (pattern[0] !== "!" || pattern[1] === "(") matchPatterns.push(normalizePattern(pattern, options, props, false));
823
+ else if (pattern[1] !== "!" || pattern[2] === "(") ignorePatterns.push(normalizePattern(pattern.slice(1), options, props, true));
824
+ }
825
+ return {
826
+ match: matchPatterns,
827
+ ignore: ignorePatterns
828
+ };
829
+ }
830
+ function buildCrawler(options, patterns) {
831
+ const cwd = options.cwd;
832
+ const props = {
833
+ root: cwd,
834
+ depthOffset: 0
835
+ };
836
+ const processed = processPatterns(options, patterns, props);
837
+ if (options.debug) log("internal processing patterns:", processed);
838
+ const { absolute, caseSensitiveMatch, debug, dot, followSymbolicLinks, onlyDirectories } = options;
839
+ const root = props.root.replace(BACKSLASHES, "");
840
+ const matchOptions = {
841
+ dot,
842
+ nobrace: options.braceExpansion === false,
843
+ nocase: !caseSensitiveMatch,
844
+ noextglob: options.extglob === false,
845
+ noglobstar: options.globstar === false,
846
+ posix: true
847
+ };
848
+ const matcher = picomatch(processed.match, matchOptions);
849
+ const ignore = picomatch(processed.ignore, matchOptions);
850
+ const partialMatcher = getPartialMatcher(processed.match, matchOptions);
851
+ const format = buildFormat(cwd, root, absolute);
852
+ const excludeFormatter = absolute ? format : buildFormat(cwd, root, true);
853
+ const excludePredicate = (_, p) => {
854
+ const relativePath = excludeFormatter(p, true);
855
+ return relativePath !== "." && !partialMatcher(relativePath) || ignore(relativePath);
856
+ };
857
+ let maxDepth;
858
+ if (options.deep !== void 0) maxDepth = Math.round(options.deep - props.depthOffset);
859
+ const crawler = new Builder({
860
+ filters: [debug ? (p, isDirectory) => {
861
+ const path = format(p, isDirectory);
862
+ const matches = matcher(path) && !ignore(path);
863
+ if (matches) log(`matched ${path}`);
864
+ return matches;
865
+ } : (p, isDirectory) => {
866
+ const path = format(p, isDirectory);
867
+ return matcher(path) && !ignore(path);
868
+ }],
869
+ exclude: debug ? (_, p) => {
870
+ const skipped = excludePredicate(_, p);
871
+ log(`${skipped ? "skipped" : "crawling"} ${p}`);
872
+ return skipped;
873
+ } : excludePredicate,
874
+ fs: options.fs,
875
+ pathSeparator: "/",
876
+ relativePaths: !absolute,
877
+ resolvePaths: absolute,
878
+ includeBasePath: absolute,
879
+ resolveSymlinks: followSymbolicLinks,
880
+ excludeSymlinks: !followSymbolicLinks,
881
+ excludeFiles: onlyDirectories,
882
+ includeDirs: onlyDirectories || !options.onlyFiles,
883
+ maxDepth,
884
+ signal: options.signal
885
+ }).crawl(root);
886
+ if (options.debug) log("internal properties:", {
887
+ ...props,
888
+ root
889
+ });
890
+ return [crawler, cwd !== root && !absolute && buildRelative(cwd, root)];
891
+ }
892
+ function formatPaths(paths, mapper) {
893
+ if (mapper) for (let i = paths.length - 1; i >= 0; i--) paths[i] = mapper(paths[i]);
894
+ return paths;
895
+ }
896
+ const defaultOptions = {
897
+ caseSensitiveMatch: true,
898
+ cwd: process.cwd(),
899
+ debug: !!process.env.TINYGLOBBY_DEBUG,
900
+ expandDirectories: true,
901
+ followSymbolicLinks: true,
902
+ onlyFiles: true
903
+ };
904
+ function getOptions(options) {
905
+ const opts = {
906
+ ...defaultOptions,
907
+ ...options
908
+ };
909
+ opts.cwd = (opts.cwd instanceof URL ? fileURLToPath(opts.cwd) : resolve$1(opts.cwd)).replace(BACKSLASHES, "/");
910
+ opts.ignore = ensureStringArray(opts.ignore);
911
+ opts.fs && (opts.fs = {
912
+ readdir: opts.fs.readdir || readdir,
913
+ readdirSync: opts.fs.readdirSync || readdirSync,
914
+ realpath: opts.fs.realpath || realpath,
915
+ realpathSync: opts.fs.realpathSync || realpathSync,
916
+ stat: opts.fs.stat || stat,
917
+ statSync: opts.fs.statSync || statSync$1
918
+ });
919
+ if (opts.debug) log("globbing with options:", opts);
920
+ return opts;
921
+ }
922
+ function getCrawler(globInput, inputOptions = {}) {
923
+ var _ref;
924
+ if (globInput && (inputOptions === null || inputOptions === void 0 ? void 0 : inputOptions.patterns)) throw new Error("Cannot pass patterns as both an argument and an option");
925
+ const isModern = isReadonlyArray(globInput) || typeof globInput === "string";
926
+ const patterns = ensureStringArray((_ref = isModern ? globInput : globInput.patterns) !== null && _ref !== void 0 ? _ref : "**/*");
927
+ const options = getOptions(isModern ? inputOptions : globInput);
928
+ return patterns.length > 0 ? buildCrawler(options, patterns) : [];
929
+ }
930
+ function globSync(globInput, options) {
931
+ const [crawler, relative] = getCrawler(globInput, options);
932
+ return crawler ? formatPaths(crawler.sync(), relative) : [];
933
+ }
934
+ //#endregion
935
+ //#region src/client/resolve_assets.ts
936
+ const GLOB_CHARS_REGEX = /[*?{}[\]]/;
937
+ /**
938
+ * Returns a plugin that emits user-supplied files into the build output.
939
+ *
940
+ * `chunks` are passed to Vite's `emitFile({ type: 'chunk' })` after glob
941
+ * expansion. They are processed by the bundler and surface in the manifest
942
+ * with hashed filenames.
943
+ *
944
+ * `assets` are emitted as raw `type: 'asset'` files (no glob expansion —
945
+ * exact paths only) so the original source content is preserved verbatim.
946
+ * The `originalFileName` field tells Vite to use the source path as the
947
+ * manifest key, so templates can resolve them via
948
+ * `vite.assetPath('resources/images/logo.png')` without any post-build
949
+ * manifest rewriting.
950
+ *
951
+ * Returns an empty array (no-op) when neither chunks nor assets are
952
+ * configured.
953
+ */
954
+ function resolveAssets(input) {
955
+ const chunks = Array.isArray(input) ? input : input?.chunks ?? [];
956
+ const assets = Array.isArray(input) ? [] : input?.assets ?? [];
957
+ if (chunks.length === 0 && assets.length === 0) return [];
958
+ for (const asset of assets) if (GLOB_CHARS_REGEX.test(asset)) throw new Error(`Assets do not support glob patterns. Received "${asset}". Provide an exact file path instead.`);
959
+ let root = process.cwd();
960
+ return [{
961
+ name: "adonisjs:resolve-assets",
962
+ apply: "build",
963
+ configResolved(config) {
964
+ root = config.root;
965
+ },
966
+ buildStart() {
967
+ for (const file of globSync(chunks, {
968
+ cwd: root,
969
+ absolute: true
970
+ })) if (statSync(file).isFile()) this.emitFile({
971
+ type: "chunk",
972
+ id: file
973
+ });
974
+ for (const file of assets) {
975
+ const absolute = isAbsolute(file) ? file : resolve(root, file);
976
+ this.emitFile({
977
+ type: "asset",
978
+ name: basename(file),
979
+ originalFileName: file,
980
+ source: readFileSync(absolute)
981
+ });
982
+ }
983
+ }
984
+ }];
985
+ }
986
+ //#endregion
62
987
  //#region src/client/main.ts
63
988
  /**
64
989
  * Vite plugin for AdonisJS
@@ -67,9 +992,14 @@ function adonisjs(options) {
67
992
  const fullOptions = Object.assign({
68
993
  assetsUrl: "/assets",
69
994
  buildDirectory: "public/assets",
70
- reload: ["./resources/views/**/*.edge"]
995
+ reload: ["./resources/views/**/*.edge"],
996
+ serverEntrypoints: []
71
997
  }, options);
72
- return [PluginRestart({ reload: fullOptions.reload }), config(fullOptions)];
998
+ return [
999
+ reload(fullOptions.reload),
1000
+ ...resolveAssets(options.assets),
1001
+ config(fullOptions)
1002
+ ];
73
1003
  }
74
1004
  //#endregion
75
1005
  export { adonisjs as default };