@rsdk/yarn.constraints 6.0.0-next.39 → 6.0.0-next.40
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/DEPENDENCY_MODEL.md +452 -0
- package/README.MD +24 -0
- package/__tests__/compatibility.test.ts +321 -0
- package/__tests__/engine.test.ts +1002 -0
- package/__tests__/fixtures/imports/bin.js +4 -0
- package/__tests__/fixtures/imports/export-entry.mjs +1 -0
- package/__tests__/fixtures/imports/root-entry.js +3 -0
- package/__tests__/fixtures/imports/src/common.cjs +3 -0
- package/__tests__/fixtures/imports/src/common.cts +3 -0
- package/__tests__/fixtures/imports/src/component.tsx +4 -0
- package/__tests__/fixtures/imports/src/index.ts +13 -0
- package/__tests__/fixtures/imports/src/module.mjs +3 -0
- package/__tests__/fixtures/imports/src/module.mts +3 -0
- package/__tests__/fixtures/imports/src/plain.js +3 -0
- package/__tests__/fixtures/imports/src/test-only-usage.ts +1 -0
- package/__tests__/imports.test.ts +206 -0
- package/__tests__/manifest-writer.test.ts +157 -0
- package/dist/ansi.d.ts +9 -0
- package/dist/ansi.js +24 -0
- package/dist/ansi.js.map +1 -0
- package/dist/bin/depdoc.d.ts +2 -0
- package/dist/bin/depdoc.js +157 -0
- package/dist/bin/depdoc.js.map +1 -0
- package/dist/collectors/config.d.ts +2 -0
- package/dist/collectors/config.js +25 -0
- package/dist/collectors/config.js.map +1 -0
- package/dist/collectors/external-metadata.d.ts +5 -0
- package/dist/collectors/external-metadata.js +110 -0
- package/dist/collectors/external-metadata.js.map +1 -0
- package/dist/collectors/package-extensions.d.ts +3 -0
- package/dist/collectors/package-extensions.js +43 -0
- package/dist/collectors/package-extensions.js.map +1 -0
- package/dist/collectors/type-providers.d.ts +3 -0
- package/dist/collectors/type-providers.js +46 -0
- package/dist/collectors/type-providers.js.map +1 -0
- package/dist/collectors/workspaces.d.ts +2 -0
- package/dist/collectors/workspaces.js +88 -0
- package/dist/collectors/workspaces.js.map +1 -0
- package/dist/dependency-model.d.ts +11 -0
- package/dist/dependency-model.js +18 -0
- package/dist/dependency-model.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +13 -33
- package/dist/index.js.map +1 -1
- package/dist/lib/imports.d.ts +9 -0
- package/dist/lib/imports.js +249 -0
- package/dist/lib/imports.js.map +1 -0
- package/dist/lib/package-json.d.ts +21 -0
- package/dist/lib/package-json.js +32 -0
- package/dist/lib/package-json.js.map +1 -0
- package/dist/model/diagnostics.d.ts +4 -0
- package/dist/model/diagnostics.js +273 -0
- package/dist/model/diagnostics.js.map +1 -0
- package/dist/model/engine.d.ts +5 -0
- package/dist/model/engine.js +52 -0
- package/dist/model/engine.js.map +1 -0
- package/dist/model/expected.d.ts +20 -0
- package/dist/model/expected.js +89 -0
- package/dist/model/expected.js.map +1 -0
- package/dist/model/peer-propagation.d.ts +2 -0
- package/dist/model/peer-propagation.js +124 -0
- package/dist/model/peer-propagation.js.map +1 -0
- package/dist/model/placement.d.ts +9 -0
- package/dist/model/placement.js +205 -0
- package/dist/model/placement.js.map +1 -0
- package/dist/model/rules.d.ts +14 -0
- package/dist/model/rules.js +46 -0
- package/dist/model/rules.js.map +1 -0
- package/dist/model/types.d.ts +117 -0
- package/dist/model/types.js +9 -0
- package/dist/model/types.js.map +1 -0
- package/dist/model/versions.d.ts +3 -0
- package/dist/model/versions.js +73 -0
- package/dist/model/versions.js.map +1 -0
- package/dist/reporting.d.ts +3 -0
- package/dist/reporting.js +80 -0
- package/dist/reporting.js.map +1 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +70 -0
- package/dist/runner.js.map +1 -0
- package/dist/writer/manifest-writer.d.ts +2 -0
- package/dist/writer/manifest-writer.js +72 -0
- package/dist/writer/manifest-writer.js.map +1 -0
- package/eslint.config.cjs +3 -0
- package/jest.config.js +1 -0
- package/package.json +7 -3
- package/src/ansi.ts +23 -0
- package/src/bin/depdoc.ts +213 -0
- package/src/collectors/config.ts +26 -0
- package/src/collectors/external-metadata.ts +148 -0
- package/src/collectors/package-extensions.ts +52 -0
- package/src/collectors/type-providers.ts +51 -0
- package/src/collectors/workspaces.ts +99 -0
- package/src/dependency-model.ts +26 -0
- package/src/index.ts +28 -45
- package/src/lib/imports.ts +293 -0
- package/src/lib/package-json.ts +46 -0
- package/src/model/diagnostics.ts +328 -0
- package/src/model/engine.ts +120 -0
- package/src/model/expected.ts +141 -0
- package/src/model/peer-propagation.ts +199 -0
- package/src/model/placement.ts +372 -0
- package/src/model/rules.ts +73 -0
- package/src/model/types.ts +164 -0
- package/src/model/versions.ts +109 -0
- package/src/reporting.ts +117 -0
- package/src/runner.ts +102 -0
- package/src/writer/manifest-writer.ts +111 -0
- package/tsconfig.build.json +1 -0
- package/tsconfig.json +6 -1
- package/dist/constraint-schema.d.ts +0 -1
- package/dist/constraint-schema.js +0 -17
- package/dist/constraint-schema.js.map +0 -1
- package/dist/dependency-checker.d.ts +0 -8
- package/dist/dependency-checker.js +0 -40
- package/dist/dependency-checker.js.map +0 -1
- package/src/constraint-schema.ts +0 -20
- package/src/dependency-checker.ts +0 -41
package/src/reporting.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI-oriented dependency model reporting.
|
|
3
|
+
*
|
|
4
|
+
* The engine returns structured diagnostics and reason trails. This module
|
|
5
|
+
* turns them into stable human-readable text for `check`, `fix`, and `explain`.
|
|
6
|
+
*/
|
|
7
|
+
import {
|
|
8
|
+
getDeclaredRange,
|
|
9
|
+
getDeclaredSection,
|
|
10
|
+
getExpectedRange,
|
|
11
|
+
getExpectedSection,
|
|
12
|
+
} from './model/expected';
|
|
13
|
+
import type { DependencyModelResult } from './model/types';
|
|
14
|
+
import { ansi } from './ansi';
|
|
15
|
+
|
|
16
|
+
export function formatDependencyModelResult(
|
|
17
|
+
result: DependencyModelResult,
|
|
18
|
+
): string {
|
|
19
|
+
const lines: string[] = [];
|
|
20
|
+
|
|
21
|
+
for (const violation of result.violations) {
|
|
22
|
+
const dep = violation.dependency ? ` ${violation.dependency}` : '';
|
|
23
|
+
const location =
|
|
24
|
+
violation.workspaceLocation === '.'
|
|
25
|
+
? ''
|
|
26
|
+
: ` (${violation.workspaceLocation})`;
|
|
27
|
+
|
|
28
|
+
lines.push(
|
|
29
|
+
`${ansi.red('✖')} ${ansi.bold(violation.workspace)}${ansi.dim(location)}${ansi.red(dep)}: ${violation.message}`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const warning of result.warnings) {
|
|
34
|
+
const workspace = warning.workspace ? `${warning.workspace}: ` : '';
|
|
35
|
+
|
|
36
|
+
lines.push(`${ansi.yellow('⚠')} ${ansi.bold(workspace)}${warning.message}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (result.violations.length === 0) {
|
|
40
|
+
lines.push(`${ansi.green('✓')} ${ansi.bold('dependency model is consistent')}`);
|
|
41
|
+
} else {
|
|
42
|
+
lines.push(
|
|
43
|
+
`${ansi.red('✖')} ${ansi.bold(`${result.violations.length} dependency model violation(s)`)}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (result.warnings.length > 0) {
|
|
48
|
+
lines.push(
|
|
49
|
+
`${ansi.yellow('⚠')} ${ansi.bold(`${result.warnings.length} warning(s)`)}`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function explainDependency(
|
|
57
|
+
result: DependencyModelResult,
|
|
58
|
+
workspaceSelector: string,
|
|
59
|
+
depIdent: string,
|
|
60
|
+
): string {
|
|
61
|
+
const workspace = result.contexts.find(
|
|
62
|
+
(ctx) =>
|
|
63
|
+
ctx.name === workspaceSelector ||
|
|
64
|
+
ctx.location === workspaceSelector ||
|
|
65
|
+
(workspaceSelector === '<root>' && ctx.isRoot),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (!workspace) {
|
|
69
|
+
return `Workspace not found: ${workspaceSelector}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const expected = result.expected.get(workspace.location);
|
|
73
|
+
if (!expected) {
|
|
74
|
+
return `No dependency model data for workspace: ${workspaceSelector}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const actualSection = getDeclaredSection(workspace.pkg, depIdent);
|
|
78
|
+
const actualRange = getDeclaredRange(workspace.pkg, depIdent);
|
|
79
|
+
const expectedSection = getExpectedSection(expected, depIdent);
|
|
80
|
+
const expectedRange = getExpectedRange(expected, depIdent);
|
|
81
|
+
const reasons = expected.reasons.get(depIdent) ?? [];
|
|
82
|
+
const lines = [
|
|
83
|
+
`${ansi.bold(workspace.name)} ${ansi.dim(`(${workspace.location})`)}`,
|
|
84
|
+
ansi.cyan(depIdent),
|
|
85
|
+
`${ansi.bold('actual:')} ${actualSection ? `${ansi.yellow(actualSection)}@${actualRange}` : ansi.dim('not declared')}`,
|
|
86
|
+
`${ansi.bold('expected:')} ${expectedSection ? `${ansi.green(expectedSection)}@${expectedRange}` : ansi.dim('not required')}`,
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
if (actualSection && !expectedSection) {
|
|
90
|
+
lines.push(
|
|
91
|
+
`${ansi.bold('status:')} ${ansi.yellow('actual dependency is stale in the derived model')}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (reasons.length > 0) {
|
|
96
|
+
lines.push(ansi.bold('reasons:'));
|
|
97
|
+
for (const reason of reasons) {
|
|
98
|
+
lines.push(` - ${ansi.magenta(reason.kind)}: ${reason.detail}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const usage = workspace.sourceUsage.get(depIdent);
|
|
103
|
+
if (usage) {
|
|
104
|
+
lines.push(ansi.bold('source imports:'));
|
|
105
|
+
for (const file of [...usage.files].sort()) {
|
|
106
|
+
lines.push(` - ${ansi.dim(file)}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (workspace.dtsImports.has(depIdent)) {
|
|
111
|
+
lines.push(
|
|
112
|
+
`${ansi.bold('public type surface:')} ${ansi.green('appears in dist/**/*.d.ts')}`,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return lines.join('\n');
|
|
117
|
+
}
|
package/src/runner.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dependency model runner.
|
|
3
|
+
*
|
|
4
|
+
* The runner coordinates impure work: locating the repo root, collecting facts,
|
|
5
|
+
* iterating external metadata discovery, invoking the pure engine, and applying
|
|
6
|
+
* manifest fixes when requested.
|
|
7
|
+
*/
|
|
8
|
+
import { loadConfig } from './collectors/config';
|
|
9
|
+
import {
|
|
10
|
+
collectExternalMetadata,
|
|
11
|
+
collectExternalProviderIdents,
|
|
12
|
+
} from './collectors/external-metadata';
|
|
13
|
+
import { loadPackageExtensions } from './collectors/package-extensions';
|
|
14
|
+
import { collectTypeProviderPackages } from './collectors/type-providers';
|
|
15
|
+
import { loadWorkspaces } from './collectors/workspaces';
|
|
16
|
+
import { findMonorepoRoot } from './lib/package-json';
|
|
17
|
+
import { deriveDependencyModel } from './model/engine';
|
|
18
|
+
import type {
|
|
19
|
+
DependencyModelOptions,
|
|
20
|
+
DependencyModelOutput,
|
|
21
|
+
DependencyModelResult,
|
|
22
|
+
} from './model/types';
|
|
23
|
+
import { writeFixes } from './writer/manifest-writer';
|
|
24
|
+
|
|
25
|
+
export function runDependencyModel(
|
|
26
|
+
options: DependencyModelOptions = {},
|
|
27
|
+
): DependencyModelResult {
|
|
28
|
+
const rootDir = options.rootDir ?? findMonorepoRoot(process.cwd());
|
|
29
|
+
if (!rootDir) {
|
|
30
|
+
throw new Error('Unable to find monorepo root');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const config = loadConfig(rootDir, options.constraintsPath);
|
|
34
|
+
const rules = config.rules ?? [];
|
|
35
|
+
const withDts = options.withDts === true;
|
|
36
|
+
const contexts = loadWorkspaces(rootDir, withDts);
|
|
37
|
+
const packageExtensions = loadPackageExtensions(rootDir);
|
|
38
|
+
const workspaceNames = new Set(
|
|
39
|
+
contexts.filter((ws) => !ws.isRoot).map((ws) => ws.name),
|
|
40
|
+
);
|
|
41
|
+
const typeProviderPackages = collectTypeProviderPackages(
|
|
42
|
+
rootDir,
|
|
43
|
+
contexts[0]!.pkg,
|
|
44
|
+
rules,
|
|
45
|
+
);
|
|
46
|
+
const externalPeerMetadata = new Map<string, Map<string, string> | null>();
|
|
47
|
+
const externalTypeMetadata = new Map<string, { hasBundledTypes: boolean }>();
|
|
48
|
+
const providerIdents = collectExternalProviderIdents(
|
|
49
|
+
contexts,
|
|
50
|
+
workspaceNames,
|
|
51
|
+
);
|
|
52
|
+
let output: DependencyModelOutput | null = null;
|
|
53
|
+
|
|
54
|
+
for (let pass = 0; pass < 10; pass++) {
|
|
55
|
+
collectExternalMetadata(
|
|
56
|
+
rootDir,
|
|
57
|
+
packageExtensions,
|
|
58
|
+
providerIdents,
|
|
59
|
+
externalPeerMetadata,
|
|
60
|
+
externalTypeMetadata,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
output = deriveDependencyModel({
|
|
64
|
+
workspaces: contexts,
|
|
65
|
+
externalPeerMetadata,
|
|
66
|
+
externalTypeMetadata,
|
|
67
|
+
typeProviderPackages,
|
|
68
|
+
rules,
|
|
69
|
+
...(withDts ? { withDts: true } : {}),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
let changed = false;
|
|
73
|
+
|
|
74
|
+
for (const ident of collectExternalProviderIdents(
|
|
75
|
+
contexts,
|
|
76
|
+
workspaceNames,
|
|
77
|
+
output.expected,
|
|
78
|
+
)) {
|
|
79
|
+
if (providerIdents.has(ident)) continue;
|
|
80
|
+
providerIdents.add(ident);
|
|
81
|
+
changed = true;
|
|
82
|
+
}
|
|
83
|
+
if (!changed) break;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!output) {
|
|
87
|
+
throw new Error('Unable to derive dependency model');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (options.fix && output.violations.length > 0) {
|
|
91
|
+
writeFixes(rootDir, output.expected);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
rootDir,
|
|
96
|
+
violations: output.violations,
|
|
97
|
+
warnings: output.warnings,
|
|
98
|
+
contexts,
|
|
99
|
+
expected: output.expected,
|
|
100
|
+
config,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manifest writer.
|
|
3
|
+
*
|
|
4
|
+
* The writer is the only module that mutates package.json files. It preserves
|
|
5
|
+
* unrelated fields, rewrites dependency sections from the expected graph, and
|
|
6
|
+
* skips writes when the normalized section content is unchanged.
|
|
7
|
+
*/
|
|
8
|
+
import { writeFileSync } from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
|
|
11
|
+
import type { PackageJson } from '../lib/package-json';
|
|
12
|
+
import type { ExpectedWorkspace } from '../model/types';
|
|
13
|
+
import { SECTIONS } from '../model/types';
|
|
14
|
+
|
|
15
|
+
function sortedRecord(map: Map<string, string>): Record<string, string> {
|
|
16
|
+
return Object.fromEntries(
|
|
17
|
+
[...map.entries()].sort(([a], [b]) => a.localeCompare(b)),
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function recordsEqual(
|
|
22
|
+
actual: Record<string, string> | undefined,
|
|
23
|
+
expected: Map<string, string>,
|
|
24
|
+
): boolean {
|
|
25
|
+
const actualEntries = Object.entries(actual ?? {}).sort(([a], [b]) =>
|
|
26
|
+
a.localeCompare(b),
|
|
27
|
+
);
|
|
28
|
+
const expectedEntries = [...expected.entries()].sort(([a], [b]) =>
|
|
29
|
+
a.localeCompare(b),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return JSON.stringify(actualEntries) === JSON.stringify(expectedEntries);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function peerDependenciesMetaEqual(
|
|
36
|
+
actual: PackageJson['peerDependenciesMeta'] | undefined,
|
|
37
|
+
expected: PackageJson['peerDependenciesMeta'],
|
|
38
|
+
): boolean {
|
|
39
|
+
const actualEntries = Object.entries(actual ?? {}).sort(([a], [b]) =>
|
|
40
|
+
a.localeCompare(b),
|
|
41
|
+
);
|
|
42
|
+
const expectedEntries = Object.entries(expected ?? {}).sort(([a], [b]) =>
|
|
43
|
+
a.localeCompare(b),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return JSON.stringify(actualEntries) === JSON.stringify(expectedEntries);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function prunePeerDependenciesMeta(
|
|
50
|
+
pkg: PackageJson,
|
|
51
|
+
expectedPeerDependencies: Map<string, string>,
|
|
52
|
+
): boolean {
|
|
53
|
+
if (pkg.peerDependenciesMeta === undefined) return false;
|
|
54
|
+
|
|
55
|
+
const nextMeta = Object.fromEntries(
|
|
56
|
+
Object.entries(pkg.peerDependenciesMeta)
|
|
57
|
+
.filter(([depIdent]) => expectedPeerDependencies.has(depIdent))
|
|
58
|
+
.sort(([a], [b]) => a.localeCompare(b)),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (Object.keys(nextMeta).length === 0) {
|
|
62
|
+
delete pkg.peerDependenciesMeta;
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (peerDependenciesMetaEqual(pkg.peerDependenciesMeta, nextMeta)) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
pkg.peerDependenciesMeta = nextMeta;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function writeFixes(
|
|
75
|
+
rootDir: string,
|
|
76
|
+
expectedByLocation: Map<string, ExpectedWorkspace>,
|
|
77
|
+
): void {
|
|
78
|
+
for (const expected of expectedByLocation.values()) {
|
|
79
|
+
const pkg = expected.workspace.pkg;
|
|
80
|
+
let changed = false;
|
|
81
|
+
|
|
82
|
+
for (const section of SECTIONS) {
|
|
83
|
+
if (expected.sections[section].size === 0) {
|
|
84
|
+
if (pkg[section] !== undefined) {
|
|
85
|
+
delete pkg[section];
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!recordsEqual(pkg[section], expected.sections[section])) {
|
|
92
|
+
pkg[section] = sortedRecord(expected.sections[section]);
|
|
93
|
+
changed = true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
changed =
|
|
98
|
+
prunePeerDependenciesMeta(pkg, expected.sections.peerDependencies) ||
|
|
99
|
+
changed;
|
|
100
|
+
|
|
101
|
+
if (changed) {
|
|
102
|
+
const pkgPath = path.join(
|
|
103
|
+
rootDir,
|
|
104
|
+
expected.workspace.location,
|
|
105
|
+
'package.json',
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
package/tsconfig.build.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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]>>;
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
if (part && packageOrPrefix === '*') {
|
|
12
|
-
if (typeof value !== 'string') {
|
|
13
|
-
throw new TypeError('Incorrect constraints object', {
|
|
14
|
-
cause: {
|
|
15
|
-
constraints,
|
|
16
|
-
part,
|
|
17
|
-
packageOrPrefix,
|
|
18
|
-
value,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
for (const dependency of this.yarn.dependencies()) {
|
|
23
|
-
if (dependency.ident.startsWith(part + '/')) {
|
|
24
|
-
dependency.update(value);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const resolvedName = [part, packageOrPrefix].filter(Boolean).join('/');
|
|
29
|
-
if (typeof value === 'string') {
|
|
30
|
-
for (const dep of this.yarn.dependencies({ ident: resolvedName })) {
|
|
31
|
-
dep.update(value);
|
|
32
|
-
}
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
this.enforceConsistentDependenciesAcrossTheProject(value, resolvedName);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
exports.DependencyChecker = DependencyChecker;
|
|
40
|
-
//# sourceMappingURL=dependency-checker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,CAAC;YACnE,IAAI,IAAI,IAAI,eAAe,KAAK,GAAG,EAAE,CAAC;gBACpC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;oBAC9B,MAAM,IAAI,SAAS,CAAC,8BAA8B,EAAE;wBAClD,KAAK,EAAE;4BACL,WAAW;4BACX,IAAI;4BACJ,eAAe;4BACf,KAAK;yBACN;qBACF,CAAC,CAAC;gBACL,CAAC;gBACD,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;oBAClD,IAAI,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,GAAG,GAAG,CAAC,EAAE,CAAC;wBAC5C,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC3B,CAAC;gBACH,CAAC;YACH,CAAC;YACD,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,CAAC;gBAC9B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC;oBAClE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC;gBACD,SAAS;YACX,CAAC;YACD,IAAI,CAAC,6CAA6C,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;CACF;AAnCD,8CAmCC"}
|
package/src/constraint-schema.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
);
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
if (part && packageOrPrefix === '*') {
|
|
15
|
-
if (typeof value !== 'string') {
|
|
16
|
-
throw new TypeError('Incorrect constraints object', {
|
|
17
|
-
cause: {
|
|
18
|
-
constraints,
|
|
19
|
-
part,
|
|
20
|
-
packageOrPrefix,
|
|
21
|
-
value,
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
for (const dependency of this.yarn.dependencies()) {
|
|
26
|
-
if (dependency.ident.startsWith(part + '/')) {
|
|
27
|
-
dependency.update(value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const resolvedName = [part, packageOrPrefix].filter(Boolean).join('/');
|
|
32
|
-
if (typeof value === 'string') {
|
|
33
|
-
for (const dep of this.yarn.dependencies({ ident: resolvedName })) {
|
|
34
|
-
dep.update(value);
|
|
35
|
-
}
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
this.enforceConsistentDependenciesAcrossTheProject(value, resolvedName);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|