From 4a855eca2afb7ff1e7f562be7ef53093e8b2af91 Mon Sep 17 00:00:00 2001 From: Vlad Frangu Date: Tue, 27 Aug 2024 18:33:38 +0300 Subject: [PATCH] fix(push-data): passing the item via stdin works again (#617) Previously, doing `apify actor get-input | apify actor push-data` did not work. Now it does again. --- src/commands/actor/push-data.ts | 11 +---------- src/lib/apify_command.ts | 8 -------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/commands/actor/push-data.ts b/src/commands/actor/push-data.ts index 5834c914..580e466b 100644 --- a/src/commands/actor/push-data.ts +++ b/src/commands/actor/push-data.ts @@ -20,24 +20,15 @@ export class PushDataCommand extends ApifyCommand { }), }; - private stdin?: string; - - override async init() { - await super.init(); - // Read data from stdin of the command - this.stdin = await this.readStdin(process.stdin); - } - async run() { const { item } = this.args; const apifyClient = await getApifyStorageClient(); const defaultStoreId = getDefaultStorageId(APIFY_STORAGE_TYPES.DATASET); - const data = item || this.stdin; let parsedData: Record | Record[]; try { - parsedData = JSON.parse(data!); + parsedData = JSON.parse(item!); } catch (err) { throw new Error(`Failed to parse data as JSON string: ${(err as Error).message}`); } diff --git a/src/lib/apify_command.ts b/src/lib/apify_command.ts index fd323fd2..9641ed05 100644 --- a/src/lib/apify_command.ts +++ b/src/lib/apify_command.ts @@ -2,7 +2,6 @@ import process from 'node:process'; import { Command, type Interfaces, loadHelpClass } from '@oclif/core'; -import { readStdin } from './commands/read-stdin.js'; import { COMMANDS_WITHIN_ACTOR, LANGUAGE } from './consts.js'; import { maybeTrackTelemetry } from './telemetry.js'; import { type KeysToCamelCase, argsToCamelCase, detectLocalActorLanguage } from './utils.js'; @@ -73,13 +72,6 @@ export abstract class ApifyCommand extends Command { return super.finally(err); } - /** - * Reads data on standard input as a string. - */ - async readStdin(stdinStream: typeof process.stdin) { - return readStdin(stdinStream); - } - async printHelp(customCommand?: string) { const HelpCommand = await loadHelpClass(this.config); const help = new HelpCommand(this.config);