zarro 1.173.2 โ†’ 1.173.6

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.
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ (function () {
3
+ class CacheItem {
4
+ constructor(value, expires) {
5
+ this.value = value;
6
+ this.expires = expires;
7
+ }
8
+ }
9
+ class Cache {
10
+ constructor() {
11
+ this._store = {};
12
+ }
13
+ /**
14
+ * reads a value from the cache
15
+ * if the value is not found, the fallback, if supplied
16
+ * is returned, otherwise undefined is returned
17
+ * @param key
18
+ * @param fallback
19
+ */
20
+ read(key, fallback) {
21
+ const cached = this._findCacheItem(key);
22
+ return cached === undefined
23
+ ? fallback
24
+ : cached.value;
25
+ }
26
+ /**
27
+ * clears all cached values
28
+ */
29
+ clear() {
30
+ this._store = {};
31
+ }
32
+ /**
33
+ * stores a value in the cache
34
+ * @param key
35
+ * @param value
36
+ * @param ttlSeconds
37
+ */
38
+ write(key, value, ttlSeconds) {
39
+ this._store[key] = new CacheItem(value, Date.now() + ttlSeconds);
40
+ }
41
+ /**
42
+ * Runs the generator if there is no cache item with
43
+ * the provided key and stores the result. Subsequent
44
+ * calls will skip the generator function to retrieve
45
+ * from cache until the item expires.
46
+ * @param key
47
+ * @param generator
48
+ * @param ttlSeconds
49
+ */
50
+ async through(key, generator, ttlSeconds) {
51
+ const cached = this._findCacheItem(key);
52
+ if (cached) {
53
+ return cached.value;
54
+ }
55
+ const result = await generator();
56
+ this.write(key, result, ttlSeconds);
57
+ return result;
58
+ }
59
+ /**
60
+ * Runs the generator if there is no cache item with
61
+ * the provided key and stores the result. Subsequent
62
+ * calls will skip the generator function to retrieve
63
+ * from cache until the item expires.
64
+ * @param key
65
+ * @param generator
66
+ * @param ttlSeconds
67
+ */
68
+ throughSync(key, generator, ttlSeconds) {
69
+ const cached = this._findCacheItem(key);
70
+ if (cached) {
71
+ return cached.value;
72
+ }
73
+ const result = generator();
74
+ this.write(key, result, ttlSeconds);
75
+ return result;
76
+ }
77
+ _findCacheItem(key) {
78
+ const result = this._store[key];
79
+ if (result === undefined) {
80
+ return undefined;
81
+ }
82
+ if (result.expires < Date.now()) {
83
+ this.forget(key);
84
+ return undefined;
85
+ }
86
+ return result;
87
+ }
88
+ /**
89
+ * creates a new empty cache
90
+ */
91
+ create() {
92
+ return new Cache();
93
+ }
94
+ /**
95
+ * trims expired items from the cache
96
+ */
97
+ trim() {
98
+ for (const key of Object.keys(this._store)) {
99
+ const item = this._store[key];
100
+ if (item.expires < Date.now()) {
101
+ this.forget(key);
102
+ }
103
+ }
104
+ }
105
+ /**
106
+ * forgets the cached item by key
107
+ * @param key
108
+ */
109
+ forget(key) {
110
+ delete this._store[key];
111
+ }
112
+ }
113
+ module.exports = new Cache();
114
+ })();
@@ -18,6 +18,7 @@
18
18
  const env = requireModule("env");
19
19
  const Version = requireModule("version");
20
20
  const SystemError = requireModule("system-error");
21
+ const cache = requireModule("cache");
21
22
  const emojiLabels = {
22
23
  testing: `๐Ÿงช Testing`,
23
24
  packing: `๐Ÿ“ฆ Packing`,
@@ -787,6 +788,13 @@ WARNING: 'dotnet pack' ignores --version-suffix when a nuspec file is provided.
787
788
  const opts = typeof options === "string"
788
789
  ? { search: options }
789
790
  : options;
791
+ if (opts.skipCache) {
792
+ return await searchPackages(opts);
793
+ }
794
+ return await cache.through(JSON.stringify(opts), async () => await searchPackagesUncached(opts), 60 // cache for a minute
795
+ );
796
+ }
797
+ async function searchPackagesUncached(opts) {
790
798
  const args = ["package", "search"];
791
799
  pushIfSet(args, opts.source, "--source");
792
800
  pushFlag(args, opts.exactMatch, "--exact-match");
@@ -963,12 +971,19 @@ WARNING: 'dotnet pack' ignores --version-suffix when a nuspec file is provided.
963
971
  return source;
964
972
  }
965
973
  async function upgradePackages(opts) {
966
- var _a;
967
974
  verifyExists(opts, "no options provided to upgradePackages");
968
975
  verifyNonEmptyString(opts.pathToProjectOrSolution, "no path to a project or solution was supplied");
969
976
  if (!opts.packages || opts.packages.length === 0) {
970
977
  throw new ZarroError(`no packages were specified`);
971
978
  }
979
+ if (opts.showProgress === undefined) {
980
+ opts.showProgress = true;
981
+ }
982
+ const { ExecStepContext, Labelers } = require("exec-step"), ctx = new ExecStepContext({
983
+ labeler: opts.showProgress
984
+ ? Labelers.interactive
985
+ : Labelers.none
986
+ });
972
987
  const projects = isProject(opts.pathToProjectOrSolution)
973
988
  ? [opts.pathToProjectOrSolution]
974
989
  : await listProjects(opts.pathToProjectOrSolution);
@@ -978,23 +993,33 @@ WARNING: 'dotnet pack' ignores --version-suffix when a nuspec file is provided.
978
993
  for (const pkg of opts.packages) {
979
994
  const test = isRegex(pkg)
980
995
  ? (s) => pkg.test(s)
981
- : (s) => projectPackages.find(pp => pp.id.toLowerCase() === s.toLowerCase());
996
+ : (s) => s.toLowerCase() == pkg.toLowerCase();
982
997
  for (const projectPackage of projectPackages) {
983
998
  if (test(projectPackage.id)) {
984
999
  toUpgrade.push(projectPackage.id);
985
1000
  }
986
1001
  }
987
1002
  }
988
- const upstream = await searchForMultiplePackages(toUpgrade, opts.source, (_a = opts.preRelease) !== null && _a !== void 0 ? _a : false);
1003
+ if (toUpgrade.length === 0) {
1004
+ if (opts.showProgress) {
1005
+ console.log(` -> no matching packages to upgrade in '${project}'`);
1006
+ }
1007
+ continue;
1008
+ }
1009
+ const message = `searching for ${toUpgrade.length} packages to upgrade in ${project}`;
1010
+ const upstream = await ctx.exec(message, async () => {
1011
+ var _a;
1012
+ return await searchForMultiplePackages(toUpgrade, opts.source, (_a = opts.preRelease) !== null && _a !== void 0 ? _a : false);
1013
+ });
989
1014
  for (const pkg of upstream) {
990
- await installPackage({
1015
+ await ctx.exec(`installing '${pkg.id}' at version '${pkg.version}' into '${project}'`, async () => await installPackage({
991
1016
  projectFile: project,
992
1017
  id: pkg.id,
993
1018
  version: pkg.version.toString(),
994
1019
  source: opts.source,
995
1020
  noRestore: opts.noRestore,
996
1021
  preRelease: opts.preRelease
997
- });
1022
+ }));
998
1023
  }
999
1024
  }
1000
1025
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zarro",
3
- "version": "1.173.2",
3
+ "version": "1.173.6",
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"
@@ -61,7 +61,7 @@
61
61
  "decompress": "^4.2.1",
62
62
  "del": "^5.1.0",
63
63
  "event-stream": "^4.0.1",
64
- "exec-step": "^0.11.0",
64
+ "exec-step": "^0.14.0",
65
65
  "fancy-log": "^1.3.3",
66
66
  "gulp": "^4.0.0",
67
67
  "gulp-debug": "^4.0.0",
package/types.d.ts CHANGED
@@ -83,7 +83,7 @@ declare global {
83
83
  }
84
84
 
85
85
  interface Log {
86
- setThreshold(level: number): void;
86
+ setThreshold(level: number | string): void;
87
87
 
88
88
  debug(...args: any[]): void;
89
89
 
@@ -1543,6 +1543,12 @@ declare global {
1543
1543
  preRelease?: boolean;
1544
1544
  configFile?: string;
1545
1545
  latestOnly?: boolean;
1546
+ /**
1547
+ * search results are typically cached in memory
1548
+ * for 1 minute. If you absolutely _must_ have
1549
+ * fresh data, set this to false
1550
+ */
1551
+ skipCache?: boolean;
1546
1552
  }
1547
1553
 
1548
1554
  interface DotNetInstallNugetPackageOption
@@ -1635,6 +1641,10 @@ declare global {
1635
1641
  preRelease?: boolean;
1636
1642
  noRestore?: boolean;
1637
1643
  source?: string;
1644
+ /**
1645
+ * defaults to true
1646
+ */
1647
+ showProgress?: boolean;
1638
1648
  }
1639
1649
 
1640
1650
  type DotNetTestFunction = (opts: DotNetTestOptions) => Promise<SystemResult | SystemError>;
@@ -2135,5 +2145,24 @@ declare global {
2135
2145
  "ZPL-1.1" |
2136
2146
  "ZPL-2.0" |
2137
2147
  "ZPL-2.1"
2148
+
2149
+ interface Cache {
2150
+ read<T>(key: string, fallback?: T): Optional<T>;
2151
+ write<T>(key: string, value: T, ttlSeconds: number): void;
2152
+ through<T>(
2153
+ key: string,
2154
+ generator: Func<Promise<T>>,
2155
+ ttlSeconds: number
2156
+ ): Promise<T>;
2157
+ throughSync<T>(
2158
+ key: string,
2159
+ generator: Func<T>,
2160
+ ttlSeconds: number
2161
+ ): T;
2162
+ create(): Cache;
2163
+ trim(): void;
2164
+ forget(key: string): void;
2165
+ clear(): void;
2166
+ }
2138
2167
  }
2139
2168