Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/task_queue/array_queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert';

import type { TaskQueue, Task } from '.';

Expand Down
2 changes: 1 addition & 1 deletion src/task_queue/fixed_queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* License: MIT License
* Source: https://github.com/nodejs/node/blob/de7b37880f5a541d5f874c1c2362a65a4be76cd0/lib/internal/fixed_queue.js
*/
import assert from 'node:assert';
import * as assert from 'node:assert';
import type { Task } from './common';
import { TaskQueue } from '.';
// Currently optimal queue size, tested on V8 6.0 - 6.6. Must be power of two.
Expand Down
11 changes: 9 additions & 2 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,23 @@ async function getHandler (filename : string, name : string) : Promise<Function
// With our current set of TypeScript options, this is transpiled to
// `require(filename)`.
handler = await import(filename);
if (typeof handler !== 'function') {

if (name?.length > 0) {
handler = await ((handler as any)[name]);
} else if (typeof handler !== 'function') {
handler = await ((handler as any)[name]);
}
} catch {}

if (typeof handler !== 'function') {
handler = await getImportESM()(pathToFileURL(filename).href);
if (typeof handler !== 'function') {
if (name?.length > 0) {
handler = await ((handler as any)[name]);
} else if (typeof handler !== 'function') {
handler = await ((handler as any)[name]);
}
}

if (typeof handler !== 'function') {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/worker_pool/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert';

export abstract class AsynchronouslyCreatedResource {
onreadyListeners : (() => void)[] | null = [];
Expand Down
2 changes: 1 addition & 1 deletion src/worker_pool/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Worker, MessagePort, receiveMessageOnPort, WorkerOptions, Transferable } from 'node:worker_threads';
import { createHistogram, RecordableHistogram } from 'node:perf_hooks';
import assert from 'node:assert';
import * as assert from 'node:assert';

import { RequestMessage, ResponseMessage, StartupMessage } from '../types';
import { Errors } from '../errors';
Expand Down
2 changes: 1 addition & 1 deletion test/abort-task.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { EventEmitter } from 'node:events';
import Piscina from '..';
import { resolve } from 'path';
Expand Down
2 changes: 1 addition & 1 deletion test/async-context.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { createHook, executionAsyncId } from 'node:async_hooks';
Expand Down
2 changes: 1 addition & 1 deletion test/atomics-optimization.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina from '..';
Expand Down
2 changes: 1 addition & 1 deletion test/console-log.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { spawn } from 'node:child_process';
import { test } from 'node:test';
Expand Down
2 changes: 1 addition & 1 deletion test/fixed-queue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { kQueueOptions } from '../dist/symbols';
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/cjs-default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.default = async function generate() {
return 42;
}
4 changes: 2 additions & 2 deletions test/fixtures/move.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { types } from 'node:util';
import Piscina from '../..';

export default function (moved) {
if (moved !== undefined) {
assert(types.isAnyArrayBuffer(moved));
assert.ok(types.isAnyArrayBuffer(moved));
}
return Piscina.move(new ArrayBuffer(10));
}
2 changes: 1 addition & 1 deletion test/fixtures/notify-then-sleep-or.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Set the index-th bith in i32array[0], then wait for it to be un-set again.
module.exports = function ({ i32array, index }) {
export default function ({ i32array, index }) {
Atomics.or(i32array, 0, 1 << index);
Atomics.notify(i32array, 0, Infinity);
do {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wait-for-notify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function (i32array) {
export default function (i32array) {
Atomics.wait(i32array, 0, 0);
Atomics.store(i32array, 0, -1);
Atomics.notify(i32array, 0, Infinity);
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/wait-for-others.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { threadId } from 'worker_threads';

module.exports = async function ([i32array, n]) {
export default async function ([i32array, n]) {
Atomics.add(i32array, 0, 1);
Atomics.notify(i32array, 0, Infinity);
let lastSeenValue;
Expand Down
2 changes: 1 addition & 1 deletion test/generics.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { test } from 'node:test';
import Piscina from '../dist';
Expand Down
2 changes: 1 addition & 1 deletion test/histogram.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { test } from 'node:test';
import type { TestContext } from 'node:test';
Expand Down
2 changes: 1 addition & 1 deletion test/idle-timeout.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { promisify } from 'node:util';
Expand Down
2 changes: 1 addition & 1 deletion test/issue-513.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina from '..';
Expand Down
2 changes: 1 addition & 1 deletion test/load-with-esm.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';


Expand Down
2 changes: 1 addition & 1 deletion test/messages.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { once } from 'node:events';
Expand Down
2 changes: 1 addition & 1 deletion test/move-test.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { types } from 'node:util';
import { MessageChannel, MessagePort } from 'node:worker_threads';
Expand Down
2 changes: 1 addition & 1 deletion test/nice.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { test } from 'node:test';
import { getCurrentProcessPriority, WindowsThreadPriority } from '@napi-rs/nice';
Expand Down
2 changes: 1 addition & 1 deletion test/option-validation.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import Piscina from '..';

Expand Down
2 changes: 1 addition & 1 deletion test/pool-close.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { once } from 'node:events';
import { resolve } from 'node:path';
import { describe, it, test } from 'node:test';
Expand Down
2 changes: 1 addition & 1 deletion test/pool-destroy.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina from '..';
Expand Down
2 changes: 1 addition & 1 deletion test/pool.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { resolve } from 'node:path';
import { test } from 'node:test';
import { once } from 'node:events';
Expand Down
2 changes: 1 addition & 1 deletion test/post-task.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { test, TestContext } from 'node:test';
import { MessageChannel } from 'node:worker_threads';
import { resolve } from 'node:path';
Expand Down
2 changes: 1 addition & 1 deletion test/ready-message.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { once } from 'node:events';
Expand Down
13 changes: 11 additions & 2 deletions test/simple-test.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { pathToFileURL } from 'node:url';
import { resolve } from 'node:path';
Expand Down Expand Up @@ -233,7 +233,7 @@ test('named tasks work', async () => {
assert.strictEqual(await worker.run({}), 'a');
});

test('named tasks work', async () => {
test('named tasks work (2)', async () => {
const worker = new Piscina({
filename: resolve(__dirname, 'fixtures/multiple.js'),
name: 'b'
Expand All @@ -243,3 +243,12 @@ test('named tasks work', async () => {
assert.strictEqual(await worker.run({}, { name: 'b' }), 'b');
assert.strictEqual(await worker.run({}), 'b');
});

test('cjs#default named export works (#1012)', async () => {
const worker = new Piscina({
filename: resolve(__dirname, 'fixtures/cjs-default.js'),
name: 'default'
});

assert.strictEqual(await worker.run({}), 42);
});
2 changes: 1 addition & 1 deletion test/task-queue.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina, { PiscinaTask, TaskQueue } from '..';
Expand Down
2 changes: 1 addition & 1 deletion test/test-is-buffer-transferred.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina from '..';
Expand Down
2 changes: 1 addition & 1 deletion test/test-resourcelimits.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina from '..';
Expand Down
2 changes: 1 addition & 1 deletion test/test-uncaught-exception-from-handler.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { once } from 'node:events';
Expand Down
2 changes: 1 addition & 1 deletion test/thread-count.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert/strict';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import { cpus } from 'node:os';
Expand Down
2 changes: 1 addition & 1 deletion test/workers.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import assert from 'node:assert';
import * as assert from 'node:assert/strict';
import { test } from 'node:test';
import { resolve } from 'node:path';
import Piscina from '../dist';
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,

"resolveJsonModule": true, /* Include modules imported with '.json' extension */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
Expand Down
Loading