Skip to content

Commit

Permalink
perf(source-build): remove p-map dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Jan 14, 2024
1 parent 5c5f7ec commit e673359
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 45 deletions.
3 changes: 1 addition & 2 deletions packages/monorepo-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"@types/js-yaml": "^4.0.6",
"fast-glob": "^3.3.1",
"js-yaml": "^4.1.0",
"json5": "^2.2.3",
"p-map": "^4.0.0"
"json5": "^2.2.3"
},
"devDependencies": {
"@types/node": "16.x",
Expand Down
19 changes: 6 additions & 13 deletions packages/monorepo-utils/src/common/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'path';
import { fse } from '@rsbuild/shared';
import { load } from 'js-yaml';
import glob, { type Options as GlobOptions } from 'fast-glob';
import pMap from 'p-map';
import { Project } from '../project/project';
import { PNPM_WORKSPACE_FILE, PACKAGE_JSON } from '../constants';
import { readPackageJson } from '../utils';
Expand Down Expand Up @@ -43,21 +42,18 @@ export const makeFileFinder = (rootPath: string, patterns: string[]) => {
return async <FileMapperType>(
fileName: string,
fileMapper: (filepath: string[]) => Promise<FileMapperType[]>,
customGlobOpts: GlobOptions = {},
) => {
const options = { ...customGlobOpts, ...globOpts };

let result = await glob(
patterns.map((globPath) => path.posix.join(globPath, fileName)),
options,
globOpts,
);

// fast-glob does not respect pattern order, so we re-sort by absolute path
result = result.sort();
// POSIX results always need to be normalized
result = normalize(result);

return await fileMapper(result);
return fileMapper(result);
};
};

Expand All @@ -73,14 +69,11 @@ export const readPnpmProjects = async (
manifest: pkgJson,
};
};
const projects = await finder(
PACKAGE_JSON,
(filePaths) =>
pMap(filePaths, mapper, {
concurrency: filePaths.length || Infinity,
}),
{},

const projects = await finder(PACKAGE_JSON, (filePaths) =>
Promise.all(filePaths.map(mapper)),
);

return projects;
};

Expand Down
9 changes: 2 additions & 7 deletions packages/monorepo-utils/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import path from 'path';
import { fse } from '@rsbuild/shared';
import json5 from 'json5';
import { PACKAGE_JSON, RUSH_JSON_FILE } from './constants';
import { RUSH_JSON_FILE } from './constants';
import type { INodePackageJson, IRushConfig } from './types';

export const readPackageJson = async (pkgJsonFilePath: string) => {
const packageJson = readJson<INodePackageJson>(
pkgJsonFilePath.includes(PACKAGE_JSON)
? pkgJsonFilePath
: path.join(pkgJsonFilePath, PACKAGE_JSON),
);
return packageJson;
return readJson<INodePackageJson>(pkgJsonFilePath);
};

export const readRushJson = async (rushJsonFilePath: string) => {
Expand Down
24 changes: 1 addition & 23 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e673359

Please sign in to comment.