Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 39 additions & 49 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
"webpack": "^4.27.0 || ^5.0.0"
},
"dependencies": {
"json-parse-better-errors": "^1.0.2",
"loader-runner": "^4.1.0",
"loader-utils": "^2.0.0",
"neo-async": "^2.6.2"
"neo-async": "^2.6.2",
"schema-utils": "^3.0.0"
},
"devDependencies": {
"@babel/cli": "^7.12.1",
Expand Down Expand Up @@ -72,7 +74,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.1.2",
"sass": "^1.27.0",
"sass-loader": "^10.0.4",
"sass-loader": "^11.0.1",
"standard-version": "^9.0.0",
"webpack": "^5.3.0",
"webpack-cli": "^4.1.0",
Expand Down
51 changes: 51 additions & 0 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
import fs from 'fs';
import NativeModule from 'module';

import querystring from 'querystring';

import loaderRunner from 'loader-runner';
import asyncQueue from 'neo-async/queue';
import parseJson from 'json-parse-better-errors';
import { validate } from 'schema-utils';

import readBuffer from './readBuffer';
import { replacer, reviver } from './serializer';
Expand Down Expand Up @@ -158,6 +162,53 @@ const queue = asyncQueue(({ id, data }, taskCallback) => {
});
}
},
// Not an arrow function because it uses this
getOptions(schema) {
// loaders, loaderIndex will be defined by runLoaders
const loader = this.loaders[this.loaderIndex];

// Verbatim copy from
// https://github.com/webpack/webpack/blob/v5.31.2/lib/NormalModule.js#L471-L508
// except eslint/prettier differences
// -- unfortunate result of getOptions being synchronous functions.

let { options } = loader;

if (typeof options === 'string') {
if (options.substr(0, 1) === '{' && options.substr(-1) === '}') {
try {
options = parseJson(options);
} catch (e) {
throw new Error(`Cannot parse string options: ${e.message}`);
}
} else {
options = querystring.parse(options, '&', '=', {
maxKeys: 0,
});
}
}

// eslint-disable-next-line no-undefined
if (options === null || options === undefined) {
options = {};
}

if (schema) {
let name = 'Loader';
let baseDataPath = 'options';
let match;
// eslint-disable-next-line no-cond-assign
if (schema.title && (match = /^(.+) (.+)$/.exec(schema.title))) {
[, name, baseDataPath] = match;
}
validate(schema, options, {
name,
baseDataPath,
});
}

return options;
},
emitWarning: (warning) => {
writeJson({
type: 'emitWarning',
Expand Down