including-modules

This commit is contained in:
Kismet Hasanaj
2026-05-03 00:14:08 +02:00
parent ec83a0d879
commit 39a8a128be
20434 changed files with 3906546 additions and 3 deletions
@@ -0,0 +1,15 @@
import type { FileReader } from './file-reader';
/**
* CachedFileReader will deduplicate requests made to the same folder structure
* to scan for files.
*/
export declare class BatchedFileReader implements FileReader {
private readonly reader;
private batch?;
constructor(reader: FileReader);
private schedulePromise?;
private schedule;
private getOrCreateBatch;
private load;
read(dir: string): Promise<ReadonlyArray<string>>;
}
@@ -0,0 +1,106 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "BatchedFileReader", {
enumerable: true,
get: function() {
return BatchedFileReader;
}
});
class BatchedFileReader {
constructor(reader){
this.reader = reader;
}
schedule(callback) {
if (!this.schedulePromise) {
this.schedulePromise = Promise.resolve();
}
this.schedulePromise.then(()=>{
process.nextTick(callback);
});
}
getOrCreateBatch() {
// If there is an existing batch and it's not completed, then reuse it.
if (this.batch && !this.batch.completed) {
return this.batch;
}
const batch = {
completed: false,
directories: [],
callbacks: []
};
this.batch = batch;
this.schedule(async ()=>{
batch.completed = true;
if (batch.directories.length === 0) return;
// Collect all the results for each of the directories. If any error
// occurs, send the results back to the loaders.
let values;
try {
values = await this.load(batch.directories);
} catch (err) {
// Reject all the callbacks.
for (const { reject } of batch.callbacks){
reject(err);
}
return;
}
// Loop over all the callbacks and send them their results.
for(let i = 0; i < batch.callbacks.length; i++){
const value = values[i];
if (value instanceof Error) {
batch.callbacks[i].reject(value);
} else {
batch.callbacks[i].resolve(value);
}
}
});
return batch;
}
async load(directories) {
// Make a unique array of directories. This is what lets us de-duplicate
// loads for the same directory.
const unique = [
...new Set(directories)
];
const results = await Promise.all(unique.map(async (directory)=>{
let files;
let error;
try {
files = await this.reader.read(directory);
} catch (err) {
if (err instanceof Error) error = err;
}
return {
directory,
files,
error
};
}));
return directories.map((directory)=>{
const found = results.find((result)=>result.directory === directory);
if (!found) return [];
if (found.files) return found.files;
if (found.error) return found.error;
return [];
});
}
async read(dir) {
// Get or create a new file reading batch.
const batch = this.getOrCreateBatch();
// Push this directory into the batch to resolve.
batch.directories.push(dir);
// Push the promise handles into the batch (under the same index) so it can
// be resolved later when it's scheduled.
const promise = new Promise((resolve, reject)=>{
batch.callbacks.push({
resolve,
reject
});
});
return promise;
}
}
//# sourceMappingURL=batched-file-reader.js.map
File diff suppressed because one or more lines are too long
@@ -0,0 +1,30 @@
import type { FileReader } from './file-reader';
import type { RecursiveReadDirOptions } from '../../../../../lib/recursive-readdir';
export type DefaultFileReaderOptions = Pick<RecursiveReadDirOptions, 'pathnameFilter' | 'ignorePartFilter'>;
/**
* Reads all the files in the directory and its subdirectories following any
* symbolic links.
*/
export declare class DefaultFileReader implements FileReader {
/**
* Filter to ignore files with absolute pathnames. If undefined, no files are
* ignored.
*/
private readonly options;
/**
* Creates a new file reader.
*
* @param pathnameFilter filter to ignore files with absolute pathnames, false to ignore
* @param ignoreFilter filter to ignore files and directories with absolute pathnames, false to ignore
* @param ignorePartFilter filter to ignore files and directories with the pathname part, false to ignore
*/
constructor(options: Readonly<DefaultFileReaderOptions>);
/**
* Reads all the files in the directory and its subdirectories following any
* symbolic links.
*
* @param dir the directory to read
* @returns a promise that resolves to the list of files
*/
read(dir: string): Promise<ReadonlyArray<string>>;
}
@@ -0,0 +1,42 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "DefaultFileReader", {
enumerable: true,
get: function() {
return DefaultFileReader;
}
});
const _recursivereaddir = require("../../../../../lib/recursive-readdir");
class DefaultFileReader {
/**
* Creates a new file reader.
*
* @param pathnameFilter filter to ignore files with absolute pathnames, false to ignore
* @param ignoreFilter filter to ignore files and directories with absolute pathnames, false to ignore
* @param ignorePartFilter filter to ignore files and directories with the pathname part, false to ignore
*/ constructor(options){
this.options = options;
}
/**
* Reads all the files in the directory and its subdirectories following any
* symbolic links.
*
* @param dir the directory to read
* @returns a promise that resolves to the list of files
*/ async read(dir) {
return (0, _recursivereaddir.recursiveReadDir)(dir, {
pathnameFilter: this.options.pathnameFilter,
ignorePartFilter: this.options.ignorePartFilter,
// We don't need to sort the results because we're not depending on the
// order of the results.
sortPathnames: false,
// We want absolute pathnames because we're going to be comparing them
// with other absolute pathnames.
relativePathnames: false
});
}
}
//# sourceMappingURL=default-file-reader.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../../../src/server/route-matcher-providers/dev/helpers/file-reader/default-file-reader.ts"],"sourcesContent":["import type { FileReader } from './file-reader'\nimport type { RecursiveReadDirOptions } from '../../../../../lib/recursive-readdir'\nimport { recursiveReadDir } from '../../../../../lib/recursive-readdir'\n\nexport type DefaultFileReaderOptions = Pick<\n RecursiveReadDirOptions,\n 'pathnameFilter' | 'ignorePartFilter'\n>\n\n/**\n * Reads all the files in the directory and its subdirectories following any\n * symbolic links.\n */\nexport class DefaultFileReader implements FileReader {\n /**\n * Filter to ignore files with absolute pathnames. If undefined, no files are\n * ignored.\n */\n private readonly options: Readonly<DefaultFileReaderOptions>\n\n /**\n * Creates a new file reader.\n *\n * @param pathnameFilter filter to ignore files with absolute pathnames, false to ignore\n * @param ignoreFilter filter to ignore files and directories with absolute pathnames, false to ignore\n * @param ignorePartFilter filter to ignore files and directories with the pathname part, false to ignore\n */\n constructor(options: Readonly<DefaultFileReaderOptions>) {\n this.options = options\n }\n\n /**\n * Reads all the files in the directory and its subdirectories following any\n * symbolic links.\n *\n * @param dir the directory to read\n * @returns a promise that resolves to the list of files\n */\n public async read(dir: string): Promise<ReadonlyArray<string>> {\n return recursiveReadDir(dir, {\n pathnameFilter: this.options.pathnameFilter,\n ignorePartFilter: this.options.ignorePartFilter,\n\n // We don't need to sort the results because we're not depending on the\n // order of the results.\n sortPathnames: false,\n\n // We want absolute pathnames because we're going to be comparing them\n // with other absolute pathnames.\n relativePathnames: false,\n })\n }\n}\n"],"names":["DefaultFileReader","constructor","options","read","dir","recursiveReadDir","pathnameFilter","ignorePartFilter","sortPathnames","relativePathnames"],"mappings":";;;;+BAaaA;;;eAAAA;;;kCAXoB;AAW1B,MAAMA;IAOX;;;;;;GAMC,GACDC,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACA,OAAO,GAAGA;IACjB;IAEA;;;;;;GAMC,GACD,MAAaC,KAAKC,GAAW,EAAkC;QAC7D,OAAOC,IAAAA,kCAAgB,EAACD,KAAK;YAC3BE,gBAAgB,IAAI,CAACJ,OAAO,CAACI,cAAc;YAC3CC,kBAAkB,IAAI,CAACL,OAAO,CAACK,gBAAgB;YAE/C,uEAAuE;YACvE,wBAAwB;YACxBC,eAAe;YAEf,sEAAsE;YACtE,iCAAiC;YACjCC,mBAAmB;QACrB;IACF;AACF","ignoreList":[0]}
@@ -0,0 +1,8 @@
export interface FileReader {
/**
* Reads the directory contents recursively.
*
* @param dir directory to read recursively from
*/
read(dir: string): Promise<ReadonlyArray<string>> | ReadonlyArray<string>;
}
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=file-reader.js.map
@@ -0,0 +1 @@
{"version":3,"sources":[],"names":[],"mappings":"","ignoreList":[]}