From 5405a89e5f912bb843f436d976cf77279d9a32b2 Mon Sep 17 00:00:00 2001 From: Stephane Rigaud Date: Tue, 24 Sep 2024 14:22:38 +0300 Subject: [PATCH] delete dist --- dist/206.index.cjs.js | 14 -- dist/file.js | 12 -- dist/index.cjs | 468 ---------------------------------------- dist/worker-pipeline.js | 38 ---- dist/worker.js | 54 ----- dist/worker1.js | 171 --------------- dist/worker2.js | 174 --------------- 7 files changed, 931 deletions(-) delete mode 100644 dist/206.index.cjs.js delete mode 100644 dist/file.js delete mode 100644 dist/index.cjs delete mode 100644 dist/worker-pipeline.js delete mode 100644 dist/worker.js delete mode 100644 dist/worker1.js delete mode 100644 dist/worker2.js diff --git a/dist/206.index.cjs.js b/dist/206.index.cjs.js deleted file mode 100644 index 1cd225c..0000000 --- a/dist/206.index.cjs.js +++ /dev/null @@ -1,14 +0,0 @@ -exports.id = 206; -exports.ids = [206]; -exports.modules = { - -/***/ 9206: -/***/ ((module) => { - -module.exports = eval("require")("smee-client"); - - -/***/ }) - -}; -; \ No newline at end of file diff --git a/dist/file.js b/dist/file.js deleted file mode 100644 index ed9d86f..0000000 --- a/dist/file.js +++ /dev/null @@ -1,12 +0,0 @@ -'use strict' - -const pino = require('./pino') -const { once } = require('events') - -module.exports = async function (opts = {}) { - const destOpts = Object.assign({}, opts, { dest: opts.destination || 1, sync: false }) - delete destOpts.destination - const destination = pino.destination(destOpts) - await once(destination, 'ready') - return destination -} diff --git a/dist/index.cjs b/dist/index.cjs deleted file mode 100644 index 5e184ea..0000000 --- a/dist/index.cjs +++ /dev/null @@ -1,468 +0,0 @@ -/******/ (() => { // webpackBootstrap -/******/ var __webpack_modules__ = ({ - -/***/ 944: -/***/ ((module) => { - -module.exports = eval("require")("@probot/adapter-github-actions"); - - -/***/ }), - -/***/ 317: -/***/ ((module) => { - -"use strict"; -module.exports = require("child_process"); - -/***/ }), - -/***/ 928: -/***/ ((module) => { - -"use strict"; -module.exports = require("path"); - -/***/ }), - -/***/ 23: -/***/ ((module) => { - -"use strict"; -module.exports = require("util"); - -/***/ }), - -/***/ 899: -/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { - -const path = __nccwpck_require__(928); -const { promisify } = __nccwpck_require__(23); -const { exec } = __nccwpck_require__(317); -const execPromise = promisify(exec); - -/** - * Helper function to update the code of the bindings of a repository - * - * @param {*} context - * @param {*} owner - * @param {*} repo - * @param {*} branch_name - * @param {*} tag - * @param {*} scriptName - * @returns {Promise} - */ -async function updateBindings(context, owner, repo, branch_name, tag, scriptName) { - context.log.info(`Updating bindings of ${owner}-${repo} to ${tag} using ${scriptName} on branch ${branch_name}`); - const script_target_repo = scriptName.split('_')[0]; - - const { data: gencle_data } = await context.octokit.repos.get({ - owner: 'clEsperanto', - repo: 'gencle', - }); - const gencle_dir = path.join('/tmp', 'gencle'); - await execPromise(`git clone ${gencle_data.clone_url} ${gencle_dir}`); - - const { data: repo_data } = await context.octokit.repos.get({ - owner, - repo, - }); - const repo_dir = path.join('/tmp', repo); - await execPromise(`git clone ${repo_data.clone_url} ${repo_dir}`); - - console.log(`gencle_dir: ${gencle_dir}`); - console.log(`repo_dir: ${repo_dir}`); - - await execPromise(`cd ${repo_dir} && git fetch && git checkout ${branch_name}`); - const { stdout: py_stdout } = await execPromise(`python ${gencle_dir}/update_scripts/${scriptName} ${repo_dir} ${tag}`); - console.log(py_stdout); - - const { stdout: diff } = await execPromise(`cd ${repo_dir} && git status --porcelain`); - if (diff) { - console.log('There are changes:', diff); - await execPromise(` - git config --global user.name "github-actions[bot]" && \ - git config --global user.email "github-actions[bot]@users.noreply.github.com"`); - await execPromise(` - cd ${repo_dir} && \ - git add . && \ - git commit -m "Update ${script_target_repo} to ${tag}"`); - await execPromise(` - git push https://github-actions[bot]:${process.env.GITHUB_TOKEN}@github.com/${owner}/${repo}.git ${branch_name} - `); - } else { - console.log("No changes made by the update script"); - } - - // Clean up - await execPromise(`rm -rf ${gencle_dir}`); - await execPromise(`rm -rf ${repo_dir}`); -} - -/** - * Helper function to find an issue by title - * - * @param {*} context - * @param {*} owner - * @param {*} repo - * @param {*} issue_title - * @param {*} issue_labels - * @returns {Object|undefined} The issue object if found, otherwise undefined - */ -async function findIssueByTitle(context, owner, repo, issue_title, issue_labels) { - try { - const { data: issues } = await context.octokit.issues.listForRepo({ - owner: owner, - repo: repo, - state: "all", - labels: issue_labels.join(","), - }); - return issues.find((issue) => issue.title === issue_title); - } - catch (error) { - console.error("Error finding issue:", error); - throw error; - } -} - -/** -* Function to create an issue in the given repository if it doesn't already exist -* Will update the issue if it is closed and has the same title -* Will do nothing if the issue is open and has the same title -* Will return the issue -* -* @param {*} context -* @param {*} owner -* @param {*} repo -* @param {*} issue_title -* @param {*} issue_body -* @param {*} issue_labels -* @returns {Object} The issue object that was created or found -*/ -async function createIssue(context, owner, repo, issue_title, issue_body, issue_labels) { - try { - let _issue = await findIssueByTitle(context, owner, repo, issue_title, issue_labels); - if (_issue === undefined) { - _issue = (await context.octokit.issues.create({ - owner: owner, - repo: repo, - title: issue_title, - body: issue_body, - labels: issue_labels, - })).data; - } else if (_issue.state === "closed") { - await context.octokit.issues.update({ - owner: owner, - repo: repo, - issue_number: _issue.number, - state: "open", - }); - await context.octokit.issues.createComment({ - owner: owner, - repo: repo, - issue_number: _issue.number, - body: issue_body, - }); - } - if (_issue === undefined) { - throw new Error("We are about to return an undefined issue"); - } - return _issue; - } catch (error) { - console.error("Error creating or updating issue:", error); - throw error; - } -} - -/** -* Helper function to find a branch by name -* -* @param {*} context -* @param {*} owner -* @param {*} repo -* @param {*} branch_name -* @returns {Object|undefined} The branch object if found, otherwise undefined -*/ -async function findBranchByName(context, owner, repo, branch_name) { - try { - const { data: branches } = await context.octokit.repos.listBranches({ - owner: owner, - repo: repo, - }); - return branches.find((branch) => branch.name === branch_name); - } catch (error) { - console.error("Error finding branch:", error); - throw error; - } -} - -/** -* Function to create a branch in the given repository if it doesn't already exist -* The branch will be created from the main branch -* Will return the branch -* -* @param {*} context -* @param {*} owner -* @param {*} repo -* @param {*} branch_name -* @returns {Object} The branch object that was created or found -*/ -async function createBranch(context, owner, repo, branch_name) { - try { - let _branch = await findBranchByName(context, owner, repo, branch_name); - if (_branch === undefined) { - const { data: main_branch } = await context.octokit.repos.getBranch({ - owner: owner, - repo: repo, - branch: "main", - }); - _branch = (await context.octokit.git.createRef({ - owner: owner, - repo: repo, - ref: `refs/heads/${branch_name}`, - sha: main_branch.commit.sha, - })).data; - _branch.name = branch_name; - } - if (_branch === undefined) { - throw new Error("We are about to return an undefined branch"); - } - return _branch; - } catch (error) { - console.error("Error creating branch:", error); - throw error; - } -} - -/** -* Helper function to find a pull request by branch name and title -* -* @param {*} context -* @param {*} owner -* @param {*} repo -* @param {*} branch_name -* @param {*} pr_title -* @returns {Object|undefined} The pull request object if found, otherwise undefined -*/ -async function findPullRequest(context, owner, repo, branch_name, pr_title) { - try { - const { data: pull_requests } = await context.octokit.pulls.list({ - owner: owner, - repo: repo, - state: "open", - }); - return pull_requests.find((pr) => pr.head.ref === branch_name && pr.title === pr_title); - } catch (error) { - console.error("Error finding pull request:", error); - throw error; - } -} - -/** -* Function to create a pull request in the given repository if it doesn't already exist -* -* @param {*} context -* @param {*} owner -* @param {*} repo -* @param {*} branch_name -* @param {*} pr_title -* @param {*} pr_body -* @returns {Object} The pull request object that was created or found -*/ -async function createPullRequest(context, owner, repo, branch_name, pr_title, pr_body) { - try { - let _pr = await findPullRequest(context, owner, repo, branch_name, pr_title); - if (_pr === undefined) { - _pr = (await context.octokit.pulls.create({ - owner: owner, - repo: repo, - title: pr_title, - head: branch_name, - base: "main", - body: pr_body, - })).data; - } - if (_pr === undefined) { - throw new Error("We are about to return an undefined pull request"); - } - return _pr; - } catch (error) { - console.error("Error creating pull request:", error); - throw error; - } -} - -/** - * Helper function to handle a binding update PR - * - * @param {*} context - * @param {*} repository - * @param {*} releaseTag - * @param {*} scriptName - */ -async function handleBindingsUpdate(context, repository, releaseTag, scriptName) { - const title = "Update to CLIc@" + releaseTag; - const issue_body = ` -## Release Update: ${releaseTag} - -A new release of [CLIc](https://github.com/clEsperanto/CLIc) is available. - -### Info: -**Release Tag:** ${releaseTag} -**Release Notes:** [Release Notes](https://github.com/clEsperanto/CLIc/releases/tag/${releaseTag}) - -Please review the changes and update the code bindings accordingly. -Cheers! :robot: -`; - - const issue = await createIssue(context, repository.owner.login, repository.name, title, issue_body, ["auto-update"]); - console.log(`Issue created or updated ${issue.number}: ${issue.html_url}`); - - const branch = await createBranch(context, repository.owner.login, repository.name, "update-clic-" + releaseTag); - console.log(`Branch created or updated ${branch.name}:`, branch); - - await updateBindings(context, repository.owner.login, repository.name, branch.name, releaseTag, scriptName); - context.log.info(`Bindings of ${repository.name} updated for CLIc release: ${releaseTag}`); - - const pr_body = ` -## Release Update: ${releaseTag} - -A new release of [CLIc](https://github.com/clEsperanto/CLIc) is available. - -### Info: -**Release Tag:** ${releaseTag} -**Release Notes:** [Release Notes](https://github.com/clEsperanto/CLIc/releases/tag/${releaseTag}) - -Please review the changes and update the code bindings accordingly. -Cheers! :robot: - -closes #${issue.number} - `; - const pr = await createPullRequest(context, repository.owner.login, repository.name, branch.name, title, pr_body); - context.log.info(`Pull Request created: ${pr.number}: ${pr.html_url}`); -} - -/** - * This is the main entrypoint to your Probot app - * @param {import('probot').Probot} app - */ -module.exports = (app) => { - app.log.info("cle-RoBoTo is loaded!"); - - // Removed for now because it's not needed - // when an issue is opened, greet the author - // app.on("issues.opened", async (context) => { - // const user = context.payload.issue.user.login; - // const issueComment = context.issue({ - // body: "Hello @" + user + "! Thanks for opening this issue. We will get back to you asap.", - // }); - - // return context.octokit.issues.createComment(issueComment); - // }); - - // dispatch event from CLIc release workflow - app.on("repository_dispatch", async (context) => { - const { action, repository, client_payload } = context.payload; - - // handle the clic_update event dispatched by the CLIc release workflow - if (action === "clic_update") { - context.log.info(`repository_dispatch action: ${action}, release_tag: ${releaseTag} for ${repository.name}`); - - const releaseTag = client_payload.release_tag; - const scriptMapping = { - "pyclesperanto": "pyclesperanto_auto_update.py", - "clesperantoj": "clesperantoj_auto_update.py" - }; - const scriptName = scriptMapping[repository.name]; - if (scriptName) { - await handleBindingsUpdate(context, repository, releaseTag, scriptName); - } else { - context.log.info(`repository_dispatch action: ${action}, release_tag: ${releaseTag} not handled for ${repository.name}`); - } - } - }); - - // dispatch event from manual workflow behing triggered - // must contain a release_tag as input (can be a branch name) - app.on("workflow_dispatch", async (context) => { - const { repository, inputs } = context.payload; - const { release_tag } = inputs; - - context.log.info(`Workflow dispatch event for repository: ${repository.name} with release_tag: ${release_tag}`); - const scriptMapping = { - "pyclesperanto": "pyclesperanto_auto_update.py", - "clesperantoj": "clesperantoj_auto_update.py" - }; - const scriptName = scriptMapping[repository.name]; - if (scriptName) { - console.log('Updating bindings for:', scriptName); - await handleBindingsUpdate(context, repository, release_tag, scriptName); - } else { - console.log('Updating bindings for all'); - await handleBindingsUpdate(context, repository, release_tag, "pyclesperanto_auto_update.py"); - await handleBindingsUpdate(context, repository, release_tag, "clesperantoj_auto_update.py"); - } - - }); - - - // For more information on building apps: - // https://probot.github.io/docs/ - - // To get your app running against GitHub, see: - // https://probot.github.io/docs/development/ -}; - - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; -/******/ -/******/ // The require function -/******/ function __nccwpck_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ var threw = true; -/******/ try { -/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); -/******/ threw = false; -/******/ } finally { -/******/ if(threw) delete __webpack_module_cache__[moduleId]; -/******/ } -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ -/******/ /* webpack/runtime/compat */ -/******/ -/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; -/******/ -/************************************************************************/ -var __webpack_exports__ = {}; -// index.js -const { run } = __nccwpck_require__(944); -const app = __nccwpck_require__(899); - -run(app).catch((error) => { - console.error(error); - process.exit(1); -}); -module.exports = __webpack_exports__; -/******/ })() -; \ No newline at end of file diff --git a/dist/worker-pipeline.js b/dist/worker-pipeline.js deleted file mode 100644 index 76cb3b8..0000000 --- a/dist/worker-pipeline.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict' - -const EE = require('events') -const loadTransportStreamBuilder = require('./transport-stream') -const { pipeline, PassThrough } = require('stream') - -// This file is not checked by the code coverage tool, -// as it is not reliable. - -/* istanbul ignore file */ - -module.exports = async function ({ targets }) { - const streams = await Promise.all(targets.map(async (t) => { - const fn = await loadTransportStreamBuilder(t.target) - const stream = await fn(t.options) - return stream - })) - const ee = new EE() - - const stream = new PassThrough({ - autoDestroy: true, - destroy (_, cb) { - ee.on('error', cb) - ee.on('closed', cb) - } - }) - - pipeline(stream, ...streams, function (err) { - if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') { - ee.emit('error', err) - return - } - - ee.emit('closed') - }) - - return stream -} diff --git a/dist/worker.js b/dist/worker.js deleted file mode 100644 index c20c19a..0000000 --- a/dist/worker.js +++ /dev/null @@ -1,54 +0,0 @@ -'use strict' - -const pino = require('../pino.js') -const build = require('pino-abstract-transport') -const loadTransportStreamBuilder = require('./transport-stream') - -// This file is not checked by the code coverage tool, -// as it is not reliable. - -/* istanbul ignore file */ - -module.exports = async function ({ targets, levels, dedupe }) { - targets = await Promise.all(targets.map(async (t) => { - const fn = await loadTransportStreamBuilder(t.target) - const stream = await fn(t.options) - return { - level: t.level, - stream - } - })) - return build(process, { - parse: 'lines', - metadata: true, - close (err, cb) { - let expected = 0 - for (const transport of targets) { - expected++ - transport.stream.on('close', closeCb) - transport.stream.end() - } - - function closeCb () { - if (--expected === 0) { - cb(err) - } - } - } - }) - - function process (stream) { - const multi = pino.multistream(targets, { levels, dedupe }) - // TODO manage backpressure - stream.on('data', function (chunk) { - const { lastTime, lastMsg, lastObj, lastLevel } = this - multi.lastLevel = lastLevel - multi.lastTime = lastTime - multi.lastMsg = lastMsg - multi.lastObj = lastObj - - // TODO handle backpressure - multi.write(chunk + '\n') - }) - } -} diff --git a/dist/worker1.js b/dist/worker1.js deleted file mode 100644 index 198a957..0000000 --- a/dist/worker1.js +++ /dev/null @@ -1,171 +0,0 @@ -'use strict' - -const { realImport, realRequire } = require('real-require') -const { workerData, parentPort } = require('worker_threads') -const { WRITE_INDEX, READ_INDEX } = require('./indexes') -const { waitDiff } = require('./wait') - -const { - dataBuf, - filename, - stateBuf -} = workerData - -let destination - -const state = new Int32Array(stateBuf) -const data = Buffer.from(dataBuf) - -async function start () { - let worker - try { - if (filename.endsWith('.ts') || filename.endsWith('.cts')) { - // TODO: add support for the TSM modules loader ( https://github.com/lukeed/tsm ). - if (!process[Symbol.for('ts-node.register.instance')]) { - realRequire('ts-node/register') - } else if (process.env.TS_NODE_DEV) { - realRequire('ts-node-dev') - } - // TODO: Support ES imports once tsc, tap & ts-node provide better compatibility guarantees. - // Remove extra forwardslash on Windows - worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', ''))) - } else { - worker = (await realImport(filename)) - } - } catch (error) { - // A yarn user that tries to start a ThreadStream for an external module - // provides a filename pointing to a zip file. - // eg. require.resolve('pino-elasticsearch') // returns /foo/pino-elasticsearch-npm-6.1.0-0c03079478-6915435172.zip/bar.js - // The `import` will fail to try to load it. - // This catch block executes the `require` fallback to load the module correctly. - // In fact, yarn modifies the `require` function to manage the zipped path. - // More details at https://github.com/pinojs/pino/pull/1113 - // The error codes may change based on the node.js version (ENOTDIR > 12, ERR_MODULE_NOT_FOUND <= 12 ) - if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND') && - filename.startsWith('file://')) { - worker = realRequire(decodeURIComponent(filename.replace('file://', ''))) - } else if (error.code === undefined || error.code === 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING') { - // When bundled with pkg, an undefined error is thrown when called with realImport - // When bundled with pkg and using node v20, an ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error is thrown when called with realImport - // More info at: https://github.com/pinojs/thread-stream/issues/143 - worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', ''))) - } else { - throw error - } - } - - // Depending on how the default export is performed, and on how the code is - // transpiled, we may find cases of two nested "default" objects. - // See https://github.com/pinojs/pino/issues/1243#issuecomment-982774762 - if (typeof worker === 'object') worker = worker.default - if (typeof worker === 'object') worker = worker.default - - destination = await worker(workerData.workerData) - - destination.on('error', function (err) { - Atomics.store(state, WRITE_INDEX, -2) - Atomics.notify(state, WRITE_INDEX) - - Atomics.store(state, READ_INDEX, -2) - Atomics.notify(state, READ_INDEX) - - parentPort.postMessage({ - code: 'ERROR', - err - }) - }) - - destination.on('close', function () { - // process._rawDebug('worker close emitted') - const end = Atomics.load(state, WRITE_INDEX) - Atomics.store(state, READ_INDEX, end) - Atomics.notify(state, READ_INDEX) - setImmediate(() => { - process.exit(0) - }) - }) -} - -// No .catch() handler, -// in case there is an error it goes -// to unhandledRejection -start().then(function () { - parentPort.postMessage({ - code: 'READY' - }) - - process.nextTick(run) -}) - -function run () { - const current = Atomics.load(state, READ_INDEX) - const end = Atomics.load(state, WRITE_INDEX) - - // process._rawDebug(`pre state ${current} ${end}`) - - if (end === current) { - if (end === data.length) { - waitDiff(state, READ_INDEX, end, Infinity, run) - } else { - waitDiff(state, WRITE_INDEX, end, Infinity, run) - } - return - } - - // process._rawDebug(`post state ${current} ${end}`) - - if (end === -1) { - // process._rawDebug('end') - destination.end() - return - } - - const toWrite = data.toString('utf8', current, end) - // process._rawDebug('worker writing: ' + toWrite) - - const res = destination.write(toWrite) - - if (res) { - Atomics.store(state, READ_INDEX, end) - Atomics.notify(state, READ_INDEX) - setImmediate(run) - } else { - destination.once('drain', function () { - Atomics.store(state, READ_INDEX, end) - Atomics.notify(state, READ_INDEX) - run() - }) - } -} - -process.on('unhandledRejection', function (err) { - parentPort.postMessage({ - code: 'ERROR', - err - }) - process.exit(1) -}) - -process.on('uncaughtException', function (err) { - parentPort.postMessage({ - code: 'ERROR', - err - }) - process.exit(1) -}) - -process.once('exit', exitCode => { - if (exitCode !== 0) { - process.exit(exitCode) - return - } - - if (destination?.writableNeedDrain && !destination?.writableEnded) { - parentPort.postMessage({ - code: 'WARNING', - err: new Error('ThreadStream: process exited before destination stream was drained. this may indicate that the destination stream try to write to a another missing stream') - }) - } - - process.exit(0) -}) diff --git a/dist/worker2.js b/dist/worker2.js deleted file mode 100644 index 6f0825c..0000000 --- a/dist/worker2.js +++ /dev/null @@ -1,174 +0,0 @@ -'use strict' - -const { realImport, realRequire } = require('real-require') -const { workerData, parentPort } = require('worker_threads') -const { WRITE_INDEX, READ_INDEX } = require('./indexes') -const { waitDiff } = require('./wait') - -const { - dataBuf, - filename, - stateBuf -} = workerData - -let destination - -const state = new Int32Array(stateBuf) -const data = Buffer.from(dataBuf) - -async function start () { - let worker - try { - if (filename.endsWith('.ts') || filename.endsWith('.cts')) { - // TODO: add support for the TSM modules loader ( https://github.com/lukeed/tsm ). - if (!process[Symbol.for('ts-node.register.instance')]) { - realRequire('ts-node/register') - } else if (process.env.TS_NODE_DEV) { - realRequire('ts-node-dev') - } - // TODO: Support ES imports once tsc, tap & ts-node provide better compatibility guarantees. - // Remove extra forwardslash on Windows - worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', ''))) - } else { - worker = (await realImport(filename)) - } - } catch (error) { - // A yarn user that tries to start a ThreadStream for an external module - // provides a filename pointing to a zip file. - // eg. require.resolve('pino-elasticsearch') // returns /foo/pino-elasticsearch-npm-6.1.0-0c03079478-6915435172.zip/bar.js - // The `import` will fail to try to load it. - // This catch block executes the `require` fallback to load the module correctly. - // In fact, yarn modifies the `require` function to manage the zipped path. - // More details at https://github.com/pinojs/pino/pull/1113 - // The error codes may change based on the node.js version (ENOTDIR > 12, ERR_MODULE_NOT_FOUND <= 12 ) - if ((error.code === 'ENOTDIR' || error.code === 'ERR_MODULE_NOT_FOUND') && - filename.startsWith('file://')) { - worker = realRequire(decodeURIComponent(filename.replace('file://', ''))) - } else if (error.code === undefined || error.code === 'ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING') { - // When bundled with pkg, an undefined error is thrown when called with realImport - // When bundled with pkg and using node v20, an ERR_VM_DYNAMIC_IMPORT_CALLBACK_MISSING error is thrown when called with realImport - // More info at: https://github.com/pinojs/thread-stream/issues/143 - try { - worker = realRequire(decodeURIComponent(filename.replace(process.platform === 'win32' ? 'file:///' : 'file://', ''))) - } catch { - throw error - } - } else { - throw error - } - } - - // Depending on how the default export is performed, and on how the code is - // transpiled, we may find cases of two nested "default" objects. - // See https://github.com/pinojs/pino/issues/1243#issuecomment-982774762 - if (typeof worker === 'object') worker = worker.default - if (typeof worker === 'object') worker = worker.default - - destination = await worker(workerData.workerData) - - destination.on('error', function (err) { - Atomics.store(state, WRITE_INDEX, -2) - Atomics.notify(state, WRITE_INDEX) - - Atomics.store(state, READ_INDEX, -2) - Atomics.notify(state, READ_INDEX) - - parentPort.postMessage({ - code: 'ERROR', - err - }) - }) - - destination.on('close', function () { - // process._rawDebug('worker close emitted') - const end = Atomics.load(state, WRITE_INDEX) - Atomics.store(state, READ_INDEX, end) - Atomics.notify(state, READ_INDEX) - setImmediate(() => { - process.exit(0) - }) - }) -} - -// No .catch() handler, -// in case there is an error it goes -// to unhandledRejection -start().then(function () { - parentPort.postMessage({ - code: 'READY' - }) - - process.nextTick(run) -}) - -function run () { - const current = Atomics.load(state, READ_INDEX) - const end = Atomics.load(state, WRITE_INDEX) - - // process._rawDebug(`pre state ${current} ${end}`) - - if (end === current) { - if (end === data.length) { - waitDiff(state, READ_INDEX, end, Infinity, run) - } else { - waitDiff(state, WRITE_INDEX, end, Infinity, run) - } - return - } - - // process._rawDebug(`post state ${current} ${end}`) - - if (end === -1) { - // process._rawDebug('end') - destination.end() - return - } - - const toWrite = data.toString('utf8', current, end) - // process._rawDebug('worker writing: ' + toWrite) - - const res = destination.write(toWrite) - - if (res) { - Atomics.store(state, READ_INDEX, end) - Atomics.notify(state, READ_INDEX) - setImmediate(run) - } else { - destination.once('drain', function () { - Atomics.store(state, READ_INDEX, end) - Atomics.notify(state, READ_INDEX) - run() - }) - } -} - -process.on('unhandledRejection', function (err) { - parentPort.postMessage({ - code: 'ERROR', - err - }) - process.exit(1) -}) - -process.on('uncaughtException', function (err) { - parentPort.postMessage({ - code: 'ERROR', - err - }) - process.exit(1) -}) - -process.once('exit', exitCode => { - if (exitCode !== 0) { - process.exit(exitCode) - return - } - if (destination?.writableNeedDrain && !destination?.writableEnded) { - parentPort.postMessage({ - code: 'WARNING', - err: new Error('ThreadStream: process exited before destination stream was drained. this may indicate that the destination stream try to write to a another missing stream') - }) - } - - process.exit(0) -})