MCPcopy Create free account
hub / github.com/hashintel/hash / enforceProtocols

Function enforceProtocols

yarn.config.cjs:115–207  ·  view source on GitHub ↗

* Enforce that the package protocols are correct. * * @param {Context} context

({ Yarn })

Source from the content-addressed store, hash-verified

113 * @param {Context} context
114 */
115function enforceProtocols({ Yarn }) {
116 const workspaces = Yarn.workspaces();
117
118 for (const dependency of Yarn.dependencies()) {
119 if (shouldIgnoreDependencyForProtocol(dependency)) {
120 continue;
121 }
122
123 const workspaceDependency = workspaces.find(
124 (workspace) => workspace.ident === dependency.ident,
125 );
126
127 if (workspaceDependency) {
128 const isPublishable = dependency.workspace.manifest.private !== true;
129 const expectedRange =
130 isPublishable && dependency.type !== "devDependencies"
131 ? "workspace:^"
132 : "workspace:*";
133
134 if (dependency.range !== expectedRange) {
135 dependency.update(expectedRange);
136 }
137 }
138
139 if (dependency.range.startsWith("file:")) {
140 // the file: protocol makes problems when used in conjunction with pnpm mode, portal is the equivalent protocol
141 dependency.update(dependency.range.replace("file:", "portal:"));
142 }
143
144 if (dependency.range.startsWith("link:")) {
145 dependency.error(
146 `The link protocol allows for non-packages to be linked and is not allowed, dependency: ${dependency.ident}`,
147 );
148 }
149
150 if (dependency.range.startsWith("exec:")) {
151 dependency.error(
152 `The exec protocol allows for arbitrary code execution and is not allowed, dependency: ${dependency.ident}`,
153 );
154 }
155
156 let shouldCheckIfValidGitDependency = false;
157
158 if (
159 dependency.range.startsWith("https://") ||
160 dependency.range.startsWith("http://")
161 ) {
162 // always prefix with the git protocol
163 dependency.update(`git:${dependency.range}`);
164 shouldCheckIfValidGitDependency = true;
165 }
166
167 if (dependency.range.startsWith("ssh://")) {
168 // always prefix with the git protocol
169 dependency.update(`git:${dependency.range.replace(/^ssh:\/\//, "git:")}`);
170 shouldCheckIfValidGitDependency = true;
171 }
172

Callers 1

constraintsFunction · 0.85

Calls 6

replaceMethod · 0.80
splitMethod · 0.80
popMethod · 0.65
findMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected