diff --git a/src/ModuleLoader.ts b/src/ModuleLoader.ts index f7ca8c25194..1fb6677ba69 100644 --- a/src/ModuleLoader.ts +++ b/src/ModuleLoader.ts @@ -220,9 +220,9 @@ export class ModuleLoader { timeStart('load modules', 3); let source: string | SourceDescription; try { - source = - (await this.pluginDriver.hookFirst('load', [id])) ?? - (await this.readQueue.run(async () => readFile(id))); + source = await this.readQueue.run( + async () => (await this.pluginDriver.hookFirst('load', [id])) ?? (await readFile(id)) + ); } catch (err) { timeEnd('load modules', 3); let msg = `Could not load ${id}`; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/1.js b/test/function/samples/max-parallel-file-reads-with-plugin/1.js new file mode 100644 index 00000000000..877dd1fbb70 --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/1.js @@ -0,0 +1 @@ +export const x1 = 1; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/2.js b/test/function/samples/max-parallel-file-reads-with-plugin/2.js new file mode 100644 index 00000000000..c269ae0d246 --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/2.js @@ -0,0 +1 @@ +export const x2 = 2; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/3.js b/test/function/samples/max-parallel-file-reads-with-plugin/3.js new file mode 100644 index 00000000000..1c323539956 --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/3.js @@ -0,0 +1 @@ +export const x3 = 3; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/4.js b/test/function/samples/max-parallel-file-reads-with-plugin/4.js new file mode 100644 index 00000000000..1b01b419ace --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/4.js @@ -0,0 +1 @@ +export const x4 = 4; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/5.js b/test/function/samples/max-parallel-file-reads-with-plugin/5.js new file mode 100644 index 00000000000..734bf3f6f04 --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/5.js @@ -0,0 +1 @@ +export const x5 = 5; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/_config.js b/test/function/samples/max-parallel-file-reads-with-plugin/_config.js new file mode 100644 index 00000000000..29bfcd49965 --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/_config.js @@ -0,0 +1,37 @@ +const assert = require('assert'); +const fs = require('fs'); + +const fsReadFile = fs.readFile; +let currentReads = 0; +let maxReads = 0; + +module.exports = { + description: 'maxParallelFileReads with plugin', + options: { + maxParallelFileReads: 3, + plugins: [ + { + async load(id) { + return new Promise((fulfil, reject) => + fs.readFile(id, 'utf-8', (err, contents) => (err ? reject(err) : fulfil(contents))) + ); + } + } + ] + }, + before() { + fs.readFile = (path, options, callback) => { + console.log('mock read'); + currentReads++; + maxReads = Math.max(maxReads, currentReads); + fsReadFile(path, options, (err, data) => { + currentReads--; + callback(err, data); + }); + }; + }, + after() { + fs.readFile = fsReadFile; + assert.strictEqual(maxReads, 3, 'Wrong number of parallel file reads: ' + maxReads); + } +}; diff --git a/test/function/samples/max-parallel-file-reads-with-plugin/main.js b/test/function/samples/max-parallel-file-reads-with-plugin/main.js new file mode 100644 index 00000000000..5f0a705e464 --- /dev/null +++ b/test/function/samples/max-parallel-file-reads-with-plugin/main.js @@ -0,0 +1,5 @@ +export * from './1'; +export * from './2'; +export * from './3'; +export * from './4'; +export * from './5';