@raegent/earshot 0.3.0 → 0.3.1

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/main.js CHANGED
@@ -18381,7 +18381,7 @@ class ShadowGit {
18381
18381
  }
18382
18382
 
18383
18383
  // packages/core/src/version.ts
18384
- var VERSION = "0.3.0";
18384
+ var VERSION = "0.3.1";
18385
18385
 
18386
18386
  // packages/core/src/session/repair.ts
18387
18387
  var REPAIR_TEXT = "No result was recorded for this call: earshot exited before the tool finished. " + "The call may or may not have run, so treat its effect as unknown and check " + "the current state rather than assuming either outcome.";
@@ -22757,23 +22757,38 @@ function compareVersions(a, b) {
22757
22757
  return -1;
22758
22758
  return left.pre < right.pre ? -1 : 1;
22759
22759
  }
22760
- async function resolveLatest(kind, fetchImpl) {
22761
- if (kind === "npm") {
22762
- const response2 = await fetchImpl(REGISTRY);
22763
- if (!response2.ok)
22764
- throw new Error(`npm registry returned ${response2.status}`);
22765
- const body2 = await response2.json();
22766
- if (!body2.version)
22767
- throw new Error("npm registry returned no version");
22768
- return body2.version;
22769
- }
22770
- const response = await fetchImpl(RELEASE);
22760
+ function releaseAuth(env) {
22761
+ const token = env.EARSHOT_GITHUB_TOKEN ?? env.GITHUB_TOKEN ?? env.GH_TOKEN;
22762
+ return token ? { headers: { authorization: `Bearer ${token}` } } : {};
22763
+ }
22764
+ function releaseNotFound(env) {
22765
+ return releaseAuth(env).headers === undefined ? "GitHub returned 404. The releases are not public, so this needs a token: " + "set GITHUB_TOKEN (or GH_TOKEN) to one that can read the repository." : "GitHub returned 404 for the token in GITHUB_TOKEN; it may not have access " + "to this repository.";
22766
+ }
22767
+ async function fetchRelease(fetchImpl, env) {
22768
+ const response = await fetchImpl(RELEASE, releaseAuth(env));
22769
+ if (response.status === 404)
22770
+ throw new Error(releaseNotFound(env));
22771
22771
  if (!response.ok)
22772
22772
  throw new Error(`GitHub releases returned ${response.status}`);
22773
22773
  const body = await response.json();
22774
22774
  if (!body.tag_name)
22775
22775
  throw new Error("GitHub returned a release with no tag");
22776
- return body.tag_name.replace(/^v/, "");
22776
+ const assets = {};
22777
+ for (const asset of body.assets ?? [])
22778
+ assets[asset.name] = asset.url;
22779
+ return { version: body.tag_name.replace(/^v/, ""), assets };
22780
+ }
22781
+ async function resolveLatest(kind, fetchImpl, env = process.env) {
22782
+ if (kind === "npm") {
22783
+ const response = await fetchImpl(REGISTRY);
22784
+ if (!response.ok)
22785
+ throw new Error(`npm registry returned ${response.status}`);
22786
+ const body = await response.json();
22787
+ if (!body.version)
22788
+ throw new Error("npm registry returned no version");
22789
+ return body.version;
22790
+ }
22791
+ return (await fetchRelease(fetchImpl, env)).version;
22777
22792
  }
22778
22793
  function findChecksum(sums, asset) {
22779
22794
  for (const line of sums.split(`
@@ -22811,7 +22826,7 @@ async function runUpdate(options = {}) {
22811
22826
  },
22812
22827
  isProjectRoot: (dir) => existsSync2(join19(dir, "package.json"))
22813
22828
  });
22814
- const fetchImpl = options.fetch ?? ((url) => fetch(url));
22829
+ const fetchImpl = options.fetch ?? ((url, init) => fetch(url, init));
22815
22830
  if (install.kind === "source" || install.kind === "unknown") {
22816
22831
  err(`earshot update: ${install.reason}
22817
22832
  `);
@@ -22826,8 +22841,14 @@ async function runUpdate(options = {}) {
22826
22841
  return 2;
22827
22842
  }
22828
22843
  let latest;
22844
+ let release2;
22829
22845
  try {
22830
- latest = await resolveLatest(install.kind, fetchImpl);
22846
+ if (install.kind === "binary") {
22847
+ release2 = await fetchRelease(fetchImpl, options.env ?? process.env);
22848
+ latest = release2.version;
22849
+ } else {
22850
+ latest = await resolveLatest(install.kind, fetchImpl, options.env ?? process.env);
22851
+ }
22831
22852
  } catch (error) {
22832
22853
  err(`earshot update: ${error.message}
22833
22854
  `);
@@ -22871,7 +22892,7 @@ async function runUpdate(options = {}) {
22871
22892
  `);
22872
22893
  return 0;
22873
22894
  }
22874
- return await updateBinary(install, latest, options, out, err);
22895
+ return await updateBinary(install, release2, options, out, err);
22875
22896
  }
22876
22897
  function runCommand2(command, args) {
22877
22898
  const result = spawnSync2(command, args, { stdio: "inherit", windowsHide: true, shell: false });
@@ -22894,11 +22915,12 @@ async function defaultConfirm(question) {
22894
22915
  rl.close();
22895
22916
  }
22896
22917
  }
22897
- async function updateBinary(install, latest, options, out, err) {
22918
+ async function updateBinary(install, release2, options, out, err) {
22898
22919
  const target = install.path;
22899
22920
  const asset = install.asset;
22900
22921
  const dir = dirname9(target);
22901
- const fetchImpl = options.fetch ?? ((url) => fetch(url));
22922
+ const latest = release2.version;
22923
+ const fetchImpl = options.fetch ?? ((url, init) => fetch(url, init));
22902
22924
  await sweepStale(dir, target);
22903
22925
  out(` ${target} ${asset}
22904
22926
  `);
@@ -22919,16 +22941,29 @@ async function updateBinary(install, latest, options, out, err) {
22919
22941
  `);
22920
22942
  return 0;
22921
22943
  }
22922
- const base = `https://github.com/${REPO}/releases/download/v${latest}`;
22944
+ const assetUrl = release2.assets[asset];
22945
+ const sumsUrl = release2.assets.SHA256SUMS;
22946
+ if (assetUrl === undefined || sumsUrl === undefined) {
22947
+ err(`earshot update: release v${latest} does not publish ${assetUrl ? "SHA256SUMS" : asset}
22948
+ `);
22949
+ return 1;
22950
+ }
22923
22951
  const temp = join19(dir, `.earshot-update-${process.pid}.tmp`);
22924
22952
  try {
22953
+ const auth2 = releaseAuth(options.env ?? process.env);
22954
+ const octet = {
22955
+ ...auth2,
22956
+ headers: { ...auth2.headers, accept: "application/octet-stream" }
22957
+ };
22925
22958
  out(" downloading… ");
22926
- const download = await fetchImpl(`${base}/${asset}`);
22959
+ const download = await fetchImpl(assetUrl, octet);
22960
+ if (download.status === 404)
22961
+ throw new Error(releaseNotFound(options.env ?? process.env));
22927
22962
  if (!download.ok)
22928
22963
  throw new Error(`downloading ${asset} returned ${download.status}`);
22929
22964
  const bytes = new Uint8Array(await download.arrayBuffer());
22930
22965
  out("verifying SHA256… ");
22931
- const sumsResponse = await fetchImpl(`${base}/SHA256SUMS`);
22966
+ const sumsResponse = await fetchImpl(sumsUrl, octet);
22932
22967
  if (!sumsResponse.ok)
22933
22968
  throw new Error(`SHA256SUMS returned ${sumsResponse.status}`);
22934
22969
  const expected = findChecksum(await sumsResponse.text(), asset);
@@ -23068,5 +23103,5 @@ async function main(argv = process.argv.slice(2)) {
23068
23103
  var code = await main();
23069
23104
  process.exitCode = code;
23070
23105
 
23071
- //# debugId=8F9F015F9221906F64756E2164756E21
23106
+ //# debugId=6AB54613CF301A9064756E2164756E21
23072
23107
  //# sourceMappingURL=main.js.map