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
39 changes: 35 additions & 4 deletions packages/runtime-core/src/recipe-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,16 @@ export function buildWordPressPhpunitRecipe(options: WordPressPhpunitRecipeOptio
const pluginTarget = `/wordpress/wp-content/plugins/${pluginSlug}`
const autoloadFile = options.autoloadFile ?? (options.bootstrapMode === "project" ? "" : "/wp-codebox-vendor/autoload.php")
const services = phpunitRuntimeServices(options.databaseType, options.services)
const extraPlugins = options.databaseType === "mdi-native"
? [...normalizeExtraPlugins(options.extra_plugins), mdiNativePlugin()]
: normalizeExtraPlugins(options.extra_plugins)
const extraPlugins = normalizeExtraPlugins(options.extra_plugins)
if (options.databaseType === "mdi-native") {
const nativePlugin = nativeMdiPlugin(extraPlugins)
const nativeIndex = extraPlugins.findIndex((plugin) => plugin.slug === "markdown-database-integration")
if (nativeIndex === -1) {
extraPlugins.push(nativePlugin)
} else {
extraPlugins[nativeIndex] = nativePlugin
}
}

return {
schema: "wp-codebox/workspace-recipe/v1",
Expand Down Expand Up @@ -155,7 +162,28 @@ function phpunitDependencyPlugins(mounts: readonly string[], plugins: readonly W
})
}

function mdiNativePlugin(): WorkspaceRecipeExtraPlugin {
function nativeMdiPlugin(plugins: readonly WorkspaceRecipeExtraPlugin[]): WorkspaceRecipeExtraPlugin {
const candidates = plugins.filter((plugin) => plugin.slug === "markdown-database-integration")
if (candidates.length > 1) {
throw new Error("mdi-native accepts at most one markdown-database-integration extra plugin source")
}
const candidate = candidates[0]
if (candidate) {
if (candidate.loadAs !== undefined && candidate.loadAs !== "plugin") {
throw new Error("mdi-native markdown-database-integration source must use loadAs=plugin")
}
return {
...candidate,
slug: "markdown-database-integration",
pluginFile: "markdown-database-integration/markdown-database-integration.php",
activate: false,
metadata: {
...candidate.metadata,
phase: "pre-install",
databaseDropIn: true,
},
}
}
return {
source: "wp-codebox:mdi-native",
sha256: "b01d119e994c5c498373edcd2e3a62fcaec72bc8ad360f6c9a209341e1c5cc88",
Expand Down Expand Up @@ -298,6 +326,9 @@ function normalizeExtraPlugins(plugins: readonly WorkspaceRecipeExtraPlugin[] =
if (plugin.composer !== undefined) {
normalized.composer = plugin.composer
}
if (plugin.metadata !== undefined) {
normalized.metadata = plugin.metadata
}

return normalized
})
Expand Down
39 changes: 39 additions & 0 deletions tests/runtime-services.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,45 @@ try {
} finally {
await cleanupRecipePreparedSources([], preparedMdiPlugins)
}
const candidateMdiSource = "/tmp/markdown-database-integration"
const candidateMdiRecipe = buildWordPressPhpunitRecipe({
pluginSlug: "example",
databaseType: "mdi-native",
extra_plugins: [{
source: candidateMdiSource,
slug: "markdown-database-integration",
sha256: "0123456789abcdef",
activate: true,
metadata: { revision: "548042c47efac724d13d25744765dbc65a851b20" },
}],
})
assert.deepEqual(candidateMdiRecipe.inputs?.extra_plugins, [{
source: candidateMdiSource,
slug: "markdown-database-integration",
sha256: "0123456789abcdef",
pluginFile: "markdown-database-integration/markdown-database-integration.php",
activate: false,
metadata: { revision: "548042c47efac724d13d25744765dbc65a851b20", phase: "pre-install", databaseDropIn: true },
}])
assert.throws(
() => buildWordPressPhpunitRecipe({
pluginSlug: "example",
databaseType: "mdi-native",
extra_plugins: [
{ source: "/tmp/one", slug: "markdown-database-integration" },
{ source: "/tmp/two", slug: "markdown-database-integration" },
],
}),
/at most one markdown-database-integration extra plugin source/,
)
assert.throws(
() => buildWordPressPhpunitRecipe({
pluginSlug: "example",
databaseType: "mdi-native",
extra_plugins: [{ source: "/tmp/mdi", slug: "markdown-database-integration", loadAs: "mu-plugin" }],
}),
/must use loadAs=plugin/,
)
assert.equal(buildWordPressPhpunitRecipe({ pluginSlug: "example", wordpressInstallMode: "do-not-attempt-installing" }).runtime?.wordpressInstallMode, "do-not-attempt-installing")
const builderDirectory = await mkdtemp(join(tmpdir(), "wp-codebox-phpunit-builder-"))
try {
Expand Down
Loading