forked from DimensionDev/Maskbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pnpmfile.cjs
97 lines (86 loc) · 4.02 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
90
91
92
93
94
95
96
97
// !!! 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.
/** @type {Map<string, string | string[]>} */
// @ts-expect-error
const approvedList = new Map([
// opensea-js https://github.com/ProjectOpenSea/opensea-js/issues/407
[
'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.13.1'],
/* cspell:disable-next-line */
['async-eventemitter', 'github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c'],
// opensea-js (v1), (and more, run `pnpm -r why [email protected]`) -> web3
['bignumber.js', 'git+https://github.com/frozeman/bignumber.js-nolookahead.git'],
// https://github.com/i18next/i18next-translation-parser/issues/11
// @magic-works/i18n-codegen -> i18next-translation-parser
/* cspell:disable-next-line */
['html-parse-stringify2', 'github:locize/html-parse-stringify2'],
// ipfs https://github.com/ipfs/js-ipfs-utils/issues/158
['node-fetch', 'https://registry.npmjs.org/@achingbrain/node-fetch/-/node-fetch-2.6.7.tgz'],
])
/**
* @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]
}
}
}