This is an automated email from the ASF dual-hosted git repository.
domoritz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/main by this push:
new 5abd933858 GH-39482: [JS] Refactor imports (#39483)
5abd933858 is described below
commit 5abd9338589f5211ce833a73c2200690b20d37c1
Author: Dominik Moritz <[email protected]>
AuthorDate: Tue Apr 16 15:51:11 2024 -0400
GH-39482: [JS] Refactor imports (#39483)
* use `node:` prefix for node imports
* remove `import` for types where it makes sense
* Closes: #39482
* GitHub Issue: #39482
---------
Co-authored-by: Paul Taylor <[email protected]>
---
js/.eslintrc.cjs | 6 ++----
js/bin/file-to-stream.ts | 6 +++---
js/bin/integration.ts | 20 ++++++++++----------
js/bin/json-to-arrow.ts | 10 +++++-----
js/bin/print-buffer-alignment.ts | 4 ++--
js/bin/stream-to-file.ts | 6 +++---
js/gulp/arrow-task.js | 4 ++--
js/gulp/bundle-task.js | 10 +++++-----
js/gulp/closure-task.js | 4 ++--
js/gulp/test-task.js | 10 +++++-----
js/gulp/typescript-task.js | 4 ++--
js/gulp/util.js | 12 ++++++------
js/src/bin/arrow2csv.ts | 4 ++--
js/src/builder.ts | 9 +++++++--
js/src/fb/.eslintrc.cjs | 1 +
js/src/io/adapters.ts | 12 +++++++-----
js/src/io/interfaces.ts | 13 +++++++------
js/src/io/node/builder.ts | 2 +-
js/src/io/node/iterable.ts | 4 ++--
js/src/io/node/reader.ts | 2 +-
js/src/io/node/writer.ts | 3 ++-
js/src/ipc/reader.ts | 4 +++-
js/src/ipc/writer.ts | 6 ++++--
js/src/util/compat.ts | 10 ++++++----
js/test/.eslintrc.cjs | 1 +
js/test/unit/ipc/helpers.ts | 4 ++--
js/test/unit/ipc/reader/streams-node-tests.ts | 2 +-
27 files changed, 94 insertions(+), 79 deletions(-)
diff --git a/js/.eslintrc.cjs b/js/.eslintrc.cjs
index 8a36516eec..1792a33aba 100644
--- a/js/.eslintrc.cjs
+++ b/js/.eslintrc.cjs
@@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
+/** @type {import('eslint').Linter.Config} */
module.exports = {
env: {
browser: true,
@@ -25,7 +26,7 @@ module.exports = {
parserOptions: {
project: ["tsconfig.json", "tsconfig/tsconfig.bin.cjs.json"],
sourceType: "module",
- ecmaVersion: 2020,
+ ecmaVersion: "latest",
},
plugins: ["@typescript-eslint", "jest", "unicorn"],
extends: [
@@ -92,16 +93,13 @@ module.exports = {
"unicorn/empty-brace-spaces": "off",
"unicorn/no-zero-fractions": "off",
"unicorn/prevent-abbreviations": "off",
- "unicorn/prefer-module": "off",
"unicorn/numeric-separators-style": "off",
"unicorn/prefer-spread": "off",
"unicorn/filename-case": "off",
"unicorn/prefer-export-from": "off",
"unicorn/prefer-switch": "off",
- "unicorn/prefer-node-protocol": "off",
"unicorn/text-encoding-identifier-case": "off",
"unicorn/prefer-top-level-await": "off",
-
"unicorn/consistent-destructuring": "off",
"unicorn/no-array-reduce": "off",
"unicorn/no-await-expression-member": "off",
diff --git a/js/bin/file-to-stream.ts b/js/bin/file-to-stream.ts
index 9dad4951f9..b7341faf2c 100755
--- a/js/bin/file-to-stream.ts
+++ b/js/bin/file-to-stream.ts
@@ -17,9 +17,9 @@
// specific language governing permissions and limitations
// under the License.
-import * as fs from 'fs';
-import * as Path from 'path';
-import { finished as eos } from 'stream/promises';
+import * as fs from 'node:fs';
+import * as Path from 'node:path';
+import { finished as eos } from 'node:stream/promises';
import { RecordBatchReader, RecordBatchStreamWriter } from '../index.ts';
(async () => {
diff --git a/js/bin/integration.ts b/js/bin/integration.ts
index f9aad3422a..f73388cc85 100755
--- a/js/bin/integration.ts
+++ b/js/bin/integration.ts
@@ -17,8 +17,8 @@
// specific language governing permissions and limitations
// under the License.
-import * as fs from 'fs';
-import * as Path from 'path';
+import * as fs from 'node:fs';
+import * as Path from 'node:path';
import { glob } from 'glob';
import { zip } from 'ix/iterable/zip.js';
import commandLineArgs from 'command-line-args';
@@ -41,8 +41,8 @@ const argv = commandLineArgs(cliOpts(), { partial: true });
const exists = async (p: string) => {
try {
return !!(await fs.promises.stat(p));
- } catch (e) { return false; }
-}
+ } catch { return false; }
+};
(async () => {
@@ -52,17 +52,17 @@ const exists = async (p: string) => {
let jsonPaths = [...(argv.json || [])];
let arrowPaths = [...(argv.arrow || [])];
- if (mode === 'VALIDATE' && !jsonPaths.length) {
+ if (mode === 'VALIDATE' && jsonPaths.length === 0) {
[jsonPaths, arrowPaths] = await
loadLocalJSONAndArrowPathsForDebugging(jsonPaths, arrowPaths);
}
- if (!jsonPaths.length) { return print_usage(); }
+ if (jsonPaths.length === 0) { return print_usage(); }
let threw = false;
switch (mode) {
case 'VALIDATE':
- for (let [jsonPath, arrowPath] of zip(jsonPaths, arrowPaths)) {
+ for (const [jsonPath, arrowPath] of zip(jsonPaths, arrowPaths)) {
try {
await validate(jsonPath, arrowPath);
} catch (e: any) {
@@ -232,7 +232,7 @@ function compareVectors(actual: Vector, expected: Vector) {
(() => {
let i = -1;
- for (let [x1, x2] of zip(actual, expected)) {
+ for (const [x1, x2] of zip(actual, expected)) {
++i;
if (!createElementComparator(x2)(x1)) {
throw new Error(`${i}: ${x1} !== ${x2}`);
@@ -245,14 +245,14 @@ async function
loadLocalJSONAndArrowPathsForDebugging(jsonPaths: string[], arrow
const sourceJSONPaths = await glob(Path.resolve(__dirname,
`../test/data/json/`, `*.json`));
- if (!arrowPaths.length) {
+ if (arrowPaths.length === 0) {
await loadJSONAndArrowPaths(sourceJSONPaths, jsonPaths, arrowPaths,
'cpp', 'file');
await loadJSONAndArrowPaths(sourceJSONPaths, jsonPaths, arrowPaths,
'java', 'file');
await loadJSONAndArrowPaths(sourceJSONPaths, jsonPaths, arrowPaths,
'cpp', 'stream');
await loadJSONAndArrowPaths(sourceJSONPaths, jsonPaths, arrowPaths,
'java', 'stream');
}
- for (let [jsonPath, arrowPath] of zip(jsonPaths, arrowPaths)) {
+ for (const [jsonPath, arrowPath] of zip(jsonPaths, arrowPaths)) {
console.log(`jsonPath: ${jsonPath}`);
console.log(`arrowPath: ${arrowPath}`);
}
diff --git a/js/bin/json-to-arrow.ts b/js/bin/json-to-arrow.ts
index 49726706a1..168db00a54 100755
--- a/js/bin/json-to-arrow.ts
+++ b/js/bin/json-to-arrow.ts
@@ -17,10 +17,10 @@
// specific language governing permissions and limitations
// under the License.
-import * as fs from 'fs';
-import * as Path from 'path';
+import * as fs from 'node:fs';
+import * as Path from 'node:path';
import commandLineArgs from 'command-line-args';
-import { finished as eos } from 'stream/promises';
+import { finished as eos } from 'node:stream/promises';
// @ts-ignore
import { parse as bignumJSONParse } from 'json-bignum';
import { RecordBatchReader, RecordBatchFileWriter, RecordBatchStreamWriter }
from '../index.ts';
@@ -31,7 +31,7 @@ const arrowPaths = [...(argv.arrow || [])];
(async () => {
- if (!jsonPaths.length || !arrowPaths.length || (jsonPaths.length !==
arrowPaths.length)) {
+ if (jsonPaths.length === 0 || arrowPaths.length === 0 || (jsonPaths.length
!== arrowPaths.length)) {
return print_usage();
}
@@ -51,7 +51,7 @@ const arrowPaths = [...(argv.arrow || [])];
await eos(jsonToArrow);
}));
- return undefined;
+ return;
})()
.then((x) => x ?? 0, (e) => {
e && process.stderr.write(`${e}`);
diff --git a/js/bin/print-buffer-alignment.ts b/js/bin/print-buffer-alignment.ts
index 07563af5a8..dabe3c5f9a 100755
--- a/js/bin/print-buffer-alignment.ts
+++ b/js/bin/print-buffer-alignment.ts
@@ -17,8 +17,8 @@
// specific language governing permissions and limitations
// under the License.
-import * as fs from 'fs';
-import * as Path from 'path';
+import * as fs from 'node:fs';
+import * as Path from 'node:path';
import { VectorLoader } from '../src/visitor/vectorloader.ts';
import { RecordBatch, AsyncMessageReader, makeData, Struct, Schema, Field }
from '../index.ts';
diff --git a/js/bin/stream-to-file.ts b/js/bin/stream-to-file.ts
index 6e09ead2fd..c1317abc97 100755
--- a/js/bin/stream-to-file.ts
+++ b/js/bin/stream-to-file.ts
@@ -17,9 +17,9 @@
// specific language governing permissions and limitations
// under the License.
-import * as fs from 'fs';
-import * as path from 'path';
-import { finished as eos } from 'stream/promises';
+import * as fs from 'node:fs';
+import * as path from 'node:path';
+import { finished as eos } from 'node:stream/promises';
import { RecordBatchReader, RecordBatchFileWriter } from '../index.ts';
(async () => {
diff --git a/js/gulp/arrow-task.js b/js/gulp/arrow-task.js
index f8a18fe122..855cb71283 100644
--- a/js/gulp/arrow-task.js
+++ b/js/gulp/arrow-task.js
@@ -18,9 +18,9 @@
import { mainExport, targetDir, observableFromStreams } from './util.js';
import gulp from 'gulp';
-import path from 'path';
+import path from 'node:path';
import { mkdirp } from 'mkdirp';
-import * as fs from 'fs/promises';
+import * as fs from 'node:fs/promises';
import gulpRename from 'gulp-rename';
import gulpReplace from 'gulp-replace';
import { memoizeTask } from './memoize-task.js';
diff --git a/js/gulp/bundle-task.js b/js/gulp/bundle-task.js
index 41a0895b08..b0aab6c468 100644
--- a/js/gulp/bundle-task.js
+++ b/js/gulp/bundle-task.js
@@ -23,9 +23,9 @@ import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import { observableFromStreams } from './util.js';
import { forkJoin as ObservableForkJoin } from 'rxjs';
-import { resolve, join } from 'path';
-import { readdirSync } from 'fs';
-import { execSync } from 'child_process';
+import { resolve, join } from 'node:path';
+import { readdirSync } from 'node:fs';
+import { execSync } from 'node:child_process';
import gulpEsbuild from 'gulp-esbuild';
import esbuildAlias from 'esbuild-plugin-alias';
@@ -38,8 +38,8 @@ import { BundleAnalyzerPlugin } from
'webpack-bundle-analyzer';
import webpack from 'webpack-stream';
import named from 'vinyl-named';
-import { fileURLToPath } from 'url';
-import { dirname } from 'path';
+import { fileURLToPath } from 'node:url';
+import { dirname } from 'node:path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
diff --git a/js/gulp/closure-task.js b/js/gulp/closure-task.js
index 7c0ae1c1b6..c620784fd1 100644
--- a/js/gulp/closure-task.js
+++ b/js/gulp/closure-task.js
@@ -17,9 +17,9 @@
import { targetDir, mainExport, esmRequire, gCCLanguageNames,
publicModulePaths, observableFromStreams, shouldRunInChildProcess,
spawnGulpCommandInChildProcess } from "./util.js";
-import fs from 'fs';
+import fs from 'node:fs';
import gulp from 'gulp';
-import path from 'path';
+import path from 'node:path';
import { mkdirp } from 'mkdirp';
import sourcemaps from 'gulp-sourcemaps';
import { memoizeTask } from './memoize-task.js';
diff --git a/js/gulp/test-task.js b/js/gulp/test-task.js
index 5d190be22d..e2263049b3 100644
--- a/js/gulp/test-task.js
+++ b/js/gulp/test-task.js
@@ -16,14 +16,14 @@
// under the License.
import { deleteAsync as del } from 'del';
-import path from 'path';
+import path from 'node:path';
import { mkdirp } from 'mkdirp';
import { argv } from './argv.js';
-import { promisify } from 'util';
+import { promisify } from 'node:util';
import { glob } from 'glob';
-import child_process from 'child_process';
+import child_process from 'node:child_process';
import { memoizeTask } from './memoize-task.js';
-import fs from 'fs';
+import fs from 'node:fs';
const readFile = promisify(fs.readFile);
import asyncDoneSync from 'async-done';
const asyncDone = promisify(asyncDoneSync);
@@ -31,7 +31,7 @@ const exec = promisify(child_process.exec);
import xml2js from 'xml2js';
const parseXML = promisify(xml2js.parseString);
import { targetAndModuleCombinations, npmPkgName } from './util.js';
-import { createRequire } from 'module';
+import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
diff --git a/js/gulp/typescript-task.js b/js/gulp/typescript-task.js
index 31769e3b1b..b5a4c3232d 100644
--- a/js/gulp/typescript-task.js
+++ b/js/gulp/typescript-task.js
@@ -18,10 +18,10 @@
import { targetDir, tsconfigName, observableFromStreams,
shouldRunInChildProcess, spawnGulpCommandInChildProcess } from './util.js';
import gulp from 'gulp';
-import path from 'path';
+import path from 'node:path';
import tsc from 'typescript';
import ts from 'gulp-typescript';
-import * as fs from 'fs/promises';
+import * as fs from 'node:fs/promises';
import sourcemaps from 'gulp-sourcemaps';
import { memoizeTask } from './memoize-task.js';
import { ReplaySubject, forkJoin as ObservableForkJoin, defer as
ObservableDefer } from 'rxjs';
diff --git a/js/gulp/util.js b/js/gulp/util.js
index d86011008a..2ce756f4ac 100644
--- a/js/gulp/util.js
+++ b/js/gulp/util.js
@@ -15,18 +15,18 @@
// specific language governing permissions and limitations
// under the License.
-import fs from 'fs';
-import path from 'path';
-import child_process from 'child_process';
-import stream from 'stream';
-import util from 'util';
+import fs from 'node:fs';
+import path from 'node:path';
+import child_process from 'node:child_process';
+import stream from 'node:stream';
+import util from 'node:util';
import asyncDoneSync from 'async-done';
const pump = stream.pipeline;
import { targets, modules } from './argv.js';
import { ReplaySubject, empty as ObservableEmpty, throwError as
ObservableThrow, fromEvent as ObservableFromEvent } from 'rxjs';
import { share, flatMap, takeUntil, defaultIfEmpty, mergeWith } from
'rxjs/operators';
const asyncDone = util.promisify(asyncDoneSync);
-import { createRequire } from 'module';
+import { createRequire } from 'node:module';
import esmRequire from './esm-require.cjs'
const require = createRequire(import.meta.url);
diff --git a/js/src/bin/arrow2csv.ts b/js/src/bin/arrow2csv.ts
index 4115f30099..569e419faa 100755
--- a/js/src/bin/arrow2csv.ts
+++ b/js/src/bin/arrow2csv.ts
@@ -19,8 +19,8 @@
/* eslint-disable unicorn/no-array-for-each */
-import * as fs from 'fs';
-import * as stream from 'stream';
+import * as fs from 'node:fs';
+import * as stream from 'node:stream';
import { Schema, RecordBatch, RecordBatchReader, AsyncByteQueue, util } from
'../Arrow.js';
import * as commandLineUsage from 'command-line-usage';
diff --git a/js/src/builder.ts b/js/src/builder.ts
index 1880db3818..5ae43a8836 100644
--- a/js/src/builder.ts
+++ b/js/src/builder.ts
@@ -27,6 +27,11 @@ import {
import { createIsValidFunction } from './builder/valid.js';
import { BufferBuilder, BitmapBufferBuilder, DataBufferBuilder,
OffsetsBufferBuilder } from './builder/buffer.js';
+import type { BuilderDuplexOptions } from './io/node/builder.js';
+import type { BuilderTransform, BuilderTransformOptions } from
'./io/whatwg/builder.js';
+
+import type { Duplex } from 'node:stream';
+
/**
* A set of options required to create a `Builder` instance for a given
`DataType`.
* @see {@link Builder}
@@ -98,12 +103,12 @@ export abstract class Builder<T extends DataType = any,
TNull = any> {
/** @nocollapse */
// @ts-ignore
- public static throughNode<T extends DataType = any, TNull = any>(options:
import('./io/node/builder').BuilderDuplexOptions<T, TNull>):
import('stream').Duplex {
+ public static throughNode<T extends DataType = any, TNull = any>(options:
BuilderDuplexOptions<T, TNull>): Duplex {
throw new Error(`"throughNode" not available in this environment`);
}
/** @nocollapse */
// @ts-ignore
- public static throughDOM<T extends DataType = any, TNull = any>(options:
import('./io/whatwg/builder').BuilderTransformOptions<T, TNull>):
import('./io/whatwg/builder').BuilderTransform<T, TNull> {
+ public static throughDOM<T extends DataType = any, TNull = any>(options:
BuilderTransformOptions<T, TNull>): BuilderTransform<T, TNull> {
throw new Error(`"throughDOM" not available in this environment`);
}
diff --git a/js/src/fb/.eslintrc.cjs b/js/src/fb/.eslintrc.cjs
index eb0fc1c7cd..b7fc1c0290 100644
--- a/js/src/fb/.eslintrc.cjs
+++ b/js/src/fb/.eslintrc.cjs
@@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
+/** @type {import('eslint').Linter.Config} */
module.exports = {
rules: {
"@typescript-eslint/type-annotation-spacing": "off",
diff --git a/js/src/io/adapters.ts b/js/src/io/adapters.ts
index 05020314aa..3118cba049 100644
--- a/js/src/io/adapters.ts
+++ b/js/src/io/adapters.ts
@@ -25,6 +25,8 @@ import {
import { ReadableDOMStreamOptions } from './interfaces.js';
+import type { ReadableOptions, Readable } from 'node:stream';
+
type Uint8ArrayGenerator = Generator<Uint8Array, null, { cmd: 'peek' | 'read';
size: number }>;
type AsyncUint8ArrayGenerator = AsyncGenerator<Uint8Array, null, { cmd: 'peek'
| 'read'; size: number }>;
@@ -47,7 +49,7 @@ export default {
throw new Error(`"toDOMStream" not available in this environment`);
},
// @ts-ignore
- toNodeStream<T>(source: Iterable<T> | AsyncIterable<T>, options?:
import('stream').ReadableOptions): import('stream').Readable {
+ toNodeStream<T>(source: Iterable<T> | AsyncIterable<T>, options?:
ReadableOptions): Readable {
throw new Error(`"toNodeStream" not available in this environment`);
},
};
@@ -71,7 +73,7 @@ function* fromIterable<T extends
ArrayBufferViewInput>(source: Iterable<T> | T):
}
// Yield so the caller can inject the read command before creating the
source Iterator
- ({ cmd, size } = (yield (() => <any>null)()) || {cmd: 'read', size: 0});
+ ({ cmd, size } = (yield (() => <any>null)()) || { cmd: 'read', size: 0 });
// initialize the iterator
const it = toUint8ArrayIterator(source)[Symbol.iterator]();
@@ -117,7 +119,7 @@ async function* fromAsyncIterable<T extends
ArrayBufferViewInput>(source: AsyncI
}
// Yield so the caller can inject the read command before creating the
source AsyncIterator
- ({ cmd, size } = (yield (() => <any>null)()) || {cmd: 'read', size: 0});
+ ({ cmd, size } = (yield (() => <any>null)()) || { cmd: 'read', size: 0 });
// initialize the iterator
const it = toUint8ArrayAsyncIterator(source)[Symbol.asyncIterator]();
@@ -167,7 +169,7 @@ async function* fromDOMStream<T extends
ArrayBufferViewInput>(source: ReadableSt
}
// Yield so the caller can inject the read command before we establish the
ReadableStream lock
- ({ cmd, size } = (yield (() => <any>null)()) || {cmd: 'read', size: 0});
+ ({ cmd, size } = (yield (() => <any>null)()) || { cmd: 'read', size: 0 });
// initialize the reader and lock the stream
const it = new AdaptiveByteReader(source);
@@ -273,7 +275,7 @@ async function* fromNodeStream(stream:
NodeJS.ReadableStream): AsyncUint8ArrayGe
// Yield so the caller can inject the read command before we
// add the listener for the source stream's 'readable' event.
- ({ cmd, size } = (yield (() => <any>null)()) || {cmd: 'read', size: 0});
+ ({ cmd, size } = (yield (() => <any>null)()) || { cmd: 'read', size: 0 });
// ignore stdin if it's a TTY
if ((stream as any)['isTTY']) {
diff --git a/js/src/io/interfaces.ts b/js/src/io/interfaces.ts
index d69841bcbb..6775c3240b 100644
--- a/js/src/io/interfaces.ts
+++ b/js/src/io/interfaces.ts
@@ -17,11 +17,12 @@
import streamAdapters from './adapters.js';
+export type { FileHandle } from 'node:fs/promises';
+import type { ReadableOptions, Readable as StreamReadable } from 'node:stream';
+
/** @ignore */
export const ITERATOR_DONE: any = Object.freeze({ done: true, value: void (0)
});
-/** @ignore */
-export type FileHandle = import('fs').promises.FileHandle;
/** @ignore */
export type ArrowJSONLike = { schema: any; batches?: any[]; dictionaries?:
any[] };
/** @ignore */
@@ -60,14 +61,14 @@ export interface Writable<T> {
export interface ReadableWritable<TReadable, TWritable> extends
Readable<TReadable>, Writable<TWritable> {
[Symbol.asyncIterator](): AsyncIterableIterator<TReadable>;
toDOMStream(options?: ReadableDOMStreamOptions): ReadableStream<TReadable>;
- toNodeStream(options?: import('stream').ReadableOptions):
import('stream').Readable;
+ toNodeStream(options?: ReadableOptions): StreamReadable;
}
/** @ignore */
export abstract class ReadableInterop<T> {
public abstract toDOMStream(options?: ReadableDOMStreamOptions):
ReadableStream<T>;
- public abstract toNodeStream(options?: import('stream').ReadableOptions):
import('stream').Readable;
+ public abstract toNodeStream(options?: ReadableOptions): StreamReadable;
public tee(): [ReadableStream<T>, ReadableStream<T>] {
return this._getDOMStream().tee();
@@ -85,7 +86,7 @@ export abstract class ReadableInterop<T> {
return this._DOMStream || (this._DOMStream = this.toDOMStream());
}
- protected _nodeStream?: import('stream').Readable;
+ protected _nodeStream?: StreamReadable;
private _getNodeStream() {
return this._nodeStream || (this._nodeStream = this.toNodeStream());
}
@@ -144,7 +145,7 @@ export class AsyncQueue<TReadable = Uint8Array, TWritable =
TReadable> extends R
: (this._values as any) as Iterable<TReadable>,
options);
}
- public toNodeStream(options?: import('stream').ReadableOptions) {
+ public toNodeStream(options?: ReadableOptions) {
return streamAdapters.toNodeStream(
(this._closedPromiseResolve || this._error)
? (this as AsyncIterable<TReadable>)
diff --git a/js/src/io/node/builder.ts b/js/src/io/node/builder.ts
index be289f447f..1d02febac7 100644
--- a/js/src/io/node/builder.ts
+++ b/js/src/io/node/builder.ts
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-import { Duplex } from 'stream';
+import { Duplex } from 'node:stream';
import { DataType } from '../../type.js';
import { Builder, BuilderOptions } from '../../builder.js';
import { makeBuilder } from '../../factories.js';
diff --git a/js/src/io/node/iterable.ts b/js/src/io/node/iterable.ts
index 6698e7fa92..67b2143ea2 100644
--- a/js/src/io/node/iterable.ts
+++ b/js/src/io/node/iterable.ts
@@ -15,11 +15,11 @@
// specific language governing permissions and limitations
// under the License.
-import { Readable } from 'stream';
+import { Readable, ReadableOptions as ReadableOptions_ } from 'node:stream';
import { isIterable, isAsyncIterable } from '../../util/compat.js';
/** @ignore */
-type ReadableOptions = import('stream').ReadableOptions;
+type ReadableOptions = ReadableOptions_;
/** @ignore */
type SourceIterator<T> = Generator<T, void, number | null>;
/** @ignore */
diff --git a/js/src/io/node/reader.ts b/js/src/io/node/reader.ts
index e8bbf736aa..77e1fc26e2 100644
--- a/js/src/io/node/reader.ts
+++ b/js/src/io/node/reader.ts
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-import { Duplex, DuplexOptions } from 'stream';
+import { Duplex, DuplexOptions } from 'node:stream';
import { AsyncByteQueue } from '../../io/stream.js';
import { RecordBatchReader } from '../../ipc/reader.js';
import { RecordBatch } from '../../recordbatch.js';
diff --git a/js/src/io/node/writer.ts b/js/src/io/node/writer.ts
index 5725ef7a5d..fb426a9681 100644
--- a/js/src/io/node/writer.ts
+++ b/js/src/io/node/writer.ts
@@ -15,7 +15,8 @@
// specific language governing permissions and limitations
// under the License.
-import { Duplex, DuplexOptions } from 'stream';
+import { Duplex } from 'node:stream';
+import type { DuplexOptions } from 'node:stream';
import { AsyncByteStream } from '../../io/stream.js';
import { RecordBatchWriter } from '../../ipc/writer.js';
import { TypeMap } from '../../type.js';
diff --git a/js/src/ipc/reader.ts b/js/src/ipc/reader.ts
index e4dac0606a..547739dacc 100644
--- a/js/src/ipc/reader.ts
+++ b/js/src/ipc/reader.ts
@@ -47,6 +47,8 @@ import {
isReadableDOMStream, isReadableNodeStream
} from '../util/compat.js';
+import type { DuplexOptions, Duplex } from 'node:stream';
+
/** @ignore */ export type FromArg0 = ArrowJSONLike;
/** @ignore */ export type FromArg1 = PromiseLike<ArrowJSONLike>;
/** @ignore */ export type FromArg2 = Iterable<ArrayBufferViewInput> |
ArrayBufferViewInput;
@@ -129,7 +131,7 @@ export class RecordBatchReader<T extends TypeMap = any>
extends ReadableInterop<
/** @nocollapse */
// @ts-ignore
- public static throughNode(options?: import('stream').DuplexOptions & {
autoDestroy: boolean }): import('stream').Duplex {
+ public static throughNode(options?: DuplexOptions & { autoDestroy: boolean
}): Duplex {
throw new Error(`"throughNode" not available in this environment`);
}
/** @nocollapse */
diff --git a/js/src/ipc/writer.ts b/js/src/ipc/writer.ts
index 565b0825bd..8d924ab64c 100644
--- a/js/src/ipc/writer.ts
+++ b/js/src/ipc/writer.ts
@@ -35,6 +35,8 @@ import { RecordBatch, _InternalEmptyPlaceholderRecordBatch }
from '../recordbatc
import { Writable, ReadableInterop, ReadableDOMStreamOptions } from
'../io/interfaces.js';
import { isPromise, isAsyncIterable, isWritableDOMStream,
isWritableNodeStream, isIterable, isObject } from '../util/compat.js';
+import type { DuplexOptions, Duplex, ReadableOptions } from 'node:stream';
+
export interface RecordBatchStreamWriterOptions {
/**
*
@@ -53,7 +55,7 @@ export class RecordBatchWriter<T extends TypeMap = any>
extends ReadableInterop<
/** @nocollapse */
// @ts-ignore
- public static throughNode(options?: import('stream').DuplexOptions & {
autoDestroy: boolean }): import('stream').Duplex {
+ public static throughNode(options?: DuplexOptions & { autoDestroy: boolean
}): Duplex {
throw new Error(`"throughNode" not available in this environment`);
}
/** @nocollapse */
@@ -111,7 +113,7 @@ export class RecordBatchWriter<T extends TypeMap = any>
extends ReadableInterop<
public get closed() { return this._sink.closed; }
public [Symbol.asyncIterator]() { return
this._sink[Symbol.asyncIterator](); }
public toDOMStream(options?: ReadableDOMStreamOptions) { return
this._sink.toDOMStream(options); }
- public toNodeStream(options?: import('stream').ReadableOptions) { return
this._sink.toNodeStream(options); }
+ public toNodeStream(options?: ReadableOptions) { return
this._sink.toNodeStream(options); }
public close() {
return this.reset()._sink.close();
diff --git a/js/src/util/compat.ts b/js/src/util/compat.ts
index 0948e8bea2..73af3087ea 100644
--- a/js/src/util/compat.ts
+++ b/js/src/util/compat.ts
@@ -17,12 +17,14 @@
import { ReadableInterop, ArrowJSONLike } from '../io/interfaces.js';
-/* eslint-disable unicorn/throw-new-error */
+import type { ByteBuffer } from 'flatbuffers';
+import type { ReadStream } from 'node:fs';
+import type { FileHandle as FileHandle_ } from 'node:fs/promises';
/** @ignore */
-type FSReadStream = import('fs').ReadStream;
+type FSReadStream = ReadStream;
/** @ignore */
-type FileHandle = import('fs').promises.FileHandle;
+type FileHandle = FileHandle_;
/** @ignore */
export interface Subscription {
@@ -145,7 +147,7 @@ export const isReadableNodeStream = (x: any): x is
NodeJS.ReadableStream => {
};
/** @ignore */
-export const isFlatbuffersByteBuffer = (x: any): x is
import('flatbuffers').ByteBuffer => {
+export const isFlatbuffersByteBuffer = (x: any): x is ByteBuffer => {
return isObject(x) &&
isFunction(x['clear']) &&
isFunction(x['bytes']) &&
diff --git a/js/test/.eslintrc.cjs b/js/test/.eslintrc.cjs
index bb388f463a..41197c6edb 100644
--- a/js/test/.eslintrc.cjs
+++ b/js/test/.eslintrc.cjs
@@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.
+/** @type {import('eslint').Linter.Config} */
module.exports = {
rules: {
"@typescript-eslint/no-require-imports": "off",
diff --git a/js/test/unit/ipc/helpers.ts b/js/test/unit/ipc/helpers.ts
index 2a228aa7ab..02f45b5742 100644
--- a/js/test/unit/ipc/helpers.ts
+++ b/js/test/unit/ipc/helpers.ts
@@ -15,9 +15,9 @@
// specific language governing permissions and limitations
// under the License.
-import * as fs from 'fs';
+import * as fs from 'node:fs';
import { fs as memfs } from 'memfs';
-import { PassThrough, Readable } from 'stream';
+import { PassThrough, Readable } from 'node:stream';
import {
RecordBatchFileWriter,
diff --git a/js/test/unit/ipc/reader/streams-node-tests.ts
b/js/test/unit/ipc/reader/streams-node-tests.ts
index 2e3f08c4e7..bde685cb95 100644
--- a/js/test/unit/ipc/reader/streams-node-tests.ts
+++ b/js/test/unit/ipc/reader/streams-node-tests.ts
@@ -101,7 +101,7 @@ import {
it('readAll() should pipe to separate NodeJS WritableStreams', async () =>
{
const { default: MultiStream } = await import('multistream');
- const { PassThrough } = await import('stream');
+ const { PassThrough } = await import('node:stream');
expect.hasAssertions();