zarro 1.170.4 → 1.170.8

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.
@@ -13,7 +13,7 @@
13
13
  const nugetPushSource = sourceName ||
14
14
  env.resolve(env.NUGET_PUSH_SOURCE, env.NUGET_SOURCE) ||
15
15
  "nuget.org";
16
- const apiKey = resolveNugetApiKey(nugetPushSource);
16
+ const apiKey = await resolveNugetApiKey(nugetPushSource);
17
17
  options = options || {};
18
18
  options.skipDuplicates = options.skipDuplicates === undefined
19
19
  ? env.resolveFlag("NUGET_IGNORE_DUPLICATE_PACKAGES")
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  (function () {
3
- const env = requireModule("env");
4
- function resolveNugetApiKey(source) {
3
+ const env = requireModule("env"), log = requireModule("log"), { listNugetSources } = requireModule("dotnet-cli");
4
+ async function resolveNugetApiKey(source) {
5
5
  const allKeys = resolveSourceToKeyLookup(), requestedSource = resolveSource(source);
6
6
  if (!requestedSource) {
7
7
  return findValue(allKeys, "nuget.org") || findValue(allKeys, "*");
8
8
  }
9
- const perSource = findValue(allKeys, requestedSource), multiKeyFallback = findValue(allKeys, "*"), nugetOrgFallback = findValue(allKeys, "nuget.org"), ultimateFallback = env.resolve(env.NUGET_API_KEY);
9
+ const perSource = findValue(allKeys, requestedSource, await resolveSourceName(requestedSource)), multiKeyFallback = findValue(allKeys, "*"), nugetOrgFallback = findValue(allKeys, "nuget.org"), ultimateFallback = env.resolve(env.NUGET_API_KEY);
10
10
  return perSource || multiKeyFallback || nugetOrgFallback || ultimateFallback || undefined;
11
11
  }
12
12
  function resolveSourceToKeyLookup() {
@@ -32,15 +32,23 @@
32
32
  ["*"]: k
33
33
  };
34
34
  }
35
- function findValue(keys, seek) {
36
- if (!keys || !seek) {
35
+ function findValue(data, ...seekKeys) {
36
+ if (!data || !seekKeys) {
37
37
  return undefined;
38
38
  }
39
- const exactMatch = keys[seek];
40
- if (exactMatch) {
41
- return exactMatch;
39
+ const setValues = seekKeys.filter(s => !!s);
40
+ const uniqueKeys = new Set(setValues);
41
+ for (let seek of uniqueKeys) {
42
+ const exactMatch = data[seek];
43
+ if (exactMatch) {
44
+ return exactMatch;
45
+ }
46
+ const thisPass = fuzzyFindValue(data, seek);
47
+ if (thisPass) {
48
+ return thisPass;
49
+ }
42
50
  }
43
- return fuzzyFindValue(keys, seek);
51
+ return undefined;
44
52
  }
45
53
  function fuzzyFindValue(keys, seek) {
46
54
  const keyLookup = Object.keys(keys)
@@ -51,6 +59,29 @@
51
59
  const key = keyLookup[seek.toLowerCase()];
52
60
  return keys[key];
53
61
  }
62
+ async function resolveSourceName(sourceToResolve) {
63
+ const sources = await listNugetSources();
64
+ for (const source of sources) {
65
+ if (source.name.toLowerCase() === sourceToResolve.toLowerCase()) {
66
+ return source.name;
67
+ }
68
+ if (source.url.toLowerCase() === sourceToResolve.toLowerCase()) {
69
+ return source.name;
70
+ }
71
+ }
72
+ if (!!process.env[env.NUGET_API_KEY] && looksLikeUrl(sourceToResolve)) {
73
+ return undefined;
74
+ }
75
+ log.warn(`Unable to match provided nuget push source '${sourceToResolve}' to the url or name of any registered source on this machine`);
76
+ log.warn(` known sources are:`);
77
+ for (const source of sources) {
78
+ log.warn(` ${source.name}: ${source.url} (${source.enabled ? "enabled" : "disabled"})`);
79
+ }
80
+ return undefined;
81
+ }
82
+ function looksLikeUrl(str) {
83
+ return !!str && str.includes("://");
84
+ }
54
85
  function resolveSource(source) {
55
86
  if (source) {
56
87
  return source;
@@ -1,9 +1,13 @@
1
1
  "use strict";
2
2
  (function () {
3
3
  const _which_ = require("which");
4
+ const cache = {};
4
5
  module.exports = function which(executable) {
6
+ if (cache[executable]) {
7
+ return cache[executable];
8
+ }
5
9
  try {
6
- return _which_.sync(executable);
10
+ return cache[executable] = _which_.sync(executable);
7
11
  }
8
12
  catch (e) {
9
13
  return undefined;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  (function () {
3
3
  gulp.task("nuget-push", "Pushes the latest versions of packages in the package build dir", async () => {
4
- const debug = requireModule("debug")(__filename), path = require("path"), nugetPush = requireModule("nuget-push"), { ls, FsEntities } = require("yafs"), env = requireModule("env"), folder = env.resolve(env.PACK_TARGET_FOLDER), versionRe = /^(?<id>[A-Za-z\.]+)\.(?<version>\d\.\d\.\d)(-(?<tag>.*))?.nupkg$/, packages = await ls(folder, {
4
+ const debug = requireModule("debug")(__filename), path = require("path"), nugetPush = requireModule("nuget-push"), { ls, FsEntities } = require("yafs"), env = requireModule("env"), folder = env.resolve(env.PACK_TARGET_FOLDER), versionRe = /^(?<id>[A-Za-z\.]+)\.(?<version>\d\.\d\.\d)(-(?<tag>.*))?\.nupkg$/, packages = await ls(folder, {
5
5
  recurse: false,
6
6
  entities: FsEntities.files,
7
7
  match: versionRe
@@ -30,7 +30,7 @@
30
30
  await nugetPush({
31
31
  source,
32
32
  target: pkg,
33
- apiKey: resolveNugetApiKey(source)
33
+ apiKey: await resolveNugetApiKey(source)
34
34
  });
35
35
  }
36
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zarro",
3
- "version": "1.170.4",
3
+ "version": "1.170.8",
4
4
  "description": "Some glue to make gulp easier, perhaps even zero- or close-to-zero-conf",
5
5
  "bin": {
6
6
  "zarro": "./index.js"
@@ -121,6 +121,7 @@
121
121
  "@types/semver": "^7.5.0",
122
122
  "@types/through2": "^2.0.38",
123
123
  "@types/typescript": "^2.0.0",
124
+ "@types/which": "^3.0.3",
124
125
  "@types/xml2js": "^0.4.8",
125
126
  "@types/yargs": "^15.0.13",
126
127
  "console-cls": "^1.2.2",
package/types.d.ts CHANGED
@@ -531,7 +531,7 @@ declare global {
531
531
  open(url: string): Promise<void>;
532
532
  }
533
533
 
534
- type ResolveNugetApiKey = (forSource?: string) => Optional<string>;
534
+ type ResolveNugetApiKey = (forSource?: string) => Promise<Optional<string>>;
535
535
 
536
536
  interface Env
537
537
  extends Dictionary<any> {