Skip to content
Merged
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
2 changes: 1 addition & 1 deletion apps/cli/commands/preview/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PreviewCommandLoggerAction as LoggerAction } from '@studio/common/logge
import { Snapshot } from '@studio/common/types/snapshot';
import { __, _n, sprintf } from '@wordpress/i18n';
import CliTable3 from 'cli-table3';
import { format } from 'date-fns';
import { format } from 'date-fns/format';
import { readCliConfig } from 'cli/lib/cli-config/core';
import { getSiteByFolder } from 'cli/lib/cli-config/sites';
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/commands/preview/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { readAuthToken } from '@studio/common/lib/shared-config';
import { PreviewCommandLoggerAction as LoggerAction } from '@studio/common/logger-actions';
import { Snapshot } from '@studio/common/types/snapshot';
import { __, _n, sprintf } from '@wordpress/i18n';
import { addDays } from 'date-fns';
import { addDays } from 'date-fns/addDays';
import { uploadArchive, waitForSiteReady } from 'cli/lib/api';
import { cleanup, archiveSiteContent } from 'cli/lib/archive';
import { getSiteByFolder } from 'cli/lib/cli-config/sites';
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/lib/site-runtime-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
SITE_FILE_ACCESS_ALL_FILES,
type SiteFileAccess,
} from '@studio/common/lib/site-file-access';
import { isSameDay } from 'date-fns';
import { isSameDay } from 'date-fns/isSameDay';
import { bumpStat } from 'cli/lib/bump-stat';
import {
lockCliConfig,
Expand Down
6 changes: 5 additions & 1 deletion apps/cli/lib/snapshots.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { HOUR_MS, DAY_MS, DEMO_SITE_EXPIRATION_DAYS } from '@studio/common/constants';
import { __ } from '@wordpress/i18n';
import { addDays, addHours, DurationUnit, formatDuration, intervalToDuration } from 'date-fns';
import { addDays } from 'date-fns/addDays';
import { addHours } from 'date-fns/addHours';
import { formatDuration } from 'date-fns/formatDuration';
import { intervalToDuration } from 'date-fns/intervalToDuration';
import type { DurationUnit } from 'date-fns';

export {
getSnapshotsFromConfig,
Expand Down
11 changes: 10 additions & 1 deletion apps/cli/tests/startup-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@ import path from 'path';
import { describe, expect, it, vi } from 'vitest';

const agentRuntimeLoaded = vi.hoisted( () => ( { value: false } ) );
const dateFnsRootLoaded = vi.hoisted( () => ( { value: false } ) );

vi.mock( '@earendil-works/pi-coding-agent', () => {
agentRuntimeLoaded.value = true;
return {};
} );

// The `date-fns` root loads every one of its functions, about 300 modules, which took
// about 0.9 s in the packaged app. Each function has its own path, e.g. `date-fns/format`.
vi.mock( 'date-fns', () => {
dateFnsRootLoaded.value = true;
return {};
} );

// Every `studio` command loads what the CLI entry imports statically before it
// runs. The agent runtime is large, so only the commands that use it load it.
describe( 'CLI startup', () => {
it( 'loads no agent runtime before a command runs', async () => {
it( 'loads no agent runtime or date-fns root before a command runs', async () => {
const entry = readFileSync( path.join( import.meta.dirname, '..', 'index.ts' ), 'utf8' );
const staticImports = [ ...entry.matchAll( /^import [^;]*? from '(cli\/[^']+)';$/gm ) ].map(
( [ , specifier ] ) => specifier
Expand All @@ -24,5 +32,6 @@ describe( 'CLI startup', () => {
}

expect( agentRuntimeLoaded.value ).toBe( false );
expect( dateFnsRootLoaded.value ).toBe( false );
} );
} );
4 changes: 3 additions & 1 deletion packages/common/lib/bump-stat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isSameDay, isSameMonth, isSameWeek } from 'date-fns';
import { isSameDay } from 'date-fns/isSameDay';
import { isSameMonth } from 'date-fns/isSameMonth';
import { isSameWeek } from 'date-fns/isSameWeek';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this PR needs a small note in agents.md to prevent it from happening again.


// Database columns are varchar(32). Group limit is 27 to account for the '-a11n' suffix
// added by the backend for Automattic requests (27 + 5 = 32).
Expand Down
2 changes: 1 addition & 1 deletion packages/common/lib/generate-backup-filename.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'date-fns';
import { format } from 'date-fns/format';
import { sanitizeFolderName } from '@studio/common/lib/sanitize-folder-name';

export function generateBackupFilename( name: string ) {
Expand Down
Loading