From be490f1ef83eb5c407f8309253fcdd7c1fa7db73 Mon Sep 17 00:00:00 2001 From: Matthew Walsh Date: Sat, 16 Sep 2023 01:04:44 +0100 Subject: [PATCH] Revert "Remove `pump` (#1730)" This reverts commit 0c52d610a69aed5edbc460999471afc18a350acb. --- packages/snaps-controllers/package.json | 2 + .../src/services/AbstractExecutionService.ts | 15 +---- .../src/snaps/SnapController.test.ts | 15 +---- .../src/snaps/location/npm.ts | 4 +- .../src/test-utils/execution-environment.ts | 10 +-- .../src/test-utils/service.ts | 9 +-- .../lavamoat/browserify/iframe/policy.json | 48 +++++++------- .../browserify/node-process/policy.json | 62 +++++++++---------- .../browserify/node-thread/policy.json | 62 +++++++++---------- .../browserify/worker-executor/policy.json | 48 +++++++------- .../lavamoat/build-system/policy.json | 38 ++++++------ .../snaps-execution-environments/package.json | 1 + .../src/iframe/IFrameSnapExecutor.ts | 4 +- .../node-process/ChildProcessSnapExecutor.ts | 4 +- .../src/node-thread/ThreadSnapExecutor.ts | 4 +- .../executor/WebWorkerSnapExecutor.ts | 4 +- packages/snaps-simulator/jest.config.js | 8 +-- packages/snaps-simulator/package.json | 2 + .../src/features/simulation/sagas.ts | 12 ++-- yarn.lock | 14 +++++ 20 files changed, 178 insertions(+), 188 deletions(-) diff --git a/packages/snaps-controllers/package.json b/packages/snaps-controllers/package.json index db1cd3b829..9b987efd99 100644 --- a/packages/snaps-controllers/package.json +++ b/packages/snaps-controllers/package.json @@ -61,6 +61,7 @@ "json-rpc-engine": "^6.1.0", "json-rpc-middleware-stream": "^4.2.0", "nanoid": "^3.1.31", + "pump": "^3.0.0", "readable-web-to-node-stream": "^3.0.2", "tar-stream": "^2.2.0" }, @@ -83,6 +84,7 @@ "@types/jest": "^27.5.1", "@types/mocha": "^10.0.1", "@types/node": "18.14.2", + "@types/pump": "^1.1.1", "@types/readable-stream": "^2.3.15", "@types/tar-stream": "^2.2.2", "@typescript-eslint/eslint-plugin": "^5.42.1", diff --git a/packages/snaps-controllers/src/services/AbstractExecutionService.ts b/packages/snaps-controllers/src/services/AbstractExecutionService.ts index 507f492d9d..17456797c2 100644 --- a/packages/snaps-controllers/src/services/AbstractExecutionService.ts +++ b/packages/snaps-controllers/src/services/AbstractExecutionService.ts @@ -12,7 +12,7 @@ import type { import { JsonRpcEngine } from 'json-rpc-engine'; import { createStreamMiddleware } from 'json-rpc-middleware-stream'; import { nanoid } from 'nanoid'; -import { pipeline } from 'stream'; +import pump from 'pump'; import type { Duplex } from 'stream'; import { log } from '../logging'; @@ -182,16 +182,7 @@ export abstract class AbstractExecutionService const jsonRpcConnection = createStreamMiddleware(); - pipeline( - jsonRpcConnection.stream, - streams.command, - jsonRpcConnection.stream, - (error) => { - if (error) { - logError(`Command stream failure.`, error); - } - }, - ); + pump(jsonRpcConnection.stream, streams.command, jsonRpcConnection.stream); rpcEngine.push(jsonRpcConnection.middleware); @@ -457,7 +448,7 @@ export function setupMultiplex( streamName: string, ): ObjectMultiplex { const mux = new ObjectMultiplex(); - pipeline( + pump( connectionStream, // Typecast: stream type mismatch mux as unknown as Duplex, diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.ts b/packages/snaps-controllers/src/snaps/SnapController.test.ts index 971a81f106..611a14207b 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.test.ts @@ -11,7 +11,6 @@ import { DEFAULT_REQUESTED_SNAP_VERSION, getSnapChecksum, HandlerType, - logError, SnapCaveatType, SnapStatus, VirtualFile, @@ -36,7 +35,7 @@ import { ethErrors } from 'eth-rpc-errors'; import fetchMock from 'jest-fetch-mock'; import { createAsyncMiddleware, JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import { pipeline } from 'stream'; +import pump from 'pump'; import type { Duplex } from 'stream'; import type { NodeThreadExecutionService } from '../services'; @@ -1103,11 +1102,7 @@ describe('SnapController', () => { }); engine.push(middleware); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream, (error) => { - if (error) { - logError(`Provider stream failure.`, error); - } - }); + pump(stream, providerStream, stream); }); await snapController.startSnap(snap.id); @@ -1188,11 +1183,7 @@ describe('SnapController', () => { }); engine.push(middleware); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream, (error) => { - if (error) { - logError(`Provider stream failure.`, error); - } - }); + pump(stream, providerStream, stream); }); await snapController.startSnap(snap.id); diff --git a/packages/snaps-controllers/src/snaps/location/npm.ts b/packages/snaps-controllers/src/snaps/location/npm.ts index 2fe0b483ed..4f82fa3b98 100644 --- a/packages/snaps-controllers/src/snaps/location/npm.ts +++ b/packages/snaps-controllers/src/snaps/location/npm.ts @@ -18,8 +18,8 @@ import { } from '@metamask/utils'; import concat from 'concat-stream'; import createGunzipStream from 'gunzip-maybe'; +import pump from 'pump'; import { ReadableWebToNodeStream } from 'readable-web-to-node-stream'; -import { pipeline } from 'stream'; import type { Readable, Writable } from 'stream'; import { extract as tarExtract } from 'tar-stream'; @@ -182,7 +182,7 @@ export class NpmLocation implements SnapLocation { // We would need to replace tar-stream package because it requires immediate consumption of streams. await new Promise((resolve, reject) => { this.files = new Map(); - pipeline( + pump( getNodeStream(tarballResponse), // The "gz" in "tgz" stands for "gzip". The tarball needs to be decompressed // before we can actually grab any files from it. diff --git a/packages/snaps-controllers/src/test-utils/execution-environment.ts b/packages/snaps-controllers/src/test-utils/execution-environment.ts index 6cb2842c3b..33cec2b79a 100644 --- a/packages/snaps-controllers/src/test-utils/execution-environment.ts +++ b/packages/snaps-controllers/src/test-utils/execution-environment.ts @@ -1,8 +1,8 @@ -import { logError, type SnapRpcHookArgs } from '@metamask/snaps-utils'; +import type { SnapRpcHookArgs } from '@metamask/snaps-utils'; import type { MockControllerMessenger } from '@metamask/snaps-utils/test-utils'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import { pipeline } from 'stream'; +import pump from 'pump'; import type { ExecutionService, @@ -58,11 +58,7 @@ export const getNodeEES = (messenger: ReturnType) => return next(); }); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream, (error) => { - if (error) { - logError(`Provider stream failure.`, error); - } - }); + pump(stream, providerStream, stream); }), }); diff --git a/packages/snaps-controllers/src/test-utils/service.ts b/packages/snaps-controllers/src/test-utils/service.ts index caf144fb7a..2abb7146cb 100644 --- a/packages/snaps-controllers/src/test-utils/service.ts +++ b/packages/snaps-controllers/src/test-utils/service.ts @@ -1,8 +1,7 @@ import { ControllerMessenger } from '@metamask/base-controller'; -import { logError } from '@metamask/snaps-utils'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; -import { pipeline } from 'stream'; +import pump from 'pump'; import type { Duplex } from 'stream'; import type { ErrorMessageEvent } from '../services'; @@ -57,11 +56,7 @@ export const createService = < return next(); }); const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream, (error) => { - if (error) { - logError(`Provider stream failure.`, error); - } - }); + pump(stream, providerStream, stream); }, ...options, }); diff --git a/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json index f59b2580fa..b9c969c150 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/iframe/policy.json @@ -16,20 +16,9 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "@metamask/object-multiplex>readable-stream": true - } - }, - "@metamask/object-multiplex>end-of-stream": { - "packages": { - "@metamask/object-multiplex>once": true, - "browserify>process": true - } - }, - "@metamask/object-multiplex>once": { - "packages": { - "@metamask/object-multiplex>once>wrappy": true + "@metamask/object-multiplex>readable-stream": true, + "pump>end-of-stream": true, + "pump>once": true } }, "@metamask/object-multiplex>readable-stream": { @@ -106,10 +95,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, - "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true + "json-rpc-engine": true, + "pump": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -170,14 +159,6 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, - "@metamask/providers>pump": { - "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "browserify>browser-resolve": true, - "browserify>process": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, @@ -346,6 +327,25 @@ "browserify>events": true } }, + "pump": { + "packages": { + "browserify>browser-resolve": true, + "browserify>process": true, + "pump>end-of-stream": true, + "pump>once": true + } + }, + "pump>end-of-stream": { + "packages": { + "browserify>process": true, + "pump>once": true + } + }, + "pump>once": { + "packages": { + "pump>once>wrappy": true + } + }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json index ede0cc1da2..9064c4f54d 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/node-process/policy.json @@ -28,22 +28,9 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "@metamask/object-multiplex>readable-stream": true - } - }, - "@metamask/object-multiplex>end-of-stream": { - "globals": { - "process.nextTick": true - }, - "packages": { - "@metamask/object-multiplex>once": true - } - }, - "@metamask/object-multiplex>once": { - "packages": { - "@metamask/object-multiplex>once>wrappy": true + "@metamask/object-multiplex>readable-stream": true, + "pump>end-of-stream": true, + "pump>once": true } }, "@metamask/object-multiplex>readable-stream": { @@ -146,10 +133,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, - "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true + "json-rpc-engine": true, + "pump": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -231,19 +218,6 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, - "@metamask/providers>pump": { - "builtin": { - "fs": true - }, - "globals": { - "process.version": true - }, - "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "fs": true - } - }, "@metamask/utils": { "builtin": { "buffer.Buffer": true @@ -420,6 +394,32 @@ "events": true } }, + "pump": { + "builtin": { + "fs": true + }, + "globals": { + "process.version": true + }, + "packages": { + "fs": true, + "pump>end-of-stream": true, + "pump>once": true + } + }, + "pump>end-of-stream": { + "globals": { + "process.nextTick": true + }, + "packages": { + "pump>once": true + } + }, + "pump>once": { + "packages": { + "pump>once>wrappy": true + } + }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json index ede0cc1da2..9064c4f54d 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/node-thread/policy.json @@ -28,22 +28,9 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "@metamask/object-multiplex>readable-stream": true - } - }, - "@metamask/object-multiplex>end-of-stream": { - "globals": { - "process.nextTick": true - }, - "packages": { - "@metamask/object-multiplex>once": true - } - }, - "@metamask/object-multiplex>once": { - "packages": { - "@metamask/object-multiplex>once>wrappy": true + "@metamask/object-multiplex>readable-stream": true, + "pump>end-of-stream": true, + "pump>once": true } }, "@metamask/object-multiplex>readable-stream": { @@ -146,10 +133,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, - "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true + "json-rpc-engine": true, + "pump": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -231,19 +218,6 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, - "@metamask/providers>pump": { - "builtin": { - "fs": true - }, - "globals": { - "process.version": true - }, - "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "fs": true - } - }, "@metamask/utils": { "builtin": { "buffer.Buffer": true @@ -420,6 +394,32 @@ "events": true } }, + "pump": { + "builtin": { + "fs": true + }, + "globals": { + "process.version": true + }, + "packages": { + "fs": true, + "pump>end-of-stream": true, + "pump>once": true + } + }, + "pump>end-of-stream": { + "globals": { + "process.nextTick": true + }, + "packages": { + "pump>once": true + } + }, + "pump>once": { + "packages": { + "pump>once>wrappy": true + } + }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json b/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json index f59b2580fa..b9c969c150 100644 --- a/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json +++ b/packages/snaps-execution-environments/lavamoat/browserify/worker-executor/policy.json @@ -16,20 +16,9 @@ "console.warn": true }, "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "@metamask/object-multiplex>readable-stream": true - } - }, - "@metamask/object-multiplex>end-of-stream": { - "packages": { - "@metamask/object-multiplex>once": true, - "browserify>process": true - } - }, - "@metamask/object-multiplex>once": { - "packages": { - "@metamask/object-multiplex>once>wrappy": true + "@metamask/object-multiplex>readable-stream": true, + "pump>end-of-stream": true, + "pump>once": true } }, "@metamask/object-multiplex>readable-stream": { @@ -106,10 +95,10 @@ "@metamask/providers>extension-port-stream": true, "@metamask/providers>is-stream": true, "@metamask/providers>json-rpc-middleware-stream": true, - "@metamask/providers>pump": true, "eslint>fast-deep-equal": true, "eth-rpc-errors": true, - "json-rpc-engine": true + "json-rpc-engine": true, + "pump": true } }, "@metamask/providers>@metamask/safe-event-emitter": { @@ -170,14 +159,6 @@ "@metamask/providers>json-rpc-middleware-stream>readable-stream>safe-buffer": true } }, - "@metamask/providers>pump": { - "packages": { - "@metamask/object-multiplex>end-of-stream": true, - "@metamask/object-multiplex>once": true, - "browserify>browser-resolve": true, - "browserify>process": true - } - }, "@metamask/utils": { "globals": { "TextDecoder": true, @@ -346,6 +327,25 @@ "browserify>events": true } }, + "pump": { + "packages": { + "browserify>browser-resolve": true, + "browserify>process": true, + "pump>end-of-stream": true, + "pump>once": true + } + }, + "pump>end-of-stream": { + "packages": { + "browserify>process": true, + "pump>once": true + } + }, + "pump>once": { + "packages": { + "pump>once>wrappy": true + } + }, "superstruct": { "globals": { "console.warn": true, diff --git a/packages/snaps-execution-environments/lavamoat/build-system/policy.json b/packages/snaps-execution-environments/lavamoat/build-system/policy.json index 93a7525961..188a1a32d8 100644 --- a/packages/snaps-execution-environments/lavamoat/build-system/policy.json +++ b/packages/snaps-execution-environments/lavamoat/build-system/policy.json @@ -988,19 +988,6 @@ "@lavamoat/lavapack>readable-stream": true } }, - "@metamask/object-multiplex>end-of-stream": { - "globals": { - "process.nextTick": true - }, - "packages": { - "@metamask/object-multiplex>once": true - } - }, - "@metamask/object-multiplex>once": { - "packages": { - "@metamask/object-multiplex>once>wrappy": true - } - }, "@wdio/mocha-framework>mocha>supports-color": { "builtin": { "os.release": true, @@ -1292,12 +1279,12 @@ "process.platform": true }, "packages": { - "@metamask/object-multiplex>once": true, "browserify>glob>fs.realpath": true, "browserify>glob>inflight": true, "browserify>glob>minimatch": true, "browserify>glob>path-is-absolute": true, - "browserify>inherits": true + "browserify>inherits": true, + "pump>once": true } }, "browserify>glob>fs.realpath": { @@ -1330,8 +1317,8 @@ "process.nextTick": true }, "packages": { - "@metamask/object-multiplex>once": true, - "@metamask/object-multiplex>once>wrappy": true + "pump>once": true, + "pump>once>wrappy": true } }, "browserify>glob>minimatch": { @@ -1988,9 +1975,9 @@ }, "packages": { "@lavamoat/lavapack>readable-stream": true, - "@metamask/object-multiplex>end-of-stream": true, "browserify>inherits": true, - "lavamoat-browserify>duplexify>stream-shift": true + "lavamoat-browserify>duplexify>stream-shift": true, + "pump>end-of-stream": true } }, "lavamoat-browserify>through2": { @@ -2215,6 +2202,19 @@ "depcheck>@babel/traverse": true } }, + "pump>end-of-stream": { + "globals": { + "process.nextTick": true + }, + "packages": { + "pump>once": true + } + }, + "pump>once": { + "packages": { + "pump>once>wrappy": true + } + }, "terser": { "globals": { "Buffer": true, diff --git a/packages/snaps-execution-environments/package.json b/packages/snaps-execution-environments/package.json index cb28409dbb..3310340b2b 100644 --- a/packages/snaps-execution-environments/package.json +++ b/packages/snaps-execution-environments/package.json @@ -54,6 +54,7 @@ "eth-rpc-errors": "^4.0.3", "json-rpc-engine": "^6.1.0", "nanoid": "^3.1.31", + "pump": "^3.0.0", "superstruct": "^1.0.3" }, "devDependencies": { diff --git a/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts b/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts index 453e348d57..9154502d9d 100644 --- a/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/iframe/IFrameSnapExecutor.ts @@ -2,7 +2,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import type { BasePostMessageStream } from '@metamask/post-message-stream'; import { WindowPostMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import { pipeline } from 'stream'; +import pump from 'pump'; import { BaseSnapExecutor } from '../common/BaseSnapExecutor'; import { log } from '../logging'; @@ -27,7 +27,7 @@ export class IFrameSnapExecutor extends BaseSnapExecutor { log('Worker: Connecting to parent.'); const mux = new ObjectMultiplex(); - pipeline(stream, mux, stream, (error) => { + pump(stream, mux, stream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts b/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts index dfb8f9e97c..c51a717679 100644 --- a/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/node-process/ChildProcessSnapExecutor.ts @@ -1,7 +1,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import { ProcessMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import { pipeline } from 'stream'; +import pump from 'pump'; import { BaseSnapExecutor } from '../common/BaseSnapExecutor'; import { log } from '../logging'; @@ -12,7 +12,7 @@ export class ChildProcessSnapExecutor extends BaseSnapExecutor { const parentStream = new ProcessMessageStream(); const mux = new ObjectMultiplex(); - pipeline(parentStream, mux as any, parentStream, (error) => { + pump(parentStream, mux as any, parentStream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts b/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts index 51770438ed..e7c5c12f6e 100644 --- a/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/node-thread/ThreadSnapExecutor.ts @@ -1,7 +1,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import { ThreadMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import { pipeline } from 'stream'; +import pump from 'pump'; import { BaseSnapExecutor } from '../common/BaseSnapExecutor'; import { log } from '../logging'; @@ -12,7 +12,7 @@ export class ThreadSnapExecutor extends BaseSnapExecutor { const parentStream = new ThreadMessageStream(); const mux = new ObjectMultiplex(); - pipeline(parentStream, mux as any, parentStream, (error) => { + pump(parentStream, mux as any, parentStream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts b/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts index 66252966a9..edaedd73bf 100644 --- a/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/webworker/executor/WebWorkerSnapExecutor.ts @@ -2,7 +2,7 @@ import ObjectMultiplex from '@metamask/object-multiplex'; import type { BasePostMessageStream } from '@metamask/post-message-stream'; import { WebWorkerPostMessageStream } from '@metamask/post-message-stream'; import { logError, SNAP_STREAM_NAMES } from '@metamask/snaps-utils'; -import { pipeline } from 'stream'; +import pump from 'pump'; import { BaseSnapExecutor } from '../../common/BaseSnapExecutor'; import { log } from '../../logging'; @@ -22,7 +22,7 @@ export class WebWorkerSnapExecutor extends BaseSnapExecutor { log('Worker: Connecting to parent.'); const mux = new ObjectMultiplex(); - pipeline(stream, mux, stream, (error) => { + pump(stream, mux, stream, (error) => { if (error) { logError(`Parent stream failure, closing worker.`, error); } diff --git a/packages/snaps-simulator/jest.config.js b/packages/snaps-simulator/jest.config.js index a4b6ef1246..6062336a6c 100644 --- a/packages/snaps-simulator/jest.config.js +++ b/packages/snaps-simulator/jest.config.js @@ -5,10 +5,10 @@ const baseConfig = require('../../jest.config.base'); module.exports = deepmerge(baseConfig, { coverageThreshold: { global: { - branches: 72.88, - functions: 80.41, - lines: 90.13, - statements: 89.98, + branches: 74.13, + functions: 80.85, + lines: 90.17, + statements: 90, }, }, setupFiles: ['./jest.setup.js'], diff --git a/packages/snaps-simulator/package.json b/packages/snaps-simulator/package.json index c3106e4f93..3b315fcf5b 100644 --- a/packages/snaps-simulator/package.json +++ b/packages/snaps-simulator/package.json @@ -72,6 +72,7 @@ "json-rpc-engine": "^6.1.0", "json-rpc-middleware-stream": "^4.2.0", "monaco-editor": "^0.38.0", + "pump": "^3.0.0", "react": "^18.2.0", "react-dnd": "^16.0.1", "react-dom": "^18.2.0", @@ -99,6 +100,7 @@ "@types/express": "^4.17.17", "@types/jest": "^27.5.1", "@types/node": "18.14.2", + "@types/pump": "^1.1.1", "@types/react": "^18.2.5", "@types/react-dom": "^18.2.3", "@types/webpack-env": "^1.18.1", diff --git a/packages/snaps-simulator/src/features/simulation/sagas.ts b/packages/snaps-simulator/src/features/simulation/sagas.ts index 14771ab65a..e68b9c4b24 100644 --- a/packages/snaps-simulator/src/features/simulation/sagas.ts +++ b/packages/snaps-simulator/src/features/simulation/sagas.ts @@ -29,9 +29,9 @@ import { getSafeJson } from '@metamask/utils'; import type { PayloadAction } from '@reduxjs/toolkit'; import { JsonRpcEngine } from 'json-rpc-engine'; import { createEngineStream } from 'json-rpc-middleware-stream'; +import pump from 'pump'; import type { SagaIterator } from 'redux-saga'; import { all, call, put, select, takeLatest } from 'redux-saga/effects'; -import { pipeline } from 'stream'; import { runSaga } from '../../store/middleware'; import { getSnapId, getSrp, setSnapId } from '../configuration'; @@ -168,13 +168,11 @@ export function* initSaga({ payload }: PayloadAction) { }), setupSnapProvider: (_snapId, rpcStream) => { const mux = setupMultiplex(rpcStream, 'snapStream'); - const stream = mux.createStream('metamask-provider'); + const stream = mux.createStream( + 'metamask-provider', + ) as unknown as pump.Stream; const providerStream = createEngineStream({ engine }); - pipeline(stream, providerStream, stream, (error) => { - if (error) { - logError(`Provider stream failure.`, error); - } - }); + pump(stream, providerStream, stream); }, }); diff --git a/yarn.lock b/yarn.lock index 065b93aaef..73375803eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5068,6 +5068,7 @@ __metadata: "@types/jest": ^27.5.1 "@types/mocha": ^10.0.1 "@types/node": 18.14.2 + "@types/pump": ^1.1.1 "@types/readable-stream": ^2.3.15 "@types/tar-stream": ^2.2.2 "@typescript-eslint/eslint-plugin": ^5.42.1 @@ -5106,6 +5107,7 @@ __metadata: nanoid: ^3.1.31 prettier: ^2.7.1 prettier-plugin-packagejson: ^2.2.11 + pump: ^3.0.0 readable-web-to-node-stream: ^3.0.2 rimraf: ^4.1.2 tar-stream: ^2.2.0 @@ -5185,6 +5187,7 @@ __metadata: nanoid: ^3.1.31 prettier: ^2.7.1 prettier-plugin-packagejson: ^2.2.11 + pump: ^3.0.0 rimraf: ^4.1.2 serve-handler: ^6.1.5 ses: ^0.18.7 @@ -5341,6 +5344,7 @@ __metadata: "@types/express": ^4.17.17 "@types/jest": ^27.5.1 "@types/node": 18.14.2 + "@types/pump": ^1.1.1 "@types/react": ^18.2.5 "@types/react-dom": ^18.2.3 "@types/webpack-env": ^1.18.1 @@ -5380,6 +5384,7 @@ __metadata: prettier: ^2.7.1 prettier-plugin-packagejson: ^2.2.11 process: ^0.11.10 + pump: ^3.0.0 react: ^18.2.0 react-dnd: ^16.0.1 react-dom: ^18.2.0 @@ -7260,6 +7265,15 @@ __metadata: languageName: node linkType: hard +"@types/pump@npm:^1.1.1": + version: 1.1.1 + resolution: "@types/pump@npm:1.1.1" + dependencies: + "@types/node": "*" + checksum: dd4a1485f2f6052cacb71a94b48d9f360e07a2fc3fac03782ae4caa9856e6df7017ee89515d70ecefcfe281553311cde4a3748219c9fcd757fdb77f3a47e0f29 + languageName: node + linkType: hard + "@types/qs@npm:*": version: 6.9.7 resolution: "@types/qs@npm:6.9.7"