@pnpm/workspace.workspace-manifest-reader 1000.2.5

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,13 @@
1
+ # @pnpm/workspace.workspace-manifest-reader
2
+
3
+ > Reads a workspace manifest file
4
+
5
+ ## Install
6
+
7
+ ```
8
+ pnpm add @pnpm/workspace.workspace-manifest-reader
9
+ ```
10
+
11
+ ## LICENSE
12
+
13
+ MIT
@@ -0,0 +1,18 @@
1
+ export interface WorkspaceNamedCatalogs {
2
+ [catalogName: string]: WorkspaceCatalog;
3
+ }
4
+ export interface WorkspaceCatalog {
5
+ [dependencyName: string]: string;
6
+ }
7
+ export declare function assertValidWorkspaceManifestCatalog(manifest: {
8
+ packages?: readonly string[];
9
+ catalog?: unknown;
10
+ }): asserts manifest is {
11
+ catalog?: WorkspaceCatalog;
12
+ };
13
+ export declare function assertValidWorkspaceManifestCatalogs(manifest: {
14
+ packages?: readonly string[];
15
+ catalogs?: unknown;
16
+ }): asserts manifest is {
17
+ catalogs?: WorkspaceNamedCatalogs;
18
+ };
@@ -0,0 +1,42 @@
1
+ import { InvalidWorkspaceManifestError } from './errors/InvalidWorkspaceManifestError.js';
2
+ export function assertValidWorkspaceManifestCatalog(manifest) {
3
+ if (manifest.catalog == null) {
4
+ return;
5
+ }
6
+ if (Array.isArray(manifest.catalog)) {
7
+ throw new InvalidWorkspaceManifestError('Expected catalog field to be an object, but found - array');
8
+ }
9
+ if (typeof manifest.catalog !== 'object') {
10
+ throw new InvalidWorkspaceManifestError(`Expected catalog field to be an object, but found - ${typeof manifest.catalog}`);
11
+ }
12
+ for (const [alias, specifier] of Object.entries(manifest.catalog)) {
13
+ if (typeof specifier !== 'string') {
14
+ throw new InvalidWorkspaceManifestError(`Invalid catalog entry for ${alias}. Expected string, but found: ${typeof specifier}`);
15
+ }
16
+ }
17
+ }
18
+ export function assertValidWorkspaceManifestCatalogs(manifest) {
19
+ if (manifest.catalogs == null) {
20
+ return;
21
+ }
22
+ if (Array.isArray(manifest.catalogs)) {
23
+ throw new InvalidWorkspaceManifestError('Expected catalogs field to be an object, but found - array');
24
+ }
25
+ if (typeof manifest.catalogs !== 'object') {
26
+ throw new InvalidWorkspaceManifestError(`Expected catalogs field to be an object, but found - ${typeof manifest.catalogs}`);
27
+ }
28
+ for (const [catalogName, catalog] of Object.entries(manifest.catalogs)) {
29
+ if (Array.isArray(catalog)) {
30
+ throw new InvalidWorkspaceManifestError(`Expected named catalog ${catalogName} to be an object, but found - array`);
31
+ }
32
+ if (typeof catalog !== 'object') {
33
+ throw new InvalidWorkspaceManifestError(`Expected named catalog ${catalogName} to be an object, but found - ${typeof catalog}`);
34
+ }
35
+ for (const [alias, specifier] of Object.entries(catalog)) {
36
+ if (typeof specifier !== 'string') {
37
+ throw new InvalidWorkspaceManifestError(`Catalog '${catalogName}' has invalid entry '${alias}'. Expected string specifier, but found: ${typeof specifier}`);
38
+ }
39
+ }
40
+ }
41
+ }
42
+ //# sourceMappingURL=catalogs.js.map
@@ -0,0 +1,4 @@
1
+ import { PnpmError } from '@pnpm/error';
2
+ export declare class InvalidWorkspaceManifestError extends PnpmError {
3
+ constructor(message: string);
4
+ }
@@ -0,0 +1,7 @@
1
+ import { PnpmError } from '@pnpm/error';
2
+ export class InvalidWorkspaceManifestError extends PnpmError {
3
+ constructor(message) {
4
+ super('INVALID_WORKSPACE_CONFIGURATION', message);
5
+ }
6
+ }
7
+ //# sourceMappingURL=InvalidWorkspaceManifestError.js.map
package/lib/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { type GLOBAL_CONFIG_YAML_FILENAME, WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants';
2
+ import type { PnpmSettings } from '@pnpm/types';
3
+ import { type WorkspaceCatalog, type WorkspaceNamedCatalogs } from './catalogs.js';
4
+ export type ConfigFileName = typeof GLOBAL_CONFIG_YAML_FILENAME | typeof WORKSPACE_MANIFEST_FILENAME;
5
+ export interface WorkspaceManifest extends PnpmSettings {
6
+ packages: string[];
7
+ /**
8
+ * The default catalog. Package manifests may refer to dependencies in this
9
+ * definition through the `catalog:default` specifier or the `catalog:`
10
+ * shorthand.
11
+ */
12
+ catalog?: WorkspaceCatalog;
13
+ /**
14
+ * A dictionary of named catalogs. Package manifests may refer to dependencies
15
+ * in this definition through the `catalog:<name>` specifier.
16
+ */
17
+ catalogs?: WorkspaceNamedCatalogs;
18
+ }
19
+ export declare function readWorkspaceManifest(dir: string, cfgFileName?: ConfigFileName): Promise<WorkspaceManifest | undefined>;
20
+ export declare function validateWorkspaceManifest(manifest: unknown): asserts manifest is WorkspaceManifest | undefined;
package/lib/index.js ADDED
@@ -0,0 +1,69 @@
1
+ import path from 'node:path';
2
+ import util from 'node:util';
3
+ import { WORKSPACE_MANIFEST_FILENAME } from '@pnpm/constants';
4
+ import { readYamlFile } from 'read-yaml-file';
5
+ import { assertValidWorkspaceManifestCatalog, assertValidWorkspaceManifestCatalogs, } from './catalogs.js';
6
+ import { InvalidWorkspaceManifestError } from './errors/InvalidWorkspaceManifestError.js';
7
+ export async function readWorkspaceManifest(dir, cfgFileName = WORKSPACE_MANIFEST_FILENAME) {
8
+ const manifest = await readManifestRaw(dir, cfgFileName);
9
+ validateWorkspaceManifest(manifest);
10
+ return manifest;
11
+ }
12
+ async function readManifestRaw(dir, cfgFileName) {
13
+ try {
14
+ return await readYamlFile(path.join(dir, cfgFileName));
15
+ }
16
+ catch (err) {
17
+ // File not exists is the same as empty file (undefined)
18
+ if (util.types.isNativeError(err) && 'code' in err && err.code === 'ENOENT') {
19
+ return undefined;
20
+ }
21
+ // Any other error (missing perm, invalid yaml, etc.) fails the process
22
+ throw err;
23
+ }
24
+ }
25
+ export function validateWorkspaceManifest(manifest) {
26
+ if (manifest === undefined || manifest === null) {
27
+ // Empty or null manifest is ok
28
+ return;
29
+ }
30
+ if (typeof manifest !== 'object') {
31
+ throw new InvalidWorkspaceManifestError(`Expected object but found - ${typeof manifest}`);
32
+ }
33
+ if (Array.isArray(manifest)) {
34
+ throw new InvalidWorkspaceManifestError('Expected object but found - array');
35
+ }
36
+ if (Object.keys(manifest).length === 0) {
37
+ // manifest content `{}` is ok
38
+ return;
39
+ }
40
+ assertValidWorkspaceManifestPackages(manifest);
41
+ assertValidWorkspaceManifestCatalog(manifest);
42
+ assertValidWorkspaceManifestCatalogs(manifest);
43
+ checkWorkspaceManifestAssignability(manifest);
44
+ }
45
+ function assertValidWorkspaceManifestPackages(manifest) {
46
+ if (!manifest.packages) {
47
+ return;
48
+ }
49
+ if (!Array.isArray(manifest.packages)) {
50
+ throw new InvalidWorkspaceManifestError('packages field is not an array');
51
+ }
52
+ for (const pkg of manifest.packages) {
53
+ if (!pkg) {
54
+ throw new InvalidWorkspaceManifestError('Missing or empty package');
55
+ }
56
+ const type = typeof pkg;
57
+ if (type !== 'string') {
58
+ throw new InvalidWorkspaceManifestError(`Invalid package type - ${type}`);
59
+ }
60
+ }
61
+ }
62
+ /**
63
+ * Empty function to ensure TypeScript has narrowed the manifest object to
64
+ * something assignable to the {@see WorkspaceManifest} interface. This helps
65
+ * make sure the validation logic in this file is correct as it's refactored in
66
+ * the future.
67
+ */
68
+ function checkWorkspaceManifestAssignability(_manifest) { }
69
+ //# sourceMappingURL=index.js.map
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@pnpm/workspace.workspace-manifest-reader",
3
+ "version": "1000.2.5",
4
+ "description": "Reads a workspace manifest file",
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/workspace-manifest-reader",
12
+ "homepage": "https://github.com/pnpm/pnpm/tree/main/workspace/workspace-manifest-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
+ "read-yaml-file": "^3.0.0",
28
+ "@pnpm/constants": "1001.3.1",
29
+ "@pnpm/error": "1000.0.5",
30
+ "@pnpm/types": "1000.9.0"
31
+ },
32
+ "devDependencies": {
33
+ "@pnpm/workspace.workspace-manifest-reader": "1000.2.5"
34
+ },
35
+ "engines": {
36
+ "node": ">=22.13"
37
+ },
38
+ "jest": {
39
+ "preset": "@pnpm/jest-config"
40
+ },
41
+ "scripts": {
42
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
43
+ "_test": "cross-env NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules --disable-warning=ExperimentalWarning --disable-warning=DEP0169\" jest",
44
+ "test": "pnpm run compile && pnpm run _test",
45
+ "compile": "tsgo --build && pnpm run lint --fix"
46
+ }
47
+ }