Repository navigation
Expand file tree
/
Copy pathmodify-package.js
More file actions
45 lines (37 loc) · 1.42 KB
/
Copy pathmodify-package.js
File metadata and controls
45 lines (37 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const buildDir = "./build";
const packageFile = path.join(buildDir, "package.json");
// Proper __dirname replacement for ES modules
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Read the original package.json
const originalPackageData = JSON.parse(
fs.readFileSync(path.join(__dirname, "package.json"), "utf-8")
);
// Whitelist runtime dependencies
const runtimeDeps = ["discord.js", "bedrock-protocol", "minecraft-data"];
// Extract only required dependencies
const dependencies = {};
for (const dep of runtimeDeps) {
if (originalPackageData.dependencies?.[dep]) {
dependencies[dep] = originalPackageData.dependencies[dep];
} else if (originalPackageData.devDependencies?.[dep]) {
// fallback if still listed under devDependencies
dependencies[dep] = originalPackageData.devDependencies[dep];
}
}
// Build minimal package.json for distribution
const packageData = {
name: originalPackageData.name,
version: originalPackageData.version,
productName: originalPackageData.productName,
description: originalPackageData.description,
type: "module",
dependencies
};
// Ensure build directory exists
fs.mkdirSync(buildDir, { recursive: true });
// Write the modified package.json
fs.writeFileSync(packageFile, JSON.stringify(packageData, null, 2));