-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathCorePlugin.ts
88 lines (74 loc) Β· 3.34 KB
/
CorePlugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {MessageName} from './MessageName';
import {Plugin} from './Plugin';
import {Project} from './Project';
import {Resolver, ResolveOptions} from './Resolver';
import {Workspace} from './Workspace';
import * as structUtils from './structUtils';
import {Descriptor, Locator} from './types';
export const CorePlugin: Plugin = {
hooks: {
reduceDependency: (dependency: Descriptor, project: Project, locator: Locator, initialDependency: Descriptor, {resolver, resolveOptions}: {resolver: Resolver, resolveOptions: ResolveOptions}) => {
for (const {pattern, reference} of project.topLevelWorkspace.manifest.resolutions) {
if (pattern.from) {
if (pattern.from.fullName !== structUtils.stringifyIdent(locator))
continue;
const normalizedFrom = project.configuration.normalizeLocator(
structUtils.makeLocator(
structUtils.parseIdent(pattern.from.fullName),
pattern.from.description ?? locator.reference,
),
);
if (normalizedFrom.locatorHash !== locator.locatorHash) {
continue;
}
}
/* All `resolutions` field entries have a descriptor*/ {
if (pattern.descriptor.fullName !== structUtils.stringifyIdent(dependency))
continue;
const normalizedDescriptor = project.configuration.normalizeDependency(
structUtils.makeDescriptor(
structUtils.parseLocator(pattern.descriptor.fullName),
pattern.descriptor.description ?? dependency.range,
),
);
if (normalizedDescriptor.descriptorHash !== dependency.descriptorHash) {
continue;
}
}
const alias = resolver.bindDescriptor(
project.configuration.normalizeDependency(structUtils.makeDescriptor(dependency, reference)),
project.topLevelWorkspace.anchoredLocator,
resolveOptions,
);
return alias;
}
return dependency;
},
validateProject: async (project: Project, report: {
reportWarning: (name: MessageName, text: string) => void;
reportError: (name: MessageName, text: string) => void;
}) => {
for (const workspace of project.workspaces) {
const workspaceName = structUtils.prettyWorkspace(project.configuration, workspace);
await project.configuration.triggerHook(hooks => {
return hooks.validateWorkspace;
}, workspace, {
reportWarning: (name: MessageName, text: string) => report.reportWarning(name, `${workspaceName}: ${text}`),
reportError: (name: MessageName, text: string) => report.reportError(name, `${workspaceName}: ${text}`),
});
}
},
validateWorkspace: async (workspace: Workspace, report: {
reportWarning: (name: MessageName, text: string) => void;
reportError: (name: MessageName, text: string) => void;
}) => {
// Validate manifest
const {manifest} = workspace;
if (manifest.resolutions.length && workspace.cwd !== workspace.project.cwd)
manifest.errors.push(new Error(`Resolutions field will be ignored`));
for (const manifestError of manifest.errors) {
report.reportWarning(MessageName.INVALID_MANIFEST, manifestError.message);
}
},
},
};