Skip to content

Commit 9255570

Browse files
authored
Update SQLite refresh script to support the SQLite monorepo (#3452)
## Summary - The [sqlite-database-integration](https://github.com/WordPress/sqlite-database-integration) repository was restructured into a monorepo ([WordPress/sqlite-database-integration#334](WordPress/sqlite-database-integration#334)). The plugin now needs to be built from a subpackage. - The refresh script now shallow-clones the SQLite repository and runs its build script (`bin/build-sqlite-plugin-zip.sh`) to produce a self-contained plugin ZIP with the driver symlink resolved. - For older tagged versions (pre-monorepo), the script falls back to downloading the GitHub archive, which still works correctly. ## Test plan - [x] Verified `npx nx run playground-wordpress-builds:bundle-sqlite-database` succeeds for both `trunk` and `v2.1.16` - [x] Verified the trunk ZIP contains the correct flat plugin structure with `db.copy`, `load.php`, and a real `wp-includes/database/` directory - [x] Verified the v2.1.16 ZIP is identical to the previous version (84 KB) - [x] Verify Playground boots correctly with the new trunk ZIP (run `npm run dev` and confirm SQLite works)
1 parent 78eaacc commit 9255570

3 files changed

Lines changed: 42 additions & 15 deletions

File tree

packages/playground/wordpress-builds/build/refresh-sqlite-integration-plugin.js

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import yargs from 'yargs';
22
import { promises as fs, statSync } from 'fs';
3+
import { execFileSync } from 'child_process';
4+
import { tmpdir } from 'os';
5+
import path from 'path';
6+
7+
const SQLITE_REPOSITORY_URL = 'https://github.com/WordPress/sqlite-database-integration';
38

49
// The latest version of the SQLite plugin is the develop branch.
510
const latestVersion = 'trunk';
@@ -21,12 +26,8 @@ const parser = yargs(process.argv.slice(2))
2126
});
2227

2328
const args = parser.argv;
24-
25-
// Get version and URL.
2629
const version = args.pluginVersion;
27-
const url = 'trunk' === version
28-
? `https://github.com/WordPress/sqlite-database-integration/archive/refs/heads/${version}.zip`
29-
: `https://github.com/WordPress/sqlite-database-integration/archive/refs/tags/${version}.zip`;
30+
const outputZipPath = path.resolve(args.outputDir, `sqlite-database-integration-${version}.zip`);
3031

3132
// Load versions map.
3233
const versionsPath = `${args.outputDir}/sqlite-database-integration-versions.json`;
@@ -38,14 +39,7 @@ try {
3839
versions = {};
3940
}
4041

41-
// Download the plugin.
42-
const outputZipPath = `${args.outputDir}/sqlite-database-integration-${version}.zip`;
43-
const sqliteResponse = await fetch(url);
44-
if (!sqliteResponse.ok) {
45-
throw new Error(`Failed to download SQLite integration plugin: ${sqliteResponse.statusText}`);
46-
}
47-
const sqliteZip = Buffer.from(await sqliteResponse.arrayBuffer());
48-
await fs.writeFile(outputZipPath, sqliteZip);
42+
await buildPluginZip(version, outputZipPath);
4943

5044
// Update versions map.
5145
versions[version] = version;
@@ -106,3 +100,37 @@ export function getSqliteDriverModuleDetails(
106100
}
107101
`;
108102
await fs.writeFile(getSqliteDriverModuleDetailsPath, getSqliteDriverModuleDetailsContent);
103+
104+
/**
105+
* Fetch the SQLite repository and build the SQLite integration plugin ZIP.
106+
*/
107+
async function buildPluginZip(version, outputZipPath) {
108+
const tempDir = await fs.mkdtemp(path.join(tmpdir(), 'sqlite-plugin-'));
109+
try {
110+
const repoDir = path.join(tempDir, 'repo');
111+
execFileSync(
112+
'git',
113+
['clone', '--depth', '1', '--branch', version, '--single-branch', `${SQLITE_REPOSITORY_URL}.git`, repoDir],
114+
{ stdio: 'inherit' }
115+
);
116+
117+
const buildScript = path.join(repoDir, 'bin', 'build-sqlite-plugin-zip.sh');
118+
const hasBuildScript = await fs.access(buildScript).then(() => true, () => false);
119+
120+
if (hasBuildScript) {
121+
// Monorepo structure: Run the repository's build script.
122+
execFileSync('bash', [buildScript], { cwd: repoDir, stdio: 'inherit' });
123+
await fs.copyFile(path.join(repoDir, 'build', 'plugin-sqlite-database-integration.zip'), outputZipPath);
124+
} else {
125+
// Old flat structure: Download the GitHub archive.
126+
const url = `${SQLITE_REPOSITORY_URL}/archive/refs/tags/${version}.zip`;
127+
const response = await fetch(url);
128+
if (!response.ok) {
129+
throw new Error(`Failed to download SQLite integration plugin ${version}: ${response.statusText}`);
130+
}
131+
await fs.writeFile(outputZipPath, Buffer.from(await response.arrayBuffer()));
132+
}
133+
} finally {
134+
await fs.rm(tempDir, { recursive: true, force: true });
135+
}
136+
}

packages/playground/wordpress-builds/src/sqlite-database-integration/get-sqlite-driver-module-details.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ export function getSqliteDriverModuleDetails(
1919
url: string;
2020
} {
2121
switch (version) {
22-
2322
case 'trunk':
2423
/** @ts-ignore */
2524
return {
26-
size: 258811,
25+
size: 263596,
2726
url: url_trunk,
2827
};
2928
case 'v2.1.16':

0 commit comments

Comments
 (0)