apify-cli 1.6.3-beta.5 → 1.6.3-beta.6
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{inspect as a,parseArgs as s,promisify as c}from"node:util";import{gt as l,gte as u,minVersion as f,satisfies as p}from"semver";import{appendFileSync as m,constants as h,copyFileSync as g,createWriteStream as _,existsSync as v,fstat as y,mkdirSync as b,openSync as x,readFileSync as S,readdirSync as C,realpathSync as ee,renameSync as te,rmSync as w,statSync as T,unlinkSync as ne,writeFileSync as E}from"node:fs";import D,{basename as re,dirname as O,isAbsolute as ie,join as k,relative as ae,resolve as oe,sep as se}from"node:path";import ce from"string-width";import le from"strip-ansi";import{once as ue}from"node:events";import{homedir as de,platform as fe}from"node:os";import pe from"ci-info";import{ACTOR_ENV_VARS as A,ACTOR_JOB_STATUSES as j,ACTOR_JOB_TERMINAL_STATUSES as me,ACTOR_NAME as he,ACTOR_SOURCE_TYPES as ge,APIFY_ENV_VARS as M,KEY_VALUE_STORE_KEYS as _e,LOCAL_ACTOR_ENV_VARS as ve,LOCAL_STORAGE_SUBDIRS as ye,MAX_MULTIFILE_BYTES as be,META_ORIGINS as xe,SOURCE_FILE_FORMATS as Se}from"@apify/consts";import{jaroWinkler as Ce}from"@skyra/jaro-winkler";import we from"js-levenshtein";import{createHmacSignature as Te,cryptoRandomObjectId as Ee}from"@apify/utilities";import{execSync as De,spawn as Oe}from"node:child_process";import{access as ke,lstat as Ae,mkdir as N,readFile as P,readdir as F,rename as je,stat as I,symlink as Me,unlink as Ne,writeFile as L}from"node:fs/promises";import{get as Pe}from"node:https";import{finished as Fe,pipeline as Ie}from"node:stream/promises";import{DurationFormatter as Le,Time as Re,TimeTypes as R}from"@sapphire/duration";import{Timestamp as ze}from"@sapphire/timestamp";import Be from"adm-zip";import Ve from"ajv/dist/2019.js";import{ApifyClient as He,DownloadItemsFormat as z}from"apify-client";import Ue
|
|
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{inspect as a,parseArgs as s,promisify as c}from"node:util";import{gt as l,gte as u,minVersion as f,satisfies as p}from"semver";import{appendFileSync as m,constants as h,copyFileSync as g,createWriteStream as _,existsSync as v,fstat as y,mkdirSync as b,openSync as x,readFileSync as S,readdirSync as C,realpathSync as ee,renameSync as te,rmSync as w,statSync as T,unlinkSync as ne,writeFileSync as E}from"node:fs";import D,{basename as re,dirname as O,isAbsolute as ie,join as k,relative as ae,resolve as oe,sep as se}from"node:path";import ce from"string-width";import le from"strip-ansi";import{once as ue}from"node:events";import{homedir as de,platform as fe}from"node:os";import pe from"ci-info";import{ACTOR_ENV_VARS as A,ACTOR_JOB_STATUSES as j,ACTOR_JOB_TERMINAL_STATUSES as me,ACTOR_NAME as he,ACTOR_SOURCE_TYPES as ge,APIFY_ENV_VARS as M,KEY_VALUE_STORE_KEYS as _e,LOCAL_ACTOR_ENV_VARS as ve,LOCAL_STORAGE_SUBDIRS as ye,MAX_MULTIFILE_BYTES as be,META_ORIGINS as xe,SOURCE_FILE_FORMATS as Se}from"@apify/consts";import{jaroWinkler as Ce}from"@skyra/jaro-winkler";import we from"js-levenshtein";import{createHmacSignature as Te,cryptoRandomObjectId as Ee}from"@apify/utilities";import{execSync as De,spawn as Oe}from"node:child_process";import{access as ke,lstat as Ae,mkdir as N,readFile as P,readdir as F,rename as je,stat as I,symlink as Me,unlink as Ne,writeFile as L}from"node:fs/promises";import{get as Pe}from"node:https";import{finished as Fe,pipeline as Ie}from"node:stream/promises";import{DurationFormatter as Le,Time as Re,TimeTypes as R}from"@sapphire/duration";import{Timestamp as ze}from"@sapphire/timestamp";import Be from"adm-zip";import Ve from"ajv/dist/2019.js";import{ApifyClient as He,DownloadItemsFormat as z}from"apify-client";import{ZipArchive as Ue}from"archiver";import We,{AxiosHeaders as Ge}from"axios";import Ke from"escape-string-regexp";import qe from"ignore";import{getEncoding as Je}from"istextorbinary";import Ye,{Mime as Xe}from"mime";import Ze from"mime/types/other.js";import Qe from"mime/types/standard.js";import{glob as $e}from"tinyglobby";import{rimraf as et}from"rimraf";import{Result as tt,err as nt,none as B,ok as V,some as rt}from"@sapphire/result";import it from"configparser";import at from"@inquirer/input";import ot from"is-ci";import{execa as st}from"execa";import ct from"which";import{calculateRunDynamicMemory as lt}from"@apify/actor-memory-expression";import{Separator as ut,createPrompt as dt,isEnterKey as ft,makeTheme as pt,useKeypress as mt,usePrefix as ht,useState as gt}from"@inquirer/core";import{MemoryStorage as _t}from"@crawlee/memory-storage";import{compile as vt}from"json-schema-to-typescript";import{cloneDeep as H}from"es-toolkit";import{validateInputSchema as yt,validateInputUsingValidator as bt}from"@apify/input_schema";import{getDatasetSchemaValidator as xt,getKeyValueStoreSchemaValidator as St,getOutputSchemaValidator as Ct}from"@apify/json_schemas";import wt from"cli-table3";import Tt from"jju";import Et from"tiged";import Dt from"open";import{fetchManifest as Ot,manifestUrl as kt,wrapperManifestUrl as At}from"@apify/actor-templates";import jt from"computer-name";import Mt from"cors";import Nt from"express";import Pt from"@inquirer/password";import Ft from"@inquirer/select";import It from"node:assert";import{ReadStream as Lt}from"node:tty";import Rt from"detect-indent";import{fileURLToPath as zt}from"node:url";import Bt from"@root/walk";import Vt 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 link(e){internalLog({[e.stdout?`stdoutOutput`:`stderrOutput`]:[t.blue(e.message),e.url]})}function detectInstallMethod(){if(process.env.APIFY_CLI_MARKED_INSTALL_METHOD)return process.env.APIFY_CLI_MARKED_INSTALL_METHOD;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=ee(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 Ht=null;function useCLIMetadata(){if(Ht)return Ht;let e=detectInstallMethod(),t=getRuntimeInfo();return Ht={version:`1.6.3-beta.6`,hash:`96c4f0942f3144248c6a5218bb531c0453d24794`,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`&&(Ht.installPath=O(process.execPath)),Ht}let Ut;function getMaxLineWidth(){if(Ut)return Ut;let e=Number(process.env.APIFY_CLI_MAX_LINE_WIDTH);if(!Number.isNaN(e))Ut=e;else if(!process.stdout.isTTY)Ut=80;else{let e=process.stdout.getWindowSize?.()[0]??-1;Ut=e<1?80:e<40?40:e}return Ut}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(`
|
|
2
2
|
`)[0]}`,``)}pushDescription(e){if(!this.command.description)return;e.push(t.bold(`DESCRIPTION`));let r=n(i(this.command.description,getMaxLineWidth()-2,{trim:!1}),2);e.push(r),e.push(``)}pushExamples(e){let{examples:r}=this.command;if(r?.length){e.push(t.bold(`EXAMPLES`));for(let a of r){if(a.description){let r=n(i(a.description,getMaxLineWidth()-4,{trim:!1}).split(`
|
|
3
3
|
`).map(e=>`# ${e}`).join(`
|
|
4
4
|
`),2);e.push(t.dim(r))}e.push(` $ ${this.normalizeExampleCommand(a.command)}`),e.push(``)}}}normalizeExampleCommand(e){let t=this.entrypoint.split(` `);if(t.length<2)return e;let n=t[t.length-1],r=`${t.slice(0,-1).join(` `)} `,i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=e;return a.startsWith(`${n} `)&&(a=`${r}${a}`),a=a.replace(RegExp(`\\|\\s+${i}\\s`,`g`),`| ${r}${n} `),a}pushInteractiveNote(e){if(!this.command.interactive)return;e.push(t.bold(`NOTE`));let r=n(i(this.command.interactiveNote||`This command prompts the user for input. To run non-interactively (e.g. in CI or from an AI agent), pass all required arguments and flags explicitly.`,getMaxLineWidth()-2,{trim:!1}),2);e.push(r),e.push(``)}pushLearnMore(e){this.command.docsUrl&&(e.push(t.bold(`LEARN MORE`)),e.push(` ${this.command.docsUrl}`),e.push(``))}pushNewLineBeforeNewEntryIfLengthIsPastTheLimit({state:e,itemToAdd:t,indentSize:n}){ce(e.join(` `).split(`
|
|
@@ -28,7 +28,7 @@ import e from"node:process";import t from"chalk";import n from"indent-string";im
|
|
|
28
28
|
`)}\n`,{flag:`a`})):E(n,`${i.join(`
|
|
29
29
|
`)}\n`,{flag:`w`}))},Tn=new Xe(Qe,Ze).define({"application/gzip":[`tgz`],"text/typescript":[`ts`,`tsx`,`mts`]},!0),getSourceFileFormat=(e,t)=>{let n=Tn.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`)?Se.TEXT:Se.BASE64:Je(t)===`binary`?Se.BASE64:Se.TEXT},createSourceFiles=async(e,t)=>e.map(e=>{let n=S(k(t,e)),r=getSourceFileFormat(e,n);return{name:e,format:r,content:r===Se.TEXT?n.toString(`utf8`):n.toString(`base64`)}}),getGitignoreFallbackFilter=async e=>{let t=await $e(`**/.gitignore`,{dot:!0,cwd:e,ignore:[`.git/**`],expandDirectories:!1}),n=[];for(let r of t){let t=O(r),i=await P(k(e,r),`utf-8`);n.push({dir:t===`.`?``:t,ig:Sn().add(i)})}let r=O(e);for(;r!==O(r)&&!v(k(r,`.git`));){let t=k(r,`.gitignore`);if(v(t))try{let i=await P(t,`utf-8`),a=ae(r,e);n.push({dir:``,ig:Sn().add(i),ancestorPrefix:a})}catch{}r=O(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=k(e,`.actorignore`);if(!v(t))return{excludeFilter:null,forceIncludePatterns:[]};let n=(await P(t,`utf-8`)).split(`
|
|
30
30
|
`),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=Sn().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=De(`git ls-files --others --ignored --exclude-standard --directory`,{cwd:n,encoding:`utf-8`,stdio:[`ignore`,`pipe`,`ignore`]}).split(`
|
|
31
|
-
`).filter(Boolean);if(e.length>0){let t=Sn().add(e);gitIgnoreFilter=e=>e.filter(e=>!t.ignores(e))}}catch{gitIgnoreFilter=await getGitignoreFallbackFilter(n)}let s=await $e([`*`,`**/**`],{ignore:r,dot:!0,expandDirectories:!1,cwd:n}),c=gitIgnoreFilter?gitIgnoreFilter(s):s;if(i&&(c=i(c)),a.length>0){let e=Sn().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)=>{v(e)&&await deleteFile(e);let r=_(e),i=Ue(
|
|
31
|
+
`).filter(Boolean);if(e.length>0){let t=Sn().add(e);gitIgnoreFilter=e=>e.filter(e=>!t.ignores(e))}}catch{gitIgnoreFilter=await getGitignoreFallbackFilter(n)}let s=await $e([`*`,`**/**`],{ignore:r,dot:!0,expandDirectories:!1,cwd:n}),c=gitIgnoreFilter?gitIgnoreFilter(s):s;if(i&&(c=i(c)),a.length>0){let e=Sn().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)=>{v(e)&&await deleteFile(e);let r=_(e),i=new Ue({zlib:{level:6}});i.pipe(r),t.forEach(e=>i.file(k(n,e),{name:e})),await i.finalize()},getLocalInput=(e,t)=>{let n=getLocalKeyValueStorePath();if(!v(k(e,n)))return;let r=C(k(e,n)).find(e=>!!e.match(inputFileRegExp(t??`INPUT`)));return r?{body:S(k(e,n,r)),contentType:Tn.getType(r),fileName:r}:void 0},purgeDefaultQueue=async()=>{let e=getLocalRequestQueuePath();v(getLocalStorageDir())&&v(e)&&await rimrafPromised(e)},purgeDefaultDataset=async()=>{let e=getLocalDatasetPath();v(getLocalStorageDir())&&v(e)&&await rimrafPromised(e)},purgeDefaultKeyValueStore=async(...e)=>{let t=getLocalKeyValueStorePath();if(!v(getLocalStorageDir())||!v(t))return;let n=C(t),r=(e.length>0?e:[`INPUT`]).map(inputFileRegExp),i=[];n.forEach(e=>{r.some(t=>t.test(e))||i.push(deleteFile(k(t,e)))}),await Promise.all(i)},outputJobLog=async({job:t,timeoutMillis:n,apifyClient:r})=>{let{id:i,status:a}=t,s=r||new He({baseUrl:e.env.APIFY_CLIENT_BASE_URL});if(me.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 e=>{let t=e||_e.INPUT;return(await $e([`${getLocalStorageDir()}/**`,`!${getLocalKeyValueStorePath()}/${t}.*`,`!${getLocalKeyValueStorePath()}/${xn}${t}.*`])).length===0},validateActorName=e=>{if(!he.REGEX.test(e))throw Error(`The Actor name must be a DNS hostname-friendly string (e.g. my-newest-actor).`);if(e.length<he.MIN_LENGTH)throw Error(`The Actor name must be at least 3 characters long.`);if(e.length>he.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<he.MIN_LENGTH&&(t=`${t}-apify-actor`),t=t.replaceAll(/^-+/g,``).replaceAll(/-+$/g,``),t.slice(0,he.MAX_LENGTH)},isPythonVersionSupported=e=>p(e,`^${sn}`),isNodeVersionSupported=e=>u(e,f(rn)),downloadAndUnzip=async({url:e,pathTo:t})=>{let n=await httpsGet(e),r=[];n.on(`data`,e=>r.push(e)),await Fe(n),new Be(Buffer.concat(r)).extractAllTo(t,!0)},G=new ze(`YYYY-MM-DD [at] HH:mm:ss`),En=new ze(`YYYY-MM-DD[
|
|
32
32
|
]HH:mm:ss`),Dn=new ze(`YYYY-MM-DD`),On=new Le,K=new Le({[R.Day]:{DEFAULT:`d`},[R.Hour]:{DEFAULT:`h`},[R.Minute]:{DEFAULT:`m`},[R.Month]:{DEFAULT:`M`},[R.Second]:{DEFAULT:`s`},[R.Week]:{DEFAULT:`w`},[R.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 tildify=e=>e.startsWith(de())?e.replace(de(),`~`):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=[k(t,`.bashrc`),k(t,`.bash_profile`)];e.env.XDG_CONFIG_HOME&&n.push(k(e.env.XDG_CONFIG_HOME,`.bashrc`),k(e.env.XDG_CONFIG_HOME,`.bash_profile`),k(e.env.XDG_CONFIG_HOME,`bashrc`),k(e.env.XDG_CONFIG_HOME,`bash_profile`));for(let e of n)if(v(e))return e;return null}case`zsh`:return k(e.env.ZDOTDIR||de(),`.zshrc`);case`fish`:return k(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 kn=[`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(`
|
|
33
33
|
`);function createAnonymousId(){return`CLI:${Ee()}`}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(!v(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:kn}),useTelemetryState()}let t=JSON.parse(S(e,`utf-8`));return await migrateStateV0ToV1(t)?useTelemetryState():t}function updateTelemetryState(e,t){let n={...e};t?.(n),b(O(TELEMETRY_FILE_PATH()),{recursive:!0}),E(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 An=useCLIMetadata(),jn=An.isBeta?`rT67mFpIQD5qS9bJBoIYSFbZucrt2DZC`:`2uPK6yhPqjC0eNUFhaY78S26cRKyaa6t`;async function trackEvent(e,t){let n=await useTelemetryIdentifiers(),r={anonymousId:n.anonymousId,context:{app:{name:`apify-cli`,version:An.version,build:An.hash},library:{name:`apify-cli`,version:An.version},os:{name:An.platform},userAgent:mn,channel:`server`},event:e,properties:{...t,app:`cli`},timestamp:new Date().toISOString(),userId:n.userId,writeKey:jn};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)}}const Mn=`confirm`,Nn=`no-${Mn}`;function stdinCheckWrapper(e,{errorMessageForStdin:t=`Please use the --${Mn}/--${Nn} flags to confirm the action.`}={}){return async(n,...r)=>{let{isTTY:i,hasData:a}=await useStdin(),s=n;if(ot||!i&&!a){if(s.providedConfirmFromStdin===void 0)throw Error(s.errorMessageForStdin??t??`Please use the --${Mn}/--${Nn} flags to confirm the action.`);return s.providedConfirmFromStdin}return await e(n,...r)}}const Pn=stdinCheckWrapper(async({message:e,validate:t,default:n})=>await at({message:e,validate:t,default:n}),{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=S(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 v(k(e,`scrapy.cfg`))}async init(){await this.loadSettings()}loadScrapyCfg(){let e=new it,t=oe(k(this.pathname,`scrapy.cfg`));if(!v(t))throw Error(`scrapy.cfg not found in "${t}".
|
|
34
34
|
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 Pn({message:`Enter the Scrapy BOT_NAME (see settings.py):`,default:e}),n=await Pn({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=k(this.pathname,n.replaceAll(`.`,`/`)),r=C(e,{withFileTypes:!0});for(let n of r)n.isFile()&&n.name.endsWith(`.py`)&&n.name!==`__init__.py`&&t.push(...new SpiderFileAnalyzer(k(e,n.name)).getSpiders())}return t}};function normalizeExecutablePath(e){return e?e.startsWith(`"`)?e:ie(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([I(k(e,`yarn.lock`)).then(()=>!0).catch(()=>!1),I(k(e,`pnpm-lock.yaml`)).then(()=>!0).catch(()=>!1),I(k(e,`bun.lockb`)).then(()=>!0).catch(()=>!1),I(k(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=`python -m pip install -r requirements.txt`)}),t}const Fn=new Map,In={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 st(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 st(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=Fn.get(t);if(n)return cliDebugPrint(`useJavaScriptRuntime`,{cacheHit:!0,cwd:t,runtime:n.unwrapOr(null)}),n;for(let[e,n]of Object.entries(In))try{let r=normalizeExecutablePath(await ct(e)),i=await getRuntimeVersion(r,n);if(i){let n={executablePath:r,version:i};if(e===`node`){let e=normalizeExecutablePath(await ct(`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 Fn.set(t,rt(n)),cliDebugPrint(`useJavaScriptRuntime`,{cacheHit:!1,cwd:t,runtime:Fn.get(t)?.unwrap()}),rt(n)}}catch{}return Fn.set(t,B),cliDebugPrint(`useJavaScriptRuntime`,{cacheHit:!1,cwd:t,runtime:null}),B}const q=new Map;async function getPythonVersion(t){try{let n=await st(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=q.get(t);if(r&&!n)return cliDebugPrint(`usePythonRuntime`,{cacheHit:!0,cwd:t,runtime:r.unwrapOr(null)}),r;let i=fe()===`win32`,a=i?[`Scripts`,`python.exe`]:[`bin`,`python3`],s;s=e.env.VIRTUAL_ENV?k(e.env.VIRTUAL_ENV,...a):k(t,`.venv`,...a),s=normalizeExecutablePath(s);try{let e=await getPythonVersion(s);if(e)return q.set(t,rt({executablePath:s,version:e})),cliDebugPrint(`usePythonRuntime`,{cacheHit:!1,cwd:t,runtime:q.get(t)?.unwrap()}),q.get(t)}catch{}let c=[`python3`,`python`,...i?[`python3.exe`,`python.exe`]:[]];for(let e of c)try{let n=normalizeExecutablePath(await ct(e)),r=await getPythonVersion(n);if(r)return q.set(t,rt({executablePath:n,version:r})),cliDebugPrint(`usePythonRuntime`,{cacheHit:!1,cwd:t,runtime:q.get(t)?.unwrap()}),q.get(t)}catch{}return q.set(t,B),cliDebugPrint(`usePythonRuntime`,{cacheHit:!1,cwd:t,runtime:null}),B}const Ln=new Map;async function useCwdProject({cwd:t=e.cwd()}={}){let n=Ln.get(t);if(n)return cliDebugPrint(`useCwdProject`,{cacheHit:!0,project:n}),V(n);let r={type:3},check=async()=>{if(await checkScrapyProject(t)){r.type=2,r.runtime=(await usePythonRuntime({cwd:t})).unwrapOr(void 0);let e=new ScrapyProjectAnalyzer(t);if(e.loadScrapyCfg(),e.configuration.hasKey(`apify`,`mainpy_location`))r.entrypoint={path:e.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 nt({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(k(k(t,e.replace(/\./g,`/`)),`__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,r.runtime=(await useJavaScriptRuntime()).unwrapOr(void 0),e.type===`file`?r.entrypoint={path:e.path}:e.type===`script`&&(r.entrypoint={script:e.script});return}return V(r)},i=await check();return i?.isErr()?(cliDebugPrint(`useCwdProject`,{cacheHit:!1,error:i}),i):(cliDebugPrint(`useCwdProject`,{cacheHit:!1,project:r}),Ln.set(t,r),V(r))}async function checkNodeProject(e){let t=k(e,`package.json`);try{let n=await P(t,`utf-8`),r=JSON.parse(n);if(r.scripts?.start)return{type:`script`,script:`start`};if(r.main)try{return await ke(oe(e,r.main)),{path:oe(e,r.main),type:`file`}}catch{}return{type:`unknown-entrypoint`}}catch{}let n=[k(e,`index.js`),k(e,`index.mjs`),k(e,`index.cjs`),k(e,`main.js`),k(e,`main.mjs`),k(e,`main.cjs`),k(e,`src`,`index.js`),k(e,`src`,`index.mjs`),k(e,`src`,`index.cjs`),k(e,`src`,`main.js`),k(e,`src`,`main.mjs`),k(e,`src`,`main.cjs`),k(e,`dist`,`index.js`),k(e,`dist`,`index.mjs`),k(e,`dist`,`index.cjs`),k(e,`dist`,`main.js`),k(e,`dist`,`main.mjs`),k(e,`dist`,`main.cjs`)];for(let e of n)try{return await ke(e),{path:e,type:`file`}}catch{}return null}async function fileExists(e){try{return await ke(e),!0}catch{return!1}}async function dirExists(e){try{return(await I(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 F(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=k(e,n.name);try{let e=await F(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 F(k(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 F(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 F(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(k(e,r.name,`__init__.py`)),a=i||await dirHasPyFiles(k(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 F(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(k(e,t,`__init__.py`))&&n.push({name:t,path:k(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=k(e,`src`),i=await fileExists(k(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(`
|
|
@@ -222,4 +222,4 @@ When no path is provided, validates all schemas found in '${W}':
|
|
|
222
222
|
- Dataset schema (from "storages.dataset")
|
|
223
223
|
- Output schema (from "output")
|
|
224
224
|
- 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:Z.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});e&&(n=!0,info({message:`Validating input schema ${r?`at ${r}`:`embedded in '${W}'`}`}),yt(new Cn({strict:!1}),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 Wr=[ActorIndexCommand,ActorsIndexCommand,AuthIndexCommand,BuildsIndexCommand,DatasetsIndexCommand,KeyValueStoresIndexCommand,RequestQueuesIndexCommand,RunsIndexCommand,SecretsIndexCommand,TasksIndexCommand,TelemetryIndexCommand,ApiCommand,TopLevelCallCommand,UpgradeCommand,InstallCommand,CreateCommand,EditInputSchemaCommand,InfoCommand,WrapScrapyCommand,InitCommand,LoginCommand,LogoutCommand,TopLevelPullCommand,ToplevelPushCommand,RunCommand,ValidateSchemaCommand,HelpCommand],Gr=[ActorSetValueCommand,ActorPushDataCommand,ActorGetValueCommand,ActorGetPublicUrlCommand,ActorGetInputCommand,ActorChargeCommand,ActorCalculateMemoryCommand,ActorGenerateSchemaTypesCommand,HelpCommand,UpgradeCommand,InstallCommand,TelemetryIndexCommand];export{runCLI as i,Wr as n,processVersionCheck as r,Gr as t};
|
|
225
|
-
//# sourceMappingURL=_register-
|
|
225
|
+
//# sourceMappingURL=_register-Dh-OWrFt.js.map
|