From d0f9eaea129c2342a99633d6e2ada2b7e54efb85 Mon Sep 17 00:00:00 2001 From: sheo13666q Date: Sun, 18 Oct 2026 15:26:42 +0000 Subject: [PATCH 1/2] feat: accept a precompiled check in the worker's getOptions webpack's getOptions(schema, check) skips the schema when the check passes (webpack/webpack#22745). The worker reimplements getOptions, so a loader running under thread-loader kept compiling its schema. It now takes the same second argument; a failing check still validates fully. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo --- src/worker.js | 7 ++- test/options-check.test.js | 57 ++++++++++++++++++++++ test/options-check/file.js | 1 + test/options-check/options-check-loader.js | 11 +++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 test/options-check.test.js create mode 100644 test/options-check/file.js create mode 100644 test/options-check/options-check-loader.js diff --git a/src/worker.js b/src/worker.js index 903a2f5..3f6acc1 100644 --- a/src/worker.js +++ b/src/worker.js @@ -210,7 +210,7 @@ const queue = asyncQueue(({ id, data }, taskCallback) => { } }, // Not an arrow function because it uses this - getOptions(schema) { + getOptions(schema, check) { // loaders, loaderIndex will be defined by runLoaders const loader = this.loaders[this.loaderIndex]; @@ -240,7 +240,10 @@ const queue = asyncQueue(({ id, data }, taskCallback) => { options = {}; } - if (schema) { + // A precompiled check that passes skips the schema, as webpack's own + // `getOptions` does; one that fails still gets the full validation + // and its error messages. + if (schema && !(typeof check === 'function' && check(options))) { let name = 'Loader'; let baseDataPath = 'options'; let match; diff --git a/test/options-check.test.js b/test/options-check.test.js new file mode 100644 index 0000000..234c49c --- /dev/null +++ b/test/options-check.test.js @@ -0,0 +1,57 @@ +import os from 'os'; +import path from 'path'; + +import webpack from 'webpack'; + +const threadLoader = require('../dist'); + +const loader = require.resolve('./options-check/options-check-loader'); + +const run = (options) => + new Promise((resolve, reject) => { + webpack( + { + mode: 'none', + context: path.resolve(__dirname, 'options-check'), + devtool: false, + entry: './file.js', + output: { + path: path.join(os.tmpdir(), 'thread-loader-options-check'), + }, + module: { + rules: [ + { + test: /file\.js$/, + use: [ + { + loader: path.resolve(__dirname, '../dist/index.js'), + options: { workers: 1, poolTimeout: 2000 }, + }, + { loader, options }, + ], + }, + ], + }, + }, + (err, stats) => (err ? reject(err) : resolve(stats)), + ); + }); + +beforeAll(() => { + threadLoader.warmup({ workers: 1, poolTimeout: 2000 }, [loader]); +}); + +test('skips the schema when the precompiled check passes', async () => { + const stats = await run({ trusted: true }); + + expect(stats.compilation.errors).toHaveLength(0); +}); + +test('validates against the schema when the precompiled check fails', async () => { + const stats = await run({ name: 1 }); + + expect(stats.compilation.errors).toHaveLength(1); + expect(stats.compilation.errors[0].message).toMatch( + /options\.name should be a string/, + ); +}); diff --git a/test/options-check/file.js b/test/options-check/file.js new file mode 100644 index 0000000..3a8edd0 --- /dev/null +++ b/test/options-check/file.js @@ -0,0 +1 @@ +module.exports = 'file'; diff --git a/test/options-check/options-check-loader.js b/test/options-check/options-check-loader.js new file mode 100644 index 0000000..e0b5c14 --- /dev/null +++ b/test/options-check/options-check-loader.js @@ -0,0 +1,11 @@ +const schema = { + type: 'object', + properties: { name: { type: 'string' } }, + additionalProperties: false, +}; + +module.exports = function optionsCheckLoader() { + const options = this.getOptions(schema, (value) => value.trusted === true); + + return `module.exports = ${JSON.stringify(options)};`; +}; From d537f4e73bbab4af170459ee4739121edd7d8ae1 Mon Sep 17 00:00:00 2001 From: sheo13666q Date: Sun, 18 Oct 2026 15:43:03 +0000 Subject: [PATCH 2/2] chore(deps): bump fast-uri to 3.1.8 fast-uri <= 3.1.7 has high severity advisories (GHSA-v2hh-gcrm-f6hx and others), which fail `npm audit --omit=dev` in the lint job. 3.1.8 is within ajv's ^3.0.1 range, so only the lockfile changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QYPkbvwyRWt2SHgXDoYRdo --- package-lock.json | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 84c5325..5774465 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7812,9 +7812,20 @@ "dev": true }, "node_modules/fast-uri": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.1.tgz", - "integrity": "sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==" + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz", + "integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" }, "node_modules/fastq": { "version": "1.17.1", @@ -21372,9 +21383,9 @@ "dev": true }, "fast-uri": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.1.tgz", - "integrity": "sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==" + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.8.tgz", + "integrity": "sha512-GZMtZUTNRpOVIECoXwLNZS5xUGE+mVNbTB8h/7Rwh2TFWcBQiPzTgyZi05BF9UMZKkLJv8XBRJTlU7zg8+ZfMg==" }, "fastq": { "version": "1.17.1",