apify-cli 1.10.1-beta.6 → 1.10.1-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from"node:process";import t from"chalk";import n from"indent-string";import r from"widest-line";import i from"wrap-ansi";import a,{basename as s,dirname as c,isAbsolute as l,join as u,relative as f,resolve as p,sep as m}from"node:path";import{inspect as h,parseArgs as g,promisify as _}from"node:util";import{gt as v,gte as y,minVersion as b,satisfies as x}from"semver";import{appendFileSync as S,chmodSync as C,constants as w,copyFileSync as T,createWriteStream as E,existsSync as D,fstat as ee,mkdirSync as O,openSync as k,readFileSync as A,readdirSync as te,realpathSync as j,renameSync as M,rmSync as N,statSync as ne,unlinkSync as re,writeFileSync as P}from"node:fs";import ie from"string-width";import ae from"strip-ansi";import{once as oe}from"node:events";import{homedir as se,platform as ce}from"node:os";import le,{isCI as ue}from"ci-info";import{ACTOR_ENV_VARS as F,ACTOR_JOB_STATUSES as I,ACTOR_JOB_TERMINAL_STATUSES as de,ACTOR_NAME as fe,ACTOR_SOURCE_TYPES as pe,APIFY_ENV_VARS as L,KEY_VALUE_STORE_KEYS as me,LOCAL_ACTOR_ENV_VARS as he,LOCAL_STORAGE_SUBDIRS as ge,MAX_MULTIFILE_BYTES as _e,META_ORIGINS as ve,SOURCE_FILE_FORMATS as ye}from"@apify/consts";import{jaroWinkler as be}from"@skyra/jaro-winkler";import xe from"js-levenshtein";import{Result as Se,err as Ce,none as we,ok as Te,some as Ee}from"@sapphire/result";import{execa as De}from"execa";import{access as Oe,appendFile as ke,mkdir as R,readFile as z,readdir as Ae,rename as je,rm as Me,stat as B,symlink as Ne,unlink as Pe,writeFile as V}from"node:fs/promises";import Fe from"configparser";import Ie from"@inquirer/input";import Le from"which";import{createHmacSignature as Re,cryptoRandomObjectId as ze}from"@apify/utilities";import{execSync as Be,spawn as Ve}from"node:child_process";import{DurationFormatter as He,Time as Ue,TimeTypes as We}from"@sapphire/duration";import{Timestamp as Ge}from"@sapphire/timestamp";import Ke from"adm-zip";import qe from"ajv/dist/2019.js";import{ApifyClient as Je,DownloadItemsFormat as H}from"apify-client";import{ZipArchive as Ye}from"archiver";import Xe,{AxiosHeaders as Ze}from"axios";import Qe from"escape-string-regexp";import $e from"ignore";import{getEncoding as et}from"istextorbinary";import tt,{Mime as nt}from"mime";import rt from"mime/types/other.js";import it from"mime/types/standard.js";import{glob as at}from"tinyglobby";import{calculateRunDynamicMemory as ot}from"@apify/actor-memory-expression";import{Separator as st,createPrompt as ct,isEnterKey as lt,makeTheme as ut,useKeypress as dt,usePrefix as ft,useState as pt}from"@inquirer/core";import{pipeline as mt}from"node:stream/promises";import{MemoryStorage as ht}from"@crawlee/memory-storage";import{compile as gt}from"json-schema-to-typescript";import{validateInputSchema as _t,validateInputUsingValidator as vt}from"@apify/input_schema";import{getDatasetSchemaValidator as yt,getKeyValueStoreSchemaValidator as bt,getOutputSchemaValidator as xt}from"@apify/json_schemas";import St from"cli-table3";import{downloadTemplate as Ct}from"giget";import wt from"jju";import Tt from"open";import{fetchManifest as Et,manifestUrl as Dt,wrapperManifestUrl as Ot}from"@apify/actor-templates";import kt from"computer-name";import At from"@inquirer/password";import jt from"@inquirer/select";import{createServer as Mt}from"node:http";import Nt from"node:assert";import{ReadStream as Pt}from"node:tty";import{setTimeout as Ft}from"node:timers/promises";import It from"detect-indent";import{fileURLToPath as Lt}from"node:url";import Rt from"@root/walk";import zt from"handlebars";function internalLog(e){e.stdoutOutput&&console.log(...e.stdoutOutput),e.stderrOutput&&console.error(...e.stderrOutput)}function simpleLog(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[e.message]})}function error(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.red(`Error:`),e.message]})}function warning(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.yellow.bold(`Warning:`),e.message]})}function success(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.green(`Success:`),e.message]})}function run(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.gray(`Run:`),e.message]})}function info(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.white(`Info:`),e.message]})}function detectInstallMethod(){if(process.env.APIFY_CLI_BUNDLE)return`bundle`;let e=process.argv[1];if(!e)return warning({message:`Failed to detect install method of CLI, assuming npm`}),`npm`;let t=j(e);return process.env.VOLTA_HOME&&t.includes(process.env.VOLTA_HOME)?`volta`:t.includes(`homebrew/Cellar`)||t.includes(`linuxbrew/Cellar`)?`homebrew`:process.env.PNPM_HOME&&t.includes(process.env.PNPM_HOME)?`pnpm`:process.env.BUN_INSTALL&&t.includes(process.env.BUN_INSTALL)?`bun`:`npm`}function getRuntimeInfo(){return process.versions.bun?{runtime:`bun`,version:process.versions.bun,nodeVersion:process.versions.node}:process.versions.deno?{runtime:`deno`,version:process.versions.deno,nodeVersion:process.versions.node}:{runtime:`node`,version:process.versions.node}}let Bt=null;function useCLIMetadata(){if(Bt)return Bt;let e=detectInstallMethod(),t=getRuntimeInfo();return Bt={version:`1.10.1-beta.
|
|
1
|
+
import e from"node:process";import t from"chalk";import n from"indent-string";import r from"widest-line";import i from"wrap-ansi";import a,{basename as s,dirname as c,isAbsolute as l,join as u,relative as f,resolve as p,sep as m}from"node:path";import{inspect as h,parseArgs as g,promisify as _}from"node:util";import{gt as v,gte as y,minVersion as b,satisfies as x}from"semver";import{appendFileSync as S,chmodSync as C,constants as w,copyFileSync as T,createWriteStream as E,existsSync as D,fstat as ee,mkdirSync as O,openSync as k,readFileSync as A,readdirSync as te,realpathSync as j,renameSync as M,rmSync as N,statSync as ne,unlinkSync as re,writeFileSync as P}from"node:fs";import ie from"string-width";import ae from"strip-ansi";import{once as oe}from"node:events";import{homedir as se,platform as ce}from"node:os";import le,{isCI as ue}from"ci-info";import{ACTOR_ENV_VARS as F,ACTOR_JOB_STATUSES as I,ACTOR_JOB_TERMINAL_STATUSES as de,ACTOR_NAME as fe,ACTOR_SOURCE_TYPES as pe,APIFY_ENV_VARS as L,KEY_VALUE_STORE_KEYS as me,LOCAL_ACTOR_ENV_VARS as he,LOCAL_STORAGE_SUBDIRS as ge,MAX_MULTIFILE_BYTES as _e,META_ORIGINS as ve,SOURCE_FILE_FORMATS as ye}from"@apify/consts";import{jaroWinkler as be}from"@skyra/jaro-winkler";import xe from"js-levenshtein";import{Result as Se,err as Ce,none as we,ok as Te,some as Ee}from"@sapphire/result";import{execa as De}from"execa";import{access as Oe,appendFile as ke,mkdir as R,readFile as z,readdir as Ae,rename as je,rm as Me,stat as B,symlink as Ne,unlink as Pe,writeFile as V}from"node:fs/promises";import Fe from"configparser";import Ie from"@inquirer/input";import Le from"which";import{createHmacSignature as Re,cryptoRandomObjectId as ze}from"@apify/utilities";import{execSync as Be,spawn as Ve}from"node:child_process";import{DurationFormatter as He,Time as Ue,TimeTypes as We}from"@sapphire/duration";import{Timestamp as Ge}from"@sapphire/timestamp";import Ke from"adm-zip";import qe from"ajv/dist/2019.js";import{ApifyClient as Je,DownloadItemsFormat as H}from"apify-client";import{ZipArchive as Ye}from"archiver";import Xe,{AxiosHeaders as Ze}from"axios";import Qe from"escape-string-regexp";import $e from"ignore";import{getEncoding as et}from"istextorbinary";import tt,{Mime as nt}from"mime";import rt from"mime/types/other.js";import it from"mime/types/standard.js";import{glob as at}from"tinyglobby";import{calculateRunDynamicMemory as ot}from"@apify/actor-memory-expression";import{Separator as st,createPrompt as ct,isEnterKey as lt,makeTheme as ut,useKeypress as dt,usePrefix as ft,useState as pt}from"@inquirer/core";import{pipeline as mt}from"node:stream/promises";import{MemoryStorage as ht}from"@crawlee/memory-storage";import{compile as gt}from"json-schema-to-typescript";import{validateInputSchema as _t,validateInputUsingValidator as vt}from"@apify/input_schema";import{getDatasetSchemaValidator as yt,getKeyValueStoreSchemaValidator as bt,getOutputSchemaValidator as xt}from"@apify/json_schemas";import St from"cli-table3";import{downloadTemplate as Ct}from"giget";import wt from"jju";import Tt from"open";import{fetchManifest as Et,manifestUrl as Dt,wrapperManifestUrl as Ot}from"@apify/actor-templates";import kt from"computer-name";import At from"@inquirer/password";import jt from"@inquirer/select";import{createServer as Mt}from"node:http";import Nt from"node:assert";import{ReadStream as Pt}from"node:tty";import{setTimeout as Ft}from"node:timers/promises";import It from"detect-indent";import{fileURLToPath as Lt}from"node:url";import Rt from"@root/walk";import zt from"handlebars";function internalLog(e){e.stdoutOutput&&console.log(...e.stdoutOutput),e.stderrOutput&&console.error(...e.stderrOutput)}function simpleLog(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[e.message]})}function error(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.red(`Error:`),e.message]})}function warning(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.yellow.bold(`Warning:`),e.message]})}function success(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.green(`Success:`),e.message]})}function run(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.gray(`Run:`),e.message]})}function info(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.white(`Info:`),e.message]})}function detectInstallMethod(){if(process.env.APIFY_CLI_BUNDLE)return`bundle`;let e=process.argv[1];if(!e)return warning({message:`Failed to detect install method of CLI, assuming npm`}),`npm`;let t=j(e);return process.env.VOLTA_HOME&&t.includes(process.env.VOLTA_HOME)?`volta`:t.includes(`homebrew/Cellar`)||t.includes(`linuxbrew/Cellar`)?`homebrew`:process.env.PNPM_HOME&&t.includes(process.env.PNPM_HOME)?`pnpm`:process.env.BUN_INSTALL&&t.includes(process.env.BUN_INSTALL)?`bun`:`npm`}function getRuntimeInfo(){return process.versions.bun?{runtime:`bun`,version:process.versions.bun,nodeVersion:process.versions.node}:process.versions.deno?{runtime:`deno`,version:process.versions.deno,nodeVersion:process.versions.node}:{runtime:`node`,version:process.versions.node}}let Bt=null;function useCLIMetadata(){if(Bt)return Bt;let e=detectInstallMethod(),t=getRuntimeInfo();return Bt={version:`1.10.1-beta.7`,hash:`adff63e3824d01da41befa7de5567472d313e6d9`,arch:process.env.APIFY_BUNDLE_ARCH??process.arch,platform:process.platform===`win32`?`windows`:process.platform,runtime:t,extraRuntimeData:t.nodeVersion?`(emulating node ${t.nodeVersion})`:``,installMethod:e,get fullVersionString(){return`apify-cli/${this.version} (${this.hash.slice(0,7)}) running on ${this.platform}-${this.arch} with ${this.runtime.runtime}-${t.version}${this.extraRuntimeData?` ${this.extraRuntimeData}`:``}, installed via ${this.installMethod}`},get isBeta(){return this.version.includes(`beta`)||this.version===`0.0.0`}},e===`bundle`&&(Bt.installPath=c(process.execPath)),Bt}function cliDebugPrint(e,...n){process.env.APIFY_CLI_DEBUG&&console.error(t.gray(`[${e}]`),...n)}const Vt=[`apify`,`actor`];function unixWrapperScript(e){return[`#!/bin/sh`,`DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"`,`APIFY_CLI_ENTRYPOINT=${e} exec "$DIR/apify-cli" "$@"`,``].join(`
|
|
2
2
|
`)}function windowsCmdWrapperScript(e){return[`@echo off`,`setlocal`,`set "APIFY_CLI_ENTRYPOINT=${e}"`,`"%~dp0apify-cli.exe" %*`,``].join(`\r
|
|
3
3
|
`)}function windowsPowershellWrapperScript(e){return[`#!/usr/bin/env pwsh`,`$prev = $env:APIFY_CLI_ENTRYPOINT`,`$env:APIFY_CLI_ENTRYPOINT = "${e}"`,`try {`,` & "$PSScriptRoot\\apify-cli.exe" @args`,`} finally {`,` $env:APIFY_CLI_ENTRYPOINT = $prev`,`}`,`exit $LASTEXITCODE`,``].join(`\r
|
|
4
4
|
`)}function atomicWriteSync(t,n,r){let i=`${t}.${e.pid}.tmp`;try{P(i,n),r!==void 0&&C(i,r),M(i,t)}catch(e){try{N(i,{force:!0})}catch{}throw e}}function atomicCopySync(t,n,r){let i=`${n}.${e.pid}.tmp`;try{T(t,i),r!==void 0&&C(i,r),M(i,n)}catch(e){try{N(i,{force:!0})}catch{}throw e}}function writeEntrypointShims(e,t){for(let n of Vt)atomicWriteSync(u(e,n),unixWrapperScript(n),493),t&&(atomicWriteSync(u(e,`${n}.cmd`),windowsCmdWrapperScript(n)),atomicWriteSync(u(e,`${n}.ps1`),windowsPowershellWrapperScript(n)))}function migrateLegacyBundleInstallIfNeeded(){let t=useCLIMetadata();if(t.installMethod!==`bundle`)return;let n=t.platform===`windows`,r=c(e.execPath),i=s(e.execPath).replace(/\.exe$/i,``).toLowerCase();if(n)for(let e of Vt){let t=u(r,`${e}.exe.old`);if(D(t))try{N(t,{force:!0}),cliDebugPrint(`[migration] removed stale legacy binary`,t)}catch(e){cliDebugPrint(`[migration] failed to remove stale legacy binary`,{stalePath:t,err:e})}}if(i===`apify-cli`||!Vt.includes(i))return;cliDebugPrint(`[migration] legacy multi-bundle install detected, migrating to single bundle`,{binDir:r,selfName:i});let a=u(r,`apify-cli${n?`.exe`:``}`);try{atomicCopySync(e.execPath,a,n?void 0:493),cliDebugPrint(`[migration] copied current bundle to`,a)}catch(e){cliDebugPrint(`[migration] failed to copy current bundle, will retry on next run`,{err:e});return}try{writeEntrypointShims(r,n),cliDebugPrint(`[migration] wrote entrypoint shims`)}catch(e){cliDebugPrint(`[migration] failed to write entrypoint shims, will retry on next run`,{err:e})}if(n){for(let t of Vt){let n=u(r,`${t}.exe`);if(D(n))try{p(n)===p(e.execPath)?(M(n,`${n}.old`),cliDebugPrint(`[migration] renamed running legacy binary`,n)):N(n,{force:!0})}catch(e){try{M(n,`${n}.old`)}catch{}cliDebugPrint(`[migration] failed to remove legacy binary`,{legacyBinaryPath:n,err:e})}}let t=u(r,`upgrade.ps1`);try{N(t,{force:!0}),cliDebugPrint(`[migration] removed upgrade script, it will be re-downloaded on the next upgrade`)}catch(e){cliDebugPrint(`[migration] failed to remove upgrade script`,{upgradeScriptPath:t,err:e})}}cliDebugPrint(`[migration] migration to single bundle complete`)}let Ht;function getMaxLineWidth(){if(Ht)return Ht;let e=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(e))Ht=e;else if(!process.stdout.isTTY)Ht=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;Ht=e<1?80:e<40?40:e}return Ht}var BaseCommandRenderer=class{command;entrypoint;constructor(e,t){this.entrypoint=e,this.command=t}pushShortDescription(e){let n=this.command.interactive?`${t.yellow(`[INTERACTIVE]`)} `:``;this.command.shortDescription?e.push(`${n}${this.command.shortDescription}`,``):this.command.description&&e.push(`${n}${this.command.description.split(`
|
|
@@ -26,7 +26,7 @@ import e from"node:process";import t from"chalk";import n from"indent-string";im
|
|
|
26
26
|
`)}case 8:{let{firstUse:e,secondUse:n}=this.metadata;return t.gray(`Flag ${t.white.bold(`--${e}`)} and ${t.white.bold(`--${n}`)} cannot both request that their value comes from standard input at the same time.`)}case 5:{let e=`--${this.metadata.flag}`,n=this.metadata.choices;return t.gray(`Invalid value for flag ${t.white.bold(e)}. Expected one of: ${n}`)}default:{let e=useCLIMetadata();return[`The CLI encountered an unhandled argument parsing error!`,`Please report this issue at https://github.com/apify/apify-cli/issues, and provide the following information:`,``,`- Error code: ${this.code} (${Jt[this.code]})`,`- Error metadata: ${JSON.stringify(this.metadata)}`,``,`- Stack:\n${this.stack}`,``,`- Arguments (!!!only provide these as is if there is no sensitive information!!!):`,` ${JSON.stringify(process.argv.slice(2))}`,``,`- CLI version: \`${e.fullVersionString}\``,`- CLI debug logs (process.env.APIFY_CLI_DEBUG): ${process.env.APIFY_CLI_DEBUG?`Enabled`:`Disabled`}`,`- Stdin data? ${fn?`Yes`:`No`}`].join(`
|
|
27
27
|
`)}}}static buildMessageFromFlagData(e){let n=[`Flag ${t.white.bold(e.shortForm?`-${e.name}`:`--${e.name}`)}`];return e.ambiguousFlag?(n.push(`is ambiguous (meaning the provided value could be interpreted as a flag too).`),e.ambiguousMessage?n.push(`\n${e.ambiguousMessage.split(`
|
|
28
28
|
`).map(e=>` ${e}`).join(`
|
|
29
|
-
`)}`):n.push(`To solve this, provide the flag like this: --${e.name}=<value>`)):e.expectsValue?n.push(`expects a value`):n.push(`does not take an argument`),n.map(e=>t.gray(e)).join(` `)}static into(e,t){if(e instanceof CommandError)return e;if(e instanceof Error&&`code`in e){let n=e;switch(n.code){case`ERR_PARSE_ARGS_INVALID_OPTION_VALUE`:return new CommandError({code:0,message:n.message,command:t});case`ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL`:return new CommandError({code:1,message:n.message,command:t});case`ERR_PARSE_ARGS_UNKNOWN_OPTION`:return new CommandError({code:2,message:n.message,command:t});default:return new CommandError({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}}return new CommandError({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}};const Yt=_(ee);let Xt;async function useStdin(){if(Xt)return Xt;let t=e.stdin,n={isTTY:t.isTTY,hasData:!1,waitDelay:0,stream:t},r=await Yt(0).then(t=>{if(cliDebugPrint(`useStdin`,{stat:t,isRegularFile:t.isFile(),isDirectory:t.isDirectory(),isBlockDevice:t.isBlockDevice(),isCharDevice:t.isCharacterDevice(),isSymbolicLink:t.isSymbolicLink(),isFIFO:t.isFIFO(),isSocket:t.isSocket()}),e.platform===`win32`){if((t.mode&w.S_IFIFO)===w.S_IFIFO)return 100;if(t.isFile())return 50}return t.isFIFO()||t.isFile()||(t.isSocket()?50:!1)}).catch(()=>!1);return cliDebugPrint(`useStdin`,{hasData:n.hasData,waitDelay:n.waitDelay,isTTY:n.isTTY,pipedIn:r,readableEnded:t.readableEnded}),(!t.isTTY||r!==!1&&(t.isTTY!==void 0||!t.readableEnded))&&(n.hasData=!0),typeof r==`number`&&(n.waitDelay=r),Xt=n,n}async function readStdin(){let e=await useStdin(),{hasData:t,waitDelay:n,stream:r}=e;if(!t)return;let i=[],a=new AbortController,s=null;n&&(s=setTimeout(()=>{a.abort()},n).unref());let onData=e=>{i.push(e),s&&=(clearTimeout(s),null)};r.on(`data`,onData);try{await oe(r,`end`,{signal:a.signal})}catch(e){if(e.name===`AbortError`)return}finally{r.off(`data`,onData),r.pause()}s&&clearTimeout(s),e.hasData=!1;let c=Buffer.concat(i);if(c.length)return c}var Zt={node:`>=22`};const Qt=`storage`,$t={actorSpecification:1,name:null,version:`0.0`,buildTag:`latest`,environmentVariables:{}},en=Date.UTC(2026,9,1),tn=[`SIGINT`,`SIGTERM`,`SIGHUP`],GLOBAL_CONFIGS_FOLDER=()=>{let t=u(se(),`.apify`);return e.env.__APIFY_INTERNAL_TEST_AUTH_PATH__?u(t,e.env.__APIFY_INTERNAL_TEST_AUTH_PATH__):t},AUTH_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`auth.json`),SECRETS_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`secrets.json`),STATE_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`state.json`),TELEMETRY_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`telemetry.json`),nn=`.actor`,W=u(nn,`actor.json`),rn=Zt.node,an=le.GITHUB_ACTIONS?`${e.env.GITHUB_SERVER_URL}/${e.env.GITHUB_REPOSITORY}/actions/runs/${e.env.GITHUB_RUN_ID}`:void 0,on={"X-Apify-Request-Origin":le.isCI?ve.CI:ve.CLI,...an&&{"X-Apify-Github-Actions-Run-Url":an}},sn=`3.11.0`;function migrateStateV0ToV1$1(e){if(e.version&&e.version>=1)return!1;let t=e;if(t.latestNpmVersionCheckedAt){let n=new Date(t.latestNpmVersionCheckedAt).getTime(),r=t.latestNpmVersion;cliDebugPrint(`LocalStateV0ToV1`,`Migrating state from v0 to v1`,{oldState:e,newState:{versionCheck:{lastChecked:n,lastVersion:r}}}),updateLocalState({version:1},e=>{e.versionCheck={lastChecked:n,lastVersion:r}})}return!0}const cn={version:1};function useLocalState(){let e=STATE_FILE_PATH();if(!D(e))return cn;let t=JSON.parse(A(e,`utf-8`));return migrateStateV0ToV1$1(t)?useLocalState():t}function updateLocalState(e,t){let n={...e};t(n);let r=STATE_FILE_PATH(),i=c(r);O(i,{recursive:!0}),P(STATE_FILE_PATH(),JSON.stringify(n,null,` `))}const ln=useCLIMetadata(),un=`Apify CLI/${ln.version} (https://github.com/apify/apify-cli)`,dn=[`https://1.1.1.1`,`https://8.8.8.8`];async function isOnline(e=500){let t=new AbortController,n=setTimeout(()=>{t.abort()},e),r=await Promise.any(dn.map(async e=>fetch(e,{signal:t.signal,headers:{"User-Agent":un},keepalive:!1}))).catch(()=>null);return clearTimeout(n),r?r.ok?(cliDebugPrint(`isOnline`,{state:`online`,site:r.url}),!0):(cliDebugPrint(`isOnline`,{state:`offline`}),!1):(cliDebugPrint(`isOnline`,{state:`timeout`}),!1)}async function getLatestVersion(e){let t=await fetch(`https://api.github.com/repos/apify/apify-cli/releases/latest`,{headers:{"User-Agent":un}});if(!t.ok)return cliDebugPrint(`useCLIVersionCheck`,`Failed to fetch latest version`,{statusCode:t.status,body:await t.text()}),warning({message:`Failed to fetch latest version of Apify CLI, using the cached version instead.`}),null;let n=(await t.json()).tag_name.replace(/^v/,``);return cliDebugPrint(`useCLIVersionCheck`,`Fetched latest version`,{version:n}),updateLocalState(e,e=>{e.versionCheck={lastChecked:Date.now(),lastVersion:n}}),n}function shouldSkipVersionCheck(){return
|
|
29
|
+
`)}`):n.push(`To solve this, provide the flag like this: --${e.name}=<value>`)):e.expectsValue?n.push(`expects a value`):n.push(`does not take an argument`),n.map(e=>t.gray(e)).join(` `)}static into(e,t){if(e instanceof CommandError)return e;if(e instanceof Error&&`code`in e){let n=e;switch(n.code){case`ERR_PARSE_ARGS_INVALID_OPTION_VALUE`:return new CommandError({code:0,message:n.message,command:t});case`ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL`:return new CommandError({code:1,message:n.message,command:t});case`ERR_PARSE_ARGS_UNKNOWN_OPTION`:return new CommandError({code:2,message:n.message,command:t});default:return new CommandError({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}}return new CommandError({code:9,message:`Unknown error: ${e instanceof Error?e.message:String(e)}`,command:t})}};const Yt=_(ee);let Xt;async function useStdin(){if(Xt)return Xt;let t=e.stdin,n={isTTY:t.isTTY,hasData:!1,waitDelay:0,stream:t},r=await Yt(0).then(t=>{if(cliDebugPrint(`useStdin`,{stat:t,isRegularFile:t.isFile(),isDirectory:t.isDirectory(),isBlockDevice:t.isBlockDevice(),isCharDevice:t.isCharacterDevice(),isSymbolicLink:t.isSymbolicLink(),isFIFO:t.isFIFO(),isSocket:t.isSocket()}),e.platform===`win32`){if((t.mode&w.S_IFIFO)===w.S_IFIFO)return 100;if(t.isFile())return 50}return t.isFIFO()||t.isFile()||(t.isSocket()?50:!1)}).catch(()=>!1);return cliDebugPrint(`useStdin`,{hasData:n.hasData,waitDelay:n.waitDelay,isTTY:n.isTTY,pipedIn:r,readableEnded:t.readableEnded}),(!t.isTTY||r!==!1&&(t.isTTY!==void 0||!t.readableEnded))&&(n.hasData=!0),typeof r==`number`&&(n.waitDelay=r),Xt=n,n}async function readStdin(){let e=await useStdin(),{hasData:t,waitDelay:n,stream:r}=e;if(!t)return;let i=[],a=new AbortController,s=null;n&&(s=setTimeout(()=>{a.abort()},n).unref());let onData=e=>{i.push(e),s&&=(clearTimeout(s),null)};r.on(`data`,onData);try{await oe(r,`end`,{signal:a.signal})}catch(e){if(e.name===`AbortError`)return}finally{r.off(`data`,onData),r.pause()}s&&clearTimeout(s),e.hasData=!1;let c=Buffer.concat(i);if(c.length)return c}var Zt={node:`>=22`};const Qt=`storage`,$t={actorSpecification:1,name:null,version:`0.0`,buildTag:`latest`,environmentVariables:{}},en=Date.UTC(2026,9,1),tn=[`SIGINT`,`SIGTERM`,`SIGHUP`],GLOBAL_CONFIGS_FOLDER=()=>{let t=u(se(),`.apify`);return e.env.__APIFY_INTERNAL_TEST_AUTH_PATH__?u(t,e.env.__APIFY_INTERNAL_TEST_AUTH_PATH__):t},AUTH_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`auth.json`),SECRETS_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`secrets.json`),STATE_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`state.json`),TELEMETRY_FILE_PATH=()=>u(GLOBAL_CONFIGS_FOLDER(),`telemetry.json`),nn=`.actor`,W=u(nn,`actor.json`),rn=Zt.node,an=le.GITHUB_ACTIONS?`${e.env.GITHUB_SERVER_URL}/${e.env.GITHUB_REPOSITORY}/actions/runs/${e.env.GITHUB_RUN_ID}`:void 0,on={"X-Apify-Request-Origin":le.isCI?ve.CI:ve.CLI,...an&&{"X-Apify-Github-Actions-Run-Url":an}},sn=`3.11.0`;function migrateStateV0ToV1$1(e){if(e.version&&e.version>=1)return!1;let t=e;if(t.latestNpmVersionCheckedAt){let n=new Date(t.latestNpmVersionCheckedAt).getTime(),r=t.latestNpmVersion;cliDebugPrint(`LocalStateV0ToV1`,`Migrating state from v0 to v1`,{oldState:e,newState:{versionCheck:{lastChecked:n,lastVersion:r}}}),updateLocalState({version:1},e=>{e.versionCheck={lastChecked:n,lastVersion:r}})}return!0}const cn={version:1};function useLocalState(){let e=STATE_FILE_PATH();if(!D(e))return cn;let t=JSON.parse(A(e,`utf-8`));return migrateStateV0ToV1$1(t)?useLocalState():t}function updateLocalState(e,t){let n={...e};t(n);let r=STATE_FILE_PATH(),i=c(r);O(i,{recursive:!0}),P(STATE_FILE_PATH(),JSON.stringify(n,null,` `))}const ln=useCLIMetadata(),un=`Apify CLI/${ln.version} (https://github.com/apify/apify-cli)`,dn=[`https://1.1.1.1`,`https://8.8.8.8`];async function isOnline(e=500){let t=new AbortController,n=setTimeout(()=>{t.abort()},e),r=await Promise.any(dn.map(async e=>fetch(e,{signal:t.signal,headers:{"User-Agent":un},keepalive:!1}))).catch(()=>null);return clearTimeout(n),r?r.ok?(cliDebugPrint(`isOnline`,{state:`online`,site:r.url}),!0):(cliDebugPrint(`isOnline`,{state:`offline`}),!1):(cliDebugPrint(`isOnline`,{state:`timeout`}),!1)}async function getLatestVersion(e){let t=await fetch(`https://api.github.com/repos/apify/apify-cli/releases/latest`,{headers:{"User-Agent":un}});if(!t.ok)return cliDebugPrint(`useCLIVersionCheck`,`Failed to fetch latest version`,{statusCode:t.status,body:await t.text()}),warning({message:`Failed to fetch latest version of Apify CLI, using the cached version instead.`}),null;let n=(await t.json()).tag_name.replace(/^v/,``);return cliDebugPrint(`useCLIVersionCheck`,`Fetched latest version`,{version:n}),updateLocalState(e,e=>{e.versionCheck={lastChecked:Date.now(),lastVersion:n}}),n}function shouldSkipVersionCheck(){return!(!process.env.APIFY_CLI_SKIP_UPDATE_CHECK||[`0`,`false`].includes(process.env.APIFY_CLI_SKIP_UPDATE_CHECK))}async function useCLIVersionCheck(e=!1){let t=useLocalState(),n=!t.versionCheck||Date.now()-t.versionCheck.lastChecked>864e5,r=e||n&&await isOnline(),i=r?await getLatestVersion(t):t.versionCheck?.lastVersion;if(!i)return{currentVersion:ln.version,latestVersion:`unknown`,shouldUpdate:!1,cacheHit:!1};let a=v(i,ln.version);return{currentVersion:ln.version,latestVersion:i,shouldUpdate:a,cacheHit:!r}}function useCommandSuggestions(e){let t=[...q.entries()].sort(([e],[t])=>e.localeCompare(t)),n=e.toLowerCase();return t.map(([e,t])=>{let r=e.toLowerCase(),i=e.split(` `),a=i[i.length-1].toLowerCase(),s=t.aliases?.includes(a)||t.hiddenAliases?.includes(a)||!1,c=xe(n,r),l=be(n,r),u=c<=2||l>=.975;return u?(cliDebugPrint(`useCommandSuggestions`,{inputString:n,lowercased:r,matches:u,levenshtein:c,jaroWinkler:l}),s?{string:`${r} (alias for ${t.name})`,distance:l}:{string:`${r}`,distance:l}):null}).filter(e=>e!==null).sort((e,t)=>t.distance-e.distance).map(e=>e.string)}const fn=await readStdin(),pn=useCLIMetadata(),mn=`Apify CLI/${pn.version} (https://github.com/apify/apify-cli)`;function processVersionCheck(t){pn.installMethod!==`bundle`&&(x(e.version,rn)||(error({message:`${t} CLI requires Node.js version ${rn}. Your current version is ${e.version}.`}),e.exit(1)))}function printCLIVersionAndExitIfFlagUsed(t){t.values.version===!0&&t.positionals.length===0&&(console.log(pn.fullVersionString),e.exit(0))}function printHelpAndExitIfFlagUsedOrNoCommandPassed(t,n){(t.values.help===!0&&t.positionals.length===0||t.positionals.length===0)&&(console.log(renderMainHelpMenu(n)),e.exit(0))}function handleCommandNotFound(n){let r=useCommandSuggestions(String(n)),i=t.gray(`Command ${t.whiteBright(n)} not found`);r.length&&(i+=`
|
|
30
30
|
`,i+=t.gray(`Did you mean: ${r.map(e=>t.whiteBright(e)).join(`, `)}?`)),error({message:i}),e.exit(1)}async function runVersionCheck(e,t){let n=q.get(`upgrade`);if([n.name,...n.aliases??[]].some(e=>t===e)){cliDebugPrint(`[VersionCheckMiddleware]`,`upgrade command detected, skipping version check`);return}if(shouldSkipVersionCheck()){cliDebugPrint(`[VersionCheckMiddleware]`,`skipping version check because APIFY_CLI_SKIP_UPDATE_CHECK is set`);return}await internalRunCommand(e,n,{flags_internalAutomaticCall:!0})}async function runCLI(t){migrateLegacyBundleInstallIfNeeded(),cliDebugPrint(`CLIMetadata`,{...pn,fullVersionString:pn.fullVersionString,argv:e.argv,cwd:e.cwd(),execPath:e.execPath});let n=e.argv.slice(2);cliDebugPrint(`ProcessArgv`,n);let r=g({allowPositionals:!0,strict:!1,options:{help:{type:`boolean`,short:`h`},version:{type:`boolean`,short:`v`}},args:n});printCLIVersionAndExitIfFlagUsed(r),printHelpAndExitIfFlagUsedOrNoCommandPassed(r,t),await runVersionCheck(t,r.positionals[0]),cliDebugPrint(`TopLevelOptions`,r);let i=r.positionals[0],a=-1;if(q.get(i)?.subcommands?.length){if(r.positionals[1]?.toLowerCase()===`help`)a=1;else if(r.positionals[2]?.toLowerCase()===`help`){let e=q.get(`${i} ${r.positionals[1]}`);e&&!e.args&&(a=2)}}if(a!==-1){let e=r.positionals[a],t=n.indexOf(e);t!==-1&&n.splice(t,1),!n.includes(`--help`)&&!n.includes(`-h`)&&n.push(`--help`),r.positionals.splice(a,1),r.values.help=!0}let s=r.positionals[1],c=!1,l=q.get(i);if(!l)return handleCommandNotFound(i);let u=l;if(l.subcommands?.length){if(!s)return l.printHelp();c=!0,u=q.get(`${i} ${s}`)}if(!u)return handleCommandNotFound(`${i} ${s}`);let f=[...n],p=f.indexOf(i);if(cliDebugPrint(`CommandNameIndex`,p),f.splice(p,1),c){let e=f.indexOf(s);cliDebugPrint(`SubcommandNameIndex`,e),f.splice(e,1)}cliDebugPrint(`RebuiltArgs`,f),cliDebugPrint(`CommandToRun`,u);let m=new u(t,c?`${l.name} ${s}`:l.name,i,c?s:void 0),h=m._buildParseArgsOption();cliDebugPrint(`ParserOptionsForCommand`,h);try{let e=g({...h,args:f});await m._run(e),cliDebugPrint(`CommandArgsResult`,e)}catch(t){error({message:U.into(t,u).getPrettyMessage()}),e.exit(1)}}const hn={output:e.stderr},gn=`confirm`,_n=`no-${gn}`;function stdinCheckWrapper(e,{errorMessageForStdin:t=`Please use the --${gn}/--${_n} flags to confirm the action.`}={}){return async(n,...r)=>{let{isTTY:i,hasData:a}=await useStdin(),s=n;if(ue||!i&&!a){if(s.providedConfirmFromStdin===void 0)throw Error(s.errorMessageForStdin??t);return s.providedConfirmFromStdin}return await e(n,...r)}}const vn=stdinCheckWrapper(async({message:e,validate:t,default:n})=>await Ie({message:e,validate:t,default:n},hn),{errorMessageForStdin:`Please provide a valid input based on the command options.`});var Spider=class{name;class_name;start_urls;pathname;constructor(e){this.name=e.name,this.class_name=e.class_name,this.start_urls=e.start_urls,this.pathname=e.pathname}},SpiderFileAnalyzer=class{pathname;constructor(e){this.pathname=e}getSpiders(){let e=A(this.pathname,`utf8`),t=/class\s+(\w+)/g,n=[],r=t.exec(e);for(;r;)n.push(new Spider({class_name:r[1],pathname:this.pathname})),r=t.exec(e);return n}},ScrapyProjectAnalyzer=class{pathname;configuration=null;settings=null;constructor(e){this.pathname=e,this.settings=null,this.loadScrapyCfg()}static isApplicable(e){return D(u(e,`scrapy.cfg`))}async init(){await this.loadSettings()}loadScrapyCfg(){let e=new Fe,t=p(u(this.pathname,`scrapy.cfg`));if(!D(t))throw Error(`scrapy.cfg not found in "${t}".
|
|
31
31
|
Are you sure there is a Scrapy project there?`);e.read(t),this.configuration=e}async loadSettings(){let e=this.configuration.get(`settings`,`default`).split(`.`)[0],t=await vn({message:`Enter the Scrapy BOT_NAME (see settings.py):`,default:e}),n=await vn({message:`What folder are the Scrapy spider modules stored in? (see SPIDER_MODULES in settings.py):`,default:`${e}.spiders`});this.settings={BOT_NAME:t,SPIDER_MODULES:typeof n==`string`?[n]:n}}getName(){return this.settings?.BOT_NAME}getAvailableSpiders(){let e=this.settings?.SPIDER_MODULES;if(!e)throw Error(`SPIDER_MODULES path not found in settings.`);let t=[];for(let n of e){let e=u(this.pathname,n.replaceAll(`.`,`/`)),r=te(e,{withFileTypes:!0});for(let n of r)n.isFile()&&n.name.endsWith(`.py`)&&n.name!==`__init__.py`&&t.push(...new SpiderFileAnalyzer(u(e,n.name)).getSpiders())}return t}};const yn=new Map,bn={node:[`--version`],deno:[`eval`,`"console.log(process.versions.node)"`],bun:[`--eval`,`"console.log(process.versions.node)"`]};async function getRuntimeVersion(t,n){try{let r=await De(t,n,{shell:!0,windowsHide:!0,verbose:e.env.APIFY_CLI_DEBUG?`full`:void 0});return r.stdout?r.stdout.trim().replace(/^v/,``):null}catch{return null}}async function getNpmVersion(t){let n=await De(t,[`--version`],{shell:!0,windowsHide:!0,verbose:e.env.APIFY_CLI_DEBUG?`full`:void 0});return n.stdout?n.stdout.trim().replace(/^v/,``):null}async function useJavaScriptRuntime(t=e.cwd()){let n=yn.get(t);if(n)return cliDebugPrint(`useJavaScriptRuntime`,{cacheHit:!0,cwd:t,runtime:n.unwrapOr(null)}),n;for(let[e,n]of Object.entries(bn))try{let r=normalizeExecutablePath(await Le(e)),i=await getRuntimeVersion(r,n);if(i){let n={executablePath:r,version:i};if(e===`node`){let e=normalizeExecutablePath(await Le(`npm`).catch(()=>null));e&&(n.pmPath=e,n.pmVersion=await getNpmVersion(e),n.pmName=`npm`)}else n.runtimeShorthand=e,n.pmPath=r,n.pmVersion=i,n.pmName=e;return yn.set(t,Ee(n)),cliDebugPrint(`useJavaScriptRuntime`,{cacheHit:!1,cwd:t,runtime:yn.get(t)?.unwrap()}),Ee(n)}}catch{}return yn.set(t,we),cliDebugPrint(`useJavaScriptRuntime`,{cacheHit:!1,cwd:t,runtime:null}),we}const xn=new Map;async function getPythonVersion(t){try{let n=await De(t,[`-c`,`"import platform; print(platform.python_version())"`],{shell:!0,windowsHide:!0,verbose:e.env.APIFY_CLI_DEBUG?`full`:void 0});return n.stdout?n.stdout.trim():null}catch{return null}}async function usePythonRuntime({cwd:t=e.cwd(),force:n=!1}={}){let r=xn.get(t);if(r&&!n)return cliDebugPrint(`usePythonRuntime`,{cacheHit:!0,cwd:t,runtime:r.unwrapOr(null)}),r;let i=ce()===`win32`,a=i?[`Scripts`,`python.exe`]:[`bin`,`python3`],s;s=e.env.VIRTUAL_ENV?u(e.env.VIRTUAL_ENV,...a):u(t,`.venv`,...a),s=normalizeExecutablePath(s);try{let e=await getPythonVersion(s);if(e)return xn.set(t,Ee({executablePath:s,version:e})),cliDebugPrint(`usePythonRuntime`,{cacheHit:!1,cwd:t,runtime:xn.get(t)?.unwrap()}),xn.get(t)}catch{}let c=[`python3`,`python`,...i?[`python3.exe`,`python.exe`]:[]];for(let e of c)try{let n=normalizeExecutablePath(await Le(e)),r=await getPythonVersion(n);if(r)return xn.set(t,Ee({executablePath:n,version:r})),cliDebugPrint(`usePythonRuntime`,{cacheHit:!1,cwd:t,runtime:xn.get(t)?.unwrap()}),xn.get(t)}catch{}return xn.set(t,we),cliDebugPrint(`usePythonRuntime`,{cacheHit:!1,cwd:t,runtime:null}),we}const Sn=new Map;async function useCwdProject({cwd:t=e.cwd()}={}){let n=Sn.get(t);if(n)return cliDebugPrint(`useCwdProject`,{cacheHit:!0,project:n}),Te(n);let r={type:3},check=async()=>{if(await checkScrapyProject(t)){r.type=2;let e=await usePythonRuntime({cwd:t});r.runtime=e.unwrapOr(void 0),await fileExists(u(t,`uv.lock`))&&(r.packageManager=`uv`);let n=new ScrapyProjectAnalyzer(t);if(n.loadScrapyCfg(),n.configuration.hasKey(`apify`,`mainpy_location`))r.entrypoint={path:n.configuration.get(`apify`,`mainpy_location`)};else try{let e=await checkPythonProject(t);e&&(r.entrypoint={path:e})}catch{}return}let e=await checkNodeProject(t);if(!e){let e=null;try{e=await checkPythonProject(t)}catch(e){return Ce({message:e instanceof Error?e.message:String(e)})}if(e){r.type=1;let n=await usePythonRuntime({cwd:t});r.entrypoint={path:e},r.runtime=n.unwrapOr(void 0),await fileExists(u(t,`uv.lock`))&&(r.packageManager=`uv`);let i=u(t,e.replace(/\./g,`/`));await fileExists(u(i,`__main__.py`))||(r.warnings=[`The detected Python package "${e}" is missing __main__.py. Running with "python -m" will fail without it.`]);return}}if(e){r.type=0;let t=await useJavaScriptRuntime();r.runtime=t.unwrapOr(void 0),e.type===`file`?r.entrypoint={path:e.path}:e.type===`script`&&(r.entrypoint={script:e.script});return}return Te(r)},i=await check();return i?.isErr()?(cliDebugPrint(`useCwdProject`,{cacheHit:!1,error:i}),i):(cliDebugPrint(`useCwdProject`,{cacheHit:!1,project:r}),Sn.set(t,r),Te(r))}async function checkNodeProject(e){let t=u(e,`package.json`);try{let n=await z(t,`utf-8`),r=JSON.parse(n);if(r.scripts?.start)return{type:`script`,script:`start`};if(r.main)try{return await Oe(p(e,r.main)),{path:p(e,r.main),type:`file`}}catch{}return{type:`unknown-entrypoint`}}catch{}let n=[u(e,`index.js`),u(e,`index.mjs`),u(e,`index.cjs`),u(e,`main.js`),u(e,`main.mjs`),u(e,`main.cjs`),u(e,`src`,`index.js`),u(e,`src`,`index.mjs`),u(e,`src`,`index.cjs`),u(e,`src`,`main.js`),u(e,`src`,`main.mjs`),u(e,`src`,`main.cjs`),u(e,`dist`,`index.js`),u(e,`dist`,`index.mjs`),u(e,`dist`,`index.cjs`),u(e,`dist`,`main.js`),u(e,`dist`,`main.mjs`),u(e,`dist`,`main.cjs`)];for(let e of n)try{return await Oe(e),{path:e,type:`file`}}catch{}return null}async function fileExists(e){try{return await Oe(e),!0}catch{return!1}}async function dirExists(e){try{return(await B(e)).isDirectory()}catch{return!1}}function isValidPythonIdentifier(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}async function hasPythonFilesInDirOrSubdirs(e){try{let t=await Ae(e,{withFileTypes:!0});if(t.some(e=>e.isFile()&&e.name.endsWith(`.py`)))return!0;for(let n of t){if(!n.isDirectory()||n.name.startsWith(`.`)||n.name.startsWith(`_`))continue;let t=u(e,n.name);try{let e=await Ae(t,{withFileTypes:!0});if(e.some(e=>e.isFile()&&e.name.endsWith(`.py`)))return!0;if(n.name===`src`){for(let n of e)if(n.isDirectory()&&!(n.name.startsWith(`.`)||n.name.startsWith(`_`)))try{if((await Ae(u(t,n.name),{withFileTypes:!0})).some(e=>e.isFile()&&e.name.endsWith(`.py`)))return!0}catch{}}}catch{}}return!1}catch{return!1}}async function dirHasPyFiles(e){try{return(await Ae(e,{withFileTypes:!0})).some(e=>e.isFile()&&e.name.endsWith(`.py`)&&e.name!==`__init__.py`)}catch{return!1}}async function findNearMissPackagesInDir(e){try{let t=await Ae(e,{withFileTypes:!0}),n=[];for(let r of t){if(!r.isDirectory()||r.name.startsWith(`.`)||r.name.startsWith(`_`))continue;let t=isValidPythonIdentifier(r.name),i=await fileExists(u(e,r.name,`__init__.py`)),a=i||await dirHasPyFiles(u(e,r.name));t&&i||a&&n.push({name:r.name,needsRename:!t,needsInit:!i})}return n}catch{return[]}}async function findPackagesInDir(e){try{let t=await Ae(e,{withFileTypes:!0}),n=[];for(let r of t){if(!r.isDirectory())continue;let{name:t}=r;t.startsWith(`.`)||t.startsWith(`_`)||!isValidPythonIdentifier(t)||await fileExists(u(e,t,`__init__.py`))&&n.push({name:t,path:u(e,t)})}return n}catch{return[]}}async function discoverPythonPackages(e){let t=[],n=await findPackagesInDir(e);t.push(...n.map(e=>e.name));let r=u(e,`src`),i=await fileExists(u(r,`__init__.py`));if(await dirExists(r)&&!i){let e=await findPackagesInDir(r);t.push(...e.map(e=>`src.${e.name}`))}return t}async function checkPythonProject(e){let t=await discoverPythonPackages(e);if(t.length===1)return t[0];if(t.length>1){let e=t.map(e=>` - ${e}`).join(`
|
|
32
32
|
`);throw Error(`Multiple Python packages found:\n${e}\n\nApify CLI cannot determine which package to run.
|
|
@@ -48,7 +48,7 @@ Common package structures:
|
|
|
48
48
|
main.py`);return null}async function checkScrapyProject(e){return ScrapyProjectAnalyzer.isApplicable(e)}function normalizeExecutablePath(e){return e?e.startsWith(`"`)?e:l(e)&&e.includes(` `)?`"${e}"`:e:null}async function getInstallCommandSuggestion(e){let t=null;return await(await useCwdProject({cwd:e})).inspectAsync(async n=>{if(n.type===0){let[r,i,a,s]=await Promise.all([B(u(e,`yarn.lock`)).then(()=>!0).catch(()=>!1),B(u(e,`pnpm-lock.yaml`)).then(()=>!0).catch(()=>!1),B(u(e,`bun.lockb`)).then(()=>!0).catch(()=>!1),B(u(e,`bun.lock`)).then(()=>!0).catch(()=>!1)]);t=r?`yarn install`:i?`pnpm install`:a||s||n.runtime?.pmName===`bun`?`bun install`:n.runtime?.pmName===`deno`?`deno install --node-modules-dir`:`npm install`}else(n.type===1||n.type===2)&&(t=n.packageManager===`uv`?`uv sync`:`python -m pip install -r requirements.txt`)}),t}let Cn=`inherit`;function keepStdoutClean(){Cn=e.stderr}const spawnPromised=async(t,n,r,{forwardSignals:i}={})=>{let a=normalizeExecutablePath(t);cliDebugPrint(`spawnPromised`,{escapedCommand:a,args:n,opts:r,forwardSignals:i});let s=De(a,n,{shell:!0,windowsHide:!0,env:r.env,cwd:r.cwd,stdout:e.env.APIFY_NO_LOGS_IN_TESTS?[`pipe`]:[`pipe`,Cn],stderr:e.env.APIFY_NO_LOGS_IN_TESTS?[`pipe`]:[`pipe`,`inherit`],verbose:e.env.APIFY_CLI_DEBUG?`full`:void 0}),c=[];if(i?.length)for(let t of i){let handler=()=>{s.kill(t)};e.on(t,handler),c.push(()=>e.off(t,handler))}try{return await Se.fromAsync(s.catch(e=>{let n;throw n=e.exitCode==null?e.signal?`${t} exited due to signal ${e.signal}`:e.shortMessage:`${t} exited with code ${e.exitCode}`,Error(n,{cause:e})}))}finally{for(let e of c)e()}};async function execWithLog({cmd:e,args:t=[],opts:n={},overrideCommand:r,forwardSignals:i}){run({message:`${r||e} ${t.join(` `)}`});let a=await spawnPromised(e,t,n,{forwardSignals:i});if(a.isErr()){let e=a.unwrapErr();if(error({message:e.message}),e.cause)throw e.cause}}const wn=[[`CLAUDECODE`,`claude_code`],[`CLAUDE_CODE_ENTRYPOINT`,`claude_code`],[`CURSOR_AGENT`,`cursor`],[`CLINE_ACTIVE`,`cline`],[`CODEX_SANDBOX`,`codex_cli`],[`CODEX_THREAD_ID`,`codex_cli`],[`GEMINI_CLI`,`gemini_cli`],[`OPENCODE`,`open_code`],[`OPENCLAW_SHELL`,`openclaw`]];function detectAiAgent(){for(let[e,t]of wn)if(process.env[e])return t}function detectCi(){return le.isCI?{isCi:!0,ciProvider:le.id?.toLowerCase()??`unknown`}:{isCi:!1,ciProvider:void 0}}function detectIsInteractive(){return!!process.stdin.isTTY&&!!process.stdout.isTTY}const updateLocalJson=async(e,t={},n=null)=>{let r=await z(e,`utf-8`),i=JSON.parse(r),a;n?(a=i,a[n]={...i[n],...t}):a={...i,...t},await V(e,JSON.stringify(a,null,` `))},ensureFolderExistsSync=(e,t)=>{t||(t=e,e=`.`),t.split(m).reduce((e,t)=>(e=u(e,t),D(e)||O(e),e),e)},rimrafPromised=async e=>{let t=Array.isArray(e)?e:[e];await Promise.all(t.map(async e=>Me(e,{recursive:!0,force:!0})))},deleteFile=async e=>{(await B(e)).isFile()&&await Pe(e)};function ensureApifyDirectory(e){let t=c(e);O(t,{recursive:!0})}const sumFilesSizeInBytes=async(e,t)=>(await Promise.all(e.map(async e=>B(u(t,e))))).map(e=>e.size).reduce((e,t)=>e+t,0),Tn=`token`,En=`proxy-password`;let Dn,On,kn;async function loadKeyringModule(){return Dn===void 0&&(Dn=await importKeyringModule()),Dn}async function importKeyringModule(){if(useCLIMetadata().installMethod===`bundle`)try{let e=await import(`__APIFY_KEYRING_NATIVE_SUBPACKAGE__`),t=e.Entry??e.default?.Entry;return t?{Entry:t}:null}catch(e){return cliDebugPrint(`credentials`,`failed to load bundled keyring`,e),null}try{return await import(`@napi-rs/keyring`)}catch(e){return cliDebugPrint(`credentials`,`failed to load @napi-rs/keyring`,e),null}}async function getBackend(){return On||(On=(async()=>e.env.APIFY_DISABLE_KEYRING===`1`||readAuthFile().secretsBackend===`file`?`file`:await loadKeyringModule()?`keyring`:`file`)(),On)}function downgradeBackendToFile(){On=Promise.resolve(`file`)}function readAuthFile(){if(!D(AUTH_FILE_PATH()))return{};try{let e=A(AUTH_FILE_PATH(),`utf-8`);return JSON.parse(e)}catch{return{}}}function writeAuthFile(e){ensureApifyDirectory(AUTH_FILE_PATH()),P(AUTH_FILE_PATH(),JSON.stringify(e,null,` `),{mode:384})}async function getKeyringEntry(e){let t=await loadKeyringModule();return t?new t.Entry(`com.apify.cli`,e):null}async function readKeyring(e){try{let t=await getKeyringEntry(e);return t?t.getPassword()??void 0:void 0}catch(t){cliDebugPrint(`credentials`,`failed to read ${e} from keyring`,t);return}}async function writeKeyring(e,t){let n=await getKeyringEntry(e);if(!n)throw Error(`OS keyring is not available.`);n.setPassword(t)}async function deleteKeyring(e){try{let t=await getKeyringEntry(e);if(!t)return;t.deletePassword()}catch(t){cliDebugPrint(`credentials`,`failed to delete ${e} from keyring`,t)}}async function getToken(){return await getBackend()===`keyring`?readKeyring(Tn):readAuthFile().token}async function getProxyPassword(){return await getBackend()===`keyring`?readKeyring(En):readAuthFile().proxy?.password}async function setToken(e,t={}){let n=await getBackend();if(t.skipIfUnchanged&&(n===`keyring`?await readKeyring(Tn):readAuthFile().token)===e)return;if(n===`keyring`)try{await writeKeyring(Tn,e);return}catch(e){cliDebugPrint(`credentials`,`keyring write failed; falling back to file`,e),downgradeBackendToFile()}let r=readAuthFile();r.token=e,r.secretsBackend=`file`,writeAuthFile(r)}async function setProxyPassword(e,t={}){let n=await getBackend();if(t.skipIfUnchanged&&(n===`keyring`?await readKeyring(En):readAuthFile().proxy?.password)===e)return;if(n===`keyring`)try{await writeKeyring(En,e);return}catch(e){cliDebugPrint(`credentials`,`keyring write failed; falling back to file`,e),downgradeBackendToFile()}let r=readAuthFile();r.proxy={...r.proxy,password:e},r.secretsBackend=`file`,writeAuthFile(r)}async function clearKeyringSecrets(){await deleteKeyring(Tn),await deleteKeyring(En)}async function ensureMigrated(){return kn||(kn=(async()=>{try{let e=readAuthFile();if(e.secretsBackend||!e.token&&!e.proxy?.password)return;if(await getBackend()===`file`){e.secretsBackend=`file`,writeAuthFile(e);return}try{e.token&&await writeKeyring(Tn,e.token),e.proxy?.password&&await writeKeyring(En,e.proxy.password)}catch(t){cliDebugPrint(`credentials`,`keyring write failed during migration; falling back to file`,t),downgradeBackendToFile(),e.secretsBackend=`file`,writeAuthFile(e);return}delete e.token,e.proxy&&(delete e.proxy.password,Object.keys(e.proxy).length===0&&delete e.proxy),e.secretsBackend=`keyring`,writeAuthFile(e)}catch(e){cliDebugPrint(`credentials`,`migration failed`,e)}})(),kn)}const An=`__CLI_`;function resolveInputKey(){return process.env[F.INPUT_KEY]||process.env[L.INPUT_KEY]||process.env.CRAWLEE_INPUT_KEY||`INPUT`}function inputFileRegExp(e){return RegExp(`(^${Qe(e)}(?:\\.[^.]+)?$)`)}const jn=$e,Mn=qe,getLocalStorageDir=()=>{let t=L.LOCAL_STORAGE_DIR;return e.env[t]||e.env.CRAWLEE_STORAGE_DIR||`storage`},getLocalKeyValueStorePath=t=>{let n=F.DEFAULT_KEY_VALUE_STORE_ID,r=t||e.env[n]||he[n];return u(getLocalStorageDir(),ge.keyValueStores,r)},getLocalDatasetPath=t=>{let n=F.DEFAULT_DATASET_ID,r=t||e.env[n]||he[n];return u(getLocalStorageDir(),ge.datasets,r)},getLocalRequestQueuePath=t=>{let n=F.DEFAULT_REQUEST_QUEUE_ID,r=t||e.env[n]||he[n];return u(getLocalStorageDir(),ge.requestQueues,r)},getLocalUserInfo=async()=>{await ensureMigrated();let e={};try{let t=await z(AUTH_FILE_PATH(),`utf-8`);e=JSON.parse(t)}catch{}if(await getBackend()===`keyring`){let t=await getToken();t&&(e.token=t);let n=await getProxyPassword();n&&(e.proxy={...e.proxy,password:n})}let t=!!(e.username||e.id);if(!(t||e.token))return{};if(!t)throw Error(`Stale credentials found without user metadata. Please run "apify login" again.`);return e};async function getLoggedClientOrThrow(){let t=await getLoggedClient();if(!t)throw e.exitCode=1,Error(`You are not logged in with your Apify account. Call "apify login" to fix that.`);return t}const resolveToken=async e=>e||(await ensureMigrated(),getToken()),getApifyClientOptions=async(t,n)=>({token:await resolveToken(t),baseUrl:n||e.env.APIFY_CLIENT_BASE_URL,requestInterceptors:[e=>{e.headers??=new Ze;for(let[t,n]of Object.entries(on))e.headers[t]=n;return e}]});async function getLoggedClient(e,t){let n=await resolveToken(e),r=new Je(await getApifyClientOptions(n,t)),i;try{i=await r.user(`me`).get()}catch(e){return cliDebugPrint(`[getLoggedClient] error getting user info`,{error:e,apiBaseUrl:t}),null}r.token&&await setToken(r.token,{skipIfUnchanged:!0});let a=i.proxy?.password;a&&await setProxyPassword(a,{skipIfUnchanged:!0}),ensureApifyDirectory(AUTH_FILE_PATH());let s=(()=>{try{return JSON.parse(A(AUTH_FILE_PATH(),`utf-8`))}catch{return{}}})(),c=await getBackend(),l={...s,...i,secretsBackend:c};if(c===`keyring`&&(delete l.token,l.proxy&&typeof l.proxy==`object`)){let{password:e,...t}=l.proxy;Object.keys(t).length>0?l.proxy=t:delete l.proxy}return P(AUTH_FILE_PATH(),JSON.stringify(l,null,` `),{mode:384}),r}const getLocalConfigPath=e=>u(e,W),getJsonFileContent=e=>{if(D(e))return JSON.parse(A(e,{encoding:`utf-8`}))},getLocalConfig=e=>getJsonFileContent(getLocalConfigPath(e)),setLocalConfig=async(t,n)=>{let r=u(n||e.cwd(),W);await R(c(r),{recursive:!0}),P(r,JSON.stringify(t,null,` `))},Nn=[getLocalStorageDir(),`node_modules`,`.venv`],setLocalEnv=async e=>{let t=getLocalKeyValueStorePath();ensureFolderExistsSync(e,getLocalDatasetPath()),ensureFolderExistsSync(e,getLocalRequestQueuePath()),ensureFolderExistsSync(e,t);let n=u(e,`.gitignore`),r=``;D(n)&&(r=A(n,{encoding:`utf-8`}));let i=[];for(let e of Nn)RegExp(`^${Qe(e)}$`,`mg`).test(r)||i.push(e);i.length>0&&(r.length>0?(i.unshift(`# Added by Apify CLI`),P(n,`\n${i.join(`
|
|
49
49
|
`)}\n`,{flag:`a`})):P(n,`${i.join(`
|
|
50
50
|
`)}\n`,{flag:`w`}))},Pn=new nt(it,rt).define({"application/gzip":[`tgz`],"text/typescript":[`ts`,`tsx`,`mts`]},!0),getSourceFileFormat=(e,t)=>{let n=Pn.getType(e);return n?n.startsWith(`text/`)||n.includes(`javascript`)||n.includes(`json`)||n.includes(`xml`)||n.includes(`application/node`)||n.includes(`application/toml`)||n.includes(`application/x-sh`)||n.includes(`application/x-httpd-php`)?ye.TEXT:ye.BASE64:et(t)===`binary`?ye.BASE64:ye.TEXT},createSourceFiles=async(e,t)=>e.map(e=>{let n=A(u(t,e)),r=getSourceFileFormat(e,n);return{name:e,format:r,content:r===ye.TEXT?n.toString(`utf8`):n.toString(`base64`)}}),getGitignoreFallbackFilter=async e=>{let t=await at(`**/.gitignore`,{dot:!0,cwd:e,ignore:[`.git/**`],expandDirectories:!1}),n=[];for(let r of t){let t=c(r),i=await z(u(e,r),`utf-8`);n.push({dir:t===`.`?``:t,ig:jn().add(i)})}let r=c(e);for(;r!==c(r)&&!D(u(r,`.git`));){let t=u(r,`.gitignore`);if(D(t))try{let i=await z(t,`utf-8`),a=f(r,e);n.push({dir:``,ig:jn().add(i),ancestorPrefix:a})}catch{}r=c(r)}return n.length===0?e=>e:e=>e.filter(e=>{for(let{dir:t,ig:r,ancestorPrefix:i}of n){let n;if(n=t?e.startsWith(`${t}/`)?e.slice(t.length+1):null:i?`${i}/${e}`:e,n!==null&&r.ignores(n))return!1}return!0})},parseActorIgnore=async e=>{let t=u(e,`.actorignore`);if(!D(t))return{excludeFilter:null,forceIncludePatterns:[]};let n=(await z(t,`utf-8`)).split(`
|
|
51
|
-
`),r=[],i=[];for(let e of n){let t=e.trim()
|
|
51
|
+
`),r=[],i=[];for(let e of n){let t=e.trim();t&&!t.startsWith(`#`)&&(t.startsWith(`!`)?i.push(t.slice(1)):r.push(t))}return{excludeFilter:r.length>0?e=>{let t=jn().add(r);return e.filter(e=>!t.ignores(e))}:null,forceIncludePatterns:i}},getActorLocalFilePaths=async t=>{let n=t??e.cwd(),r=[`.git/**`,`apify_storage`,`node_modules`,`storage`,`crawlee_storage`],{excludeFilter:i,forceIncludePatterns:a}=await parseActorIgnore(n),gitIgnoreFilter=null;try{let e=Be(`git ls-files --others --ignored --exclude-standard --directory`,{cwd:n,encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).split(`
|
|
52
52
|
`).filter(Boolean);if(e.length>0){let t=jn().add(e);gitIgnoreFilter=e=>e.filter(e=>!t.ignores(e))}}catch{gitIgnoreFilter=await getGitignoreFallbackFilter(n)}let s=await at([`*`,`**/**`],{ignore:r,dot:!0,expandDirectories:!1,cwd:n}),c=gitIgnoreFilter?gitIgnoreFilter(s):s;if(i&&(c=i(c)),a.length>0){let e=jn().add(a),t=s.filter(t=>e.ignores(t)),n=new Set(c);for(let e of t)n.add(e);c=[...n]}let l=s.filter(e=>e===`.actor`||e.startsWith(`.actor/`));if(l.length>0){let e=new Set(c);for(let t of l)e.add(t);c=[...e]}return c},createActZip=async(e,t,n)=>{D(e)&&await deleteFile(e);let r=E(e),i=new Ye({zlib:{level:6}});i.pipe(r),t.forEach(e=>i.file(u(n,e),{name:e})),await i.finalize()},getLocalInput=(e,t)=>{let n=getLocalKeyValueStorePath(),r=p(e,n);if(!D(r))return;let i=te(r).find(e=>!!e.match(inputFileRegExp(t??`INPUT`)));return i?{body:A(u(r,i)),contentType:Pn.getType(i),fileName:i}:void 0},purgeDefaultQueue=async()=>{await rimrafPromised(p(e.cwd(),getLocalRequestQueuePath()))},purgeDefaultDataset=async()=>{await rimrafPromised(p(e.cwd(),getLocalDatasetPath()))},purgeDefaultKeyValueStore=async(...t)=>{let n=p(e.cwd(),getLocalKeyValueStorePath());if(!D(n))return;let r=te(n),i=(t.length>0?t:[`INPUT`]).map(inputFileRegExp),a=[];r.forEach(e=>{i.some(t=>t.test(e))||a.push(deleteFile(u(n,e)))}),await Promise.all(a)},outputJobLog=async({job:t,timeoutMillis:n,apifyClient:r})=>{let{id:i,status:a}=t,s=r||new Je({baseUrl:e.env.APIFY_CLIENT_BASE_URL});if(de.includes(a)){if(e.env.APIFY_NO_LOGS_IN_TESTS)return;let t=await s.log(i).get();e.stderr.write(t);return}return new Promise(async t=>{let r=await s.log(i).stream();if(!r){t(`no-logs`);return}let a=null;r.on(`data`,t=>{e.env.APIFY_NO_LOGS_IN_TESTS||e.stderr.write(t.toString())}),r.once(`end`,()=>{t(`finished`),a&&clearTimeout(a)}),n!==void 0&&(a=setTimeout(()=>{r.destroy(),t(`timeouts`)},n))})},checkIfStorageIsEmpty=async t=>{let n=t||me.INPUT,r=getLocalStorageDir().replaceAll(`\\`,`/`),i=getLocalKeyValueStorePath().replaceAll(`\\`,`/`);return(await at([`${r}/**`,`!${i}/${n}.*`,`!${i}/${An}${n}.*`],{cwd:e.cwd()})).length===0},validateActorName=e=>{if(!fe.REGEX.test(e))throw Error(`The Actor name must be a DNS hostname-friendly string (e.g. my-newest-actor).`);if(e.length<fe.MIN_LENGTH)throw Error(`The Actor name must be at least 3 characters long.`);if(e.length>fe.MAX_LENGTH)throw Error(`The Actor name must be a maximum of 30 characters long.`)},sanitizeActorName=e=>{let t=e.replaceAll(/[^a-zA-Z0-9-]/g,`-`);return t.length<fe.MIN_LENGTH&&(t=`${t}-apify-actor`),t=t.replaceAll(/^-+/g,``).replaceAll(/-+$/g,``),t.slice(0,fe.MAX_LENGTH)},isPythonVersionSupported=e=>x(e,`^${sn}`),isNodeVersionSupported=e=>{let t=b(rn);return y(e,t)},downloadZip=async e=>{let t=await Xe.get(e,{responseType:`arraybuffer`,validateStatus:()=>!0,headers:{"User-Agent":`Apify CLI/${useCLIMetadata().version} (https://github.com/apify/apify-cli)`}});if(t.status<200||t.status>=300){let n=Buffer.from(t.data).toString(`utf8`).trim().slice(0,500);throw Error(`Failed to download the archive from ${e} (HTTP ${t.status}).${n?`\nServer response: ${n}`:``}`)}let n=Buffer.from(t.data);if(n.subarray(0,2).toString()!==`PK`)throw Error(`The file downloaded from ${e} is not a valid zip archive - a proxy or firewall likely intercepted the download. Check your network or try a different one.`);return new Ke(n)},downloadAndUnzip=async({url:e,pathTo:t})=>{(await downloadZip(e)).extractAllTo(t,!0)},G=new Ge(`YYYY-MM-DD [at] HH:mm:ss`),Fn=new Ge(`YYYY-MM-DD[
|
|
53
53
|
]HH:mm:ss`),In=new Ge(`YYYY-MM-DD`),Ln=new He,K=new He({[We.Day]:{DEFAULT:`d`},[We.Hour]:{DEFAULT:`h`},[We.Minute]:{DEFAULT:`m`},[We.Month]:{DEFAULT:`M`},[We.Second]:{DEFAULT:`s`},[We.Week]:{DEFAULT:`w`},[We.Year]:{DEFAULT:`y`}});function objectGroupBy(e,t){if(`groupBy`in Object)return Object.groupBy(e,t);let n={},r=0;for(let i of e){let e=t(i,r++);n[e]||(n[e]=[]),n[e].push(i)}return n}function printJsonToStdout(e){console.log(JSON.stringify(e,null,2))}const userHomeDir=()=>e.env.HOME??se(),tildify=e=>{let t=userHomeDir();return t&&e.startsWith(t)?e.replace(t,`~`):e};function detectShell(){let t=e.env.SHELL??``;return t.includes(`zsh`)?`zsh`:t.includes(`bash`)?`bash`:t.includes(`fish`)?`fish`:`unknown`}function shellConfigFile(t,n){switch(n){case`bash`:{let n=[u(t,`.bashrc`),u(t,`.bash_profile`)];e.env.XDG_CONFIG_HOME&&n.push(u(e.env.XDG_CONFIG_HOME,`.bashrc`),u(e.env.XDG_CONFIG_HOME,`.bash_profile`),u(e.env.XDG_CONFIG_HOME,`bashrc`),u(e.env.XDG_CONFIG_HOME,`bash_profile`));for(let e of n)if(D(e))return e;return null}case`zsh`:{let n=e.env.ZDOTDIR||t||userHomeDir();return u(n,`.zshrc`)}case`fish`:return u(t,`.config`,`fish`,`config.fish`);case`unknown`:return null}}function parseWaitForFinishMillis(e){if(e===void 0)return;let t=Number.parseInt(e,10);if(!(!Number.isFinite(t)||t<0))return t*1e3}const Rn=[`Apify collects telemetry data about general usage of Apify CLI to help us improve the product.`,`This feature is enabled by default, and you can disable it by setting the "APIFY_CLI_DISABLE_TELEMETRY" environment variable to "1", or by running "apify telemetry disable".`,`You can find more information about our telemetry in https://docs.apify.com/cli/docs/telemetry.`].join(`
|
|
54
54
|
`);function createAnonymousId(){return`CLI:${ze()}`}async function migrateStateV0ToV1(e){if(e.version&&e.version>=1)return!1;let t=e,n=await getLocalUserInfo().catch(()=>({}));return updateTelemetryState({version:1,enabled:!0},e=>{n.id&&t.distinctId===n.id?(e.anonymousId=createAnonymousId(),e.userId=n.id):e.anonymousId=t.distinctId}),!0}async function useTelemetryState(){let e=TELEMETRY_FILE_PATH();if(!D(e)){let e=await getLocalUserInfo().catch(()=>({}));return updateTelemetryState({version:1,enabled:!0,anonymousId:createAnonymousId(),userId:e.id}),(!process.env.APIFY_CLI_DISABLE_TELEMETRY||[`false`,`0`].includes(process.env.APIFY_CLI_DISABLE_TELEMETRY))&&info({message:Rn}),useTelemetryState()}let t=JSON.parse(A(e,`utf-8`));return await migrateStateV0ToV1(t)?useTelemetryState():t}function updateTelemetryState(e,t){let n={...e};t?.(n);let r=TELEMETRY_FILE_PATH(),i=c(r);O(i,{recursive:!0}),P(TELEMETRY_FILE_PATH(),JSON.stringify(n,null,` `))}async function updateUserId(e){updateTelemetryState(await useTelemetryState(),t=>{t.userId=e})}async function checkAndUpdateLastCommand(e){try{let t=await useTelemetryState(),n=Date.now(),r=t.lastCommand===e&&n-(t.lastCommandTimestamp??0)<1e4;return updateTelemetryState(t,t=>{t.lastCommand=e,t.lastCommandTimestamp=n}),r}catch{return!1}}async function updateTelemetryEnabled(e){updateTelemetryState(await useTelemetryState(),t=>{t.enabled=e})}async function useTelemetryEnabled(){if(process.env.APIFY_CLI_DISABLE_TELEMETRY&&![`false`,`0`].includes(process.env.APIFY_CLI_DISABLE_TELEMETRY))return cliDebugPrint(`telemetry`,`disabled by env variable`),!1;let e=await useTelemetryState();return cliDebugPrint(`telemetry state`,{telemetryState:e}),e.enabled}async function useTelemetryIdentifiers(){let e=await useTelemetryState();return{anonymousId:e.anonymousId,userId:e.userId}}const zn=useCLIMetadata(),Bn=zn.isBeta?`rT67mFpIQD5qS9bJBoIYSFbZucrt2DZC`:`2uPK6yhPqjC0eNUFhaY78S26cRKyaa6t`;async function trackEvent(e,t){let n=await useTelemetryIdentifiers(),r={anonymousId:n.anonymousId,context:{app:{name:`apify-cli`,version:zn.version,build:zn.hash},library:{name:`apify-cli`,version:zn.version},os:{name:zn.platform},userAgent:mn,channel:`server`},event:e,properties:{...t,app:`cli`},timestamp:new Date().toISOString(),userId:n.userId,writeKey:Bn};if(cliDebugPrint(`trackEvent`,r),!await useTelemetryEnabled()){cliDebugPrint(`trackEvent`,`telemetry disabled`);return}try{let e=await fetch(`https://api.segment.io/v1/track`,{method:`POST`,body:JSON.stringify(r)});if(!e.ok){cliDebugPrint(`trackEvent`,`failed to send event`,await e.text());return}cliDebugPrint(`trackEvent`,`event sent`)}catch(e){cliDebugPrint(`trackEvent`,`failed to send event`,e)}}function shouldSkipRentalSunsetNotice({now:e,isCi:t,skipEnvValue:n}){return!!(n&&![`0`,`false`].includes(n)||t||e>=en)}function wasNotifiedRecently(e,t,n){return!e?.lastNotifiedAt||e.username!==t?!1:n-e.lastNotifiedAt<864e5}function renderRentalSunsetNotice(e){let n=e===1?`rental Actor`:`rental Actors`;return[t.bold(`Rental model sunset`),``,`You have ${e} ${n} published in Apify Store. Apify is sunsetting the rental pricing model.`,``,` ${t.bold(`April 1, 2026`)} Publishing new rental Actors and pricing changes on existing ones were disabled.`,` ${t.bold(`October 1, 2026`)} Rental Actors are fully retired. All remaining Actors move to pay-per-usage pricing.`,``,`Switch your ${n} to pay-per-event before October 1 to keep control over what you charge.`,`This guide walks through picking events, setting prices, and shipping the change:`,` ${t.cyan(`https://blog.apify.com/migrating-to-pay-per-event-pricing/`)}`,``,`Questions? Ask in the ${t.cyan(`#project-rentals`)} channel on Apify Discord:`,` ${t.cyan(`https://apify.com/discord`)}`,``,t.dim(`To silence this notice, set APIFY_CLI_SKIP_RENTAL_SUNSET_NOTICE=1.`),``].join(`
|
|
@@ -219,7 +219,7 @@ Stores data in local '${Qt}' directory.\n\nNOTE: For Node.js Actors, customize b
|
|
|
219
219
|
For crawlee projects, this is the default behavior, and the flag is optional.
|
|
220
220
|
Use \`--no-purge\` to keep the storage folder intact.`,required:!1,default:!0,exclusive:[`resurrect`]}),resurrect:J.boolean({description:`Whether to keep the default request queue, dataset and key-value store before the run starts.`,required:!1,default:!1,exclusive:[`purge`]}),entrypoint:J.string({description:[`Optional entrypoint for running with injected environment variables.`,`
|
|
221
221
|
`,`For Python, it is the module name, or a path to a file.`,`
|
|
222
|
-
`,`For Node.js, it is the npm script name, or a path to a JS/MJS file.`,`You can also pass in a directory name, provided that directory contains an "index.js" file.`].join(` `),required:!1}),input:J.string({char:`i`,description:`Optional JSON input to be given to the Actor.`,required:!1,stdin:2,exclusive:[`input-file`]}),"input-file":J.string({aliases:[`if`],description:"Optional path to a file with JSON input to be given to the Actor. The file must be a valid JSON file. You can also specify `-` to read from standard input.",required:!1,stdin:2,exclusive:[`input`]}),"allow-missing-secrets":J.boolean({description:`Allow the command to continue even when secret values are not found in the local secrets storage.`,required:!1,default:!1})};async run(){let t=e.cwd(),{proxy:n,id:r,token:i}=await getLocalUserInfo(),a=await useActorConfig({cwd:t});if(a.isErr()){let{message:t,cause:n}=a.unwrapErr();error({message:`${t}${n?`\n ${n.message}`:``}`}),e.exitCode=5;return}let{config:s}=a.unwrap(),c=getLocalStorageDir(),l=resolveInputKey(),f=await useCwdProject({cwd:t});if(f.isErr()){error({message:f.unwrapErr().message}),e.exitCode=5;return}let m=f.unwrap(),{type:h,entrypoint:g,runtime:_}=m;if(m.warnings?.length)for(let e of m.warnings)warning({message:e});if(h===3)throw Error(`Actor is of an unknown format. Make sure your project is supported by Apify CLI (either a package.json file is present, or a Python entrypoint could be found) or you are in a migrated Scrapy project.`);if(!_){switch(h){case 0:error({message:`No Node.js detected! Please install Node.js ${rn} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:error({message:`No Python detected! Please install Python ${sn} (or higher) to be able to run Python Actors locally.`});break;default:error({message:`No runtime detected! Make sure you have Python ${sn} (or higher) or Node.js ${rn} (or higher) installed.`})}return}let v,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let e=u(t,this.flags.entrypoint),n=await B(e).catch(()=>null);v=n?.isDirectory()?1:n?.isFile()?0:2}else if(g?.script)v=2,y=g.script;else if(g?.path)v=h===0?0:1,y=g.path;else{error({message:`No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint.`});return}let x=p(t,`apify_storage`),S=p(t,c);D(x)&&!D(S)&&(M(x,S),warning({message:`The legacy 'apify_storage' directory was renamed to '${c}' to align it with Apify SDK v3. Contents were left intact.`}));let C=await useModuleVersion({moduleName:`crawlee`,project:m}),w=`0`;this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(w=`1`,C.isNone()&&(await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l),purgeDefaultDataset()]),info({message:`All default local stores were purged.`}))),this.flags.purge||!await checkIfStorageIsEmpty(l)&&!this.flags.resurrect&&warning({message:`The storage directory contains a previous state, the Actor will continue where it left off. To start from the initial state, use --purge parameter to clean the storage directory.`});let T=await getInputOverride(t,this.flags.input,this.flags.inputFile);if(T===!1)return;let E=await this.validateAndStoreInput(T,l),ee=l;E&&`tempInputKey`in E&&(this.flags.purge&&C.isSome()&&await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l,E.tempInputKey),purgeDefaultDataset()]),w=`0`,ee=E.tempInputKey);let O={[L.LOCAL_STORAGE_DIR]:c,CRAWLEE_STORAGE_DIR:c,CRAWLEE_PURGE_ON_START:w,[F.INPUT_KEY]:ee,[L.INPUT_KEY]:ee,CRAWLEE_INPUT_KEY:ee};if(n&&n.password&&(O[L.PROXY_PASSWORD]=n.password),r&&(O[L.USER_ID]=r),i&&(O[L.TOKEN]=i),s.environmentVariables){let e=replaceSecretsValue(s.environmentVariables,void 0,{allowMissing:this.flags.allowMissingSecrets});Object.assign(O,e)}let k={...e.env,...O};r||warning({message:`You are not logged in with your Apify Account. Some features like Apify Proxy will not work. Call "apify login" to fix that.`});try{switch(h){case 0:{let e=b(rn);if(isNodeVersionSupported(_.version)?k.NODE_OPTIONS=k.NODE_OPTIONS?`${k.NODE_OPTIONS} --max-http-header-size=80000`:`--max-http-header-size=80000`:warning({message:`You are running Node.js version ${_.version}, which is no longer supported. Please upgrade to Node.js version ${e} or later.`}),v===0||v===1)await execWithLog({cmd:_.executablePath,args:[y],opts:{env:k,cwd:t},forwardSignals:tn});else{let e=await z(u(t,`package.json`),`utf8`).catch(()=>`{}`),n=JSON.parse(e);if(!n.scripts)throw Error(`No scripts were found in package.json. Please set it up for your project. For more information about that call "apify help run".`);if(!n.scripts[y])throw Error(`The script "${y}" was not found in package.json. Please set it up for your project. For more information about that call "apify help run".`);if(!_.pmPath)throw Error(`No npm executable found! Please make sure your Node.js runtime has npm installed if you want to run package.json scripts locally.`);await execWithLog({cmd:_.pmPath,args:[`run`,y],opts:{env:k,cwd:t},overrideCommand:_.pmName,forwardSignals:tn})}break}case 1:case 2:if(!isPythonVersionSupported(_.version)){error({message:`Python Actors require Python ${sn} or higher, but you have Python ${_.version}!`}),error({message:`Please install Python ${sn} or higher to be able to run Python Actors locally.`});return}v===1?await execWithLog({cmd:_.executablePath,args:[`-m`,y],opts:{env:k,cwd:t},forwardSignals:tn}):await execWithLog({cmd:_.executablePath,args:[y],opts:{env:k,cwd:t},forwardSignals:tn});break;default:error({message:`Failed to detect the language of your project. Please report this issue to the Apify team with your project structure over at https://github.com/apify/apify-cli/issues`})}}catch(t){e.exitCode=t.exitCode??1}finally{if(E)if(`tempInputKey`in E)await deleteFile(E.tempInputFilePath);else if(E.existingInput){let e=await B(E.inputFilePath);if(Math.trunc(e.mtimeMs)-E.writtenAt>=5){warning({message:`The "${E.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await V(E.inputFilePath,E.existingInput.body)}else await deleteFile(E.inputFilePath)}}async validateAndStoreInput(t,n=`INPUT`){let{inputSchema:r}=await readInputSchema({cwd:e.cwd()}),i=p(e.cwd(),getLocalKeyValueStorePath());if(!r){if(!t)return null;await R(i,{recursive:!0});let e=`${An}${n}`,r=u(i,`${e}.json`);return await V(r,JSON.stringify(t.input,null,2)),{tempInputKey:e,tempInputFilePath:r}}let a=new Mn({strict:!1,unicodeRegExp:!1});_t(a,r);let s=getDefaultsFromInputSchema(r),c=getAjvValidator(r,a),l=getLocalInput(e.cwd(),n),f=u(i,l?.fileName??`${n}.json`),m;switch(t?.source){case`stdin`:m=`The input provided through standard input is invalid. Please fix the following errors:
|
|
222
|
+
`,`For Node.js, it is the npm script name, or a path to a JS/MJS file.`,`You can also pass in a directory name, provided that directory contains an "index.js" file.`].join(` `),required:!1}),input:J.string({char:`i`,description:`Optional JSON input to be given to the Actor.`,required:!1,stdin:2,exclusive:[`input-file`]}),"input-file":J.string({aliases:[`if`],description:"Optional path to a file with JSON input to be given to the Actor. The file must be a valid JSON file. You can also specify `-` to read from standard input.",required:!1,stdin:2,exclusive:[`input`]}),"allow-missing-secrets":J.boolean({description:`Allow the command to continue even when secret values are not found in the local secrets storage.`,required:!1,default:!1})};async run(){let t=e.cwd(),{proxy:n,id:r,token:i}=await getLocalUserInfo(),a=await useActorConfig({cwd:t});if(a.isErr()){let{message:t,cause:n}=a.unwrapErr();error({message:`${t}${n?`\n ${n.message}`:``}`}),e.exitCode=5;return}let{config:s}=a.unwrap(),c=getLocalStorageDir(),l=resolveInputKey(),f=await useCwdProject({cwd:t});if(f.isErr()){error({message:f.unwrapErr().message}),e.exitCode=5;return}let m=f.unwrap(),{type:h,entrypoint:g,runtime:_}=m;if(m.warnings?.length)for(let e of m.warnings)warning({message:e});if(h===3)throw Error(`Actor is of an unknown format. Make sure your project is supported by Apify CLI (either a package.json file is present, or a Python entrypoint could be found) or you are in a migrated Scrapy project.`);if(!_){switch(h){case 0:error({message:`No Node.js detected! Please install Node.js ${rn} (or higher) to be able to run Node.js Actors locally.`});break;case 2:case 1:error({message:`No Python detected! Please install Python ${sn} (or higher) to be able to run Python Actors locally.`});break;default:error({message:`No runtime detected! Make sure you have Python ${sn} (or higher) or Node.js ${rn} (or higher) installed.`})}return}let v,y;if(this.flags.entrypoint){y=this.flags.entrypoint;let e=u(t,this.flags.entrypoint),n=await B(e).catch(()=>null);v=n?.isDirectory()?1:n?.isFile()?0:2}else if(g?.script)v=2,y=g.script;else if(g?.path)v=h===0?0:1,y=g.path;else{error({message:`No entrypoint detected! Please provide an entrypoint using the --entrypoint flag, or make sure your project has an entrypoint.`});return}let x=p(t,`apify_storage`),S=p(t,c);D(x)&&!D(S)&&(M(x,S),warning({message:`The legacy 'apify_storage' directory was renamed to '${c}' to align it with Apify SDK v3. Contents were left intact.`}));let C=await useModuleVersion({moduleName:`crawlee`,project:m}),w=`0`;this.flags.resurrect&&(this.flags.purge=!1),this.flags.purge&&(w=`1`,C.isNone()&&(await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l),purgeDefaultDataset()]),info({message:`All default local stores were purged.`}))),this.flags.purge||!await checkIfStorageIsEmpty(l)&&!this.flags.resurrect&&warning({message:`The storage directory contains a previous state, the Actor will continue where it left off. To start from the initial state, use --purge parameter to clean the storage directory.`});let T=await getInputOverride(t,this.flags.input,this.flags.inputFile);if(T===!1)return;let E=await this.validateAndStoreInput(T,l),ee=l;E&&`tempInputKey`in E&&(this.flags.purge&&C.isSome()&&await Promise.all([purgeDefaultQueue(),purgeDefaultKeyValueStore(l,E.tempInputKey),purgeDefaultDataset()]),w=`0`,ee=E.tempInputKey);let O={[L.LOCAL_STORAGE_DIR]:c,CRAWLEE_STORAGE_DIR:c,CRAWLEE_PURGE_ON_START:w,[F.INPUT_KEY]:ee,[L.INPUT_KEY]:ee,CRAWLEE_INPUT_KEY:ee};if(n&&n.password&&(O[L.PROXY_PASSWORD]=n.password),r&&(O[L.USER_ID]=r),i&&(O[L.TOKEN]=i),s.environmentVariables){let e=replaceSecretsValue(s.environmentVariables,void 0,{allowMissing:this.flags.allowMissingSecrets});Object.assign(O,e)}let k={...e.env,...O};r||warning({message:`You are not logged in with your Apify Account. Some features like Apify Proxy will not work. Call "apify login" to fix that.`});try{switch(h){case 0:{let e=b(rn);if(isNodeVersionSupported(_.version)?k.NODE_OPTIONS=k.NODE_OPTIONS?`${k.NODE_OPTIONS} --max-http-header-size=80000`:`--max-http-header-size=80000`:warning({message:`You are running Node.js version ${_.version}, which is no longer supported. Please upgrade to Node.js version ${e} or later.`}),v===0||v===1)await execWithLog({cmd:_.executablePath,args:[y],opts:{env:k,cwd:t},forwardSignals:tn});else{let e=await z(u(t,`package.json`),`utf8`).catch(()=>`{}`),n=JSON.parse(e);if(!n.scripts)throw Error(`No scripts were found in package.json. Please set it up for your project. For more information about that call "apify help run".`);if(!n.scripts[y])throw Error(`The script "${y}" was not found in package.json. Please set it up for your project. For more information about that call "apify help run".`);if(!_.pmPath)throw Error(`No npm executable found! Please make sure your Node.js runtime has npm installed if you want to run package.json scripts locally.`);await execWithLog({cmd:_.pmPath,args:[`run`,y],opts:{env:k,cwd:t},overrideCommand:_.pmName,forwardSignals:tn})}break}case 1:case 2:if(!isPythonVersionSupported(_.version)){error({message:`Python Actors require Python ${sn} or higher, but you have Python ${_.version}!`}),error({message:`Please install Python ${sn} or higher to be able to run Python Actors locally.`});return}v===1?await execWithLog({cmd:_.executablePath,args:[`-m`,y],opts:{env:k,cwd:t},forwardSignals:tn}):await execWithLog({cmd:_.executablePath,args:[y],opts:{env:k,cwd:t},forwardSignals:tn});break;default:error({message:`Failed to detect the language of your project. Please report this issue to the Apify team with your project structure over at https://github.com/apify/apify-cli/issues`})}}catch(t){e.exitCode=t.exitCode??1}finally{if(E){if(`tempInputKey`in E)await deleteFile(E.tempInputFilePath);else if(E.existingInput){let e=await B(E.inputFilePath);if(Math.trunc(e.mtimeMs)-E.writtenAt>=5){warning({message:`The "${E.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`});return}await V(E.inputFilePath,E.existingInput.body)}else await deleteFile(E.inputFilePath)}}}async validateAndStoreInput(t,n=`INPUT`){let{inputSchema:r}=await readInputSchema({cwd:e.cwd()}),i=p(e.cwd(),getLocalKeyValueStorePath());if(!r){if(!t)return null;await R(i,{recursive:!0});let e=`${An}${n}`,r=u(i,`${e}.json`);return await V(r,JSON.stringify(t.input,null,2)),{tempInputKey:e,tempInputFilePath:r}}let a=new Mn({strict:!1,unicodeRegExp:!1});_t(a,r);let s=getDefaultsFromInputSchema(r),c=getAjvValidator(r,a),l=getLocalInput(e.cwd(),n),f=u(i,l?.fileName??`${n}.json`),m;switch(t?.source){case`stdin`:m=`The input provided through standard input is invalid. Please fix the following errors:
|
|
223
223
|
`;break;case`input`:m=`The input provided through the --input flag is invalid. Please fix the following errors:
|
|
224
224
|
`;break;default:m=t?`The input provided through the ${t.source} file is invalid. Please fix the following errors:\n`:`The input in your storage is invalid. Please fix the following errors:
|
|
225
225
|
`}if(t){let e={...s,...t.input},a=vt(c,r,e);if(a.length>0)throw Error(`${m}${a.map(e=>` - ${e.message.replace(`Field input.`,`Field `)}`).join(`
|
|
@@ -241,4 +241,4 @@ When no path is provided, validates all schemas found in '${W}':
|
|
|
241
241
|
- Dataset schema (from "storages.dataset")
|
|
242
242
|
- Output schema (from "output")
|
|
243
243
|
- Key-Value Store schema (from "storages.keyValueStore")`;static group=`Local Actor Development`;static examples=[{description:`Validate the input schema discovered from the default locations.`,command:`apify validate-schema`},{description:`Validate a specific INPUT_SCHEMA.json file.`,command:`apify validate-schema ./my-schema.json`}];static docsUrl=`https://docs.apify.com/cli/docs/reference#apify-validate-schema`;static args={path:X.string({required:!1,description:`Optional path to your INPUT_SCHEMA.json file. If not provided, validates all schemas in '${W}'.`})};static hiddenAliases=[`vis`];async run(){if(this.args.path){await this.validateInputSchemaAtPath(this.args.path);return}await this.validateAllSchemas()}async validateInputSchemaAtPath(t){await readAndValidateInputSchema({forcePath:t,cwd:e.cwd(),getMessage:e=>`Validating input schema at ${e??t}`}),success({message:`Input schema is valid.`})}async validateAllSchemas(){let t=e.cwd(),n=!1,r=!1;try{let{inputSchema:e,inputSchemaPath:r}=await readInputSchema({cwd:t,throwOnMissing:!0});if(e){n=!0,info({message:`Validating input schema ${r?`at ${r}`:`embedded in '${W}'`}`});let t=new Mn({strict:!1});_t(t,e),success({message:`Input schema is valid.`})}}catch(e){n=!0,r=!0,error({message:e.message})}let i=[{label:`Dataset`,read:()=>readStorageSchema({cwd:t,key:`dataset`,label:`Dataset`,throwOnMissing:!0}),validate:validateDatasetSchema},{label:`Output`,read:()=>readStorageSchema({cwd:t,key:`output`,label:`Output`,getRef:e=>e?.output,throwOnMissing:!0}),validate:validateOutputSchema},{label:`Key-Value Store`,read:()=>readStorageSchema({cwd:t,key:`keyValueStore`,label:`Key-Value Store`,throwOnMissing:!0}),validate:validateKvsSchema}];for(let{label:e,read:t,validate:a}of i)try{let r=t();r&&(n=!0,info({message:`Validating ${e} schema ${r.schemaPath?`at ${r.schemaPath}`:`embedded in '${W}'`}`}),a(r.schema),success({message:`${e} schema is valid.`}))}catch(e){n=!0,r=!0,error({message:e.message})}if(!n)throw Error(`No schemas found. Make sure '${W}' exists and defines at least one schema.`);r&&(e.exitCode=5)}};const fi=[ActorIndexCommand,ActorsIndexCommand,AuthIndexCommand,BuildsIndexCommand,DatasetsIndexCommand,KeyValueStoresIndexCommand,MCPIndexCommand,RequestQueuesIndexCommand,RunsIndexCommand,SecretsIndexCommand,TasksIndexCommand,TelemetryIndexCommand,TemplatesIndexCommand,ApiCommand,TopLevelCallCommand,UpgradeCommand,InstallCommand,CreateCommand,EditInputSchemaCommand,InfoCommand,WrapScrapyCommand,InitCommand,LoginCommand,LogoutCommand,TopLevelPullCommand,ToplevelPushCommand,RunCommand,ValidateSchemaCommand,HelpCommand],pi=[ActorSetValueCommand,ActorPushDataCommand,ActorGetValueCommand,ActorGetPublicUrlCommand,ActorGetInputCommand,ActorChargeCommand,ActorCalculateMemoryCommand,ActorGenerateSchemaTypesCommand,HelpCommand,UpgradeCommand,InstallCommand,TelemetryIndexCommand];export{runCLI as i,fi as n,processVersionCheck as r,pi as t};
|
|
244
|
-
//# sourceMappingURL=_register-
|
|
244
|
+
//# sourceMappingURL=_register-CVylDy59.js.map
|