mirror of
https://github.com/github/awesome-copilot.git
synced 2026-07-18 11:50:00 +00:00
Fix extension materialization to move bundles into container (#2339)
* Migrate extension plugin materialization layout Materialize extension plugins into a dedicated extensions/ container, validate the new manifest convention, and bump extension plugin versions. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Keep extension manifests source-compatible Restore source extension manifests to "extensions": "." while preserving materialization-time rewrite to "extensions" in distribution output. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Validate canvas extension layout for external submissions Add intake and quality-gate checks for canvas-tagged external plugins so they must include extensions/extension.mjs and optional manifest extensions is validated when present. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Fix plugin clean extension pass and typo guard text Declare EXTENSIONS_DIR in clean-materialized-plugins and run extension cleanup once after plugin cleanup. Also normalize misspelled-key detection strings to satisfy spelling checks without changing validation behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Proper codespell fix * Separate canvas structure quality gate status Track canvas structure as its own gate status and output, include it in aggregate summaries, and enforce Git object types so extensions/ is a tree and extensions/extension.mjs is a blob. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Move extension bundles during materialization Change extension-plugin materialization to move root bundle entries into extensions/ instead of copying them, and assert originals are removed in test coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Nest materialized extension bundles by plugin name Materialize extension plugins into extensions/<plugin-name>/... (moved entries) so resulting paths are duplicated by design, and bump extension plugin versions to the next patch release. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Fix extension materialization publish and cleanup Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1 * Preserve root extension logo asset Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: d26008fb-9928-4ba7-b7c8-36f35320f7c1
This commit is contained in:
@@ -28,6 +28,41 @@ const MATERIALIZED_SPECS = {
|
||||
},
|
||||
};
|
||||
|
||||
function copyDirRecursive(src, dest) {
|
||||
fs.mkdirSync(dest, { recursive: true });
|
||||
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
||||
const srcPath = path.join(src, entry.name);
|
||||
const destPath = path.join(dest, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
copyDirRecursive(srcPath, destPath);
|
||||
} else {
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function moveEntry(srcPath, destPath) {
|
||||
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
||||
try {
|
||||
fs.renameSync(srcPath, destPath);
|
||||
return;
|
||||
} catch (error) {
|
||||
if (!["EXDEV", "EEXIST", "ENOTEMPTY", "EPERM"].includes(error?.code)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const stats = fs.statSync(srcPath);
|
||||
if (stats.isDirectory()) {
|
||||
copyDirRecursive(srcPath, destPath);
|
||||
fs.rmSync(srcPath, { recursive: true, force: true });
|
||||
return;
|
||||
}
|
||||
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
fs.rmSync(srcPath, { force: true });
|
||||
}
|
||||
|
||||
export function restoreManifestFromMaterializedFiles(pluginPath) {
|
||||
const pluginJsonPath = path.join(pluginPath, ".github/plugin", "plugin.json");
|
||||
if (!fs.existsSync(pluginJsonPath)) {
|
||||
@@ -90,15 +125,22 @@ function cleanPlugin(pluginPath) {
|
||||
return { removed, manifestUpdated };
|
||||
}
|
||||
|
||||
function cleanMaterializedExtensionPlugin(extensionPath) {
|
||||
export function cleanMaterializedExtensionPlugin(extensionPath) {
|
||||
const pluginJsonPath = path.join(extensionPath, ".github", "plugin", "plugin.json");
|
||||
let manifestUpdated = false;
|
||||
if (fs.existsSync(pluginJsonPath)) {
|
||||
const plugin = JSON.parse(fs.readFileSync(pluginJsonPath, "utf8"));
|
||||
const extensionBundlePrefix = `extensions/${path.basename(extensionPath)}/`;
|
||||
if (plugin.extensions === "extensions") {
|
||||
plugin.extensions = ".";
|
||||
fs.writeFileSync(pluginJsonPath, JSON.stringify(plugin, null, 2) + "\n", "utf8");
|
||||
manifestUpdated = true;
|
||||
}
|
||||
if (typeof plugin.logo === "string" && plugin.logo.startsWith(extensionBundlePrefix)) {
|
||||
plugin.logo = plugin.logo.slice(extensionBundlePrefix.length);
|
||||
manifestUpdated = true;
|
||||
}
|
||||
if (manifestUpdated) {
|
||||
fs.writeFileSync(pluginJsonPath, JSON.stringify(plugin, null, 2) + "\n", "utf8");
|
||||
console.log(` Updated ${path.basename(extensionPath)}/.github/plugin/plugin.json`);
|
||||
}
|
||||
}
|
||||
@@ -108,12 +150,43 @@ function cleanMaterializedExtensionPlugin(extensionPath) {
|
||||
return { removed: 0, manifestUpdated };
|
||||
}
|
||||
|
||||
const bundleRoot = path.join(target, path.basename(extensionPath));
|
||||
const count = countFiles(target);
|
||||
if (fs.existsSync(bundleRoot) && fs.statSync(bundleRoot).isDirectory()) {
|
||||
for (const entry of fs.readdirSync(bundleRoot, { withFileTypes: true })) {
|
||||
moveEntry(path.join(bundleRoot, entry.name), path.join(extensionPath, entry.name));
|
||||
}
|
||||
console.log(` Restored ${path.basename(extensionPath)}/ from materialized extensions bundle`);
|
||||
}
|
||||
|
||||
fs.rmSync(target, { recursive: true, force: true });
|
||||
console.log(` Removed ${path.basename(extensionPath)}/extensions/ (${count} files)`);
|
||||
return { removed: count, manifestUpdated };
|
||||
}
|
||||
|
||||
function isExtensionPluginDirectory(extensionPath) {
|
||||
if (fs.existsSync(path.join(extensionPath, "extension.mjs"))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const bundleEntry = path.join(extensionPath, "extensions", path.basename(extensionPath), "extension.mjs");
|
||||
if (fs.existsSync(bundleEntry)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const pluginJsonPath = path.join(extensionPath, ".github", "plugin", "plugin.json");
|
||||
if (!fs.existsSync(pluginJsonPath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
const plugin = JSON.parse(fs.readFileSync(pluginJsonPath, "utf8"));
|
||||
return plugin.extensions === "extensions";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function countFiles(dir) {
|
||||
let count = 0;
|
||||
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
@@ -204,7 +277,7 @@ function main() {
|
||||
|
||||
for (const dirName of extensionDirs) {
|
||||
const extensionPath = path.join(EXTENSIONS_DIR, dirName);
|
||||
if (!fs.existsSync(path.join(extensionPath, "extension.mjs"))) {
|
||||
if (!isExtensionPluginDirectory(extensionPath)) {
|
||||
continue;
|
||||
}
|
||||
const { removed, manifestUpdated } = cleanMaterializedExtensionPlugin(extensionPath);
|
||||
|
||||
@@ -62,6 +62,16 @@ function collectLocalPluginsFromRoot(rootDir, sourcePrefix, includeEntry = () =>
|
||||
return plugins;
|
||||
}
|
||||
|
||||
function hasExtensionEntryPoint(extensionDir, extensionName) {
|
||||
const candidateEntryPoints = [
|
||||
path.join(extensionDir, "extension.mjs"),
|
||||
path.join(extensionDir, "extensions", "extension.mjs"),
|
||||
path.join(extensionDir, "extensions", extensionName, "extension.mjs"),
|
||||
];
|
||||
|
||||
return candidateEntryPoints.some((entryPointPath) => fs.existsSync(entryPointPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate marketplace.json from plugin directories
|
||||
*/
|
||||
@@ -78,7 +88,7 @@ function generateMarketplace() {
|
||||
...collectLocalPluginsFromRoot(
|
||||
EXTENSIONS_DIR,
|
||||
"extensions",
|
||||
(entryName) => fs.existsSync(path.join(EXTENSIONS_DIR, entryName, "extension.mjs"))
|
||||
(entryName) => hasExtensionEntryPoint(path.join(EXTENSIONS_DIR, entryName), entryName)
|
||||
)
|
||||
];
|
||||
|
||||
|
||||
@@ -35,6 +35,16 @@ const WEBSITE_SOURCE_DATA_DIR = path.join(WEBSITE_DIR, "data");
|
||||
const EXTERNAL_CANVAS_KEYWORD = "canvas";
|
||||
const EXTERNAL_CANVAS_PREVIEW_PATH = "assets/preview.png";
|
||||
|
||||
function hasExtensionEntryPoint(extensionDir, extensionName) {
|
||||
const candidateEntryPoints = [
|
||||
path.join(extensionDir, "extension.mjs"),
|
||||
path.join(extensionDir, "extensions", "extension.mjs"),
|
||||
path.join(extensionDir, "extensions", extensionName, "extension.mjs"),
|
||||
];
|
||||
|
||||
return candidateEntryPoints.some((entryPointPath) => fs.existsSync(entryPointPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the output directory exists
|
||||
*/
|
||||
@@ -544,7 +554,7 @@ function generatePluginsData(gitDates, resourceIndex = {}) {
|
||||
const extensionDirs = fs.readdirSync(EXTENSIONS_DIR, { withFileTypes: true })
|
||||
.filter((entry) => {
|
||||
if (!entry.isDirectory()) return false;
|
||||
return fs.existsSync(path.join(EXTENSIONS_DIR, entry.name, "extension.mjs"));
|
||||
return hasExtensionEntryPoint(path.join(EXTENSIONS_DIR, entry.name), entry.name);
|
||||
})
|
||||
.map((entry) => entry.name)
|
||||
.sort((a, b) => a.localeCompare(b));
|
||||
@@ -1235,12 +1245,7 @@ function generateCanvasManifest(gitDates, commitSha) {
|
||||
.readdirSync(EXTENSIONS_DIR, { withFileTypes: true })
|
||||
.filter((entry) => {
|
||||
if (!entry.isDirectory()) return false;
|
||||
const extensionEntryPoint = path.join(
|
||||
EXTENSIONS_DIR,
|
||||
entry.name,
|
||||
"extension.mjs"
|
||||
);
|
||||
return fs.existsSync(extensionEntryPoint);
|
||||
return hasExtensionEntryPoint(path.join(EXTENSIONS_DIR, entry.name), entry.name);
|
||||
})
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
|
||||
|
||||
+41
-11
@@ -24,15 +24,34 @@ function copyDirRecursive(src, dest) {
|
||||
}
|
||||
}
|
||||
|
||||
function copyEntryRecursive(srcPath, destPath) {
|
||||
function moveEntry(srcPath, destPath) {
|
||||
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
||||
try {
|
||||
fs.renameSync(srcPath, destPath);
|
||||
return;
|
||||
} catch (error) {
|
||||
if (error?.code !== "EXDEV") {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
const stats = fs.statSync(srcPath);
|
||||
if (stats.isDirectory()) {
|
||||
copyDirRecursive(srcPath, destPath);
|
||||
fs.rmSync(srcPath, { recursive: true, force: true });
|
||||
return;
|
||||
}
|
||||
|
||||
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
||||
fs.copyFileSync(srcPath, destPath);
|
||||
fs.rmSync(srcPath, { force: true });
|
||||
}
|
||||
|
||||
function isRelativeAssetPath(assetPath) {
|
||||
return typeof assetPath === "string" &&
|
||||
assetPath.length > 0 &&
|
||||
!/^(?:[a-z][a-z0-9+.-]*:)?\/\//i.test(assetPath) &&
|
||||
!assetPath.startsWith("data:") &&
|
||||
!path.isAbsolute(assetPath);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +80,7 @@ function resolveSource(relPath) {
|
||||
export function materializeExtensionPlugin(extensionPath) {
|
||||
const pluginJsonPath = path.join(extensionPath, ".github", "plugin", "plugin.json");
|
||||
if (!fs.existsSync(pluginJsonPath)) {
|
||||
return { copiedEntries: 0, manifestUpdated: false, skipped: true };
|
||||
return { movedEntries: 0, manifestUpdated: false, skipped: true };
|
||||
}
|
||||
|
||||
let metadata;
|
||||
@@ -72,20 +91,31 @@ export function materializeExtensionPlugin(extensionPath) {
|
||||
}
|
||||
|
||||
const extensionContainerPath = path.join(extensionPath, "extensions");
|
||||
const extensionBundlePath = path.join(extensionContainerPath, path.basename(extensionPath));
|
||||
fs.rmSync(extensionContainerPath, { recursive: true, force: true });
|
||||
fs.mkdirSync(extensionContainerPath, { recursive: true });
|
||||
fs.mkdirSync(extensionBundlePath, { recursive: true });
|
||||
|
||||
let copiedEntries = 0;
|
||||
let movedEntries = 0;
|
||||
for (const entry of fs.readdirSync(extensionPath, { withFileTypes: true })) {
|
||||
if (entry.name === ".github" || entry.name === "extensions") {
|
||||
continue;
|
||||
}
|
||||
|
||||
copyEntryRecursive(
|
||||
moveEntry(
|
||||
path.join(extensionPath, entry.name),
|
||||
path.join(extensionContainerPath, entry.name)
|
||||
path.join(extensionBundlePath, entry.name)
|
||||
);
|
||||
copiedEntries++;
|
||||
movedEntries++;
|
||||
}
|
||||
|
||||
if (isRelativeAssetPath(metadata.logo)) {
|
||||
const normalizedLogoPath = metadata.logo.replace(/\\/g, "/").replace(/^\.\//, "");
|
||||
const bundledLogoPath = path.join(extensionBundlePath, normalizedLogoPath);
|
||||
if (fs.existsSync(bundledLogoPath)) {
|
||||
const rootLogoPath = path.join(extensionPath, normalizedLogoPath);
|
||||
fs.mkdirSync(path.dirname(rootLogoPath), { recursive: true });
|
||||
fs.copyFileSync(bundledLogoPath, rootLogoPath);
|
||||
}
|
||||
}
|
||||
|
||||
let manifestUpdated = false;
|
||||
@@ -97,7 +127,7 @@ export function materializeExtensionPlugin(extensionPath) {
|
||||
fs.writeFileSync(pluginJsonPath, JSON.stringify(metadata, null, 2) + "\n", "utf8");
|
||||
}
|
||||
|
||||
return { copiedEntries, manifestUpdated, skipped: false };
|
||||
return { movedEntries, manifestUpdated, skipped: false };
|
||||
}
|
||||
|
||||
function materializePlugins() {
|
||||
@@ -261,8 +291,8 @@ function materializePlugins() {
|
||||
}
|
||||
|
||||
totalExtensionPlugins++;
|
||||
totalExtensionPluginEntries += result.copiedEntries;
|
||||
console.log(`✓ ${dirName}: materialized extension bundle into ./extensions (${result.copiedEntries} entries)`);
|
||||
totalExtensionPluginEntries += result.movedEntries;
|
||||
console.log(`✓ ${dirName}: materialized extension bundle into ./extensions (${result.movedEntries} entries)`);
|
||||
} catch (err) {
|
||||
console.error(`Error: Failed to materialize extension plugin ${dirName}: ${err.message}`);
|
||||
errors++;
|
||||
|
||||
@@ -4,6 +4,7 @@ import os from "os";
|
||||
import path from "path";
|
||||
import { after, test } from "node:test";
|
||||
import { materializeExtensionPlugin } from "./materialize-plugins.mjs";
|
||||
import { cleanMaterializedExtensionPlugin } from "./clean-materialized-plugins.mjs";
|
||||
|
||||
const tempDirs = [];
|
||||
|
||||
@@ -13,7 +14,7 @@ after(() => {
|
||||
}
|
||||
});
|
||||
|
||||
test("materializeExtensionPlugin writes extension bundles to ./extensions and rewrites manifest", () => {
|
||||
test("materializeExtensionPlugin writes extension bundles to ./extensions and preserves root logo assets", () => {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "materialize-extension-plugin-"));
|
||||
tempDirs.push(tempDir);
|
||||
|
||||
@@ -32,17 +33,57 @@ test("materializeExtensionPlugin writes extension bundles to ./extensions and re
|
||||
fs.writeFileSync(path.join(pluginDir, "assets", "preview.png"), "fake-image-bytes");
|
||||
|
||||
const result = materializeExtensionPlugin(pluginDir);
|
||||
const bundleRoot = path.join(pluginDir, "extensions", "extension-plugin");
|
||||
|
||||
assert.equal(result.skipped, false);
|
||||
assert.equal(result.manifestUpdated, true);
|
||||
assert.equal(result.copiedEntries, 3);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extensions", "extension.mjs")), true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extensions", "assets", "preview.png")), true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extensions", "README.md")), true);
|
||||
assert.equal(result.movedEntries, 3);
|
||||
assert.equal(fs.existsSync(path.join(bundleRoot, "extension.mjs")), true);
|
||||
assert.equal(fs.existsSync(path.join(bundleRoot, "assets", "preview.png")), true);
|
||||
assert.equal(fs.existsSync(path.join(bundleRoot, "README.md")), true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extensions", ".github")), false);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extension.mjs")), false);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "README.md")), false);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "assets", "preview.png")), true);
|
||||
|
||||
const pluginManifest = JSON.parse(
|
||||
fs.readFileSync(path.join(pluginDir, ".github", "plugin", "plugin.json"), "utf8")
|
||||
);
|
||||
assert.equal(pluginManifest.extensions, "extensions");
|
||||
assert.equal(pluginManifest.logo, "assets/preview.png");
|
||||
});
|
||||
|
||||
test("cleanMaterializedExtensionPlugin restores moved extension files to root", () => {
|
||||
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "clean-materialized-extension-plugin-"));
|
||||
tempDirs.push(tempDir);
|
||||
|
||||
const pluginDir = path.join(tempDir, "extension-plugin");
|
||||
fs.mkdirSync(path.join(pluginDir, ".github", "plugin"), { recursive: true });
|
||||
fs.mkdirSync(path.join(pluginDir, "assets"), { recursive: true });
|
||||
fs.writeFileSync(path.join(pluginDir, ".github", "plugin", "plugin.json"), JSON.stringify({
|
||||
name: "test-extension-plugin",
|
||||
description: "test plugin",
|
||||
version: "1.0.0",
|
||||
logo: "assets/preview.png",
|
||||
extensions: ".",
|
||||
}, null, 2));
|
||||
fs.writeFileSync(path.join(pluginDir, "extension.mjs"), "export default {};\n");
|
||||
fs.writeFileSync(path.join(pluginDir, "README.md"), "# test\n");
|
||||
fs.writeFileSync(path.join(pluginDir, "assets", "preview.png"), "fake-image-bytes");
|
||||
|
||||
materializeExtensionPlugin(pluginDir);
|
||||
const result = cleanMaterializedExtensionPlugin(pluginDir);
|
||||
|
||||
assert.equal(result.removed, 3);
|
||||
assert.equal(result.manifestUpdated, true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extension.mjs")), true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "README.md")), true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "assets", "preview.png")), true);
|
||||
assert.equal(fs.existsSync(path.join(pluginDir, "extensions")), false);
|
||||
|
||||
const pluginManifest = JSON.parse(
|
||||
fs.readFileSync(path.join(pluginDir, ".github", "plugin", "plugin.json"), "utf8")
|
||||
);
|
||||
assert.equal(pluginManifest.extensions, ".");
|
||||
assert.equal(pluginManifest.logo, "assets/preview.png");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user