@pubm/plugin-brew 0.4.0 → 0.4.2

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.
Files changed (2) hide show
  1. package/dist/index.js +23 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -72,20 +72,28 @@ function updateFormula(content, version, assets) {
72
72
  }
73
73
  return updated;
74
74
  }
75
- function mapReleaseAssets(assets) {
76
- const platformMap = {
77
- "darwin-arm64": "darwin-arm64",
78
- "darwin-x64": "darwin-x64",
79
- "linux-arm64": "linux-arm64",
80
- "linux-x64": "linux-x64"
81
- };
75
+ var FORMULA_PLATFORMS = {
76
+ "darwin-arm64": { os: "darwin", arch: "arm64" },
77
+ "darwin-x64": { os: "darwin", arch: "x64" },
78
+ "linux-arm64": { os: "linux", arch: "arm64" },
79
+ "linux-x64": { os: "linux", arch: "x64" }
80
+ };
81
+ function matchAssetToPlatform(assets, formulaPlatform, customMatcher) {
82
+ if (customMatcher)
83
+ return assets.find(customMatcher);
84
+ const { os, arch } = FORMULA_PLATFORMS[formulaPlatform];
85
+ return assets.find((a) => a.platform.os === os && a.platform.arch === arch);
86
+ }
87
+ function releaseAssetsToFormulaAssets(assets, customMatchers) {
82
88
  const result = [];
83
- for (const asset of assets) {
84
- for (const [key, platform] of Object.entries(platformMap)) {
85
- if (asset.name.includes(key)) {
86
- result.push({ platform, url: asset.url, sha256: asset.sha256 });
87
- break;
88
- }
89
+ for (const key of Object.keys(FORMULA_PLATFORMS)) {
90
+ const matched = matchAssetToPlatform(assets, key, customMatchers?.[key]);
91
+ if (matched) {
92
+ result.push({
93
+ platform: key,
94
+ url: matched.url,
95
+ sha256: matched.sha256
96
+ });
89
97
  }
90
98
  }
91
99
  return result;
@@ -154,7 +162,7 @@ function brewCore(options) {
154
162
  const pkgPath = resolve(cwd, "package.json");
155
163
  const pkg = existsSync(pkgPath) ? JSON.parse(readFileSync(pkgPath, "utf-8")) : {};
156
164
  const name = pkg.name?.replace(/^@[^/]+\//, "") ?? "my-tool";
157
- const formulaAssets = mapReleaseAssets(releaseCtx.assets);
165
+ const formulaAssets = releaseAssetsToFormulaAssets(releaseCtx.assets, options.assetPlatforms);
158
166
  try {
159
167
  execSync2("gh repo fork homebrew/homebrew-core --clone=false", {
160
168
  stdio: "pipe"
@@ -244,7 +252,7 @@ function brewTap(options) {
244
252
  if (options.packageName && releaseCtx.packageName !== options.packageName) {
245
253
  return;
246
254
  }
247
- const formulaAssets = mapReleaseAssets(releaseCtx.assets);
255
+ const formulaAssets = releaseAssetsToFormulaAssets(releaseCtx.assets, options.assetPlatforms);
248
256
  const formulaPath = resolve2(process.cwd(), options.formula);
249
257
  let content;
250
258
  if (existsSync2(formulaPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubm/plugin-brew",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "pubm plugin for Homebrew formula publishing workflows",
6
6
  "main": "./dist/index.js",