@x18n/core 0.1.1 → 0.1.3

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.mjs +14 -8
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -2542,7 +2542,14 @@ function renderPrompt(data) {
2542
2542
  }
2543
2543
  //#endregion
2544
2544
  //#region src/project/project.ts
2545
- const scanConcurrency = 64;
2545
+ const ioConcurrency = 64;
2546
+ async function forEachLimit(items, limit, fn) {
2547
+ let next = 0;
2548
+ const worker = async () => {
2549
+ while (next < items.length) await fn(items[next++]);
2550
+ };
2551
+ await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
2552
+ }
2546
2553
  function createProject(options) {
2547
2554
  const { host, setup } = options;
2548
2555
  const { config, registry } = setup;
@@ -2786,14 +2793,13 @@ function createProject(options) {
2786
2793
  }
2787
2794
  async function loadResources(candidates, reread) {
2788
2795
  const next = /* @__PURE__ */ new Map();
2789
- const paths = [...new Set(candidates.map((c) => c.path))];
2790
- await Promise.all(paths.map(async (path) => {
2796
+ await forEachLimit([...new Set(candidates.map((c) => c.path))], ioConcurrency, async (path) => {
2791
2797
  if (reread === "all" || reread.has(path) || !fileTexts.has(path)) {
2792
2798
  const text = await host.readFile(path);
2793
2799
  if (text === void 0) fileTexts.delete(path);
2794
2800
  else fileTexts.set(path, text);
2795
2801
  }
2796
- }));
2802
+ });
2797
2803
  namespaced = config.namespace.separator !== "." && candidates.some((c) => c.namespace !== void 0);
2798
2804
  await Promise.all(candidates.map((candidate) => registry.loadFormatFor(candidate.path, candidate.format)));
2799
2805
  for (const candidate of candidates) {
@@ -2857,7 +2863,7 @@ function createProject(options) {
2857
2863
  async function scanPaths(paths) {
2858
2864
  const pending = [];
2859
2865
  const cacheKeys = /* @__PURE__ */ new Map();
2860
- await Promise.all(paths.map(async (path) => {
2866
+ await forEachLimit(paths, ioConcurrency, async (path) => {
2861
2867
  const text = await host.readFile(path);
2862
2868
  if (text === void 0) {
2863
2869
  files.delete(path);
@@ -2884,7 +2890,7 @@ function createProject(options) {
2884
2890
  text,
2885
2891
  extension: extensionOf(path)
2886
2892
  });
2887
- }));
2893
+ });
2888
2894
  const store = (file, result, error) => {
2889
2895
  files.set(file.path, {
2890
2896
  hash: hashText(file.text),
@@ -2895,7 +2901,7 @@ function createProject(options) {
2895
2901
  const cacheKey = cacheKeys.get(file.path);
2896
2902
  if (result && cacheKey && host.cache) host.cache.set(cacheKey, JSON.stringify(result));
2897
2903
  };
2898
- for (let i = 0; i < pending.length; i += scanConcurrency) await Promise.all(pending.slice(i, i + scanConcurrency).map(async (file) => {
2904
+ await forEachLimit(pending, ioConcurrency, async (file) => {
2899
2905
  try {
2900
2906
  store(file, await scanOne(file));
2901
2907
  } catch (error) {
@@ -2905,7 +2911,7 @@ function createProject(options) {
2905
2911
  cause: error
2906
2912
  }));
2907
2913
  }
2908
- }));
2914
+ });
2909
2915
  }
2910
2916
  async function scanAll() {
2911
2917
  if (registry.scanners.length === 0) return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@x18n/core",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "description": "Runtime-neutral engine of x18n: domain model, plugin API and project analysis",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",