@pnpm/catalogs.resolver 0.1.0
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 +22 -0
- package/README.md +3 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/matchCatalogResolveResult.d.ts +7 -0
- package/lib/matchCatalogResolveResult.js +12 -0
- package/lib/matchCatalogResolveResult.js.map +1 -0
- package/lib/resolveFromCatalog.d.ts +49 -0
- package/lib/resolveFromCatalog.js +35 -0
- package/lib/resolveFromCatalog.js.map +1 -0
- package/package.json +43 -0
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-2024 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
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { resolveFromCatalog, type CatalogResolution, type CatalogResolutionFound, type CatalogResolutionMisconfiguration, type CatalogResolutionUnused as CatalogResolutionNotUsed, type CatalogResolutionResult, type CatalogResolver, type WantedDependency, } from './resolveFromCatalog';
|
|
2
|
+
export { type CatalogResultMatcher, matchCatalogResolveResult } from './matchCatalogResolveResult';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchCatalogResolveResult = exports.resolveFromCatalog = void 0;
|
|
4
|
+
var resolveFromCatalog_1 = require("./resolveFromCatalog");
|
|
5
|
+
Object.defineProperty(exports, "resolveFromCatalog", { enumerable: true, get: function () { return resolveFromCatalog_1.resolveFromCatalog; } });
|
|
6
|
+
var matchCatalogResolveResult_1 = require("./matchCatalogResolveResult");
|
|
7
|
+
Object.defineProperty(exports, "matchCatalogResolveResult", { enumerable: true, get: function () { return matchCatalogResolveResult_1.matchCatalogResolveResult; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,2DAS6B;AAR3B,wHAAA,kBAAkB,OAAA;AASpB,yEAAkG;AAA9D,sIAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type CatalogResolutionUnused, type CatalogResolutionResult, type CatalogResolutionFound, type CatalogResolutionMisconfiguration } from './resolveFromCatalog';
|
|
2
|
+
export interface CatalogResultMatcher<T> {
|
|
3
|
+
readonly found: (found: CatalogResolutionFound) => T;
|
|
4
|
+
readonly misconfiguration: (misconfiguration: CatalogResolutionMisconfiguration) => T;
|
|
5
|
+
readonly unused: (unused: CatalogResolutionUnused) => T;
|
|
6
|
+
}
|
|
7
|
+
export declare function matchCatalogResolveResult<T>(result: CatalogResolutionResult, matcher: CatalogResultMatcher<T>): T;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.matchCatalogResolveResult = void 0;
|
|
4
|
+
function matchCatalogResolveResult(result, matcher) {
|
|
5
|
+
switch (result.type) {
|
|
6
|
+
case 'found': return matcher.found(result);
|
|
7
|
+
case 'misconfiguration': return matcher.misconfiguration(result);
|
|
8
|
+
case 'unused': return matcher.unused(result);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.matchCatalogResolveResult = matchCatalogResolveResult;
|
|
12
|
+
//# sourceMappingURL=matchCatalogResolveResult.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchCatalogResolveResult.js","sourceRoot":"","sources":["../src/matchCatalogResolveResult.ts"],"names":[],"mappings":";;;AAQA,SAAgB,yBAAyB,CACvC,MAA+B,EAC/B,OAAgC;IAEhC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,OAAO,CAAC,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC1C,KAAK,kBAAkB,CAAC,CAAC,OAAO,OAAO,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;QAChE,KAAK,QAAQ,CAAC,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC5C,CAAC;AACH,CAAC;AATD,8DASC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PnpmError } from '@pnpm/error';
|
|
2
|
+
import { type Catalogs } from '@pnpm/catalogs.types';
|
|
3
|
+
export interface WantedDependency {
|
|
4
|
+
readonly pref: string;
|
|
5
|
+
readonly alias: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Dereferences a wanted dependency using the catalog protocol and returns the
|
|
9
|
+
* configured version.
|
|
10
|
+
*
|
|
11
|
+
* Example: catalog:default -> ^1.2.3
|
|
12
|
+
*/
|
|
13
|
+
export type CatalogResolver = (wantedDependency: WantedDependency) => CatalogResolutionResult;
|
|
14
|
+
export type CatalogResolutionResult = CatalogResolutionFound | CatalogResolutionMisconfiguration | CatalogResolutionUnused;
|
|
15
|
+
export interface CatalogResolutionFound {
|
|
16
|
+
readonly type: 'found';
|
|
17
|
+
readonly resolution: CatalogResolution;
|
|
18
|
+
}
|
|
19
|
+
export interface CatalogResolution {
|
|
20
|
+
/**
|
|
21
|
+
* The name of the catalog the resolved specifier was defined in.
|
|
22
|
+
*/
|
|
23
|
+
readonly catalogName: string;
|
|
24
|
+
/**
|
|
25
|
+
* The specifier that should be used for the wanted dependency. This is a
|
|
26
|
+
* usable version that replaces the catalog protocol with the relevant user
|
|
27
|
+
* defined specifier.
|
|
28
|
+
*/
|
|
29
|
+
readonly specifier: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The user misconfigured a catalog entry. The entry could be missing or
|
|
33
|
+
* invalid.
|
|
34
|
+
*/
|
|
35
|
+
export interface CatalogResolutionMisconfiguration {
|
|
36
|
+
readonly type: 'misconfiguration';
|
|
37
|
+
/**
|
|
38
|
+
* Convenience error to rethrow.
|
|
39
|
+
*/
|
|
40
|
+
readonly error: PnpmError;
|
|
41
|
+
readonly catalogName: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The wanted dependency does not use the catalog protocol.
|
|
45
|
+
*/
|
|
46
|
+
export interface CatalogResolutionUnused {
|
|
47
|
+
readonly type: 'unused';
|
|
48
|
+
}
|
|
49
|
+
export declare function resolveFromCatalog(catalogs: Catalogs, wantedDependency: WantedDependency): CatalogResolutionResult;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveFromCatalog = void 0;
|
|
4
|
+
const error_1 = require("@pnpm/error");
|
|
5
|
+
const catalogs_protocol_parser_1 = require("@pnpm/catalogs.protocol-parser");
|
|
6
|
+
function resolveFromCatalog(catalogs, wantedDependency) {
|
|
7
|
+
const catalogName = (0, catalogs_protocol_parser_1.parseCatalogProtocol)(wantedDependency.pref);
|
|
8
|
+
if (catalogName == null) {
|
|
9
|
+
return { type: 'unused' };
|
|
10
|
+
}
|
|
11
|
+
const catalogLookup = catalogs[catalogName]?.[wantedDependency.alias];
|
|
12
|
+
if (catalogLookup == null) {
|
|
13
|
+
return {
|
|
14
|
+
type: 'misconfiguration',
|
|
15
|
+
catalogName,
|
|
16
|
+
error: new error_1.PnpmError('CATALOG_ENTRY_NOT_FOUND_FOR_SPEC', `No catalog entry '${wantedDependency.alias}' was found for catalog '${catalogName}'.`),
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if ((0, catalogs_protocol_parser_1.parseCatalogProtocol)(catalogLookup) != null) {
|
|
20
|
+
return {
|
|
21
|
+
type: 'misconfiguration',
|
|
22
|
+
catalogName,
|
|
23
|
+
error: new error_1.PnpmError('CATALOG_ENTRY_INVALID_RECURSIVE_DEFINITION', `Found invalid catalog entry using the catalog protocol recursively. The entry for '${wantedDependency.alias}' in catalog '${catalogName}' is invalid.`),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
type: 'found',
|
|
28
|
+
resolution: {
|
|
29
|
+
catalogName,
|
|
30
|
+
specifier: catalogLookup,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
exports.resolveFromCatalog = resolveFromCatalog;
|
|
35
|
+
//# sourceMappingURL=resolveFromCatalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveFromCatalog.js","sourceRoot":"","sources":["../src/resolveFromCatalog.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AACvC,6EAAqE;AA0DrE,SAAgB,kBAAkB,CAAE,QAAkB,EAAE,gBAAkC;IACxF,MAAM,WAAW,GAAG,IAAA,+CAAoB,EAAC,gBAAgB,CAAC,IAAI,CAAC,CAAA;IAE/D,IAAI,WAAW,IAAI,IAAI,EAAE,CAAC;QACxB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;IAC3B,CAAC;IAED,MAAM,aAAa,GAAG,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;IACrE,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;QAC1B,OAAO;YACL,IAAI,EAAE,kBAAkB;YACxB,WAAW;YACX,KAAK,EAAE,IAAI,iBAAS,CAClB,kCAAkC,EAClC,qBAAqB,gBAAgB,CAAC,KAAK,4BAA4B,WAAW,IAAI,CAAC;SAC1F,CAAA;IACH,CAAC;IAED,IAAI,IAAA,+CAAoB,EAAC,aAAa,CAAC,IAAI,IAAI,EAAE,CAAC;QAChD,OAAO;YACL,IAAI,EAAE,kBAAkB;YACxB,WAAW;YACX,KAAK,EAAE,IAAI,iBAAS,CAClB,4CAA4C,EAC5C,sFAAsF,gBAAgB,CAAC,KAAK,iBAAiB,WAAW,eAAe,CAAC;SAC3J,CAAA;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,OAAO;QACb,UAAU,EAAE;YACV,WAAW;YACX,SAAS,EAAE,aAAa;SACzB;KACF,CAAA;AACH,CAAC;AAnCD,gDAmCC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pnpm/catalogs.resolver",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Dereferences catalog protocol specifiers into usable specifiers.",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=18.12"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"lib",
|
|
12
|
+
"!*.map"
|
|
13
|
+
],
|
|
14
|
+
"repository": "https://github.com/pnpm/pnpm/blob/main/catalogs/resolver",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"pnpm9",
|
|
17
|
+
"pnpm",
|
|
18
|
+
"types"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/pnpm/pnpm/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/pnpm/pnpm/blob/main/catalogs/resolver#readme",
|
|
25
|
+
"funding": "https://opencollective.com/pnpm",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": "./lib/index.js"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@pnpm/catalogs.protocol-parser": "^0.1.0",
|
|
31
|
+
"@pnpm/error": "^6.0.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@pnpm/catalogs.resolver": "0.1.0",
|
|
35
|
+
"@pnpm/catalogs.types": "0.1.0"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
39
|
+
"compile": "tsc --build && pnpm run lint --fix",
|
|
40
|
+
"test": "pnpm run compile && pnpm run _test",
|
|
41
|
+
"_test": "jest"
|
|
42
|
+
}
|
|
43
|
+
}
|