onreza-release 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2739,6 +2739,8 @@ function getBinarySourcePath(config, platform) {
2739
2739
  }
2740
2740
 
2741
2741
  // src/utils/binary-postinstall-generator.ts
2742
+ import { mkdir, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
2743
+ import { join } from "node:path";
2742
2744
  function generatePostinstallScript(manifest) {
2743
2745
  return `#!/usr/bin/env node
2744
2746
  "use strict";
@@ -2872,6 +2874,88 @@ function generateMasterPackageJson(name, version, binName, description) {
2872
2874
  };
2873
2875
  return JSON.stringify(pkg, null, 2);
2874
2876
  }
2877
+ async function writeNpmFiles(options) {
2878
+ const { manifest, binName, npmConfig, baseDir = ".", dryRun = false } = options;
2879
+ const scriptsDir = join(baseDir, npmConfig.scriptsDir);
2880
+ const binDir = join(baseDir, npmConfig.binDir);
2881
+ const postinstallPath = join(scriptsDir, "postinstall.js");
2882
+ const binWrapperPath = join(binDir, `${binName}.js`);
2883
+ const postinstallContent = generatePostinstallScript(manifest);
2884
+ const binWrapperContent = generateBinWrapper(binName);
2885
+ if (dryRun) {
2886
+ console.log(`
2887
+ \uD83D\uDCDD Would write postinstall script to: ${postinstallPath}`);
2888
+ console.log(`\uD83D\uDCDD Would write bin wrapper to: ${binWrapperPath}`);
2889
+ } else {
2890
+ await mkdir(scriptsDir, { recursive: true });
2891
+ await mkdir(binDir, { recursive: true });
2892
+ await writeFile3(postinstallPath, postinstallContent, "utf-8");
2893
+ await writeFile3(binWrapperPath, binWrapperContent, { encoding: "utf-8", mode: 493 });
2894
+ console.log(`✅ Created postinstall script: ${postinstallPath}`);
2895
+ console.log(`✅ Created bin wrapper: ${binWrapperPath}`);
2896
+ }
2897
+ let packageJsonUpdated = false;
2898
+ if (npmConfig.updatePackageJson) {
2899
+ packageJsonUpdated = await updatePackageJsonForBinaries({
2900
+ baseDir,
2901
+ binDir: npmConfig.binDir,
2902
+ binName,
2903
+ dryRun,
2904
+ scriptsDir: npmConfig.scriptsDir
2905
+ });
2906
+ }
2907
+ return {
2908
+ binWrapperPath,
2909
+ packageJsonUpdated,
2910
+ postinstallPath
2911
+ };
2912
+ }
2913
+ async function updatePackageJsonForBinaries(options) {
2914
+ const { baseDir, binName, scriptsDir, binDir, dryRun = false } = options;
2915
+ const packageJsonPath = join(baseDir, "package.json");
2916
+ try {
2917
+ const content = await readFile5(packageJsonPath, "utf-8");
2918
+ const pkg = JSON.parse(content);
2919
+ let modified = false;
2920
+ const expectedBin = `${binDir}/${binName}.js`;
2921
+ if (!pkg.bin || pkg.bin[binName] !== expectedBin) {
2922
+ pkg.bin = pkg.bin || {};
2923
+ pkg.bin[binName] = expectedBin;
2924
+ modified = true;
2925
+ }
2926
+ const expectedPostinstall = `node ${scriptsDir}/postinstall.js`;
2927
+ if (!pkg.scripts?.postinstall || pkg.scripts.postinstall !== expectedPostinstall) {
2928
+ pkg.scripts = pkg.scripts || {};
2929
+ pkg.scripts.postinstall = expectedPostinstall;
2930
+ modified = true;
2931
+ }
2932
+ if (pkg.files && Array.isArray(pkg.files)) {
2933
+ if (!pkg.files.includes(scriptsDir)) {
2934
+ pkg.files.push(scriptsDir);
2935
+ modified = true;
2936
+ }
2937
+ if (!pkg.files.includes(binDir)) {
2938
+ pkg.files.push(binDir);
2939
+ modified = true;
2940
+ }
2941
+ }
2942
+ if (modified) {
2943
+ if (dryRun) {
2944
+ console.log("\uD83D\uDCDD Would update package.json with bin and scripts.postinstall");
2945
+ } else {
2946
+ await writeFile3(packageJsonPath, `${JSON.stringify(pkg, null, 2)}
2947
+ `, "utf-8");
2948
+ console.log("✅ Updated package.json with bin and scripts.postinstall");
2949
+ }
2950
+ return true;
2951
+ }
2952
+ console.log("ℹ️ package.json already has correct bin and scripts.postinstall");
2953
+ return false;
2954
+ } catch (error) {
2955
+ console.warn(`⚠️ Could not update package.json: ${error instanceof Error ? error.message : String(error)}`);
2956
+ return false;
2957
+ }
2958
+ }
2875
2959
 
2876
2960
  // src/binaries.ts
2877
2961
  function sleep2(ms) {
@@ -3008,14 +3092,35 @@ async function publishBinaries(options = {}) {
3008
3092
  }
3009
3093
  const binName = binariesConfig.binName ?? binariesConfig.name;
3010
3094
  const manifest = createBinaryManifest(version, binName, assets);
3011
- console.log(`
3095
+ if (binariesConfig.npm?.generateScripts !== false) {
3096
+ const npmConfig = {
3097
+ binDir: binariesConfig.npm?.binDir ?? "bin",
3098
+ generateScripts: binariesConfig.npm?.generateScripts ?? true,
3099
+ scriptsDir: binariesConfig.npm?.scriptsDir ?? "scripts",
3100
+ updatePackageJson: binariesConfig.npm?.updatePackageJson ?? true
3101
+ };
3102
+ console.log(`
3103
+ \uD83D\uDCE6 Generating npm distribution files...`);
3104
+ await writeNpmFiles({
3105
+ binName,
3106
+ manifest,
3107
+ npmConfig
3108
+ });
3109
+ console.log(`
3110
+ \uD83D\uDCA1 Next steps:`);
3111
+ console.log(" 1. Review generated files in scripts/ and bin/");
3112
+ console.log(" 2. Run: npm publish (or bun publish)");
3113
+ console.log(` 3. Users install with: npm install ${binariesConfig.name}`);
3114
+ } else {
3115
+ console.log(`
3012
3116
  \uD83D\uDCDD Generated manifest:`);
3013
- console.log(JSON.stringify(manifest, null, 2));
3014
- console.log(`
3117
+ console.log(JSON.stringify(manifest, null, 2));
3118
+ console.log(`
3015
3119
  \uD83D\uDCDC Postinstall script:`);
3016
- console.log("---");
3017
- console.log(generatePostinstallScript(manifest));
3018
- console.log("---");
3120
+ console.log("---");
3121
+ console.log(generatePostinstallScript(manifest));
3122
+ console.log("---");
3123
+ }
3019
3124
  }
3020
3125
  result.success = successfulUploads.length > 0;
3021
3126
  if (result.success) {
@@ -3110,6 +3215,17 @@ function printDryRun(config, version, platforms) {
3110
3215
  console.log(` Max files per upload: ${GITVERSE_ASSET_LIMITS.maxFilesPerUpload}`);
3111
3216
  console.log(` Max total size: ${formatFileSize2(GITVERSE_ASSET_LIMITS.maxTotalSizeBytes)}`);
3112
3217
  console.log(" Note: Actual limits depend on detected platform");
3218
+ if (config.npm?.generateScripts !== false) {
3219
+ const scriptsDir = config.npm?.scriptsDir ?? "scripts";
3220
+ const binDir = config.npm?.binDir ?? "bin";
3221
+ console.log(`
3222
+ \uD83D\uDCDD NPM distribution files to generate:`);
3223
+ console.log(` Postinstall script: ${scriptsDir}/postinstall.js`);
3224
+ console.log(` Bin wrapper: ${binDir}/${binName}.js`);
3225
+ if (config.npm?.updatePackageJson !== false) {
3226
+ console.log(" package.json: will be updated with bin and scripts.postinstall");
3227
+ }
3228
+ }
3113
3229
  }
3114
3230
 
3115
3231
  // src/index.ts
@@ -3464,4 +3580,4 @@ export {
3464
3580
  ALL_PLATFORMS
3465
3581
  };
3466
3582
 
3467
- //# debugId=979CA2E5EEBF807664756E2164756E21
3583
+ //# debugId=A12CD79F2B321E6A64756E2164756E21