UNPKG

2.22 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const read_project_manifest_1 = require("@pnpm/read-project-manifest");
4const fastGlob = require("fast-glob");
5const pFilter = require("p-filter");
6const path = require("path");
7const DEFAULT_IGNORE = [
8 '**/node_modules/**',
9 '**/bower_components/**',
10 '**/test/**',
11 '**/tests/**',
12];
13async 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 // Always include the workspace root (https://github.com/pnpm/pnpm/issues/1986)
21 Array.prototype.push.apply(paths, await fastGlob(normalizePatterns(['.']), globOpts));
22 }
23 return pFilter(
24 // `Array.from()` doesn't create an intermediate instance,
25 // unlike `array.map()`
26 Array.from(
27 // Remove duplicate paths using `Set`
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}
45exports.default = findPkgs;
46function normalizePatterns(patterns) {
47 const normalizedPatterns = [];
48 for (const pattern of patterns) {
49 // We should add separate pattern for each extension
50 // for some reason, fast-glob is buggy with /package.{json,yaml,json5} pattern
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//# sourceMappingURL=index.js.map
\No newline at end of file