Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:Automattic/studio into add/exclude…
Browse files Browse the repository at this point in the history
…-plugins-themes-from-wpcli
  • Loading branch information
sejas committed Dec 18, 2024
2 parents 74f58c4 + 4533c37 commit fba5ec8
Show file tree
Hide file tree
Showing 9 changed files with 1,058 additions and 477 deletions.
4 changes: 1 addition & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ GEM
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.3.6)
strscan
rexml (3.4.0)
rouge (2.0.7)
rubocop (1.66.0)
json (~> 2.3)
Expand Down Expand Up @@ -272,7 +271,6 @@ GEM
simctl (1.6.10)
CFPropertyList
naturally
strscan (3.1.0)
terminal-notifier (2.0.0)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
Expand Down
1,459 changes: 1,006 additions & 453 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"electron": "29.1.0",
"electron-devtools-installer": "^3.2.0",
"electron-playwright-helpers": "^1.7.0",
"eslint": "^8.0.1",
"eslint": "^8.57.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.25.0",
"eslint-plugin-jest-dom": "^5.1.0",
Expand Down Expand Up @@ -106,7 +106,7 @@
"@php-wasm/scopes": "^0.9.44",
"@php-wasm/universal": "^0.9.44",
"@rive-app/react-canvas": "^4.12.0",
"@sentry/electron": "^4.17.0",
"@sentry/electron": "^4.24.0",
"@sentry/webpack-plugin": "^2.16.1",
"@types/adm-zip": "^0.5.5",
"@wordpress/compose": "^6.27.0",
Expand All @@ -123,7 +123,7 @@
"date-fns": "^3.3.1",
"electron-squirrel-startup": "^1.0.0",
"electron2appx": "^2.1.2",
"express": "4.19.2",
"express": "4.21.2",
"file-stream-rotator": "^1.0.0",
"follow-redirects": "1.15.6",
"fs-extra": "11.1.1",
Expand Down
7 changes: 5 additions & 2 deletions src/hooks/sync-sites/use-sync-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,11 @@ export function useSyncPush( {
status: pushStatesProgressInfo.failed,
} );
getIpcApi().showErrorMessageBox( {
title: sprintf( __( 'Error exporting site to %s' ), connectedSite.name ),
message: __( 'Studio was unable to export the site.' ),
title: sprintf( __( 'Error pushing to %s' ), connectedSite.name ),
message: __(
'An error occurred while pushing the site. If this problem persists, please contact support.'
),
error,
} );
return;
}
Expand Down
1 change: 0 additions & 1 deletion src/hooks/use-chat-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const parseWpCliOutput = ( stdout: string, defaultValue: string[] ): string[] =>
const data = JSON.parse( stdout );
return data?.map( ( item: { name: string } ) => item.name ) || [];
} catch ( error ) {
console.error( error, stdout );
Sentry.captureException( error, {
extra: { stdout },
} );
Expand Down
14 changes: 12 additions & 2 deletions src/lib/import-export/export/export-database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function exportDatabaseToMultipleFiles(
}

const tablesResult = await server.executeWpCliCommand(
`sqlite tables --format=csv --require=/tmp/sqlite-command/command.php`,
`sqlite tables --format=json --require=/tmp/sqlite-command/command.php`,
{
skipPluginsAndThemes: true,
}
Expand All @@ -61,7 +61,17 @@ export async function exportDatabaseToMultipleFiles(
if ( tablesResult.exitCode ) {
throw new Error( 'Database export failed' );
}
const tables = tablesResult.stdout.split( ',' );

let tables;

try {
tables = JSON.parse( tablesResult.stdout );
} catch ( error ) {
console.error(
`Could not get list of database tables. The WP CLI output: ${ tablesResult.stdout }`
);
throw new Error( 'Could not get list of database tables to export.' );
}

const tmpFiles: string[] = [];

Expand Down
26 changes: 22 additions & 4 deletions src/lib/import-export/export/exporters/default-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,19 @@ export class DefaultExporter extends EventEmitter implements Exporter {

if ( stderr ) {
console.error( `Could not get information about plugins: ${ stderr }` );
return [];
throw new Error(
'Could not get information about installed plugins to create meta.json file.'
);
}

return JSON.parse( stdout );
try {
return JSON.parse( stdout );
} catch ( error ) {
console.error( `Could not parse plugins list. The WP CLI output: ${ stdout }` );
throw new Error(
'Could not parse information about installed plugins to create meta.json file.'
);
}
}

private async getSiteThemes( site_id: string ) {
Expand All @@ -298,9 +307,18 @@ export class DefaultExporter extends EventEmitter implements Exporter {

if ( stderr ) {
console.error( `Could not get information about themes: ${ stderr }` );
return [];
throw new Error(
'Could not get information about installed themes to create meta.json file.'
);
}

return JSON.parse( stdout );
try {
return JSON.parse( stdout );
} catch ( error ) {
console.error( `Could not parse themes list. The WP CLI output: ${ stdout }` );
throw new Error(
'Could not parse information about installed themes to create meta.json file.'
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe( 'DefaultExporter', () => {
case /theme list/.test( command ):
return { stdout: '[{"name":"twentytwentyfour","status":"active","version":"1.0"}]' };
case /tables/.test( command ):
return { stdout: defaultTableNames.join( ',' ) };
return { stdout: JSON.stringify( defaultTableNames ) };
default:
return { stderr: null };
}
Expand Down Expand Up @@ -323,7 +323,7 @@ describe( 'DefaultExporter', () => {
expect( canHandle ).toBe( false );
} );

it( 'should not fail when can not get plugin or theme details', async () => {
it( 'should fail when can not get plugin or theme details', async () => {
( SiteServer.get as jest.Mock ).mockReturnValue( {
details: { path: '/path/to/site' },
executeWpCliCommand: jest.fn( function ( command: string ) {
Expand All @@ -338,10 +338,9 @@ describe( 'DefaultExporter', () => {
} );

const exporter = new DefaultExporter( mockOptions );
await exporter.export();

expect( mockArchiver.file ).toHaveBeenCalledWith( '/tmp/studio_export_123/meta.json', {
name: 'meta.json',
} );
await expect( exporter.export() ).rejects.toThrow(
'Could not get information about installed plugins to create meta.json file.'
);
} );
} );
7 changes: 4 additions & 3 deletions src/lib/wp-cli-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type MessageName = 'execute';
export type WpCliResult = ReturnType< typeof executeWPCli >;
export type MessageCanceled = { error: Error; canceled: boolean };

const DEFAULT_RESPONSE_TIMEOUT = 120000;
const DEFAULT_RESPONSE_TIMEOUT = 300 * 1000;

export default class WpCliProcess {
lastMessageId = 0;
Expand Down Expand Up @@ -121,9 +121,10 @@ export default class WpCliProcess {
resolve( data );
};

const timeoutHandler = () => {
reject( new Error( `Request for message ${ originalMessage } timed out` ) );
const timeoutHandler = async () => {
await this.#killProcess();
process.removeListener( 'message', handler );
reject( new Error( `Request for message ${ originalMessage } timed out` ) );
};
const timeoutId = setTimeout( timeoutHandler, timeout );
const cancelHandler = () => {
Expand Down

0 comments on commit fba5ec8

Please sign in to comment.