@budsbox/constraints 1.0.2
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/README.md +1 -0
- package/dist/base.d.ts +10 -0
- package/dist/base.d.ts.map +1 -0
- package/dist/base.js +50 -0
- package/dist/dependencies/index.d.ts +4 -0
- package/dist/dependencies/index.d.ts.map +1 -0
- package/dist/dependencies/index.js +9 -0
- package/dist/dependencies/peer.d.ts +3 -0
- package/dist/dependencies/peer.d.ts.map +1 -0
- package/dist/dependencies/peer.js +78 -0
- package/dist/dependencies/root.d.ts +8 -0
- package/dist/dependencies/root.d.ts.map +1 -0
- package/dist/dependencies/root.js +37 -0
- package/dist/dependencies/workspace.d.ts +5 -0
- package/dist/dependencies/workspace.d.ts.map +1 -0
- package/dist/dependencies/workspace.js +29 -0
- package/dist/esm.d.ts +4 -0
- package/dist/esm.d.ts.map +1 -0
- package/dist/esm.js +21 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +36 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @budsbox/constraints
|
package/dist/base.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ConstraintFabric } from './utils';
|
|
2
|
+
import { type Constraint } from './utils';
|
|
3
|
+
export declare const constraintPackageName: Constraint;
|
|
4
|
+
export declare const createManifestFieldsConstraint: ConstraintFabric<[
|
|
5
|
+
{
|
|
6
|
+
readonly sharedFields: readonly string[];
|
|
7
|
+
requiredFields?: ReadonlyArray<string | [string, unknown]>;
|
|
8
|
+
}
|
|
9
|
+
]>;
|
|
10
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAiC,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,KAAK,UAAU,EAAa,MAAM,SAAS,CAAC;AAErD,eAAO,MAAM,qBAAqB,EAAE,UAwBnC,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,gBAAgB,CAC3D;IACE;QACE,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;QACzC,cAAc,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;KAC5D;CACF,CAqBA,CAAC"}
|
package/dist/base.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createManifestFieldsConstraint = exports.constraintPackageName = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const utils_2 = require("./utils");
|
|
6
|
+
const constraintPackageName = ({ Yarn }) => {
|
|
7
|
+
const root = (0, utils_2.getRootWs)(Yarn);
|
|
8
|
+
const rootIdent = root.ident;
|
|
9
|
+
if (rootIdent == null) {
|
|
10
|
+
root.error('Missing field "name" in the root\'s package.json');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { ns } = (0, utils_1.parsePackageName)(rootIdent);
|
|
14
|
+
if (ns != null) {
|
|
15
|
+
for (const workspace of Yarn.workspaces()) {
|
|
16
|
+
const { ident } = workspace;
|
|
17
|
+
if (ident == null) {
|
|
18
|
+
workspace.error(`The workspace "${workspace.cwd}" has no package name`);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const parsedIdent = (0, utils_1.parsePackageName)(ident);
|
|
22
|
+
if (parsedIdent.ns == null) {
|
|
23
|
+
workspace.set('name', `${ns}${ident}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.constraintPackageName = constraintPackageName;
|
|
30
|
+
const createManifestFieldsConstraint = ({ sharedFields, requiredFields }) => function constraintManifestFields({ Yarn }) {
|
|
31
|
+
const rootManifest = (0, utils_1.getManifest)((0, utils_2.getRootWs)(Yarn));
|
|
32
|
+
for (const workspace of Yarn.workspaces()) {
|
|
33
|
+
for (const field of sharedFields) {
|
|
34
|
+
workspace.set(field, rootManifest[field]);
|
|
35
|
+
}
|
|
36
|
+
for (const field of [['type', 'module'], ...(requiredFields ?? [])]) {
|
|
37
|
+
const [key, value] = Array.isArray(field) ? field : [field, null];
|
|
38
|
+
const manifest = (0, utils_1.getManifest)(workspace);
|
|
39
|
+
if (!Object.hasOwn(manifest, key)) {
|
|
40
|
+
if (value != null) {
|
|
41
|
+
workspace.set(key, value);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
workspace.error(`Missing field ${key} in package.json`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.createManifestFieldsConstraint = createManifestFieldsConstraint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dependencies/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EAAE,qCAAqC,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkspaceDependenciesConstraint = exports.constraintPeerDependencies = exports.constraintRootDependencies = void 0;
|
|
4
|
+
var root_js_1 = require("./root.js");
|
|
5
|
+
Object.defineProperty(exports, "constraintRootDependencies", { enumerable: true, get: function () { return root_js_1.constraintRootDependencies; } });
|
|
6
|
+
var peer_js_1 = require("./peer.js");
|
|
7
|
+
Object.defineProperty(exports, "constraintPeerDependencies", { enumerable: true, get: function () { return peer_js_1.constraintPeerDependencies; } });
|
|
8
|
+
var workspace_js_1 = require("./workspace.js");
|
|
9
|
+
Object.defineProperty(exports, "createWorkspaceDependenciesConstraint", { enumerable: true, get: function () { return workspace_js_1.createWorkspaceDependenciesConstraint; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"peer.d.ts","sourceRoot":"","sources":["../../src/dependencies/peer.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,UAAU,EAGhB,MAAM,UAAU,CAAC;AAElB,eAAO,MAAM,0BAA0B,EAAE,UAyFxC,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constraintPeerDependencies = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const constraintPeerDependencies = ({ Yarn }) => {
|
|
6
|
+
for (const workspace of Yarn.workspaces()) {
|
|
7
|
+
const isPrivate = (0, utils_1.getManifest)(workspace).private === true;
|
|
8
|
+
for (const peerDependency of Yarn.dependencies({
|
|
9
|
+
workspace,
|
|
10
|
+
type: 'peerDependencies',
|
|
11
|
+
})) {
|
|
12
|
+
if (isPrivate) {
|
|
13
|
+
// private packages should have no peer dependencies
|
|
14
|
+
peerDependency.delete();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const query = { workspace, ident: peerDependency.ident };
|
|
18
|
+
// the same dependency both in "dependencies" and "peerDependencies" probably is a bug
|
|
19
|
+
Yarn.dependency({ ...query, type: 'dependencies' })?.delete();
|
|
20
|
+
if (Yarn.workspace({ ident: peerDependency.ident }) != null) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
// a code below needed to properly update peer dependencies
|
|
24
|
+
const devDependency = Yarn.dependency({
|
|
25
|
+
...query,
|
|
26
|
+
type: 'devDependencies',
|
|
27
|
+
});
|
|
28
|
+
if (workspace.ident === '@budsbox/linting' &&
|
|
29
|
+
peerDependency.ident === 'eslint-import-resolver-typescript') {
|
|
30
|
+
// console.log(peerDependency, devDependency);
|
|
31
|
+
}
|
|
32
|
+
if (devDependency == null) {
|
|
33
|
+
workspace.set(['devDependencies', peerDependency.ident], (0, utils_1.getRangeConsideringRoot)(Yarn, peerDependency));
|
|
34
|
+
}
|
|
35
|
+
else if (peerDependency.range !== devDependency.range) {
|
|
36
|
+
peerDependency.update((0, utils_1.getRangeConsideringRoot)(Yarn, devDependency));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Map<<workspace name>, <workspace peer dependencies without optional>>
|
|
42
|
+
const peersMap = new Map(Yarn.workspaces().flatMap((workspace) => {
|
|
43
|
+
const { peerDependenciesMeta = {} } = (0, utils_1.getManifest)(workspace);
|
|
44
|
+
return workspace.ident != null ?
|
|
45
|
+
[
|
|
46
|
+
[
|
|
47
|
+
workspace.ident,
|
|
48
|
+
Yarn.dependencies({ workspace, type: 'peerDependencies' }).filter(({ ident }) => peerDependenciesMeta[ident]?.optional !== true),
|
|
49
|
+
],
|
|
50
|
+
]
|
|
51
|
+
: [];
|
|
52
|
+
}));
|
|
53
|
+
// Ensures that peerDependencies of workspaces are met in dependent workspaces
|
|
54
|
+
for (const workspace of Yarn.workspaces()) {
|
|
55
|
+
for (const [ident, peers] of peersMap) {
|
|
56
|
+
if (peers.length === 0) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
const wsDependency = Yarn.dependency({ workspace, ident });
|
|
60
|
+
if (wsDependency != null) {
|
|
61
|
+
for (const peer of peers) {
|
|
62
|
+
const peerInWs = Yarn.dependency({
|
|
63
|
+
workspace,
|
|
64
|
+
ident: peer.ident,
|
|
65
|
+
});
|
|
66
|
+
const range = (0, utils_1.getRangeConsideringRoot)(Yarn, peer);
|
|
67
|
+
if (peerInWs != null) {
|
|
68
|
+
peerInWs.update(range);
|
|
69
|
+
}
|
|
70
|
+
else if (peer.ident !== workspace.ident) {
|
|
71
|
+
workspace.set([wsDependency.type, peer.ident], range);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.constraintPeerDependencies = constraintPeerDependencies;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Constraint } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* This function ensures that packages that more than one workspace depends on are added to the root workspace dependencies.
|
|
4
|
+
*
|
|
5
|
+
* @param Yarn
|
|
6
|
+
*/
|
|
7
|
+
export declare const constraintRootDependencies: Constraint;
|
|
8
|
+
//# sourceMappingURL=root.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"root.d.ts","sourceRoot":"","sources":["../../src/dependencies/root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAa,MAAM,UAAU,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,UAuCxC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constraintRootDependencies = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
/**
|
|
6
|
+
* This function ensures that packages that more than one workspace depends on are added to the root workspace dependencies.
|
|
7
|
+
*
|
|
8
|
+
* @param Yarn
|
|
9
|
+
*/
|
|
10
|
+
const constraintRootDependencies = ({ Yarn }) => {
|
|
11
|
+
const root = (0, utils_1.getRootWs)(Yarn);
|
|
12
|
+
const dependencyRecords = Yarn.workspaces()
|
|
13
|
+
.filter((ws) => ws !== root)
|
|
14
|
+
.reduce((acc, workspace) => ({
|
|
15
|
+
...acc,
|
|
16
|
+
...Yarn.dependencies({ workspace }).reduce((depAcc, { ident, range }) => (Yarn.dependency({ workspace: root, ident }) == null &&
|
|
17
|
+
Yarn.workspace({ ident }) == null) ?
|
|
18
|
+
{
|
|
19
|
+
...depAcc,
|
|
20
|
+
[ident]: [...(depAcc[ident] ?? []), range],
|
|
21
|
+
}
|
|
22
|
+
: depAcc, {}),
|
|
23
|
+
}), {});
|
|
24
|
+
for (const [ident, ranges] of Object.entries(dependencyRecords)) {
|
|
25
|
+
if (ranges.length > 1) {
|
|
26
|
+
const rangeSet = new Set(ranges);
|
|
27
|
+
if (rangeSet.size > 1) {
|
|
28
|
+
root.error(`More than one workspaces has dependency "${ident}" with following ranges: "${[...rangeSet].join('", "')}".
|
|
29
|
+
Please add this dependency to the root workspace manually`);
|
|
30
|
+
}
|
|
31
|
+
else if (Yarn.dependency({ workspace: root, ident }) == null) {
|
|
32
|
+
root.set(['dependencies', ident], rangeSet.values().next().value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.constraintRootDependencies = constraintRootDependencies;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workspace.d.ts","sourceRoot":"","sources":["../../src/dependencies/workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAa,MAAM,UAAU,CAAC;AAEtD,eAAO,MAAM,qCAAqC,6BAE/C;IACD,QAAQ,CAAC,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACjD,KAAQ,UAwBN,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkspaceDependenciesConstraint = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const createWorkspaceDependenciesConstraint = ({ bannedDependencies, } = {}) => function constraintWorkspaceDependencies({ Yarn }) {
|
|
6
|
+
const root = (0, utils_1.getRootWs)(Yarn);
|
|
7
|
+
const workspaces = Yarn.workspaces();
|
|
8
|
+
for (const workspace of workspaces) {
|
|
9
|
+
if (workspace !== root) {
|
|
10
|
+
for (const { ident, range } of Yarn.dependencies({ workspace: root })) {
|
|
11
|
+
Yarn.dependency({ workspace, ident })?.update(range);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const banned = new Set([
|
|
15
|
+
root.ident,
|
|
16
|
+
workspace.ident,
|
|
17
|
+
...(bannedDependencies ?? []),
|
|
18
|
+
]);
|
|
19
|
+
for (const dep of Yarn.dependencies({ workspace })) {
|
|
20
|
+
if (banned.has(dep.ident)) {
|
|
21
|
+
dep.delete();
|
|
22
|
+
}
|
|
23
|
+
else if (Yarn.workspace({ ident: dep.ident }) != null) {
|
|
24
|
+
dep.update('workspace:^');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.createWorkspaceDependenciesConstraint = createWorkspaceDependenciesConstraint;
|
package/dist/esm.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esm.d.ts","sourceRoot":"","sources":["../src/esm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,eAAO,MAAM,iBAAiB,EAAE,UAI/B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,UAe/B,CAAC"}
|
package/dist/esm.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.constraintImports = exports.constraintExports = void 0;
|
|
4
|
+
const constraintExports = ({ Yarn }) => {
|
|
5
|
+
for (const workspace of Yarn.workspaces()) {
|
|
6
|
+
workspace.set(['exports', './package.json'], './package.json');
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
exports.constraintExports = constraintExports;
|
|
10
|
+
const constraintImports = ({ Yarn }) => {
|
|
11
|
+
for (const workspace of Yarn.workspaces()) {
|
|
12
|
+
const { exports } = workspace.manifest;
|
|
13
|
+
if (exports != null) {
|
|
14
|
+
for (const [exportName, value] of Object.entries(exports)) {
|
|
15
|
+
const importName = exportName === '.' ? '#@' : exportName.replace('./', '#');
|
|
16
|
+
workspace.set(['imports', importName], value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
exports.constraintImports = constraintImports;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Constraint, ConstraintOptions } from './utils.js';
|
|
2
|
+
export declare function runConstraintsSequence(options: ConstraintOptions, ...constraints: readonly Constraint[]): Promise<void>;
|
|
3
|
+
export { constraintPackageName, createManifestFieldsConstraint, } from './base.js';
|
|
4
|
+
export { constraintExports, constraintImports } from './esm.js';
|
|
5
|
+
export { constraintRootDependencies, constraintPeerDependencies, createWorkspaceDependenciesConstraint, } from './dependencies/index.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEhE,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,iBAAiB,EAC1B,GAAG,WAAW,EAAE,SAAS,UAAU,EAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAIf;AAED,OAAO,EACL,qBAAqB,EACrB,8BAA8B,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,qCAAqC,GACtC,MAAM,yBAAyB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createWorkspaceDependenciesConstraint = exports.constraintPeerDependencies = exports.constraintRootDependencies = exports.constraintImports = exports.constraintExports = exports.createManifestFieldsConstraint = exports.constraintPackageName = void 0;
|
|
4
|
+
exports.runConstraintsSequence = runConstraintsSequence;
|
|
5
|
+
async function runConstraintsSequence(options, ...constraints) {
|
|
6
|
+
for (const constraint of constraints) {
|
|
7
|
+
await constraint(options);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var base_js_1 = require("./base.js");
|
|
11
|
+
Object.defineProperty(exports, "constraintPackageName", { enumerable: true, get: function () { return base_js_1.constraintPackageName; } });
|
|
12
|
+
Object.defineProperty(exports, "createManifestFieldsConstraint", { enumerable: true, get: function () { return base_js_1.createManifestFieldsConstraint; } });
|
|
13
|
+
var esm_js_1 = require("./esm.js");
|
|
14
|
+
Object.defineProperty(exports, "constraintExports", { enumerable: true, get: function () { return esm_js_1.constraintExports; } });
|
|
15
|
+
Object.defineProperty(exports, "constraintImports", { enumerable: true, get: function () { return esm_js_1.constraintImports; } });
|
|
16
|
+
var index_js_1 = require("./dependencies/index.js");
|
|
17
|
+
Object.defineProperty(exports, "constraintRootDependencies", { enumerable: true, get: function () { return index_js_1.constraintRootDependencies; } });
|
|
18
|
+
Object.defineProperty(exports, "constraintPeerDependencies", { enumerable: true, get: function () { return index_js_1.constraintPeerDependencies; } });
|
|
19
|
+
Object.defineProperty(exports, "createWorkspaceDependenciesConstraint", { enumerable: true, get: function () { return index_js_1.createWorkspaceDependenciesConstraint; } });
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AsyncV } from '@budsbox/types';
|
|
2
|
+
import type { Yarn } from '@yarnpkg/types';
|
|
3
|
+
export interface ConstraintOptions {
|
|
4
|
+
readonly Yarn: Yarn.Constraints.Yarn;
|
|
5
|
+
}
|
|
6
|
+
export type Constraint = (options: ConstraintOptions) => AsyncV<void>;
|
|
7
|
+
export type ConstraintFabric<T extends readonly unknown[]> = (...args: T) => Constraint;
|
|
8
|
+
export declare function getRootWs(yarn: Yarn.Constraints.Yarn): Yarn.Constraints.Workspace;
|
|
9
|
+
export declare function getManifest<T extends object = Record<string, unknown>>(workspace: Yarn.Constraints.Workspace): T;
|
|
10
|
+
export declare function getRangeConsideringRoot(yarn: Yarn.Constraints.Yarn, dependency: Yarn.Constraints.Dependency): string;
|
|
11
|
+
export declare function parsePackageName(packageName: string): {
|
|
12
|
+
ns: `@${string}/` | null;
|
|
13
|
+
name: string;
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;CACtC;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,EAAE,iBAAiB,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC;AAEtE,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,SAAS,OAAO,EAAE,IAAI,CAC3D,GAAG,IAAI,EAAE,CAAC,KACP,UAAU,CAAC;AAEhB,wBAAgB,SAAS,CACvB,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,GAC1B,IAAI,CAAC,WAAW,CAAC,SAAS,CAQ5B;AACD,wBAAgB,WAAW,CAEzB,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1C,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,SAAS,GAAG,CAAC,CAO1C;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAC3B,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,UAAU,GACtC,MAAM,CAOR;AAED,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG;IACrD,EAAE,EAAE,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,CAQA"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRootWs = getRootWs;
|
|
4
|
+
exports.getManifest = getManifest;
|
|
5
|
+
exports.getRangeConsideringRoot = getRangeConsideringRoot;
|
|
6
|
+
exports.parsePackageName = parsePackageName;
|
|
7
|
+
function getRootWs(yarn) {
|
|
8
|
+
const [root] = yarn.workspaces({ cwd: '.' });
|
|
9
|
+
if (root == null) {
|
|
10
|
+
throw new Error('Failed to get root workspace');
|
|
11
|
+
}
|
|
12
|
+
return root;
|
|
13
|
+
}
|
|
14
|
+
function getManifest(workspace) {
|
|
15
|
+
if (workspace.manifest == null) {
|
|
16
|
+
throw new Error(`Workspace manifest is ${String(workspace.manifest)}`);
|
|
17
|
+
}
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
19
|
+
return workspace.manifest;
|
|
20
|
+
}
|
|
21
|
+
function getRangeConsideringRoot(yarn, dependency) {
|
|
22
|
+
const rootDep = yarn.dependency({
|
|
23
|
+
workspace: getRootWs(yarn),
|
|
24
|
+
ident: dependency.ident,
|
|
25
|
+
});
|
|
26
|
+
return rootDep == null ? dependency.range : rootDep.range;
|
|
27
|
+
}
|
|
28
|
+
function parsePackageName(packageName) {
|
|
29
|
+
const [ns] = /^@[^/]+\//.exec(packageName) ?? [
|
|
30
|
+
null,
|
|
31
|
+
];
|
|
32
|
+
return {
|
|
33
|
+
ns,
|
|
34
|
+
name: packageName.replace(ns ?? '', ''),
|
|
35
|
+
};
|
|
36
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@budsbox/constraints",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"homepage": "https://gitlab.com/budsbox/fe/seed",
|
|
5
|
+
"bugs": {
|
|
6
|
+
"url": "https://gitlab.com/budsbox/fe/seed/-/issues"
|
|
7
|
+
},
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Konstantin Kutsyllo <trikadin@pm.me>",
|
|
10
|
+
"type": "commonjs",
|
|
11
|
+
"imports": {
|
|
12
|
+
"#package.json": "./package.json",
|
|
13
|
+
"#@": {
|
|
14
|
+
"require": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
"./package.json": "./package.json",
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"prepack": "yarn p:ts:prepack"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@budsbox/iso-utils": "^1.0.2",
|
|
35
|
+
"@yarnpkg/types": "^4.0.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@budsbox/linting": "^1.0.2",
|
|
39
|
+
"@budsbox/tsconfigs": "^2.0.2",
|
|
40
|
+
"@budsbox/types": "^1.0.2",
|
|
41
|
+
"@eslint/js": "^9.9.1",
|
|
42
|
+
"@types/node": "^20.16.2",
|
|
43
|
+
"@typescript-eslint/parser": "^8.3.0",
|
|
44
|
+
"eslint": "^8.57.0",
|
|
45
|
+
"eslint-import-resolver-typescript": "^3.6.3",
|
|
46
|
+
"eslint-plugin-jsdoc": "^50.2.2",
|
|
47
|
+
"eslint-plugin-react": "^7.35.0",
|
|
48
|
+
"eslint-plugin-react-hooks": "^4.6.2",
|
|
49
|
+
"eslint-plugin-react-refresh": "^0.4.11",
|
|
50
|
+
"globals": "^15.9.0",
|
|
51
|
+
"tslib": "^2.7.0",
|
|
52
|
+
"typescript": "^5.5.4",
|
|
53
|
+
"typescript-eslint": "^8.3.0"
|
|
54
|
+
},
|
|
55
|
+
"packageManager": "yarn@4.4.0"
|
|
56
|
+
}
|