feat(plugins): add plugin packaging script and improve build command handling

This commit is contained in:
Johannes Millan 2025-11-26 17:23:17 +01:00
parent 6e25ed7053
commit 363b8d3729
4 changed files with 162 additions and 41 deletions

114
package-lock.json generated
View file

@ -5054,6 +5054,7 @@
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5070,6 +5071,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5086,6 +5088,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5102,6 +5105,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5118,6 +5122,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5134,6 +5139,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5150,6 +5156,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5166,6 +5173,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5182,6 +5190,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5198,6 +5207,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5214,6 +5224,7 @@
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5230,6 +5241,7 @@
"cpu": [
"loong64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5246,6 +5258,7 @@
"cpu": [
"mips64el"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5262,6 +5275,7 @@
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5278,6 +5292,7 @@
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5294,6 +5309,7 @@
"cpu": [
"s390x"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5310,6 +5326,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5326,6 +5343,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5342,6 +5360,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5358,6 +5377,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5374,6 +5394,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5390,6 +5411,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5406,6 +5428,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5422,6 +5445,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5438,6 +5462,7 @@
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -5454,6 +5479,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -6429,7 +6455,7 @@
"version": "0.3.13",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.13.tgz",
"integrity": "sha512-2kkt/7niJ6MgEPxF0bYdQ6etZaA+fQvDcLKckhy1yIQOzaoKjBBjSj63/aLVjYE3qhRt5dvM+uUyfCg6UKCBbA==",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.5.0",
@ -6438,7 +6464,7 @@
},
"node_modules/@jridgewell/resolve-uri": {
"version": "3.1.2",
"devOptional": true,
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6.0.0"
@ -6446,7 +6472,7 @@
},
"node_modules/@jridgewell/source-map": {
"version": "0.3.6",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.5",
@ -6455,14 +6481,14 @@
},
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.5.0",
"devOptional": true,
"dev": true,
"license": "MIT"
},
"node_modules/@jridgewell/trace-mapping": {
"version": "0.3.30",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.30.tgz",
"integrity": "sha512-GQ7Nw5G2lTu/BtHTKfXhKHok2WGetd4XYcVKGx00SjAk8GMwgJM3zr6zORiPGuOE+/vkc90KtTosSSvaCjKb2Q==",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/resolve-uri": "^3.1.0",
@ -7895,6 +7921,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7908,6 +7935,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7921,6 +7949,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7946,6 +7975,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7959,6 +7989,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7972,6 +8003,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7985,6 +8017,7 @@
"cpu": [
"arm"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -7998,6 +8031,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8011,6 +8045,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8024,6 +8059,7 @@
"cpu": [
"loong64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8037,6 +8073,7 @@
"cpu": [
"ppc64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8050,6 +8087,7 @@
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8063,6 +8101,7 @@
"cpu": [
"riscv64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8076,6 +8115,7 @@
"cpu": [
"s390x"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8100,6 +8140,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8113,6 +8154,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8126,6 +8168,7 @@
"cpu": [
"arm64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8139,6 +8182,7 @@
"cpu": [
"ia32"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -8152,6 +8196,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -9106,6 +9151,7 @@
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz",
"integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/express": {
@ -9222,7 +9268,7 @@
},
"node_modules/@types/node": {
"version": "20.12.4",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~5.26.4"
@ -10052,7 +10098,7 @@
"version": "8.15.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"devOptional": true,
"dev": true,
"license": "MIT",
"bin": {
"acorn": "bin/acorn"
@ -11165,7 +11211,7 @@
},
"node_modules/buffer-from": {
"version": "1.1.2",
"devOptional": true,
"dev": true,
"license": "MIT"
},
"node_modules/builder-util": {
@ -12228,7 +12274,7 @@
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-2.0.6.tgz",
"integrity": "sha512-1j20GZTsvKNkc4BY3NpMOM8tt///wY3FpIzozTOFO2ffuZcV61nojHXVKIy3WM+7ADCy5FVhdZYHYDdgTU0yJw==",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"is-what": "^3.14.1"
@ -14270,6 +14316,7 @@
"version": "0.25.9",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.9.tgz",
"integrity": "sha512-CRbODhYyQx3qp7ZEwzxOk4JBqmD/seJrzPa/cGjY1VtIn5E09Oi9/dB4JwctnfZ8Q8iT7rioVv5k/FNT/uf54g==",
"dev": true,
"hasInstallScript": true,
"license": "MIT",
"bin": {
@ -15318,6 +15365,7 @@
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
"integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12.0.0"
@ -15718,6 +15766,7 @@
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
"integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==",
"dev": true,
"hasInstallScript": true,
"optional": true,
"os": [
@ -16675,7 +16724,7 @@
},
"node_modules/immutable": {
"version": "5.1.1",
"devOptional": true,
"dev": true,
"license": "MIT"
},
"node_modules/import-fresh": {
@ -17310,7 +17359,7 @@
"version": "3.14.1",
"resolved": "https://registry.npmjs.org/is-what/-/is-what-3.14.1.tgz",
"integrity": "sha512-sNxgpk9793nzSs7bA6JQJGeIuRBQhAaNGG77kzYQgMkrID+lS6SlK07K5LaptscDlSaIgH+GPFzf+d75FVxozA==",
"devOptional": true,
"dev": true,
"license": "MIT"
},
"node_modules/is-wsl": {
@ -17623,7 +17672,7 @@
},
"node_modules/jiti": {
"version": "1.21.6",
"devOptional": true,
"dev": true,
"license": "MIT",
"bin": {
"jiti": "bin/jiti.js"
@ -18154,7 +18203,7 @@
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/less/-/less-4.4.0.tgz",
"integrity": "sha512-kdTwsyRuncDfjEs0DlRILWNvxhDG/Zij4YLO4TMJgDLW+8OzpfkdPnRgrsRuY1o+oaxJGWsps5f/RVBgGmmN0w==",
"devOptional": true,
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"copy-anything": "^2.0.1",
@ -20959,7 +21008,7 @@
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parse-node-version/-/parse-node-version-1.0.1.tgz",
"integrity": "sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==",
"devOptional": true,
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 0.10"
@ -21170,10 +21219,12 @@
},
"node_modules/picocolors": {
"version": "1.1.1",
"dev": true,
"license": "ISC"
},
"node_modules/picomatch": {
"version": "4.0.2",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
@ -21313,6 +21364,7 @@
"version": "8.5.6",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz",
"integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==",
"dev": true,
"funding": [
{
"type": "opencollective",
@ -21540,6 +21592,7 @@
"version": "3.3.11",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz",
"integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==",
"dev": true,
"funding": [
{
"type": "github",
@ -22459,6 +22512,7 @@
"version": "4.52.3",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.52.3.tgz",
"integrity": "sha512-RIDh866U8agLgiIcdpB+COKnlCreHJLfIhWC3LVflku5YHfpnsIKigRZeFfMfCc4dVcqNVfQQ5gO/afOck064A==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/estree": "1.0.8"
@ -22503,6 +22557,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -22516,6 +22571,7 @@
"cpu": [
"x64"
],
"dev": true,
"license": "MIT",
"optional": true,
"os": [
@ -22701,7 +22757,7 @@
"version": "1.90.0",
"resolved": "https://registry.npmjs.org/sass/-/sass-1.90.0.tgz",
"integrity": "sha512-9GUyuksjw70uNpb1MTYWsH9MQHOHY6kwfnkafC24+7aOMZn9+rVMBxRbLvw756mrBFbIsFg6Xw9IkR2Fnn3k+Q==",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"chokidar": "^4.0.0",
@ -22763,7 +22819,7 @@
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-4.0.3.tgz",
"integrity": "sha512-Qgzu8kfBvo+cA4962jnP1KkS6Dop5NS6g7R5LFYJr4b8Ub94PPQXUksCw9PvXoeXPRRddRNC5C1JQUR2SMGtnA==",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"readdirp": "^4.0.1"
@ -22779,7 +22835,7 @@
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.1.2.tgz",
"integrity": "sha512-GDhwkLfywWL2s6vEjyhri+eXmfH6j1L7JE27WhqLeYzoh/A3DBaYGEj2H/HFZCn/kMfim73FXxEJTw06WtxQwg==",
"devOptional": true,
"dev": true,
"license": "MIT",
"engines": {
"node": ">= 14.18.0"
@ -23448,6 +23504,7 @@
},
"node_modules/source-map-js": {
"version": "1.2.1",
"dev": true,
"license": "BSD-3-Clause",
"engines": {
"node": ">=0.10.0"
@ -23476,7 +23533,7 @@
},
"node_modules/source-map-support": {
"version": "0.5.21",
"devOptional": true,
"dev": true,
"license": "MIT",
"dependencies": {
"buffer-from": "^1.0.0",
@ -23485,7 +23542,7 @@
},
"node_modules/source-map-support/node_modules/source-map": {
"version": "0.6.1",
"devOptional": true,
"dev": true,
"license": "BSD-3-Clause",
"engines": {
"node": ">=0.10.0"
@ -24350,7 +24407,7 @@
"version": "5.43.1",
"resolved": "https://registry.npmjs.org/terser/-/terser-5.43.1.tgz",
"integrity": "sha512-+6erLbBm0+LROX2sPXlUYx/ux5PyE9K/a92Wrt6oA+WDAoFTdpHE5tCYCI5PNzq2y8df4rA+QgHLJuR4jNymsg==",
"devOptional": true,
"dev": true,
"license": "BSD-2-Clause",
"dependencies": {
"@jridgewell/source-map": "^0.3.3",
@ -24402,7 +24459,7 @@
},
"node_modules/terser/node_modules/commander": {
"version": "2.20.3",
"devOptional": true,
"dev": true,
"license": "MIT"
},
"node_modules/text-table": {
@ -24481,6 +24538,7 @@
"version": "0.2.14",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.14.tgz",
"integrity": "sha512-tX5e7OM1HnYr2+a2C/4V0htOcSQcoSTH9KgJnVvNm5zm/cyEWKJ7j7YutsH9CxMdtOkkLFy2AHrMci9IM8IPZQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"fdir": "^6.4.4",
@ -24718,7 +24776,7 @@
},
"node_modules/tslib": {
"version": "2.8.1",
"devOptional": true,
"dev": true,
"license": "0BSD"
},
"node_modules/tuf-js": {
@ -25237,7 +25295,7 @@
},
"node_modules/undici-types": {
"version": "5.26.5",
"devOptional": true,
"dev": true,
"license": "MIT"
},
"node_modules/unicode-canonical-property-names-ecmascript": {
@ -25478,6 +25536,7 @@
"version": "6.4.1",
"resolved": "https://registry.npmjs.org/vite/-/vite-6.4.1.tgz",
"integrity": "sha512-+Oxm7q9hDoLMyJOYfUYBuHQo+dkAloi33apOPP56pzj+vsdJDzr+j1NISE5pyaAuKL4A3UD34qd0lx5+kfKp2g==",
"dev": true,
"license": "MIT",
"dependencies": {
"esbuild": "^0.25.0",
@ -26562,12 +26621,13 @@
"packages/vite-plugin": {
"name": "@super-productivity/vite-plugin",
"version": "1.0.0",
"dependencies": {
"vite": "^6.0.0"
},
"devDependencies": {
"@types/node": "^22.0.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"vite": "^6.0.0"
},
"peerDependencies": {
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
}
},
"packages/vite-plugin/node_modules/@types/node": {

View file

@ -50,18 +50,23 @@ async function getPlugins() {
try {
await fs.access(packageJsonPath);
// It's a valid package
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf8'));
// Skip boilerplate
if (entry.name === 'boilerplate-solid-js') continue;
const buildScript = packageJson.scripts && packageJson.scripts.build;
// Check if it's a real build script or just a placeholder
const hasRealBuildScript =
buildScript && !buildScript.includes("echo 'No build needed");
plugins.push({
name: entry.name,
path: `packages/plugin-dev/${entry.name}`,
buildCommand: 'npm run build',
buildCommand: hasRealBuildScript ? 'npm run build' : undefined,
// Standard files to copy for bundled plugins
files: ['manifest.json', 'plugin.js', 'index.html', 'icon.svg'],
sourcePath: 'dist',
sourcePath: hasRealBuildScript ? 'dist' : '.',
});
} catch (e) {
// Not a package, skip
@ -82,16 +87,18 @@ async function ensureDir(dir) {
async function copyFile(src, dest) {
try {
// console.log(`Copying ${src} to ${dest}`);
await fs.copyFile(src, dest);
return true;
} catch (error) {
if (error.code !== 'ENOENT') {
// Only log if it's not a "file not found" error, as some plugins might not have all assets
// e.g. no index.html or icon.svg
// But for bundled plugins we generally expect them.
// Let's be silent about ENOENT for optional files
if (error.code === 'ENOENT') {
log(` ❌ Missing expected file: ${path.basename(src)} (path: ${src})`, colors.red);
// We want to fail if a file is missing
throw new Error(`Missing expected file: ${path.basename(src)}`);
} else {
log(` ❌ Failed to copy ${path.basename(src)}: ${error.message}`, colors.red);
throw error;
}
return false;
}
}
@ -144,8 +151,13 @@ async function buildPlugin(plugin) {
for (const file of filesToCopy) {
const src = path.join(sourcePath, file);
const dest = path.join(targetDir, file);
if (await copyFile(src, dest)) {
copiedCount++;
try {
if (await copyFile(src, dest)) {
copiedCount++;
}
} catch (e) {
// If copy fails (e.g. missing file), we stop and fail the build for this plugin
throw e;
}
}

View file

@ -0,0 +1,48 @@
import fs from 'fs';
import path from 'path';
import archiver from 'archiver';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(__dirname, '..');
const distDir = path.resolve(rootDir, 'dist');
const packageJson = JSON.parse(
fs.readFileSync(path.resolve(rootDir, 'package.json'), 'utf8'),
);
// Ensure dist exists
if (!fs.existsSync(distDir)) {
console.error('❌ dist directory not found. Run npm run build first.');
process.exit(1);
}
const zipName = `${packageJson.name}.zip`;
const output = fs.createWriteStream(path.join(rootDir, zipName));
const archive = archiver('zip', {
zlib: { level: 9 }, // Sets the compression level.
});
output.on('close', function () {
console.log(
`✅ Plugin packaged successfully: ${zipName} (${archive.pointer()} total bytes)`,
);
});
archive.on('warning', function (err) {
if (err.code === 'ENOENT') {
console.warn(err);
} else {
throw err;
}
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
// Append files from dist directory
archive.directory(distDir, false);
archive.finalize();

View file

@ -7,11 +7,12 @@
"scripts": {
"build": "tsc"
},
"dependencies": {
"vite": "^6.0.0"
"peerDependencies": {
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
},
"devDependencies": {
"@types/node": "^22.0.0",
"typescript": "^5.0.0"
"typescript": "^5.0.0",
"vite": "^6.0.0"
}
}