globsync 로 파일 시스템에서 동적 import 를 Promise all 로 받는 과정

// 파일 1
import { globSync } from 'node:fs';
import { fileURLToPath } from 'node:url';

export function getWorkspacePJSONs(path = './workspaces/*/package.json') {
  return Promise.all(
    globSync(
        fileURLToPath(import.meta.resolve(path))
    ).map(path => import(path, { with: { type: 'json' } }))
  );
}

//파일 2
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { getWorkspacePJSONs } from './getWorkspacePJSONs.mjs';
const requiredKeywords = ['node.js', 'sliced bread'];
test('Check package.jsons', { concurrency: true }, async t => {
  const pjsons = await getWorkspacePJSONs();
  const cases = pjsons.map(pjson =>
    // ⚠️ `t.test`, NOT `test`
    t.test(`Ensure fields are properly set: ${pjson.name}`, () => {
      assert.partialDeepStrictEqual(pjson.keywords, requiredKeywords);
    })
  );
  // Allow the cases to run concurrently.
  await Promise.allSettled(cases);
});

설명

globSync
↓
파일 경로 배열 반환

[
  'api/package.json',
  'web/package.json',
  'mobile/package.json'
]

↓ map

[
  import('api/package.json'),
  import('web/package.json'),
  import('mobile/package.json')
]

↓

[
  Promise,
  Promise,
  Promise
]

↓ Promise.all

[
  apiJson,
  webJson,
  mobileJson
]