@spica-devkit/testing 0.19.6 → 0.19.7

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/index.js CHANGED
@@ -278,6 +278,7 @@ var ChangeKind;
278
278
  ChangeKind["Update"] = "update";
279
279
  ChangeKind["Delete"] = "delete";
280
280
  })(ChangeKind || (ChangeKind = {}));
281
+ const DEFAULT_CONCURRENCY = 10;
281
282
 
282
283
  const noopProgress = {
283
284
  update() { },
@@ -11744,12 +11745,13 @@ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader
11744
11745
  return ret.join('\n') + '\n';
11745
11746
  }
11746
11747
 
11747
- async function buildPlan(modules, http, rootDir, detailed = false, detectRenames = true, reporter = silentReporter) {
11748
+ async function buildPlan(modules, http, rootDir, options = {}) {
11749
+ const { detailed = false, detectRenames = true, reporter = silentReporter, concurrency = DEFAULT_CONCURRENCY } = options;
11748
11750
  const modulePlans = [];
11749
11751
  for (const mod of modules) {
11750
11752
  const [locals, remotes] = await Promise.all([
11751
11753
  reporter.task(`Reading local ${mod.displayName} files`, () => mod.readLocal(rootDir)),
11752
- reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http))
11754
+ reporter.task(`Fetching remote ${mod.displayName}`, () => mod.readRemote(http, { concurrency }))
11753
11755
  ]);
11754
11756
  const localBySlug = new Map(locals.map(l => [l.slug, l]));
11755
11757
  const remoteBySlug = new Map(remotes.map(r => [r.slug, r]));
@@ -11829,7 +11831,7 @@ async function buildPlan(modules, http, rootDir, detailed = false, detectRenames
11829
11831
  return { modules: modulePlans };
11830
11832
  }
11831
11833
  async function applyPlan(plan, http, opts = {}) {
11832
- const concurrency = opts.concurrency ?? 10;
11834
+ const concurrency = opts.concurrency ?? DEFAULT_CONCURRENCY;
11833
11835
  const reporter = opts.reporter ?? silentReporter;
11834
11836
  const errors = [];
11835
11837
  const handleErr = (label, e) => {
@@ -12029,6 +12031,14 @@ function normalizeSchema(schema) {
12029
12031
  }
12030
12032
  return normalized;
12031
12033
  }
12034
+ async function mapInBatches(items, size, fn) {
12035
+ const limit = Math.max(1, size);
12036
+ const results = [];
12037
+ for (let i = 0; i < items.length; i += limit) {
12038
+ results.push(...(await Promise.all(items.slice(i, i + limit).map(fn))));
12039
+ }
12040
+ return results;
12041
+ }
12032
12042
  function isNotFoundError(error) {
12033
12043
  if (!error || typeof error !== "object")
12034
12044
  return false;
@@ -12038,6 +12048,11 @@ function isNotFoundError(error) {
12038
12048
  c.response?.status === 404 ||
12039
12049
  c.response?.statusCode === 404);
12040
12050
  }
12051
+ const emptyIfMissing = (empty) => (error) => {
12052
+ if (isNotFoundError(error))
12053
+ return empty;
12054
+ throw error;
12055
+ };
12041
12056
  const functionModule = {
12042
12057
  name: "function",
12043
12058
  displayName: "Function",
@@ -12074,17 +12089,19 @@ const functionModule = {
12074
12089
  }
12075
12090
  return results;
12076
12091
  },
12077
- async readRemote(http) {
12092
+ async readRemote(http, options = {}) {
12078
12093
  const res = await http.get("function");
12079
12094
  const fns = unwrapList(res);
12080
- return Promise.all(fns.map(async (fn) => {
12095
+ return mapInBatches(fns, options.concurrency ?? DEFAULT_CONCURRENCY, async (fn) => {
12081
12096
  const id = fn._id;
12082
12097
  const [indexRes, depsRes] = await Promise.all([
12083
- http.get(`function/${id}/index`).catch(() => ({ index: "" })),
12098
+ http.get(`function/${id}/index`).catch(emptyIfMissing({ index: "" })),
12084
12099
  http
12085
12100
  .get(`function/${id}/dependencies`)
12086
- .catch(() => [])
12087
- ]);
12101
+ .catch(emptyIfMissing([]))
12102
+ ]).catch(error => {
12103
+ throw new Error(`Could not read function "${fn.name}": ${error?.message ?? error}`);
12104
+ });
12088
12105
  const dependencies = {};
12089
12106
  for (const dep of depsRes) {
12090
12107
  dependencies[dep.name] = dep.version;
@@ -12098,7 +12115,7 @@ const functionModule = {
12098
12115
  dependencies
12099
12116
  }
12100
12117
  };
12101
- }));
12118
+ });
12102
12119
  },
12103
12120
  async create(http, local) {
12104
12121
  const id = await this.createSchema(http, local.data.schema);