UNPKG

2.41 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.CorePlugin = void 0;
4const tslib_1 = require("tslib");
5const MessageName_1 = require("./MessageName");
6const structUtils = tslib_1.__importStar(require("./structUtils"));
7exports.CorePlugin = {
8 hooks: {
9 reduceDependency: (dependency, project, locator, initialDependency, { resolver, resolveOptions }) => {
10 for (const { pattern, reference } of project.topLevelWorkspace.manifest.resolutions) {
11 if (pattern.from && pattern.from.fullName !== structUtils.requirableIdent(locator))
12 continue;
13 if (pattern.from && pattern.from.description && pattern.from.description !== locator.reference)
14 continue;
15 if (pattern.descriptor.fullName !== structUtils.requirableIdent(dependency))
16 continue;
17 if (pattern.descriptor.description && pattern.descriptor.description !== dependency.range)
18 continue;
19 const alias = resolver.bindDescriptor(structUtils.makeDescriptor(dependency, reference), project.topLevelWorkspace.anchoredLocator, resolveOptions);
20 return alias;
21 }
22 return dependency;
23 },
24 validateProject: async (project, report) => {
25 for (const workspace of project.workspaces) {
26 const workspaceName = structUtils.prettyWorkspace(project.configuration, workspace);
27 await project.configuration.triggerHook(hooks => {
28 return hooks.validateWorkspace;
29 }, workspace, {
30 reportWarning: (name, text) => report.reportWarning(name, `${workspaceName}: ${text}`),
31 reportError: (name, text) => report.reportError(name, `${workspaceName}: ${text}`),
32 });
33 }
34 },
35 validateWorkspace: async (workspace, report) => {
36 // Validate manifest
37 const { manifest } = workspace;
38 if (manifest.resolutions.length && workspace.cwd !== workspace.project.cwd)
39 manifest.errors.push(new Error(`Resolutions field will be ignored`));
40 for (const manifestError of manifest.errors) {
41 report.reportWarning(MessageName_1.MessageName.INVALID_MANIFEST, manifestError.message);
42 }
43 },
44 },
45};