Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"homepage": "https://github.com/apify/apify-cli#readme",
"engines": {
"node": ">=22"
"node": ">=22.15.0"
},
"dependencies": {
"@apify/actor-memory-expression": "^1.0.3",
Expand All @@ -86,7 +86,7 @@
"@skyra/jaro-winkler": "^1.1.1",
"adm-zip": "~0.6.1",
"ajv": "~8.20.0",
"apify-client": "^2.26.0",
"apify-client": "^3.0.0-rc.2",
"archiver": "~8.0.0",
"axios": "^1.21.1",
"chalk": "~6.0.1",
Expand Down
32 changes: 30 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 2 additions & 12 deletions scripts/build-cli-bundles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,9 @@ for (const entryPoint of entryPoints) {
// entrypoint file name (`bundle.ts`) - install/upgrade and the asset matcher all key off `apify-cli`.
const cliName = 'apify-cli';

const lines = readFileSync(entryPoint, 'utf-8').split('\n');
lines.splice(1, 0, 'import "proxy-agent";');

// Step 1: create one fat JS file with node resolver to ensure no imports point to non-node export conditions
const result = await build({
entrypoints: [entryPoint],
files: {
[entryPoint]: lines.join('\n'),
},
define: {
__APIFY_CLI_SKILL__: JSON.stringify(APIFY_CLI_SKILL),
__APIFY_WINDOWS_UPGRADE_SCRIPT__: JSON.stringify(WINDOWS_UPGRADE_SCRIPT),
Expand All @@ -131,12 +125,8 @@ for (const entryPoint of entryPoints) {

const entrypointResultFilePath = result.outputs[0]!.path;

// Fix apify client js (it now lazy loads proxy-agent, which makes bun skip it from the bundle).
// Kept in memory only — the per-target write below is what lands on disk before each compile.
const fatEntrypointContent = (await result.outputs[0]!.text()).replace(
`(0, utils_1.dynamicNodeImport)("proxy-agent")`,
`Promise.resolve().then(() => import_proxy_agent)`,
);
const fatEntrypointContent = await result.outputs[0]!.text();

// `replaceAll` is silent if the placeholder is gone, shipping a bundle that falls back to
// plaintext storage. Validate once up front and fail loud.
Expand All @@ -162,7 +152,7 @@ for (const entryPoint of entryPoints) {

// Point the keyring import at this target's native subpackage so --compile embeds its
// `.node`. Rewrite every iteration so the compiled file is never the stale, unpatched
// Bun output — the proxy-agent fix above lands on disk here too, not just the keyring swap.
// Bun output.
const subpackage = keyringSubpackage(os, arch, isMusl);
await writeFile(entrypointResultFilePath, fatEntrypointContent.replaceAll(KEYRING_PLACEHOLDER, subpackage));

Expand Down
2 changes: 1 addition & 1 deletion src/commands/actor/get-public-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ActorGetPublicUrlCommand extends ApifyCommand<typeof ActorGetPublic
return;
}

const apifyClient = (await getApifyStorageClient()) as ApifyClient;
const apifyClient = (await getApifyStorageClient()) as unknown as ApifyClient;
const store = await apifyClient.keyValueStore(storeId).get();

if (!store) {
Expand Down
16 changes: 8 additions & 8 deletions src/commands/actors/call.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import process from 'node:process';

import {
type ActorRun,
type Run,
type ActorStartOptions,
type ActorTaggedBuild,
type TaggedBuildInfo,
type ApifyClient,
type Dataset,
type DatasetResource,
DownloadItemsFormat,
} from 'apify-client';
import chalk from 'chalk';
Expand Down Expand Up @@ -152,7 +152,7 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
}

if (this.flags.timeout !== undefined) {
runOpts.timeout = this.flags.timeout;
runOpts.runTimeoutSecs = this.flags.timeout;
}

if (this.flags.memory) {
Expand Down Expand Up @@ -181,7 +181,7 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
}

let runStarted = false;
let run: ActorRun;
let run: Run;

const iterator = runActorOrTaskOnCloud(apifyClient, {
actorOrTaskData: {
Expand Down Expand Up @@ -217,12 +217,12 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {

// basic version info

const expectedActorVersion = run.buildNumber.split('.').slice(0, 2).join('.');
const expectedActorVersion = run.buildNumber?.split('.').slice(0, 2).join('.');

const actorVersion = actorData.versions.find((item) => item.versionNumber === expectedActorVersion);

const runVersionTaggedAs = Object.entries(
(actorData.taggedBuilds ?? {}) as Record<string, ActorTaggedBuild>,
(actorData.taggedBuilds ?? {}) as Record<string, TaggedBuildInfo>,
).find(([, data]) => data.buildNumber === yieldedRun.buildNumber)?.[0];

const messageParts = [`${chalk.yellow('Build')}:`, chalk.cyan(run.buildNumber)];
Expand Down Expand Up @@ -270,7 +270,7 @@ export class ActorsCallCommand extends ApifyCommand<typeof ActorsCallCommand> {
if (this.flags.outputDataset && run!.status === ACTOR_JOB_STATUSES.SUCCEEDED) {
const datasetId = run!.defaultDatasetId;

let info: Dataset;
let info: DatasetResource;
let retries = 4;

// Why is this needed? Sometimes, when fetching the dataset info right after the run ends, the object doesn't have the stats up-to-date.
Expand Down
20 changes: 14 additions & 6 deletions src/commands/actors/info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import type { Actor, ActorChargeEvent, ActorTaggedBuild, ApifyApiError, ApifyClient, Build, User } from 'apify-client';
import type {
ActorResource,
ActorChargeEvent,
TaggedBuildInfo,
ApifyApiError,
ApifyClient,
Build,
UserPrivateInfo,
} from 'apify-client';
import chalk from 'chalk';

import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
Expand All @@ -9,9 +17,9 @@ import { CompactMode, ResponsiveTable } from '../../lib/commands/responsive-tabl
import { error, simpleLog } from '../../lib/outputs.js';
import { DurationFormatter, getLoggedClientOrThrow, printJsonToStdout, TimestampFormatter } from '../../lib/utils.js';

interface HydratedActorInfo extends Omit<Actor, 'taggedBuilds'> {
taggedBuilds?: Record<string, ActorTaggedBuild & { build?: Build }>;
actorMaker?: User;
interface HydratedActorInfo extends Omit<ActorResource, 'taggedBuilds'> {
taggedBuilds?: Record<string, TaggedBuildInfo & { build?: Build }>;
actorMaker?: UserPrivateInfo;
}

// apify-client's ActorChargeEvent declares eventPriceUsd as required and is missing
Expand Down Expand Up @@ -188,7 +196,7 @@ export class ActorsInfoCommand extends ApifyCommand<typeof ActorsInfoCommand> {
if (actorInfo.actorMaker) {
message.push(
'',
`${chalk.yellow('Made by:')} ${chalk.cyan(actorInfo.actorMaker.profile.name ?? actorInfo.actorMaker.username)}`,
`${chalk.yellow('Made by:')} ${chalk.cyan(actorInfo.actorMaker.profile?.name ?? actorInfo.actorMaker.username)}`,
);

// Missing types who?
Expand Down Expand Up @@ -230,7 +238,7 @@ export class ActorsInfoCommand extends ApifyCommand<typeof ActorsInfoCommand> {
break;
}
case 'PRICE_PER_DATASET_ITEM': {
const pricePerOneKItems = latestPricingInfo.pricePerUnitUsd * 1000;
const pricePerOneKItems = (latestPricingInfo.pricePerUnitUsd ?? 0) * 1000;

message.push(
`${chalk.yellow('Pricing information:')} ${chalk.bgGray(`$${pricePerOneKItems.toFixed(2)} / 1,000 results`)}`,
Expand Down
28 changes: 9 additions & 19 deletions src/commands/actors/ls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Time } from '@sapphire/duration';
import type { Actor, ActorRunListItem, ActorTaggedBuild, PaginatedList } from 'apify-client';
import type { ActorListItem, ActorResource, RunListItem, TaggedBuildInfo, PaginatedList } from 'apify-client';
import chalk from 'chalk';

import type { ACTOR_JOB_STATUSES } from '@apify/consts';
Expand Down Expand Up @@ -79,19 +79,9 @@ const myRecentlyUsedTable = new ResponsiveTable({
},
});

interface HydratedListData {
id: string;
createdAt: Date;
modifiedAt: Date;
name: string;
username: string;
title: string;
stats: {
totalRuns: number;
lastRunStartedAt: string | null;
};
actor: Actor | null;
lastRun: ActorRunListItem | null;
interface HydratedListData extends ActorListItem {
actor: ActorResource | null;
lastRun: RunListItem | null;
}

export class ActorsLsCommand extends ApifyCommand<typeof ActorsLsCommand> {
Expand Down Expand Up @@ -180,14 +170,14 @@ export class ActorsLsCommand extends ApifyCommand<typeof ActorsLsCommand> {
limit: 1,
offset: 0,
total: 0,
}) satisfies PaginatedList<ActorRunListItem>,
}) satisfies PaginatedList<RunListItem>,
);

return {
...actorData,
actor: actor ?? null,
lastRun: (runs.items[0] ?? null) as ActorRunListItem | null,
} as HydratedListData;
lastRun: (runs.items[0] ?? null) as RunListItem | null,
};
}),
),
};
Expand Down Expand Up @@ -217,7 +207,7 @@ export class ActorsLsCommand extends ApifyCommand<typeof ActorsLsCommand> {
6;

for (const item of actorList.items) {
const lastRunDisplayedTimestamp = item.stats.lastRunStartedAt
const lastRunDisplayedTimestamp = item.stats?.lastRunStartedAt
? MultilineTimestampFormatter.display(item.stats.lastRunStartedAt)
: '';

Expand All @@ -238,7 +228,7 @@ export class ActorsLsCommand extends ApifyCommand<typeof ActorsLsCommand> {
const defaultBuild = item.actor
? (() => {
const buildVersionToTag = Object.entries(
(item.actor.taggedBuilds ?? {}) as Record<string, ActorTaggedBuild>,
(item.actor.taggedBuilds ?? {}) as Record<string, TaggedBuildInfo>,
).find(
([tag, data]) =>
data.buildNumber === item.actor!.defaultRunOptions.build || tag === item.actor!.defaultRunOptions.build,
Expand Down
11 changes: 7 additions & 4 deletions src/commands/actors/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { mkdirSync, readdirSync, writeFileSync } from 'node:fs';
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
import process from 'node:process';

import type { SourceCodeFile, SourceCodeFolder } from 'apify-client';
import { downloadTemplate } from 'giget';
import jju from 'jju';
import { gt } from 'semver';
Expand Down Expand Up @@ -31,6 +32,9 @@ const extractGitHubZip = async (url: string, directoryPath: string) => {
zipFile.extractEntryTo(entries[0].entryName, directoryPath, false);
};

const isSourceFolder = (file: SourceCodeFile | SourceCodeFolder): file is SourceCodeFolder =>
'folder' in file && file.folder;

export class ActorsPullCommand extends ApifyCommand<typeof ActorsPullCommand> {
static override name = 'pull' as const;

Expand Down Expand Up @@ -192,10 +196,9 @@ export class ActorsPullCommand extends ApifyCommand<typeof ActorsPullCommand> {
for (const { file, target } of files) {
mkdirSync(dirname(target), { recursive: true });

// @ts-expect-error TODO: is this an actual field?
if (!file.folder) {
const fileContent =
file.format === 'BASE64' ? Buffer.from(file.content, 'base64').toString() : file.content;
if (!isSourceFolder(file)) {
const content = file.content ?? '';
const fileContent = file.format === 'BASE64' ? Buffer.from(content, 'base64').toString() : content;

if (target === join(root, LOCAL_CONFIG_PATH)) {
const actorJson = jju.parse(fileContent);
Expand Down
8 changes: 4 additions & 4 deletions src/commands/actors/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tmpdir } from 'node:os';
import { dirname, join, relative, resolve } from 'node:path';
import process from 'node:process';

import type { Actor, ActorCollectionCreateOptions, ActorDefaultRunOptions, ApifyClient, Build } from 'apify-client';
import type { ActorResource, ActorCollectionCreateOptions, DefaultRunOptions, ApifyClient, Build } from 'apify-client';
import chalk from 'chalk';
import { isCI } from 'ci-info';
import open from 'open';
Expand Down Expand Up @@ -811,7 +811,7 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
const redirectUrlPart = isOrganizationLoggedIn ? `/organization/${userInfo.id}` : '';

let actorId: string;
let actor: Actor;
let actor: ActorResource;
let isActorCreatedNow = false;

// User can override Actor version and build tag, attributes in localConfig will remain same.
Expand Down Expand Up @@ -845,7 +845,7 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
} else {
const { templates } = await fetchManifest();
const actorTemplate = templates.find((t) => t.name === actorConfig!.template);
const defaultRunOptions = (actorTemplate?.defaultRunOptions || DEFAULT_RUN_OPTIONS) as ActorDefaultRunOptions;
const defaultRunOptions = (actorTemplate?.defaultRunOptions || DEFAULT_RUN_OPTIONS) as DefaultRunOptions;
const newActor: ActorCollectionCreateOptions = {
name: actorConfig!.name as string,
title: actorConfig!.title as string | undefined,
Expand Down Expand Up @@ -1182,7 +1182,7 @@ Skipping push. Use --force to override.`,
let standbyUrl: string | undefined;

if (outcome.ok && actorConfig!.usesStandbyMode) {
const pushedActor = (await actorClient.get()) as (Actor & { standbyUrl?: string | null }) | undefined;
const pushedActor = (await actorClient.get()) as (ActorResource & { standbyUrl?: string | null }) | undefined;
standbyUrl = pushedActor?.standbyUrl ?? undefined;
}

Expand Down
7 changes: 3 additions & 4 deletions src/commands/actors/search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApifyClient } from 'apify-client';
import chalk from 'chalk';

import { getAnonymousApifyClientOptions } from '../../lib/auth.js';
import { createApifyClient, getAnonymousApifyClientOptions } from '../../lib/auth.js';
import { ApifyCommand } from '../../lib/command-framework/apify-command.js';
import { Args } from '../../lib/command-framework/args.js';
import { Flags } from '../../lib/command-framework/flags.js';
Expand All @@ -23,7 +22,7 @@ function formatPricingModel(model?: string): string {
return pricingModelLabels[model] ?? model;
}

function truncateDescription(description?: string, maxLength = 60): string {
function truncateDescription(description?: string | null, maxLength = 60): string {
if (!description) return '';

if (description.length <= maxLength) return description;
Expand Down Expand Up @@ -97,7 +96,7 @@ export class ActorsSearchCommand extends ApifyCommand<typeof ActorsSearchCommand
const { query } = this.args;
const { json, sortBy, category, username, pricingModel, limit, offset } = this.flags;

const client = new ApifyClient(getAnonymousApifyClientOptions());
const client = createApifyClient(getAnonymousApifyClientOptions());

let result;

Expand Down
Loading
Loading