1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const read_project_manifest_1 = require("@pnpm/read-project-manifest");
|
4 | const fastGlob = require("fast-glob");
|
5 | const pFilter = require("p-filter");
|
6 | const path = require("path");
|
7 | const DEFAULT_IGNORE = [
|
8 | '**/node_modules/**',
|
9 | '**/bower_components/**',
|
10 | '**/test/**',
|
11 | '**/tests/**',
|
12 | ];
|
13 | async function findPkgs(root, opts) {
|
14 | opts = opts || {};
|
15 | const globOpts = { ...opts, cwd: root, includeRoot: undefined };
|
16 | globOpts.ignore = opts.ignore || DEFAULT_IGNORE;
|
17 | const patterns = normalizePatterns(opts.patterns ? opts.patterns : ['.', '**']);
|
18 | const paths = await fastGlob(patterns, globOpts);
|
19 | if (opts.includeRoot) {
|
20 |
|
21 | Array.prototype.push.apply(paths, await fastGlob(normalizePatterns(['.']), globOpts));
|
22 | }
|
23 | return pFilter(
|
24 |
|
25 |
|
26 | Array.from(
|
27 |
|
28 | new Set(paths
|
29 | .map(manifestPath => path.join(root, manifestPath))
|
30 | .sort((path1, path2) => path.dirname(path1).localeCompare(path.dirname(path2)))), async (manifestPath) => {
|
31 | try {
|
32 | return {
|
33 | dir: path.dirname(manifestPath),
|
34 | ...await read_project_manifest_1.readExactProjectManifest(manifestPath),
|
35 | };
|
36 | }
|
37 | catch (err) {
|
38 | if (err.code === 'ENOENT') {
|
39 | return null;
|
40 | }
|
41 | throw err;
|
42 | }
|
43 | }), Boolean);
|
44 | }
|
45 | exports.default = findPkgs;
|
46 | function normalizePatterns(patterns) {
|
47 | const normalizedPatterns = [];
|
48 | for (const pattern of patterns) {
|
49 |
|
50 |
|
51 | normalizedPatterns.push(pattern.replace(/\/?$/, '/package.json'));
|
52 | normalizedPatterns.push(pattern.replace(/\/?$/, '/package.json5'));
|
53 | normalizedPatterns.push(pattern.replace(/\/?$/, '/package.yaml'));
|
54 | }
|
55 | return normalizedPatterns;
|
56 | }
|
57 |
|
\ | No newline at end of file |