first commit
This commit is contained in:
30
app_vue/node_modules/thread-loader/dist/WorkerError.js
generated
vendored
Normal file
30
app_vue/node_modules/thread-loader/dist/WorkerError.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
const stack = (err, worker, workerId) => {
|
||||
const originError = (err.stack || '').split('\n').filter(line => line.trim().startsWith('at'));
|
||||
const workerError = worker.split('\n').filter(line => line.trim().startsWith('at'));
|
||||
const diff = workerError.slice(0, workerError.length - originError.length).join('\n');
|
||||
originError.unshift(diff);
|
||||
originError.unshift(err.message);
|
||||
originError.unshift(`Thread Loader (Worker ${workerId})`);
|
||||
return originError.join('\n');
|
||||
};
|
||||
|
||||
class WorkerError extends Error {
|
||||
constructor(err, workerId) {
|
||||
super(err);
|
||||
this.name = err.name;
|
||||
this.message = err.message;
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
this.stack = stack(err, this.stack, workerId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var _default = WorkerError;
|
||||
exports.default = _default;
|
468
app_vue/node_modules/thread-loader/dist/WorkerPool.js
generated
vendored
Normal file
468
app_vue/node_modules/thread-loader/dist/WorkerPool.js
generated
vendored
Normal file
@ -0,0 +1,468 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _child_process = _interopRequireDefault(require("child_process"));
|
||||
|
||||
var _queue = _interopRequireDefault(require("neo-async/queue"));
|
||||
|
||||
var _mapSeries = _interopRequireDefault(require("neo-async/mapSeries"));
|
||||
|
||||
var _readBuffer = _interopRequireDefault(require("./readBuffer"));
|
||||
|
||||
var _WorkerError = _interopRequireDefault(require("./WorkerError"));
|
||||
|
||||
var _serializer = require("./serializer");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/* eslint-disable no-console */
|
||||
const workerPath = require.resolve('./worker');
|
||||
|
||||
let workerId = 0;
|
||||
|
||||
class PoolWorker {
|
||||
constructor(options, onJobDone) {
|
||||
this.disposed = false;
|
||||
this.nextJobId = 0;
|
||||
this.jobs = Object.create(null);
|
||||
this.activeJobs = 0;
|
||||
this.onJobDone = onJobDone;
|
||||
this.id = workerId;
|
||||
workerId += 1; // Empty or invalid node args would break the child process
|
||||
|
||||
const sanitizedNodeArgs = (options.nodeArgs || []).filter(opt => !!opt);
|
||||
this.worker = _child_process.default.spawn(process.execPath, [].concat(sanitizedNodeArgs).concat(workerPath, options.parallelJobs), {
|
||||
detached: true,
|
||||
stdio: ['ignore', 'pipe', 'pipe', 'pipe', 'pipe']
|
||||
});
|
||||
this.worker.unref(); // This prevents a problem where the worker stdio can be undefined
|
||||
// when the kernel hits the limit of open files.
|
||||
// More info can be found on: https://github.com/webpack-contrib/thread-loader/issues/2
|
||||
|
||||
if (!this.worker.stdio) {
|
||||
throw new Error(`Failed to create the worker pool with workerId: ${workerId} and ${''}configuration: ${JSON.stringify(options)}. Please verify if you hit the OS open files limit.`);
|
||||
}
|
||||
|
||||
const [,,, readPipe, writePipe] = this.worker.stdio;
|
||||
this.readPipe = readPipe;
|
||||
this.writePipe = writePipe;
|
||||
this.listenStdOutAndErrFromWorker(this.worker.stdout, this.worker.stderr);
|
||||
this.readNextMessage();
|
||||
}
|
||||
|
||||
listenStdOutAndErrFromWorker(workerStdout, workerStderr) {
|
||||
if (workerStdout) {
|
||||
workerStdout.on('data', this.writeToStdout);
|
||||
}
|
||||
|
||||
if (workerStderr) {
|
||||
workerStderr.on('data', this.writeToStderr);
|
||||
}
|
||||
}
|
||||
|
||||
ignoreStdOutAndErrFromWorker(workerStdout, workerStderr) {
|
||||
if (workerStdout) {
|
||||
workerStdout.removeListener('data', this.writeToStdout);
|
||||
}
|
||||
|
||||
if (workerStderr) {
|
||||
workerStderr.removeListener('data', this.writeToStderr);
|
||||
}
|
||||
}
|
||||
|
||||
writeToStdout(data) {
|
||||
if (!this.disposed) {
|
||||
process.stdout.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
writeToStderr(data) {
|
||||
if (!this.disposed) {
|
||||
process.stderr.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
run(data, callback) {
|
||||
const jobId = this.nextJobId;
|
||||
this.nextJobId += 1;
|
||||
this.jobs[jobId] = {
|
||||
data,
|
||||
callback
|
||||
};
|
||||
this.activeJobs += 1;
|
||||
this.writeJson({
|
||||
type: 'job',
|
||||
id: jobId,
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
warmup(requires) {
|
||||
this.writeJson({
|
||||
type: 'warmup',
|
||||
requires
|
||||
});
|
||||
}
|
||||
|
||||
writeJson(data) {
|
||||
const lengthBuffer = Buffer.alloc(4);
|
||||
const messageBuffer = Buffer.from(JSON.stringify(data, _serializer.replacer), 'utf-8');
|
||||
lengthBuffer.writeInt32BE(messageBuffer.length, 0);
|
||||
this.writePipe.write(lengthBuffer);
|
||||
this.writePipe.write(messageBuffer);
|
||||
}
|
||||
|
||||
writeEnd() {
|
||||
const lengthBuffer = Buffer.alloc(4);
|
||||
lengthBuffer.writeInt32BE(0, 0);
|
||||
this.writePipe.write(lengthBuffer);
|
||||
}
|
||||
|
||||
readNextMessage() {
|
||||
this.state = 'read length';
|
||||
this.readBuffer(4, (lengthReadError, lengthBuffer) => {
|
||||
if (lengthReadError) {
|
||||
console.error(`Failed to communicate with worker (read length) ${lengthReadError}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.state = 'length read';
|
||||
const length = lengthBuffer.readInt32BE(0);
|
||||
this.state = 'read message';
|
||||
this.readBuffer(length, (messageError, messageBuffer) => {
|
||||
if (messageError) {
|
||||
console.error(`Failed to communicate with worker (read message) ${messageError}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.state = 'message read';
|
||||
const messageString = messageBuffer.toString('utf-8');
|
||||
const message = JSON.parse(messageString, _serializer.reviver);
|
||||
this.state = 'process message';
|
||||
this.onWorkerMessage(message, err => {
|
||||
if (err) {
|
||||
console.error(`Failed to communicate with worker (process message) ${err}`);
|
||||
return;
|
||||
}
|
||||
|
||||
this.state = 'soon next';
|
||||
setImmediate(() => this.readNextMessage());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onWorkerMessage(message, finalCallback) {
|
||||
const {
|
||||
type,
|
||||
id
|
||||
} = message;
|
||||
|
||||
switch (type) {
|
||||
case 'job':
|
||||
{
|
||||
const {
|
||||
data,
|
||||
error,
|
||||
result
|
||||
} = message;
|
||||
(0, _mapSeries.default)(data, (length, callback) => this.readBuffer(length, callback), (eachErr, buffers) => {
|
||||
const {
|
||||
callback: jobCallback
|
||||
} = this.jobs[id];
|
||||
|
||||
const callback = (err, arg) => {
|
||||
if (jobCallback) {
|
||||
delete this.jobs[id];
|
||||
this.activeJobs -= 1;
|
||||
this.onJobDone();
|
||||
|
||||
if (err) {
|
||||
jobCallback(err instanceof Error ? err : new Error(err), arg);
|
||||
} else {
|
||||
jobCallback(null, arg);
|
||||
}
|
||||
}
|
||||
|
||||
finalCallback();
|
||||
};
|
||||
|
||||
if (eachErr) {
|
||||
callback(eachErr);
|
||||
return;
|
||||
}
|
||||
|
||||
let bufferPosition = 0;
|
||||
|
||||
if (result.result) {
|
||||
result.result = result.result.map(r => {
|
||||
if (r.buffer) {
|
||||
const buffer = buffers[bufferPosition];
|
||||
bufferPosition += 1;
|
||||
|
||||
if (r.string) {
|
||||
return buffer.toString('utf-8');
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return r.data;
|
||||
});
|
||||
}
|
||||
|
||||
if (error) {
|
||||
callback(this.fromErrorObj(error), result);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, result);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case 'loadModule':
|
||||
{
|
||||
const {
|
||||
request,
|
||||
questionId
|
||||
} = message;
|
||||
const {
|
||||
data
|
||||
} = this.jobs[id]; // eslint-disable-next-line no-unused-vars
|
||||
|
||||
data.loadModule(request, (error, source, sourceMap, module) => {
|
||||
this.writeJson({
|
||||
type: 'result',
|
||||
id: questionId,
|
||||
error: error ? {
|
||||
message: error.message,
|
||||
details: error.details,
|
||||
missing: error.missing
|
||||
} : null,
|
||||
result: [source, sourceMap // TODO: Serialize module?
|
||||
// module,
|
||||
]
|
||||
});
|
||||
});
|
||||
finalCallback();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'resolve':
|
||||
{
|
||||
const {
|
||||
context,
|
||||
request,
|
||||
options,
|
||||
questionId
|
||||
} = message;
|
||||
const {
|
||||
data
|
||||
} = this.jobs[id];
|
||||
|
||||
if (options) {
|
||||
data.getResolve(options)(context, request, (error, result) => {
|
||||
this.writeJson({
|
||||
type: 'result',
|
||||
id: questionId,
|
||||
error: error ? {
|
||||
message: error.message,
|
||||
details: error.details,
|
||||
missing: error.missing
|
||||
} : null,
|
||||
result
|
||||
});
|
||||
});
|
||||
} else {
|
||||
data.resolve(context, request, (error, result) => {
|
||||
this.writeJson({
|
||||
type: 'result',
|
||||
id: questionId,
|
||||
error: error ? {
|
||||
message: error.message,
|
||||
details: error.details,
|
||||
missing: error.missing
|
||||
} : null,
|
||||
result
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
finalCallback();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'emitWarning':
|
||||
{
|
||||
const {
|
||||
data
|
||||
} = message;
|
||||
const {
|
||||
data: jobData
|
||||
} = this.jobs[id];
|
||||
jobData.emitWarning(this.fromErrorObj(data));
|
||||
finalCallback();
|
||||
break;
|
||||
}
|
||||
|
||||
case 'emitError':
|
||||
{
|
||||
const {
|
||||
data
|
||||
} = message;
|
||||
const {
|
||||
data: jobData
|
||||
} = this.jobs[id];
|
||||
jobData.emitError(this.fromErrorObj(data));
|
||||
finalCallback();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
console.error(`Unexpected worker message ${type} in WorkerPool.`);
|
||||
finalCallback();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fromErrorObj(arg) {
|
||||
let obj;
|
||||
|
||||
if (typeof arg === 'string') {
|
||||
obj = {
|
||||
message: arg
|
||||
};
|
||||
} else {
|
||||
obj = arg;
|
||||
}
|
||||
|
||||
return new _WorkerError.default(obj, this.id);
|
||||
}
|
||||
|
||||
readBuffer(length, callback) {
|
||||
(0, _readBuffer.default)(this.readPipe, length, callback);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
if (!this.disposed) {
|
||||
this.disposed = true;
|
||||
this.ignoreStdOutAndErrFromWorker(this.worker.stdout, this.worker.stderr);
|
||||
this.writeEnd();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class WorkerPool {
|
||||
constructor(options) {
|
||||
this.options = options || {};
|
||||
this.numberOfWorkers = options.numberOfWorkers;
|
||||
this.poolTimeout = options.poolTimeout;
|
||||
this.workerNodeArgs = options.workerNodeArgs;
|
||||
this.workerParallelJobs = options.workerParallelJobs;
|
||||
this.workers = new Set();
|
||||
this.activeJobs = 0;
|
||||
this.timeout = null;
|
||||
this.poolQueue = (0, _queue.default)(this.distributeJob.bind(this), options.poolParallelJobs);
|
||||
this.terminated = false;
|
||||
this.setupLifeCycle();
|
||||
}
|
||||
|
||||
isAbleToRun() {
|
||||
return !this.terminated;
|
||||
}
|
||||
|
||||
terminate() {
|
||||
if (this.terminated) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.terminated = true;
|
||||
this.poolQueue.kill();
|
||||
this.disposeWorkers(true);
|
||||
}
|
||||
|
||||
setupLifeCycle() {
|
||||
process.on('exit', () => {
|
||||
this.terminate();
|
||||
});
|
||||
}
|
||||
|
||||
run(data, callback) {
|
||||
if (this.timeout) {
|
||||
clearTimeout(this.timeout);
|
||||
this.timeout = null;
|
||||
}
|
||||
|
||||
this.activeJobs += 1;
|
||||
this.poolQueue.push(data, callback);
|
||||
}
|
||||
|
||||
distributeJob(data, callback) {
|
||||
// use worker with the fewest jobs
|
||||
let bestWorker;
|
||||
|
||||
for (const worker of this.workers) {
|
||||
if (!bestWorker || worker.activeJobs < bestWorker.activeJobs) {
|
||||
bestWorker = worker;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestWorker && (bestWorker.activeJobs === 0 || this.workers.size >= this.numberOfWorkers)) {
|
||||
bestWorker.run(data, callback);
|
||||
return;
|
||||
}
|
||||
|
||||
const newWorker = this.createWorker();
|
||||
newWorker.run(data, callback);
|
||||
}
|
||||
|
||||
createWorker() {
|
||||
// spin up a new worker
|
||||
const newWorker = new PoolWorker({
|
||||
nodeArgs: this.workerNodeArgs,
|
||||
parallelJobs: this.workerParallelJobs
|
||||
}, () => this.onJobDone());
|
||||
this.workers.add(newWorker);
|
||||
return newWorker;
|
||||
}
|
||||
|
||||
warmup(requires) {
|
||||
while (this.workers.size < this.numberOfWorkers) {
|
||||
this.createWorker().warmup(requires);
|
||||
}
|
||||
}
|
||||
|
||||
onJobDone() {
|
||||
this.activeJobs -= 1;
|
||||
|
||||
if (this.activeJobs === 0 && isFinite(this.poolTimeout)) {
|
||||
this.timeout = setTimeout(() => this.disposeWorkers(), this.poolTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
disposeWorkers(fromTerminate) {
|
||||
if (!this.options.poolRespawn && !fromTerminate) {
|
||||
this.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.activeJobs === 0 || fromTerminate) {
|
||||
for (const worker of this.workers) {
|
||||
worker.dispose();
|
||||
}
|
||||
|
||||
this.workers.clear();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
exports.default = WorkerPool;
|
3
app_vue/node_modules/thread-loader/dist/cjs.js
generated
vendored
Normal file
3
app_vue/node_modules/thread-loader/dist/cjs.js
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = require('./index');
|
66
app_vue/node_modules/thread-loader/dist/index.js
generated
vendored
Normal file
66
app_vue/node_modules/thread-loader/dist/index.js
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.pitch = pitch;
|
||||
exports.warmup = warmup;
|
||||
|
||||
var _loaderUtils = _interopRequireDefault(require("loader-utils"));
|
||||
|
||||
var _workerPools = require("./workerPools");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function pitch() {
|
||||
const options = _loaderUtils.default.getOptions(this);
|
||||
|
||||
const workerPool = (0, _workerPools.getPool)(options);
|
||||
|
||||
if (!workerPool.isAbleToRun()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const callback = this.async();
|
||||
workerPool.run({
|
||||
loaders: this.loaders.slice(this.loaderIndex + 1).map(l => {
|
||||
return {
|
||||
loader: l.path,
|
||||
options: l.options,
|
||||
ident: l.ident
|
||||
};
|
||||
}),
|
||||
resource: this.resourcePath + (this.resourceQuery || ''),
|
||||
sourceMap: this.sourceMap,
|
||||
emitError: this.emitError,
|
||||
emitWarning: this.emitWarning,
|
||||
loadModule: this.loadModule,
|
||||
resolve: this.resolve,
|
||||
getResolve: this.getResolve,
|
||||
target: this.target,
|
||||
minimize: this.minimize,
|
||||
resourceQuery: this.resourceQuery,
|
||||
optionsContext: this.rootContext || this.options.context,
|
||||
rootContext: this.rootContext
|
||||
}, (err, r) => {
|
||||
if (r) {
|
||||
r.fileDependencies.forEach(d => this.addDependency(d));
|
||||
r.contextDependencies.forEach(d => this.addContextDependency(d));
|
||||
r.missingDependencies.forEach(d => this.addMissingDependency(d));
|
||||
r.buildDependencies.forEach(d => // Compatibility with webpack v4
|
||||
this.addBuildDependency ? this.addBuildDependency(d) : this.addDependency(d));
|
||||
}
|
||||
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, ...r.result);
|
||||
});
|
||||
}
|
||||
|
||||
function warmup(options, requires) {
|
||||
const workerPool = (0, _workerPools.getPool)(options);
|
||||
workerPool.warmup(requires);
|
||||
} // eslint-disable-line import/prefer-default-export
|
49
app_vue/node_modules/thread-loader/dist/readBuffer.js
generated
vendored
Normal file
49
app_vue/node_modules/thread-loader/dist/readBuffer.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = readBuffer;
|
||||
|
||||
function readBuffer(pipe, length, callback) {
|
||||
if (length === 0) {
|
||||
callback(null, Buffer.alloc(0));
|
||||
return;
|
||||
}
|
||||
|
||||
let remainingLength = length;
|
||||
const buffers = [];
|
||||
|
||||
const readChunk = () => {
|
||||
const onChunk = arg => {
|
||||
let chunk = arg;
|
||||
let overflow;
|
||||
|
||||
if (chunk.length > remainingLength) {
|
||||
overflow = chunk.slice(remainingLength);
|
||||
chunk = chunk.slice(0, remainingLength);
|
||||
remainingLength = 0;
|
||||
} else {
|
||||
remainingLength -= chunk.length;
|
||||
}
|
||||
|
||||
buffers.push(chunk);
|
||||
|
||||
if (remainingLength === 0) {
|
||||
pipe.removeListener('data', onChunk);
|
||||
pipe.pause();
|
||||
|
||||
if (overflow) {
|
||||
pipe.unshift(overflow);
|
||||
}
|
||||
|
||||
callback(null, Buffer.concat(buffers, length));
|
||||
}
|
||||
};
|
||||
|
||||
pipe.on('data', onChunk);
|
||||
pipe.resume();
|
||||
};
|
||||
|
||||
readChunk();
|
||||
}
|
30
app_vue/node_modules/thread-loader/dist/serializer.js
generated
vendored
Normal file
30
app_vue/node_modules/thread-loader/dist/serializer.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.replacer = replacer;
|
||||
exports.reviver = reviver;
|
||||
|
||||
function replacer(_key, value) {
|
||||
if (value instanceof RegExp) {
|
||||
return {
|
||||
__serialized_type: 'RegExp',
|
||||
source: value.source,
|
||||
flags: value.flags
|
||||
};
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function reviver(_key, value) {
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
// eslint-disable-next-line no-underscore-dangle
|
||||
if (value.__serialized_type === 'RegExp') {
|
||||
return new RegExp(value.source, value.flags);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
419
app_vue/node_modules/thread-loader/dist/worker.js
generated
vendored
Normal file
419
app_vue/node_modules/thread-loader/dist/worker.js
generated
vendored
Normal file
@ -0,0 +1,419 @@
|
||||
"use strict";
|
||||
|
||||
var _fs = _interopRequireDefault(require("fs"));
|
||||
|
||||
var _module = _interopRequireDefault(require("module"));
|
||||
|
||||
var _querystring = _interopRequireDefault(require("querystring"));
|
||||
|
||||
var _loaderRunner = _interopRequireDefault(require("loader-runner"));
|
||||
|
||||
var _queue = _interopRequireDefault(require("neo-async/queue"));
|
||||
|
||||
var _jsonParseBetterErrors = _interopRequireDefault(require("json-parse-better-errors"));
|
||||
|
||||
var _schemaUtils = require("schema-utils");
|
||||
|
||||
var _readBuffer = _interopRequireDefault(require("./readBuffer"));
|
||||
|
||||
var _serializer = require("./serializer");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
/* eslint-disable no-console */
|
||||
const writePipe = _fs.default.createWriteStream(null, {
|
||||
fd: 3
|
||||
});
|
||||
|
||||
const readPipe = _fs.default.createReadStream(null, {
|
||||
fd: 4
|
||||
});
|
||||
|
||||
writePipe.on('finish', onTerminateWrite);
|
||||
readPipe.on('end', onTerminateRead);
|
||||
writePipe.on('close', onTerminateWrite);
|
||||
readPipe.on('close', onTerminateRead);
|
||||
readPipe.on('error', onError);
|
||||
writePipe.on('error', onError);
|
||||
const PARALLEL_JOBS = +process.argv[2] || 20;
|
||||
let terminated = false;
|
||||
let nextQuestionId = 0;
|
||||
const callbackMap = Object.create(null);
|
||||
|
||||
function onError(error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
function onTerminateRead() {
|
||||
terminateRead();
|
||||
}
|
||||
|
||||
function onTerminateWrite() {
|
||||
terminateWrite();
|
||||
}
|
||||
|
||||
function writePipeWrite(...args) {
|
||||
if (!terminated) {
|
||||
writePipe.write(...args);
|
||||
}
|
||||
}
|
||||
|
||||
function writePipeCork() {
|
||||
if (!terminated) {
|
||||
writePipe.cork();
|
||||
}
|
||||
}
|
||||
|
||||
function writePipeUncork() {
|
||||
if (!terminated) {
|
||||
writePipe.uncork();
|
||||
}
|
||||
}
|
||||
|
||||
function terminateRead() {
|
||||
terminated = true;
|
||||
readPipe.removeAllListeners();
|
||||
}
|
||||
|
||||
function terminateWrite() {
|
||||
terminated = true;
|
||||
writePipe.removeAllListeners();
|
||||
}
|
||||
|
||||
function terminate() {
|
||||
terminateRead();
|
||||
terminateWrite();
|
||||
}
|
||||
|
||||
function toErrorObj(err) {
|
||||
return {
|
||||
message: err.message,
|
||||
details: err.details,
|
||||
stack: err.stack,
|
||||
hideStack: err.hideStack
|
||||
};
|
||||
}
|
||||
|
||||
function toNativeError(obj) {
|
||||
if (!obj) return null;
|
||||
const err = new Error(obj.message);
|
||||
err.details = obj.details;
|
||||
err.missing = obj.missing;
|
||||
return err;
|
||||
}
|
||||
|
||||
function writeJson(data) {
|
||||
writePipeCork();
|
||||
process.nextTick(() => {
|
||||
writePipeUncork();
|
||||
});
|
||||
const lengthBuffer = Buffer.alloc(4);
|
||||
const messageBuffer = Buffer.from(JSON.stringify(data, _serializer.replacer), 'utf-8');
|
||||
lengthBuffer.writeInt32BE(messageBuffer.length, 0);
|
||||
writePipeWrite(lengthBuffer);
|
||||
writePipeWrite(messageBuffer);
|
||||
}
|
||||
|
||||
const queue = (0, _queue.default)(({
|
||||
id,
|
||||
data
|
||||
}, taskCallback) => {
|
||||
try {
|
||||
const resolveWithOptions = (context, request, callback, options) => {
|
||||
callbackMap[nextQuestionId] = callback;
|
||||
writeJson({
|
||||
type: 'resolve',
|
||||
id,
|
||||
questionId: nextQuestionId,
|
||||
context,
|
||||
request,
|
||||
options
|
||||
});
|
||||
nextQuestionId += 1;
|
||||
};
|
||||
|
||||
const buildDependencies = [];
|
||||
|
||||
_loaderRunner.default.runLoaders({
|
||||
loaders: data.loaders,
|
||||
resource: data.resource,
|
||||
readResource: _fs.default.readFile.bind(_fs.default),
|
||||
context: {
|
||||
version: 2,
|
||||
fs: _fs.default,
|
||||
loadModule: (request, callback) => {
|
||||
callbackMap[nextQuestionId] = (error, result) => callback(error, ...result);
|
||||
|
||||
writeJson({
|
||||
type: 'loadModule',
|
||||
id,
|
||||
questionId: nextQuestionId,
|
||||
request
|
||||
});
|
||||
nextQuestionId += 1;
|
||||
},
|
||||
resolve: (context, request, callback) => {
|
||||
resolveWithOptions(context, request, callback);
|
||||
},
|
||||
// eslint-disable-next-line consistent-return
|
||||
getResolve: options => (context, request, callback) => {
|
||||
if (callback) {
|
||||
resolveWithOptions(context, request, callback, options);
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolveWithOptions(context, request, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
}, options);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
// 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 = (0, _jsonParseBetterErrors.default)(options);
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot parse string options: ${e.message}`);
|
||||
}
|
||||
} else {
|
||||
options = _querystring.default.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;
|
||||
}
|
||||
|
||||
(0, _schemaUtils.validate)(schema, options, {
|
||||
name,
|
||||
baseDataPath
|
||||
});
|
||||
}
|
||||
|
||||
return options;
|
||||
},
|
||||
|
||||
emitWarning: warning => {
|
||||
writeJson({
|
||||
type: 'emitWarning',
|
||||
id,
|
||||
data: toErrorObj(warning)
|
||||
});
|
||||
},
|
||||
emitError: error => {
|
||||
writeJson({
|
||||
type: 'emitError',
|
||||
id,
|
||||
data: toErrorObj(error)
|
||||
});
|
||||
},
|
||||
exec: (code, filename) => {
|
||||
const module = new _module.default(filename, void 0);
|
||||
module.paths = _module.default._nodeModulePaths((void 0).context); // eslint-disable-line no-underscore-dangle
|
||||
|
||||
module.filename = filename;
|
||||
|
||||
module._compile(code, filename); // eslint-disable-line no-underscore-dangle
|
||||
|
||||
|
||||
return module.exports;
|
||||
},
|
||||
addBuildDependency: filename => {
|
||||
buildDependencies.push(filename);
|
||||
},
|
||||
options: {
|
||||
context: data.optionsContext
|
||||
},
|
||||
webpack: true,
|
||||
'thread-loader': true,
|
||||
sourceMap: data.sourceMap,
|
||||
target: data.target,
|
||||
minimize: data.minimize,
|
||||
resourceQuery: data.resourceQuery,
|
||||
rootContext: data.rootContext
|
||||
}
|
||||
}, (err, lrResult) => {
|
||||
const {
|
||||
result,
|
||||
cacheable,
|
||||
fileDependencies,
|
||||
contextDependencies,
|
||||
missingDependencies
|
||||
} = lrResult;
|
||||
const buffersToSend = [];
|
||||
const convertedResult = Array.isArray(result) && result.map(item => {
|
||||
const isBuffer = Buffer.isBuffer(item);
|
||||
|
||||
if (isBuffer) {
|
||||
buffersToSend.push(item);
|
||||
return {
|
||||
buffer: true
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof item === 'string') {
|
||||
const stringBuffer = Buffer.from(item, 'utf-8');
|
||||
buffersToSend.push(stringBuffer);
|
||||
return {
|
||||
buffer: true,
|
||||
string: true
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
data: item
|
||||
};
|
||||
});
|
||||
writeJson({
|
||||
type: 'job',
|
||||
id,
|
||||
error: err && toErrorObj(err),
|
||||
result: {
|
||||
result: convertedResult,
|
||||
cacheable,
|
||||
fileDependencies,
|
||||
contextDependencies,
|
||||
missingDependencies,
|
||||
buildDependencies
|
||||
},
|
||||
data: buffersToSend.map(buffer => buffer.length)
|
||||
});
|
||||
buffersToSend.forEach(buffer => {
|
||||
writePipeWrite(buffer);
|
||||
});
|
||||
setImmediate(taskCallback);
|
||||
});
|
||||
} catch (e) {
|
||||
writeJson({
|
||||
type: 'job',
|
||||
id,
|
||||
error: toErrorObj(e)
|
||||
});
|
||||
taskCallback();
|
||||
}
|
||||
}, PARALLEL_JOBS);
|
||||
|
||||
function dispose() {
|
||||
terminate();
|
||||
queue.kill();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function onMessage(message) {
|
||||
try {
|
||||
const {
|
||||
type,
|
||||
id
|
||||
} = message;
|
||||
|
||||
switch (type) {
|
||||
case 'job':
|
||||
{
|
||||
queue.push(message);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'result':
|
||||
{
|
||||
const {
|
||||
error,
|
||||
result
|
||||
} = message;
|
||||
const callback = callbackMap[id];
|
||||
|
||||
if (callback) {
|
||||
const nativeError = toNativeError(error);
|
||||
callback(nativeError, result);
|
||||
} else {
|
||||
console.error(`Worker got unexpected result id ${id}`);
|
||||
}
|
||||
|
||||
delete callbackMap[id];
|
||||
break;
|
||||
}
|
||||
|
||||
case 'warmup':
|
||||
{
|
||||
const {
|
||||
requires
|
||||
} = message; // load modules into process
|
||||
|
||||
requires.forEach(r => require(r)); // eslint-disable-line import/no-dynamic-require, global-require
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
console.error(`Worker got unexpected job type ${type}`);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Error in worker ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
function readNextMessage() {
|
||||
(0, _readBuffer.default)(readPipe, 4, (lengthReadError, lengthBuffer) => {
|
||||
if (lengthReadError) {
|
||||
console.error(`Failed to communicate with main process (read length) ${lengthReadError}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const length = lengthBuffer.length && lengthBuffer.readInt32BE(0);
|
||||
|
||||
if (length === 0) {
|
||||
// worker should dispose and exit
|
||||
dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
(0, _readBuffer.default)(readPipe, length, (messageError, messageBuffer) => {
|
||||
if (terminated) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (messageError) {
|
||||
console.error(`Failed to communicate with main process (read message) ${messageError}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const messageString = messageBuffer.toString('utf-8');
|
||||
const message = JSON.parse(messageString, _serializer.reviver);
|
||||
onMessage(message);
|
||||
setImmediate(() => readNextMessage());
|
||||
});
|
||||
});
|
||||
} // start reading messages from main process
|
||||
|
||||
|
||||
readNextMessage();
|
39
app_vue/node_modules/thread-loader/dist/workerPools.js
generated
vendored
Normal file
39
app_vue/node_modules/thread-loader/dist/workerPools.js
generated
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.getPool = getPool;
|
||||
|
||||
var _os = _interopRequireDefault(require("os"));
|
||||
|
||||
var _WorkerPool = _interopRequireDefault(require("./WorkerPool"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
const workerPools = Object.create(null);
|
||||
|
||||
function calculateNumberOfWorkers() {
|
||||
// There are situations when this call will return undefined so
|
||||
// we are fallback here to 1.
|
||||
// More info on: https://github.com/nodejs/node/issues/19022
|
||||
const cpus = _os.default.cpus() || {
|
||||
length: 1
|
||||
};
|
||||
return Math.max(1, cpus.length - 1);
|
||||
}
|
||||
|
||||
function getPool(options) {
|
||||
const workerPoolOptions = {
|
||||
name: options.name || '',
|
||||
numberOfWorkers: options.workers || calculateNumberOfWorkers(),
|
||||
workerNodeArgs: options.workerNodeArgs,
|
||||
workerParallelJobs: options.workerParallelJobs || 20,
|
||||
poolTimeout: options.poolTimeout || 500,
|
||||
poolParallelJobs: options.poolParallelJobs || 200,
|
||||
poolRespawn: options.poolRespawn || false
|
||||
};
|
||||
const tpKey = JSON.stringify(workerPoolOptions);
|
||||
workerPools[tpKey] = workerPools[tpKey] || new _WorkerPool.default(workerPoolOptions);
|
||||
return workerPools[tpKey];
|
||||
} // eslint-disable-line import/prefer-default-export
|
Reference in New Issue
Block a user