0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/common/require-as.js

29 lines
674 B
JavaScript
Raw Normal View History

/* eslint-disable node-core/require-common-first, node-core/required-modules */
'use strict';
if (module.parent) {
const { spawnSync } = require('child_process');
function runModuleAs(filename, flags, spawnOptions, role) {
return spawnSync(process.execPath,
[...flags, __filename, role, filename], spawnOptions);
}
module.exports = runModuleAs;
return;
}
const { Worker, isMainThread, workerData } = require('worker_threads');
if (isMainThread) {
if (process.argv[2] === 'worker') {
new Worker(__filename, {
workerData: process.argv[3]
});
return;
}
require(process.argv[3]);
} else {
require(workerData);
}