@pnpm/workspace.projects-reader 1000.0.43

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.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2026 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @pnpm/workspace.find-packages
2
+
3
+ > Finds packages inside a workspace
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@pnpm/workspace.find-packages.svg)](https://www.npmjs.com/package/@pnpm/workspace.find-packages)
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ pnpm add @pnpm/workspace.find-packages
11
+ ```
12
+
13
+ ## License
14
+
15
+ MIT
@@ -0,0 +1,7 @@
1
+ import type { Project } from '@pnpm/types';
2
+ export interface FindPackagesOptions {
3
+ ignore?: string[];
4
+ includeRoot?: boolean;
5
+ patterns?: string[];
6
+ }
7
+ export declare function findPackages(root: string, opts?: FindPackagesOptions): Promise<Project[]>;
@@ -0,0 +1,56 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import util from 'node:util';
4
+ import { lexCompare } from '@pnpm/util.lex-comparator';
5
+ import { readExactProjectManifest } from '@pnpm/workspace.project-manifest-reader';
6
+ import pFilter from 'p-filter';
7
+ import { glob } from 'tinyglobby';
8
+ const DEFAULT_IGNORE = [
9
+ '**/node_modules/**',
10
+ '**/bower_components/**',
11
+ '**/test/**',
12
+ '**/tests/**',
13
+ ];
14
+ export async function findPackages(root, opts) {
15
+ opts = opts ?? {};
16
+ const globOpts = { ...opts, cwd: root, expandDirectories: false };
17
+ globOpts.ignore = opts.ignore ?? DEFAULT_IGNORE;
18
+ const patterns = normalizePatterns(opts.patterns ?? ['.', '**']);
19
+ delete globOpts.patterns;
20
+ const paths = await glob(patterns, globOpts);
21
+ if (opts.includeRoot) {
22
+ // Always include the workspace root (https://github.com/pnpm/pnpm/issues/1986)
23
+ paths.push(...(await glob(normalizePatterns(['.']), globOpts)));
24
+ }
25
+ return pFilter(
26
+ // `Array.from()` doesn't create an intermediate instance,
27
+ // unlike `array.map()`
28
+ Array.from(
29
+ // Remove duplicate paths using `Set`
30
+ new Set(paths
31
+ .map(manifestPath => path.join(root, manifestPath))
32
+ .sort((path1, path2) => lexCompare(path.dirname(path1), path.dirname(path2)))), async manifestPath => {
33
+ try {
34
+ const rootDir = path.dirname(manifestPath);
35
+ return {
36
+ rootDir,
37
+ rootDirRealPath: await fs.realpath(rootDir),
38
+ ...await readExactProjectManifest(manifestPath),
39
+ };
40
+ }
41
+ catch (err) {
42
+ if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
43
+ return null;
44
+ }
45
+ throw err;
46
+ }
47
+ }), Boolean);
48
+ }
49
+ function normalizePatterns(patterns) {
50
+ const normalizedPatterns = [];
51
+ for (const pattern of patterns) {
52
+ normalizedPatterns.push(pattern.replace(/\/?$/, '/package.{json,yaml,json5}'));
53
+ }
54
+ return normalizedPatterns;
55
+ }
56
+ //# sourceMappingURL=findPackages.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import type { Project, SupportedArchitectures } from '@pnpm/types';
2
+ export { findPackages, type FindPackagesOptions } from './findPackages.js';
3
+ export type { Project };
4
+ export interface FindWorkspaceProjectsOpts {
5
+ /**
6
+ * An array of globs for the packages included in the workspace.
7
+ *
8
+ * In most cases, callers should read the pnpm-workspace.yml and pass the
9
+ * "packages" field.
10
+ */
11
+ patterns?: string[];
12
+ engineStrict?: boolean;
13
+ packageManagerStrict?: boolean;
14
+ packageManagerStrictVersion?: boolean;
15
+ nodeVersion?: string;
16
+ sharedWorkspaceLockfile?: boolean;
17
+ supportedArchitectures?: SupportedArchitectures;
18
+ }
19
+ export declare function findWorkspaceProjects(workspaceRoot: string, opts?: FindWorkspaceProjectsOpts): Promise<Project[]>;
20
+ export declare function findWorkspaceProjectsNoCheck(workspaceRoot: string, opts?: {
21
+ patterns?: string[];
22
+ }): Promise<Project[]>;
package/lib/index.js ADDED
@@ -0,0 +1,51 @@
1
+ import { packageIsInstallable } from '@pnpm/cli.utils';
2
+ import { logger } from '@pnpm/logger';
3
+ import { lexCompare } from '@pnpm/util.lex-comparator';
4
+ import { findPackages } from './findPackages.js';
5
+ export { findPackages } from './findPackages.js';
6
+ export async function findWorkspaceProjects(workspaceRoot, opts) {
7
+ const projects = await findWorkspaceProjectsNoCheck(workspaceRoot, opts);
8
+ for (const project of projects) {
9
+ packageIsInstallable(project.rootDir, project.manifest, {
10
+ ...opts,
11
+ supportedArchitectures: opts?.supportedArchitectures ?? {
12
+ os: ['current'],
13
+ cpu: ['current'],
14
+ libc: ['current'],
15
+ },
16
+ });
17
+ // When setting shared-workspace-lockfile=false, `pnpm` can be set in sub-project's package.json.
18
+ if (opts?.sharedWorkspaceLockfile && project.rootDir !== workspaceRoot) {
19
+ checkNonRootProjectManifest(project);
20
+ }
21
+ }
22
+ return projects;
23
+ }
24
+ export async function findWorkspaceProjectsNoCheck(workspaceRoot, opts) {
25
+ const projects = await findPackages(workspaceRoot, {
26
+ ignore: [
27
+ '**/node_modules/**',
28
+ '**/bower_components/**',
29
+ ],
30
+ includeRoot: true,
31
+ patterns: opts?.patterns,
32
+ });
33
+ projects.sort((project1, project2) => lexCompare(project1.rootDir, project2.rootDir));
34
+ return projects;
35
+ }
36
+ const uselessNonRootManifestFields = ['resolutions'];
37
+ function checkNonRootProjectManifest({ manifest, rootDir }) {
38
+ const warn = printNonRootFieldWarning.bind(null, rootDir);
39
+ for (const field of uselessNonRootManifestFields) {
40
+ if (field in manifest) {
41
+ warn(field);
42
+ }
43
+ }
44
+ }
45
+ function printNonRootFieldWarning(prefix, propertyPath) {
46
+ logger.warn({
47
+ message: `The field "${propertyPath}" was found in ${prefix}/package.json. This will not take effect. You should configure "${propertyPath}" at the root of the workspace instead.`,
48
+ prefix,
49
+ });
50
+ }
51
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@pnpm/workspace.projects-reader",
3
+ "version": "1000.0.43",
4
+ "description": "Finds packages inside a workspace",
5
+ "keywords": [
6
+ "pnpm",
7
+ "pnpm11"
8
+ ],
9
+ "license": "MIT",
10
+ "funding": "https://opencollective.com/pnpm",
11
+ "repository": "https://github.com/pnpm/pnpm/tree/main/workspace/projects-reader",
12
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/workspace/projects-reader#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/pnpm/pnpm/issues"
15
+ },
16
+ "type": "module",
17
+ "main": "lib/index.js",
18
+ "types": "lib/index.d.ts",
19
+ "exports": {
20
+ ".": "./lib/index.js"
21
+ },
22
+ "files": [
23
+ "lib",
24
+ "!*.map"
25
+ ],
26
+ "dependencies": {
27
+ "@pnpm/util.lex-comparator": "^3.0.2",
28
+ "p-filter": "^4.1.0",
29
+ "tinyglobby": "^0.2.14",
30
+ "@pnpm/cli.utils": "1001.2.8",
31
+ "@pnpm/constants": "1001.3.1",
32
+ "@pnpm/types": "1000.9.0",
33
+ "@pnpm/workspace.project-manifest-reader": "1001.1.4"
34
+ },
35
+ "peerDependencies": {
36
+ "@pnpm/logger": ">=1001.0.0 <1002.0.0"
37
+ },
38
+ "devDependencies": {
39
+ "@jest/globals": "30.0.5",
40
+ "@pnpm/logger": "1001.0.1",
41
+ "@pnpm/workspace.projects-reader": "1000.0.43",
42
+ "@pnpm/workspace.workspace-manifest-reader": "1000.2.5"
43
+ },
44
+ "engines": {
45
+ "node": ">=22.13"
46
+ },
47
+ "jest": {
48
+ "preset": "@pnpm/jest-config"
49
+ },
50
+ "scripts": {
51
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
52
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
53
+ "test": "pnpm run compile && pnpm run _test",
54
+ "compile": "tsgo --build && pnpm run lint --fix"
55
+ }
56
+ }