forked from DimensionDev/Maskbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pnpmfile.cjs
89 lines (80 loc) · 3.61 KB
/
.pnpmfile.cjs
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
89
// !!! There is some relative path installation source in the dependency tree,
// !!! but if we do not allow those packages to run install scripts anyway, it might be safe.
// !!! If we can resolve 'link:../empty' to something like 'workspaceRoot:/projects/empty', it will be safe to install.
const approvedList = new Map([
[
'ethereumjs-abi',
[
'git+https://github.com/ProjectWyvern/ethereumjs-abi.git',
'git+https://github.com/ethereumjs/ethereumjs-abi.git',
'https://github.com/ProjectWyvern/ethereumjs-abi.git',
],
],
[
'wyvern-js',
['git+https://github.com/ProjectOpenSea/wyvern-js.git#v3.2.1', 'github:ProjectOpenSea/wyvern-js#semver:^3.2.1'],
],
['wyvern-schemas', 'git+https://github.com/ProjectOpenSea/wyvern-schemas.git#v0.11.1'],
['bignumber.js', 'git+https://github.com/frozeman/bignumber.js-nolookahead.git'],
/* cspell:disable-next-line */
['html-parse-stringify2', 'github:locize/html-parse-stringify2'],
/* cspell:disable-next-line */
['async-eventemitter', 'github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c'],
// !!! Relative path
['xhr2-cookies', 'link:./package-overrides/xhr2-cookies'],
])
/**
* @param {string} parentPackage The current resolving parentPackage
* @param {string} dependedPackage The package it depends on
* @param {string} installationSource An unusual installation source (e.g. git: https: or link:)
*/
function assertInstallationSourceValid(parentPackage, dependedPackage, installationSource) {
if (approvedList.has(dependedPackage)) {
const source = approvedList.get(dependedPackage)
if (source === installationSource) return
if (Array.isArray(source) && source.indexOf(installationSource) !== -1) return
}
if (dependedPackage === 'lodash-es' && installationSource.startsWith('npm:lodash@^4')) return
// !!! Relative path
if (installationSource === 'link:../empty' || installationSource === 'link:..\\empty') return
if (installationSource === '../empty' || installationSource === '..\\empty') return
throw new Error(
`Unapproved dependency source:
Package: ${dependedPackage}
Source: ${installationSource}
Declared by: ${parentPackage}`,
)
}
function validatePackage({ dependencies, devDependencies, optionalDependencies, peerDependencies, name }) {
for (const [k, v] of notNormativeInstall(dependencies)) assertInstallationSourceValid(name, k, v)
// devDependencies won't be installed for intermediate dependencies
// for (const [k, v] of notNormativeInstall(devDependencies)) assertInstallationSourceValid(name, k, v)
for (const [k, v] of notNormativeInstall(optionalDependencies)) assertInstallationSourceValid(name, k, v)
for (const [k, v] of notNormativeInstall(peerDependencies)) assertInstallationSourceValid(name, k, v)
}
function lockPackage(pkg) {
if (pkg.name === 'opensea-js') {
const prefix = 'git+https://github.com/ProjectOpenSea/wyvern-'
pkg.dependencies['wyvern-js'] = `${prefix}js.git#fabb7660f23f2252c141077e32193d281036299e`
pkg.dependencies['wyvern-schemas'] = `${prefix}schemas.git#e1a08fcf8ce2b11a0fe9cbdc7c9f77c59fadef26`
}
}
function readPackage(pkg, context) {
validatePackage(pkg)
lockPackage(pkg)
return pkg
}
module.exports = {
hooks: {
readPackage,
},
}
function* notNormativeInstall(deps) {
for (const key in deps) {
const val = deps[key]
if (val.startsWith('workspace:')) continue
if (val.includes(':') || val.includes('/')) {
yield [key, val]
}
}
}