@rsdk/yarn.constraints 4.0.0-next.10

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/CHANGELOG.md ADDED
@@ -0,0 +1,26 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## [4.0.0-next.10](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.9...v4.0.0-next.10) (2023-11-29)
7
+
8
+ **Note:** Version bump only for package @rsdk/yarn.constraints
9
+
10
+ ## [4.0.0-next.9](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.8...v4.0.0-next.9) (2023-11-29)
11
+
12
+ **Note:** Version bump only for package @rsdk/yarn.constraints
13
+
14
+ ## [4.0.0-next.8](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.7...v4.0.0-next.8) (2023-11-29)
15
+
16
+ ### Features
17
+
18
+ * Kafka batch producer ([#150](https://github.com/R-Vision/rsdk/issues/150)) ([2faa2f4](https://github.com/R-Vision/rsdk/commit/2faa2f41ca0dbb6d8a92cbf0ab20cf5cefeaf4e9))
19
+
20
+ ## [4.0.0-next.7](https://github.com/R-Vision/rsdk/compare/v4.0.0-next.6...v4.0.0-next.7) (2023-11-21)
21
+
22
+ ### Features
23
+
24
+ * check access to file ([b9fb6bc](https://github.com/R-Vision/rsdk/commit/b9fb6bcc0a4fe79cdc580c3f2154bdc0a8ad906c))
25
+ * **yarn.constraints:** added constraints package
26
+ for `yarn constraints` ([3567951](https://github.com/R-Vision/rsdk/commit/3567951a47de667d3f3be5bb0f4892a9e6168087))
package/README.MD ADDED
@@ -0,0 +1,35 @@
1
+ # @rsdk/yarn.constraints
2
+
3
+ Tool for make consistent version dependencies in workspaces
4
+
5
+ ## .rsdk/.constraints
6
+
7
+ ```yaml
8
+ some-package: 1.0.0
9
+ "@scope":
10
+ scope-package: ~1.0.0
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Default
16
+
17
+ ```js
18
+ // yarn.config.js
19
+ module.exports = require('@rsdk/yarn.constraints').config
20
+ ```
21
+
22
+ With configuration
23
+
24
+ ```js
25
+ // yarn.config.js
26
+ module.exports = require('@rsdk/yarn.constraints').override(async (cfg) => {
27
+ // some actions, reference https://yarnpkg.com/features/constraints
28
+ })
29
+ ```
30
+
31
+ ## Variables
32
+
33
+ | Name | Description | Default |
34
+ |---------------------------|-------------------------|--------------------------|
35
+ | RSDK_YARN_CONSTRAINTS_CFG | path to constraints yml | ./.rsdk/.constraints.yml |
@@ -0,0 +1 @@
1
+ export declare const ConstraintSchema: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>, import("@sinclair/typebox").TString]>>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConstraintSchema = void 0;
4
+ const typebox_1 = require("@sinclair/typebox");
5
+ exports.ConstraintSchema = typebox_1.Type.Record(typebox_1.Type.String({
6
+ description: 'scope or package name',
7
+ }), typebox_1.Type.Union([
8
+ typebox_1.Type.Record(typebox_1.Type.String({
9
+ description: 'scope package name',
10
+ }), typebox_1.Type.String({
11
+ description: 'scope package version',
12
+ })),
13
+ typebox_1.Type.String({
14
+ description: 'package version',
15
+ }),
16
+ ]));
17
+ //# sourceMappingURL=constraint-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constraint-schema.js","sourceRoot":"","sources":["../src/constraint-schema.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAE5B,QAAA,gBAAgB,GAAG,cAAI,CAAC,MAAM,CACzC,cAAI,CAAC,MAAM,CAAC;IACV,WAAW,EAAE,uBAAuB;CACrC,CAAC,EACF,cAAI,CAAC,KAAK,CAAC;IACT,cAAI,CAAC,MAAM,CACT,cAAI,CAAC,MAAM,CAAC;QACV,WAAW,EAAE,oBAAoB;KAClC,CAAC,EACF,cAAI,CAAC,MAAM,CAAC;QACV,WAAW,EAAE,uBAAuB;KACrC,CAAC,CACH;IACD,cAAI,CAAC,MAAM,CAAC;QACV,WAAW,EAAE,iBAAiB;KAC/B,CAAC;CACH,CAAC,CACH,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Static } from '@sinclair/typebox';
2
+ import type { Constraints } from '@yarnpkg/types/lib/yarn';
3
+ import type { ConstraintSchema } from './constraint-schema';
4
+ export declare class DependencyChecker {
5
+ private readonly yarn;
6
+ constructor(yarn: Constraints.Yarn);
7
+ enforceConsistentDependenciesAcrossTheProject(constraints: Static<typeof ConstraintSchema>, part?: string): void;
8
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DependencyChecker = void 0;
4
+ class DependencyChecker {
5
+ yarn;
6
+ constructor(yarn) {
7
+ this.yarn = yarn;
8
+ }
9
+ enforceConsistentDependenciesAcrossTheProject(constraints, part = '') {
10
+ for (const [packageOrPrefix, value] of Object.entries(constraints)) {
11
+ const resolvedName = [part, packageOrPrefix].filter(Boolean).join('/');
12
+ if (typeof value === 'string') {
13
+ for (const dep of this.yarn.dependencies({ ident: resolvedName })) {
14
+ dep.update(value);
15
+ }
16
+ continue;
17
+ }
18
+ this.enforceConsistentDependenciesAcrossTheProject(value, resolvedName);
19
+ }
20
+ }
21
+ }
22
+ exports.DependencyChecker = DependencyChecker;
23
+ //# sourceMappingURL=dependency-checker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-checker.js","sourceRoot":"","sources":["../src/dependency-checker.ts"],"names":[],"mappings":";;;AAKA,MAAa,iBAAiB;IACC;IAA7B,YAA6B,IAAsB;QAAtB,SAAI,GAAJ,IAAI,CAAkB;IAAG,CAAC;IAEvD,6CAA6C,CAC3C,WAA4C,EAC5C,IAAI,GAAG,EAAE;QAET,KAAK,MAAM,CAAC,eAAe,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAClE,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBAC7B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE;oBACjE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBACnB;gBACD,SAAS;aACV;YACD,IAAI,CAAC,6CAA6C,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;SACzE;IACH,CAAC;CACF;AAlBD,8CAkBC"}
@@ -0,0 +1,5 @@
1
+ import type { Yarn } from '@yarnpkg/types';
2
+ import type { Constraints } from '@yarnpkg/types/lib/yarn';
3
+ export declare const createConstraints: (overrideConfig?: Yarn.Config) => (ctx: Constraints.Context) => Promise<void>;
4
+ export declare const config: Yarn.Config;
5
+ export declare const override: (config: Yarn.Config) => Yarn.Config;
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.override = exports.config = exports.createConstraints = void 0;
7
+ const value_1 = require("@sinclair/typebox/value");
8
+ const promises_1 = require("node:fs/promises");
9
+ const yaml_1 = __importDefault(require("yaml"));
10
+ const constraint_schema_1 = require("./constraint-schema");
11
+ const dependency_checker_1 = require("./dependency-checker");
12
+ const constraintsManifestPath = process.env.RSDK_YARN_CONSTRAINTS_CFG ?? './.rsdk/.constraints.yml';
13
+ const createConstraints = (overrideConfig) => async (ctx) => {
14
+ const { Yarn } = ctx;
15
+ await (0, promises_1.access)(constraintsManifestPath, promises_1.constants.R_OK);
16
+ const constraints = yaml_1.default.parse(await (0, promises_1.readFile)(constraintsManifestPath, 'utf8'));
17
+ const isValid = value_1.Value.Check(constraint_schema_1.ConstraintSchema, constraints);
18
+ if (!isValid) {
19
+ const cause = [...value_1.Value.Errors(constraint_schema_1.ConstraintSchema, constraints)];
20
+ throw new Error('Invalid constraints.yml\n' + JSON.stringify(cause, null, 2), {
21
+ cause: cause,
22
+ });
23
+ }
24
+ new dependency_checker_1.DependencyChecker(Yarn).enforceConsistentDependenciesAcrossTheProject(constraints);
25
+ overrideConfig?.constraints?.(ctx);
26
+ };
27
+ exports.createConstraints = createConstraints;
28
+ exports.config = {
29
+ constraints: (0, exports.createConstraints)(),
30
+ };
31
+ const override = (config) => ({
32
+ ...config,
33
+ constraints: (0, exports.createConstraints)(config),
34
+ });
35
+ exports.override = override;
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mDAAgD;AAGhD,+CAA+D;AAC/D,gDAAwB;AAExB,2DAAuD;AACvD,6DAAyD;AAEzD,MAAM,uBAAuB,GAC3B,OAAO,CAAC,GAAG,CAAC,yBAAyB,IAAI,0BAA0B,CAAC;AAE/D,MAAM,iBAAiB,GAC5B,CAAC,cAA4B,EAAE,EAAE,CACjC,KAAK,EAAE,GAAwB,EAAiB,EAAE;IAChD,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAErB,MAAM,IAAA,iBAAM,EAAC,uBAAuB,EAAE,oBAAS,CAAC,IAAI,CAAC,CAAC;IACtD,MAAM,WAAW,GAAG,cAAI,CAAC,KAAK,CAC5B,MAAM,IAAA,mBAAQ,EAAC,uBAAuB,EAAE,MAAM,CAAC,CAChD,CAAC;IACF,MAAM,OAAO,GAAG,aAAK,CAAC,KAAK,CAAC,oCAAgB,EAAE,WAAW,CAAC,CAAC;IAC3D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,KAAK,GAAG,CAAC,GAAG,aAAK,CAAC,MAAM,CAAC,oCAAgB,EAAE,WAAW,CAAC,CAAC,CAAC;QAE/D,MAAM,IAAI,KAAK,CACb,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,EAC5D;YACE,KAAK,EAAE,KAAK;SACb,CACF,CAAC;KACH;IACD,IAAI,sCAAiB,CAAC,IAAI,CAAC,CAAC,6CAA6C,CACvE,WAAW,CACZ,CAAC;IACF,cAAc,EAAE,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC;AACrC,CAAC,CAAC;AAxBS,QAAA,iBAAiB,qBAwB1B;AAES,QAAA,MAAM,GAAgB;IACjC,WAAW,EAAE,IAAA,yBAAiB,GAAE;CACjC,CAAC;AAEK,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAe,EAAE,CAAC,CAAC;IAC7D,GAAG,MAAM;IACT,WAAW,EAAE,IAAA,yBAAiB,EAAC,MAAM,CAAC;CACvC,CAAC,CAAC;AAHU,QAAA,QAAQ,YAGlB"}
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@rsdk/yarn.constraints",
3
+ "version": "4.0.0-next.10",
4
+ "description": "Useful common classes, functions and types",
5
+ "license": "Apache License 2.0",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "url": "https://github.com/R-Vision/rsdk"
11
+ },
12
+ "main": "dist/index.js",
13
+ "dependencies": {
14
+ "@sinclair/typebox": "^0.31.25",
15
+ "yaml": "^2.3.4"
16
+ },
17
+ "gitHead": "c41d4da9aa0318d5e6417514c763618ce924f9b7"
18
+ }
@@ -0,0 +1,20 @@
1
+ import { Type } from '@sinclair/typebox';
2
+
3
+ export const ConstraintSchema = Type.Record(
4
+ Type.String({
5
+ description: 'scope or package name',
6
+ }),
7
+ Type.Union([
8
+ Type.Record(
9
+ Type.String({
10
+ description: 'scope package name',
11
+ }),
12
+ Type.String({
13
+ description: 'scope package version',
14
+ }),
15
+ ),
16
+ Type.String({
17
+ description: 'package version',
18
+ }),
19
+ ]),
20
+ );
@@ -0,0 +1,24 @@
1
+ import type { Static } from '@sinclair/typebox';
2
+ import type { Constraints } from '@yarnpkg/types/lib/yarn';
3
+
4
+ import type { ConstraintSchema } from './constraint-schema';
5
+
6
+ export class DependencyChecker {
7
+ constructor(private readonly yarn: Constraints.Yarn) {}
8
+
9
+ enforceConsistentDependenciesAcrossTheProject(
10
+ constraints: Static<typeof ConstraintSchema>,
11
+ part = '',
12
+ ): void {
13
+ for (const [packageOrPrefix, value] of Object.entries(constraints)) {
14
+ const resolvedName = [part, packageOrPrefix].filter(Boolean).join('/');
15
+ if (typeof value === 'string') {
16
+ for (const dep of this.yarn.dependencies({ ident: resolvedName })) {
17
+ dep.update(value);
18
+ }
19
+ continue;
20
+ }
21
+ this.enforceConsistentDependenciesAcrossTheProject(value, resolvedName);
22
+ }
23
+ }
24
+ }
package/src/index.ts ADDED
@@ -0,0 +1,46 @@
1
+ import { Value } from '@sinclair/typebox/value';
2
+ import type { Yarn } from '@yarnpkg/types';
3
+ import type { Constraints } from '@yarnpkg/types/lib/yarn';
4
+ import { access, constants, readFile } from 'node:fs/promises';
5
+ import yaml from 'yaml';
6
+
7
+ import { ConstraintSchema } from './constraint-schema';
8
+ import { DependencyChecker } from './dependency-checker';
9
+
10
+ const constraintsManifestPath =
11
+ process.env.RSDK_YARN_CONSTRAINTS_CFG ?? './.rsdk/.constraints.yml';
12
+
13
+ export const createConstraints =
14
+ (overrideConfig?: Yarn.Config) =>
15
+ async (ctx: Constraints.Context): Promise<void> => {
16
+ const { Yarn } = ctx;
17
+
18
+ await access(constraintsManifestPath, constants.R_OK);
19
+ const constraints = yaml.parse(
20
+ await readFile(constraintsManifestPath, 'utf8'),
21
+ );
22
+ const isValid = Value.Check(ConstraintSchema, constraints);
23
+ if (!isValid) {
24
+ const cause = [...Value.Errors(ConstraintSchema, constraints)];
25
+
26
+ throw new Error(
27
+ 'Invalid constraints.yml\n' + JSON.stringify(cause, null, 2),
28
+ {
29
+ cause: cause,
30
+ },
31
+ );
32
+ }
33
+ new DependencyChecker(Yarn).enforceConsistentDependenciesAcrossTheProject(
34
+ constraints,
35
+ );
36
+ overrideConfig?.constraints?.(ctx);
37
+ };
38
+
39
+ export const config: Yarn.Config = {
40
+ constraints: createConstraints(),
41
+ };
42
+
43
+ export const override = (config: Yarn.Config): Yarn.Config => ({
44
+ ...config,
45
+ constraints: createConstraints(config),
46
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@rsdk/tsconfig/base.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "dist"
6
+ },
7
+ "exclude": [
8
+ "node_modules",
9
+ "dist",
10
+ "test",
11
+ "**/*spec.ts"
12
+ ]
13
+ }