Skip to content
Closed
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"examples/*"
],
"scripts": {
"postinstall": "node scripts/setup-bun.mjs || echo 'setup-bun.mjs failed or not available'",
"start": "npm run examples:dev",
"generate:schemas": "tsx scripts/generate-schemas.ts && prettier --write \"src/generated/**/*\"",
"sync:snippets": "bun scripts/sync-snippets.ts",
"build": "npm run generate:schemas && npm run sync:snippets && node scripts/run-bun.mjs build.bun.ts && node scripts/link-self.mjs",
"prepack": "npm run build",
"prepack": "npm run build && node scripts/strip-optional-deps.mjs",
"postpack": "node scripts/restore-package-json.mjs",
"build:all": "npm run examples:build",
"test": "bun test src",
"test:e2e": "playwright test",
Expand Down
14 changes: 14 additions & 0 deletions scripts/restore-package-json.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node
// Restores the original package.json after packing (saved by strip-optional-deps.mjs).

import { copyFileSync, unlinkSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const pkgPath = join(__dirname, "..", "package.json");

copyFileSync(pkgPath + ".bak", pkgPath);
unlinkSync(pkgPath + ".bak");

console.log("[restore-package-json] Restored original package.json");
32 changes: 32 additions & 0 deletions scripts/strip-optional-deps.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env node
// Strips dev-only platform binaries (@oven/bun-*, @rollup/rollup-*) from
// optionalDependencies before packing. Consumers don't need these.
// Original is saved to package.json.bak and restored by restore-package-json.mjs (postpack).

import { readFileSync, writeFileSync, copyFileSync } from "fs";
import { join, dirname } from "path";
import { fileURLToPath } from "url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const pkgPath = join(__dirname, "..", "package.json");

copyFileSync(pkgPath, pkgPath + ".bak");

const DEV_ONLY_PREFIXES = ["@oven/bun-", "@rollup/rollup-"];

const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
const optional = pkg.optionalDependencies;
if (optional) {
const removed = [];
for (const name of Object.keys(optional)) {
if (DEV_ONLY_PREFIXES.some((p) => name.startsWith(p))) {
delete optional[name];
removed.push(name);
}
}
if (Object.keys(optional).length === 0) delete pkg.optionalDependencies;
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
console.log(
`[strip-optional-deps] Removed ${removed.length} dev-only packages from optionalDependencies`,
);
}