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

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: 3 additions & 1 deletion apps/cli/lib/dependency-management/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export function getSqliteCommandPath(): string {
return path.join( getWpFilesPath(), SQLITE_COMMAND_DIRNAME );
}

// Language packs ship read-only with the CLI bundle and are copied into each site's
// `wp-content/languages/` directory on site create. No writable cache needed.
export function getLanguagePacksPath(): string {
return path.join( getServerFilesPath(), 'language-packs' );
return path.join( getWpFilesPath(), 'latest', 'languages' );
}

// AI instructions ship read-only with the CLI bundle and are installed into each site's
Expand Down
36 changes: 1 addition & 35 deletions apps/cli/lib/dependency-management/setup.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import fs from 'fs';
import path from 'path';
import { LOCKFILE_STALE_TIME, LOCKFILE_WAIT_TIME } from '@studio/common/constants';
import { recursiveCopyDirectory } from '@studio/common/lib/fs-utils';
import { lockFileAsync, unlockFileAsync } from '@studio/common/lib/lockfile';
import semver from 'semver';
import { readCliConfig, updateCliConfigWithPartial } from 'cli/lib/cli-config/core';
import { getLanguagePacksPath, getWordPressVersionPath, getWpFilesPath } from './paths';
import { areDirectoriesDifferentBySizeAndMtime } from './utils';
import { getWordPressVersionPath, getWpFilesPath } from './paths';
import { getWordPressVersionFromInstallation, updateLatestWordPressVersion } from './wordpress';

// Compare the WordPress version in the bundled `wp-files/latest/wordpress` directory (that ships
Expand Down Expand Up @@ -38,40 +35,9 @@ async function copyBundledLatestWpVersion() {
}
}

async function copyBundledLanguagePacks() {
const sourceLanguagePacksPath = path.join( getWpFilesPath(), 'latest', 'languages' );
if ( ! fs.existsSync( sourceLanguagePacksPath ) ) {
return;
}
const targetLanguagePacksPath = getLanguagePacksPath();
const lockPath = `${ targetLanguagePacksPath }.lock`;
await fs.promises.mkdir( path.dirname( lockPath ), { recursive: true } );
await lockFileAsync( lockPath, {
wait: LOCKFILE_WAIT_TIME,
stale: LOCKFILE_STALE_TIME,
} );
try {
const isSourceDirectoryDifferent = await areDirectoriesDifferentBySizeAndMtime(
sourceLanguagePacksPath,
targetLanguagePacksPath
);
if ( isSourceDirectoryDifferent ) {
try {
await fs.promises.rm( targetLanguagePacksPath, { recursive: true, force: true } );
} catch {
// Do nothing if the target directory is missing or corrupted
}
await recursiveCopyDirectory( sourceLanguagePacksPath, targetLanguagePacksPath );
}
} finally {
await unlockFileAsync( lockPath );
}
}

export async function setupServerFiles() {
const steps: [ string, () => Promise< void > ][] = [
[ 'WordPress version', copyBundledLatestWpVersion ],
[ 'language packs', copyBundledLanguagePacks ],
];

for ( const [ name, step ] of steps ) {
Expand Down
101 changes: 0 additions & 101 deletions apps/cli/lib/dependency-management/utils.ts

This file was deleted.

7 changes: 7 additions & 0 deletions apps/cli/lib/language-packs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import path from 'path';
import { pathExists } from '@studio/common/lib/fs-utils';
import { WP_LOCALES } from '@studio/common/lib/wp-locales';
import { getLanguagePacksPath } from 'cli/lib/dependency-management/paths';

/**
Expand Down Expand Up @@ -51,6 +52,12 @@ export async function copyLanguagePackToSite(
sitePath: string,
wpLocale: string
): Promise< boolean > {
// Translations are only bundled for `WP_LOCALES`; skip the readdir() calls over the
// ~1,400-entry bundled languages directories when no files could match anyway.
if ( ! WP_LOCALES.includes( wpLocale ) ) {
return false;
}

const languagePacksDir = getLanguagePacksPath();
if ( ! ( await pathExists( languagePacksDir ) ) ) {
return false;
Expand Down
3 changes: 3 additions & 0 deletions apps/cli/migrations/04-cleanup-obsolete-server-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* - `phpmyadmin/` (phpMyAdmin)
* - `wp-cli.phar` (WP-CLI)
* - `wordpress-versions/latest/available-site-translations.json`
* - `language-packs/` (WordPress translations, plus its lockfile)
*
* Safe to re-run: `needsToRun()` checks for the presence of any obsolete
* entry, and `run()` tolerates missing paths.
Expand All @@ -31,6 +32,8 @@ function getObsoletePaths(): string[] {
'latest',
'available-site-translations.json'
),
path.join( serverFilesPath, 'language-packs' ),
path.join( serverFilesPath, 'language-packs.lock' ),
];
}

Expand Down