forked from DimensionDev/Maskbook
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pnpmfile.cjs
110 lines (92 loc) · 4.16 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
98
99
100
101
102
103
104
105
106
107
108
109
110
// !!! 1. Be responsible.
// !!! 2. Open a new issue to the library author.
// !!! 3. Add a pnpm/resolution in package.json if the package specifier does not include git hash to pin the version.
/* cspell:disable */
/** @type {Map<string, RegExp | string | (string | RegExp)[]>} */
const approvedList = new Map()
approvedList.set('ethereumjs-abi', [
// wyvern-js
'https://github.com/ProjectWyvern/ethereumjs-abi.git',
// eth-sig-util
'git+https://github.com/ethereumjs/ethereumjs-abi.git',
])
approvedList.set('webpack', 'Jack-Works/webpack#lazy-import')
approvedList.set('wyvern-js', [
// wyvern-schemas
'github:ProjectOpenSea/wyvern-js#semver:^3.2.1',
])
// https://github.com/storybookjs/storybook/issues/19055
approvedList.set('@storybook/react-docgen-typescript-plugin', 'npm:[email protected]')
// openseajs -> wyvern-schemas -> web3-provider-engine -> eth-block-tracker
approvedList.set('async-eventemitter', 'github:ahultgren/async-eventemitter#fa06e39e56786ba541c180061dbf2c0a5bbf951c')
// pnpm -r why [email protected]
approvedList.set('bignumber.js', [
'git+https://github.com/frozeman/bignumber.js-nolookahead.git',
'git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934',
])
// @magic-works/i18n-codegen -> i18next-translation-parser
// https://github.com/i18next/i18next-translation-parser/issues/11
approvedList.set('html-parse-stringify2', [
'github:locize/html-parse-stringify2',
'github:locize/html-parse-stringify2#d463109433b2c49c74a081044f54b2a6a1ccad7c',
])
/**
* @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 === '@typescript/lib-dom' && installationSource.startsWith('npm:@types/web@^')) return
// !!! 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.
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}
If you want to approve this new unusual dependency, please edit .pnpmfile.cjs.`,
)
}
/* cspell:enable */
function validatePackage({ dependencies, optionalDependencies, peerDependencies, name, exports }) {
if (
exports &&
!name.startsWith('@dimensiondev') &&
!name.startsWith('@masknet') &&
JSON.stringify(exports).includes('mask-src')
) {
throw new Error(
'A package ' + name + ' out of @dimensiondev or @masknet scope using mask-src in exports field.',
)
}
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(optionalDependencies)) assertInstallationSourceValid(name, k, v)
for (const [k, v] of notNormativeInstall(peerDependencies)) assertInstallationSourceValid(name, k, v)
}
function readPackage(pkg, context) {
validatePackage(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]
}
}
}