-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathindex.ts
50 lines (41 loc) Β· 1.91 KB
/
index.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
import {Hooks as CoreHooks, Plugin, structUtils} from '@yarnpkg/core';
import {Hooks as PatchHooks} from '@yarnpkg/plugin-patch';
import {packageExtensions} from './extensions';
import {getPatch as getFseventsPatch} from './patches/fsevents.patch';
import {getPatch as getResolvePatch} from './patches/resolve.patch';
import {getPatch as getTypescriptPatch} from './patches/typescript.patch';
const PATCHES = new Map([
[structUtils.makeIdent(null, `fsevents`).identHash, getFseventsPatch],
[structUtils.makeIdent(null, `resolve`).identHash, getResolvePatch],
[structUtils.makeIdent(null, `typescript`).identHash, getTypescriptPatch],
]);
const plugin: Plugin<CoreHooks & PatchHooks> = {
hooks: {
registerPackageExtensions: async (configuration, registerPackageExtension) => {
for (const [descriptorStr, extensionData] of packageExtensions) {
registerPackageExtension(structUtils.parseDescriptor(descriptorStr, true), extensionData);
}
},
getBuiltinPatch: async (project, name) => {
const TAG = `compat/`;
if (!name.startsWith(TAG))
return undefined;
const ident = structUtils.parseIdent(name.slice(TAG.length));
const patch = PATCHES.get(ident.identHash)?.();
return typeof patch !== `undefined` ? patch : null;
},
reduceDependency: async (dependency, project, locator, initialDescriptor) => {
const patch = PATCHES.get(dependency.identHash);
if (typeof patch === `undefined`)
return dependency;
return structUtils.makeDescriptor(dependency, structUtils.makeRange({
protocol: `patch:`,
source: structUtils.stringifyDescriptor(dependency),
selector: `optional!builtin<compat/${structUtils.stringifyIdent(dependency)}>`,
params: null,
}));
},
},
};
// eslint-disable-next-line arca/no-default-export
export default plugin;